From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/nvme/target/fc.c

---
 drivers/nvme/target/fc.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) 2016 Avago Technologies.  All rights reserved.
  */
+
 #ifdef pr_fmt
 #undef pr_fmt
 #endif
@@ -1146,7 +1147,11 @@ nvmet_fc_alloc_target_assoc(struct nvmet
 	if (!assoc)
 		return NULL;
 
+#ifdef HAVE_IDA_ALLOC
 	idx = ida_alloc(&tgtport->assoc_cnt, GFP_KERNEL);
+#else
+	idx = ida_simple_get(&tgtport->assoc_cnt, 0, 0, GFP_KERNEL);
+#endif
 	if (idx < 0)
 		goto out_free_assoc;
 
@@ -1180,7 +1185,11 @@ nvmet_fc_alloc_target_assoc(struct nvmet
 	return assoc;
 
 out_ida:
-	ida_free(&tgtport->assoc_cnt, idx);
+#ifdef HAVE_IDA_FREE
+ 	ida_free(&tgtport->assoc_cnt, idx);
+#else
+	ida_simple_remove(&tgtport->assoc_cnt, idx);
+#endif
 out_free_assoc:
 	kfree(assoc);
 	return NULL;
@@ -1211,7 +1220,11 @@ nvmet_fc_target_assoc_free(struct kref *
 	/* if pending Rcv Disconnect Association LS, send rsp now */
 	if (oldls)
 		nvmet_fc_xmt_ls_rsp(tgtport, oldls);
+#ifdef HAVE_IDA_FREE
 	ida_free(&tgtport->assoc_cnt, assoc->a_id);
+#else
+	ida_simple_remove(&tgtport->assoc_cnt, assoc->a_id);
+#endif
 	dev_info(tgtport->dev,
 		"{%d:%d} Association freed\n",
 		tgtport->fc_target_port.port_num, assoc->a_id);
@@ -1402,7 +1415,11 @@ nvmet_fc_register_targetport(struct nvme
 		goto out_regtgt_failed;
 	}
 
+#ifdef HAVE_IDA_ALLOC
 	idx = ida_alloc(&nvmet_fc_tgtport_cnt, GFP_KERNEL);
+#else
+	idx = ida_simple_get(&nvmet_fc_tgtport_cnt, 0, 0, GFP_KERNEL);
+#endif
 	if (idx < 0) {
 		ret = -ENOSPC;
 		goto out_fail_kfree;
@@ -1453,7 +1470,11 @@ nvmet_fc_register_targetport(struct nvme
 out_free_newrec:
 	put_device(dev);
 out_ida_put:
+#ifdef HAVE_IDA_FREE
 	ida_free(&nvmet_fc_tgtport_cnt, idx);
+#else
+	ida_simple_remove(&nvmet_fc_tgtport_cnt, idx);
+#endif
 out_fail_kfree:
 	kfree(newrec);
 out_regtgt_failed:
@@ -1480,8 +1501,13 @@ nvmet_fc_free_tgtport(struct kref *ref)
 	/* let the LLDD know we've finished tearing it down */
 	tgtport->ops->targetport_delete(&tgtport->fc_target_port);
 
+#ifdef HAVE_IDA_FREE
 	ida_free(&nvmet_fc_tgtport_cnt,
 			tgtport->fc_target_port.port_num);
+#else
+	ida_simple_remove(&nvmet_fc_tgtport_cnt,
+			tgtport->fc_target_port.port_num);
+#endif
 
 	ida_destroy(&tgtport->assoc_cnt);
 
@@ -2096,11 +2122,9 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_f
 {
 	struct scatterlist *sg;
 	unsigned int nent;
-
 	sg = sgl_alloc(fod->req.transfer_len, GFP_KERNEL, &nent);
 	if (!sg)
 		goto out;
-
 	fod->data_sg = sg;
 	fod->data_sg_cnt = nent;
 	fod->data_sg_cnt = fc_dma_map_sg(fod->tgtport->dev, sg, nent,
@@ -2110,7 +2134,6 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_f
 	fod->next_sg = fod->data_sg;
 
 	return 0;
-
 out:
 	return NVME_SC_INTERNAL;
 }
@@ -2969,3 +2992,7 @@ module_exit(nvmet_fc_exit_module);
 
 MODULE_DESCRIPTION("NVMe target FC transport driver");
 MODULE_LICENSE("GPL v2");
+#ifdef RETPOLINE_MLNX
+MODULE_INFO(retpoline, "Y");
+#endif
+
