mmc: Revert all packing related patches

The version of packing support excepted by the linux community is
slightly different from the one that was merged. This revert is needed
in order to upload the latest version from the linux community.

This patch reverts the following commits:
1.mmc: card: Add eMMC4.5 write packed commands unit-tests
  commit:  9b54d88c6a11ebfe069b7fdebcb521da21754c3f
2.mmc: card: Fix packing control enabling algorithm
  commit: e2ecb58a6c5011549aac3e86fb1c13e7b7c65104
3.mmc: block: Add MMC write packing statistics
  commit: e544d700e2dac1584a8172c4dc347d81ede203bd
4.mmc: msm_sdcc: enable the write packing control
  commit: 8afe8d2a98a1bbf3804162ff5c95a56226935f5a
5.mmc: msm_sdcc: Enable write packing capability
  commit: 25e2261a556c4393f79d58bce814bb3df34b9549
6.mmc: block: Add write packing control
  commit: 63c61d6d8b8f37c71b4162b3affffdf72ac06811
7.mmc: core: Support packed write command for eMMC4.5 device
  commit: 968c774ea6466fa7adbf2eac333220132acda306
8.mmc: core: Add packed command feature of eMMC4.5
  commit: 516994eee39282b8648b509e449ff83b49833209.

Change-Id: I8d5a3a2d035e66d81a6e32c4fecc65ea8f87865c
Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org>
diff --git a/Documentation/mmc/mmc-dev-attrs.txt b/Documentation/mmc/mmc-dev-attrs.txt
index 08f7312..22ae844 100644
--- a/Documentation/mmc/mmc-dev-attrs.txt
+++ b/Documentation/mmc/mmc-dev-attrs.txt
@@ -8,23 +8,6 @@
 
 	force_ro		Enforce read-only access even if write protect switch is off.
 
-	num_wr_reqs_to_start_packing 	This attribute is used to determine
-	the trigger for activating the write packing, in case the write
-	packing control feature is enabled.
-
-	When the MMC manages to reach a point where num_wr_reqs_to_start_packing
-	write requests could be packed, it enables the write packing feature.
-	This allows us to start the write packing only when it is beneficial
-	and has minimum affect on the read latency.
-
-	The number of potential packed requests that will trigger the packing
-	can be configured via sysfs by writing the required value to:
-	/sys/block/<block_dev_name>/num_wr_reqs_to_start_packing.
-
-	The default value of num_wr_reqs_to_start_packing was determined by
-	running parallel lmdd write and lmdd read operations and calculating
-	the max number of packed writes requests.
-
 SD and MMC Device Attributes
 ============================
 
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index 15254fb..ebb4afe 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -76,14 +76,3 @@
 
 	  This driver is only of interest to those developing or
 	  testing a host driver. Most people should say N here.
-
-config MMC_BLOCK_TEST
-	tristate "MMC block test"
-	depends on MMC_BLOCK && IOSCHED_TEST
-	default m
-	help
-	  MMC block test can be used with test iosched to test the MMC block
-	  device.
-	  Currently used to test eMMC 4.5 features (packed commands, sanitize,
-	  BKOPs).
-
diff --git a/drivers/mmc/card/Makefile b/drivers/mmc/card/Makefile
index d55107f..c73b406 100644
--- a/drivers/mmc/card/Makefile
+++ b/drivers/mmc/card/Makefile
@@ -8,4 +8,3 @@
 
 obj-$(CONFIG_SDIO_UART)		+= sdio_uart.o
 
-obj-$(CONFIG_MMC_BLOCK_TEST)		+= mmc_block_test.o
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 8b9d08b..63d2fa1 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -59,16 +59,6 @@
 #define INAND_CMD38_ARG_SECTRIM2 0x88
 
 #define MMC_SANITIZE_REQ_TIMEOUT 240000 /* msec */
-#define mmc_req_rel_wr(req)	(((req->cmd_flags & REQ_FUA) || \
-			(req->cmd_flags & REQ_META)) && \
-			(rq_data_dir(req) == WRITE))
-#define PACKED_CMD_VER		0x01
-#define PACKED_CMD_WR		0x02
-#define MMC_BLK_UPDATE_STOP_REASON(stats, reason)			\
-	do {								\
-		if (stats->enabled)					\
-			stats->pack_stop_reason[reason]++;		\
-	} while (0)
 
 static DEFINE_MUTEX(block_mutex);
 
@@ -120,26 +110,24 @@
 	struct device_attribute force_ro;
 	struct device_attribute power_ro_lock;
 	int	area_type;
-	struct device_attribute num_wr_reqs_to_start_packing;
 };
 
 static DEFINE_MUTEX(open_lock);
 
-enum {
-        MMC_PACKED_N_IDX = -1,
-        MMC_PACKED_N_ZERO,
-        MMC_PACKED_N_SINGLE,
+enum mmc_blk_status {
+	MMC_BLK_SUCCESS = 0,
+	MMC_BLK_PARTIAL,
+	MMC_BLK_CMD_ERR,
+	MMC_BLK_RETRY,
+	MMC_BLK_ABORT,
+	MMC_BLK_DATA_ERR,
+	MMC_BLK_ECC_ERR,
+	MMC_BLK_NOMEDIUM,
 };
 
 module_param(perdev_minors, int, 0444);
 MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
 
-static inline void mmc_blk_clear_packed(struct mmc_queue_req *mqrq)
-{
-        mqrq->packed_cmd = MMC_PACKED_NONE;
-        mqrq->packed_num = MMC_PACKED_N_ZERO;
-}
-
 static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
 {
 	struct mmc_blk_data *md;
@@ -273,38 +261,6 @@
 	return ret;
 }
 
-static ssize_t
-num_wr_reqs_to_start_packing_show(struct device *dev,
-				  struct device_attribute *attr, char *buf)
-{
-	struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
-	int num_wr_reqs_to_start_packing;
-	int ret;
-
-	num_wr_reqs_to_start_packing = md->queue.num_wr_reqs_to_start_packing;
-
-	ret = snprintf(buf, PAGE_SIZE, "%d\n", num_wr_reqs_to_start_packing);
-
-	mmc_blk_put(md);
-	return ret;
-}
-
-static ssize_t
-num_wr_reqs_to_start_packing_store(struct device *dev,
-				 struct device_attribute *attr,
-				 const char *buf, size_t count)
-{
-	int value;
-	struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
-
-	sscanf(buf, "%d", &value);
-	if (value >= 0)
-		md->queue.num_wr_reqs_to_start_packing = value;
-
-	mmc_blk_put(md);
-	return count;
-}
-
 static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
 {
 	struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
@@ -1140,60 +1096,12 @@
 	if (!brq->data.bytes_xfered)
 		return MMC_BLK_RETRY;
 
-	if (mq_mrq->packed_cmd != MMC_PACKED_NONE) {
-		if (unlikely(brq->data.blocks << 9 != brq->data.bytes_xfered))
-			return MMC_BLK_PARTIAL;
-		else
-			return MMC_BLK_SUCCESS;
-	}
-
 	if (blk_rq_bytes(req) != brq->data.bytes_xfered)
 		return MMC_BLK_PARTIAL;
 
 	return MMC_BLK_SUCCESS;
 }
 
-static int mmc_blk_packed_err_check(struct mmc_card *card,
-				    struct mmc_async_req *areq)
-{
-	struct mmc_queue_req *mq_rq = container_of(areq, struct mmc_queue_req,
-			mmc_active);
-	struct request *req = mq_rq->req;
-	int err, check, status;
-	u8 ext_csd[512];
-
-	check = mmc_blk_err_check(card, areq);
-	err = get_card_status(card, &status, 0);
-	if (err) {
-		pr_err("%s: error %d sending status command\n",
-				req->rq_disk->disk_name, err);
-		return MMC_BLK_ABORT;
-	}
-
-	if (status & R1_EXP_EVENT) {
-		err = mmc_send_ext_csd(card, ext_csd);
-		if (err) {
-			pr_err("%s: error %d sending ext_csd\n",
-					req->rq_disk->disk_name, err);
-			return MMC_BLK_ABORT;
-		}
-
-		if ((ext_csd[EXT_CSD_EXP_EVENTS_STATUS] &
-					EXT_CSD_PACKED_FAILURE) &&
-				(ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
-				 EXT_CSD_PACKED_GENERIC_ERROR)) {
-			if (ext_csd[EXT_CSD_PACKED_CMD_STATUS] &
-					EXT_CSD_PACKED_INDEXED_ERROR) {
-				mq_rq->packed_fail_idx =
-				  ext_csd[EXT_CSD_PACKED_FAILURE_INDEX] - 1;
-				return MMC_BLK_PARTIAL;
-			}
-		}
-	}
-
-	return check;
-}
-
 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
 			       struct mmc_card *card,
 			       int disable_multi,
@@ -1349,357 +1257,10 @@
 	mmc_queue_bounce_pre(mqrq);
 }
 
