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
@@ -1480,7 +1480,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;
@@ -1825,7 +1829,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;
@@ -1847,7 +1855,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;
@@ -2534,83 +2546,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,
 	},
@@ -2620,13 +2670,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)
