From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: net/mlxdevm/mlxdevm.c

Change-Id: I4f75139b210dc01aa08d199bb5042ddd322dac06
---
 net/mlxdevm/mlxdevm.c | 74 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

--- a/net/mlxdevm/mlxdevm.c
+++ b/net/mlxdevm/mlxdevm.c
@@ -1438,7 +1438,11 @@ static int mlxdevm_nl_cmd_port_get_dumpi
 						   NETLINK_CB(cb->skb).portid,
 						   cb->nlh->nlmsg_seq,
 						   NLM_F_MULTI,
+#ifdef HAVE_NETLINK_CALLBACK_EXTACK
 						   cb->extack);
+#else
+						   NULL);
+#endif
 			if (err) {
 				up_read(&dev->port_list_rwsem);
 				goto out;
@@ -1738,7 +1742,11 @@ static int mlxdevm_nl_cmd_rate_get_dumpi
 						   NETLINK_CB(cb->skb).portid,
 						   cb->nlh->nlmsg_seq,
 						   NLM_F_MULTI,
+#ifdef HAVE_NETLINK_CALLBACK_EXTACK
 						   cb->extack);
+#else
+						   NULL);
+#endif
 			if (err) {
 				up_read(&dev->rate_group_rwsem);
 				goto out;
@@ -1760,7 +1768,11 @@ static int mlxdevm_nl_cmd_rate_get_dumpi
 						   NETLINK_CB(cb->skb).portid,
 						   cb->nlh->nlmsg_seq,
 						   NLM_F_MULTI,
+#ifdef HAVE_NETLINK_CALLBACK_EXTACK
 						   cb->extack);
+#else
+						   NULL);
+#endif
 			if (err) {
 				up_read(&dev->port_list_rwsem);
 				goto out;
@@ -2173,6 +2185,9 @@ mlxdevm_nl_cmd_port_new_doit(struct sk_b
 	struct mlxdevm_port_new_attrs new_attrs = {};
 	struct mlxdevm *dev;
 	unsigned int new_port_index;
+#ifdef HAVE_DEVLINK_PORT_OPS
+	struct devlink_port *devlink_port;
+#endif
 	int err;
 
 	mutex_lock(&mlxdevm_mutex);
@@ -2219,10 +2234,17 @@ mlxdevm_nl_cmd_port_new_doit(struct sk_b
 		new_attrs.sfnum_valid = true;
 	}
 
+#ifdef HAVE_DEVLINK_PORT_OPS
+	err = dev->ops->port_new(dev, &new_attrs, extack, &devlink_port);
+#else
 	err = dev->ops->port_new(dev, &new_attrs, extack, &new_port_index);
+#endif
 	if (err)
 		goto out;
 
+#ifdef HAVE_DEVLINK_PORT_OPS
+	        new_port_index = devlink_port->index;
+#endif
 	err = mlxdevm_port_new_notifiy(dev, new_port_index, info);
 	if (err && err != -ENODEV) {
 		/* Fail to send the response; destroy newly created port. */
@@ -2365,74 +2387,121 @@ static const struct nla_policy mlxdevm_n
 static const struct genl_ops mlxdevm_nl_ops[] = {
 	{
 		.cmd = MLXDEVM_CMD_DEV_GET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_dev_get_doit,
 		.dumpit = mlxdevm_nl_cmd_dev_get_dumpit,
 	},
 	{
 		.cmd = MLXDEVM_CMD_PORT_SET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_port_set_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_PORT_GET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_port_get_doit,
 		.dumpit = mlxdevm_nl_cmd_port_get_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
 	{
 		.cmd = MLXDEVM_CMD_PORT_NEW,
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_port_new_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_PORT_DEL,
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_port_del_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_PARAM_GET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
 		.doit = mlxdevm_nl_cmd_param_get_doit,
 		.dumpit = mlxdevm_nl_cmd_param_get_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
 	{
 		.cmd = MLXDEVM_CMD_PARAM_SET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
 		.doit = mlxdevm_nl_cmd_param_set_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_EXT_CAP_SET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
 		.doit = mlxdevm_nl_cmd_port_fn_cap_set_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_EXT_RATE_SET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_rate_set_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_EXT_RATE_GET,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_rate_get_doit,
 		.dumpit = mlxdevm_nl_cmd_rate_get_dumpit,
 		/* can be retrieved by unprivileged users */
 	},
 	{
 		.cmd = MLXDEVM_CMD_EXT_RATE_NEW,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_rate_new_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
 	{
 		.cmd = MLXDEVM_CMD_EXT_RATE_DEL,
+#ifdef HAVE_GENL_OPS_VALIDATE
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+#endif
+#ifndef HAVE_GENL_FAMILY_POLICY
+		.policy = mlxdevm_nl_policy,
+#endif
 		.doit = mlxdevm_nl_cmd_rate_del_doit,
 		.flags = GENL_ADMIN_PERM,
 	},
@@ -2442,11 +2511,16 @@ static struct genl_family mlxdevm_nl_fam
 	.name = MLXDEVM_GENL_NAME,
 	.version = MLXDEVM_GENL_VERSION,
 	.maxattr = MLXDEVM_ATTR_MAX,
+#ifdef HAVE_GENL_FAMILY_POLICY
 	.policy = mlxdevm_nl_policy,
+#endif
 	.netnsok = false,
 	.module = THIS_MODULE,
 	.ops = mlxdevm_nl_ops,
 	.n_ops = ARRAY_SIZE(mlxdevm_nl_ops),
+#ifdef HAVE_GENL_FAMILY_RESV_START_OP
+	.resv_start_op = MLXDEVM_CMD_MAX + 1,
+#endif
 };
 
 static int __init mlxdevm_init(void)