-static void mmc_blk_write_packing_control(struct mmc_queue *mq,
-					  struct request *req)
-{
-	struct mmc_host *host = mq->card->host;
-	int data_dir;
-
-	if (!(host->caps2 & MMC_CAP2_PACKED_WR))
-		return;
-
-	/*
-	 * In case the packing control is not supported by the host, it should
-	 * not have an effect on the write packing. Therefore we have to enable
-	 * the write packing
-	 */
-	if (!(host->caps2 & MMC_CAP2_PACKED_WR_CONTROL)) {
-		mq->wr_packing_enabled = true;
-		return;
-	}
-
-	if (!req || (req && (req->cmd_flags & REQ_FLUSH))) {
-		if (mq->num_of_potential_packed_wr_reqs >
-				mq->num_wr_reqs_to_start_packing)
-			mq->wr_packing_enabled = true;
-		mq->num_of_potential_packed_wr_reqs = 0;
-		return;
-	}
-
-	data_dir = rq_data_dir(req);
-
-	if (data_dir == READ) {
-		mq->num_of_potential_packed_wr_reqs = 0;
-		mq->wr_packing_enabled = false;
-		return;
-	} else if (data_dir == WRITE) {
-		mq->num_of_potential_packed_wr_reqs++;
-	}
-
-	if (mq->num_of_potential_packed_wr_reqs >
-			mq->num_wr_reqs_to_start_packing)
-		mq->wr_packing_enabled = true;
-
-}
-
-struct mmc_wr_pack_stats *mmc_blk_get_packed_statistics(struct mmc_card *card)
-{
-	if (!card)
-		return NULL;
-
-	return &card->wr_pack_stats;
-}
-EXPORT_SYMBOL(mmc_blk_get_packed_statistics);
-
-void mmc_blk_init_packed_statistics(struct mmc_card *card)
-{
-	int max_num_of_packed_reqs = 0;
-
-	if (!card || !card->wr_pack_stats.packing_events)
-		return;
-
-	max_num_of_packed_reqs = card->ext_csd.max_packed_writes;
-
-	spin_lock(&card->wr_pack_stats.lock);
-	memset(card->wr_pack_stats.packing_events, 0,
-		(max_num_of_packed_reqs + 1) *
-	       sizeof(*card->wr_pack_stats.packing_events));
-	memset(&card->wr_pack_stats.pack_stop_reason, 0,
-		sizeof(card->wr_pack_stats.pack_stop_reason));
-	card->wr_pack_stats.enabled = true;
-	spin_unlock(&card->wr_pack_stats.lock);
-}
-EXPORT_SYMBOL(mmc_blk_init_packed_statistics);
-
-void print_mmc_packing_stats(struct mmc_card *card)
-{
-	int i;
-	int max_num_of_packed_reqs = 0;
-
-	if ((!card) || (!card->wr_pack_stats.packing_events))
-		return;
-
-	max_num_of_packed_reqs = card->ext_csd.max_packed_writes;
-
-	spin_lock(&card->wr_pack_stats.lock);
-
-	pr_info("%s: write packing statistics:\n",
-		mmc_hostname(card->host));
-
-	for (i = 1 ; i <= max_num_of_packed_reqs ; ++i) {
-		if (card->wr_pack_stats.packing_events[i] != 0)
-			pr_info("%s: Packed %d reqs - %d times\n",
-				mmc_hostname(card->host), i,
-				card->wr_pack_stats.packing_events[i]);
-	}
-
-	pr_info("%s: stopped packing due to the following reasons:\n",
-		mmc_hostname(card->host));
-
-	if (card->wr_pack_stats.pack_stop_reason[EXCEEDS_SEGMENTS])
-		pr_info("%s: %d times: exceedmax num of segments\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[EXCEEDS_SEGMENTS]);
-	if (card->wr_pack_stats.pack_stop_reason[EXCEEDS_SECTORS])
-		pr_info("%s: %d times: exceeding the max num of sectors\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[EXCEEDS_SECTORS]);
-	if (card->wr_pack_stats.pack_stop_reason[WRONG_DATA_DIR])
-		pr_info("%s: %d times: wrong data direction\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[WRONG_DATA_DIR]);
-	if (card->wr_pack_stats.pack_stop_reason[FLUSH_OR_DISCARD])
-		pr_info("%s: %d times: flush or discard\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[FLUSH_OR_DISCARD]);
-	if (card->wr_pack_stats.pack_stop_reason[EMPTY_QUEUE])
-		pr_info("%s: %d times: empty queue\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[EMPTY_QUEUE]);
-	if (card->wr_pack_stats.pack_stop_reason[REL_WRITE])
-		pr_info("%s: %d times: rel write\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[REL_WRITE]);
-	if (card->wr_pack_stats.pack_stop_reason[THRESHOLD])
-		pr_info("%s: %d times: Threshold\n",
-			mmc_hostname(card->host),
-			card->wr_pack_stats.pack_stop_reason[THRESHOLD]);
-
-	spin_unlock(&card->wr_pack_stats.lock);
-}
-EXPORT_SYMBOL(print_mmc_packing_stats);
-
-static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
-{
-	struct request_queue *q = mq->queue;
-	struct mmc_card *card = mq->card;
-	struct request *cur = req, *next = NULL;
-	struct mmc_blk_data *md = mq->data;
-	bool en_rel_wr = card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN;
-	unsigned int req_sectors = 0, phys_segments = 0;
-	unsigned int max_blk_count, max_phys_segs;
-	u8 put_back = 0;
-	u8 max_packed_rw = 0;
-	u8 reqs = 0;
-	struct mmc_wr_pack_stats *stats = &card->wr_pack_stats;
-
-	mmc_blk_clear_packed(mq->mqrq_cur);
-
-	if (!(md->flags & MMC_BLK_CMD23) ||
-			!card->ext_csd.packed_event_en)
-		goto no_packed;
-
-	if (!mq->wr_packing_enabled)
-		goto no_packed;
-
-	if ((rq_data_dir(cur) == WRITE) &&
-			(card->host->caps2 & MMC_CAP2_PACKED_WR))
-		max_packed_rw = card->ext_csd.max_packed_writes;
-
-	if (max_packed_rw == 0)
-		goto no_packed;
-
-	if (mmc_req_rel_wr(cur) &&
-			(md->flags & MMC_BLK_REL_WR) &&
-			!en_rel_wr) {
-		goto no_packed;
-	}
-
-	max_blk_count = min(card->host->max_blk_count,
-			card->host->max_req_size >> 9);
-	if (unlikely(max_blk_count > 0xffff))
-		max_blk_count = 0xffff;
-
-	max_phys_segs = queue_max_segments(q);
-	req_sectors += blk_rq_sectors(cur);
-	phys_segments += cur->nr_phys_segments;
-
-	if (rq_data_dir(cur) == WRITE) {
-		req_sectors++;
-		phys_segments++;
-	}
-
-	spin_lock(&stats->lock);
-
-	while (reqs < max_packed_rw - 1) {
-		spin_lock_irq(q->queue_lock);
-		next = blk_fetch_request(q);
-		spin_unlock_irq(q->queue_lock);
-		if (!next) {
-			MMC_BLK_UPDATE_STOP_REASON(stats, EMPTY_QUEUE);
-			break;
-		}
-
-		if (next->cmd_flags & REQ_DISCARD ||
-				next->cmd_flags & REQ_FLUSH) {
-			MMC_BLK_UPDATE_STOP_REASON(stats, FLUSH_OR_DISCARD);
-			put_back = 1;
-			break;
-		}
-
-		if (rq_data_dir(cur) != rq_data_dir(next)) {
-			MMC_BLK_UPDATE_STOP_REASON(stats, WRONG_DATA_DIR);
-			put_back = 1;
-			break;
-		}
-
-		if (mmc_req_rel_wr(next) &&
-				(md->flags & MMC_BLK_REL_WR) &&
-				!en_rel_wr) {
-			MMC_BLK_UPDATE_STOP_REASON(stats, REL_WRITE);
-			put_back = 1;
-			break;
-		}
-
-		req_sectors += blk_rq_sectors(next);
-		if (req_sectors > max_blk_count) {
-			if (stats->enabled)
-				stats->pack_stop_reason[EXCEEDS_SECTORS]++;
-			put_back = 1;
-			break;
-		}
-
-		phys_segments +=  next->nr_phys_segments;
-		if (phys_segments > max_phys_segs) {
-			MMC_BLK_UPDATE_STOP_REASON(stats, EXCEEDS_SEGMENTS);
-			put_back = 1;
-			break;
-		}
-
-		if (rq_data_dir(next) == WRITE)
-			mq->num_of_potential_packed_wr_reqs++;
-		list_add_tail(&next->queuelist, &mq->mqrq_cur->packed_list);
-		cur = next;
-		reqs++;
-	}
-
-	if (put_back) {
-		spin_lock_irq(q->queue_lock);
-		blk_requeue_request(q, next);
-		spin_unlock_irq(q->queue_lock);
-	}
-
-	if (stats->enabled) {
-		if (reqs + 1 <= card->ext_csd.max_packed_writes)
-			stats->packing_events[reqs + 1]++;
-		if (reqs + 1 == max_packed_rw)
-			MMC_BLK_UPDATE_STOP_REASON(stats, THRESHOLD);
-	}
-
-	spin_unlock(&stats->lock);
-
-	if (reqs > 0) {
-		list_add(&req->queuelist, &mq->mqrq_cur->packed_list);
-		mq->mqrq_cur->packed_num = ++reqs;
-		return reqs;
-	}
-
-no_packed:
-	mmc_blk_clear_packed(mq->mqrq_cur);
-	return 0;
-}
-
-static void mmc_blk_packed_hdr_wrq_prep(struct mmc_queue_req *mqrq,
-					struct mmc_card *card,
-					struct mmc_queue *mq)
-{
-	struct mmc_blk_request *brq = &mqrq->brq;
-	struct request *req = mqrq->req;
-	struct request *prq;
-	struct mmc_blk_data *md = mq->data;
-	bool do_rel_wr;
-	u32 *packed_cmd_hdr = mqrq->packed_cmd_hdr;
-	u8 i = 1;
-
-	mqrq->packed_cmd = MMC_PACKED_WRITE;
-	mqrq->packed_blocks = 0;
-	mqrq->packed_fail_idx = MMC_PACKED_N_IDX;
-
-	memset(packed_cmd_hdr, 0, sizeof(mqrq->packed_cmd_hdr));
-	packed_cmd_hdr[0] = (mqrq->packed_num << 16) |
-		(PACKED_CMD_WR << 8) | PACKED_CMD_VER;
-
-	/*
-	 * Argument for each entry of packed group
-	 */
-	list_for_each_entry(prq, &mqrq->packed_list, queuelist) {
-		do_rel_wr = mmc_req_rel_wr(prq) && (md->flags & MMC_BLK_REL_WR);
-		/* Argument of CMD23*/
-		packed_cmd_hdr[(i * 2)] =
-			(do_rel_wr ? MMC_CMD23_ARG_REL_WR : 0) |
-			blk_rq_sectors(prq);
-		/* Argument of CMD18 or CMD25 */
-		packed_cmd_hdr[((i * 2)) + 1] =
-			mmc_card_blockaddr(card) ?
-			blk_rq_pos(prq) : blk_rq_pos(prq) << 9;
-		mqrq->packed_blocks += blk_rq_sectors(prq);
-		i++;
-	}
-
-	memset(brq, 0, sizeof(struct mmc_blk_request));
-	brq->mrq.cmd = &brq->cmd;
-	brq->mrq.data = &brq->data;
-	brq->mrq.sbc = &brq->sbc;
-	brq->mrq.stop = &brq->stop;
-
-	brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
-	brq->sbc.arg = MMC_CMD23_ARG_PACKED | (mqrq->packed_blocks + 1);
-	brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
-
-	brq->cmd.opcode = MMC_WRITE_MULTIPLE_BLOCK;
-	brq->cmd.arg = blk_rq_pos(req);
-	if (!mmc_card_blockaddr(card))
-		brq->cmd.arg <<= 9;
-	brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
-
-	brq->data.blksz = 512;
-	brq->data.blocks = mqrq->packed_blocks + 1;
-	brq->data.flags |= MMC_DATA_WRITE;
-	brq->data.fault_injected = false;
-
-	brq->stop.opcode = MMC_STOP_TRANSMISSION;
-	brq->stop.arg = 0;
-	brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
-
-	mmc_set_data_timeout(&brq->data, card);
-
-	brq->data.sg = mqrq->sg;
-	brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
-
-	mqrq->mmc_active.mrq = &brq->mrq;
-
-	/*
-	 * This is intended for packed commands tests usage - in case these
-	 * functions are not in use the respective pointers are NULL
-	 */
-	if (mq->err_check_fn)
-		mqrq->mmc_active.err_check = mq->err_check_fn;
-	else
-		mqrq->mmc_active.err_check = mmc_blk_packed_err_check;
-
-	if (mq->packed_test_fn)
-		mq->packed_test_fn(mq->queue, mqrq);
-
-	mmc_queue_bounce_pre(mqrq);
-}
-
 static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
 			   struct mmc_blk_request *brq, struct request *req,
 			   int ret)
 {
-	struct mmc_queue_req *mq_rq;
-	mq_rq = container_of(brq, struct mmc_queue_req, brq);
-
 	/*
 	 * If this is an SD card and we're writing, we can first
 	 * mark the known good sectors as ok.
@@ -1716,41 +1277,8 @@
 				ret = blk_end_request(req, 0, blocks << 9);
 		} else
 			ret = blk_end_request(req, 0, brq->data.bytes_xfered);
-	} else {
-		if (mq_rq->packed_cmd == MMC_PACKED_NONE) {
-			ret = blk_end_request(req, 0, brq->data.bytes_xfered);
-		}
-	}
-	return ret;
-}
-
-static int mmc_blk_end_packed_req(struct mmc_queue *mq,
-				  struct mmc_queue_req *mq_rq)
-{
-	struct request *prq;
-	int idx = mq_rq->packed_fail_idx, i = 0;
-	int ret = 0;
-
-	while (!list_empty(&mq_rq->packed_list)) {
-		prq = list_entry_rq(mq_rq->packed_list.next);
-		if (idx == i) {
-			/* retry from error index */
-			mq_rq->packed_num -= idx;
-			mq_rq->req = prq;
-			ret = 1;
-
-			if (mq_rq->packed_num == MMC_PACKED_N_SINGLE) {
-				list_del_init(&prq->queuelist);
-				mmc_blk_clear_packed(mq_rq);
-			}
-			return ret;
-		}
-		list_del_init(&prq->queuelist);
-		blk_end_request(prq, 0, blk_rq_bytes(prq));
-		i++;
-	}
-
-	mmc_blk_clear_packed(mq_rq);
+	} else
+		ret = blk_end_request(req, 0, brq->data.bytes_xfered);
 	return ret;
 }
 
@@ -1762,24 +1290,15 @@
 	int ret = 1, disable_multi = 0, retry = 0, type;
 	enum mmc_blk_status status;
 	struct mmc_queue_req *mq_rq;
-	struct request *req, *prq;
+	struct request *req;
 	struct mmc_async_req *areq;
-	const u8 packed_num = 2;
-	u8 reqs = 0;
 
 	if (!rqc && !mq->mqrq_prev->req)
 		return 0;
 
-	if (rqc)
-		reqs = mmc_blk_prep_packed_list(mq, rqc);
-
 	do {
 		if (rqc) {
-			if (reqs >= packed_num)
-				mmc_blk_packed_hdr_wrq_prep(mq->mqrq_cur,
-						card, mq);
-			else
-				mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
+			mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
 			areq = &mq->mqrq_cur->mmc_active;
 		} else
 			areq = NULL;
@@ -1800,15 +1319,8 @@
 			 * A block was successfully transferred.
 			 */
 			mmc_blk_reset_success(md, type);
-
-			if (mq_rq->packed_cmd != MMC_PACKED_NONE) {
-				ret = mmc_blk_end_packed_req(mq, mq_rq);
-				break;
-			} else {
-				ret = blk_end_request(req, 0,
+			ret = blk_end_request(req, 0,
 						brq->data.bytes_xfered);
-			}
-
 			/*
 			 * If the blk_end_request function returns non-zero even
 			 * though all data has been transferred and no errors
@@ -1841,8 +1353,7 @@
 			err = mmc_blk_reset(md, card->host, type);
 			if (!err)
 				break;
-			if (err == -ENODEV ||
-				mq_rq->packed_cmd != MMC_PACKED_NONE)
+			if (err == -ENODEV)
 				goto cmd_abort;
 			/* Fall through */
 		}
@@ -1869,62 +1380,26 @@
 		}
 
 		if (ret) {
-			if (mq_rq->packed_cmd == MMC_PACKED_NONE) {
-				/*
-				 * In case of a incomplete request
-				 * prepare it again and resend.
-				 */
-				mmc_blk_rw_rq_prep(mq_rq, card,
-						disable_multi, mq);
-				mmc_start_req(card->host,
-						&mq_rq->mmc_active, NULL);
-			} else {
-				mmc_blk_packed_hdr_wrq_prep(mq_rq, card, mq);
-				mmc_start_req(card->host,
-						&mq_rq->mmc_active, NULL);
-			}
+			/*
+			 * In case of a incomplete request
+			 * prepare it again and resend.
+			 */
+			mmc_blk_rw_rq_prep(mq_rq, card, disable_multi, mq);
+			mmc_start_req(card->host, &mq_rq->mmc_active, NULL);
 		}
 	} while (ret);
 
 	return 1;
 
  cmd_abort:
-	if (mq_rq->packed_cmd == MMC_PACKED_NONE) {
-		if (mmc_card_removed(card))
-			req->cmd_flags |= REQ_QUIET;
-		while (ret)
-			ret = blk_end_request(req, -EIO,
-					blk_rq_cur_bytes(req));
-	} else {
-		while (!list_empty(&mq_rq->packed_list)) {
-			prq = list_entry_rq(mq_rq->packed_list.next);
-			list_del_init(&prq->queuelist);
-			blk_end_request(prq, -EIO, blk_rq_bytes(prq));
-		}
-		mmc_blk_clear_packed(mq_rq);
-	}
+	if (mmc_card_removed(card))
+		req->cmd_flags |= REQ_QUIET;
+	while (ret)
+		ret = blk_end_request(req, -EIO,
+				blk_rq_cur_bytes(req));
 
  start_new_req:
 	if (rqc) {
-		/*
-		 * If current request is packed, it needs to put back.
-		 */
-		if (mq->mqrq_cur->packed_cmd != MMC_PACKED_NONE) {
-			while (!list_empty(&mq->mqrq_cur->packed_list)) {
-				prq = list_entry_rq(
-					mq->mqrq_cur->packed_list.prev);
-				if (prq->queuelist.prev !=
-						&mq->mqrq_cur->packed_list) {
-					list_del_init(&prq->queuelist);
-					spin_lock_irq(mq->queue->queue_lock);
-					blk_requeue_request(mq->queue, prq);
-					spin_unlock_irq(mq->queue->queue_lock);
-				} else {
-					list_del_init(&prq->queuelist);
-				}
-			}
-			mmc_blk_clear_packed(mq->mqrq_cur);
-		}
 		mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
 		mmc_start_req(card->host, &mq->mqrq_cur->mmc_active, NULL);
 	}
@@ -1958,8 +1433,6 @@
 		goto out;
 	}
 
-	mmc_blk_write_packing_control(mq, req);
-
 	if (req && req->cmd_flags & REQ_SANITIZE) {
 		/* complete ongoing async transfer before issuing sanitize */
 		if (card->host && card->host->areq)
@@ -2191,8 +1664,6 @@
 
 	if (md) {
 		card = md->queue.card;
-		device_remove_file(disk_to_dev(md->disk),
-				   &md->num_wr_reqs_to_start_packing);
 		if (md->disk->flags & GENHD_FL_UP) {
 			device_remove_file(disk_to_dev(md->disk), &md->force_ro);
 			if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
@@ -2260,16 +1731,6 @@
 			goto power_ro_lock_fail;
 	}
 
-	md->num_wr_reqs_to_start_packing.show =
-		num_wr_reqs_to_start_packing_show;
-	md->num_wr_reqs_to_start_packing.store =
-		num_wr_reqs_to_start_packing_store;
-	sysfs_attr_init(&md->num_wr_reqs_to_start_packing.attr);
-	md->num_wr_reqs_to_start_packing.attr.name =
-		"num_wr_reqs_to_start_packing";
-	md->num_wr_reqs_to_start_packing.attr.mode = S_IRUGO | S_IWUSR;
-	ret = device_create_file(disk_to_dev(md->disk),
-				 &md->num_wr_reqs_to_start_packing);
 	if (ret)
 		goto power_ro_lock_fail;
 
diff --git a/drivers/mmc/card/mmc_block_test.c b/drivers/mmc/card/mmc_block_test.c
deleted file mode 100644
index 871675c..0000000
--- a/drivers/mmc/card/mmc_block_test.c
+++ /dev/null
@@ -1,2068 +0,0 @@
-
-/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-/* MMC block test */
-
-#include <linux/module.h>
-#include <linux/blkdev.h>
-#include <linux/debugfs.h>
-#include <linux/mmc/card.h>
-#include <linux/mmc/host.h>
-#include <linux/delay.h>
-#include <linux/test-iosched.h>
-#include "queue.h"
-
-#define MODULE_NAME "mmc_block_test"
-#define TEST_MAX_SECTOR_RANGE		(600*1024*1024) /* 600 MB */
-#define TEST_MAX_BIOS_PER_REQ		120
-#define CMD23_PACKED_BIT	(1 << 30)
-#define LARGE_PRIME_1	1103515367
-#define LARGE_PRIME_2	35757
-#define PACKED_HDR_VER_MASK 0x000000FF
-#define PACKED_HDR_RW_MASK 0x0000FF00
-#define PACKED_HDR_NUM_REQS_MASK 0x00FF0000
-#define PACKED_HDR_BITS_16_TO_29_SET 0x3FFF0000
-#define SECTOR_SIZE 512
-#define NUM_OF_SECTORS_PER_BIO		((BIO_U32_SIZE * 4) / SECTOR_SIZE)
-#define BIO_TO_SECTOR(x)		(x * NUM_OF_SECTORS_PER_BIO)
-
-#define test_pr_debug(fmt, args...) pr_debug("%s: "fmt"\n", MODULE_NAME, args)
-#define test_pr_info(fmt, args...) pr_info("%s: "fmt"\n", MODULE_NAME, args)
-#define test_pr_err(fmt, args...) pr_err("%s: "fmt"\n", MODULE_NAME, args)
-
-#define SANITIZE_TEST_TIMEOUT 240000
-
-enum is_random {
-	NON_RANDOM_TEST,
-	RANDOM_TEST,
-};
-
-enum mmc_block_test_testcases {
-	/* Start of send write packing test group */
-	SEND_WRITE_PACKING_MIN_TESTCASE,
-	TEST_STOP_DUE_TO_READ = SEND_WRITE_PACKING_MIN_TESTCASE,
-	TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS,
-	TEST_STOP_DUE_TO_FLUSH,
-	TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS,
-	TEST_STOP_DUE_TO_EMPTY_QUEUE,
-	TEST_STOP_DUE_TO_MAX_REQ_NUM,
-	TEST_STOP_DUE_TO_THRESHOLD,
-	SEND_WRITE_PACKING_MAX_TESTCASE = TEST_STOP_DUE_TO_THRESHOLD,
-
-	/* Start of err check test group */
-	ERR_CHECK_MIN_TESTCASE,
-	TEST_RET_ABORT = ERR_CHECK_MIN_TESTCASE,
-	TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS,
-	TEST_RET_PARTIAL_FOLLOWED_BY_ABORT,
-	TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS,
-	TEST_RET_PARTIAL_MAX_FAIL_IDX,
-	TEST_RET_RETRY,
-	TEST_RET_CMD_ERR,
-	TEST_RET_DATA_ERR,
-	ERR_CHECK_MAX_TESTCASE = TEST_RET_DATA_ERR,
-
-	/* Start of send invalid test group */
-	INVALID_CMD_MIN_TESTCASE,
-	TEST_HDR_INVALID_VERSION = INVALID_CMD_MIN_TESTCASE,
-	TEST_HDR_WRONG_WRITE_CODE,
-	TEST_HDR_INVALID_RW_CODE,
-	TEST_HDR_DIFFERENT_ADDRESSES,
-	TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL,
-	TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL,
-	TEST_HDR_CMD23_PACKED_BIT_SET,
-	TEST_CMD23_MAX_PACKED_WRITES,
-	TEST_CMD23_ZERO_PACKED_WRITES,
-	TEST_CMD23_PACKED_BIT_UNSET,
-	TEST_CMD23_REL_WR_BIT_SET,
-	TEST_CMD23_BITS_16TO29_SET,
-	TEST_CMD23_HDR_BLK_NOT_IN_COUNT,
-	INVALID_CMD_MAX_TESTCASE = TEST_CMD23_HDR_BLK_NOT_IN_COUNT,
-
-	/*
-	 * Start of packing control test group.
-	 * in these next testcases the abbreviation FB = followed by
-	 */
-	PACKING_CONTROL_MIN_TESTCASE,
-	TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ =
-				PACKING_CONTROL_MIN_TESTCASE,
-	TEST_PACKING_EXP_N_OVER_TRIGGER,
-	TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ,
-	TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N,
-	TEST_PACKING_EXP_THRESHOLD_OVER_TRIGGER,
-	TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS,
-	TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS,
-	TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER,
-	TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER,
-	TEST_PACK_MIX_PACKED_NO_PACKED_PACKED,
-	TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED,
-	PACKING_CONTROL_MAX_TESTCASE = TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED,
-
-	TEST_WRITE_DISCARD_SANITIZE_READ,
-};
-
-enum mmc_block_test_group {
-	TEST_NO_GROUP,
-	TEST_GENERAL_GROUP,
-	TEST_SEND_WRITE_PACKING_GROUP,
-	TEST_ERR_CHECK_GROUP,
-	TEST_SEND_INVALID_GROUP,
-	TEST_PACKING_CONTROL_GROUP,
-};
-
-struct mmc_block_test_debug {
-	struct dentry *send_write_packing_test;
-	struct dentry *err_check_test;
-	struct dentry *send_invalid_packed_test;
-	struct dentry *random_test_seed;
-	struct dentry *packing_control_test;
-	struct dentry *discard_sanitize_test;
-};
-
-struct mmc_block_test_data {
-	/* The number of write requests that the test will issue */
-	int num_requests;
-	/* The expected write packing statistics for the current test */
-	struct mmc_wr_pack_stats exp_packed_stats;
-	/*
-	 * A user-defined seed for random choices of number of bios written in
-	 * a request, and of number of requests issued in a test
-	 * This field is randomly updated after each use
-	 */
-	unsigned int random_test_seed;
-	/* A retry counter used in err_check tests */
-	int err_check_counter;
-	/* Can be one of the values of enum test_group */
-	enum mmc_block_test_group test_group;
-	/*
-	 * Indicates if the current testcase is running with random values of
-	 * num_requests and num_bios (in each request)
-	 */
-	int is_random;
-	/* Data structure for debugfs dentrys */
-	struct mmc_block_test_debug debug;
-	/*
-	 * Data structure containing individual test information, including
-	 * self-defined specific data
-	 */
-	struct test_info test_info;
-	/* mmc block device test */
-	struct blk_dev_test_type bdt;
-};
-
-static struct mmc_block_test_data *mbtd;
-
-/*
- * A callback assigned to the packed_test_fn field.
- * Called from block layer in mmc_blk_packed_hdr_wrq_prep.
- * Here we alter the packed header or CMD23 in order to send an invalid
- * packed command to the card.
- */
-static void test_invalid_packed_cmd(struct request_queue *q,
-				    struct mmc_queue_req *mqrq)
-{
-	struct mmc_queue *mq = q->queuedata;
-	u32 *packed_cmd_hdr = mqrq->packed_cmd_hdr;
-	struct request *req = mqrq->req;
-	struct request *second_rq;
-	struct test_request *test_rq;
-	struct mmc_blk_request *brq = &mqrq->brq;
-	int num_requests;
-	int max_packed_reqs;
-
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return;
-	}
-
-	test_rq = (struct test_request *)req->elv.priv[0];
-	if (!test_rq) {
-		test_pr_err("%s: NULL test_rq", __func__);
-		return;
-	}
-	max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-
-	switch (mbtd->test_info.testcase) {
-	case TEST_HDR_INVALID_VERSION:
-		test_pr_info("%s: set invalid header version", __func__);
-		/* Put 0 in header version field (1 byte, offset 0 in header) */
-		packed_cmd_hdr[0] = packed_cmd_hdr[0] & ~PACKED_HDR_VER_MASK;
-		break;
-	case TEST_HDR_WRONG_WRITE_CODE:
-		test_pr_info("%s: wrong write code", __func__);
-		/* Set R/W field with R value (1 byte, offset 1 in header) */
-		packed_cmd_hdr[0] = packed_cmd_hdr[0] & ~PACKED_HDR_RW_MASK;
-		packed_cmd_hdr[0] = packed_cmd_hdr[0] | 0x00000100;
-		break;
-	case TEST_HDR_INVALID_RW_CODE:
-		test_pr_info("%s: invalid r/w code", __func__);
-		/* Set R/W field with invalid value */
-		packed_cmd_hdr[0] = packed_cmd_hdr[0] & ~PACKED_HDR_RW_MASK;
-		packed_cmd_hdr[0] = packed_cmd_hdr[0] | 0x00000400;
-		break;
-	case TEST_HDR_DIFFERENT_ADDRESSES:
-		test_pr_info("%s: different addresses", __func__);
-		second_rq = list_entry(req->queuelist.next, struct request,
-				queuelist);
-		test_pr_info("%s: test_rq->sector=%ld, second_rq->sector=%ld",
-			      __func__, (long)req->__sector,
-			     (long)second_rq->__sector);
-		/*
-		 * Put start sector of second write request in the first write
-		 * request's cmd25 argument in the packed header
-		 */
-		packed_cmd_hdr[3] = second_rq->__sector;
-		break;
-	case TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL:
-		test_pr_info("%s: request num smaller than actual" , __func__);
-		num_requests = (packed_cmd_hdr[0] & PACKED_HDR_NUM_REQS_MASK)
-									>> 16;
-		/* num of entries is decremented by 1 */
-		num_requests = (num_requests - 1) << 16;
-		/*
-		 * Set number of requests field in packed write header to be
-		 * smaller than the actual number (1 byte, offset 2 in header)
-		 */
-		packed_cmd_hdr[0] = (packed_cmd_hdr[0] &
-				     ~PACKED_HDR_NUM_REQS_MASK) + num_requests;
-		break;
-	case TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL:
-		test_pr_info("%s: request num larger than actual" , __func__);
-		num_requests = (packed_cmd_hdr[0] & PACKED_HDR_NUM_REQS_MASK)
-									>> 16;
-		/* num of entries is incremented by 1 */
-		num_requests = (num_requests + 1) << 16;
-		/*
-		 * Set number of requests field in packed write header to be
-		 * larger than the actual number (1 byte, offset 2 in header).
-		 */
-		packed_cmd_hdr[0] = (packed_cmd_hdr[0] &
-				     ~PACKED_HDR_NUM_REQS_MASK) + num_requests;
-		break;
-	case TEST_HDR_CMD23_PACKED_BIT_SET:
-		test_pr_info("%s: header CMD23 packed bit set" , __func__);
-		/*
-		 * Set packed bit (bit 30) in cmd23 argument of first and second
-		 * write requests in packed write header.
-		 * These are located at bytes 2 and 4 in packed write header
-		 */
-		packed_cmd_hdr[2] = packed_cmd_hdr[2] | CMD23_PACKED_BIT;
-		packed_cmd_hdr[4] = packed_cmd_hdr[4] | CMD23_PACKED_BIT;
-		break;
-	case TEST_CMD23_MAX_PACKED_WRITES:
-		test_pr_info("%s: CMD23 request num > max_packed_reqs",
-			      __func__);
-		/*
-		 * Set the individual packed cmd23 request num to
-		 * max_packed_reqs + 1
-		 */
-		brq->sbc.arg = MMC_CMD23_ARG_PACKED | (max_packed_reqs + 1);
-		break;
-	case TEST_CMD23_ZERO_PACKED_WRITES:
-		test_pr_info("%s: CMD23 request num = 0", __func__);
-		/* Set the individual packed cmd23 request num to zero */
-		brq->sbc.arg = MMC_CMD23_ARG_PACKED;
-		break;
-	case TEST_CMD23_PACKED_BIT_UNSET:
-		test_pr_info("%s: CMD23 packed bit unset", __func__);
-		/*
-		 * Set the individual packed cmd23 packed bit to 0,
-		 *  although there is a packed write request
-		 */
-		brq->sbc.arg &= ~CMD23_PACKED_BIT;
-		break;
-	case TEST_CMD23_REL_WR_BIT_SET:
-		test_pr_info("%s: CMD23 REL WR bit set", __func__);
-		/* Set the individual packed cmd23 reliable write bit */
-		brq->sbc.arg = MMC_CMD23_ARG_PACKED | MMC_CMD23_ARG_REL_WR;
-		break;
-	case TEST_CMD23_BITS_16TO29_SET:
-		test_pr_info("%s: CMD23 bits [16-29] set", __func__);
-		brq->sbc.arg = MMC_CMD23_ARG_PACKED |
-			PACKED_HDR_BITS_16_TO_29_SET;
-		break;
-	case TEST_CMD23_HDR_BLK_NOT_IN_COUNT:
-		test_pr_info("%s: CMD23 hdr not in block count", __func__);
-		brq->sbc.arg = MMC_CMD23_ARG_PACKED |
-		((rq_data_dir(req) == READ) ? 0 : mqrq->packed_blocks);
-		break;
-	default:
-		test_pr_err("%s: unexpected testcase %d",
-			__func__, mbtd->test_info.testcase);
-		break;
-	}
-}
-
-/*
- * A callback assigned to the err_check_fn field of the mmc_request by the
- * MMC/card/block layer.
- * Called upon request completion by the MMC/core layer.
- * Here we emulate an error return value from the card.
- */
-static int test_err_check(struct mmc_card *card, struct mmc_async_req *areq)
-{
-	struct mmc_queue_req *mq_rq = container_of(areq, struct mmc_queue_req,
-			mmc_active);
-	struct request_queue *req_q = test_iosched_get_req_queue();
-	struct mmc_queue *mq;
-	int max_packed_reqs;
-	int ret = 0;
-
-	if (req_q)
-		mq = req_q->queuedata;
-	else {
-		test_pr_err("%s: NULL request_queue", __func__);
-		return 0;
-	}
-
-	if (!mq) {
-		test_pr_err("%s: %s: NULL mq", __func__,
-			mmc_hostname(card->host));
-		return 0;
-	}
-
-	max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-
-	if (!mq_rq) {
-		test_pr_err("%s: %s: NULL mq_rq", __func__,
-			mmc_hostname(card->host));
-		return 0;
-	}
-
-	switch (mbtd->test_info.testcase) {
-	case TEST_RET_ABORT:
-		test_pr_info("%s: return abort", __func__);
-		ret = MMC_BLK_ABORT;
-		break;
-	case TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS:
-		test_pr_info("%s: return partial followed by success",
-			      __func__);
-		/*
-		 * Since in this testcase num_requests is always >= 2,
-		 * we can be sure that packed_fail_idx is always >= 1
-		 */
-		mq_rq->packed_fail_idx = (mbtd->num_requests / 2);
-		test_pr_info("%s: packed_fail_idx = %d"
-			, __func__, mq_rq->packed_fail_idx);
-		mq->err_check_fn = NULL;
-		ret = MMC_BLK_PARTIAL;
-		break;
-	case TEST_RET_PARTIAL_FOLLOWED_BY_ABORT:
-		if (!mbtd->err_check_counter) {
-			test_pr_info("%s: return partial followed by abort",
-				      __func__);
-			mbtd->err_check_counter++;
-			/*
-			 * Since in this testcase num_requests is always >= 3,
-			 * we have that packed_fail_idx is always >= 1
-			 */
-			mq_rq->packed_fail_idx = (mbtd->num_requests / 2);
-			test_pr_info("%s: packed_fail_idx = %d"
-				, __func__, mq_rq->packed_fail_idx);
-			ret = MMC_BLK_PARTIAL;
-			break;
-		}
-		mbtd->err_check_counter = 0;
-		mq->err_check_fn = NULL;
-		ret = MMC_BLK_ABORT;
-		break;
-	case TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS:
-		test_pr_info("%s: return partial multiple until success",
-			     __func__);
-		if (++mbtd->err_check_counter >= (mbtd->num_requests)) {
-			mq->err_check_fn = NULL;
-			mbtd->err_check_counter = 0;
-			ret = MMC_BLK_PARTIAL;
-			break;
-		}
-		mq_rq->packed_fail_idx = 1;
-		ret = MMC_BLK_PARTIAL;
-		break;
-	case TEST_RET_PARTIAL_MAX_FAIL_IDX:
-		test_pr_info("%s: return partial max fail_idx", __func__);
-		mq_rq->packed_fail_idx = max_packed_reqs - 1;
-		mq->err_check_fn = NULL;
-		ret = MMC_BLK_PARTIAL;
-		break;
-	case TEST_RET_RETRY:
-		test_pr_info("%s: return retry", __func__);
-		ret = MMC_BLK_RETRY;
-		break;
-	case TEST_RET_CMD_ERR:
-		test_pr_info("%s: return cmd err", __func__);
-		ret = MMC_BLK_CMD_ERR;
-		break;
-	case TEST_RET_DATA_ERR:
-		test_pr_info("%s: return data err", __func__);
-		ret = MMC_BLK_DATA_ERR;
-		break;
-	default:
-		test_pr_err("%s: unexpected testcase %d",
-			__func__, mbtd->test_info.testcase);
-	}
-
-	return ret;
-}
-
-/*
- * This is a specific implementation for the get_test_case_str_fn function
- * pointer in the test_info data structure. Given a valid test_data instance,
- * the function returns a string resembling the test name, based on the testcase
- */
-static char *get_test_case_str(struct test_data *td)
-{
-	if (!td) {
-		test_pr_err("%s: NULL td", __func__);
-		return NULL;
-	}
-
-	switch (td->test_info.testcase) {
-	case TEST_STOP_DUE_TO_FLUSH:
-		return "Test stop due to flush";
-	case TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS:
-		return "Test stop due to flush after max-1 reqs";
-	case TEST_STOP_DUE_TO_READ:
-		return "Test stop due to read";
-	case TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS:
-		return "Test stop due to read after max-1 reqs";
-	case TEST_STOP_DUE_TO_EMPTY_QUEUE:
-		return "Test stop due to empty queue";
-	case TEST_STOP_DUE_TO_MAX_REQ_NUM:
-		return "Test stop due to max req num";
-	case TEST_STOP_DUE_TO_THRESHOLD:
-		return "Test stop due to exceeding threshold";
-	case TEST_RET_ABORT:
-		return "Test err_check return abort";
-	case TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS:
-		return "Test err_check return partial followed by success";
-	case TEST_RET_PARTIAL_FOLLOWED_BY_ABORT:
-		return "Test err_check return partial followed by abort";
-	case TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS:
-		return "Test err_check return partial multiple until success";
-	case TEST_RET_PARTIAL_MAX_FAIL_IDX:
-		return "Test err_check return partial max fail index";
-	case TEST_RET_RETRY:
-		return "Test err_check return retry";
-	case TEST_RET_CMD_ERR:
-		return "Test err_check return cmd error";
-	case TEST_RET_DATA_ERR:
-		return "Test err_check return data error";
-	case TEST_HDR_INVALID_VERSION:
-		return "Test invalid - wrong header version";
-	case TEST_HDR_WRONG_WRITE_CODE:
-		return "Test invalid - wrong write code";
-	case TEST_HDR_INVALID_RW_CODE:
-		return "Test invalid - wrong R/W code";
-	case TEST_HDR_DIFFERENT_ADDRESSES:
-		return "Test invalid - header different addresses";
-	case TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL:
-		return "Test invalid - header req num smaller than actual";
-	case TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL:
-		return "Test invalid - header req num larger than actual";
-	case TEST_HDR_CMD23_PACKED_BIT_SET:
-		return "Test invalid - header cmd23 packed bit set";
-	case TEST_CMD23_MAX_PACKED_WRITES:
-		return "Test invalid - cmd23 max packed writes";
-	case TEST_CMD23_ZERO_PACKED_WRITES:
-		return "Test invalid - cmd23 zero packed writes";
-	case TEST_CMD23_PACKED_BIT_UNSET:
-		return "Test invalid - cmd23 packed bit unset";
-	case TEST_CMD23_REL_WR_BIT_SET:
-		return "Test invalid - cmd23 rel wr bit set";
-	case TEST_CMD23_BITS_16TO29_SET:
-		return "Test invalid - cmd23 bits [16-29] set";
-	case TEST_CMD23_HDR_BLK_NOT_IN_COUNT:
-		return "Test invalid - cmd23 header block not in count";
-	case TEST_PACKING_EXP_N_OVER_TRIGGER:
-		return "\nTest packing control - pack n";
-	case TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ:
-		return "\nTest packing control - pack n followed by read";
-	case TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N:
-		return "\nTest packing control - pack n followed by flush";
-	case TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ:
-		return "\nTest packing control - pack one followed by read";
-	case TEST_PACKING_EXP_THRESHOLD_OVER_TRIGGER:
-		return "\nTest packing control - pack threshold";
-	case TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS:
-		return "\nTest packing control - no packing";
-	case TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS:
-		return "\nTest packing control - no packing, trigger requests";
-	case TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER:
-		return "\nTest packing control - no pack, trigger-read-trigger";
-	case TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER:
-		return "\nTest packing control- no pack, trigger-flush-trigger";
-	case TEST_PACK_MIX_PACKED_NO_PACKED_PACKED:
-		return "\nTest packing control - mix: pack -> no pack -> pack";
-	case TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED:
-		return "\nTest packing control - mix: no pack->pack->no pack";
-	case TEST_WRITE_DISCARD_SANITIZE_READ:
-		return "\nTest write, discard, sanitize";
-	default:
-		 return "Unknown testcase";
-	}
-
-	return NULL;
-}
-
-/*
- * Compare individual testcase's statistics to the expected statistics:
- * Compare stop reason and number of packing events
- */
-static int check_wr_packing_statistics(struct test_data *td)
-{
-	struct mmc_wr_pack_stats *mmc_packed_stats;
-	struct mmc_queue *mq = td->req_q->queuedata;
-	int max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-	int i;
-	struct mmc_card *card = mq->card;
-	struct mmc_wr_pack_stats expected_stats;
-	int *stop_reason;
-	int ret = 0;
-
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	expected_stats = mbtd->exp_packed_stats;
-
-	mmc_packed_stats = mmc_blk_get_packed_statistics(card);
-	if (!mmc_packed_stats) {
-		test_pr_err("%s: NULL mmc_packed_stats", __func__);
-		return -EINVAL;
-	}
-
-	if (!mmc_packed_stats->packing_events) {
-		test_pr_err("%s: NULL packing_events", __func__);
-		return -EINVAL;
-	}
-
-	spin_lock(&mmc_packed_stats->lock);
-
-	if (!mmc_packed_stats->enabled) {
-		test_pr_err("%s write packing statistics are not enabled",
-			     __func__);
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-	stop_reason = mmc_packed_stats->pack_stop_reason;
-
-	for (i = 1; i <= max_packed_reqs; ++i) {
-		if (mmc_packed_stats->packing_events[i] !=
-		    expected_stats.packing_events[i]) {
-			test_pr_err(
-			"%s: Wrong pack stats in index %d, got %d, expected %d",
-			__func__, i, mmc_packed_stats->packing_events[i],
-			       expected_stats.packing_events[i]);
-			if (td->fs_wr_reqs_during_test)
-				goto cancel_round;
-			ret = -EINVAL;
-			goto exit_err;
-		}
-	}
-
-	if (mmc_packed_stats->pack_stop_reason[EXCEEDS_SEGMENTS] !=
-	    expected_stats.pack_stop_reason[EXCEEDS_SEGMENTS]) {
-		test_pr_err(
-		"%s: Wrong pack stop reason EXCEEDS_SEGMENTS %d, expected %d",
-			__func__, stop_reason[EXCEEDS_SEGMENTS],
-		       expected_stats.pack_stop_reason[EXCEEDS_SEGMENTS]);
-		if (td->fs_wr_reqs_during_test)
-			goto cancel_round;
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-	if (mmc_packed_stats->pack_stop_reason[EXCEEDS_SECTORS] !=
-	    expected_stats.pack_stop_reason[EXCEEDS_SECTORS]) {
-		test_pr_err(
-		"%s: Wrong pack stop reason EXCEEDS_SECTORS %d, expected %d",
-			__func__, stop_reason[EXCEEDS_SECTORS],
-		       expected_stats.pack_stop_reason[EXCEEDS_SECTORS]);
-		if (td->fs_wr_reqs_during_test)
-			goto cancel_round;
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-	if (mmc_packed_stats->pack_stop_reason[WRONG_DATA_DIR] !=
-	    expected_stats.pack_stop_reason[WRONG_DATA_DIR]) {
-		test_pr_err(
-		"%s: Wrong pack stop reason WRONG_DATA_DIR %d, expected %d",
-		       __func__, stop_reason[WRONG_DATA_DIR],
-		       expected_stats.pack_stop_reason[WRONG_DATA_DIR]);
-		if (td->fs_wr_reqs_during_test)
-			goto cancel_round;
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-	if (mmc_packed_stats->pack_stop_reason[FLUSH_OR_DISCARD] !=
-	    expected_stats.pack_stop_reason[FLUSH_OR_DISCARD]) {
-		test_pr_err(
-		"%s: Wrong pack stop reason FLUSH_OR_DISCARD %d, expected %d",
-		       __func__, stop_reason[FLUSH_OR_DISCARD],
-		       expected_stats.pack_stop_reason[FLUSH_OR_DISCARD]);
-		if (td->fs_wr_reqs_during_test)
-			goto cancel_round;
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-	if (mmc_packed_stats->pack_stop_reason[EMPTY_QUEUE] !=
-	    expected_stats.pack_stop_reason[EMPTY_QUEUE]) {
-		test_pr_err(
-		"%s: Wrong pack stop reason EMPTY_QUEUE %d, expected %d",
-		       __func__, stop_reason[EMPTY_QUEUE],
-		       expected_stats.pack_stop_reason[EMPTY_QUEUE]);
-		if (td->fs_wr_reqs_during_test)
-			goto cancel_round;
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-	if (mmc_packed_stats->pack_stop_reason[REL_WRITE] !=
-	    expected_stats.pack_stop_reason[REL_WRITE]) {
-		test_pr_err(
-			"%s: Wrong pack stop reason REL_WRITE %d, expected %d",
-		       __func__, stop_reason[REL_WRITE],
-		       expected_stats.pack_stop_reason[REL_WRITE]);
-		if (td->fs_wr_reqs_during_test)
-			goto cancel_round;
-		ret = -EINVAL;
-		goto exit_err;
-	}
-
-exit_err:
-	spin_unlock(&mmc_packed_stats->lock);
-	if (ret && mmc_packed_stats->enabled)
-		print_mmc_packing_stats(card);
-	return ret;
-cancel_round:
-	spin_unlock(&mmc_packed_stats->lock);
-	test_iosched_set_ignore_round(true);
-	return 0;
-}
-
-/*
- * Pseudo-randomly choose a seed based on the last seed, and update it in
- * seed_number. then return seed_number (mod max_val), or min_val.
- */
-static unsigned int pseudo_random_seed(unsigned int *seed_number,
-				       unsigned int min_val,
-				       unsigned int max_val)
-{
-	int ret = 0;
-
-	if (!seed_number)
-		return 0;
-
-	*seed_number = ((unsigned int)(((unsigned long)*seed_number *
-				(unsigned long)LARGE_PRIME_1) + LARGE_PRIME_2));
-	ret = (unsigned int)((*seed_number) % max_val);
-
-	return (ret > min_val ? ret : min_val);
-}
-
-/*
- * Given a pseudo-random seed, find a pseudo-random num_of_bios.
- * Make sure that num_of_bios is not larger than TEST_MAX_SECTOR_RANGE
- */
-static void pseudo_rnd_num_of_bios(unsigned int *num_bios_seed,
-				   unsigned int *num_of_bios)
-{
-	do {
-		*num_of_bios = pseudo_random_seed(num_bios_seed, 1,
-						  TEST_MAX_BIOS_PER_REQ);
-		if (!(*num_of_bios))
-			*num_of_bios = 1;
-	} while ((*num_of_bios) * BIO_U32_SIZE * 4 > TEST_MAX_SECTOR_RANGE);
-}
-
-/* Add a single read request to the given td's request queue */
-static int prepare_request_add_read(struct test_data *td)
-{
-	int ret;
-	int start_sec;
-
-	if (td)
-		start_sec = td->start_sector;
-	else {
-		test_pr_err("%s: NULL td", __func__);
-		return 0;
-	}
-
-	test_pr_info("%s: Adding a read request, first req_id=%d", __func__,
-		     td->wr_rd_next_req_id);
-
-	ret = test_iosched_add_wr_rd_test_req(0, READ, start_sec, 2,
-					      TEST_PATTERN_5A, NULL);
-	if (ret) {
-		test_pr_err("%s: failed to add a read request", __func__);
-		return ret;
-	}
-
-	return 0;
-}
-
-/* Add a single flush request to the given td's request queue */
-static int prepare_request_add_flush(struct test_data *td)
-{
-	int ret;
-
-	if (!td) {
-		test_pr_err("%s: NULL td", __func__);
-		return 0;
-	}
-
-	test_pr_info("%s: Adding a flush request, first req_id=%d", __func__,
-		     td->unique_next_req_id);
-	ret = test_iosched_add_unique_test_req(0, REQ_UNIQUE_FLUSH,
-				  0, 0, NULL);
-	if (ret) {
-		test_pr_err("%s: failed to add a flush request", __func__);
-		return ret;
-	}
-
-	return ret;
-}
-
-/*
- * Add num_requets amount of write requests to the given td's request queue.
- * If random test mode is chosen we pseudo-randomly choose the number of bios
- * for each write request, otherwise add between 1 to 5 bio per request.
- */
-static int prepare_request_add_write_reqs(struct test_data *td,
-					  int num_requests, int is_err_expected,
-					  int is_random)
-{
-	int i;
-	unsigned int start_sec;
-	int num_bios;
-	int ret = 0;
-	unsigned int *bio_seed = &mbtd->random_test_seed;
-
-	if (td)
-		start_sec = td->start_sector;
-	else {
-		test_pr_err("%s: NULL td", __func__);
-		return ret;
-	}
-
-	test_pr_info("%s: Adding %d write requests, first req_id=%d", __func__,
-		     num_requests, td->wr_rd_next_req_id);
-
-	for (i = 1; i <= num_requests; i++) {
-		start_sec = td->start_sector + 4096 * td->num_of_write_bios;
-		if (is_random)
-			pseudo_rnd_num_of_bios(bio_seed, &num_bios);
-		else
-			/*
-			 * For the non-random case, give num_bios a value
-			 * between 1 and 5, to keep a small number of BIOs
-			 */
-			num_bios = (i%5)+1;
-
-		ret = test_iosched_add_wr_rd_test_req(is_err_expected, WRITE,
-				start_sec, num_bios, TEST_PATTERN_5A, NULL);
-
-		if (ret) {
-			test_pr_err("%s: failed to add a write request",
-				    __func__);
-			return ret;
-		}
-	}
-	return 0;
-}
-
-/*
- * Prepare the write, read and flush requests for a generic packed commands
- * testcase
- */
-static int prepare_packed_requests(struct test_data *td, int is_err_expected,
-				   int num_requests, int is_random)
-{
-	int ret = 0;
-	struct mmc_queue *mq;
-	int max_packed_reqs;
-	struct request_queue *req_q;
-
-	if (!td) {
-		pr_err("%s: NULL td", __func__);
-		return -EINVAL;
-	}
-
-	req_q = td->req_q;
-
-	if (!req_q) {
-		pr_err("%s: NULL request queue", __func__);
-		return -EINVAL;
-	}
-
-	mq = req_q->queuedata;
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-
-	if (mbtd->random_test_seed <= 0) {
-		mbtd->random_test_seed =
-			(unsigned int)(get_jiffies_64() & 0xFFFF);
-		test_pr_info("%s: got seed from jiffies %d",
-			     __func__, mbtd->random_test_seed);
-	}
-
-	mmc_blk_init_packed_statistics(mq->card);
-
-	ret = prepare_request_add_write_reqs(td, num_requests, is_err_expected,
-					     is_random);
-	if (ret)
-		return ret;
-
-	/* Avoid memory corruption in upcoming stats set */
-	if (td->test_info.testcase == TEST_STOP_DUE_TO_THRESHOLD)
-		num_requests--;
-
-	memset((void *)mbtd->exp_packed_stats.pack_stop_reason, 0,
-		sizeof(mbtd->exp_packed_stats.pack_stop_reason));
-	memset(mbtd->exp_packed_stats.packing_events, 0,
-		(max_packed_reqs + 1) * sizeof(u32));
-	if (num_requests <= max_packed_reqs)
-		mbtd->exp_packed_stats.packing_events[num_requests] = 1;
-
-	switch (td->test_info.testcase) {
-	case TEST_STOP_DUE_TO_FLUSH:
-	case TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS:
-		ret = prepare_request_add_flush(td);
-		if (ret)
-			return ret;
-
-		mbtd->exp_packed_stats.pack_stop_reason[FLUSH_OR_DISCARD] = 1;
-		break;
-	case TEST_STOP_DUE_TO_READ:
-	case TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS:
-		ret = prepare_request_add_read(td);
-		if (ret)
-			return ret;
-
-		mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
-		break;
-	case TEST_STOP_DUE_TO_THRESHOLD:
-		mbtd->exp_packed_stats.packing_events[num_requests] = 1;
-		mbtd->exp_packed_stats.packing_events[1] = 1;
-		mbtd->exp_packed_stats.pack_stop_reason[THRESHOLD] = 1;
-		mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
-		break;
-	case TEST_STOP_DUE_TO_MAX_REQ_NUM:
-	case TEST_RET_PARTIAL_MAX_FAIL_IDX:
-		mbtd->exp_packed_stats.pack_stop_reason[THRESHOLD] = 1;
-		break;
-	default:
-		mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
-	}
-	mbtd->num_requests = num_requests;
-
-	return 0;
-}
-
-/*
- * Prepare the write, read and flush requests for the packing control
- * testcases
- */
-static int prepare_packed_control_tests_requests(struct test_data *td,
-			int is_err_expected, int num_requests, int is_random)
-{
-	int ret = 0;
-	struct mmc_queue *mq;
-	int max_packed_reqs;
-	int temp_num_req = num_requests;
-	struct request_queue *req_q;
-	int test_packed_trigger;
-	int num_packed_reqs;
-
-	if (!td) {
-		test_pr_err("%s: NULL td\n", __func__);
-		return -EINVAL;
-	}
-
-	req_q = td->req_q;
-
-	if (!req_q) {
-		test_pr_err("%s: NULL request queue\n", __func__);
-		return -EINVAL;
-	}
-
-	mq = req_q->queuedata;
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-	test_packed_trigger = mq->num_wr_reqs_to_start_packing;
-	num_packed_reqs = num_requests - test_packed_trigger;
-
-	if (mbtd->random_test_seed == 0) {
-		mbtd->random_test_seed =
-			(unsigned int)(get_jiffies_64() & 0xFFFF);
-		test_pr_info("%s: got seed from jiffies %d",
-			     __func__, mbtd->random_test_seed);
-	}
-
-	mmc_blk_init_packed_statistics(mq->card);
-
-	if (td->test_info.testcase ==
-			TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED) {
-		temp_num_req = num_requests;
-		num_requests = test_packed_trigger - 1;
-	}
-
-	/* Verify that the packing is disabled before starting the test */
-	mq->wr_packing_enabled = false;
-	mq->num_of_potential_packed_wr_reqs = 0;
-
-	if (td->test_info.testcase == TEST_PACK_MIX_PACKED_NO_PACKED_PACKED) {
-		mq->num_of_potential_packed_wr_reqs = test_packed_trigger + 1;
-		mq->wr_packing_enabled = true;
-		num_requests = test_packed_trigger + 2;
-	}
-
-	ret = prepare_request_add_write_reqs(td, num_requests, is_err_expected,
-					     is_random);
-	if (ret)
-		goto exit;
-
-	if (td->test_info.testcase == TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED)
-		num_requests = temp_num_req;
-
-	memset((void *)mbtd->exp_packed_stats.pack_stop_reason, 0,
-		sizeof(mbtd->exp_packed_stats.pack_stop_reason));
-	memset(mbtd->exp_packed_stats.packing_events, 0,
-		(max_packed_reqs + 1) * sizeof(u32));
-
-	switch (td->test_info.testcase) {
-	case TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ:
-	case TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ:
-		ret = prepare_request_add_read(td);
-		if (ret)
-			goto exit;
-
-		mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
-		break;
-	case TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N:
-		ret = prepare_request_add_flush(td);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, num_packed_reqs,
-					     is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
-		mbtd->exp_packed_stats.pack_stop_reason[FLUSH_OR_DISCARD] = 1;
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 2;
-		break;
-	case TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER:
-		ret = prepare_request_add_read(td);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, test_packed_trigger,
-						    is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
-		break;
-	case TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER:
-		ret = prepare_request_add_flush(td);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, test_packed_trigger,
-						    is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
-		break;
-	case TEST_PACK_MIX_PACKED_NO_PACKED_PACKED:
-		ret = prepare_request_add_read(td);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, test_packed_trigger-1,
-						    is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, num_requests,
-						    is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		mbtd->exp_packed_stats.packing_events[num_requests] = 1;
-		mbtd->exp_packed_stats.packing_events[num_requests-1] = 1;
-		mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
-		mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
-		break;
-	case TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED:
-		ret = prepare_request_add_read(td);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, num_requests,
-						    is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_read(td);
-		if (ret)
-			goto exit;
-
-		ret = prepare_request_add_write_reqs(td, test_packed_trigger-1,
-						    is_err_expected, is_random);
-		if (ret)
-			goto exit;
-
-		mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
-		break;
-	case TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS:
-	case TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS:
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
-		break;
-	default:
-		mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
-		mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
-	}
-	mbtd->num_requests = num_requests;
-
-exit:
-	return ret;
-}
-
-/*
- * Prepare requests for the TEST_RET_PARTIAL_FOLLOWED_BY_ABORT testcase.
- * In this testcase we have mixed error expectations from different
- * write requests, hence the special prepare function.
- */
-static int prepare_partial_followed_by_abort(struct test_data *td,
-					      int num_requests)
-{
-	int i, start_address;
-	int is_err_expected = 0;
-	int ret = 0;
-	struct mmc_queue *mq = test_iosched_get_req_queue()->queuedata;
-	int max_packed_reqs;
-
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-
-	mmc_blk_init_packed_statistics(mq->card);
-
-	for (i = 1; i <= num_requests; i++) {
-		if (i > (num_requests / 2))
-			is_err_expected = 1;
-
-		start_address = td->start_sector + 4096 * td->num_of_write_bios;
-		ret = test_iosched_add_wr_rd_test_req(is_err_expected, WRITE,
-				start_address, (i % 5) + 1, TEST_PATTERN_5A,
-				NULL);
-		if (ret) {
-			test_pr_err("%s: failed to add a write request",
-				    __func__);
-			return ret;
-		}
-	}
-
-	memset((void *)&mbtd->exp_packed_stats.pack_stop_reason, 0,
-		sizeof(mbtd->exp_packed_stats.pack_stop_reason));
-	memset(mbtd->exp_packed_stats.packing_events, 0,
-		(max_packed_reqs + 1) * sizeof(u32));
-	mbtd->exp_packed_stats.packing_events[num_requests] = 1;
-	mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
-
-	mbtd->num_requests = num_requests;
-
-	return ret;
-}
-
-/*
- * Get number of write requests for current testcase. If random test mode was
- * chosen, pseudo-randomly choose the number of requests, otherwise set to
- * two less than the packing threshold.
- */
-static int get_num_requests(struct test_data *td)
-{
-	int *seed = &mbtd->random_test_seed;
-	struct request_queue *req_q;
-	struct mmc_queue *mq;
-	int max_num_requests;
-	int num_requests;
-	int min_num_requests = 2;
-	int is_random = mbtd->is_random;
-	int max_for_double;
-	int test_packed_trigger;
-
-	req_q = test_iosched_get_req_queue();
-	if (req_q)
-		mq = req_q->queuedata;
-	else {
-		test_pr_err("%s: NULL request queue", __func__);
-		return 0;
-	}
-
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	max_num_requests = mq->card->ext_csd.max_packed_writes;
-	num_requests = max_num_requests - 2;
-	test_packed_trigger = mq->num_wr_reqs_to_start_packing;
-
-	/*
-	 * Here max_for_double is intended for packed control testcases
-	 * in which we issue many write requests. It's purpose is to prevent
-	 * exceeding max number of req_queue requests.
-	 */
-	max_for_double = max_num_requests - 10;
-
-	if (td->test_info.testcase ==
-				TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS)
-		/* Don't expect packing, so issue up to trigger-1 reqs */
-		num_requests = test_packed_trigger - 1;
-
-	if (is_random) {
-		if (td->test_info.testcase ==
-		    TEST_RET_PARTIAL_FOLLOWED_BY_ABORT)
-			/*
-			 * Here we don't want num_requests to be less than 1
-			 * as a consequence of division by 2.
-			 */
-			min_num_requests = 3;
-
-		if (td->test_info.testcase ==
-				TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS)
-			/* Don't expect packing, so issue up to trigger reqs */
-			max_num_requests = test_packed_trigger;
-
-		num_requests = pseudo_random_seed(seed, min_num_requests,
-						  max_num_requests - 1);
-	}
-
-	if (td->test_info.testcase ==
-				TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS)
-		num_requests -= test_packed_trigger;
-
-	if (td->test_info.testcase == TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N)
-		num_requests =
-		num_requests > max_for_double ? max_for_double : num_requests;
-
-	if (mbtd->test_group == TEST_PACKING_CONTROL_GROUP)
-		num_requests += test_packed_trigger;
-
-	if (td->test_info.testcase == TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS)
-		num_requests = test_packed_trigger;
-
-	return num_requests;
-}
-
-/*
- * An implementation for the prepare_test_fn pointer in the test_info
- * data structure. According to the testcase we add the right number of requests
- * and decide if an error is expected or not.
- */
-static int prepare_test(struct test_data *td)
-{
-	struct mmc_queue *mq = test_iosched_get_req_queue()->queuedata;
-	int max_num_requests;
-	int num_requests = 0;
-	int ret = 0;
-	int is_random = mbtd->is_random;
-	int test_packed_trigger = mq->num_wr_reqs_to_start_packing;
-
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	max_num_requests = mq->card->ext_csd.max_packed_writes;
-
-	if (is_random && mbtd->random_test_seed == 0) {
-		mbtd->random_test_seed =
-			(unsigned int)(get_jiffies_64() & 0xFFFF);
-		test_pr_info("%s: got seed from jiffies %d",
-			__func__, mbtd->random_test_seed);
-	}
-
-	num_requests = get_num_requests(td);
-
-	if (mbtd->test_group == TEST_SEND_INVALID_GROUP)
-		mq->packed_test_fn =
-				test_invalid_packed_cmd;
-
-	if (mbtd->test_group == TEST_ERR_CHECK_GROUP)
-		mq->err_check_fn = test_err_check;
-
-	switch (td->test_info.testcase) {
-	case TEST_STOP_DUE_TO_FLUSH:
-	case TEST_STOP_DUE_TO_READ:
-	case TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS:
-	case TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS:
-	case TEST_STOP_DUE_TO_EMPTY_QUEUE:
-	case TEST_CMD23_PACKED_BIT_UNSET:
-		ret = prepare_packed_requests(td, 0, num_requests, is_random);
-		break;
-	case TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS:
-	case TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS:
-		ret = prepare_packed_requests(td, 0, max_num_requests - 1,
-					      is_random);
-		break;
-	case TEST_RET_PARTIAL_FOLLOWED_BY_ABORT:
-		ret = prepare_partial_followed_by_abort(td, num_requests);
-		break;
-	case TEST_STOP_DUE_TO_MAX_REQ_NUM:
-	case TEST_RET_PARTIAL_MAX_FAIL_IDX:
-		ret = prepare_packed_requests(td, 0, max_num_requests,
-					      is_random);
-		break;
-	case TEST_STOP_DUE_TO_THRESHOLD:
-		ret = prepare_packed_requests(td, 0, max_num_requests + 1,
-					      is_random);
-		break;
-	case TEST_RET_ABORT:
-	case TEST_RET_RETRY:
-	case TEST_RET_CMD_ERR:
-	case TEST_RET_DATA_ERR:
-	case TEST_HDR_INVALID_VERSION:
-	case TEST_HDR_WRONG_WRITE_CODE:
-	case TEST_HDR_INVALID_RW_CODE:
-	case TEST_HDR_DIFFERENT_ADDRESSES:
-	case TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL:
-	case TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL:
-	case TEST_CMD23_MAX_PACKED_WRITES:
-	case TEST_CMD23_ZERO_PACKED_WRITES:
-	case TEST_CMD23_REL_WR_BIT_SET:
-	case TEST_CMD23_BITS_16TO29_SET:
-	case TEST_CMD23_HDR_BLK_NOT_IN_COUNT:
-	case TEST_HDR_CMD23_PACKED_BIT_SET:
-		ret = prepare_packed_requests(td, 1, num_requests, is_random);
-		break;
-	case TEST_PACKING_EXP_N_OVER_TRIGGER:
-	case TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ:
-	case TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS:
-	case TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS:
-	case TEST_PACK_MIX_PACKED_NO_PACKED_PACKED:
-	case TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED:
-		ret = prepare_packed_control_tests_requests(td, 0, num_requests,
-			is_random);
-		break;
-	case TEST_PACKING_EXP_THRESHOLD_OVER_TRIGGER:
-		ret = prepare_packed_control_tests_requests(td, 0,
-			max_num_requests, is_random);
-		break;
-	case TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ:
-		ret = prepare_packed_control_tests_requests(td, 0,
-			test_packed_trigger + 1,
-					is_random);
-		break;
-	case TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N:
-		ret = prepare_packed_control_tests_requests(td, 0, num_requests,
-			is_random);
-		break;
-	case TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER:
-	case TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER:
-		ret = prepare_packed_control_tests_requests(td, 0,
-			test_packed_trigger, is_random);
-		break;
-	default:
-		test_pr_info("%s: Invalid test case...", __func__);
-		return -EINVAL;
-	}
-
-	return ret;
-}
-
-/*
- * An implementation for the post_test_fn in the test_info data structure.
- * In our case we just reset the function pointers in the mmc_queue in order for
- * the FS to be able to dispatch it's requests correctly after the test is
- * finished.
- */
-static int post_test(struct test_data *td)
-{
-	struct mmc_queue *mq;
-
-	if (!td)
-		return -EINVAL;
-
-	mq = td->req_q->queuedata;
-
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	mq->packed_test_fn = NULL;
-	mq->err_check_fn = NULL;
-
-	return 0;
-}
-
-/*
- * This function checks, based on the current test's test_group, that the
- * packed commands capability and control are set right. In addition, we check
- * if the card supports the packed command feature.
- */
-static int validate_packed_commands_settings(void)
-{
-	struct request_queue *req_q;
-	struct mmc_queue *mq;
-	int max_num_requests;
-	struct mmc_host *host;
-
-	req_q = test_iosched_get_req_queue();
-	if (!req_q) {
-		test_pr_err("%s: test_iosched_get_req_queue failed", __func__);
-		test_iosched_set_test_result(TEST_FAILED);
-		return -EINVAL;
-	}
-
-	mq = req_q->queuedata;
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return -EINVAL;
-	}
-
-	max_num_requests = mq->card->ext_csd.max_packed_writes;
-	host = mq->card->host;
-
-	if (!(host->caps2 && MMC_CAP2_PACKED_WR)) {
-		test_pr_err("%s: Packed Write capability disabled, exit test",
-			    __func__);
-		test_iosched_set_test_result(TEST_NOT_SUPPORTED);
-		return -EINVAL;
-	}
-
-	if (max_num_requests == 0) {
-		test_pr_err(
-		"%s: no write packing support, ext_csd.max_packed_writes=%d",
-		__func__, mq->card->ext_csd.max_packed_writes);
-		test_iosched_set_test_result(TEST_NOT_SUPPORTED);
-		return -EINVAL;
-	}
-
-	test_pr_info("%s: max number of packed requests supported is %d ",
-		     __func__, max_num_requests);
-
-	switch (mbtd->test_group) {
-	case TEST_SEND_WRITE_PACKING_GROUP:
-	case TEST_ERR_CHECK_GROUP:
-	case TEST_SEND_INVALID_GROUP:
-		/* disable the packing control */
-		host->caps2 &= ~MMC_CAP2_PACKED_WR_CONTROL;
-		break;
-	case TEST_PACKING_CONTROL_GROUP:
-		host->caps2 |=  MMC_CAP2_PACKED_WR_CONTROL;
-		break;
-	default:
-		break;
-	}
-
-	return 0;
-}
-
-static void pseudo_rnd_sector_and_size(unsigned int *seed,
-				       unsigned int min_start_sector,
-				       unsigned int *start_sector,
-				       unsigned int *num_of_bios)
-{
-	unsigned int max_sec = min_start_sector + TEST_MAX_SECTOR_RANGE;
-	do {
-		*start_sector = pseudo_random_seed(seed,
-						   1, max_sec);
-		*num_of_bios = pseudo_random_seed(seed,
-						  1, TEST_MAX_BIOS_PER_REQ);
-		if (!(*num_of_bios))
-			*num_of_bios = 1;
-	} while ((*start_sector < min_start_sector) ||
-		 (*start_sector + (*num_of_bios * BIO_U32_SIZE * 4)) > max_sec);
-}
-
-/* sanitize test functions */
-static int prepare_write_discard_sanitize_read(struct test_data *td)
-{
-	unsigned int start_sector;
-	unsigned int num_of_bios = 0;
-	static unsigned int total_bios;
-	unsigned int *num_bios_seed;
-	int i = 0;
-
-	if (mbtd->random_test_seed == 0) {
-		mbtd->random_test_seed =
-			(unsigned int)(get_jiffies_64() & 0xFFFF);
-		test_pr_info("%s: got seed from jiffies %d",
-			     __func__, mbtd->random_test_seed);
-	}
-	num_bios_seed = &mbtd->random_test_seed;
-
-	do {
-		pseudo_rnd_sector_and_size(num_bios_seed, td->start_sector,
-					   &start_sector, &num_of_bios);
-
-		/* DISCARD */
-		total_bios += num_of_bios;
-		test_pr_info("%s: discard req: id=%d, startSec=%d, NumBios=%d",
-		       __func__, td->unique_next_req_id, start_sector,
-			     num_of_bios);
-		test_iosched_add_unique_test_req(0, REQ_UNIQUE_DISCARD,
-				    start_sector, BIO_TO_SECTOR(num_of_bios),
-						 NULL);
-
-	} while (++i < (BLKDEV_MAX_RQ-10));
-
-	test_pr_info("%s: total discard bios = %d", __func__, total_bios);
-
-	test_pr_info("%s: add sanitize req", __func__);
-	test_iosched_add_unique_test_req(0, REQ_UNIQUE_SANITIZE, 0, 0, NULL);
-
-	return 0;
-}
-
-static bool message_repeat;
-static int test_open(struct inode *inode, struct file *file)
-{
-	file->private_data = inode->i_private;
-	message_repeat = 1;
-	return 0;
-}
-
-/* send_packing TEST */
-static ssize_t send_write_packing_test_write(struct file *file,
-				const char __user *buf,
-				size_t count,
-				loff_t *ppos)
-{
-	int ret = 0;
-	int i = 0;
-	int number = -1;
-	int j = 0;
-
-	test_pr_info("%s: -- send_write_packing TEST --", __func__);
-
-	sscanf(buf, "%d", &number);
-
-	if (number <= 0)
-		number = 1;
-
-
-	mbtd->test_group = TEST_SEND_WRITE_PACKING_GROUP;
-
-	if (validate_packed_commands_settings())
-		return count;
-
-	if (mbtd->random_test_seed > 0)
-		test_pr_info("%s: Test seed: %d", __func__,
-			      mbtd->random_test_seed);
-
-	memset(&mbtd->test_info, 0, sizeof(struct test_info));
-
-	mbtd->test_info.data = mbtd;
-	mbtd->test_info.prepare_test_fn = prepare_test;
-	mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
-	mbtd->test_info.get_test_case_str_fn = get_test_case_str;
-	mbtd->test_info.post_test_fn = post_test;
-
-	for (i = 0; i < number; ++i) {
-		test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
-		test_pr_info("%s: ====================", __func__);
-
-		for (j = SEND_WRITE_PACKING_MIN_TESTCASE;
-		      j <= SEND_WRITE_PACKING_MAX_TESTCASE; j++) {
-
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret)
-				break;
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = NON_RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret)
-				break;
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-		}
-	}
-
-	test_pr_info("%s: Completed all the test cases.", __func__);
-
-	return count;
-}
-
-static ssize_t send_write_packing_test_read(struct file *file,
-			       char __user *buffer,
-			       size_t count,
-			       loff_t *offset)
-{
-	memset((void *)buffer, 0, count);
-
-	snprintf(buffer, count,
-		 "\nsend_write_packing_test\n"
-		 "=========\n"
-		 "Description:\n"
-		 "This test checks the following scenarios\n"
-		 "- Pack due to FLUSH message\n"
-		 "- Pack due to FLUSH after threshold writes\n"
-		 "- Pack due to READ message\n"
-		 "- Pack due to READ after threshold writes\n"
-		 "- Pack due to empty queue\n"
-		 "- Pack due to threshold writes\n"
-		 "- Pack due to one over threshold writes\n");
-
-	if (message_repeat == 1) {
-		message_repeat = 0;
-		return strnlen(buffer, count);
-	} else {
-		return 0;
-	}
-}
-
-const struct file_operations send_write_packing_test_ops = {
-	.open = test_open,
-	.write = send_write_packing_test_write,
-	.read = send_write_packing_test_read,
-};
-
-/* err_check TEST */
-static ssize_t err_check_test_write(struct file *file,
-				const char __user *buf,
-				size_t count,
-				loff_t *ppos)
-{
-	int ret = 0;
-	int i = 0;
-	int number = -1;
-	int j = 0;
-
-	test_pr_info("%s: -- err_check TEST --", __func__);
-
-	sscanf(buf, "%d", &number);
-
-	if (number <= 0)
-		number = 1;
-
-	mbtd->test_group = TEST_ERR_CHECK_GROUP;
-
-	if (validate_packed_commands_settings())
-		return count;
-
-	if (mbtd->random_test_seed > 0)
-		test_pr_info("%s: Test seed: %d", __func__,
-			      mbtd->random_test_seed);
-
-	memset(&mbtd->test_info, 0, sizeof(struct test_info));
-
-	mbtd->test_info.data = mbtd;
-	mbtd->test_info.prepare_test_fn = prepare_test;
-	mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
-	mbtd->test_info.get_test_case_str_fn = get_test_case_str;
-	mbtd->test_info.post_test_fn = post_test;
-
-	for (i = 0; i < number; ++i) {
-		test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
-		test_pr_info("%s: ====================", __func__);
-
-		for (j = ERR_CHECK_MIN_TESTCASE;
-					j <= ERR_CHECK_MAX_TESTCASE ; j++) {
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret)
-				break;
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = NON_RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret)
-				break;
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-		}
-	}
-
-	test_pr_info("%s: Completed all the test cases.", __func__);
-
-	return count;
-}
-
-static ssize_t err_check_test_read(struct file *file,
-			       char __user *buffer,
-			       size_t count,
-			       loff_t *offset)
-{
-	memset((void *)buffer, 0, count);
-
-	snprintf(buffer, count,
-		 "\nerr_check_TEST\n"
-		 "=========\n"
-		 "Description:\n"
-		 "This test checks the following scenarios\n"
-		 "- Return ABORT\n"
-		 "- Return PARTIAL followed by success\n"
-		 "- Return PARTIAL followed by abort\n"
-		 "- Return PARTIAL multiple times until success\n"
-		 "- Return PARTIAL with fail index = threshold\n"
-		 "- Return RETRY\n"
-		 "- Return CMD_ERR\n"
-		 "- Return DATA_ERR\n");
-
-	if (message_repeat == 1) {
-		message_repeat = 0;
-		return strnlen(buffer, count);
-	} else {
-		return 0;
-	}
-}
-
-const struct file_operations err_check_test_ops = {
-	.open = test_open,
-	.write = err_check_test_write,
-	.read = err_check_test_read,
-};
-
-/* send_invalid_packed TEST */
-static ssize_t send_invalid_packed_test_write(struct file *file,
-				const char __user *buf,
-				size_t count,
-				loff_t *ppos)
-{
-	int ret = 0;
-	int i = 0;
-	int number = -1;
-	int j = 0;
-	int num_of_failures = 0;
-
-	test_pr_info("%s: -- send_invalid_packed TEST --", __func__);
-
-	sscanf(buf, "%d", &number);
-
-	if (number <= 0)
-		number = 1;
-
-	mbtd->test_group = TEST_SEND_INVALID_GROUP;
-
-	if (validate_packed_commands_settings())
-		return count;
-
-	if (mbtd->random_test_seed > 0)
-		test_pr_info("%s: Test seed: %d", __func__,
-			      mbtd->random_test_seed);
-
-	memset(&mbtd->test_info, 0, sizeof(struct test_info));
-
-	mbtd->test_info.data = mbtd;
-	mbtd->test_info.prepare_test_fn = prepare_test;
-	mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
-	mbtd->test_info.get_test_case_str_fn = get_test_case_str;
-	mbtd->test_info.post_test_fn = post_test;
-
-	for (i = 0; i < number; ++i) {
-		test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
-		test_pr_info("%s: ====================", __func__);
-
-		for (j = INVALID_CMD_MIN_TESTCASE;
-				j <= INVALID_CMD_MAX_TESTCASE ; j++) {
-
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret)
-				num_of_failures++;
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = NON_RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret)
-				num_of_failures++;
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-		}
-	}
-
-	test_pr_info("%s: Completed all the test cases.", __func__);
-
-	if (num_of_failures > 0) {
-		test_iosched_set_test_result(TEST_FAILED);
-		test_pr_err(
-			"There were %d failures during the test, TEST FAILED",
-			num_of_failures);
-	}
-	return count;
-}
-
-static ssize_t send_invalid_packed_test_read(struct file *file,
-			       char __user *buffer,
-			       size_t count,
-			       loff_t *offset)
-{
-	memset((void *)buffer, 0, count);
-
-	snprintf(buffer, count,
-		 "\nsend_invalid_packed_TEST\n"
-		 "=========\n"
-		 "Description:\n"
-		 "This test checks the following scenarios\n"
-		 "- Send an invalid header version\n"
-		 "- Send the wrong write code\n"
-		 "- Send an invalid R/W code\n"
-		 "- Send wrong start address in header\n"
-		 "- Send header with block_count smaller than actual\n"
-		 "- Send header with block_count larger than actual\n"
-		 "- Send header CMD23 packed bit set\n"
-		 "- Send CMD23 with block count over threshold\n"
-		 "- Send CMD23 with block_count equals zero\n"
-		 "- Send CMD23 packed bit unset\n"
-		 "- Send CMD23 reliable write bit set\n"
-		 "- Send CMD23 bits [16-29] set\n"
-		 "- Send CMD23 header block not in block_count\n");
-
-	if (message_repeat == 1) {
-		message_repeat = 0;
-		return strnlen(buffer, count);
-	} else {
-		return 0;
-	}
-}
-
-const struct file_operations send_invalid_packed_test_ops = {
-	.open = test_open,
-	.write = send_invalid_packed_test_write,
-	.read = send_invalid_packed_test_read,
-};
-
-/* packing_control TEST */
-static ssize_t write_packing_control_test_write(struct file *file,
-				const char __user *buf,
-				size_t count,
-				loff_t *ppos)
-{
-	int ret = 0;
-	int i = 0;
-	int number = -1;
-	int j = 0;
-	struct mmc_queue *mq = test_iosched_get_req_queue()->queuedata;
-	int max_num_requests = mq->card->ext_csd.max_packed_writes;
-	int test_successful = 1;
-
-	test_pr_info("%s: -- write_packing_control TEST --", __func__);
-
-	sscanf(buf, "%d", &number);
-
-	if (number <= 0)
-		number = 1;
-
-	test_pr_info("%s: max_num_requests = %d ", __func__,
-			max_num_requests);
-
-	memset(&mbtd->test_info, 0, sizeof(struct test_info));
-	mbtd->test_group = TEST_PACKING_CONTROL_GROUP;
-
-	if (validate_packed_commands_settings())
-		return count;
-
-	mbtd->test_info.data = mbtd;
-	mbtd->test_info.prepare_test_fn = prepare_test;
-	mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
-	mbtd->test_info.get_test_case_str_fn = get_test_case_str;
-
-	for (i = 0; i < number; ++i) {
-		test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
-		test_pr_info("%s: ====================", __func__);
-
-		for (j = PACKING_CONTROL_MIN_TESTCASE;
-				j <= PACKING_CONTROL_MAX_TESTCASE; j++) {
-
-			test_successful = 1;
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret) {
-				test_successful = 0;
-				break;
-			}
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-
-			mbtd->test_info.testcase = j;
-			mbtd->is_random = NON_RANDOM_TEST;
-			ret = test_iosched_start_test(&mbtd->test_info);
-			if (ret) {
-				test_successful = 0;
-				break;
-			}
-			/* Allow FS requests to be dispatched */
-			msleep(1000);
-		}
-
-		if (!test_successful)
-			break;
-	}
-
-	test_pr_info("%s: Completed all the test cases.", __func__);
-
-	return count;
-}
-
-static ssize_t write_packing_control_test_read(struct file *file,
-			       char __user *buffer,
-			       size_t count,
-			       loff_t *offset)
-{
-	memset((void *)buffer, 0, count);
-
-	snprintf(buffer, count,
-		 "\nwrite_packing_control_test\n"
-		 "=========\n"
-		 "Description:\n"
-		 "This test checks the following scenarios\n"
-		 "- Packing expected - one over trigger\n"
-		 "- Packing expected - N over trigger\n"
-		 "- Packing expected - N over trigger followed by read\n"
-		 "- Packing expected - N over trigger followed by flush\n"
-		 "- Packing expected - threshold over trigger FB by flush\n"
-		 "- Packing not expected - less than trigger\n"
-		 "- Packing not expected - trigger requests\n"
-		 "- Packing not expected - trigger, read, trigger\n"
-		 "- Mixed state - packing -> no packing -> packing\n"
-		 "- Mixed state - no packing -> packing -> no packing\n");
-
-	if (message_repeat == 1) {
-		message_repeat = 0;
-		return strnlen(buffer, count);
-	} else {
-		return 0;
-	}
-}
-
-const struct file_operations write_packing_control_test_ops = {
-	.open = test_open,
-	.write = write_packing_control_test_write,
-	.read = write_packing_control_test_read,
-};
-
-static ssize_t write_discard_sanitize_test_write(struct file *file,
-				const char __user *buf,
-				size_t count,
-				loff_t *ppos)
-{
-	int ret = 0;
-	int i = 0;
-	int number = -1;
-
-	sscanf(buf, "%d", &number);
-	if (number <= 0)
-		number = 1;
-
-	test_pr_info("%s: -- write_discard_sanitize TEST --\n", __func__);
-
-	memset(&mbtd->test_info, 0, sizeof(struct test_info));
-
-	mbtd->test_group = TEST_GENERAL_GROUP;
-
-	mbtd->test_info.data = mbtd;
-	mbtd->test_info.prepare_test_fn = prepare_write_discard_sanitize_read;
-	mbtd->test_info.get_test_case_str_fn = get_test_case_str;
-	mbtd->test_info.timeout_msec = SANITIZE_TEST_TIMEOUT;
-
-	for (i = 0 ; i < number ; ++i) {
-		test_pr_info("%s: Cycle # %d / %d\n", __func__, i+1, number);
-		test_pr_info("%s: ===================", __func__);
-
-		mbtd->test_info.testcase = TEST_WRITE_DISCARD_SANITIZE_READ;
-		ret = test_iosched_start_test(&mbtd->test_info);
-
-		if (ret)
-			break;
-	}
-
-	return count;
-}
-
-const struct file_operations write_discard_sanitize_test_ops = {
-	.open = test_open,
-	.write = write_discard_sanitize_test_write,
-};
-
-static void mmc_block_test_debugfs_cleanup(void)
-{
-	debugfs_remove(mbtd->debug.random_test_seed);
-	debugfs_remove(mbtd->debug.send_write_packing_test);
-	debugfs_remove(mbtd->debug.err_check_test);
-	debugfs_remove(mbtd->debug.send_invalid_packed_test);
-	debugfs_remove(mbtd->debug.packing_control_test);
-	debugfs_remove(mbtd->debug.discard_sanitize_test);
-}
-
-static int mmc_block_test_debugfs_init(void)
-{
-	struct dentry *utils_root, *tests_root;
-
-	utils_root = test_iosched_get_debugfs_utils_root();
-	tests_root = test_iosched_get_debugfs_tests_root();
-
-	if (!utils_root || !tests_root)
-		return -EINVAL;
-
-	mbtd->debug.random_test_seed = debugfs_create_u32(
-					"random_test_seed",
-					S_IRUGO | S_IWUGO,
-					utils_root,
-					&mbtd->random_test_seed);
-
-	if (!mbtd->debug.random_test_seed)
-		goto err_nomem;
-
-	mbtd->debug.send_write_packing_test =
-		debugfs_create_file("send_write_packing_test",
-				    S_IRUGO | S_IWUGO,
-				    tests_root,
-				    NULL,
-				    &send_write_packing_test_ops);
-
-	if (!mbtd->debug.send_write_packing_test)
-		goto err_nomem;
-
-	mbtd->debug.err_check_test =
-		debugfs_create_file("err_check_test",
-				    S_IRUGO | S_IWUGO,
-				    tests_root,
-				    NULL,
-				    &err_check_test_ops);
-
-	if (!mbtd->debug.err_check_test)
-		goto err_nomem;
-
-	mbtd->debug.send_invalid_packed_test =
-		debugfs_create_file("send_invalid_packed_test",
-				    S_IRUGO | S_IWUGO,
-				    tests_root,
-				    NULL,
-				    &send_invalid_packed_test_ops);
-
-	if (!mbtd->debug.send_invalid_packed_test)
-		goto err_nomem;
-
-	mbtd->debug.packing_control_test = debugfs_create_file(
-					"packing_control_test",
-					S_IRUGO | S_IWUGO,
-					tests_root,
-					NULL,
-					&write_packing_control_test_ops);
-
-	if (!mbtd->debug.packing_control_test)
-		goto err_nomem;
-
-	mbtd->debug.discard_sanitize_test =
-		debugfs_create_file("write_discard_sanitize_test",
-				    S_IRUGO | S_IWUGO,
-				    tests_root,
-				    NULL,
-				    &write_discard_sanitize_test_ops);
-	if (!mbtd->debug.discard_sanitize_test) {
-		mmc_block_test_debugfs_cleanup();
-		return -ENOMEM;
-	}
-
-	return 0;
-
-err_nomem:
-	mmc_block_test_debugfs_cleanup();
-	return -ENOMEM;
-}
-
-static void mmc_block_test_probe(void)
-{
-	struct request_queue *q = test_iosched_get_req_queue();
-	struct mmc_queue *mq;
-	int max_packed_reqs;
-
-	if (!q) {
-		test_pr_err("%s: NULL request queue", __func__);
-		return;
-	}
-
-	mq = q->queuedata;
-	if (!mq) {
-		test_pr_err("%s: NULL mq", __func__);
-		return;
-	}
-
-	max_packed_reqs = mq->card->ext_csd.max_packed_writes;
-	mbtd->exp_packed_stats.packing_events =
-			kzalloc((max_packed_reqs + 1) *
-				sizeof(*mbtd->exp_packed_stats.packing_events),
-				GFP_KERNEL);
-
-	mmc_block_test_debugfs_init();
-}
-
-static void mmc_block_test_remove(void)
-{
-	mmc_block_test_debugfs_cleanup();
-}
-
-static int __init mmc_block_test_init(void)
-{
-	mbtd = kzalloc(sizeof(struct mmc_block_test_data), GFP_KERNEL);
-	if (!mbtd) {
-		test_pr_err("%s: failed to allocate mmc_block_test_data",
-			    __func__);
-		return -ENODEV;
-	}
-
-	mbtd->bdt.init_fn = mmc_block_test_probe;
-	mbtd->bdt.exit_fn = mmc_block_test_remove;
-	INIT_LIST_HEAD(&mbtd->bdt.list);
-	test_iosched_register(&mbtd->bdt);
-
-	return 0;
-}
-
-static void __exit mmc_block_test_exit(void)
-{
-	test_iosched_unregister(&mbtd->bdt);
-	kfree(mbtd);
-}
-
-module_init(mmc_block_test_init);
-module_exit(mmc_block_test_exit);
-
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("MMC block test");
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index e1e4408..9e9dfcd 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -25,13 +25,6 @@
 #define MMC_QUEUE_SUSPENDED	(1 << 0)
 
 /*
- * Based on benchmark tests the default num of requests to trigger the write
- * packing was determined, to keep the read latency as low as possible and
- * manage to keep the high write throughput.
- */
-#define DEFAULT_NUM_REQS_TO_START_PACK 17
-
-/*
  * Prepare a MMC request. This just filters out odd stuff.
  */
 static int mmc_prep_request(struct request_queue *q, struct request *req)
