From: Weijie Gao <weijie.gao@mediatek.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 18/26] net: mt7628-eth: add support to isolate LAN/WAN ports
Date: Thu, 29 Aug 2019 12:27:21 +0800 [thread overview]
Message-ID: <1567052841.2874.143.camel@mcddlt001> (raw)
In-Reply-To: <bd18c67b-d9f4-3220-0721-408677ccdcad@denx.de>
On Wed, 2019-08-28 at 15:46 +0200, Stefan Roese wrote:
> On 28.08.19 08:38, Weijie Gao wrote:
> > This patch add support for mt7628-eth to isolate LAN/WAN ports mainly to
>
> Nitpicking:
>
> s/add/adds
>
> > prevent LAN devices from getting IP address from WAN.
> >
> > Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
> > ---
> > drivers/net/mt7628-eth.c | 32 ++++++++++++++++++++++++++++++++
> > 1 file changed, 32 insertions(+)
> >
> > diff --git a/drivers/net/mt7628-eth.c b/drivers/net/mt7628-eth.c
> > index 8ca2c66edb..1215b24eaf 100644
> > --- a/drivers/net/mt7628-eth.c
> > +++ b/drivers/net/mt7628-eth.c
> > @@ -57,6 +57,11 @@
> > /* Ethernet switch register */
> > #define MT7628_SWITCH_FCT0 0x0008
> > #define MT7628_SWITCH_PFC1 0x0014
> > +#define MT7628_SWITCH_PVIDC0 0x0040
> > +#define MT7628_SWITCH_PVIDC1 0x0044
> > +#define MT7628_SWITCH_PVIDC2 0x0048
> > +#define MT7628_SWITCH_PVIDC3 0x004c
> > +#define MT7628_SWITCH_VMSC0 0x0070
> > #define MT7628_SWITCH_FPA 0x0084
> > #define MT7628_SWITCH_SOCPC 0x008c
> > #define MT7628_SWITCH_POC0 0x0090
> > @@ -137,6 +142,8 @@ struct mt7628_eth_dev {
> > int tx_dma_idx;
> >
> > struct reset_ctl rst_ephy;
> > +
> > + int wan_port;
> > };
> >
> > static int mt7628_eth_free_pkt(struct udevice *dev, uchar *packet, int length);
> > @@ -269,6 +276,9 @@ static void mt7628_ephy_init(struct mt7628_eth_dev *priv)
> > static void rt305x_esw_init(struct mt7628_eth_dev *priv)
> > {
> > void __iomem *base = priv->eth_sw_base;
> > + void __iomem *reg;
> > + u32 val = 0, pvid;
> > + int i;
> >
> > /*
> > * FC_RLS_TH=200, FC_SET_TH=160
> > @@ -290,6 +300,25 @@ static void rt305x_esw_init(struct mt7628_eth_dev *priv)
> > /* 1us cycle number=125 (FE's clock=125Mhz) */
> > writel(0x7d000000, base + MT7628_SWITCH_BMU_CTRL);
> >
> > + /* LAN/WAN partition, WAN port will be unusable in u-boot network */
> > + if (priv->wan_port >= 0 && priv->wan_port < 6) {
> > + for (i = 0; i < 8; i++) {
> > + pvid = i == priv->wan_port ? 2 : 1;
> > + reg = base + MT7628_SWITCH_PVIDC0 + (i / 2) * 4;
> > + if (i % 2 == 0) {
> > + val = pvid;
> > + } else {
> > + val |= (pvid << 12);
> > + writel(val, reg);
> > + }
> > + }
> > +
> > + val = 0xffff407f;
> > + val |= 1 << (8 + priv->wan_port);
> > + val &= ~(1 << priv->wan_port);
> > + writel(val, base + MT7628_SWITCH_VMSC0);
> > + }
> > +
> > /* Reset PHY */
> > reset_assert(&priv->rst_ephy);
> > reset_deassert(&priv->rst_ephy);
> > @@ -529,6 +558,9 @@ static int mt7628_eth_probe(struct udevice *dev)
> > return ret;
> > }
> >
> > + /* WAN port will be isolated from LAN ports */
> > + priv->wan_port = dev_read_u32_default(dev, "mediatek,wan-port", -1);
>
> Where is this DT property documented? I can't find it in Linux either. We should
> find some other way to reference the ports. Perhaps something like done in
> Linux DSA?
>
> What is your reasoning for this change? Which board / target are you supporting
> with this new code?
>
> Thanks,
> Stefan
This is for the situation mt76x8 used as a router with more than one
ethernet ports.
The mt76x8 has one switch, both LAN ports and WAN port come from it.
By default the switch is in dumb switch mode after power on, which means
any packet can be broadcast to any port with out restriction.
If a router powered on with both LAN cable and WAN cable plugged in, the
LAN device may get IP address from upstream before the kernel setting
the correct VLAN. However the IP address which is supposed to be get by
the router itself. This is what we don't want to be happened.
If we're using a switch like mt7530, we can use the port matrix to
isolate each port to solve this problem perfectly. You can refer to
mtk_eth.c, at the end of mt7530_setup().
However mt76x8 switch core does not have the port matrix functionality,
that means the VLAN must be used.
Considering you are using OpenWrt. The switch registers a switch object
to swconfig (OpenWrt's switch framework). So the VLAN is set by
swconfig, not the ethernet driver.
However u-boot does not have a switch framework, I have to add this
directly to the ethernet driver.
The WAN port, depending on the design of the router, can be any ports
from 0 to 4. So I use "mediatek,wan-port" to specify the WAN port.
If "mediatek,wan-port" is set, the WAN port is isolated from the switch.
Otherwise all ports are interconnected.
Weijie
next prev parent reply other threads:[~2019-08-29 4:27 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-28 6:37 [U-Boot] [PATCH 00/26] Add and update drivers for MediaTek MT76x8 SoCs Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 01/26] serial: serial_mtk: enable FIFO and disable flow control Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 02/26] serial: serial_mtk: add non-DM version for SPL Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 03/26] dts: mtmips: move uart property clock-frequency into mt7628an.dtsi Weijie Gao
2019-08-28 7:13 ` Stefan Roese
2019-08-28 6:37 ` [U-Boot] [PATCH 04/26] dts: mtmips: enable high-speed UART support for mt7628 Weijie Gao
2019-08-28 7:14 ` Stefan Roese
2019-08-28 6:37 ` [U-Boot] [PATCH 05/26] spi: mt7621-spi: remove data cache and rewrite its xfer function Weijie Gao
2019-08-28 7:55 ` Stefan Roese
2019-08-28 6:37 ` [U-Boot] [PATCH 06/26] spi: mt7621-spi: restore default register value after each xfer Weijie Gao
2019-08-28 8:01 ` Stefan Roese
2019-08-28 6:37 ` [U-Boot] [PATCH 07/26] pinctrl: add support for MediaTek MT7628 Weijie Gao
2019-08-28 12:26 ` Stefan Roese
2019-08-28 12:37 ` Stefan Roese
2019-08-29 3:04 ` Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 08/26] dts: mtmips: add pinctrl node for mt7628 Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 09/26] dts: mtmips: add default pinctrl for uart nodes Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 10/26] reset: add reset controller driver for MediaTek MIPS platform Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 11/26] dts: mtmips: update reset controller node for mt7628 Weijie Gao
2019-08-28 13:18 ` Stefan Roese
2019-08-29 3:18 ` Weijie Gao
2019-12-30 9:19 ` Mauro Condarelli
2019-12-30 10:22 ` Daniel Schwierzeck
2019-12-30 11:09 ` Mauro Condarelli
2019-12-30 12:14 ` Mauro Condarelli
2020-01-02 12:30 ` Stefan Roese
2020-01-02 13:36 ` Mauro Condarelli
2019-08-28 6:37 ` [U-Boot] [PATCH 12/26] clk: add clock gating driver for MediaTek MIPS platform Weijie Gao
2019-08-28 13:24 ` Daniel Schwierzeck
2019-08-29 3:25 ` Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 13/26] dts: mtmips: add gate clock node for mt7628 Weijie Gao
2019-08-28 6:37 ` [U-Boot] [PATCH 14/26] phy: mt76x8-usb-phy: add slew rate calibration and remove non-mt7628 part Weijie Gao
2019-08-28 6:38 ` [U-Boot] [PATCH 15/26] net: mt7628-eth: remove hardcoded gpio settings and regmap-based phy reset Weijie Gao
2019-08-28 13:32 ` Stefan Roese
2019-08-28 6:38 ` [U-Boot] [PATCH 16/26] net: mt7628-eth: remove phy link up detection Weijie Gao
2019-08-28 13:37 ` Stefan Roese
2019-08-29 3:32 ` Weijie Gao
2019-08-28 6:38 ` [U-Boot] [PATCH 17/26] net: mt7628-eth: free rx descriptor on receiving failure Weijie Gao
2019-08-28 13:42 ` Stefan Roese
2019-08-28 6:38 ` [U-Boot] [PATCH 18/26] net: mt7628-eth: add support to isolate LAN/WAN ports Weijie Gao
2019-08-28 13:46 ` Stefan Roese
2019-08-29 4:27 ` Weijie Gao [this message]
2019-08-28 6:38 ` [U-Boot] [PATCH 19/26] dts: mtmips: enable eth port0 led function for all boards Weijie Gao
2019-08-28 13:47 ` Stefan Roese
2019-08-28 6:38 ` [U-Boot] [PATCH 20/26] mmc: mtk-sd: add support for MediaTek MT7620/MT7628 SoCs Weijie Gao
2019-08-28 13:50 ` Stefan Roese
2019-08-29 4:28 ` Weijie Gao
2019-08-28 6:38 ` [U-Boot] [PATCH 21/26] mmc: mtk-sd: add a dts property cd-active-high for builtin-cd mode Weijie Gao
2019-08-28 6:38 ` [U-Boot] [PATCH 22/26] dts: mtmips: add mmc related nodes for mt7628an.dtsi Weijie Gao
2019-08-28 6:38 ` [U-Boot] [PATCH 23/26] dts: mtmips: add default pinctrl for gardena-smart-gateway-mt7688 Weijie Gao
2019-08-28 13:52 ` Stefan Roese
2019-08-28 6:38 ` [U-Boot] [PATCH 24/26] dts: mtmips: add default pinctrl to eth nodes for all boards Weijie Gao
2019-08-28 13:55 ` Stefan Roese
2019-08-28 6:38 ` [U-Boot] [PATCH 25/26] configs: mtmips: change all boards to use mtk high-speed uart driver Weijie Gao
2019-08-28 13:57 ` Stefan Roese
2019-08-29 4:30 ` Weijie Gao
2019-08-28 6:38 ` [U-Boot] [PATCH 26/26] configs: mtmips: add necessary drivers for mtmips boards Weijie Gao
2019-08-28 13:35 ` Daniel Schwierzeck
2019-08-28 13:40 ` Stefan Roese
2019-08-29 3:34 ` Weijie Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1567052841.2874.143.camel@mcddlt001 \
--to=weijie.gao@mediatek.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox