[PATCH net-next 07/13] selftests: mlxsw: Add router test

2018-06-29 Thread Petr Machata
From: Arkadi Sharshevsky 

This test aims for both stand alone and internal usage by the resource
infra. The test receives the number routes to offload and checks:
- The routes were offloaded correctly
- Traffic for each route.

Signed-off-by: Arkadi Sharshevsky 
Signed-off-by: Yuval Mintz 
Reviewed-by: Petr Machata 
Signed-off-by: Petr Machata 
---
 .../selftests/drivers/net/mlxsw/router_scale.sh| 167 +
 1 file changed, 167 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/net/mlxsw/router_scale.sh

diff --git a/tools/testing/selftests/drivers/net/mlxsw/router_scale.sh 
b/tools/testing/selftests/drivers/net/mlxsw/router_scale.sh
new file mode 100644
index ..d231649b4f01
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/mlxsw/router_scale.sh
@@ -0,0 +1,167 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ROUTER_NUM_NETIFS=4
+
+router_h1_create()
+{
+   simple_if_init $h1 192.0.1.1/24
+   ip route add 193.0.0.0/8 via 192.0.1.2 dev $h1
+}
+
+router_h1_destroy()
+{
+   ip route del 193.0.0.0/8 via 192.0.1.2 dev $h1
+   simple_if_fini $h1 192.0.1.1/24
+}
+
+router_h2_create()
+{
+   simple_if_init $h2 192.0.2.1/24
+   tc qdisc add dev $h2 handle : ingress
+}
+
+router_h2_destroy()
+{
+   tc qdisc del dev $h2 handle : ingress
+   simple_if_fini $h2 192.0.2.1/24
+}
+
+router_create()
+{
+   ip link set dev $rp1 up
+   ip link set dev $rp2 up
+
+   ip address add 192.0.1.2/24 dev $rp1
+   ip address add 192.0.2.2/24 dev $rp2
+}
+
+router_destroy()
+{
+   ip address del 192.0.2.2/24 dev $rp2
+   ip address del 192.0.1.2/24 dev $rp1
+
+   ip link set dev $rp2 down
+   ip link set dev $rp1 down
+}
+
+router_setup_prepare()
+{
+   h1=${NETIFS[p1]}
+   rp1=${NETIFS[p2]}
+
+   rp2=${NETIFS[p3]}
+   h2=${NETIFS[p4]}
+
+   h1mac=$(mac_get $h1)
+   rp1mac=$(mac_get $rp1)
+
+   vrf_prepare
+
+   router_h1_create
+   router_h2_create
+
+   router_create
+}
+
+router_offload_validate()
+{
+   local route_count=$1
+   local offloaded_count
+
+   offloaded_count=$(ip route | grep -o 'offload' | wc -l)
+   [[ $offloaded_count -ge $route_count ]]
+}
+
+router_routes_create()
+{
+   local route_count=$1
+   local count=0
+
+   ROUTE_FILE="$(mktemp)"
+
+   for i in {0..255}
+   do
+   for j in {0..255}
+   do
+   for k in {0..255}
+   do
+   if [[ $count -eq $route_count ]]; then
+   break 3
+   fi
+
+   echo route add 193.${i}.${j}.${k}/32 via \
+  192.0.2.1 dev $rp2  >> $ROUTE_FILE
+   ((count++))
+   done
+   done
+   done
+
+   ip -b $ROUTE_FILE &> /dev/null
+}
+
+router_routes_destroy()
+{
+   if [[ -v ROUTE_FILE ]]; then
+   rm -f $ROUTE_FILE
+   fi
+}
+
+router_test()
+{
+   local route_count=$1
+   local should_fail=$2
+   local count=0
+
+   RET=0
+
+   router_routes_create $route_count
+
+   router_offload_validate $route_count
+   check_err_fail $should_fail $? "Offload of $route_count routes"
+   if [[ $RET -ne 0 ]] || [[ $should_fail -eq 1 ]]; then
+   return
+   fi
+
+   tc filter add dev $h2 ingress protocol ip pref 1 flower \
+   skip_sw dst_ip 193.0.0.0/8 action drop
+
+   for i in {0..255}
+   do
+   for j in {0..255}
+   do
+   for k in {0..255}
+   do
+   if [[ $count -eq $route_count ]]; then
+   break 3
+   fi
+
+   $MZ $h1 -c 1 -p 64 -a $h1mac -b $rp1mac \
+   -A 192.0.1.1 -B 193.${i}.${j}.${k} \
+   -t ip -q
+   ((count++))
+   done
+   done
+   done
+
+   tc_check_packets "dev $h2 ingress" 1 $route_count
+   check_err $? "Offload mismatch"
+
+   tc filter del dev $h2 ingress protocol ip pref 1 flower \
+   skip_sw dst_ip 193.0.0.0/8 action drop
+
+   router_routes_destroy
+}
+
+router_cleanup()
+{
+   pre_cleanup
+
+   router_routes_destroy
+   router_destroy
+
+   router_h2_destroy
+   router_h1_destroy
+
+   vrf_cleanup
+}
-- 
2.4.11



[PATCH net-next 06/13] selftests: mlxsw: Add devlink KVD resource test

2018-06-29 Thread Petr Machata
From: Yuval Mintz 

Add a selftest that can be used to perform basic sanity of the devlink
resource API as well as test the behavior of KVD manipulation in the
driver.

This is the first case of a HW-only test - in order to test the devlink
resource a driver capable of exposing resources has to be provided
first.

Signed-off-by: Yuval Mintz 
[pe...@mellanox.com: Extracted two patches out of this patch. Tweaked
commit message.]
Signed-off-by: Petr Machata 
---
 .../net/mlxsw/spectrum/devlink_resources.sh| 117 +
 1 file changed, 117 insertions(+)
 create mode 100755 
tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_resources.sh

diff --git 
a/tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_resources.sh 
b/tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_resources.sh
new file mode 100755
index ..b1fe960e398a
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_resources.sh
@@ -0,0 +1,117 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+NUM_NETIFS=1
+source devlink_lib_spectrum.sh
+
+setup_prepare()
+{
+   devlink_sp_read_kvd_defaults
+}
+
+cleanup()
+{
+   pre_cleanup
+   devlink_sp_size_kvd_to_default
+}
+
+trap cleanup EXIT
+
+setup_prepare
+
+profiles_test()
+{
+   local i
+
+   log_info "Running profile tests"
+
+   for i in $KVD_PROFILES; do
+   RET=0
+   devlink_sp_resource_kvd_profile_set $i
+   log_test "'$i' profile"
+   done
+
+   # Default is explicitly tested at end to ensure it's actually applied
+   RET=0
+   devlink_sp_resource_kvd_profile_set "default"
+   log_test "'default' profile"
+}
+
+resources_min_test()
+{
+   local size
+   local i
+   local j
+
+   log_info "Running KVD-minimum tests"
+
+   for i in $KVD_CHILDREN; do
+   RET=0
+   size=$(devlink_resource_get kvd "$i" | jq '.["size_min"]')
+   devlink_resource_size_set "$size" kvd "$i"
+
+   # In case of linear, need to minimize sub-resources as well
+   if [[ "$i" == "linear" ]]; then
+   for j in $KVDL_CHILDREN; do
+   devlink_resource_size_set 0 kvd linear "$j"
+   done
+   fi
+
+   devlink_reload
+   devlink_sp_size_kvd_to_default
+   log_test "'$i' minimize [$size]"
+   done
+}
+
+resources_max_test()
+{
+   local min_size
+   local size
+   local i
+   local j
+
+   log_info "Running KVD-maximum tests"
+   for i in $KVD_CHILDREN; do
+   RET=0
+   devlink_sp_resource_minimize
+
+   # Calculate the maximum possible size for the given partition
+   size=$(devlink_resource_size_get kvd)
+   for j in $KVD_CHILDREN; do
+   if [ "$i" != "$j" ]; then
+   min_size=$(devlink_resource_get kvd "$j" | \
+  jq '.["size_min"]')
+   size=$((size - min_size))
+   fi
+   done
+
+   # Test almost maximum size
+   devlink_resource_size_set "$((size - 128))" kvd "$i"
+   devlink_reload
+   log_test "'$i' almost maximize [$((size - 128))]"
+
+   # Test above maximum size
+   devlink resource set "$DEVLINK_DEV" \
+   path "kvd/$i" size $((size + 128)) &> /dev/null
+   check_fail $? "Set kvd/$i to size $((size + 128)) should fail"
+   log_test "'$i' Overflow rejection [$((size + 128))]"
+
+   # Test maximum size
+   if [ "$i" == "hash_single" ] || [ "$i" == "hash_double" ]; then
+   echo "SKIP: Observed problem with exact max $i"
+   continue
+   fi
+
+   devlink_resource_size_set "$size" kvd "$i"
+   devlink_reload
+   log_test "'$i' maximize [$size]"
+
+   devlink_sp_size_kvd_to_default
+   done
+}
+
+profiles_test
+resources_min_test
+resources_max_test
+
+exit "$RET"
-- 
2.4.11



[PATCH net-next 05/13] selftests: mlxsw: Add devlink_lib_spectrum.sh

2018-06-29 Thread Petr Machata
This library builds on top of devlink_lib.sh and contains functionality
specific to Spectrum ASICs, e.g., re-partitioning the various KVD
sub-parts.

Signed-off-by: Yuval Mintz 
[pe...@mellanox.com: Split this out from another patch. Fix line length
in devlink_sp_read_kvd_defaults().]
Signed-off-by: Petr Machata 
---
 MAINTAINERS|   1 +
 .../net/mlxsw/spectrum/devlink_lib_spectrum.sh | 119 +
 2 files changed, 120 insertions(+)
 create mode 100644 
tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_lib_spectrum.sh

diff --git a/MAINTAINERS b/MAINTAINERS
index f3e766e504d8..f3dd6c4f61e1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9154,6 +9154,7 @@ S:Supported
 W: http://www.mellanox.com
 Q: http://patchwork.ozlabs.org/project/netdev/list/
 F: drivers/net/ethernet/mellanox/mlxsw/
+F: tools/testing/selftests/drivers/net/mlxsw/
 
 MELLANOX FIRMWARE FLASH LIBRARY (mlxfw)
 M: ml...@mellanox.com
diff --git 
a/tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_lib_spectrum.sh 
b/tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_lib_spectrum.sh
new file mode 100644
index ..73035e25085d
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_lib_spectrum.sh
@@ -0,0 +1,119 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source "../../../../net/forwarding/devlink_lib.sh"
+
+if [ "$DEVLINK_VIDDID" != "15b3:cb84" ]; then
+   echo "SKIP: test is tailored for Mellanox Spectrum"
+   exit 1
+fi
+
+# Needed for returning to default
+declare -A KVD_DEFAULTS
+
+KVD_CHILDREN="linear hash_single hash_double"
+KVDL_CHILDREN="singles chunks large_chunks"
+
+devlink_sp_resource_minimize()
+{
+   local size
+   local i
+
+   for i in $KVD_CHILDREN; do
+   size=$(devlink_resource_get kvd "$i" | jq '.["size_min"]')
+   devlink_resource_size_set "$size" kvd "$i"
+   done
+
+   for i in $KVDL_CHILDREN; do
+   size=$(devlink_resource_get kvd linear "$i" | \
+  jq '.["size_min"]')
+   devlink_resource_size_set "$size" kvd linear "$i"
+   done
+}
+
+devlink_sp_size_kvd_to_default()
+{
+   local need_reload=0
+   local i
+
+   for i in $KVD_CHILDREN; do
+   local size=$(echo "${KVD_DEFAULTS[kvd_$i]}" | jq '.["size"]')
+   current_size=$(devlink_resource_size_get kvd "$i")
+
+   if [ "$size" -ne "$current_size" ]; then
+   devlink_resource_size_set "$size" kvd "$i"
+   need_reload=1
+   fi
+   done
+
+   for i in $KVDL_CHILDREN; do
+   local size=$(echo "${KVD_DEFAULTS[kvd_linear_$i]}" | \
+jq '.["size"]')
+   current_size=$(devlink_resource_size_get kvd linear "$i")
+
+   if [ "$size" -ne "$current_size" ]; then
+   devlink_resource_size_set "$size" kvd linear "$i"
+   need_reload=1
+   fi
+   done
+
+   if [ "$need_reload" -ne "0" ]; then
+   devlink_reload
+   fi
+}
+
+devlink_sp_read_kvd_defaults()
+{
+   local key
+   local i
+
+   KVD_DEFAULTS[kvd]=$(devlink_resource_get "kvd")
+   for i in $KVD_CHILDREN; do
+   key=kvd_$i
+   KVD_DEFAULTS[$key]=$(devlink_resource_get kvd "$i")
+   done
+
+   for i in $KVDL_CHILDREN; do
+   key=kvd_linear_$i
+   KVD_DEFAULTS[$key]=$(devlink_resource_get kvd linear "$i")
+   done
+}
+
+KVD_PROFILES="default scale ipv4_max"
+
+devlink_sp_resource_kvd_profile_set()
+{
+   local profile=$1
+
+   case "$profile" in
+   scale)
+   devlink_resource_size_set 64000 kvd linear
+   devlink_resource_size_set 15616 kvd linear singles
+   devlink_resource_size_set 32000 kvd linear chunks
+   devlink_resource_size_set 16384 kvd linear large_chunks
+   devlink_resource_size_set 128000 kvd hash_single
+   devlink_resource_size_set 48000 kvd hash_double
+   devlink_reload
+   ;;
+   ipv4_max)
+   devlink_resource_size_set 64000 kvd linear
+   devlink_resource_size_set 15616 kvd linear singles
+   devlink_resource_size_set 32000 kvd linear chunks
+   devlink_resource_size_set 16384 kvd linear large_chunks
+   devlink_resource_size_set 144000 kvd hash_single
+   devlink_resource_size_set 32

[PATCH net-next 04/13] selftests: forwarding: Add devlink_lib.sh

2018-06-29 Thread Petr Machata
This helper library contains wrappers to devlink functionality agnostic
to the underlying device.

Signed-off-by: Yuval Mintz 
[pe...@mellanox.com: Split this out from another patch.]
Signed-off-by: Petr Machata 
---
 .../selftests/net/forwarding/devlink_lib.sh| 108 +
 1 file changed, 108 insertions(+)
 create mode 100644 tools/testing/selftests/net/forwarding/devlink_lib.sh