@@ -190,12 +183,9 @@
 
 	memset(&mq->mqrq_cur, 0, sizeof(mq->mqrq_cur));
 	memset(&mq->mqrq_prev, 0, sizeof(mq->mqrq_prev));
-	INIT_LIST_HEAD(&mqrq_cur->packed_list);
-	INIT_LIST_HEAD(&mqrq_prev->packed_list);
 	mq->mqrq_cur = mqrq_cur;
 	mq->mqrq_prev = mqrq_prev;
 	mq->queue->queuedata = mq;
-	mq->num_wr_reqs_to_start_packing = DEFAULT_NUM_REQS_TO_START_PACK;
 
 	blk_queue_prep_rq(mq->queue, mmc_prep_request);
 	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
@@ -396,35 +386,6 @@
 	}
 }
 
-static unsigned int mmc_queue_packed_map_sg(struct mmc_queue *mq,
-					    struct mmc_queue_req *mqrq,
-					    struct scatterlist *sg)
-{
-	struct scatterlist *__sg;
-	unsigned int sg_len = 0;
-	struct request *req;
-	enum mmc_packed_cmd cmd;
-
-	cmd = mqrq->packed_cmd;
-
-	if (cmd == MMC_PACKED_WRITE) {
-		__sg = sg;
-		sg_set_buf(__sg, mqrq->packed_cmd_hdr,
-				sizeof(mqrq->packed_cmd_hdr));
-		sg_len++;
-		__sg->page_link &= ~0x02;
-	}
-
-	__sg = sg + sg_len;
-	list_for_each_entry(req, &mqrq->packed_list, queuelist) {
-		sg_len += blk_rq_map_sg(mq->queue, req, __sg);
-		__sg = sg + (sg_len - 1);
-		(__sg++)->page_link &= ~0x02;
-	}
-	sg_mark_end(sg + (sg_len - 1));
-	return sg_len;
-}
-
 /*
  * Prepare the sg list(s) to be handed of to the host driver
  */
