From 0c1d1f8c98f5531b8236124011a4b1bf137f752c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 31 Mar 2019 16:26:45 +0000 Subject: [PATCH] qla2x00t-32gbit, target: Backport to kernel v3.11 and before Note: this code has not yet been tested. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8115 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c | 20 +++++++++++++++---- qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.h | 4 +++- qla2x00t-32gbit/qla_target.h | 7 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c index 2533374a3..6e3d7d6ee 100644 --- a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c +++ b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c @@ -445,7 +445,7 @@ static void sqa_qla2xxx_rel_cmd(struct qla_tgt_cmd *cmd) sbitmap_queue_clear(&sqa_tgt->tgt_tag_pool, cmd->se_cmd.map_tag, cmd->se_cmd.map_cpu); #else -#error Neither percpu_ida nor sbitmap are available. + clear_bit(cmd->map_tag, sqa_tgt->tgt_tag_pool); #endif } @@ -463,7 +463,16 @@ static struct qla_tgt_cmd *sqa_qla2xxx_get_cmd(struct fc_port *sess) tag = sbitmap_queue_get(&sqa_tgt->tgt_tag_pool, &cpu); #else -#error Neither percpu_ida nor sbitmap are available. + for (;;) { + tag = find_first_zero_bit(sqa_tgt->tgt_tag_pool, + sqa_tgt->tag_num); + if (test_and_set_bit(tag, sqa_tgt->tgt_tag_pool) == 0) + break; + if (tag >= sqa_tgt->tag_num) { + tag = -ENOENT; + break; + } + } #endif if (tag < 0) return NULL; @@ -1464,10 +1473,13 @@ static int sqa_init_scst_tgt(struct scsi_qla_host *vha) res = sbitmap_queue_init_node(&sqa_tgt->tgt_tag_pool, tag_num, -1, false, GFP_KERNEL, NUMA_NO_NODE); #else -#error Neither percpu_ida nor sbitmap are available. + sqa_tgt->tag_num = tag_num; + sqa_tgt->tgt_tag_pool = kzalloc(BITS_TO_LONGS(tag_num), GFP_KERNEL); + res = IS_ERR(sqa_tgt->tgt_tag_pool) ? PTR_ERR(sqa_tgt->tgt_tag_pool) : + 0; #endif if (res < 0) { - pr_err("Unable to init se_sess->sess_tag_pool," + pr_err("Unable to init se_sess->tgt_tag_pool," " tag_num: %u\n", tag_num); kvfree(sqa_tgt->tgt_cmd_map); kfree(pwwn); diff --git a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.h b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.h index 8848cc871..2350cf5c8 100644 --- a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.h +++ b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.h @@ -3,6 +3,7 @@ !(defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) #define QLT_USE_PERCPU_IDA 0 #define QLT_USE_SBITMAP 0 +#include #elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) #define QLT_USE_PERCPU_IDA 1 #define QLT_USE_SBITMAP 0 @@ -30,6 +31,7 @@ struct sqa_scst_tgt{ #elif QLT_USE_SBITMAP struct sbitmap_queue tgt_tag_pool; #else -#error Neither percpu_ida nor sbitmap are available. + unsigned long *tgt_tag_pool; + unsigned int tag_num; #endif }; diff --git a/qla2x00t-32gbit/qla_target.h b/qla2x00t-32gbit/qla_target.h index 3414c203d..8ec9d7741 100644 --- a/qla2x00t-32gbit/qla_target.h +++ b/qla2x00t-32gbit/qla_target.h @@ -899,6 +899,13 @@ struct qla_tgt_cmd { uint8_t cmd_type; uint8_t pad[7]; struct se_cmd se_cmd; +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0) + /* + * Used if neither nor are + * available. + */ + unsigned int map_tag; +#endif #if !HAVE_SE_CMD_TAG u64 tag; #endif