diff --git a/tools/testing/selftests/net/forwarding/devlink_lib.sh 
b/tools/testing/selftests/net/forwarding/devlink_lib.sh
new file mode 100644
index ..5ab1e5f43022
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/devlink_lib.sh
@@ -0,0 +1,108 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+##
+# Source library
+
+relative_path="${BASH_SOURCE%/*}"
+if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
+   relative_path="."
+fi
+
+source "$relative_path/lib.sh"
+
+##
+# Defines
+
+DEVLINK_DEV=$(devlink port show | grep "${NETIFS[p1]}" | \
+ grep -v "${NETIFS[p1]}[0-9]" | cut -d" " -f1 | \
+ rev | cut -d"/" -f2- | rev)
+if [ -z "$DEVLINK_DEV" ]; then
+   echo "SKIP: ${NETIFS[p1]} has no devlink device registered for it"
+   exit 1
+fi
+if [[ "$(echo $DEVLINK_DEV | grep -c pci)" -eq 0 ]]; then
+   echo "SKIP: devlink device's bus is not PCI"
+   exit 1
+fi
+
+DEVLINK_VIDDID=$(lspci -s $(echo $DEVLINK_DEV | cut -d"/" -f2) \
+-n | cut -d" " -f3)
+
+##
+# Sanity checks
+
+devlink -j resource show "$DEVLINK_DEV" &> /dev/null
+if [ $? -ne 0 ]; then
+   echo "SKIP: iproute2 too old, missing devlink resource support"
+   exit 1
+fi
+
+##
+# Devlink helpers
+
+devlink_resource_names_to_path()
+{
+   local resource
+   local path=""
+
+   for resource in "${@}"; do
+   if [ "$path" == "" ]; then
+   path="$resource"
+   else
+   path="${path}/$resource"
+   fi
+   done
+
+   echo "$path"
+}
+
+devlink_resource_get()
+{
+   local name=$1
+   local resource_name=.[][\"$DEVLINK_DEV\"]
+
+   resource_name="$resource_name | .[] | select (.name == \"$name\")"
+
+   shift
+   for resource in "${@}"; do
+   resource_name="${resource_name} | .[\"resources\"][] | \
+  select (.name == \"$resource\")"
+   done
+
+   devlink -j resource show "$DEVLINK_DEV" | jq "$resource_name"
+}
+
+devlink_resource_size_get()
+{
+   local size=$(devlink_resource_get "$@" | jq '.["size_new"]')
+
+   if [ "$size" == "null" ]; then
+   devlink_resource_get "$@" | jq '.["size"]'
+   else
+   echo "$size"
+   fi
+}
+
+devlink_resource_size_set()
+{
+   local new_size=$1
+   local path
+
+   shift
+   path=$(devlink_resource_names_to_path "$@")
+   devlink resource set "$DEVLINK_DEV" path "$path" size "$new_size"
+   check_err $? "Failed setting path $path to size $size"
+}
+
+devlink_reload()
+{
+   local still_pending
+
+   devlink dev reload "$DEVLINK_DEV" &> /dev/null
+   check_err $? "Failed reload"
+
+   still_pending=$(devlink resource show "$DEVLINK_DEV" | \
+   grep -c "size_new")
+   check_err $still_pending "Failed reload - There are still unset sizes"
+}
-- 
2.4.11



[PATCH net-next 03/13] selftests: forwarding: lib: Parameterize NUM_NETIFS in two functions

2018-06-29 Thread Petr Machata
setup_wait() and tc_offload_check() both assume that all NUM_NETIFS
interfaces are relevant for a given test. However, the scale test script
acts as an umbrella for a number of sub-tests, some of which may not
require all the interfaces.

Thus it's suboptimal for tc_offload_check() to query all the interfaces.
In case of setup_wait() it's incorrect, because the sub-test in question
of course doesn't configure any interfaces beyond what it needs, and
setup_wait() then ends up waiting indefinitely for the extraneous
interfaces to come up.

For that reason, give setup_wait() and tc_offload_check() an optional
parameter with a number of interfaces to probe. Fall back to global
NUM_NETIFS if the parameter is not given.

Signed-off-by: Petr Machata 
Reviewed-by: Yuval Mintz 
---
 tools/testing/selftests/net/forwarding/lib.sh | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 5f4b7ed2c65a..e073918bbe15 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -220,7 +220,9 @@ setup_wait_dev()
 
 setup_wait()
 {
-   for i in $(eval echo {1..$NUM_NETIFS}); do
+   local num_netifs=${1:-$NUM_NETIFS}
+
+   for ((i = 1; i <= num_netifs; ++i)); do
setup_wait_dev ${NETIFS[p$i]}
done
 
@@ -481,7 +483,9 @@ forwarding_restore()
 
 tc_offload_check()
 {
-   for i in $(eval echo {1..$NUM_NETIFS}); do
+   local num_netifs=${1:-$NUM_NETIFS}
+
+   for ((i = 1; i <= num_netifs; ++i)); do
ethtool -k ${NETIFS[p$i]} \
| grep "hw-tc-offload: on" &> /dev/null
if [[ $? -ne 0 ]]; then
-- 
2.4.11



[PATCH net-next 01/13] selftests: forwarding: Allow lib.sh sourcing from other directories

2018-06-29 Thread Petr Machata
From: Yuval Mintz 

The devlink related scripts are mlxsw-specific. As a result, they'll
reside in a different directory - but would still need the common logic
implemented in lib.sh.
So as a preliminary step, allow lib.sh to be sourced from other
directories as well.

Signed-off-by: Yuval Mintz 
Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/lib.sh | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index d1f14f83979e..59272824ef37 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -14,8 +14,13 @@ PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no}
 NETIF_TYPE=${NETIF_TYPE:=veth}
 NETIF_CREATE=${NETIF_CREATE:=yes}
 
-if [[ -f forwarding.config ]]; then
-   source forwarding.config
+relative_path="${BASH_SOURCE%/*}"
+if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
+   relative_path="."
+fi
+
+if [[ -f $relative_path/forwarding.config ]]; then
+   source "$relative_path/forwarding.config"
 fi
 
 ##
-- 
2.4.11



[PATCH net-next 02/13] selftests: forwarding: lib: Add check_err_fail()

2018-06-29 Thread Petr Machata
In the scale testing scenarios, one usually has a condition that is
expected to either fail, or pass, depending on which side of the scale
is being tested.

To capture this logic, add a function check_err_fail(), which dispatches
either to check_err() or check_fail(), depending on the value of the
first argument, should_fail.

Signed-off-by: Petr Machata 
Reviewed-by: Yuval Mintz 
---
 tools/testing/selftests/net/forwarding/lib.sh | 13 +
 1 file changed, 13 insertions(+)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 59272824ef37..5f4b7ed2c65a 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -156,6 +156,19 @@ check_fail()
fi
 }
 
+check_err_fail()
+{
+   local should_fail=$1; shift
+   local err=$1; shift
+   local what=$1; shift
+
+   if ((should_fail)); then
+   check_fail $err "$what succeeded, but should have failed"
+   else
+   check_err $err "$what failed"
+   fi
+}
+
 log_test()
 {
local test_name=$1
-- 
2.4.11



[PATCH net-next 00/13] mlxsw: Add resource scale tests

2018-06-29 Thread Petr Machata
There are a number of tests that check features of the Linux networking
stack. By running them on suitable interfaces, one can exercise the
mlxsw offloading code. However none of these tests attempts to push
mlxsw to the limits supported by the ASIC.

As an additional wrinkle, the "limits supported by the ASIC" themselves
may not be a set of fixed numbers, but rather depend on a profile that
determines how the ASIC resources are allocated for different purposes.

This patchset introduces several tests that verify capability of mlxsw
to offload amounts of routes, flower rules, and mirroring sessions that
match predicted ASIC capacity, at different configuration profiles.
Additionally they verify that amounts exceeding the predicted capacity
can *not* be offloaded.

These are not generic tests, but ones that are tailored for mlxsw
specifically. For that reason they are not added to net/forwarding
selftests subdirectory, but rather to a newly-added drivers/net/mlxsw.

Patches #1, #2 and #3 tweak the generic forwarding/lib.sh to support the
new additions.

In patches #4 and #5, new libraries for interfacing with devlink are
introduced, first a generic one, then a Spectrum-specific one.

In patch #6, a devlink resource test is introduced.

Patches #7 and #8, #9 and #10, and #11 and #12 introduce three scale
tests: router, flower and mirror-to-gretap. The first of each pair of
patches introduces a generic portion of the test (mlxsw-specific), the
second introduces a Spectrum-specific wrapper.

Patch #13 then introduces a scale test driver that runs (possibly a
subset of) the tests introduced by patches from previous paragraph.

Arkadi Sharshevsky (1):
  selftests: mlxsw: Add router test

Petr Machata (8):
  selftests: forwarding: lib: Add check_err_fail()
  selftests: forwarding: lib: Parameterize NUM_NETIFS in two functions
  selftests: forwarding: Add devlink_lib.sh
  selftests: mlxsw: Add devlink_lib_spectrum.sh
  selftests: mlxsw: Add tc flower scale test
  selftests: mlxsw: Add target for tc flower test on spectrum
  selftests: mlxsw: Add scale test for mirror-to-gretap
  selftests: mlxsw: Add target for mirror-to-gretap test on spectrum

Yuval Mintz (4):
  selftests: forwarding: Allow lib.sh sourcing from other directories
  selftests: mlxsw: Add devlink KVD resource test
  selftests: mlxsw: Add target for router test on spectrum
  selftests: mlxsw: Add scale test for resources

 MAINTAINERS|   1 +
 .../drivers/net/mlxsw/mirror_gre_scale.sh  | 197 +
 .../selftests/drivers/net/mlxsw/router_scale.sh| 167 +
 .../net/mlxsw/spectrum/devlink_lib_spectrum.sh | 119 +
 .../net/mlxsw/spectrum/devlink_resources.sh| 117 
 .../drivers/net/mlxsw/spectrum/mirror_gre_scale.sh |  13 ++
 .../drivers/net/mlxsw/spectrum/resource_scale.sh   |  55 ++
 .../drivers/net/mlxsw/spectrum/router_scale.sh |  18 ++
 .../drivers/net/mlxsw/spectrum/tc_flower_scale.sh  |  19 ++
 .../selftests/drivers/net/mlxsw/tc_flower_scale.sh | 134 ++
 .../selftests/net/forwarding/devlink_lib.sh| 108 +++
 tools/testing/selftests/net/forwarding/lib.sh  |  30 +++-
 12 files changed, 974 insertions(+), 4 deletions(-)
 create mode 100644 
tools/testing/selftests/drivers/net/mlxsw/mirror_gre_scale.sh
 create mode 100644 tools/testing/selftests/drivers/net/mlxsw/router_scale.sh
 create mode 100644 
tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_lib_spectrum.sh
 create mode 100755 
tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_resources.sh
 create mode 100644 
tools/testing/selftests/drivers/net/mlxsw/spectrum/mirror_gre_scale.sh
 create mode 100755 
tools/testing/selftests/drivers/net/mlxsw/spectrum/resource_scale.sh
 create mode 100644 
tools/testing/selftests/drivers/net/mlxsw/spectrum/router_scale.sh
 create mode 100644 
tools/testing/selftests/drivers/net/mlxsw/spectrum/tc_flower_scale.sh
 create mode 100644 tools/testing/selftests/drivers/net/mlxsw/tc_flower_scale.sh
 create mode 100644 tools/testing/selftests/net/forwarding/devlink_lib.sh

-- 
2.4.11



[PATCH net-next 4/4] selftests: forwarding: mirror_gre_changes: Fix waiting for neighbor

2018-06-28 Thread Petr Machata
When running the test on soft devices, there's no mechanism to
gratuitously start resolving the neighbor for remote tunnel endpoint.
So instead of passively waiting, wait for the device to be up, and then
probe the neighbor with a ping.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_gre_changes.sh | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh
index aa29d46186a8..135902aa8b11 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh
@@ -122,15 +122,8 @@ test_span_gre_egress_up()
# After setting the device up, wait for neighbor to get resolved so that
# we can expect mirroring to work.
ip link set dev $swp3 up
-   while true; do
-   ip neigh sh dev $swp3 $remote_ip nud reachable |
-   grep -q ^
-   if [[ $? -ne 0 ]]; then
-   sleep 1
-   else
-   break
-   fi
-   done
+   setup_wait_dev $swp3
+   ping -c 1 -I $swp3 $remote_ip &>/dev/null
 
quick_test_span_gre_dir $tundev ingress
mirror_uninstall $swp1 ingress
-- 
2.4.11



[PATCH net-next 3/4] selftests: forwarding: Tweak tc filters for mirror-to-gretap tests

2018-06-28 Thread Petr Machata
When running mirror_gre_bridge_1d_vlan tests on veth, several issues
cause spurious failures:

- vlan_ethtype should be ip, not ipv6 even in mirror-to-ip6gretap case,
  because the overlay packet is still IPv4.
- Similarly ip_proto matches the innermost IP protocol, so can't be used
  to filter out GRE packet. Drop the corresponding condition.
- Because the above fixes the filters to match in slow path as well,
  they need to be made skip_hw so as not to double-count packets.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh | 6 --
 tools/testing/selftests/net/forwarding/mirror_gre_lib.sh| 2 +-
 tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh | 6 --
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh
index 3bb4c2ba7b14..197e769c2ed1 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh
@@ -74,12 +74,14 @@ test_vlan_match()
 
 test_gretap()
 {
-   test_vlan_match gt4 'vlan_id 555 vlan_ethtype ip' "mirror to gretap"
+   test_vlan_match gt4 'skip_hw vlan_id 555 vlan_ethtype ip' \
+   "mirror to gretap"
 }
 
 test_ip6gretap()
 {
-   test_vlan_match gt6 'vlan_id 555 vlan_ethtype ipv6' "mirror to 
ip6gretap"
+   test_vlan_match gt6 'skip_hw vlan_id 555 vlan_ethtype ip' \
+   "mirror to ip6gretap"
 }
 
 test_gretap_stp()
diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
index 619b469365be..1c18e332cd4f 100644
--- a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
@@ -62,7 +62,7 @@ full_test_span_gre_dir_vlan_ips()
  "$backward_type" "$ip1" "$ip2"
 
tc filter add dev $h3 ingress pref 77 prot 802.1q \
-   flower $vlan_match ip_proto 0x2f \
+   flower $vlan_match \
action pass
mirror_test v$h1 $ip1 $ip2 $h3 77 10
tc filter del dev $h3 ingress pref 77
diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
index 1ac5038ae256..d3e75bb6a2d8 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
@@ -88,12 +88,14 @@ test_vlan_match()
 
 test_gretap()
 {
-   test_vlan_match gt4 'vlan_id 555 vlan_ethtype ip' "mirror to gretap"
+   test_vlan_match gt4 'skip_hw vlan_id 555 vlan_ethtype ip' \
+   "mirror to gretap"
 }
 
 test_ip6gretap()
 {
-   test_vlan_match gt6 'vlan_id 555 vlan_ethtype ipv6' "mirror to 
ip6gretap"
+   test_vlan_match gt6 'skip_hw vlan_id 555 vlan_ethtype ip' \
+   "mirror to ip6gretap"
 }
 
 test_span_gre_forbidden_cpu()
-- 
2.4.11



[PATCH net-next 2/4] selftests: forwarding: lib: Avoid trapping soft devices

2018-06-28 Thread Petr Machata
There are several cases where traffic that would normally be forwarded
in silicon needs to be observed in slow path. That's achieved by
trapping such traffic, and the functions trap_install() and
trap_uninstall() realize that. However, such treatment is obviously
wrong if the device in question is actually a soft device not backed by
an ASIC.

Therefore try to trap if possible, but fall back to inserting a continue
if not.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/lib.sh | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index ac1df4860fbe..d1f14f83979e 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -479,9 +479,15 @@ trap_install()
local dev=$1; shift
local direction=$1; shift
 
-   # For slow-path testing, we need to install a trap to get to
-   # slow path the packets that would otherwise be switched in HW.
-   tc filter add dev $dev $direction pref 1 flower skip_sw action trap
+   # Some devices may not support or need in-hardware trapping of traffic
+   # (e.g. the veth pairs that this library creates for non-existent
+   # loopbacks). Use continue instead, so that there is a filter in there
+   # (some tests check counters), and so that other filters are still
+   # processed.
+   tc filter add dev $dev $direction pref 1 \
+   flower skip_sw action trap 2>/dev/null \
+   || tc filter add dev $dev $direction pref 1 \
+  flower action continue
 }
 
 trap_uninstall()
@@ -489,11 +495,13 @@ trap_uninstall()
local dev=$1; shift
local direction=$1; shift
 
-   tc filter del dev $dev $direction pref 1 flower skip_sw
+   tc filter del dev $dev $direction pref 1 flower
 }
 
 slow_path_trap_install()
 {
+   # For slow-path testing, we need to install a trap to get to
+   # slow path the packets that would otherwise be switched in HW.
if [ "${tcflags/skip_hw}" != "$tcflags" ]; then
trap_install "$@"
fi
-- 
2.4.11



[PATCH net-next 0/4] Fixes for running mirror-to-gretap tests on veth

2018-06-28 Thread Petr Machata
The forwarding selftests infrastructure makes it possible to run the
individual tests on a purely software netdevices. Names of interfaces to
run the test with can be passed as command line arguments to a test.
lib.sh then creates veth pairs backing the interfaces if none exist in
the system.

However, the tests need to recognize that they might be run on a soft
device. Many mirror-to-gretap tests are buggy in this regard. This patch
set aims to fix the problems in running mirror-to-gretap tests on veth
devices.

In patch #1, a service function is split out of setup_wait().
In patch #2, installing a trap is made optional.
In patch #3, tc filters in several tests are tweaked to work with veth.
In patch #4, the logic for waiting for neighbor is fixed for veth.

Petr Machata (4):
  selftests: forwarding: lib: Split out setup_wait_dev()
  selftests: forwarding: lib: Avoid trapping soft devices
  selftests: forwarding: Tweak tc filters for mirror-to-gretap tests
  selftests: forwarding: mirror_gre_changes: Fix waiting for neighbor

 tools/testing/selftests/net/forwarding/lib.sh  | 41 +++---
 .../net/forwarding/mirror_gre_bridge_1d_vlan.sh|  6 ++--
 .../selftests/net/forwarding/mirror_gre_changes.sh | 11 ++
 .../selftests/net/forwarding/mirror_gre_lib.sh |  2 +-
 .../net/forwarding/mirror_gre_vlan_bridge_1q.sh|  6 ++--
 5 files changed, 39 insertions(+), 27 deletions(-)

-- 
2.4.11



[PATCH net-next 1/4] selftests: forwarding: lib: Split out setup_wait_dev()

2018-06-28 Thread Petr Machata
Split out of setup_wait() a function setup_wait_dev() that waits for a
single device. This gives tests the opportunity to wait for a selected
device after they tinkered with its upness.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/lib.sh | 25 -
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 1dfdf14894e2..ac1df4860fbe 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -185,18 +185,25 @@ log_info()
echo "INFO: $msg"
 }
 