@@ -435,19 +396,12 @@
 	struct scatterlist *sg;
 	int i;
 
-	if (!mqrq->bounce_buf) {
-		if (!list_empty(&mqrq->packed_list))
-			return mmc_queue_packed_map_sg(mq, mqrq, mqrq->sg);
-		else
-			return blk_rq_map_sg(mq->queue, mqrq->req, mqrq->sg);
-	}
+	if (!mqrq->bounce_buf)
+		return blk_rq_map_sg(mq->queue, mqrq->req, mqrq->sg);
 
 	BUG_ON(!mqrq->bounce_sg);
 
-	if (!list_empty(&mqrq->packed_list))
-		sg_len = mmc_queue_packed_map_sg(mq, mqrq, mqrq->bounce_sg);
-	else
-		sg_len = blk_rq_map_sg(mq->queue, mqrq->req, mqrq->bounce_sg);
+	sg_len = blk_rq_map_sg(mq->queue, mqrq->req, mqrq->bounce_sg);
 
 	mqrq->bounce_sg_len = sg_len;
 
diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h
index ec3d6d2..d2a1eb4 100644
--- a/drivers/mmc/card/queue.h
+++ b/drivers/mmc/card/queue.h
@@ -12,22 +12,6 @@
 	struct mmc_data		data;
 };
 
