xref: /linux/Documentation/networking/device_drivers/ethernet/ti/cpsw_switchdev.rst (revision 3d0fe49454652117522f60bfbefb978ba0e5300b)
1.. SPDX-License-Identifier: GPL-2.0
2
3======================================================
4Texas Instruments CPSW switchdev based ethernet driver
5======================================================
6
7:Version: 2.0
8
9Port renaming
10=============
11
12On older udev versions renaming of ethX to swXpY will not be automatically
13supported
14
15In order to rename via udev::
16
17    ip -d link show dev sw0p1 | grep switchid
18
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 mode
24=============
25
26- The new (cpsw_new.c) driver is operating in dual-emac mode by default, thus
27  working as 2 individual network interfaces. Main differences from legacy CPSW
28  driver are:
29
30 - optimized promiscuous mode: The P0_UNI_FLOOD (both ports) is enabled in
31   addition to ALLMULTI (current port) instead of ALE_BYPASS.
32   So, Ports in promiscuous mode will keep possibility of mcast and vlan
33   filtering, which is provides significant benefits when ports are joined
34   to the same bridge, but without enabling "switch" mode, or to different
35   bridges.
36 - learning disabled on ports as it make not too much sense for
37   segregated ports - no forwarding in HW.
38 - enabled basic support for devlink.
39
40   ::
41
42	devlink dev show
43		platform/48484000.switch
44
45	devlink dev param show
46	platform/48484000.switch:
47	name switch_mode type driver-specific
48	values:
49		cmode runtime value false
50	name ale_bypass type driver-specific
51	values:
52		cmode runtime value false
53
54Devlink configuration parameters
55================================
56
57See Documentation/networking/devlink/ti-cpsw-switch.rst
58
59Bridging in dual mac mode
60=========================
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 be
64configured in vlan unaware mode or default_pvid has to be adjusted::
65
66	ip link add name br0 type bridge
67	ip link set dev br0 type bridge vlan_filtering 0
68	echo 0 > /sys/class/net/br0/bridge/default_pvid
69	ip link set dev sw0p1 master br0
70	ip link set dev sw0p2 master br0
71
72or::
73
74	ip link add name br0 type bridge
75	ip link set dev br0 type bridge vlan_filtering 0
76	echo 100 > /sys/class/net/br0/bridge/default_pvid
77	ip link set dev br0 type bridge vlan_filtering 1
78	ip link set dev sw0p1 master br0
79	ip link set dev sw0p2 master br0
80
81Enabling "switch"
82=================
83
84The Switch mode can be enabled by configuring devlink driver parameter
85"switch_mode" to 1/true::
86
87	devlink dev param set platform/48484000.switch \
88	name switch_mode value 1 cmode runtime
89
90This can be done regardless of the state of Port's netdev devices - UP/DOWN, but
91Port's netdev devices have to be in UP before joining to the bridge to avoid
92overwriting of bridge configuration as CPSW switch driver copletly reloads its
93configuration when first Port changes its state to UP.
94
95When the both interfaces joined the bridge - CPSW switch driver will enable
96marking packets with offload_fwd_mark flag unless "ale_bypass=0"
97
98All configuration is implemented via switchdev API.
99
100Bridge setup
101============
102
103::
104
105	devlink dev param set platform/48484000.switch \
106	name switch_mode value 1 cmode runtime
107
108	ip link add name br0 type bridge
109	ip link set dev br0 type bridge ageing_time 1000
110	ip link set dev sw0p1 up
111	ip link set dev sw0p2 up
112	ip link set dev sw0p1 master br0
113	ip link set dev sw0p2 master br0
114
115	[*] bridge vlan add dev br0 vid 1 pvid untagged self
116
117	[*] if vlan_filtering=1. where default_pvid=1
118
119	Note. Steps [*] are mandatory.
120
121
122On/off STP
123==========
124
125::
126
127	ip link set dev BRDEV type bridge stp_state 1/0
128
129VLAN configuration
130==================
131
132::
133
134  bridge vlan add dev br0 vid 1 pvid untagged self <---- add cpu port to VLAN 1
135
136Note. This step is mandatory for bridge/default_pvid.
137
138Add extra VLANs
139===============
140
141 1. untagged::
142
143	bridge vlan add dev sw0p1 vid 100 pvid untagged master
144	bridge vlan add dev sw0p2 vid 100 pvid untagged master
145	bridge vlan add dev br0 vid 100 pvid untagged self <---- Add cpu port to VLAN100
146
147 2. tagged::
148
149	bridge vlan add dev sw0p1 vid 100 master
150	bridge vlan add dev sw0p2 vid 100 master
151	bridge vlan add dev br0 vid 100 pvid tagged self <---- Add cpu port to VLAN100
152
153FDBs
154----
155
156FDBs are automatically added on the appropriate switch port upon detection
157
158Manually adding FDBs::
159
160    bridge fdb add aa:bb:cc:dd:ee:ff dev sw0p1 master vlan 100
161    bridge fdb add aa:bb:cc:dd:ee:fe dev sw0p2 master <---- Add on all VLANs
162
163MDBs
164----
165
166MDBs are automatically added on the appropriate switch port upon detection
167
168Manually adding MDBs::
169
170  bridge mdb add dev br0 port sw0p1 grp 239.1.1.1 permanent vid 100
171  bridge mdb add dev br0 port sw0p1 grp 239.1.1.1 permanent <---- Add on all VLANs
172
173Multicast flooding
174==================
175CPU port mcast_flooding is always on
176
177Turning flooding on/off on switch ports:
178bridge link set dev sw0p1 mcast_flood on/off
179
180Access and Trunk port
181=====================
182
183::
184
185 bridge vlan add dev sw0p1 vid 100 pvid untagged master
186 bridge vlan add dev sw0p2 vid 100 master
187
188
189 bridge vlan add dev br0 vid 100 self
190 ip link add link br0 name br0.100 type vlan id 100
191
192Note. Setting PVID on Bridge device itself working only for
193default VLAN (default_pvid).
194
195NFS
196===
197
198The only way for NFS to work is by chrooting to a minimal environment when
199switch configuration that will affect connectivity is needed.
200Assuming you are booting NFS with eth1 interface(the script is hacky and
201it's just there to prove NFS is doable).
202
203setup.sh::
204
205	#!/bin/sh
206	mkdir proc
207	mount -t proc none /proc
208	ifconfig br0  > /dev/null
209	if [ $? -ne 0 ]; then
210		echo "Setting up bridge"
211		ip link add name br0 type bridge
212		ip link set dev br0 type bridge ageing_time 1000
213		ip link set dev br0 type bridge vlan_filtering 1
214
215		ip link set eth1 down
216		ip link set eth1 name sw0p1
217		ip link set dev sw0p1 up
218		ip link set dev sw0p2 up
219		ip link set dev sw0p2 master br0
220		ip link set dev sw0p1 master br0
221		bridge vlan add dev br0 vid 1 pvid untagged self
222		ifconfig sw0p1 0.0.0.0
223		udhchc -i br0
224	fi
225	umount /proc
226
227run_nfs.sh:::
228
229	#!/bin/sh
230	mkdir /tmp/root/bin -p
231	mkdir /tmp/root/lib -p
232
233	cp -r /lib/ /tmp/root/
234	cp -r /bin/ /tmp/root/
235	cp /sbin/ip /tmp/root/bin
236	cp /sbin/bridge /tmp/root/bin
237	cp /sbin/ifconfig /tmp/root/bin
238	cp /sbin/udhcpc /tmp/root/bin
239	cp /path/to/setup.sh /tmp/root/bin
240	chroot /tmp/root/ busybox sh /bin/setup.sh
241
242	run ./run_nfs.sh
243