Subject: Re: [PATCH 2/2] net: ethernet: Add driver for Sunplus SP7021

From: Andrew Lunn <[email-masked]>
Date: Mon, 8 Nov 2021 18:32:52 +0100

On Mon, Nov 08, 2021 at 04:47:34PM +0000, Wells Lu 呂芳騰 wrote:
> > > The switch will not recognize type of packets, regardless BPDU, PTP or
> > > any other packets. If turning off source-address learning function, it
> > > works like an Ethernet plus a 2-port hub.
> > 
> > So without STP, there is no way to stop an loop, and a broadcast storm taking
> > down your network?
> 
> Do you mean connecting two PHY ports to the same LAN? We never 
> connect two PHY ports to the same LAN (or hub). I never think of this 
> loop problem. I thought only WAN has the loop problem.

Any Ethernet network can have a loop. Often loops a deliberate because
they give redundancy. STP will detect this loop, and somewhere in the
network one of the switches will block traffic to break the loop. But
if something in the network breaks, the port can be unblocked to allow
traffic to flow, redundancy. Well behaved switches should always
implement STP.

> How an Ethernet hub take care of this situation?

STP. Run tcpdump on your network. Depending on how your network is
configured, you might see BPDU from your building switches.

> Is that reasonable to connect two ports of an Ethernet hub together?

It is not just together. You cannot guarantee any Ethernet network is
a tree. You could connect the two ports to two different hubs, but
those hubs are connected together, and so you get a loop.

> > Looking at the TX descriptor, there are two bits:
> > 
> >           [18]: force forward to port 0
> >           [19]: force forward to port 1
> > 
> > When the switch is enabled, can these two bits be used?
> 
> Yes, for example, when bit 19 of TX descriptor is enabled, a packet from CPU 
> port is forwarded to LAN port 0 forcibly.
> 
> 
> > In the RX descriptor there is:
> > 
> > pkt_sp:
> >           000: from port0
> >           001: from port1
> >           110: soc0 loopback
> >           101: soc1 loopback
> > 
> > Are these bits used when the switch is enabled?
> 
> Yes, E- MAC driver uses these bits to tell where a packet comes from.
> Note that soc1 port (CPU port) has been removed in this chip.
 
Right. So you can have two netdev when in L2 switch mode.

You need to think about the Linux model some more. In linux,
networking hardware is there to accelerate what the Linux stack can do
in software. Take for example a simple SoC will have two Ethernet
interfaces. You can perform software bridging on those two interfaces:

ip link add name br0 type bridge
ip link set dev br0 up
ip link set dev eth0 master br0
ip link set dev eth1 master br0

The software bridge will decided which interface to send a packet
out. The software will perform learning etc.

You can use your dual MAC setup exactly like this. But you can also go
further. You can use the hardware to accelerate switching packets
between eth0 and eth1. But also Linux can still send packets out
specific ports using these bits. The software bridge and the hardware
bridge work together. This is the correct way to do this in Linux.

> Sorry, I don't know what is a RMC packet?

Sorry, i have no idea.

       Andrew