-enum mmc_blk_status {
-	MMC_BLK_SUCCESS = 0,
-	MMC_BLK_PARTIAL,
-	MMC_BLK_CMD_ERR,
-	MMC_BLK_RETRY,
-	MMC_BLK_ABORT,
-	MMC_BLK_DATA_ERR,
-	MMC_BLK_ECC_ERR,
-	MMC_BLK_NOMEDIUM,
-};
-
-enum mmc_packed_cmd {
-	MMC_PACKED_NONE = 0,
-	MMC_PACKED_WRITE,
-};
-
 struct mmc_queue_req {
 	struct request		*req;
 	struct mmc_blk_request	brq;
@@ -36,12 +20,6 @@
 	struct scatterlist	*bounce_sg;
 	unsigned int		bounce_sg_len;
 	struct mmc_async_req	mmc_active;
-	struct list_head	packed_list;
-	u32			packed_cmd_hdr[128];
-	unsigned int		packed_blocks;
-	enum mmc_packed_cmd	packed_cmd;
-	int		packed_fail_idx;
-	u8		packed_num;
 };
 
 struct mmc_queue {
@@ -55,11 +33,6 @@
 	struct mmc_queue_req	mqrq[2];
 	struct mmc_queue_req	*mqrq_cur;
 	struct mmc_queue_req	*mqrq_prev;
-	bool			wr_packing_enabled;
-	int			num_of_potential_packed_wr_reqs;
-	int			num_wr_reqs_to_start_packing;
-	int (*err_check_fn) (struct mmc_card *, struct mmc_async_req *);
-	void (*packed_test_fn) (struct request_queue *, struct mmc_queue_req *);
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
@@ -73,6 +46,4 @@
 extern void mmc_queue_bounce_pre(struct mmc_queue_req *);
 extern void mmc_queue_bounce_post(struct mmc_queue_req *);
 
-extern void print_mmc_packing_stats(struct mmc_card *card);
-
 #endif
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 0592f9d..33f7d29 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -254,8 +254,6 @@
 	card->dev.release = mmc_release_card;
 	card->dev.type = type;
 
-	spin_lock_init(&card->wr_pack_stats.lock);
-
 	return card;
 }
 