+setup_wait_dev()
+{
+   local dev=$1; shift
+
+   while true; do
+   ip link show dev $dev up \
+   | grep 'state UP' &> /dev/null
+   if [[ $? -ne 0 ]]; then
+   sleep 1
+   else
+   break
+   fi
+   done
+}
+
 setup_wait()
 {
for i in $(eval echo {1..$NUM_NETIFS}); do
-   while true; do
-   ip link show dev ${NETIFS[p$i]} up \
-   | grep 'state UP' &> /dev/null
-   if [[ $? -ne 0 ]]; then
-   sleep 1
-   else
-   break
-   fi
-   done
+   setup_wait_dev ${NETIFS[p$i]}
done
 
# Make sure links are ready.
-- 
2.4.11



[PATCH net-next 6/6] selftests: forwarding: README: Require diagrams

2018-06-25 Thread Petr Machata
ASCII art diagrams are well suited for presenting the topology that a
test uses while being easy to embed directly in the test file iteslf.
They make the information very easy to grasp even for simple topologies,
and for more complex ones they are almost essential, as figuring out the
interconnects from the script itself proves to be difficult.

Therefore state the requirement for topology ASCII art in README.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 tools/testing/selftests/net/forwarding/README | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/net/forwarding/README 
b/tools/testing/selftests/net/forwarding/README
index 4a0964c42860..b8a2af8fcfb7 100644
--- a/tools/testing/selftests/net/forwarding/README
+++ b/tools/testing/selftests/net/forwarding/README
@@ -46,6 +46,8 @@ Guidelines for Writing Tests
 
 o Where possible, reuse an existing topology for different tests instead
   of recreating the same topology.
+o Tests that use anything but the most trivial topologies should include
+  an ASCII art showing the topology.
 o Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
   RFC 5737, respectively.
 o Where possible, tests shall be written so that they can be reused by
-- 
2.4.11



[PATCH net-next 3/6] selftests: forwarding: tc_rule_stats_get: Parameterize direction

2018-06-25 Thread Petr Machata
The GRE multipath tests need stats on an egress counter. Change
tc_rule_stats_get() to take direction as an optional argument, with
default of ingress.

Take the opportunity to change line continuation character from | to \.
Move the | to the next line, which indent.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 tools/testing/selftests/net/forwarding/lib.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 911d753c4ff0..f94ea4bafa13 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -383,9 +383,10 @@ tc_rule_stats_get()
 {
local dev=$1; shift
local pref=$1; shift
+   local dir=$1; shift
 
-   tc -j -s filter show dev $dev ingress pref $pref |
-   jq '.[1].options.actions[].stats.packets'
+   tc -j -s filter show dev $dev ${dir:-ingress} pref $pref \
+   | jq '.[1].options.actions[].stats.packets'
 }
 
 mac_get()
-- 
2.4.11



[PATCH net-next 5/6] selftests: forwarding: Test multipath tunneling

2018-06-25 Thread Petr Machata
Add a GRE-tunneling test such that there are two tunnels involved, with
a multipath route listing both as next hops. Similarly to
router_multipath.sh, test that the distribution of traffic to the
tunnels honors the configured weights.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 .../selftests/net/forwarding/gre_multipath.sh  | 354 +
 1 file changed, 354 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/gre_multipath.sh

diff --git a/tools/testing/selftests/net/forwarding/gre_multipath.sh 
b/tools/testing/selftests/net/forwarding/gre_multipath.sh
new file mode 100755
index ..982cc8c23200
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/gre_multipath.sh
@@ -0,0 +1,354 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# Test traffic distribution when a wECMP route forwards traffic to two GRE
+# tunnels.
+#
+# +-+
+# | H1  |
+# |   $h1 + |
+# |  192.0.2.1/28 | |
+# |  2001:db8:1::1/64 | |
+# +---|-+
+# |
+# +---|+
+# | SW1   ||
+# |  $ol1 +|
+# |  192.0.2.2/28  |
+# |  2001:db8:1::2/64  |
+# ||
+# |  + g1a (gre)  + g1b (gre)  |
+# |loc=192.0.2.65   loc=192.0.2.81 |
+# |rem=192.0.2.66 --.   rem=192.0.2.82 --. |
+# |tos=inherit  |   tos=inherit  | |
+# |  .--'| |
+# |  |.--' |
+# |  vv|
+# |  + $ul1.111 (vlan)+ $ul1.222 (vlan)|
+# |  | 192.0.2.129/28 | 192.0.2.145/28 |
+# |   \  / |
+# |\/  |
+# ||   |
+# |+ $ul1  |
+# +|---+
+#  |
+# +|---+
+# | SW2+ $ul2  |
+# | ___|   |
+# |/\  |
+# |   /  \ |
+# |  + $ul2.111 (vlan)+ $ul2.222 (vlan)|
+# |  ^ 192.0.2.130/28 ^ 192.0.2.146/28 |
+# |  |||
+# |  |'--. |
+# |  '--.| |
+# |  + g2a (gre)| + g2b (gre)| |
+# |loc=192.0.2.66   |   loc=192.0.2.82   | |
+# |rem=192.0.2.65 --'   rem=192.0.2.81 --' |
+# |tos=inherit  tos=inherit|
+# ||
+# |  $ol2 +|
+# | 192.0.2.17/28 ||
+# |  2001:db8:2::1/64 ||
+# +---|+
+# |
+# +---|-+
+# | H2| |
+# |   $h2 + |
+# | 192.0.2.18/28   |
+# |  2001:db8:2::2/64   |
+# +-+
+
+ALL_TESTS="
+   ping_ipv4
+   ping_ipv6
+   multipath_ipv4
+   multipath_ipv6
+   multipath_ipv6_l4
+"
+
+NUM_NETIFS=6
+source lib.sh
+
+h1_create()
+{
+   simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
+   ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
+   ip route add vrf v$h1 2001:db8:2::/64 via 2001:db8:1::2
+}
+
+h1_destroy()
+{
+   ip route del vrf v$h1 2001:db8:2::/64 via 2001:db8:1::2
+   ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
+   simple_if_fini $h1 192.0.2.1/28
+}
+
+sw1_create()
+{
+   simple_if_init $ol1 192.0.2.2/28 2001:db8:1::2/64
+   __simple_if_init $ul1 v$ol1
+   vlan_create $ul1 111 v$ol1 192.0.2.129/28
+   vlan_create $ul1 222 v$ol1 192.0.2.145/28
+
+   tunnel_create g1a gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
+   __simple_if_init g1a v$ol1 192.0.2.65/32
+   ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
+
+   tunnel_create g1b gre 192.0.2.81 192.0.2.82 tos inherit dev v$ol1
+   __simple_if_init g1b v$ol1 192.0.2.81/32
+   ip route add vrf v$ol1 192.0.2.82/32 via 192.0.2.146
+
+   ip route add vrf v$ol1 192.0.2.16/28 \
+  nexthop dev g1a \
+  nexthop dev g1b
+   ip route add vrf v$ol1 2001:db8:2::/64 \
+  nexthop dev g1a \
+  nexthop dev g1b
+
+   tc qdisc add dev $ul1 clsact
+   tc filter add dev $ul1 egress pref 111 prot 802.1q \
+  flower vlan_id 111 action pass
+   tc filter add dev $ul1 egress pref 222 prot 802.1q \
+  flower vlan_id 222 action pass
+}
+
+sw1_destroy()
+{
+   tc qdisc del dev $ul1 clsact
+
+   ip route del vrf v$ol1 2001:db8:2::/64

[PATCH net-next 4/6] selftests: forwarding: lib: Extract interface-init functions

2018-06-25 Thread Petr Machata
The function simple_if_init() does two things: it creates a VRF, then
moves an interface into this VRF and configures addresses. The latter
comes in handy when adding more interfaces into a VRF later on. The
situation is similar for simple_if_fini().

Therefore split the interface remastering and address de/initialization
logic to a new pair of helpers __simple_if_init() / __simple_if_fini(),
and defer to these helpers from simple_if_init() and simple_if_fini().

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 tools/testing/selftests/net/forwarding/lib.sh | 32 +--
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index f94ea4bafa13..1dfdf14894e2 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -287,6 +287,29 @@ __addr_add_del()
done
 }
 
+__simple_if_init()
+{
+   local if_name=$1; shift
+   local vrf_name=$1; shift
+   local addrs=("${@}")
+
+   ip link set dev $if_name master $vrf_name
+   ip link set dev $if_name up
+
+   __addr_add_del $if_name add "${addrs[@]}"
+}
+
+__simple_if_fini()
+{
+   local if_name=$1; shift
+   local addrs=("${@}")
+
+   __addr_add_del $if_name del "${addrs[@]}"
+
+   ip link set dev $if_name down
+   ip link set dev $if_name nomaster
+}
+
 simple_if_init()
 {
local if_name=$1
@@ -298,11 +321,8 @@ simple_if_init()
array=("${@}")
 
vrf_create $vrf_name
-   ip link set dev $if_name master $vrf_name
ip link set dev $vrf_name up
-   ip link set dev $if_name up
-
-   __addr_add_del $if_name add "${array[@]}"
+   __simple_if_init $if_name $vrf_name "${array[@]}"
 }
 
 simple_if_fini()
@@ -315,9 +335,7 @@ simple_if_fini()
vrf_name=v$if_name
array=("${@}")
 
-   __addr_add_del $if_name del "${array[@]}"
-
-   ip link set dev $if_name down
+   __simple_if_fini $if_name "${array[@]}"
vrf_destroy $vrf_name
 }
 
-- 
2.4.11



[PATCH net-next 1/6] selftests: forwarding: Move multipath_eval() to lib.sh

2018-06-25 Thread Petr Machata
This function will be useful for the GRE multipath test that is coming
later.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 tools/testing/selftests/net/forwarding/lib.sh  | 39 ++
 .../selftests/net/forwarding/router_multipath.sh   | 39 --
 2 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 7b18a53aa556..7fae805147ae 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -557,6 +557,45 @@ tests_run()
done
 }
 
+multipath_eval()
+{
+   local desc="$1"
+   local weight_rp12=$2
+   local weight_rp13=$3
+   local packets_rp12=$4
+   local packets_rp13=$5
+   local weights_ratio packets_ratio diff
+
+   RET=0
+
+   if [[ "$packets_rp12" -eq "0" || "$packets_rp13" -eq "0" ]]; then
+  check_err 1 "Packet difference is 0"
+  log_test "Multipath"
+  log_info "Expected ratio $weights_ratio"
+  return
+   fi
+
+   if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
+   weights_ratio=$(echo "scale=2; $weight_rp12 / $weight_rp13" \
+  | bc -l)
+   packets_ratio=$(echo "scale=2; $packets_rp12 / $packets_rp13" \
+  | bc -l)
+   else
+   weights_ratio=$(echo "scale=2; $weight_rp13 / $weight_rp12" | \
+  bc -l)
+   packets_ratio=$(echo "scale=2; $packets_rp13 / $packets_rp12" | 
\
+  bc -l)
+   fi
+
+   diff=$(echo $weights_ratio - $packets_ratio | bc -l)
+   diff=${diff#-}
+
+   test "$(echo "$diff / $weights_ratio > 0.15" | bc -l)" -eq 0
+   check_err $? "Too large discrepancy between expected and measured 
ratios"
+   log_test "$desc"
+   log_info "Expected ratio $weights_ratio Measured ratio $packets_ratio"
+}
+
 ##
 # Tests
 
diff --git a/tools/testing/selftests/net/forwarding/router_multipath.sh 
b/tools/testing/selftests/net/forwarding/router_multipath.sh
index 8b6d0fb6d604..79a209927962 100755
--- a/tools/testing/selftests/net/forwarding/router_multipath.sh
+++ b/tools/testing/selftests/net/forwarding/router_multipath.sh
@@ -159,45 +159,6 @@ router2_destroy()
vrf_destroy "vrf-r2"
 }
 
