162306a36Sopenharmony_ci=========================
262306a36Sopenharmony_ciNXP SJA1105 switch driver
362306a36Sopenharmony_ci=========================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciOverview
662306a36Sopenharmony_ci========
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThe NXP SJA1105 is a family of 10 SPI-managed automotive switches:
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci- SJA1105E: First generation, no TTEthernet
1162306a36Sopenharmony_ci- SJA1105T: First generation, TTEthernet
1262306a36Sopenharmony_ci- SJA1105P: Second generation, no TTEthernet, no SGMII
1362306a36Sopenharmony_ci- SJA1105Q: Second generation, TTEthernet, no SGMII
1462306a36Sopenharmony_ci- SJA1105R: Second generation, no TTEthernet, SGMII
1562306a36Sopenharmony_ci- SJA1105S: Second generation, TTEthernet, SGMII
1662306a36Sopenharmony_ci- SJA1110A: Third generation, TTEthernet, SGMII, integrated 100base-T1 and
1762306a36Sopenharmony_ci  100base-TX PHYs
1862306a36Sopenharmony_ci- SJA1110B: Third generation, TTEthernet, SGMII, 100base-T1, 100base-TX
1962306a36Sopenharmony_ci- SJA1110C: Third generation, TTEthernet, SGMII, 100base-T1, 100base-TX
2062306a36Sopenharmony_ci- SJA1110D: Third generation, TTEthernet, SGMII, 100base-T1
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciBeing automotive parts, their configuration interface is geared towards
2362306a36Sopenharmony_ciset-and-forget use, with minimal dynamic interaction at runtime. They
2462306a36Sopenharmony_cirequire a static configuration to be composed by software and packed
2562306a36Sopenharmony_ciwith CRC and table headers, and sent over SPI.
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciThe static configuration is composed of several configuration tables. Each
2862306a36Sopenharmony_citable takes a number of entries. Some configuration tables can be (partially)
2962306a36Sopenharmony_cireconfigured at runtime, some not. Some tables are mandatory, some not:
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci============================= ================== =============================
3262306a36Sopenharmony_ciTable                          Mandatory          Reconfigurable
3362306a36Sopenharmony_ci============================= ================== =============================
3462306a36Sopenharmony_ciSchedule                       no                 no
3562306a36Sopenharmony_ciSchedule entry points          if Scheduling      no
3662306a36Sopenharmony_ciVL Lookup                      no                 no
3762306a36Sopenharmony_ciVL Policing                    if VL Lookup       no
3862306a36Sopenharmony_ciVL Forwarding                  if VL Lookup       no
3962306a36Sopenharmony_ciL2 Lookup                      no                 no
4062306a36Sopenharmony_ciL2 Policing                    yes                no
4162306a36Sopenharmony_ciVLAN Lookup                    yes                yes
4262306a36Sopenharmony_ciL2 Forwarding                  yes                partially (fully on P/Q/R/S)
4362306a36Sopenharmony_ciMAC Config                     yes                partially (fully on P/Q/R/S)
4462306a36Sopenharmony_ciSchedule Params                if Scheduling      no
4562306a36Sopenharmony_ciSchedule Entry Points Params   if Scheduling      no
4662306a36Sopenharmony_ciVL Forwarding Params           if VL Forwarding   no
4762306a36Sopenharmony_ciL2 Lookup Params               no                 partially (fully on P/Q/R/S)
4862306a36Sopenharmony_ciL2 Forwarding Params           yes                no
4962306a36Sopenharmony_ciClock Sync Params              no                 no
5062306a36Sopenharmony_ciAVB Params                     no                 no
5162306a36Sopenharmony_ciGeneral Params                 yes                partially
5262306a36Sopenharmony_ciRetagging                      no                 yes
5362306a36Sopenharmony_cixMII Params                    yes                no
5462306a36Sopenharmony_ciSGMII                          no                 yes
5562306a36Sopenharmony_ci============================= ================== =============================
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciAlso the configuration is write-only (software cannot read it back from the
5962306a36Sopenharmony_ciswitch except for very few exceptions).
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ciThe driver creates a static configuration at probe time, and keeps it at
6262306a36Sopenharmony_ciall times in memory, as a shadow for the hardware state. When required to
6362306a36Sopenharmony_cichange a hardware setting, the static configuration is also updated.
6462306a36Sopenharmony_ciIf that changed setting can be transmitted to the switch through the dynamic
6562306a36Sopenharmony_cireconfiguration interface, it is; otherwise the switch is reset and
6662306a36Sopenharmony_cireprogrammed with the updated static configuration.
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ciSwitching features
6962306a36Sopenharmony_ci==================
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ciThe driver supports the configuration of L2 forwarding rules in hardware for
7262306a36Sopenharmony_ciport bridging. The forwarding, broadcast and flooding domain between ports can
7362306a36Sopenharmony_cibe restricted through two methods: either at the L2 forwarding level (isolate
7462306a36Sopenharmony_cione bridge's ports from another's) or at the VLAN port membership level
7562306a36Sopenharmony_ci(isolate ports within the same bridge). The final forwarding decision taken by
7662306a36Sopenharmony_cithe hardware is a logical AND of these two sets of rules.
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ciThe hardware tags all traffic internally with a port-based VLAN (pvid), or it
7962306a36Sopenharmony_cidecodes the VLAN information from the 802.1Q tag. Advanced VLAN classification
8062306a36Sopenharmony_ciis not possible. Once attributed a VLAN tag, frames are checked against the
8162306a36Sopenharmony_ciport's membership rules and dropped at ingress if they don't match any VLAN.
8262306a36Sopenharmony_ciThis behavior is available when switch ports are enslaved to a bridge with
8362306a36Sopenharmony_ci``vlan_filtering 1``.
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciNormally the hardware is not configurable with respect to VLAN awareness, but
8662306a36Sopenharmony_ciby changing what TPID the switch searches 802.1Q tags for, the semantics of a
8762306a36Sopenharmony_cibridge with ``vlan_filtering 0`` can be kept (accept all traffic, tagged or
8862306a36Sopenharmony_ciuntagged), and therefore this mode is also supported.
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ciSegregating the switch ports in multiple bridges is supported (e.g. 2 + 2), but
9162306a36Sopenharmony_ciall bridges should have the same level of VLAN awareness (either both have
9262306a36Sopenharmony_ci``vlan_filtering`` 0, or both 1).
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciTopology and loop detection through STP is supported.
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciOffloads
9762306a36Sopenharmony_ci========
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciTime-aware scheduling
10062306a36Sopenharmony_ci---------------------
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ciThe switch supports a variation of the enhancements for scheduled traffic
10362306a36Sopenharmony_cispecified in IEEE 802.1Q-2018 (formerly 802.1Qbv). This means it can be used to
10462306a36Sopenharmony_ciensure deterministic latency for priority traffic that is sent in-band with its
10562306a36Sopenharmony_cigate-open event in the network schedule.
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciThis capability can be managed through the tc-taprio offload ('flags 2'). The
10862306a36Sopenharmony_cidifference compared to the software implementation of taprio is that the latter
10962306a36Sopenharmony_ciwould only be able to shape traffic originated from the CPU, but not
11062306a36Sopenharmony_ciautonomously forwarded flows.
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciThe device has 8 traffic classes, and maps incoming frames to one of them based
11362306a36Sopenharmony_cion the VLAN PCP bits (if no VLAN is present, the port-based default is used).
11462306a36Sopenharmony_ciAs described in the previous sections, depending on the value of
11562306a36Sopenharmony_ci``vlan_filtering``, the EtherType recognized by the switch as being VLAN can
11662306a36Sopenharmony_cieither be the typical 0x8100 or a custom value used internally by the driver
11762306a36Sopenharmony_cifor tagging. Therefore, the switch ignores the VLAN PCP if used in standalone
11862306a36Sopenharmony_cior bridge mode with ``vlan_filtering=0``, as it will not recognize the 0x8100
11962306a36Sopenharmony_ciEtherType. In these modes, injecting into a particular TX queue can only be
12062306a36Sopenharmony_cidone by the DSA net devices, which populate the PCP field of the tagging header
12162306a36Sopenharmony_cion egress. Using ``vlan_filtering=1``, the behavior is the other way around:
12262306a36Sopenharmony_cioffloaded flows can be steered to TX queues based on the VLAN PCP, but the DSA
12362306a36Sopenharmony_cinet devices are no longer able to do that. To inject frames into a hardware TX
12462306a36Sopenharmony_ciqueue with VLAN awareness active, it is necessary to create a VLAN
12562306a36Sopenharmony_cisub-interface on the DSA master port, and send normal (0x8100) VLAN-tagged
12662306a36Sopenharmony_citowards the switch, with the VLAN PCP bits set appropriately.
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciManagement traffic (having DMAC 01-80-C2-xx-xx-xx or 01-19-1B-xx-xx-xx) is the
12962306a36Sopenharmony_cinotable exception: the switch always treats it with a fixed priority and
13062306a36Sopenharmony_cidisregards any VLAN PCP bits even if present. The traffic class for management
13162306a36Sopenharmony_citraffic has a value of 7 (highest priority) at the moment, which is not
13262306a36Sopenharmony_ciconfigurable in the driver.
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ciBelow is an example of configuring a 500 us cyclic schedule on egress port
13562306a36Sopenharmony_ci``swp5``. The traffic class gate for management traffic (7) is open for 100 us,
13662306a36Sopenharmony_ciand the gates for all other traffic classes are open for 400 us::
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci  #!/bin/bash
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci  set -e -u -o pipefail
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci  NSEC_PER_SEC="1000000000"
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci  gatemask() {
14562306a36Sopenharmony_ci          local tc_list="$1"
14662306a36Sopenharmony_ci          local mask=0
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci          for tc in ${tc_list}; do
14962306a36Sopenharmony_ci                  mask=$((${mask} | (1 << ${tc})))
15062306a36Sopenharmony_ci          done
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci          printf "%02x" ${mask}
15362306a36Sopenharmony_ci  }
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci  if ! systemctl is-active --quiet ptp4l; then
15662306a36Sopenharmony_ci          echo "Please start the ptp4l service"
15762306a36Sopenharmony_ci          exit
15862306a36Sopenharmony_ci  fi
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci  now=$(phc_ctl /dev/ptp1 get | gawk '/clock time is/ { print $5; }')
16162306a36Sopenharmony_ci  # Phase-align the base time to the start of the next second.
16262306a36Sopenharmony_ci  sec=$(echo "${now}" | gawk -F. '{ print $1; }')
16362306a36Sopenharmony_ci  base_time="$(((${sec} + 1) * ${NSEC_PER_SEC}))"
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci  tc qdisc add dev swp5 parent root handle 100 taprio \
16662306a36Sopenharmony_ci          num_tc 8 \
16762306a36Sopenharmony_ci          map 0 1 2 3 5 6 7 \
16862306a36Sopenharmony_ci          queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \
16962306a36Sopenharmony_ci          base-time ${base_time} \
17062306a36Sopenharmony_ci          sched-entry S $(gatemask 7) 100000 \
17162306a36Sopenharmony_ci          sched-entry S $(gatemask "0 1 2 3 4 5 6") 400000 \
17262306a36Sopenharmony_ci          flags 2
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ciIt is possible to apply the tc-taprio offload on multiple egress ports. There
17562306a36Sopenharmony_ciare hardware restrictions related to the fact that no gate event may trigger
17662306a36Sopenharmony_cisimultaneously on two ports. The driver checks the consistency of the schedules
17762306a36Sopenharmony_ciagainst this restriction and errors out when appropriate. Schedule analysis is
17862306a36Sopenharmony_cineeded to avoid this, which is outside the scope of the document.
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ciRouting actions (redirect, trap, drop)
18162306a36Sopenharmony_ci--------------------------------------
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ciThe switch is able to offload flow-based redirection of packets to a set of
18462306a36Sopenharmony_cidestination ports specified by the user. Internally, this is implemented by
18562306a36Sopenharmony_cimaking use of Virtual Links, a TTEthernet concept.
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ciThe driver supports 2 types of keys for Virtual Links:
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci- VLAN-aware virtual links: these match on destination MAC address, VLAN ID and
19062306a36Sopenharmony_ci  VLAN PCP.
19162306a36Sopenharmony_ci- VLAN-unaware virtual links: these match on destination MAC address only.
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ciThe VLAN awareness state of the bridge (vlan_filtering) cannot be changed while
19462306a36Sopenharmony_cithere are virtual link rules installed.
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ciComposing multiple actions inside the same rule is supported. When only routing
19762306a36Sopenharmony_ciactions are requested, the driver creates a "non-critical" virtual link. When
19862306a36Sopenharmony_cithe action list also contains tc-gate (more details below), the virtual link
19962306a36Sopenharmony_cibecomes "time-critical" (draws frame buffers from a reserved memory partition,
20062306a36Sopenharmony_cietc).
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ciThe 3 routing actions that are supported are "trap", "drop" and "redirect".
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ciExample 1: send frames received on swp2 with a DA of 42:be:24:9b:76:20 to the
20562306a36Sopenharmony_ciCPU and to swp3. This type of key (DA only) when the port's VLAN awareness
20662306a36Sopenharmony_cistate is off::
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci  tc qdisc add dev swp2 clsact
20962306a36Sopenharmony_ci  tc filter add dev swp2 ingress flower skip_sw dst_mac 42:be:24:9b:76:20 \
21062306a36Sopenharmony_ci          action mirred egress redirect dev swp3 \
21162306a36Sopenharmony_ci          action trap
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ciExample 2: drop frames received on swp2 with a DA of 42:be:24:9b:76:20, a VID
21462306a36Sopenharmony_ciof 100 and a PCP of 0::
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci  tc filter add dev swp2 ingress protocol 802.1Q flower skip_sw \
21762306a36Sopenharmony_ci          dst_mac 42:be:24:9b:76:20 vlan_id 100 vlan_prio 0 action drop
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ciTime-based ingress policing
22062306a36Sopenharmony_ci---------------------------
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ciThe TTEthernet hardware abilities of the switch can be constrained to act
22362306a36Sopenharmony_cisimilarly to the Per-Stream Filtering and Policing (PSFP) clause specified in
22462306a36Sopenharmony_ciIEEE 802.1Q-2018 (formerly 802.1Qci). This means it can be used to perform
22562306a36Sopenharmony_citight timing-based admission control for up to 1024 flows (identified by a
22662306a36Sopenharmony_cituple composed of destination MAC address, VLAN ID and VLAN PCP). Packets which
22762306a36Sopenharmony_ciare received outside their expected reception window are dropped.
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ciThis capability can be managed through the offload of the tc-gate action. As
23062306a36Sopenharmony_cirouting actions are intrinsic to virtual links in TTEthernet (which performs
23162306a36Sopenharmony_ciexplicit routing of time-critical traffic and does not leave that in the hands
23262306a36Sopenharmony_ciof the FDB, flooding etc), the tc-gate action may never appear alone when
23362306a36Sopenharmony_ciasking sja1105 to offload it. One (or more) redirect or trap actions must also
23462306a36Sopenharmony_cifollow along.
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ciExample: create a tc-taprio schedule that is phase-aligned with a tc-gate
23762306a36Sopenharmony_cischedule (the clocks must be synchronized by a 1588 application stack, which is
23862306a36Sopenharmony_cioutside the scope of this document). No packet delivered by the sender will be
23962306a36Sopenharmony_cidropped. Note that the reception window is larger than the transmission window
24062306a36Sopenharmony_ci(and much more so, in this example) to compensate for the packet propagation
24162306a36Sopenharmony_cidelay of the link (which can be determined by the 1588 application stack).
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ciReceiver (sja1105)::
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci  tc qdisc add dev swp2 clsact
24662306a36Sopenharmony_ci  now=$(phc_ctl /dev/ptp1 get | awk '/clock time is/ {print $5}') && \
24762306a36Sopenharmony_ci          sec=$(echo $now | awk -F. '{print $1}') && \
24862306a36Sopenharmony_ci          base_time="$(((sec + 2) * 1000000000))" && \
24962306a36Sopenharmony_ci          echo "base time ${base_time}"
25062306a36Sopenharmony_ci  tc filter add dev swp2 ingress flower skip_sw \
25162306a36Sopenharmony_ci          dst_mac 42:be:24:9b:76:20 \
25262306a36Sopenharmony_ci          action gate base-time ${base_time} \
25362306a36Sopenharmony_ci          sched-entry OPEN  60000 -1 -1 \
25462306a36Sopenharmony_ci          sched-entry CLOSE 40000 -1 -1 \
25562306a36Sopenharmony_ci          action trap
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ciSender::
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci  now=$(phc_ctl /dev/ptp0 get | awk '/clock time is/ {print $5}') && \
26062306a36Sopenharmony_ci          sec=$(echo $now | awk -F. '{print $1}') && \
26162306a36Sopenharmony_ci          base_time="$(((sec + 2) * 1000000000))" && \
26262306a36Sopenharmony_ci          echo "base time ${base_time}"
26362306a36Sopenharmony_ci  tc qdisc add dev eno0 parent root taprio \
26462306a36Sopenharmony_ci          num_tc 8 \
26562306a36Sopenharmony_ci          map 0 1 2 3 4 5 6 7 \
26662306a36Sopenharmony_ci          queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \
26762306a36Sopenharmony_ci          base-time ${base_time} \
26862306a36Sopenharmony_ci          sched-entry S 01  50000 \
26962306a36Sopenharmony_ci          sched-entry S 00  50000 \
27062306a36Sopenharmony_ci          flags 2
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ciThe engine used to schedule the ingress gate operations is the same that the
27362306a36Sopenharmony_cione used for the tc-taprio offload. Therefore, the restrictions regarding the
27462306a36Sopenharmony_cifact that no two gate actions (either tc-gate or tc-taprio gates) may fire at
27562306a36Sopenharmony_cithe same time (during the same 200 ns slot) still apply.
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ciTo come in handy, it is possible to share time-triggered virtual links across
27862306a36Sopenharmony_cimore than 1 ingress port, via flow blocks. In this case, the restriction of
27962306a36Sopenharmony_cifiring at the same time does not apply because there is a single schedule in
28062306a36Sopenharmony_cithe system, that of the shared virtual link::
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci  tc qdisc add dev swp2 ingress_block 1 clsact
28362306a36Sopenharmony_ci  tc qdisc add dev swp3 ingress_block 1 clsact
28462306a36Sopenharmony_ci  tc filter add block 1 flower skip_sw dst_mac 42:be:24:9b:76:20 \
28562306a36Sopenharmony_ci          action gate index 2 \
28662306a36Sopenharmony_ci          base-time 0 \
28762306a36Sopenharmony_ci          sched-entry OPEN 50000000 -1 -1 \
28862306a36Sopenharmony_ci          sched-entry CLOSE 50000000 -1 -1 \
28962306a36Sopenharmony_ci          action trap
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ciHardware statistics for each flow are also available ("pkts" counts the number
29262306a36Sopenharmony_ciof dropped frames, which is a sum of frames dropped due to timing violations,
29362306a36Sopenharmony_cilack of destination ports and MTU enforcement checks). Byte-level counters are
29462306a36Sopenharmony_cinot available.
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ciLimitations
29762306a36Sopenharmony_ci===========
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ciThe SJA1105 switch family always performs VLAN processing. When configured as
30062306a36Sopenharmony_ciVLAN-unaware, frames carry a different VLAN tag internally, depending on
30162306a36Sopenharmony_ciwhether the port is standalone or under a VLAN-unaware bridge.
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ciThe virtual link keys are always fixed at {MAC DA, VLAN ID, VLAN PCP}, but the
30462306a36Sopenharmony_cidriver asks for the VLAN ID and VLAN PCP when the port is under a VLAN-aware
30562306a36Sopenharmony_cibridge. Otherwise, it fills in the VLAN ID and PCP automatically, based on
30662306a36Sopenharmony_ciwhether the port is standalone or in a VLAN-unaware bridge, and accepts only
30762306a36Sopenharmony_ci"VLAN-unaware" tc-flower keys (MAC DA).
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ciThe existing tc-flower keys that are offloaded using virtual links are no
31062306a36Sopenharmony_cilonger operational after one of the following happens:
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci- port was standalone and joins a bridge (VLAN-aware or VLAN-unaware)
31362306a36Sopenharmony_ci- port is part of a bridge whose VLAN awareness state changes
31462306a36Sopenharmony_ci- port was part of a bridge and becomes standalone
31562306a36Sopenharmony_ci- port was standalone, but another port joins a VLAN-aware bridge and this
31662306a36Sopenharmony_ci  changes the global VLAN awareness state of the bridge
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ciThe driver cannot veto all these operations, and it cannot update/remove the
31962306a36Sopenharmony_ciexisting tc-flower filters either. So for proper operation, the tc-flower
32062306a36Sopenharmony_cifilters should be installed only after the forwarding configuration of the port
32162306a36Sopenharmony_cihas been made, and removed by user space before making any changes to it.
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ciDevice Tree bindings and board design
32462306a36Sopenharmony_ci=====================================
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ciThis section references ``Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml``
32762306a36Sopenharmony_ciand aims to showcase some potential switch caveats.
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ciRMII PHY role and out-of-band signaling
33062306a36Sopenharmony_ci---------------------------------------
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ciIn the RMII spec, the 50 MHz clock signals are either driven by the MAC or by
33362306a36Sopenharmony_cian external oscillator (but not by the PHY).
33462306a36Sopenharmony_ciBut the spec is rather loose and devices go outside it in several ways.
33562306a36Sopenharmony_ciSome PHYs go against the spec and may provide an output pin where they source
33662306a36Sopenharmony_cithe 50 MHz clock themselves, in an attempt to be helpful.
33762306a36Sopenharmony_ciOn the other hand, the SJA1105 is only binary configurable - when in the RMII
33862306a36Sopenharmony_ciMAC role it will also attempt to drive the clock signal. To prevent this from
33962306a36Sopenharmony_cihappening it must be put in RMII PHY role.
34062306a36Sopenharmony_ciBut doing so has some unintended consequences.
34162306a36Sopenharmony_ciIn the RMII spec, the PHY can transmit extra out-of-band signals via RXD[1:0].
34262306a36Sopenharmony_ciThese are practically some extra code words (/J/ and /K/) sent prior to the
34362306a36Sopenharmony_cipreamble of each frame. The MAC does not have this out-of-band signaling
34462306a36Sopenharmony_cimechanism defined by the RMII spec.
34562306a36Sopenharmony_ciSo when the SJA1105 port is put in PHY role to avoid having 2 drivers on the
34662306a36Sopenharmony_ciclock signal, inevitably an RMII PHY-to-PHY connection is created. The SJA1105
34762306a36Sopenharmony_ciemulates a PHY interface fully and generates the /J/ and /K/ symbols prior to
34862306a36Sopenharmony_ciframe preambles, which the real PHY is not expected to understand. So the PHY
34962306a36Sopenharmony_cisimply encodes the extra symbols received from the SJA1105-as-PHY onto the
35062306a36Sopenharmony_ci100Base-Tx wire.
35162306a36Sopenharmony_ciOn the other side of the wire, some link partners might discard these extra
35262306a36Sopenharmony_cisymbols, while others might choke on them and discard the entire Ethernet
35362306a36Sopenharmony_ciframes that follow along. This looks like packet loss with some link partners
35462306a36Sopenharmony_cibut not with others.
35562306a36Sopenharmony_ciThe take-away is that in RMII mode, the SJA1105 must be let to drive the
35662306a36Sopenharmony_cireference clock if connected to a PHY.
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ciRGMII fixed-link and internal delays
35962306a36Sopenharmony_ci------------------------------------
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ciAs mentioned in the bindings document, the second generation of devices has
36262306a36Sopenharmony_citunable delay lines as part of the MAC, which can be used to establish the
36362306a36Sopenharmony_cicorrect RGMII timing budget.
36462306a36Sopenharmony_ciWhen powered up, these can shift the Rx and Tx clocks with a phase difference
36562306a36Sopenharmony_cibetween 73.8 and 101.7 degrees.
36662306a36Sopenharmony_ciThe catch is that the delay lines need to lock onto a clock signal with a
36762306a36Sopenharmony_cistable frequency. This means that there must be at least 2 microseconds of
36862306a36Sopenharmony_cisilence between the clock at the old vs at the new frequency. Otherwise the
36962306a36Sopenharmony_cilock is lost and the delay lines must be reset (powered down and back up).
37062306a36Sopenharmony_ciIn RGMII the clock frequency changes with link speed (125 MHz at 1000 Mbps, 25
37162306a36Sopenharmony_ciMHz at 100 Mbps and 2.5 MHz at 10 Mbps), and link speed might change during the
37262306a36Sopenharmony_ciAN process.
37362306a36Sopenharmony_ciIn the situation where the switch port is connected through an RGMII fixed-link
37462306a36Sopenharmony_cito a link partner whose link state life cycle is outside the control of Linux
37562306a36Sopenharmony_ci(such as a different SoC), then the delay lines would remain unlocked (and
37662306a36Sopenharmony_ciinactive) until there is manual intervention (ifdown/ifup on the switch port).
37762306a36Sopenharmony_ciThe take-away is that in RGMII mode, the switch's internal delays are only
37862306a36Sopenharmony_cireliable if the link partner never changes link speeds, or if it does, it does
37962306a36Sopenharmony_ciso in a way that is coordinated with the switch port (practically, both ends of
38062306a36Sopenharmony_cithe fixed-link are under control of the same Linux system).
38162306a36Sopenharmony_ciAs to why would a fixed-link interface ever change link speeds: there are
38262306a36Sopenharmony_ciEthernet controllers out there which come out of reset in 100 Mbps mode, and
38362306a36Sopenharmony_citheir driver inevitably needs to change the speed and clock frequency if it's
38462306a36Sopenharmony_cirequired to work at gigabit.
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ciMDIO bus and PHY management
38762306a36Sopenharmony_ci---------------------------
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ciThe SJA1105 does not have an MDIO bus and does not perform in-band AN either.
39062306a36Sopenharmony_ciTherefore there is no link state notification coming from the switch device.
39162306a36Sopenharmony_ciA board would need to hook up the PHYs connected to the switch to any other
39262306a36Sopenharmony_ciMDIO bus available to Linux within the system (e.g. to the DSA master's MDIO
39362306a36Sopenharmony_cibus). Link state management then works by the driver manually keeping in sync
39462306a36Sopenharmony_ci(over SPI commands) the MAC link speed with the settings negotiated by the PHY.
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ciBy comparison, the SJA1110 supports an MDIO slave access point over which its
39762306a36Sopenharmony_ciinternal 100base-T1 PHYs can be accessed from the host. This is, however, not
39862306a36Sopenharmony_ciused by the driver, instead the internal 100base-T1 and 100base-TX PHYs are
39962306a36Sopenharmony_ciaccessed through SPI commands, modeled in Linux as virtual MDIO buses.
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ciThe microcontroller attached to the SJA1110 port 0 also has an MDIO controller
40262306a36Sopenharmony_cioperating in master mode, however the driver does not support this either,
40362306a36Sopenharmony_cisince the microcontroller gets disabled when the Linux driver operates.
40462306a36Sopenharmony_ciDiscrete PHYs connected to the switch ports should have their MDIO interface
40562306a36Sopenharmony_ciattached to an MDIO controller from the host system and not to the switch,
40662306a36Sopenharmony_cisimilar to SJA1105.
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ciPort compatibility matrix
40962306a36Sopenharmony_ci-------------------------
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_ciThe SJA1105 port compatibility matrix is:
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_ci===== ============== ============== ==============
41462306a36Sopenharmony_ciPort   SJA1105E/T     SJA1105P/Q     SJA1105R/S
41562306a36Sopenharmony_ci===== ============== ============== ==============
41662306a36Sopenharmony_ci0      xMII           xMII           xMII
41762306a36Sopenharmony_ci1      xMII           xMII           xMII
41862306a36Sopenharmony_ci2      xMII           xMII           xMII
41962306a36Sopenharmony_ci3      xMII           xMII           xMII
42062306a36Sopenharmony_ci4      xMII           xMII           SGMII
42162306a36Sopenharmony_ci===== ============== ============== ==============
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ciThe SJA1110 port compatibility matrix is:
42562306a36Sopenharmony_ci
42662306a36Sopenharmony_ci===== ============== ============== ============== ==============
42762306a36Sopenharmony_ciPort   SJA1110A       SJA1110B       SJA1110C       SJA1110D
42862306a36Sopenharmony_ci===== ============== ============== ============== ==============
42962306a36Sopenharmony_ci0      RevMII (uC)    RevMII (uC)    RevMII (uC)    RevMII (uC)
43062306a36Sopenharmony_ci1      100base-TX     100base-TX     100base-TX
43162306a36Sopenharmony_ci       or SGMII                                     SGMII
43262306a36Sopenharmony_ci2      xMII           xMII           xMII           xMII
43362306a36Sopenharmony_ci       or SGMII                                     or SGMII
43462306a36Sopenharmony_ci3      xMII           xMII           xMII
43562306a36Sopenharmony_ci       or SGMII       or SGMII                      SGMII
43662306a36Sopenharmony_ci       or 2500base-X  or 2500base-X                 or 2500base-X
43762306a36Sopenharmony_ci4      SGMII          SGMII          SGMII          SGMII
43862306a36Sopenharmony_ci       or 2500base-X  or 2500base-X  or 2500base-X  or 2500base-X
43962306a36Sopenharmony_ci5      100base-T1     100base-T1     100base-T1     100base-T1
44062306a36Sopenharmony_ci6      100base-T1     100base-T1     100base-T1     100base-T1
44162306a36Sopenharmony_ci7      100base-T1     100base-T1     100base-T1     100base-T1
44262306a36Sopenharmony_ci8      100base-T1     100base-T1     n/a            n/a
44362306a36Sopenharmony_ci9      100base-T1     100base-T1     n/a            n/a
44462306a36Sopenharmony_ci10     100base-T1     n/a            n/a            n/a
44562306a36Sopenharmony_ci===== ============== ============== ============== ==============
446