@@ -358,8 +356,6 @@
 		device_del(&card->dev);
 	}
 
-	kfree(card->wr_pack_stats.packing_events);
-
 	put_device(&card->dev);
 }
 
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 898e358..9ab5b17 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -318,164 +318,6 @@
 	.llseek		= default_llseek,
 };
 
-static int mmc_wr_pack_stats_open(struct inode *inode, struct file *filp)
-{
-	struct mmc_card *card = inode->i_private;
-
-	filp->private_data = card;
-	card->wr_pack_stats.print_in_read = 1;
-	return 0;
-}
-
-#define TEMP_BUF_SIZE 256
-static ssize_t mmc_wr_pack_stats_read(struct file *filp, char __user *ubuf,
-				size_t cnt, loff_t *ppos)
-{
-	struct mmc_card *card = filp->private_data;
-	struct mmc_wr_pack_stats *pack_stats;
-	int i;
-	int max_num_of_packed_reqs = 0;
-	char *temp_buf;
-
-	if (!card)
-		return cnt;
-
-	if (!card->wr_pack_stats.print_in_read)
-		return 0;
-
-	if (!card->wr_pack_stats.enabled) {
-		pr_info("%s: write packing statistics are disabled\n",
-			 mmc_hostname(card->host));
-		goto exit;
-	}
-
-	pack_stats = &card->wr_pack_stats;
-
-	if (!pack_stats->packing_events) {
-		pr_info("%s: NULL packing_events\n", mmc_hostname(card->host));
-		goto exit;
-	}
-
-	max_num_of_packed_reqs = card->ext_csd.max_packed_writes;
-
-	temp_buf = kmalloc(TEMP_BUF_SIZE, GFP_KERNEL);
-	if (!temp_buf)
-		goto exit;
-
-	spin_lock(&pack_stats->lock);
-
-	snprintf(temp_buf, TEMP_BUF_SIZE, "%s: write packing statistics:\n",
-		mmc_hostname(card->host));
-	strlcat(ubuf, temp_buf, cnt);
-
-	for (i = 1 ; i <= max_num_of_packed_reqs ; ++i) {
-		if (pack_stats->packing_events[i]) {
-			snprintf(temp_buf, TEMP_BUF_SIZE,
-				 "%s: Packed %d reqs - %d times\n",
-				mmc_hostname(card->host), i,
-				pack_stats->packing_events[i]);
-			strlcat(ubuf, temp_buf, cnt);
-		}
-	}
-
-	snprintf(temp_buf, TEMP_BUF_SIZE,
-		 "%s: stopped packing due to the following reasons:\n",
-		 mmc_hostname(card->host));
-	strlcat(ubuf, temp_buf, cnt);
-
-	if (pack_stats->pack_stop_reason[EXCEEDS_SEGMENTS]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: exceed max num of segments\n",
-			 mmc_hostname(card->host),
-			 pack_stats->pack_stop_reason[EXCEEDS_SEGMENTS]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-	if (pack_stats->pack_stop_reason[EXCEEDS_SECTORS]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: exceed max num of sectors\n",
-			mmc_hostname(card->host),
-			pack_stats->pack_stop_reason[EXCEEDS_SECTORS]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-	if (pack_stats->pack_stop_reason[WRONG_DATA_DIR]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: wrong data direction\n",
-			mmc_hostname(card->host),
-			pack_stats->pack_stop_reason[WRONG_DATA_DIR]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-	if (pack_stats->pack_stop_reason[FLUSH_OR_DISCARD]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: flush or discard\n",
-			mmc_hostname(card->host),
-			pack_stats->pack_stop_reason[FLUSH_OR_DISCARD]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-	if (pack_stats->pack_stop_reason[EMPTY_QUEUE]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: empty queue\n",
-			mmc_hostname(card->host),
-			pack_stats->pack_stop_reason[EMPTY_QUEUE]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-	if (pack_stats->pack_stop_reason[REL_WRITE]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: rel write\n",
-			mmc_hostname(card->host),
-			pack_stats->pack_stop_reason[REL_WRITE]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-	if (pack_stats->pack_stop_reason[THRESHOLD]) {
-		snprintf(temp_buf, TEMP_BUF_SIZE,
-			 "%s: %d times: Threshold\n",
-			mmc_hostname(card->host),
-			pack_stats->pack_stop_reason[THRESHOLD]);
-		strlcat(ubuf, temp_buf, cnt);
-	}
-
-	spin_unlock(&pack_stats->lock);
-
-	kfree(temp_buf);
-
-	pr_info("%s", ubuf);
-
-exit:
-	if (card->wr_pack_stats.print_in_read == 1) {
-		card->wr_pack_stats.print_in_read = 0;
-		return strnlen(ubuf, cnt);
-	}
-
-	return 0;
-}
-
-static ssize_t mmc_wr_pack_stats_write(struct file *filp,
-				       const char __user *ubuf, size_t cnt,
-				       loff_t *ppos)
-{
-	struct mmc_card *card = filp->private_data;
-	int value;
-
-	if (!card)
-		return cnt;
-
-	sscanf(ubuf, "%d", &value);
-	if (value) {
-		mmc_blk_init_packed_statistics(card);
-	} else {
-		spin_lock(&card->wr_pack_stats.lock);
-		card->wr_pack_stats.enabled = false;
-		spin_unlock(&card->wr_pack_stats.lock);
-	}
-
-	return cnt;
-}
-
-static const struct file_operations mmc_dbg_wr_pack_stats_fops = {
-	.open		= mmc_wr_pack_stats_open,
-	.read		= mmc_wr_pack_stats_read,
-	.write		= mmc_wr_pack_stats_write,
-};
-
 void mmc_add_card_debugfs(struct mmc_card *card)
 {
 	struct mmc_host	*host = card->host;
@@ -508,12 +350,6 @@
 					&mmc_dbg_ext_csd_fops))
 			goto err;
 
-	if (mmc_card_mmc(card) && (card->ext_csd.rev >= 6) &&
-	    (card->host->caps2 & MMC_CAP2_PACKED_WR))
-		if (!debugfs_create_file("wr_pack_stats", S_IRUSR, root, card,
-					 &mmc_dbg_wr_pack_stats_fops))
-			goto err;
-
 	return;
 
 err:
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 6343760..7dd886c 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -527,10 +527,6 @@
 		} else {
 			card->ext_csd.data_tag_unit_size = 0;
 		}
-		card->ext_csd.max_packed_writes =
-			ext_csd[EXT_CSD_MAX_PACKED_WRITES];
-		card->ext_csd.max_packed_reads =
-			ext_csd[EXT_CSD_MAX_PACKED_READS];
 	}
 
 out:
@@ -1268,43 +1264,6 @@
 		}
 	}
 
-	if ((host->caps2 & MMC_CAP2_PACKED_CMD) &&
-			(card->ext_csd.max_packed_writes > 0) &&
-			(card->ext_csd.max_packed_reads > 0)) {
-		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-				EXT_CSD_EXP_EVENTS_CTRL,
-				EXT_CSD_PACKED_EVENT_EN,
-				card->ext_csd.generic_cmd6_time);
-		if (err && err != -EBADMSG)
-			goto free_card;
-		if (err) {
-			pr_warning("%s: Enabling packed event failed\n",
-					mmc_hostname(card->host));
-			card->ext_csd.packed_event_en = 0;
-			err = 0;
-		} else {
-			card->ext_csd.packed_event_en = 1;
-		}
-
-	}
-
-	if (!oldcard) {
-		if ((host->caps2 & MMC_CAP2_PACKED_CMD) &&
-		    (card->ext_csd.max_packed_writes > 0)) {
-			/*
-			 * We would like to keep the statistics in an index
-			 * that equals the num of packed requests
-			 * (1 to max_packed_writes)
-			 */
-			card->wr_pack_stats.packing_events = kzalloc(
-				(card->ext_csd.max_packed_writes + 1) *
-				sizeof(*card->wr_pack_stats.packing_events),
-				GFP_KERNEL);
-			if (!card->wr_pack_stats.packing_events)
-				goto free_card;
-		}
-	}
-
 	if (!oldcard)
 		host->card = card;
 
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 4f46ed1..2d282b5 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -335,7 +335,6 @@
 	return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD,
 			ext_csd, 512);
 }