-multipath_eval()
-{
-   local desc="$1"
-   local weight_rp12=$2
-   local weight_rp13=$3
-   local packets_rp12=$4
-   local packets_rp13=$5
-   local weights_ratio packets_ratio diff
-
-   RET=0
-
-   if [[ "$packets_rp12" -eq "0" || "$packets_rp13" -eq "0" ]]; then
-  check_err 1 "Packet difference is 0"
-  log_test "Multipath"
-  log_info "Expected ratio $weights_ratio"
-  return
-   fi
-
-   if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
-   weights_ratio=$(echo "scale=2; $weight_rp12 / $weight_rp13" \
-  | bc -l)
-   packets_ratio=$(echo "scale=2; $packets_rp12 / $packets_rp13" \
-  | bc -l)
-   else
-   weights_ratio=$(echo "scale=2; $weight_rp13 / $weight_rp12" | \
-  bc -l)
-   packets_ratio=$(echo "scale=2; $packets_rp13 / $packets_rp12" | 
\
-  bc -l)
-   fi
-
-   diff=$(echo $weights_ratio - $packets_ratio | bc -l)
-   diff=${diff#-}
-
-   test "$(echo "$diff / $weights_ratio > 0.15" | bc -l)" -eq 0
-   check_err $? "Too large discrepancy between expected and measured 
ratios"
-   log_test "$desc"
-   log_info "Expected ratio $weights_ratio Measured ratio $packets_ratio"
-}
-
 multipath4_test()
 {
local desc="$1"
-- 
2.4.11



[PATCH net-next 2/6] selftests: forwarding: multipath_eval(): Improve style

2018-06-25 Thread Petr Machata
- Change the indentation of the function body from 7 spaces to one tab.
- Move initialization of weights_ratio up so that it can be referenced
  from the error message about packet difference being zero.
- Move |'s consistently to continuation line, which reindent.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 tools/testing/selftests/net/forwarding/lib.sh | 74 ++-
 1 file changed, 39 insertions(+), 35 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 7fae805147ae..911d753c4ff0 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -559,41 +559,45 @@ tests_run()
 
 multipath_eval()
 {
-   local desc="$1"
-   local weight_rp12=$2
-   local weight_rp13=$3
-   local packets_rp12=$4
-   local packets_rp13=$5
-   local weights_ratio packets_ratio diff
-
-   RET=0
-
-   if [[ "$packets_rp12" -eq "0" || "$packets_rp13" -eq "0" ]]; then
-  check_err 1 "Packet difference is 0"
-  log_test "Multipath"
-  log_info "Expected ratio $weights_ratio"
-  return
-   fi
-
-   if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
-   weights_ratio=$(echo "scale=2; $weight_rp12 / $weight_rp13" \
-  | bc -l)
-   packets_ratio=$(echo "scale=2; $packets_rp12 / $packets_rp13" \
-  | bc -l)
-   else
-   weights_ratio=$(echo "scale=2; $weight_rp13 / $weight_rp12" | \
-  bc -l)
-   packets_ratio=$(echo "scale=2; $packets_rp13 / $packets_rp12" | 
\
-  bc -l)
-   fi
-
-   diff=$(echo $weights_ratio - $packets_ratio | bc -l)
-   diff=${diff#-}
-
-   test "$(echo "$diff / $weights_ratio > 0.15" | bc -l)" -eq 0
-   check_err $? "Too large discrepancy between expected and measured 
ratios"
-   log_test "$desc"
-   log_info "Expected ratio $weights_ratio Measured ratio $packets_ratio"
+   local desc="$1"
+   local weight_rp12=$2
+   local weight_rp13=$3
+   local packets_rp12=$4
+   local packets_rp13=$5
+   local weights_ratio packets_ratio diff
+
+   RET=0
+
+   if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
+   weights_ratio=$(echo "scale=2; $weight_rp12 / $weight_rp13" \
+   | bc -l)
+   else
+   weights_ratio=$(echo "scale=2; $weight_rp13 / $weight_rp12" \
+   | bc -l)
+   fi
+
+   if [[ "$packets_rp12" -eq "0" || "$packets_rp13" -eq "0" ]]; then
+  check_err 1 "Packet difference is 0"
+  log_test "Multipath"
+  log_info "Expected ratio $weights_ratio"
+  return
+   fi
+
+   if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
+   packets_ratio=$(echo "scale=2; $packets_rp12 / $packets_rp13" \
+   | bc -l)
+   else
+   packets_ratio=$(echo "scale=2; $packets_rp13 / $packets_rp12" \
+   | bc -l)
+   fi
+
+   diff=$(echo $weights_ratio - $packets_ratio | bc -l)
+   diff=${diff#-}
+
+   test "$(echo "$diff / $weights_ratio > 0.15" | bc -l)" -eq 0
+   check_err $? "Too large discrepancy between expected and measured 
ratios"
+   log_test "$desc"
+   log_info "Expected ratio $weights_ratio Measured ratio $packets_ratio"
 }
 
 ##
-- 
2.4.11



[PATCH net-next 0/6] Multipath tests for tunnel devices

2018-06-25 Thread Petr Machata
This patchset adds a test for ECMP and weighted ECMP between two GRE
tunnels.

In patches #1 and #2, the function multipath_eval() is first moved from
router_multipath.sh to lib.sh for ease of reuse, and then fixed up.

In patch #3, the function tc_rule_stats_get() is parameterized to be
useful for egress rules as well.

In patch #4, a new function __simple_if_init() is extracted from
simple_if_init(). This covers the logic that needs to be done for the
usual interface: VRF migration, upping and installation of IP addresses.

Patch #5 then adds the test itself.

Additionally in patch #6, a requirement to add diagrams to selftests is
documented.

Petr Machata (6):
  selftests: forwarding: Move multipath_eval() to lib.sh
  selftests: forwarding: multipath_eval(): Improve style
  selftests: forwarding: tc_rule_stats_get: Parameterize direction
  selftests: forwarding: lib: Extract interface-init functions
  selftests: forwarding: Test multipath tunneling
  selftests: forwarding: README: Require diagrams

 tools/testing/selftests/net/forwarding/README  |   2 +
 .../selftests/net/forwarding/gre_multipath.sh  | 354 +
 tools/testing/selftests/net/forwarding/lib.sh  |  80 -
 .../selftests/net/forwarding/router_multipath.sh   |  39 ---
 4 files changed, 427 insertions(+), 48 deletions(-)
 create mode 100755 tools/testing/selftests/net/forwarding/gre_multipath.sh

-- 
2.4.11



[PATCH net-next] selftests: forwarding: mirror_gre_vlan_bridge_1q: Unset rp_filter

2018-06-25 Thread Petr Machata
The IP addresses of tunnel endpoint at H3 are set at the VLAN device
$h3.555. Therefore when test_gretap_untagged_egress() sets vlan 555 to
egress untagged at $swp3, $h3's rp_filter rejects these packets. The
test then spuriously fails.

Therefore turn off net.ipv4.conf.{all, $h3}.rp_filter.

Fixes: 9c7c8a82442c ("selftests: forwarding: mirror_gre_vlan_bridge_1q: Add 
more tests")
Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 .../selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh| 9 +
 1 file changed, 9 insertions(+)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
index 5dbc7a08f4bd..1ac5038ae256 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
@@ -39,6 +39,12 @@ setup_prepare()
swp3=${NETIFS[p5]}
h3=${NETIFS[p6]}
 
+   # gt4's remote address is at $h3.555, not $h3. Thus the packets arriving
+   # directly to $h3 for test_gretap_untagged_egress() are rejected by
+   # rp_filter and the test spuriously fails.
+   sysctl_set net.ipv4.conf.all.rp_filter 0
+   sysctl_set net.ipv4.conf.$h3.rp_filter 0
+
vrf_prepare
mirror_gre_topo_create
 
@@ -65,6 +71,9 @@ cleanup()
 
mirror_gre_topo_destroy
vrf_cleanup
+
+   sysctl_restore net.ipv4.conf.$h3.rp_filter
+   sysctl_restore net.ipv4.conf.all.rp_filter
 }
 
 test_vlan_match()
-- 
2.4.11



[PATCH net-next v2] selftests: net: Test headroom handling of ip6_gre devices

2018-06-25 Thread Petr Machata
Commit 5691484df961 ("net: ip6_gre: Fix headroom request in
ip6erspan_tunnel_xmit()") and commit 01b8d064d58b ("net: ip6_gre:
Request headroom in __gre6_xmit()") fix problems in reserving headroom
in the packets tunneled through ip6gre/tap and ip6erspan netdevices.

These two patches included snippets that reproduced the issues. This
patch elevates the snippets to a full-fledged test case.

Suggested-by: David Miller 
Signed-off-by: Petr Machata 
---

Notes:
Changes between v1 and v2:

- Move tunnel construction to setup() and destruction to cleanup().

 tools/testing/selftests/net/ip6_gre_headroom.sh | 65 +
 1 file changed, 65 insertions(+)
 create mode 100755 tools/testing/selftests/net/ip6_gre_headroom.sh

diff --git a/tools/testing/selftests/net/ip6_gre_headroom.sh 
b/tools/testing/selftests/net/ip6_gre_headroom.sh
new file mode 100755
index ..5b41e8bb6e2d
--- /dev/null
+++ b/tools/testing/selftests/net/ip6_gre_headroom.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Test that enough headroom is reserved for the first packet passing through an
+# IPv6 GRE-like netdevice.
+
+setup_prepare()
+{
+   ip link add h1 type veth peer name swp1
+   ip link add h3 type veth peer name swp3
+
+   ip link set dev h1 up
+   ip address add 192.0.2.1/28 dev h1
+
+   ip link add dev vh3 type vrf table 20
+   ip link set dev h3 master vh3
+   ip link set dev vh3 up
+   ip link set dev h3 up
+
+   ip link set dev swp3 up
+   ip address add dev swp3 2001:db8:2::1/64
+   ip address add dev swp3 2001:db8:2::3/64
+
+   ip link set dev swp1 up
+   tc qdisc add dev swp1 clsact
+
+   ip link add name er6 type ip6erspan \
+  local 2001:db8:2::1 remote 2001:db8:2::2 oseq okey 123
+   ip link set dev er6 up
+
+   ip link add name gt6 type ip6gretap \
+  local 2001:db8:2::3 remote 2001:db8:2::4
+   ip link set dev gt6 up
+
+   sleep 1
+}
+
+cleanup()
+{
+   ip link del dev gt6
+   ip link del dev er6
+   ip link del dev swp1
+   ip link del dev swp3
+   ip link del dev vh3
+}
+
+test_headroom()
+{
+   local type=$1; shift
+   local tundev=$1; shift
+
+   tc filter add dev swp1 ingress pref 1000 matchall skip_hw \
+   action mirred egress mirror dev $tundev
+   ping -I h1 192.0.2.2 -c 1 -w 2 &> /dev/null
+   tc filter del dev swp1 ingress pref 1000
+
+   # If it doesn't panic, it passes.
+   printf "TEST: %-60s  [PASS]\n" "$type headroom"
+}
+
+trap cleanup EXIT
+
+setup_prepare
+test_headroom ip6gretap gt6
+test_headroom ip6erspan er6
-- 
2.4.11



[Bridge] [PATCH net v2] net: bridge: Fix locking in br_fdb_find_port()

2018-06-08 Thread Petr Machata
Callers of br_fdb_find() need to hold the hash lock, which
br_fdb_find_port() doesn't do. However, since br_fdb_find_port() is not
doing any actual FDB manipulation, the hash lock is not really needed at
all. So convert to br_fdb_find_rcu(), surrounded by rcu_read_lock() /
_unlock() pair.

The device pointer copied from inside the FDB entry is then kept alive
by the RTNL lock, which br_fdb_find_port() asserts.

Fixes: 4d4fd36126d6 ("net: bridge: Publish bridge accessor functions")
Signed-off-by: Petr Machata 
---

Notes:
Changes from v1 to v2:

- Instead of taking hash lock, take RCU lock and call br_fdb_find_rcu().

 net/bridge/br_fdb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index b19e310..502f663 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -135,9 +135,11 @@ struct net_device *br_fdb_find_port(const struct 
net_device *br_dev,
return NULL;
 
br = netdev_priv(br_dev);
-   f = br_fdb_find(br, addr, vid);
+   rcu_read_lock();
+   f = br_fdb_find_rcu(br, addr, vid);
if (f && f->dst)
dev = f->dst->dev;
+   rcu_read_unlock();
 
return dev;
 }
-- 
2.4.11



Re: [PATCH net-next] selftests: forwarding: Fix importing dependent libraries

2018-06-05 Thread Petr Machata
Petr Machata  writes:

> When libraries are sourced from elsewhere from the tree, such as the
> testing/selftests/drivers/net/mlxsw subdirectory, sourcing their own

Sorry, I didn't realize the mirror_bridge.sh is not upstream yet. This
patch is thus immaterial, it will be sent together with the test when it
becomes relevant.

Please ignore.

Thanks,
Petr


[PATCH net-next] selftests: forwarding: Fix importing dependent libraries

2018-06-05 Thread Petr Machata
When libraries are sourced from elsewhere from the tree, such as the
testing/selftests/drivers/net/mlxsw subdirectory, sourcing their own
dependencies directly by name doesn't work. Thus running mirror_gre.sh
from that subdirectory results in the following cascade of errors:

./../../../net/forwarding/mirror_gre_lib.sh: line 3: mirror_lib.sh: No such 
file or directory
./../../../net/forwarding/mirror_gre_topo_lib.sh: line 36: mirror_topo_lib.sh: 
No such file or directory
./../../../net/forwarding/mirror_gre_topo_lib.sh: line 80: 
mirror_topo_h1_create: command not found
./../../../net/forwarding/mirror_gre_topo_lib.sh: line 81: 
mirror_topo_h2_create: command not found
./../../../net/forwarding/mirror_gre_topo_lib.sh: line 40: 
mirror_topo_h3_create: command not found
[...]

Fix by relying on $relative_path, set up by lib.sh, which should be
imported by the test in question anyway, and source the file using
relative path appropriate for the subdirectory.

Fixes: d5ea2bfc806a ("selftests: forwarding: mirror_gre_lib: Extract generic 
functions")
Fixes: 74ed089d48a4 ("selftests: forwarding: Split mirror_gre_topo_lib.sh")
Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_gre_lib.sh  | 2 +-
 tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
index 619b469..1388845 100644
--- a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
-source mirror_lib.sh
+source "$relative_path/mirror_lib.sh"
 
 quick_test_span_gre_dir_ips()
 {
diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh
index 2534195..39c03e2 100644
--- a/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh
@@ -33,7 +33,7 @@
 #   | |
 #   +-+
 
-source mirror_topo_lib.sh
+source "$relative_path/mirror_topo_lib.sh"
 
 mirror_gre_topo_h3_create()
 {
-- 
2.4.11



[PATCH net-next 2/2] selftests: forwarding: mirror_vlan: Change test description

2018-05-31 Thread Petr Machata
The test description is displayed with the PASS/FAIL resolution after
the test is ran. There however already is one other test described
exactly like this, which makes it unclear which of the tests passed or
failed. Make the description unique.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_vlan.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/forwarding/mirror_vlan.sh 
b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
index c22e949..efade19 100755
--- a/tools/testing/selftests/net/forwarding/mirror_vlan.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
@@ -129,7 +129,7 @@ test_tagged_vlan_dir()
  192.0.2.17 192.0.2.18
mirror_uninstall $swp1 $direction
 
-   log_test "$direction mirror to vlan ($tcflags)"
+   log_test "$direction mirror tagged to vlan ($tcflags)"
 }
 
 test_tagged_vlan()
-- 
2.4.11



[PATCH net-next 0/2] selftests: forwarding: mirror_vlan: Fixlets

2018-05-31 Thread Petr Machata
This patchset includes two small fixes for the tests that were
introduced in commit 1bb58d2d3cbe ("Merge branch
'Mirroring-tests-involving-VLAN'").

In patch #1, a "tc action trap" is uninstalled after the suite runs,
instead of being installed again.

In patch #2, a test in suite is renamed to differentiate it from another
test of the same name.

Petr Machata (2):
  selftests: forwarding: mirror_vlan: Uninstall trap
  selftests: forwarding: mirror_vlan: Change test description

 tools/testing/selftests/net/forwarding/mirror_vlan.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.4.11



[PATCH net-next 1/2] selftests: forwarding: mirror_vlan: Uninstall trap

2018-05-31 Thread Petr Machata
Instead of installing a trap before tests run and uninstalling it after
they run, mirror_vlan.sh installs it twice due to a typo. Fix the typo.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_vlan.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/forwarding/mirror_vlan.sh 
b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
index 1e10520..c22e949 100755
--- a/tools/testing/selftests/net/forwarding/mirror_vlan.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
@@ -146,7 +146,7 @@ test_all()
 
tests_run
 
-   trap_install $h3 ingress
+   trap_uninstall $h3 ingress
slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
 }
-- 
2.4.11



[PATCH net-next 9/9] selftests: forwarding: mirror_gre_bridge_1d_vlan: Add STP test

2018-05-31 Thread Petr Machata
To test offloading of mirror-to-gretap in mlxsw for cases that a
VLAN-unaware bridge is in underlay packet path, test that the STP status
of bridge egress port is reflected.

Signed-off-by: Petr Machata 
---
 .../selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh| 12 
 1 file changed, 12 insertions(+)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh
index 3d47afc..3bb4c2b 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d_vlan.sh
@@ -11,6 +11,8 @@
 ALL_TESTS="
test_gretap
test_ip6gretap
+   test_gretap_stp
+   test_ip6gretap_stp
 "
 
 NUM_NETIFS=6
@@ -80,6 +82,16 @@ test_ip6gretap()
test_vlan_match gt6 'vlan_id 555 vlan_ethtype ipv6' "mirror to 
ip6gretap"
 }
 
+test_gretap_stp()
+{
+   full_test_span_gre_stp gt4 $swp3.555 "mirror to gretap"
+}
+
+test_ip6gretap_stp()
+{
+   full_test_span_gre_stp gt6 $swp3.555 "mirror to ip6gretap"
+}
+
 test_all()
 {
slow_path_trap_install $swp1 ingress
-- 
2.4.11



[PATCH net-next 8/9] selftests: forwarding: mirror_gre_vlan_bridge_1q: Add more tests

2018-05-31 Thread Petr Machata
Offloading of mirror-to-gretap in mlxsw is tricky especially in cases
when the gretap underlay involves bridges. Add more tests that exercise
the bridge handling code:

- forbidden_egress tests that check vlan removal on bridge port in the
  underlay packet path
- untagged_egress tests that similarly check "egress untagged"
- fdb_roaming tests that check whether learning FDB on a different port
  is reflected
- stp tests for handling port STP status of bridge egress port

Signed-off-by: Petr Machata 
---
 .../net/forwarding/mirror_gre_vlan_bridge_1q.sh| 129 +
 1 file changed, 129 insertions(+)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
index d91b347..5dbc7a0 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
@@ -12,6 +12,14 @@ ALL_TESTS="
test_ip6gretap
test_gretap_forbidden_cpu
test_ip6gretap_forbidden_cpu
+   test_gretap_forbidden_egress
+   test_ip6gretap_forbidden_egress
+   test_gretap_untagged_egress
+   test_ip6gretap_untagged_egress
+   test_gretap_fdb_roaming
+   test_ip6gretap_fdb_roaming
+   test_gretap_stp
+   test_ip6gretap_stp
 "
 
 NUM_NETIFS=6
@@ -43,12 +51,14 @@ setup_prepare()
 
ip link set dev $swp3 master br1
bridge vlan add dev $swp3 vid 555
+   bridge vlan add dev $swp2 vid 555
 }
 
 cleanup()
 {
pre_cleanup
 
+   ip link set dev $swp2 nomaster
ip link set dev $swp3 nomaster
vlan_destroy $h3 555
vlan_destroy br1 555
@@ -112,6 +122,125 @@ test_ip6gretap_forbidden_cpu()
test_span_gre_forbidden_cpu gt6 "mirror to ip6gretap"
 }
 
+test_span_gre_forbidden_egress()
+{
+   local tundev=$1; shift
+   local what=$1; shift
+
+   RET=0
+
+   mirror_install $swp1 ingress $tundev "matchall $tcflags"
+   quick_test_span_gre_dir $tundev ingress
+
+   bridge vlan del dev $swp3 vid 555
+   sleep 1
+   fail_test_span_gre_dir $tundev ingress
+
+   bridge vlan add dev $swp3 vid 555
+   # Re-prime FDB
+   arping -I br1.555 192.0.2.130 -fqc 1
+   sleep 1
+   quick_test_span_gre_dir $tundev ingress
+
+   mirror_uninstall $swp1 ingress
+
+   log_test "$what: vlan forbidden at a bridge egress ($tcflags)"
+}
+
+test_gretap_forbidden_egress()
+{
+   test_span_gre_forbidden_egress gt4 "mirror to gretap"
+}
+
+test_ip6gretap_forbidden_egress()
+{
+   test_span_gre_forbidden_egress gt6 "mirror to ip6gretap"
+}
+
+test_span_gre_untagged_egress()
+{
+   local tundev=$1; shift
+   local what=$1; shift
+
+   RET=0
+
+   mirror_install $swp1 ingress $tundev "matchall $tcflags"
+
+   quick_test_span_gre_dir $tundev ingress
+   quick_test_span_vlan_dir $h3 555 ingress
+
+   bridge vlan add dev $swp3 vid 555 pvid untagged
+   sleep 1
+   quick_test_span_gre_dir $tundev ingress
+   fail_test_span_vlan_dir $h3 555 ingress
+
+   bridge vlan add dev $swp3 vid 555
+   sleep 1
+   quick_test_span_gre_dir $tundev ingress
+   quick_test_span_vlan_dir $h3 555 ingress
+
+   mirror_uninstall $swp1 ingress
+
+   log_test "$what: vlan untagged at a bridge egress ($tcflags)"
+}
+
+test_gretap_untagged_egress()
+{
+   test_span_gre_untagged_egress gt4 "mirror to gretap"
+}
+
+test_ip6gretap_untagged_egress()
+{
+   test_span_gre_untagged_egress gt6 "mirror to ip6gretap"
+}
+
+test_span_gre_fdb_roaming()
+{
+   local tundev=$1; shift
+   local what=$1; shift
+   local h3mac=$(mac_get $h3)
+
+   RET=0
+
+   mirror_install $swp1 ingress $tundev "matchall $tcflags"
+   quick_test_span_gre_dir $tundev ingress
+
+   bridge fdb del dev $swp3 $h3mac vlan 555 master
+   bridge fdb add dev $swp2 $h3mac vlan 555 master
+   sleep 1
+   fail_test_span_gre_dir $tundev ingress
+
+   bridge fdb del dev $swp2 $h3mac vlan 555 master
+   # Re-prime FDB
+   arping -I br1.555 192.0.2.130 -fqc 1
+   sleep 1
+   quick_test_span_gre_dir $tundev ingress
+
+   mirror_uninstall $swp1 ingress
+
+   log_test "$what: MAC roaming ($tcflags)"
+}
+
+test_gretap_fdb_roaming()
+{
+   test_span_gre_fdb_roaming gt4 "mirror to gretap"
+}
+
+test_ip6gretap_fdb_roaming()
+{
+   test_span_gre_fdb_roaming gt6 "mirror to ip6gretap"
+}
+
+test_gretap_stp()
+{
+   full_test_span_gre_stp gt4 $swp3 "mirror to gretap"
+}
+
+test_ip6gretap_stp()
+{
+   full_test_span_gre_stp gt6 $swp3 "mirror to ip6gretap"
+}
+
 test_all()
 {
slow_path_trap_install $swp1 ingress
-- 
2.4.11



[PATCH net-next 7/9] selftests: forwarding: mirror_gre_vlan_bridge_1q: Rename two tests

2018-05-31 Thread Petr Machata
Rename test_gretap_forbidden() and test_ip6gretap_forbidden() to a more
specific test_gretap_forbidden_cpu() and test_ip6gretap_forbidden_cpu().
This will make it clearer which is which when further down a patch is
introduced that forbids a VLAN on regular bridge port.

Signed-off-by: Petr Machata 
---
 .../selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh  | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
index 0a3bac9..d91b347 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
@@ -10,8 +10,8 @@
 ALL_TESTS="
test_gretap
test_ip6gretap
-   test_gretap_forbidden
-   test_ip6gretap_forbidden
+   test_gretap_forbidden_cpu
+   test_ip6gretap_forbidden_cpu
 "
 
 NUM_NETIFS=6
@@ -77,7 +77,7 @@ test_ip6gretap()
test_vlan_match gt6 'vlan_id 555 vlan_ethtype ipv6' "mirror to 
ip6gretap"
 }
 
-test_span_gre_forbidden()
+test_span_gre_forbidden_cpu()
 {
local tundev=$1; shift
local what=$1; shift
@@ -102,14 +102,14 @@ test_span_gre_forbidden()
log_test "$what: vlan forbidden at a bridge ($tcflags)"
 }
 
-test_gretap_forbidden()
+test_gretap_forbidden_cpu()
 {
-   test_span_gre_forbidden gt4 "mirror to gretap"
+   test_span_gre_forbidden_cpu gt4 "mirror to gretap"
 }
 
-test_ip6gretap_forbidden()
+test_ip6gretap_forbidden_cpu()
 {
-   test_span_gre_forbidden gt6 "mirror to ip6gretap"
+   test_span_gre_forbidden_cpu gt6 "mirror to ip6gretap"
 }
 
 test_all()
-- 
2.4.11



[PATCH net-next 6/9] selftests: forwarding: mirror_gre_vlan_bridge_1q: Test final config

2018-05-31 Thread Petr Machata
After the final change reestablishes the original configuration, make
sure the traffic flows again as it should.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
index 29fde73..0a3bac9 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
@@ -91,12 +91,13 @@ test_span_gre_forbidden()
# Now forbid the VLAN at the bridge and see it fail.
bridge vlan del dev br1 vid 555 self
sleep 1
-
fail_test_span_gre_dir $tundev ingress
-   mirror_uninstall $swp1 ingress
 
bridge vlan add dev br1 vid 555 self
sleep 1
+   quick_test_span_gre_dir $tundev ingress
+
+   mirror_uninstall $swp1 ingress
 
log_test "$what: vlan forbidden at a bridge ($tcflags)"
 }
-- 
2.4.11



[PATCH net-next 5/9] selftests: forwarding: mirror_gre_vlan_bridge_1q: Fix tunnel name

2018-05-31 Thread Petr Machata
The "ip6gretap" in the test name refers to the tunnel device type that
the test is supposed to be testing. However test_ip6gretap_forbidden()
tests, due to a typo, a gretap tunnel. Fix the typo.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
index 01ec28a..29fde73 100755
--- a/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_vlan_bridge_1q.sh
@@ -108,7 +108,7 @@ test_gretap_forbidden()
 
 test_ip6gretap_forbidden()
 {
-   test_span_gre_forbidden gt4 "mirror to ip6gretap"
+   test_span_gre_forbidden gt6 "mirror to ip6gretap"
 }
 
 test_all()
-- 
2.4.11



[PATCH net-next 0/9] Test mirror-to-gretap with bridge in UL

2018-05-31 Thread Petr Machata
This patchset adds more tests to the mirror-to-gretap suite where bridge
is present in the underlay. Specifically it adds tests for bridge VLAN
handling, FDB, and bridge port STP status.

In patches #1-#3, the codebase is refactored to support the new tests.

In patch #4, an STP test is added to the mirroring library, that will
later be called from bridge tests.

In patches #5-#8, the test for mirror-to-gretap with an 802.1q bridge in
underlay is adapted and more tests are added.

In patch #9, an STP test is added to the test suite for mirror-to-gretap
with an 802.1d bridge in underlay.

Petr Machata (9):
  selftests: forwarding: lib: Move here vlan_capture_{,un}install()
  selftests: forwarding: mirror_lib: Move here
do_test_span_vlan_dir_ips()
  selftests: forwarding: mirror_lib: skip_hw the VLAN capture
  selftests: forwarding: mirror_gre_lib: Add STP test
  selftests: forwarding: mirror_gre_vlan_bridge_1q: Fix tunnel name
  selftests: forwarding: mirror_gre_vlan_bridge_1q: Test final config
  selftests: forwarding: mirror_gre_vlan_bridge_1q: Rename two tests
  selftests: forwarding: mirror_gre_vlan_bridge_1q: Add more tests
  selftests: forwarding: mirror_gre_bridge_1d_vlan: Add STP test

 tools/testing/selftests/net/forwarding/lib.sh  |  23 
 .../net/forwarding/mirror_gre_bridge_1d_vlan.sh|  12 ++
 .../selftests/net/forwarding/mirror_gre_lib.sh |  32 +
 .../net/forwarding/mirror_gre_vlan_bridge_1q.sh| 148 +++--
 .../testing/selftests/net/forwarding/mirror_lib.sh |  38 ++
 .../selftests/net/forwarding/mirror_vlan.sh|  38 --
 6 files changed, 244 insertions(+), 47 deletions(-)

-- 
2.4.11



[PATCH net-next 4/9] selftests: forwarding: mirror_gre_lib: Add STP test

2018-05-31 Thread Petr Machata
Add a reusable full test that toggles STP state of a given bridge port
and checks that the mirroring reacts appropriately. The test will be
used by bridge tests in follow-up patches.

Signed-off-by: Petr Machata 
---
 .../selftests/net/forwarding/mirror_gre_lib.sh | 32 ++
 1 file changed, 32 insertions(+)

diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh 
b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
index 92ef6dd..619b469 100644
--- a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
@@ -96,3 +96,35 @@ full_test_span_gre_dir_vlan()
 {
full_test_span_gre_dir_vlan_ips "$@" 192.0.2.1 192.0.2.2
 }
+
+full_test_span_gre_stp_ips()
+{
+   local tundev=$1; shift
+   local nbpdev=$1; shift
+   local what=$1; shift
+   local ip1=$1; shift
+   local ip2=$1; shift
+   local h3mac=$(mac_get $h3)
+
+   RET=0
+
+   mirror_install $swp1 ingress $tundev "matchall $tcflags"
+   quick_test_span_gre_dir_ips $tundev ingress $ip1 $ip2
+
+   bridge link set dev $nbpdev state disabled
+   sleep 1
+   fail_test_span_gre_dir_ips $tundev ingress $ip1 $ip2
+
+   bridge link set dev $nbpdev state forwarding
+   sleep 1
+   quick_test_span_gre_dir_ips $tundev ingress $ip1 $ip2
+
+   mirror_uninstall $swp1 ingress
+
+   log_test "$what: STP state ($tcflags)"
+}
+
+full_test_span_gre_stp()
+{
+   full_test_span_gre_stp_ips "$@" 192.0.2.1 192.0.2.2
+}
-- 
2.4.11



[PATCH net-next 3/9] selftests: forwarding: mirror_lib: skip_hw the VLAN capture

2018-05-31 Thread Petr Machata
When the VLAN capture is installed on a front panel device and not a
soft device, the packets are counted twice: once in fast path, and once
after they are trapped to the kernel. Resolve the problem by passing
skip_hw flag to vlan_capture_install().

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/mirror_lib.sh | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/forwarding/mirror_lib.sh 
b/tools/testing/selftests/net/forwarding/mirror_lib.sh
index 67efe25..d36dc26 100644
--- a/tools/testing/selftests/net/forwarding/mirror_lib.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_lib.sh
@@ -102,7 +102,10 @@ do_test_span_vlan_dir_ips()
local ip1=$1; shift
local ip2=$1; shift
 
-   vlan_capture_install $dev "vlan_id $vid"
+   # Install the capture as skip_hw to avoid double-counting of packets.
+   # The traffic is meant for local box anyway, so will be trapped to
+   # kernel.
+   vlan_capture_install $dev "skip_hw vlan_id $vid"
mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
vlan_capture_uninstall $dev
-- 
2.4.11



[PATCH net-next 2/9] selftests: forwarding: mirror_lib: Move here do_test_span_vlan_dir_ips()

2018-05-31 Thread Petr Machata
Move the function do_test_span_vlan_dir_ips() from mirror_vlan.sh test
to a library file mirror_lib.sh to allow reuse. Fill in other entry
points similar to other testing functions in mirror_lib.sh, they will be
useful in following patches.

Signed-off-by: Petr Machata 
---
 .../testing/selftests/net/forwarding/mirror_lib.sh | 35 ++
 .../selftests/net/forwarding/mirror_vlan.sh| 15 --
 2 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/mirror_lib.sh 
b/tools/testing/selftests/net/forwarding/mirror_lib.sh
index 04cbc38..67efe25 100644
--- a/tools/testing/selftests/net/forwarding/mirror_lib.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_lib.sh
@@ -92,3 +92,38 @@ test_span_dir()
 {
test_span_dir_ips "$@" 192.0.2.1 192.0.2.2
 }
+
+do_test_span_vlan_dir_ips()
+{
+   local expect=$1; shift
+   local dev=$1; shift
+   local vid=$1; shift
+   local direction=$1; shift
+   local ip1=$1; shift
+   local ip2=$1; shift
+
+   vlan_capture_install $dev "vlan_id $vid"
+   mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
+   mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
+   vlan_capture_uninstall $dev
+}
+
+quick_test_span_vlan_dir_ips()
+{
+   do_test_span_vlan_dir_ips 10 "$@"
+}
+
+fail_test_span_vlan_dir_ips()
+{
+   do_test_span_vlan_dir_ips 0 "$@"
+}
+
+quick_test_span_vlan_dir()
+{
+   quick_test_span_vlan_dir_ips "$@" 192.0.2.1 192.0.2.2
+}
+
+fail_test_span_vlan_dir()
+{
+   fail_test_span_vlan_dir_ips "$@" 192.0.2.1 192.0.2.2
+}
diff --git a/tools/testing/selftests/net/forwarding/mirror_vlan.sh 
b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
index 758b6d0..20b37a5 100755
--- a/tools/testing/selftests/net/forwarding/mirror_vlan.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
@@ -76,21 +76,6 @@ test_vlan()
test_vlan_dir egress 0 8
 }
 
-do_test_span_vlan_dir_ips()
-{
-   local expect=$1; shift
-   local dev=$1; shift
-   local vid=$1; shift
-   local direction=$1; shift
-   local ip1=$1; shift
-   local ip2=$1; shift
-
-   vlan_capture_install $dev "vlan_id $vid"
-   mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
-   mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
-   vlan_capture_uninstall $dev
-}
-
 test_tagged_vlan_dir()
 {
local direction=$1; shift
-- 
2.4.11



[PATCH net-next 1/9] selftests: forwarding: lib: Move here vlan_capture_{,un}install()

2018-05-31 Thread Petr Machata
Move vlan_capture_install() and vlan_capture_uninstall() from
mirror_vlan.sh test to lib.sh so that it can be reused in other tests.

Signed-off-by: Petr Machata 
---
 tools/testing/selftests/net/forwarding/lib.sh  | 23 ++
 .../selftests/net/forwarding/mirror_vlan.sh| 23 --
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh 
b/tools/testing/selftests/net/forwarding/lib.sh
index 89ba4cd..7b18a53 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -514,6 +514,29 @@ icmp6_capture_uninstall()
__icmp_capture_add_del del 100 v6 "$@"
 }
 
+__vlan_capture_add_del()
+{
+   local add_del=$1; shift
+   local pref=$1; shift
+   local dev=$1; shift
+   local filter=$1; shift
+
+   tc filter $add_del dev "$dev" ingress \
+  proto 802.1q pref $pref \
+  flower $filter \
+  action pass
+}
+
+vlan_capture_install()
+{
+   __vlan_capture_add_del add 100 "$@"
+}
+
+vlan_capture_uninstall()
+{
+   __vlan_capture_add_del del 100 "$@"
+}
+
 matchall_sink_create()
 {
local dev=$1; shift
diff --git a/tools/testing/selftests/net/forwarding/mirror_vlan.sh 
b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
index 1e10520..758b6d0 100755
--- a/tools/testing/selftests/net/forwarding/mirror_vlan.sh
+++ b/tools/testing/selftests/net/forwarding/mirror_vlan.sh
@@ -76,29 +76,6 @@ test_vlan()
test_vlan_dir egress 0 8
 }
 
-vlan_capture_add_del()
-{
-   local add_del=$1; shift
-   local pref=$1; shift
-   local dev=$1; shift
-   local filter=$1; shift
-
-   tc filter $add_del dev "$dev" ingress \
-  proto 802.1q pref $pref \
-  flower $filter \
-  action pass
-}
-
-vlan_capture_install()
-{
-   vlan_capture_add_del add 100 "$@"
-}
-
-vlan_capture_uninstall()
-{
-   vlan_capture_add_del del 100 "$@"
-}
-
 do_test_span_vlan_dir_ips()
 {
local expect=$1; shift
-- 
2.4.11



Re: [Bridge] [PATCH net-next] net: bridge: Lock before br_fdb_find()

2018-05-30 Thread Petr Machata
David Miller  writes:

> From: Petr Machata 
> Date: Mon, 28 May 2018 17:44:16 +0200
>
>> Callers of br_fdb_find() need to hold the hash lock, which
>> br_fdb_find_port() doesn't do. Add the missing lock/unlock
>> pair.
>> 
>> Signed-off-by: Petr Machata 
>
> If all of the these uses of br_fdb_find_port() are safe, then it
> should use the RCU fdb lookup variant.
>
> So I basically agree with Stephen that this locking doesn't make any
> sense.
>
> The lock is needed when you are going to add or delete an FDB entry.
>
> Here we are doing a lookup and returning a device pointer via the FDB
> entry found in the lookup.
>
> The RTNL assertion assures that the device returned won't disappear.
>
> If the device can disappear, the spinlock added by this patch doesn't
> change that at all.

OK, I'll take another look at this.

Thanks,
Petr


[Bridge] [PATCH net-next v4 8/8] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-29 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11



[Bridge] [PATCH net-next v4 7/8] net: bridge: Notify about bridge VLANs

2018-05-29 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata 
---
 net/bridge/br_vlan.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 602c869..7df2690 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -246,6 +246,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -281,6 +285,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -306,6 +312,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -558,16 +569,22 @@ static int br_vlan_add_existing(struct net_bridge *br,
 {
int err;
 
+   err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   return err;
+
if (!br_vlan_is_brentry(vlan)) {
/* Trying to change flags of non-existent bridge vlan */
-   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
-   return -EINVAL;
+   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY)) {
+   err = -EINVAL;
+   goto err_flags;
+   }
/* It was only kept for port vlans, now make it real */
err = br_fdb_insert(br, NULL, br->dev->dev_addr,
vlan->vid);
if (err) {
br_err(br, "failed to insert local address into bridge 
forwarding table\n");
-   return err;
+   goto err_fdb_insert;
}
 
refcount_inc(>refcnt);
@@ -580,6 +597,11 @@ static int br_vlan_add_existing(struct net_bridge *br,
*changed = true;
 
return 0;
+
+err_fdb_insert:
+err_flags:
+   br_switchdev_port_vlan_del(br->dev, vlan->vid);
+   return err;
 }
 
 /* Must be protected by RTNL.
-- 
2.4.11



[Bridge] [PATCH net-next v4 5/8] dsa: port: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
A follow-up patch enables emitting VLAN notifications for the bridge CPU
port in addition to the existing slave port notifications. These
notifications have orig_dev set to the bridge in question.

Because there's no specific support for these VLANs, just ignore the
notifications to maintain the current behavior.

Signed-off-by: Petr Machata 
Reviewed-by: Vivien Didelot 
---
 net/dsa/port.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 2413beb..ed05954 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -252,6 +252,9 @@ int dsa_port_vlan_add(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, );
 
@@ -267,6 +270,9 @@ int dsa_port_vlan_del(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, );
 
-- 
2.4.11



[PATCH net-next v4 8/8] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-29 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v4 7/8] net: bridge: Notify about bridge VLANs

2018-05-29 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata 
---
 net/bridge/br_vlan.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 602c869..7df2690 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -246,6 +246,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -281,6 +285,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -306,6 +312,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -558,16 +569,22 @@ static int br_vlan_add_existing(struct net_bridge *br,
 {
int err;
 
+   err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   return err;
+
if (!br_vlan_is_brentry(vlan)) {
/* Trying to change flags of non-existent bridge vlan */
-   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
-   return -EINVAL;
+   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY)) {
+   err = -EINVAL;
+   goto err_flags;
+   }
/* It was only kept for port vlans, now make it real */
err = br_fdb_insert(br, NULL, br->dev->dev_addr,
vlan->vid);
if (err) {
br_err(br, "failed to insert local address into bridge 
forwarding table\n");
-   return err;
+   goto err_fdb_insert;
}
 
refcount_inc(>refcnt);
@@ -580,6 +597,11 @@ static int br_vlan_add_existing(struct net_bridge *br,
*changed = true;
 
return 0;
+
+err_fdb_insert:
+err_flags:
+   br_switchdev_port_vlan_del(br->dev, vlan->vid);
+   return err;
 }
 
 /* Must be protected by RTNL.
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v4 6/8] staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
A follow-up patch enables emitting VLAN notifications for the bridge CPU
port in addition to the existing slave port notifications. These
notifications have orig_dev set to the bridge in question.

Because there's no specific support for these VLANs, just ignore the
notifications to maintain the current behavior.

Signed-off-by: Petr Machata 
---
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c 
b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index c723a04..a17dd29 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -719,6 +719,9 @@ static int port_vlans_add(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -873,6 +876,9 @@ static int port_vlans_del(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
err = ethsw_port_del_vlan(port_priv, vid);
if (err)
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v4 5/8] dsa: port: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
A follow-up patch enables emitting VLAN notifications for the bridge CPU
port in addition to the existing slave port notifications. These
notifications have orig_dev set to the bridge in question.

Because there's no specific support for these VLANs, just ignore the
notifications to maintain the current behavior.

Signed-off-by: Petr Machata 
Reviewed-by: Vivien Didelot 
---
 net/dsa/port.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 2413beb..ed05954 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -252,6 +252,9 @@ int dsa_port_vlan_add(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, );
 
@@ -267,6 +270,9 @@ int dsa_port_vlan_del(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, );
 
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v4 4/8] rocker: rocker_main: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
A follow-up patch enables emitting VLAN notifications for the bridge CPU
port in addition to the existing slave port notifications. These
notifications have orig_dev set to the bridge in question.

Because there's no specific support for these VLANs, just ignore the
notifications to maintain the current behavior.

Signed-off-by: Petr Machata 
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[Bridge] [PATCH net-next v4 2/8] net: bridge: Extract br_vlan_add_existing()

2018-05-29 Thread Petr Machata
Extract the code that deals with adding a preexisting VLAN to bridge CPU
port to a separate function. A follow-up patch introduces a need to roll
back operations in this block due to an error, and this split will make
the error-handling code clearer.

Signed-off-by: Petr Machata 
---
 net/bridge/br_vlan.c | 55 +++-
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index e3b14c0..602c869 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -551,6 +551,37 @@ bool br_should_learn(struct net_bridge_port *p, struct 
sk_buff *skb, u16 *vid)
return false;
 }
 
+static int br_vlan_add_existing(struct net_bridge *br,
+   struct net_bridge_vlan_group *vg,
+   struct net_bridge_vlan *vlan,
+   u16 flags, bool *changed)
+{
+   int err;
+
+   if (!br_vlan_is_brentry(vlan)) {
+   /* Trying to change flags of non-existent bridge vlan */
+   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
+   return -EINVAL;
+   /* It was only kept for port vlans, now make it real */
+   err = br_fdb_insert(br, NULL, br->dev->dev_addr,
+   vlan->vid);
+   if (err) {
+   br_err(br, "failed to insert local address into bridge 
forwarding table\n");
+   return err;
+   }
+
+   refcount_inc(>refcnt);
+   vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
+   vg->num_vlans++;
+   *changed = true;
+   }
+
+   if (__vlan_add_flags(vlan, flags))
+   *changed = true;
+
+   return 0;
+}
+
 /* Must be protected by RTNL.
  * Must be called with vid in range from 1 to 4094 inclusive.
  * changed must be true only if the vlan was created or updated
@@ -566,28 +597,8 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
*changed = false;
vg = br_vlan_group(br);
vlan = br_vlan_find(vg, vid);
-   if (vlan) {
-   if (!br_vlan_is_brentry(vlan)) {
-   /* Trying to change flags of non-existent bridge vlan */
-   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
-   return -EINVAL;
-   /* It was only kept for port vlans, now make it real */
-   ret = br_fdb_insert(br, NULL, br->dev->dev_addr,
-   vlan->vid);
-   if (ret) {
-   br_err(br, "failed insert local address into 
bridge forwarding table\n");
-   return ret;
-   }
-   refcount_inc(>refcnt);
-   vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
-   vg->num_vlans++;
-   *changed = true;
-   }
-   if (__vlan_add_flags(vlan, flags))
-   *changed = true;
-
-   return 0;
-   }
+   if (vlan)
+   return br_vlan_add_existing(br, vg, vlan, flags, changed);
 
vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
if (!vlan)
-- 
2.4.11



[PATCH net-next v4 3/8] mlxsw: spectrum_switchdev: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
A follow-up patch enables emitting VLAN notifications for the bridge CPU
port in addition to the existing slave port notifications. These
notifications have orig_dev set to the bridge in question.

Because there's no specific support for these VLANs, just ignore the
notifications to maintain the current behavior.

Signed-off-by: Petr Machata 
Reviewed-by: Ido Schimmel 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 8c9cf8e..cbc8fab 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1144,6 +1144,9 @@ static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -1741,6 +1744,9 @@ static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
if (WARN_ON(!bridge_port))
return -EINVAL;
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v4 2/8] net: bridge: Extract br_vlan_add_existing()

2018-05-29 Thread Petr Machata
Extract the code that deals with adding a preexisting VLAN to bridge CPU
port to a separate function. A follow-up patch introduces a need to roll
back operations in this block due to an error, and this split will make
the error-handling code clearer.

Signed-off-by: Petr Machata 
---
 net/bridge/br_vlan.c | 55 +++-
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index e3b14c0..602c869 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -551,6 +551,37 @@ bool br_should_learn(struct net_bridge_port *p, struct 
sk_buff *skb, u16 *vid)
return false;
 }
 
+static int br_vlan_add_existing(struct net_bridge *br,
+   struct net_bridge_vlan_group *vg,
+   struct net_bridge_vlan *vlan,
+   u16 flags, bool *changed)
+{
+   int err;
+
+   if (!br_vlan_is_brentry(vlan)) {
+   /* Trying to change flags of non-existent bridge vlan */
+   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
+   return -EINVAL;
+   /* It was only kept for port vlans, now make it real */
+   err = br_fdb_insert(br, NULL, br->dev->dev_addr,
+   vlan->vid);
+   if (err) {
+   br_err(br, "failed to insert local address into bridge 
forwarding table\n");
+   return err;
+   }
+
+   refcount_inc(>refcnt);
+   vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
+   vg->num_vlans++;
+   *changed = true;
+   }
+
+   if (__vlan_add_flags(vlan, flags))
+   *changed = true;
+
+   return 0;
+}
+
 /* Must be protected by RTNL.
  * Must be called with vid in range from 1 to 4094 inclusive.
  * changed must be true only if the vlan was created or updated
@@ -566,28 +597,8 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
*changed = false;
vg = br_vlan_group(br);
vlan = br_vlan_find(vg, vid);
-   if (vlan) {
-   if (!br_vlan_is_brentry(vlan)) {
-   /* Trying to change flags of non-existent bridge vlan */
-   if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
-   return -EINVAL;
-   /* It was only kept for port vlans, now make it real */
-   ret = br_fdb_insert(br, NULL, br->dev->dev_addr,
-   vlan->vid);
-   if (ret) {
-   br_err(br, "failed insert local address into 
bridge forwarding table\n");
-   return ret;
-   }
-   refcount_inc(>refcnt);
-   vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
-   vg->num_vlans++;
-   *changed = true;
-   }
-   if (__vlan_add_flags(vlan, flags))
-   *changed = true;
-
-   return 0;
-   }
+   if (vlan)
+   return br_vlan_add_existing(br, vg, vlan, flags, changed);
 
vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
if (!vlan)
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v4 1/8] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-29 Thread Petr Machata
A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves
initializing a struct switchdev_obj_port_vlan, a piece of code that
repeats on each call site almost verbatim. While in the current codebase
there is just one duplicated add call, the follow-up patches add more of
both add and del calls.

Thus to remove the duplication, extract the repetition into named
functions and reuse.

Signed-off-by: Petr Machata 
Reviewed-by: Vivien Didelot 
---
 net/bridge/br_private.h   | 13 +
 net/bridge/br_switchdev.c | 25 +
 net/bridge/br_vlan.c  | 26 +++---
 3 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 11520ed..5216a52 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
   unsigned long mask);
 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
 int type);
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
 
 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
 {
@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct 
net_bridge_port *p,
return 0;
 }
 
