243 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3======================================================4Texas Instruments CPSW switchdev based ethernet driver5======================================================6 7:Version: 2.08 9Port renaming10=============11 12On older udev versions renaming of ethX to swXpY will not be automatically13supported14 15In order to rename via udev::16 17 ip -d link show dev sw0p1 | grep switchid18 19 SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}==<switchid>, \20 ATTR{phys_port_name}!="", NAME="sw0$attr{phys_port_name}"21 22 23Dual mac mode24=============25 26- The new (cpsw_new.c) driver is operating in dual-emac mode by default, thus27 working as 2 individual network interfaces. Main differences from legacy CPSW28 driver are:29 30 - optimized promiscuous mode: The P0_UNI_FLOOD (both ports) is enabled in31 addition to ALLMULTI (current port) instead of ALE_BYPASS.32 So, Ports in promiscuous mode will keep possibility of mcast and vlan33 filtering, which is provides significant benefits when ports are joined34 to the same bridge, but without enabling "switch" mode, or to different35 bridges.36 - learning disabled on ports as it make not too much sense for37 segregated ports - no forwarding in HW.38 - enabled basic support for devlink.39 40 ::41 42 devlink dev show43 platform/48484000.switch44 45 devlink dev param show46 platform/48484000.switch:47 name switch_mode type driver-specific48 values:49 cmode runtime value false50 name ale_bypass type driver-specific51 values:52 cmode runtime value false53 54Devlink configuration parameters55================================56 57See Documentation/networking/devlink/ti-cpsw-switch.rst58 59Bridging in dual mac mode60=========================61 62The dual_mac mode requires two vids to be reserved for internal purposes,63which, by default, equal CPSW Port numbers. As result, bridge has to be64configured in vlan unaware mode or default_pvid has to be adjusted::65 66 ip link add name br0 type bridge67 ip link set dev br0 type bridge vlan_filtering 068 echo 0 > /sys/class/net/br0/bridge/default_pvid69 ip link set dev sw0p1 master br070 ip link set dev sw0p2 master br071 72or::73 74 ip link add name br0 type bridge75 ip link set dev br0 type bridge vlan_filtering 076 echo 100 > /sys/class/net/br0/bridge/default_pvid77 ip link set dev br0 type bridge vlan_filtering 178 ip link set dev sw0p1 master br079 ip link set dev sw0p2 master br080 81Enabling "switch"82=================83 84The Switch mode can be enabled by configuring devlink driver parameter85"switch_mode" to 1/true::86 87 devlink dev param set platform/48484000.switch \88 name switch_mode value 1 cmode runtime89 90This can be done regardless of the state of Port's netdev devices - UP/DOWN, but91Port's netdev devices have to be in UP before joining to the bridge to avoid92overwriting of bridge configuration as CPSW switch driver copletly reloads its93configuration when first Port changes its state to UP.94 95When the both interfaces joined the bridge - CPSW switch driver will enable96marking packets with offload_fwd_mark flag unless "ale_bypass=0"97 98All configuration is implemented via switchdev API.99 100Bridge setup101============102 103::104 105 devlink dev param set platform/48484000.switch \106 name switch_mode value 1 cmode runtime107 108 ip link add name br0 type bridge109 ip link set dev br0 type bridge ageing_time 1000110 ip link set dev sw0p1 up111 ip link set dev sw0p2 up112 ip link set dev sw0p1 master br0113 ip link set dev sw0p2 master br0114 115 [*] bridge vlan add dev br0 vid 1 pvid untagged self116 117 [*] if vlan_filtering=1. where default_pvid=1118 119 Note. Steps [*] are mandatory.120 121 122On/off STP123==========124 125::126 127 ip link set dev BRDEV type bridge stp_state 1/0128 129VLAN configuration130==================131 132::133 134 bridge vlan add dev br0 vid 1 pvid untagged self <---- add cpu port to VLAN 1135 136Note. This step is mandatory for bridge/default_pvid.137 138Add extra VLANs139===============140 141 1. untagged::142 143 bridge vlan add dev sw0p1 vid 100 pvid untagged master144 bridge vlan add dev sw0p2 vid 100 pvid untagged master145 bridge vlan add dev br0 vid 100 pvid untagged self <---- Add cpu port to VLAN100146 147 2. tagged::148 149 bridge vlan add dev sw0p1 vid 100 master150 bridge vlan add dev sw0p2 vid 100 master151 bridge vlan add dev br0 vid 100 pvid tagged self <---- Add cpu port to VLAN100152 153FDBs154----155 156FDBs are automatically added on the appropriate switch port upon detection157 158Manually adding FDBs::159 160 bridge fdb add aa:bb:cc:dd:ee:ff dev sw0p1 master vlan 100161 bridge fdb add aa:bb:cc:dd:ee:fe dev sw0p2 master <---- Add on all VLANs162 163MDBs164----165 166MDBs are automatically added on the appropriate switch port upon detection167 168Manually adding MDBs::169 170 bridge mdb add dev br0 port sw0p1 grp 239.1.1.1 permanent vid 100171 bridge mdb add dev br0 port sw0p1 grp 239.1.1.1 permanent <---- Add on all VLANs172 173Multicast flooding174==================175CPU port mcast_flooding is always on176 177Turning flooding on/off on switch ports:178bridge link set dev sw0p1 mcast_flood on/off179 180Access and Trunk port181=====================182 183::184 185 bridge vlan add dev sw0p1 vid 100 pvid untagged master186 bridge vlan add dev sw0p2 vid 100 master187 188 189 bridge vlan add dev br0 vid 100 self190 ip link add link br0 name br0.100 type vlan id 100191 192Note. Setting PVID on Bridge device itself working only for193default VLAN (default_pvid).194 195NFS196===197 198The only way for NFS to work is by chrooting to a minimal environment when199switch configuration that will affect connectivity is needed.200Assuming you are booting NFS with eth1 interface(the script is hacky and201it's just there to prove NFS is doable).202 203setup.sh::204 205 #!/bin/sh206 mkdir proc207 mount -t proc none /proc208 ifconfig br0 > /dev/null209 if [ $? -ne 0 ]; then210 echo "Setting up bridge"211 ip link add name br0 type bridge212 ip link set dev br0 type bridge ageing_time 1000213 ip link set dev br0 type bridge vlan_filtering 1214 215 ip link set eth1 down216 ip link set eth1 name sw0p1217 ip link set dev sw0p1 up218 ip link set dev sw0p2 up219 ip link set dev sw0p2 master br0220 ip link set dev sw0p1 master br0221 bridge vlan add dev br0 vid 1 pvid untagged self222 ifconfig sw0p1 0.0.0.0223 udhchc -i br0224 fi225 umount /proc226 227run_nfs.sh:::228 229 #!/bin/sh230 mkdir /tmp/root/bin -p231 mkdir /tmp/root/lib -p232 233 cp -r /lib/ /tmp/root/234 cp -r /bin/ /tmp/root/235 cp /sbin/ip /tmp/root/bin236 cp /sbin/bridge /tmp/root/bin237 cp /sbin/ifconfig /tmp/root/bin238 cp /sbin/udhcpc /tmp/root/bin239 cp /path/to/setup.sh /tmp/root/bin240 chroot /tmp/root/ busybox sh /bin/setup.sh241 242 run ./run_nfs.sh243