-EXPORT_SYMBOL_GPL(mmc_send_ext_csd);
 
 int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
 {
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index c4b41e1..2391360 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -5801,8 +5801,6 @@
 		mmc->caps |= (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
 				MMC_CAP_SET_XPC_180);
 
-	mmc->caps2 |= MMC_CAP2_PACKED_WR;
-	mmc->caps2 |= MMC_CAP2_PACKED_WR_CONTROL;
 	mmc->caps2 |= (MMC_CAP2_BOOTPART_NOACC | MMC_CAP2_DETECT_ON_ERR);
 	mmc->caps2 |= MMC_CAP2_SANITIZE;
 	mmc->caps2 |= MMC_CAP2_CACHE_CTRL;
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 87e06ed..3b379ba 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -53,9 +53,6 @@
 	u8			part_config;
 	u8			cache_ctrl;
 	u8			rst_n_function;
-	u8			max_packed_writes;
-	u8			max_packed_reads;
-	u8			packed_event_en;
 	unsigned int		part_time;		/* Units: ms */
 	unsigned int		sa_timeout;		/* Units: 100ns */
 	unsigned int		generic_cmd6_time;	/* Units: 10ms */
@@ -209,25 +206,6 @@
 #define MMC_BLK_DATA_AREA_GP	(1<<2)
 };
 
-enum mmc_packed_stop_reasons {
-	EXCEEDS_SEGMENTS = 0,
-	EXCEEDS_SECTORS,
-	WRONG_DATA_DIR,
-	FLUSH_OR_DISCARD,
-	EMPTY_QUEUE,
-	REL_WRITE,
-	THRESHOLD,
-	MAX_REASONS,
-};
-
-struct mmc_wr_pack_stats {
-	u32 *packing_events;
-	u32 pack_stop_reason[MAX_REASONS];
-	spinlock_t lock;
-	bool enabled;
-	bool print_in_read;
-};
-
 /*
  * MMC device
  */
@@ -302,7 +280,6 @@
 	struct mmc_part	part[MMC_NUM_PHY_PARTITION]; /* physical partitions */
 	unsigned int    nr_parts;
 
-	struct mmc_wr_pack_stats wr_pack_stats; /* packed commands stats*/
 };
 
 /*
@@ -527,8 +504,4 @@
 extern void mmc_fixup_device(struct mmc_card *card,
 			     const struct mmc_fixup *table);
 
-extern struct mmc_wr_pack_stats *mmc_blk_get_packed_statistics(
-			struct mmc_card *card);
-extern void mmc_blk_init_packed_statistics(struct mmc_card *card);
-
 #endif /* LINUX_MMC_CARD_H */
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 3f26a80..7a45622 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -18,9 +18,6 @@
 struct mmc_command {
 	u32			opcode;
 	u32			arg;
-#define MMC_CMD23_ARG_REL_WR	(1 << 31)
-#define MMC_CMD23_ARG_PACKED	((0 << 31) | (1 << 30))
-#define MMC_CMD23_ARG_TAG_REQ	(1 << 29)
 	u32			resp[4];
 	unsigned int		flags;		/* expected response type */
 #define MMC_RSP_PRESENT	(1 << 0)
@@ -151,7 +148,6 @@
 extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
 extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool);
 extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
-extern int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
 
 #define MMC_ERASE_ARG		0x00000000
 #define MMC_SECURE_ERASE_ARG	0x80000000
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index dcd9a6f..eb5b92c 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -241,11 +241,6 @@
 #define MMC_CAP2_BROKEN_VOLTAGE	(1 << 7)	/* Use the broken voltage */
 #define MMC_CAP2_DETECT_ON_ERR	(1 << 8)	/* On I/O err check card removal */
 #define MMC_CAP2_HC_ERASE_SZ	(1 << 9)	/* High-capacity erase size */
-#define MMC_CAP2_PACKED_RD	(1 << 10)	/* Allow packed read */
-#define MMC_CAP2_PACKED_WR	(1 << 11)	/* Allow packed write */
-#define MMC_CAP2_PACKED_CMD	(MMC_CAP2_PACKED_RD | \
-				 MMC_CAP2_PACKED_WR) /* Allow packed commands */
-#define MMC_CAP2_PACKED_WR_CONTROL (1 << 12) /* Allow write packing control */
 #define MMC_CAP2_SANITIZE	(1 << 13)		/* Support Sanitize */
 #define MMC_CAP2_POWER_OFF_VCCQ_DURING_SUSPEND	(1 << 16)
 
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 87cdba8..2cf8119 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -141,7 +141,6 @@
 #define R1_SWITCH_ERROR		(1 << 7)	/* sx, c */
 #define R1_EXCEPTION_EVENT	(1 << 6)	/* sx, a */
 #define R1_APP_CMD		(1 << 5)	/* sr, c */
-#define R1_EXP_EVENT		(1 << 6)	/* sr, a */
 
 #define R1_STATE_IDLE	0
 #define R1_STATE_READY	1
@@ -277,8 +276,6 @@
 #define EXT_CSD_FLUSH_CACHE		32      /* W */
 #define EXT_CSD_CACHE_CTRL		33      /* R/W */
 #define EXT_CSD_POWER_OFF_NOTIFICATION	34	/* R/W */
-#define EXT_CSD_PACKED_FAILURE_INDEX	35	/* RO */
-#define EXT_CSD_PACKED_CMD_STATUS	36	/* RO */
 #define EXT_CSD_EXP_EVENTS_STATUS	54	/* RO, 2 bytes */
 #define EXT_CSD_EXP_EVENTS_CTRL	56	/* R/W, 2 bytes */
 #define EXT_CSD_DATA_SECTOR_SIZE	61	/* R */
@@ -328,8 +325,6 @@
 #define EXT_CSD_CACHE_SIZE		249	/* RO, 4 bytes */
 #define EXT_CSD_TAG_UNIT_SIZE		498	/* RO */
 #define EXT_CSD_DATA_TAG_SUPPORT	499	/* RO */
-#define EXT_CSD_MAX_PACKED_WRITES	500	/* RO */
-#define EXT_CSD_MAX_PACKED_READS	501	/* RO */
 #define EXT_CSD_BKOPS_SUPPORT		502	/* RO */
 #define EXT_CSD_HPI_FEATURES		503	/* RO */
 
@@ -400,18 +395,12 @@
 #define EXT_CSD_PWR_CL_8BIT_SHIFT	4
 #define EXT_CSD_PWR_CL_4BIT_SHIFT	0
 
-#define EXT_CSD_PACKED_EVENT_EN	(1 << 3)
-
-#define EXT_CSD_PACKED_GENERIC_ERROR	(1 << 0)
-#define EXT_CSD_PACKED_INDEXED_ERROR	(1 << 1)
-
 /*
  * EXCEPTION_EVENT_STATUS field
  */
 #define EXT_CSD_URGENT_BKOPS		BIT(0)
 #define EXT_CSD_DYNCAP_NEEDED		BIT(1)
 #define EXT_CSD_SYSPOOL_EXHAUSTED	BIT(2)
-#define EXT_CSD_PACKED_FAILURE		BIT(3)
 
 /*
  * BKOPS status level