+static inline int br_switchdev_port_vlan_add(struct net_device *dev,
+u16 vid, u16 flags)
+{
+   return -EOPNOTSUPP;
+}
+
+static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   return -EOPNOTSUPP;
+}
+
 static inline void
 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 {
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index 35474d4..d77f807 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry 
*fdb, int type)
break;
}
 }
+
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .flags = flags,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_add(dev, );
+}
+
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_del(dev, );
+}
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index dc832c09..e3b14c0 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -82,19 +82,12 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 
flags)
 static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
  u16 vid, u16 flags)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
int err;
 
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q add.
 */
-   err = switchdev_port_obj_add(dev, );
+   err = br_switchdev_port_vlan_add(dev, vid, flags);
if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, vid);
return err;
@@ -130,18 +123,12 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
 static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
  u16 vid)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
int err;
 
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q del.
 */
-   err = switchdev_port_obj_del(dev, );
+   err = br_switchdev_port_vlan_del(dev, vid);
if (err == -EOPNOTSUPP) {
vlan_vid_del(dev, br->vlan_proto, vid);
return 0;
@@ -1053,13 +1040,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
 bool *changed)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = port->dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
struct net_bridge_vlan *vlan;
int ret;
 
@@ -1069,7 +1049

[Bridge] [PATCH net-next v4 0/8] net: bridge: Notify about bridge VLANs

