From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT:
 drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c

Change-Id: I14690c34553db8cfe772a23441b86b4ad6e4fdee
---
 .../mellanox/mlx5/core/en/rep/bridge.c        | 35 ++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
@@ -225,7 +225,10 @@ mlx5_esw_bridge_port_obj_add(struct net_
 	const struct switchdev_obj_port_vlan *vlan;
 	const struct switchdev_obj_port_mdb *mdb;
 	u16 vport_num, esw_owner_vhca_id;
-	int err;
+#ifndef HAVE_STRUCT_SWITCHDEV_OBJ_PORT_VLAN_VID
+	u16 vid = 0;
+#endif
+	int err = 0;
 
 	if (!mlx5_esw_bridge_rep_vport_num_vhca_id_get(dev, br_offloads->esw, &vport_num,
 						       &esw_owner_vhca_id))
@@ -236,8 +239,15 @@ mlx5_esw_bridge_port_obj_add(struct net_
 	switch (obj->id) {
 	case SWITCHDEV_OBJ_ID_PORT_VLAN:
 		vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
+#ifdef HAVE_STRUCT_SWITCHDEV_OBJ_PORT_VLAN_VID
 		err = mlx5_esw_bridge_port_vlan_add(vport_num, esw_owner_vhca_id, vlan->vid,
 						    vlan->flags, br_offloads, extack);
+#else
+		for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
+			err = mlx5_esw_bridge_port_vlan_add(vport_num, esw_owner_vhca_id, vid,
+							    vlan->flags, br_offloads, extack);
+		}
+#endif
 		break;
 	case SWITCHDEV_OBJ_ID_PORT_MDB:
 		mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
@@ -259,6 +269,9 @@ mlx5_esw_bridge_port_obj_del(struct net_
 	const struct switchdev_obj_port_vlan *vlan;
 	const struct switchdev_obj_port_mdb *mdb;
 	u16 vport_num, esw_owner_vhca_id;
+#ifndef HAVE_STRUCT_SWITCHDEV_OBJ_PORT_VLAN_VID
+	u16 vid = 0;
+#endif
 
 	if (!mlx5_esw_bridge_rep_vport_num_vhca_id_get(dev, br_offloads->esw, &vport_num,
 						       &esw_owner_vhca_id))
@@ -269,7 +282,13 @@ mlx5_esw_bridge_port_obj_del(struct net_
 	switch (obj->id) {
 	case SWITCHDEV_OBJ_ID_PORT_VLAN:
 		vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
+#ifdef HAVE_STRUCT_SWITCHDEV_OBJ_PORT_VLAN_VID
 		mlx5_esw_bridge_port_vlan_del(vport_num, esw_owner_vhca_id, vlan->vid, br_offloads);
+#else
+		for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
+			mlx5_esw_bridge_port_vlan_del(vport_num, esw_owner_vhca_id, vid, br_offloads);
+		}
+#endif
 		break;
 	case SWITCHDEV_OBJ_ID_PORT_MDB:
 		mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
@@ -300,7 +319,11 @@ mlx5_esw_bridge_port_obj_attr_set(struct
 
 	switch (attr->id) {
 	case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
+#ifdef HAVE_STRUCT_SWITCHDEV_BRPORT_FLAGS
 		if (attr->u.brport_flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD)) {
+#else
+		if (attr->u.brport_flags & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD)) {
+#endif
 			NL_SET_ERR_MSG_MOD(extack, "Flag is not supported");
 			err = -EINVAL;
 		}
@@ -315,12 +338,14 @@ mlx5_esw_bridge_port_obj_attr_set(struct
 		err = mlx5_esw_bridge_vlan_filtering_set(vport_num, esw_owner_vhca_id,
 							 attr->u.vlan_filtering, br_offloads);
 		break;
+#ifdef HAVE_SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL
 	case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL:
 		err = mlx5_esw_bridge_vlan_proto_set(vport_num,
 						     esw_owner_vhca_id,
 						     attr->u.vlan_protocol,
 						     br_offloads);
 		break;
+#endif
 	case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
 		err = mlx5_esw_bridge_mcast_set(vport_num, esw_owner_vhca_id,
 						!attr->u.mc_disabled, br_offloads);
@@ -554,7 +579,11 @@ void mlx5e_rep_bridge_init(struct mlx5e_
 	}
 
 	br_offloads->netdev_nb.notifier_call = mlx5_esw_bridge_switchdev_port_event;
+#ifdef HAVE_UNREGISTER_NETDEVICE_NOTIFIER_NET
 	err = register_netdevice_notifier_net(&init_net, &br_offloads->netdev_nb);
+#else
+	err = register_netdevice_notifier(&br_offloads->netdev_nb);
+#endif
 	if (err) {
 		esw_warn(mdev, "Failed to register bridge offloads netdevice notifier (err=%d)\n",
 			 err);
@@ -589,7 +618,11 @@ void mlx5e_rep_bridge_cleanup(struct mlx
 		return;
 
 	cancel_delayed_work_sync(&br_offloads->update_work);
+#ifdef HAVE_UNREGISTER_NETDEVICE_NOTIFIER_NET
 	unregister_netdevice_notifier_net(&init_net, &br_offloads->netdev_nb);
+#else
+	unregister_netdevice_notifier(&br_offloads->netdev_nb);
+#endif
 	unregister_switchdev_blocking_notifier(&br_offloads->nb_blk);
 	unregister_switchdev_notifier(&br_offloads->nb);
 	destroy_workqueue(br_offloads->wq);
