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

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

--- a/net/mlxdevm/mlxdevm.c
+++ b/net/mlxdevm/mlxdevm.c
@@ -1476,7 +1476,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;
@@ -1776,7 +1780,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;
@@ -1798,7 +1806,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;
@@ -2427,83 +2439,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,
 	},
@@ -2513,13 +2563,17 @@ 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,
 	.parallel_ops = true,
 	.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)