2018-05-29 Thread Petr Machata
In commit 946a11e7408e ("mlxsw: spectrum_span: Allow bridge for gretap
mirror"), mlxsw got support for offloading mirror-to-gretap such that
the underlay packet path involves a bridge. In that case, the offload is
also influenced by PVID setting of said bridge. However, changes to VLAN
configuration of the bridge itself do not generate switchdev
notifications, so there's no mechanism to prod mlxsw to update the
offload when these settings change.

In this patchset, the problem is resolved by distributing the switchdev
notification SWITCHDEV_OBJ_ID_PORT_VLAN also for configuration changes
on bridge VLANs. Since stacked devices distribute the notification to
lower devices, such event eventually reaches the driver, which can
determine whether it's a bridge or port VLAN by inspecting orig_dev.

To keep things consistent, the newly-distributed notifications observe
the same protocol as the existing ones: dual prepare/commit, with
-EOPNOTSUPP indicating lack of support, even though there's currently
nothing to prepare for and nothing to support. Correspondingly, all
switchdev drivers have been updated to return -EOPNOTSUPP for bridge
VLAN notifications.

In patches #1 and #2, the code base is changed to support the following
additions: functions br_switchdev_port_vlan_add() and
br_switchdev_port_vlan_del() are introduced to simplify sending
notifications; and br_vlan_add_existing() is introduced to later make it
simpler to add error-handling code for the case of configuring a
preexisting VLAN on bridge CPU port.

In patches #3-#6, respectively for mlxsw, rocker, DSA and DPAA2 ethsw,
the new notifications (which are not enabled yet) are ignored to
maintain the current behavior.

In patch #7, the notification is actually enabled.

In patch #8, mlxsw is changed to update offloads of mirror-to-gre also
for bridge-related notifications.

Changes from v3 to v4:

- In patch #1, separate variable declarations from program logic.
- Add patch #2.
- In patch #7, add error handling around a newly-introduced call to
  br_switchdev_port_vlan_add().
- Rephrase commit messages of patches #3-#6 to explain motivation for
  the change.

Changes from v2 to v3:

- Add a fallback definition for br_switchdev_port_obj_add() and
  br_switchdev_port_obj_del() when !CONFIG_NET_SWITCHDEV.

Changes from v1 to v2:

- Rename br_switchdev_port_obj_add() and br_switchdev_port_obj_del() to
  br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del(), and
  move from br_vlan.c to br_switchdev.c.

Petr Machata (8):
  net: bridge: Extract boilerplate around switchdev_port_obj_*()
  net: bridge: Extract br_vlan_add_existing()
  mlxsw: spectrum_switchdev: Ignore bridge VLAN events
  rocker: rocker_main: Ignore bridge VLAN events
  dsa: port: Ignore bridge VLAN events
  staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events
  net: bridge: Notify about bridge VLANs
  mlxsw: spectrum_switchdev: Schedule respin during trans prepare

 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   |   8 +-
 drivers/net/ethernet/rocker/rocker_main.c  |   6 ++
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c|   6 ++
 net/bridge/br_private.h|  13 +++
 net/bridge/br_switchdev.c  |  25 +
 net/bridge/br_vlan.c   | 103 -
 net/dsa/port.c |   6 ++
 7 files changed, 121 insertions(+), 46 deletions(-)

-- 
2.4.11



[PATCH net-next v4 0/8] net: bridge: Notify about bridge VLANs

2018-05-29 Thread Petr Machata
In commit 946a11e7408e ("mlxsw: spectrum_span: Allow bridge for gretap
mirror"), mlxsw got support for offloading mirror-to-gretap such that
the underlay packet path involves a bridge. In that case, the offload is
also influenced by PVID setting of said bridge. However, changes to VLAN
configuration of the bridge itself do not generate switchdev
notifications, so there's no mechanism to prod mlxsw to update the
offload when these settings change.

In this patchset, the problem is resolved by distributing the switchdev
notification SWITCHDEV_OBJ_ID_PORT_VLAN also for configuration changes
on bridge VLANs. Since stacked devices distribute the notification to
lower devices, such event eventually reaches the driver, which can
determine whether it's a bridge or port VLAN by inspecting orig_dev.

To keep things consistent, the newly-distributed notifications observe
the same protocol as the existing ones: dual prepare/commit, with
-EOPNOTSUPP indicating lack of support, even though there's currently
nothing to prepare for and nothing to support. Correspondingly, all
switchdev drivers have been updated to return -EOPNOTSUPP for bridge
VLAN notifications.

In patches #1 and #2, the code base is changed to support the following
additions: functions br_switchdev_port_vlan_add() and
br_switchdev_port_vlan_del() are introduced to simplify sending
notifications; and br_vlan_add_existing() is introduced to later make it
simpler to add error-handling code for the case of configuring a
preexisting VLAN on bridge CPU port.

In patches #3-#6, respectively for mlxsw, rocker, DSA and DPAA2 ethsw,
the new notifications (which are not enabled yet) are ignored to
maintain the current behavior.

In patch #7, the notification is actually enabled.

In patch #8, mlxsw is changed to update offloads of mirror-to-gre also
for bridge-related notifications.

Changes from v3 to v4:

- In patch #1, separate variable declarations from program logic.
- Add patch #2.
- In patch #7, add error handling around a newly-introduced call to
  br_switchdev_port_vlan_add().
- Rephrase commit messages of patches #3-#6 to explain motivation for
  the change.

Changes from v2 to v3:

- Add a fallback definition for br_switchdev_port_obj_add() and
  br_switchdev_port_obj_del() when !CONFIG_NET_SWITCHDEV.

Changes from v1 to v2:

- Rename br_switchdev_port_obj_add() and br_switchdev_port_obj_del() to
  br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del(), and
  move from br_vlan.c to br_switchdev.c.

Petr Machata (8):
  net: bridge: Extract boilerplate around switchdev_port_obj_*()
  net: bridge: Extract br_vlan_add_existing()
  mlxsw: spectrum_switchdev: Ignore bridge VLAN events
  rocker: rocker_main: Ignore bridge VLAN events
  dsa: port: Ignore bridge VLAN events
  staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events
  net: bridge: Notify about bridge VLANs
  mlxsw: spectrum_switchdev: Schedule respin during trans prepare

 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   |   8 +-
 drivers/net/ethernet/rocker/rocker_main.c  |   6 ++
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c|   6 ++
 net/bridge/br_private.h|  13 +++
 net/bridge/br_switchdev.c  |  25 +
 net/bridge/br_vlan.c   | 103 -
 net/dsa/port.c |   6 ++
 7 files changed, 121 insertions(+), 46 deletions(-)

-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [Bridge] [PATCH net-next v2 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
Ilias Apalodimas  writes:

>> diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
>> b/drivers/net/ethernet/rocker/rocker_main.c
>> index e73e4fe..aeafdb9 100644
>> --- a/drivers/net/ethernet/rocker/rocker_main.c
>> +++ b/drivers/net/ethernet/rocker/rocker_main.c
>> @@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
>> *rocker_port,
>>  {
>>  struct rocker_world_ops *wops = rocker_port->rocker->wops;
>>  
>> +if (netif_is_bridge_master(vlan->obj.orig_dev))
>> +return -EOPNOTSUPP;
>> +
> What will happen to the "bridge vlan add dev br0 vid X pvid untagged self" 
> when
> the lower level (the driver) returns -EOPNOTSUPP? Will it avoid adding a vlan 
> on
> the bridge ?

No, it will still do it. The reasons are:

- that's what currently happens anyway: none of the drivers has any
  support, yet the bridge logic is done

- -EOPNOTSUPP is what switchdev_port_obj_*() return if switchdev is not
  compiled in

In order to suppress the setting, return e.g. -EINVAL:

# bridge vlan add dev br vid 111 self
RTNETLINK answers: Invalid argument
# bridge vlan show dev br
portvlan ids
br   1 PVID Egress Untagged

Thanks,
Petr


Re: [PATCH net-next v2 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-29 Thread Petr Machata
Ilias Apalodimas  writes:

>> diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
>> b/drivers/net/ethernet/rocker/rocker_main.c
>> index e73e4fe..aeafdb9 100644
>> --- a/drivers/net/ethernet/rocker/rocker_main.c
>> +++ b/drivers/net/ethernet/rocker/rocker_main.c
>> @@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
>> *rocker_port,
>>  {
>>  struct rocker_world_ops *wops = rocker_port->rocker->wops;
>>  
>> +if (netif_is_bridge_master(vlan->obj.orig_dev))
>> +return -EOPNOTSUPP;
>> +
> What will happen to the "bridge vlan add dev br0 vid X pvid untagged self" 
> when
> the lower level (the driver) returns -EOPNOTSUPP? Will it avoid adding a vlan 
> on
> the bridge ?

No, it will still do it. The reasons are:

- that's what currently happens anyway: none of the drivers has any
  support, yet the bridge logic is done

- -EOPNOTSUPP is what switchdev_port_obj_*() return if switchdev is not
  compiled in

In order to suppress the setting, return e.g. -EINVAL:

# bridge vlan add dev br vid 111 self
RTNETLINK answers: Invalid argument
# bridge vlan show dev br
portvlan ids
br   1 PVID Egress Untagged

Thanks,
Petr
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH net-next v3 6/7] net: bridge: Notify about bridge VLANs

2018-05-29 Thread Petr Machata
Dan Carpenter  writes:

> On Mon, May 28, 2018 at 05:11:04PM +0200, Petr Machata wrote:
>> @@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 
>> flags, bool *changed)
>>  vg->num_vlans++;
>>  *changed = true;
>>  }
>> +ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
>> +if (ret && ret != -EOPNOTSUPP)
>> +return ret;
>
> We should probably do some error handling instead of returning directly?

I missed that, you are right. There's a bunch of mutations in the block
above.

Thanks,
Petr
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [Bridge] [PATCH net-next v3 6/7] net: bridge: Notify about bridge VLANs

2018-05-29 Thread Petr Machata
Dan Carpenter  writes:

> On Mon, May 28, 2018 at 05:11:04PM +0200, Petr Machata wrote:
>> @@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 
>> flags, bool *changed)
>>  vg->num_vlans++;
>>  *changed = true;
>>  }
>> +ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
>> +if (ret && ret != -EOPNOTSUPP)
>> +return ret;
>
> We should probably do some error handling instead of returning directly?

I missed that, you are right. There's a bunch of mutations in the block
above.

Thanks,
Petr


Re: [PATCH net-next] net: bridge: Lock before br_fdb_find()

2018-05-28 Thread Petr Machata
Nikolay Aleksandrov  writes:

> Fixes: 4d4fd36126d6 ("net: bridge: Publish bridge accessor functions")

Correct.

Thanks,
Petr


Re: [Bridge] [PATCH net-next] net: bridge: Lock before br_fdb_find()

2018-05-28 Thread Petr Machata
Nikolay Aleksandrov  writes:

> Fixes: 4d4fd36126d6 ("net: bridge: Publish bridge accessor functions")

Correct.

Thanks,
Petr


[PATCH net-next] net: bridge: Lock before br_fdb_find()

2018-05-28 Thread Petr Machata
Callers of br_fdb_find() need to hold the hash lock, which
br_fdb_find_port() doesn't do. Add the missing lock/unlock
pair.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 net/bridge/br_fdb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index b19e310..3f5691a 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -135,9 +135,11 @@ struct net_device *br_fdb_find_port(const struct 
net_device *br_dev,
return NULL;
 
br = netdev_priv(br_dev);
+   spin_lock_bh(>hash_lock);
f = br_fdb_find(br, addr, vid);
if (f && f->dst)
dev = f->dst->dev;
+   spin_unlock_bh(>hash_lock);
 
return dev;
 }
-- 
2.4.11



[Bridge] [PATCH net-next v3 7/7] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-28 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11



[Bridge] [PATCH net-next v3 6/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Florian Fainelli <f.faine...@gmail.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
Reviewed-by: Nikolay Aleksandrov <niko...@cumulusnetworks.com>
Tested-by: Florian Fainelli <f.faine...@gmail.com>
---
 net/bridge/br_vlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 8ad5756..b15ef3f 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -243,6 +243,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -278,6 +282,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -303,6 +309,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
vg->num_vlans++;
*changed = true;
}
+   ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
+   if (ret && ret != -EOPNOTSUPP)
+   return ret;
if (__vlan_add_flags(vlan, flags))
*changed = true;
 
-- 
2.4.11



[Bridge] [PATCH net-next v3 5/7] staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c 
b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index c723a04..a17dd29 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -719,6 +719,9 @@ static int port_vlans_add(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -873,6 +876,9 @@ static int port_vlans_del(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
err = ethsw_port_del_vlan(port_priv, vid);
if (err)
-- 
2.4.11



[Bridge] [PATCH net-next v3 4/7] dsa: port: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
---
 net/dsa/port.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 2413beb..ed05954 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -252,6 +252,9 @@ int dsa_port_vlan_add(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, );
 
@@ -267,6 +270,9 @@ int dsa_port_vlan_del(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, );
 
-- 
2.4.11



[Bridge] [PATCH net-next v3 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11



[Bridge] [PATCH net-next v3 2/7] mlxsw: spectrum_switchdev: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 8c9cf8e..cbc8fab 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1144,6 +1144,9 @@ static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -1741,6 +1744,9 @@ static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
if (WARN_ON(!bridge_port))
return -EINVAL;
-- 
2.4.11



[PATCH net-next v3 5/7] staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c 
b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index c723a04..a17dd29 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -719,6 +719,9 @@ static int port_vlans_add(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -873,6 +876,9 @@ static int port_vlans_del(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
err = ethsw_port_del_vlan(port_priv, vid);
if (err)
-- 
2.4.11



[PATCH net-next v3 2/7] mlxsw: spectrum_switchdev: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 8c9cf8e..cbc8fab 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1144,6 +1144,9 @@ static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -1741,6 +1744,9 @@ static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
if (WARN_ON(!bridge_port))
return -EINVAL;
-- 
2.4.11



[PATCH net-next v3 6/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Florian Fainelli <f.faine...@gmail.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
Reviewed-by: Nikolay Aleksandrov <niko...@cumulusnetworks.com>
Tested-by: Florian Fainelli <f.faine...@gmail.com>
---
 net/bridge/br_vlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 8ad5756..b15ef3f 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -243,6 +243,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -278,6 +282,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -303,6 +309,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
vg->num_vlans++;
*changed = true;
}
+   ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
+   if (ret && ret != -EOPNOTSUPP)
+   return ret;
if (__vlan_add_flags(vlan, flags))
*changed = true;
 
-- 
2.4.11



[PATCH net-next v3 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11



[PATCH net-next v3 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves
initializing a struct switchdev_obj_port_vlan, a piece of code that
repeats on each call site almost verbatim. While in the current codebase
there is just one duplicated add call, the follow-up patches add more of
both add and del calls.

Thus to remove the duplication, extract the repetition into named
functions and reuse.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 net/bridge/br_private.h   | 13 +
 net/bridge/br_switchdev.c | 25 +
 net/bridge/br_vlan.c  | 31 ---
 3 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 11520ed..5216a52 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
   unsigned long mask);
 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
 int type);
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
 
 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
 {
@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct 
net_bridge_port *p,
return 0;
 }
 
+static inline int br_switchdev_port_vlan_add(struct net_device *dev,
+u16 vid, u16 flags)
+{
+   return -EOPNOTSUPP;
+}
+
+static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   return -EOPNOTSUPP;
+}
+
 static inline void
 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 {
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index 35474d4..d77f807 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry 
*fdb, int type)
break;
}
 }
+
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .flags = flags,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_add(dev, );
+}
+
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_del(dev, );
+}
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index dc832c09..8ad5756 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -82,19 +82,10 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 
flags)
 static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
  u16 vid, u16 flags)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q add.
 */
-   err = switchdev_port_obj_add(dev, );
+   int err = br_switchdev_port_vlan_add(dev, vid, flags);
if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, vid);
return err;
@@ -130,18 +121,11 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
 static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
  u16 vid)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q del.
 */
-   err = switchdev_port_obj_del(dev, );
+   int err = br_switchdev_port_vlan_del(dev, vid);
+
if (err == -EOPNOTSUPP) {
vlan_vid_del(dev, br->vlan_proto, vid);
return 0;
@@ -1053,13 +1037,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
 bool *changed)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = port->dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
struct net_bridge_vlan *vlan;
int ret;
 
@@ -1069,7

[PATCH net-next v3 7/7] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-28 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11



[PATCH net-next v3 4/7] dsa: port: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
---
 net/dsa/port.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 2413beb..ed05954 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -252,6 +252,9 @@ int dsa_port_vlan_add(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, );
 
@@ -267,6 +270,9 @@ int dsa_port_vlan_del(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, );
 
-- 
2.4.11



[PATCH net-next v3 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v3 6/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Florian Fainelli <f.faine...@gmail.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
Reviewed-by: Nikolay Aleksandrov <niko...@cumulusnetworks.com>
Tested-by: Florian Fainelli <f.faine...@gmail.com>
---
 net/bridge/br_vlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 8ad5756..b15ef3f 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -243,6 +243,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -278,6 +282,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -303,6 +309,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
vg->num_vlans++;
*changed = true;
}
+   ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
+   if (ret && ret != -EOPNOTSUPP)
+   return ret;
if (__vlan_add_flags(vlan, flags))
*changed = true;
 
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v3 5/7] staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c 
b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index c723a04..a17dd29 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -719,6 +719,9 @@ static int port_vlans_add(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -873,6 +876,9 @@ static int port_vlans_del(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
err = ethsw_port_del_vlan(port_priv, vid);
if (err)
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v3 4/7] dsa: port: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
---
 net/dsa/port.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 2413beb..ed05954 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -252,6 +252,9 @@ int dsa_port_vlan_add(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, );
 
@@ -267,6 +270,9 @@ int dsa_port_vlan_del(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, );
 
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[Bridge] [PATCH net-next v3 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves
initializing a struct switchdev_obj_port_vlan, a piece of code that
repeats on each call site almost verbatim. While in the current codebase
there is just one duplicated add call, the follow-up patches add more of
both add and del calls.

Thus to remove the duplication, extract the repetition into named
functions and reuse.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 net/bridge/br_private.h   | 13 +
 net/bridge/br_switchdev.c | 25 +
 net/bridge/br_vlan.c  | 31 ---
 3 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 11520ed..5216a52 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
   unsigned long mask);
 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
 int type);
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
 
 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
 {
@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct 
net_bridge_port *p,
return 0;
 }
 
+static inline int br_switchdev_port_vlan_add(struct net_device *dev,
+u16 vid, u16 flags)
+{
+   return -EOPNOTSUPP;
+}
+
+static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   return -EOPNOTSUPP;
+}
+
 static inline void
 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 {
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index 35474d4..d77f807 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry 
*fdb, int type)
break;
}
 }
+
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .flags = flags,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_add(dev, );
+}
+
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_del(dev, );
+}
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index dc832c09..8ad5756 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -82,19 +82,10 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 
flags)
 static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
  u16 vid, u16 flags)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q add.
 */
-   err = switchdev_port_obj_add(dev, );
+   int err = br_switchdev_port_vlan_add(dev, vid, flags);
if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, vid);
return err;
@@ -130,18 +121,11 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
 static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
  u16 vid)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q del.
 */
-   err = switchdev_port_obj_del(dev, );
+   int err = br_switchdev_port_vlan_del(dev, vid);
+
if (err == -EOPNOTSUPP) {
vlan_vid_del(dev, br->vlan_proto, vid);
return 0;
@@ -1053,13 +1037,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
 bool *changed)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = port->dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
struct net_bridge_vlan *vlan;
int ret;
 
@@ -1069,7

[PATCH net-next v3 0/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
In commit 946a11e7408e ("mlxsw: spectrum_span: Allow bridge for gretap
mirror"), mlxsw got support for offloading mirror-to-gretap such that
the underlay packet path involves a bridge. In that case, the offload is
also influenced by PVID setting of said bridge. However, changes to VLAN
configuration of the bridge itself do not generate switchdev
notifications, so there's no mechanism to prod mlxsw to update the
offload when these settings change.

In this patchset, the problem is resolved by distributing the switchdev
notification SWITCHDEV_OBJ_ID_PORT_VLAN also for configuration changes
on bridge VLANs. Since stacked devices distribute the notification to
lower devices, such event eventually reaches the driver, which can
determine whether it's a bridge or port VLAN by inspecting orig_dev.

To keep things consistent, the newly-distributed notifications observe
the same protocol as the existing ones: dual prepare/commit, with
-EOPNOTSUPP indicating lack of support, even though there's currently
nothing to prepare for and nothing to support. Correspondingly, all
switchdev drivers have been updated to return -EOPNOTSUPP for bridge
VLAN notifications.

In patch #1, the code to send notifications for adding and deleting is
factored out into two named functions.

In patches #2-#5, respectively for mlxsw, rocker, DSA and DPAA2 ethsw,
the new notifications (which are not enabled yet) are ignored to
maintain the current behavior.

In patch #6, the notification is actually enabled.

In patch #7, mlxsw is changed to update offloads of mirror-to-gre also
for bridge-related notifications.

Changes from v2 to v3:

- Add a fallback definition for br_switchdev_port_obj_add() and
  br_switchdev_port_obj_del() when !CONFIG_NET_SWITCHDEV.

Changes from v1 to v2:

- Rename br_switchdev_port_obj_add() and br_switchdev_port_obj_del() to
  br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del(), and
  move from br_vlan.c to br_switchdev.c.

Petr Machata (7):
  net: bridge: Extract boilerplate around switchdev_port_obj_*()
  mlxsw: spectrum_switchdev: Ignore bridge VLAN events
  rocker: rocker_main: Ignore bridge VLAN events
  dsa: port: Ignore bridge VLAN events
  staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events
  net: bridge: Notify about bridge VLANs
  mlxsw: spectrum_switchdev: Schedule respin during trans prepare

 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   |  8 +++-
 drivers/net/ethernet/rocker/rocker_main.c  |  6 +++
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c|  6 +++
 net/bridge/br_private.h| 13 +++
 net/bridge/br_switchdev.c  | 25 
 net/bridge/br_vlan.c   | 45 +-
 net/dsa/port.c |  6 +++
 7 files changed, 81 insertions(+), 28 deletions(-)

-- 
2.4.11



[PATCH net-next v3 7/7] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-28 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v3 2/7] mlxsw: spectrum_switchdev: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 8c9cf8e..cbc8fab 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1144,6 +1144,9 @@ static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -1741,6 +1744,9 @@ static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
if (WARN_ON(!bridge_port))
return -EINVAL;
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v3 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves
initializing a struct switchdev_obj_port_vlan, a piece of code that
repeats on each call site almost verbatim. While in the current codebase
there is just one duplicated add call, the follow-up patches add more of
both add and del calls.

Thus to remove the duplication, extract the repetition into named
functions and reuse.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 net/bridge/br_private.h   | 13 +
 net/bridge/br_switchdev.c | 25 +
 net/bridge/br_vlan.c  | 31 ---
 3 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 11520ed..5216a52 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
   unsigned long mask);
 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
 int type);
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
 
 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
 {
@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct 
net_bridge_port *p,
return 0;
 }
 
+static inline int br_switchdev_port_vlan_add(struct net_device *dev,
+u16 vid, u16 flags)
+{
+   return -EOPNOTSUPP;
+}
+
+static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   return -EOPNOTSUPP;
+}
+
 static inline void
 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 {
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index 35474d4..d77f807 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry 
*fdb, int type)
break;
}
 }
+
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .flags = flags,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_add(dev, );
+}
+
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_del(dev, );
+}
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index dc832c09..8ad5756 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -82,19 +82,10 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 
flags)
 static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
  u16 vid, u16 flags)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q add.
 */
-   err = switchdev_port_obj_add(dev, );
+   int err = br_switchdev_port_vlan_add(dev, vid, flags);
if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, vid);
return err;
@@ -130,18 +121,11 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
 static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
  u16 vid)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q del.
 */
-   err = switchdev_port_obj_del(dev, );
+   int err = br_switchdev_port_vlan_del(dev, vid);
+
if (err == -EOPNOTSUPP) {
vlan_vid_del(dev, br->vlan_proto, vid);
return 0;
@@ -1053,13 +1037,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
 bool *changed)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = port->dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
struct net_bridge_vlan *vlan;
int ret;
 
@@ -1069,7

[Bridge] [PATCH net-next v3 0/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
In commit 946a11e7408e ("mlxsw: spectrum_span: Allow bridge for gretap
mirror"), mlxsw got support for offloading mirror-to-gretap such that
the underlay packet path involves a bridge. In that case, the offload is
also influenced by PVID setting of said bridge. However, changes to VLAN
configuration of the bridge itself do not generate switchdev
notifications, so there's no mechanism to prod mlxsw to update the
offload when these settings change.

In this patchset, the problem is resolved by distributing the switchdev
notification SWITCHDEV_OBJ_ID_PORT_VLAN also for configuration changes
on bridge VLANs. Since stacked devices distribute the notification to
lower devices, such event eventually reaches the driver, which can
determine whether it's a bridge or port VLAN by inspecting orig_dev.

To keep things consistent, the newly-distributed notifications observe
the same protocol as the existing ones: dual prepare/commit, with
-EOPNOTSUPP indicating lack of support, even though there's currently
nothing to prepare for and nothing to support. Correspondingly, all
switchdev drivers have been updated to return -EOPNOTSUPP for bridge
VLAN notifications.

In patch #1, the code to send notifications for adding and deleting is
factored out into two named functions.

In patches #2-#5, respectively for mlxsw, rocker, DSA and DPAA2 ethsw,
the new notifications (which are not enabled yet) are ignored to
maintain the current behavior.

In patch #6, the notification is actually enabled.

In patch #7, mlxsw is changed to update offloads of mirror-to-gre also
for bridge-related notifications.

Changes from v2 to v3:

- Add a fallback definition for br_switchdev_port_obj_add() and
  br_switchdev_port_obj_del() when !CONFIG_NET_SWITCHDEV.

Changes from v1 to v2:

- Rename br_switchdev_port_obj_add() and br_switchdev_port_obj_del() to
  br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del(), and
  move from br_vlan.c to br_switchdev.c.

Petr Machata (7):
  net: bridge: Extract boilerplate around switchdev_port_obj_*()
  mlxsw: spectrum_switchdev: Ignore bridge VLAN events
  rocker: rocker_main: Ignore bridge VLAN events
  dsa: port: Ignore bridge VLAN events
  staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events
  net: bridge: Notify about bridge VLANs
  mlxsw: spectrum_switchdev: Schedule respin during trans prepare

 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   |  8 +++-
 drivers/net/ethernet/rocker/rocker_main.c  |  6 +++
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c|  6 +++
 net/bridge/br_private.h| 13 +++
 net/bridge/br_switchdev.c  | 25 
 net/bridge/br_vlan.c   | 45 +-
 net/dsa/port.c |  6 +++
 7 files changed, 81 insertions(+), 28 deletions(-)

-- 
2.4.11



[PATCH net-next v3 0/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
In commit 946a11e7408e ("mlxsw: spectrum_span: Allow bridge for gretap
mirror"), mlxsw got support for offloading mirror-to-gretap such that
the underlay packet path involves a bridge. In that case, the offload is
also influenced by PVID setting of said bridge. However, changes to VLAN
configuration of the bridge itself do not generate switchdev
notifications, so there's no mechanism to prod mlxsw to update the
offload when these settings change.

In this patchset, the problem is resolved by distributing the switchdev
notification SWITCHDEV_OBJ_ID_PORT_VLAN also for configuration changes
on bridge VLANs. Since stacked devices distribute the notification to
lower devices, such event eventually reaches the driver, which can
determine whether it's a bridge or port VLAN by inspecting orig_dev.

To keep things consistent, the newly-distributed notifications observe
the same protocol as the existing ones: dual prepare/commit, with
-EOPNOTSUPP indicating lack of support, even though there's currently
nothing to prepare for and nothing to support. Correspondingly, all
switchdev drivers have been updated to return -EOPNOTSUPP for bridge
VLAN notifications.

In patch #1, the code to send notifications for adding and deleting is
factored out into two named functions.

In patches #2-#5, respectively for mlxsw, rocker, DSA and DPAA2 ethsw,
the new notifications (which are not enabled yet) are ignored to
maintain the current behavior.

In patch #6, the notification is actually enabled.

In patch #7, mlxsw is changed to update offloads of mirror-to-gre also
for bridge-related notifications.

Changes from v2 to v3:

- Add a fallback definition for br_switchdev_port_obj_add() and
  br_switchdev_port_obj_del() when !CONFIG_NET_SWITCHDEV.

Changes from v1 to v2:

- Rename br_switchdev_port_obj_add() and br_switchdev_port_obj_del() to
  br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del(), and
  move from br_vlan.c to br_switchdev.c.

Petr Machata (7):
  net: bridge: Extract boilerplate around switchdev_port_obj_*()
  mlxsw: spectrum_switchdev: Ignore bridge VLAN events
  rocker: rocker_main: Ignore bridge VLAN events
  dsa: port: Ignore bridge VLAN events
  staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events
  net: bridge: Notify about bridge VLANs
  mlxsw: spectrum_switchdev: Schedule respin during trans prepare

 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   |  8 +++-
 drivers/net/ethernet/rocker/rocker_main.c  |  6 +++
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c|  6 +++
 net/bridge/br_private.h| 13 +++
 net/bridge/br_switchdev.c  | 25 
 net/bridge/br_vlan.c   | 45 +-
 net/dsa/port.c |  6 +++
 7 files changed, 81 insertions(+), 28 deletions(-)

-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH net-next v2 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
Petr Machata <pe...@mellanox.com> writes:

> diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
> index 11520ed..33bd914 100644
> --- a/net/bridge/br_private.h
> +++ b/net/bridge/br_private.h
> @@ -1178,6 +1178,9 @@ static inline void br_switchdev_frame_unmark(struct 
> sk_buff *skb)
>  }
>  #endif /* CONFIG_NET_SWITCHDEV */
>  
> +int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
> +int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
> +

Nope, this actually does need to be in the ifdef block. The whole
br_switchdev.c is built conditionally.

I'll send v3.

Petr


Re: [Bridge] [PATCH net-next v2 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
Petr Machata <pe...@mellanox.com> writes:

> diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
> index 11520ed..33bd914 100644
> --- a/net/bridge/br_private.h
> +++ b/net/bridge/br_private.h
> @@ -1178,6 +1178,9 @@ static inline void br_switchdev_frame_unmark(struct 
> sk_buff *skb)
>  }
>  #endif /* CONFIG_NET_SWITCHDEV */
>  
> +int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
> +int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
> +

Nope, this actually does need to be in the ifdef block. The whole
br_switchdev.c is built conditionally.

I'll send v3.

Petr


Re: [PATCH net-next v2 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
Petr Machata <pe...@mellanox.com> writes:

> diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
> index 11520ed..33bd914 100644
> --- a/net/bridge/br_private.h
> +++ b/net/bridge/br_private.h
> @@ -1178,6 +1178,9 @@ static inline void br_switchdev_frame_unmark(struct 
> sk_buff *skb)
>  }
>  #endif /* CONFIG_NET_SWITCHDEV */
>  
> +int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
> +int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
> +

Nope, this actually does need to be in the ifdef block. The whole
br_switchdev.c is built conditionally.

I'll send v3.

Petr
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next v2 0/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
In commit 946a11e7408e ("mlxsw: spectrum_span: Allow bridge for gretap
mirror"), mlxsw got support for offloading mirror-to-gretap such that
the underlay packet path involves a bridge. In that case, the offload is
also influenced by PVID setting of said bridge. However, changes to VLAN
configuration of the bridge itself do not generate switchdev
notifications, so there's no mechanism to prod mlxsw to update the
offload when these settings change.

In this patchset, the problem is resolved by distributing the switchdev
notification SWITCHDEV_OBJ_ID_PORT_VLAN also for configuration changes
on bridge VLANs. Since stacked devices distribute the notification to
lower devices, such event eventually reaches the driver, which can
determine whether it's a bridge or port VLAN by inspecting orig_dev.

To keep things consistent, the newly-distributed notifications observe
the same protocol as the existing ones: dual prepare/commit, with
-EOPNOTSUPP indicating lack of support, even though there's currently
nothing to prepare for and nothing to support. Correspondingly, all
switchdev drivers have been updated to return -EOPNOTSUPP for bridge
VLAN notifications.

In patch #1, the code to send notifications for adding and deleting is
factored out into two named functions.

In patches #2-#5, respectively for mlxsw, rocker, DSA and DPAA2 ethsw,
the new notifications (which are not enabled yet) are ignored to
maintain the current behavior.

In patch #6, the notification is actually enabled.

In patch #7, mlxsw is changed to update offloads of mirror-to-gre also
for bridge-related notifications.

Changes from v1 to v2:

- Rename br_switchdev_port_obj_add() and br_switchdev_port_obj_del() to
  br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del(), and
  move from br_vlan.c to br_switchdev.c.

Petr Machata (7):
  net: bridge: Extract boilerplate around switchdev_port_obj_*()
  mlxsw: spectrum_switchdev: Ignore bridge VLAN events
  rocker: rocker_main: Ignore bridge VLAN events
  dsa: port: Ignore bridge VLAN events
  staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events
  net: bridge: Notify about bridge VLANs
  mlxsw: spectrum_switchdev: Schedule respin during trans prepare

 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   |  8 +++-
 drivers/net/ethernet/rocker/rocker_main.c  |  6 +++
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c|  6 +++
 net/bridge/br_private.h|  3 ++
 net/bridge/br_switchdev.c  | 25 
 net/bridge/br_vlan.c   | 45 +-
 net/dsa/port.c |  6 +++
 7 files changed, 71 insertions(+), 28 deletions(-)

-- 
2.4.11



[PATCH net-next v2 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*()

2018-05-28 Thread Petr Machata
A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves
initializing a struct switchdev_obj_port_vlan, a piece of code that
repeats on each call site almost verbatim. While in the current codebase
there is just one duplicated add call, the follow-up patches add more of
both add and del calls.

Thus to remove the duplication, extract the repetition into named
functions and reuse.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 net/bridge/br_private.h   |  3 +++
 net/bridge/br_switchdev.c | 25 +
 net/bridge/br_vlan.c  | 31 ---
 3 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 11520ed..33bd914 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1178,6 +1178,9 @@ static inline void br_switchdev_frame_unmark(struct 
sk_buff *skb)
 }
 #endif /* CONFIG_NET_SWITCHDEV */
 
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
+
 /* br_arp_nd_proxy.c */
 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br);
 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index 35474d4..d77f807 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry 
*fdb, int type)
break;
}
 }
+
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .flags = flags,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_add(dev, );
+}
+
+int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
+{
+   struct switchdev_obj_port_vlan v = {
+   .obj.orig_dev = dev,
+   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
+   .vid_begin = vid,
+   .vid_end = vid,
+   };
+
+   return switchdev_port_obj_del(dev, );
+}
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index dc832c09..8ad5756 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -82,19 +82,10 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 
flags)
 static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
  u16 vid, u16 flags)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q add.
 */
-   err = switchdev_port_obj_add(dev, );
+   int err = br_switchdev_port_vlan_add(dev, vid, flags);
if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, vid);
return err;
@@ -130,18 +121,11 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
 static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
  u16 vid)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
-   int err;
-
/* Try switchdev op first. In case it is not supported, fallback to
 * 8021q del.
 */
-   err = switchdev_port_obj_del(dev, );
+   int err = br_switchdev_port_vlan_del(dev, vid);
+
if (err == -EOPNOTSUPP) {
vlan_vid_del(dev, br->vlan_proto, vid);
return 0;
@@ -1053,13 +1037,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
 bool *changed)
 {
-   struct switchdev_obj_port_vlan v = {
-   .obj.orig_dev = port->dev,
-   .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
-   .flags = flags,
-   .vid_begin = vid,
-   .vid_end = vid,
-   };
struct net_bridge_vlan *vlan;
int ret;
 
@@ -1069,7 +1046,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, 
u16 flags,
vlan = br_vlan_find(nbp_vlan_group(port), vid);
if (vlan) {
/* Pass the flags to the hardware bridge */
-   ret = switchdev_port_obj_add(port->dev, );
+   ret = br_switchdev_port_vlan_add(port->dev, vid, flags);
if (ret && ret != -EOPNOTSUPP)
return ret;
*changed = __vlan_add_flags(vlan, flags);
-- 
2.4.11



[PATCH net-next v2 2/7] mlxsw: spectrum_switchdev: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 8c9cf8e..cbc8fab 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1144,6 +1144,9 @@ static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -1741,6 +1744,9 @@ static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
if (WARN_ON(!bridge_port))
return -EINVAL;
-- 
2.4.11



[PATCH net-next v2 4/7] dsa: port: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
---
 net/dsa/port.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 2413beb..ed05954 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -252,6 +252,9 @@ int dsa_port_vlan_add(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, );
 
@@ -267,6 +270,9 @@ int dsa_port_vlan_del(struct dsa_port *dp,
.vlan = vlan,
};
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (br_vlan_enabled(dp->bridge_dev))
return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, );
 
-- 
2.4.11



[PATCH net-next v2 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11



[PATCH net-next v2 7/7] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-28 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11



[PATCH net-next v2 6/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Florian Fainelli <f.faine...@gmail.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
Reviewed-by: Nikolay Aleksandrov <niko...@cumulusnetworks.com>
Tested-by: Florian Fainelli <f.faine...@gmail.com>
---
 net/bridge/br_vlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 8ad5756..b15ef3f 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -243,6 +243,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -278,6 +282,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -303,6 +309,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
vg->num_vlans++;
*changed = true;
}
+   ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
+   if (ret && ret != -EOPNOTSUPP)
+   return ret;
if (__vlan_add_flags(vlan, flags))
*changed = true;
 
-- 
2.4.11



[Bridge] [PATCH net-next v2 7/7] mlxsw: spectrum_switchdev: Schedule respin during trans prepare

2018-05-28 Thread Petr Machata
Since there's no special support for the bridge events, the driver
returns -EOPNOTSUPP, and thus the commit never happens. Therefore
schedule respin during the prepare stage: there's no real difference one
way or another.

This fixes the problem that mirror-to-gretap offload wouldn't adapt to
changes in bridge vlan configuration right away and another notification
would have to arrive for mlxsw to catch up.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index cbc8fab..8a15ac4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1697,7 +1697,7 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev,
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, trans);
 
-   if (switchdev_trans_ph_commit(trans)) {
+   if (switchdev_trans_ph_prepare(trans)) {
/* The event is emitted before the changes are actually
 * applied to the bridge. Therefore schedule the respin
 * call for later, so that the respin logic sees the
-- 
2.4.11



[Bridge] [PATCH net-next v2 6/7] net: bridge: Notify about bridge VLANs

2018-05-28 Thread Petr Machata
A driver might need to react to changes in settings of brentry VLANs.
Therefore send switchdev port notifications for these as well. Reuse
SWITCHDEV_OBJ_ID_PORT_VLAN for this purpose. Listeners should use
netif_is_bridge_master() on orig_dev to determine whether the
notification is about a bridge port or a bridge.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Florian Fainelli <f.faine...@gmail.com>
Reviewed-by: Vivien Didelot <vivien.dide...@savoirfairelinux.com>
Reviewed-by: Nikolay Aleksandrov <niko...@cumulusnetworks.com>
Tested-by: Florian Fainelli <f.faine...@gmail.com>
---
 net/bridge/br_vlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 8ad5756..b15ef3f 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -243,6 +243,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
goto out_filt;
v->brvlan = masterv;
v->stats = masterv->stats;
+   } else {
+   err = br_switchdev_port_vlan_add(dev, v->vid, flags);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
}
 
/* Add the dev mac and count the vlan only if it's usable */
@@ -278,6 +282,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
br_vlan_put_master(masterv);
v->brvlan = NULL;
}
+   } else {
+   br_switchdev_port_vlan_del(dev, v->vid);
}
 
goto out;
@@ -303,6 +309,11 @@ static int __vlan_del(struct net_bridge_vlan *v)
err = __vlan_vid_del(p->dev, p->br, v->vid);
if (err)
goto out;
+   } else {
+   err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
+   if (err && err != -EOPNOTSUPP)
+   goto out;
+   err = 0;
}
 
if (br_vlan_should_use(v)) {
@@ -580,6 +591,9 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 
bool *changed)
vg->num_vlans++;
*changed = true;
}
+   ret = br_switchdev_port_vlan_add(br->dev, vid, flags);
+   if (ret && ret != -EOPNOTSUPP)
+   return ret;
if (__vlan_add_flags(vlan, flags))
*changed = true;
 
-- 
2.4.11



[Bridge] [PATCH net-next v2 5/7] staging: fsl-dpaa2: ethsw: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c 
b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index c723a04..a17dd29 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -719,6 +719,9 @@ static int port_vlans_add(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -873,6 +876,9 @@ static int port_vlans_del(struct net_device *netdev,
struct ethsw_port_priv *port_priv = netdev_priv(netdev);
int vid, err;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
err = ethsw_port_del_vlan(port_priv, vid);
if (err)
-- 
2.4.11



[Bridge] [PATCH net-next v2 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11



[Bridge] [PATCH net-next v2 2/7] mlxsw: spectrum_switchdev: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
Reviewed-by: Ido Schimmel <ido...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 8c9cf8e..cbc8fab 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -1144,6 +1144,9 @@ static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
if (switchdev_trans_ph_prepare(trans))
return 0;
 
@@ -1741,6 +1744,9 @@ static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port 
*mlxsw_sp_port,
struct mlxsw_sp_bridge_port *bridge_port;
u16 vid;
 
+   if (netif_is_bridge_master(orig_dev))
+   return -EOPNOTSUPP;
+
bridge_port = mlxsw_sp_bridge_port_find(mlxsw_sp->bridge, orig_dev);
if (WARN_ON(!bridge_port))
return -EINVAL;
-- 
2.4.11



[PATCH net-next v2 3/7] rocker: rocker_main: Ignore bridge VLAN events

2018-05-28 Thread Petr Machata
Ignore VLAN events where the orig_dev is the bridge device itself.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c 
b/drivers/net/ethernet/rocker/rocker_main.c
index e73e4fe..aeafdb9 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1632,6 +1632,9 @@ rocker_world_port_obj_vlan_add(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_add)
return -EOPNOTSUPP;
 
@@ -1647,6 +1650,9 @@ rocker_world_port_obj_vlan_del(struct rocker_port 
*rocker_port,
 {
struct rocker_world_ops *wops = rocker_port->rocker->wops;
 
+   if (netif_is_bridge_master(vlan->obj.orig_dev))
+   return -EOPNOTSUPP;
+
if (!wops->port_obj_vlan_del)
return -EOPNOTSUPP;
return wops->port_obj_vlan_del(rocker_port, vlan);
-- 
2.4.11

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


<    1   2   3   4   5   6   7   8   9   10   >