Re: [PATCH 08/22] ide: add ide_queue_pc_tail() helper

Previous thread: TIOCGWINSZ retuns old pty size after receiving SIGWINCH by Ico Doornekamp on Sunday, August 10, 2008 - 8:08 am. (10 messages)

Next thread: [PATCH] ide: fix support for IDE PCI controllers using MMIO on frv by Bartlomiej Zolnierkiewicz on Sunday, August 10, 2008 - 8:44 am. (1 message)
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:35 am

Just some more work on generic ATAPI layer...

- code unifications here and there

- move IDEFLOPPY_IOCTL_FORMAT_* support to a separate file

- ide_pc_intr() no longer requires zillion of arguments

Applies on top of current pata tree, tested with ide-scsi.

diffstat:
 drivers/ide/Makefile           |    3 
 drivers/ide/ide-atapi.c        |  323 +++++++++++++++--
 drivers/ide/ide-floppy.c       |  739 ++++++-----------------------------------
 drivers/ide/ide-floppy.h       |   72 +++
 drivers/ide/ide-floppy_ioctl.c |  245 +++++++++++++
 drivers/ide/ide-tape.c         |  396 ++++++---------------
 drivers/scsi/ide-scsi.c        |  178 ++-------
 include/linux/ide.h            |  266 +++++++++-----
 8 files changed, 1035 insertions(+), 1187 deletions(-)
--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:35 am

map hwif->sg_{table,nents} on pc->{sg,sg_cnt} (multi-IRQs-per-sg fix)

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
I will fold this into the original patch later.

 drivers/ide/ide-floppy.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -213,12 +213,11 @@ static void ide_floppy_io_buffers(ide_dr
 	ide_hwif_t *hwif = drive->hwif;
 	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
 	xfer_func_t *xf = direction ? tp_ops->output_data : tp_ops->input_data;
-	struct scatterlist *sg = hwif->sg_table;
+	struct scatterlist *sg = pc->sg;
 	char *buf;
 	int count, done = 0;
 
 	while (bcount) {
-
 		count = min(sg->length - pc->b_count, bcount);
 		if (PageHighMem(sg_page(sg))) {
 			unsigned long flags;
@@ -237,9 +236,9 @@ static void ide_floppy_io_buffers(ide_dr
 		done += count;
 
 		if (pc->b_count == sg->length) {
-			if (!--hwif->sg_nents)
+			if (!--pc->sg_cnt)
 				break;
-			sg = sg_next(sg);
+			pc->sg = sg = sg_next(sg);
 			pc->b_count = 0;
 		}
 	}
@@ -576,6 +575,7 @@ static ide_startstop_t idefloppy_do_requ
 		struct request *rq, sector_t block_s)
 {
 	idefloppy_floppy_t *floppy = drive->driver_data;
+	ide_hwif_t *hwif = drive->hwif;
 	struct ide_atapi_pc *pc;
 	unsigned long block = (unsigned long)block_s;
 
@@ -618,11 +618,14 @@ static ide_startstop_t idefloppy_do_requ
 		return ide_stopped;
 	}
 
-	pc->rq = rq;
-
 	ide_init_sg_cmd(drive, rq);
 	ide_map_sg(drive, rq);
 
+	pc->sg = hwif->sg_table;
+	pc->sg_cnt = hwif->sg_nents;
+
+	pc->rq = rq;
+
 	return idefloppy_issue_pc(drive, pc);
 }
 
--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:35 am

Preparation for ide_{floppy,scsi}_io_buffers() unification.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/scsi/ide-scsi.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Index: b/drivers/scsi/ide-scsi.c
===================================================================
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -139,29 +139,29 @@ static void ide_scsi_io_buffers(ide_driv
 	ide_hwif_t *hwif = drive->hwif;
 	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
 	xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data;
+	struct scatterlist *sg = pc->sg;
 	char *buf;
 	int count;
 
 	while (bcount) {
-		count = min(pc->sg->length - pc->b_count, bcount);
-		if (PageHighMem(sg_page(pc->sg))) {
+		count = min(sg->length - pc->b_count, bcount);
+		if (PageHighMem(sg_page(sg))) {
 			unsigned long flags;
 
 			local_irq_save(flags);
-			buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
-					  pc->sg->offset;
+			buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
 			xf(drive, NULL, buf + pc->b_count, count);
-			kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
+			kunmap_atomic(buf - sg->offset, KM_IRQ0);
 			local_irq_restore(flags);
 		} else {
-			buf = sg_virt(pc->sg);
+			buf = sg_virt(sg);
 			xf(drive, NULL, buf + pc->b_count, count);
 		}
 		bcount -= count; pc->b_count += count;
-		if (pc->b_count == pc->sg->length) {
+		if (pc->b_count == sg->length) {
 			if (!--pc->sg_cnt)
 				break;
-			pc->sg = sg_next(pc->sg);
+			pc->sg = sg = sg_next(sg);
 			pc->b_count = 0;
 		}
 	}
--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:35 am

* Make ->io_buffers method return number of bytes transferred.

* Use ide_end_request() instead of idefloppy_end_request()
  in ide_floppy_io_buffers() and then move the call out to
  ide_pc_intr().

* Add ide_io_buffers() helper and convert ide-{floppy,scsi}.c
  to use it instead of ide*_io_buffers().

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   63 ++++++++++++++++++++++++++++++++++++++++++++---
 drivers/ide/ide-floppy.c |   47 -----------------------------------
 drivers/ide/ide-tape.c   |    4 ++
 drivers/scsi/ide-scsi.c  |   46 ----------------------------------
 include/linux/ide.h      |    4 ++
 5 files changed, 67 insertions(+), 97 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -61,12 +61,62 @@ int ide_check_atapi_device(ide_drive_t *
 }
 EXPORT_SYMBOL_GPL(ide_check_atapi_device);
 
+/* PIO data transfer routine using the scatter gather table. */
+int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
+		    unsigned int bcount, int write)
+{
+	ide_hwif_t *hwif = drive->hwif;
+	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
+	xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data;
+	struct scatterlist *sg = pc->sg;
+	char *buf;
+	int count, done = 0;
+
+	while (bcount) {
+		count = min(sg->length - pc->b_count, bcount);
+
+		if (PageHighMem(sg_page(sg))) {
+			unsigned long flags;
+
+			local_irq_save(flags);
+			buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
+			xf(drive, NULL, buf + pc->b_count, count);
+			kunmap_atomic(buf - sg->offset, KM_IRQ0);
+			local_irq_restore(flags);
+		} else {
+			buf = sg_virt(sg);
+			xf(drive, NULL, buf + pc->b_count, count);
+		}
+
+		bcount -= count;
+		pc->b_count += count;
+		done += ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:35 am

Add ide_floppy_set_media_lock() helper and convert idefloppy_open(),
idefloppy_release() and ide_floppy_lockdoor() to use it.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-floppy.c |   39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -1037,6 +1037,17 @@ static ide_driver_t idefloppy_driver = {
 #endif
 };
 
+static void ide_floppy_set_media_lock(ide_drive_t *drive, int on)
+{
+	struct ide_atapi_pc pc;
+
+	/* IOMEGA Clik! drives do not support lock/unlock commands */
+	if ((drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE) == 0) {
+		idefloppy_create_prevent_cmd(&pc, on);
+		(void)idefloppy_queue_pc_tail(drive, &pc);
+	}
+}
+
 static int idefloppy_open(struct inode *inode, struct file *filp)
 {
 	struct gendisk *disk = inode->i_bdev->bd_disk;
@@ -1083,12 +1094,9 @@ static int idefloppy_open(struct inode *
 			ret = -EROFS;
 			goto out_put_floppy;
 		}
+
 		drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
-		/* IOMEGA Clik! drives do not support lock/unlock commands */
-		if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-			idefloppy_create_prevent_cmd(&pc, 1);
-			(void) idefloppy_queue_pc_tail(drive, &pc);
-		}
+		ide_floppy_set_media_lock(drive, 1);
 		check_disk_change(inode->i_bdev);
 	} else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
 		ret = -EBUSY;
@@ -1107,17 +1115,11 @@ static int idefloppy_release(struct inod
 	struct gendisk *disk = inode->i_bdev->bd_disk;
 	struct ide_floppy_obj *floppy = ide_floppy_g(disk);
 	ide_drive_t *drive = floppy->drive;
-	struct ide_atapi_pc pc;
 
 	debug_log("Reached %s\n", __func__);
 
 	if (floppy->openers == 1) {
-		/* IOMEGA Clik! drives do not support ...
From: Sergei Shtylyov
Date: Saturday, August 23, 2008 - 4:49 am

Hello.


Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

MBR, Sergei


--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

Add ide_tape_set_media_lock() helper and convert idetape_mtioctop(),
idetape_chrdev_open() and idetape_chrdev_release() to use it.

There should be no functional changes caused by this patch (it is
OK to modify ->door_locked if idetape_create_prevent_cmd() fails).

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-tape.c |   39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

Index: b/drivers/ide/ide-tape.c
===================================================================
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1298,6 +1298,16 @@ static int idetape_create_prevent_cmd(id
 	return 1;
 }
 
+static int ide_tape_set_media_lock(ide_drive_t *drive, int on)
+{
+	struct ide_atapi_pc pc;
+
+	if (!idetape_create_prevent_cmd(drive, &pc, on))
+		return 0;
+
+	return idetape_queue_pc_tail(drive, &pc);
+}
+
 static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
 {
 	idetape_tape_t *tape = drive->driver_data;
@@ -1926,9 +1936,8 @@ static int idetape_mtioctop(ide_drive_t 
 		 * attempting to eject.
 		 */
 		if (tape->door_locked) {
-			if (idetape_create_prevent_cmd(drive, &pc, 0))
-				if (!idetape_queue_pc_tail(drive, &pc))
-					tape->door_locked = DOOR_UNLOCKED;
+			if (!ide_tape_set_media_lock(drive, 0))
+				tape->door_locked = DOOR_UNLOCKED;
 		}
 		ide_tape_discard_merge_buffer(drive, 0);
 		idetape_create_load_unload_cmd(drive, &pc,
@@ -1972,17 +1981,13 @@ static int idetape_mtioctop(ide_drive_t 
 	case MTFSR:
 	case MTBSR:
 	case MTLOCK:
-		if (!idetape_create_prevent_cmd(drive, &pc, 1))
-			return 0;
-		retval = idetape_queue_pc_tail(drive, &pc);
+		retval = ide_tape_set_media_lock(drive, 1);
 		if (retval)
 			return retval;
 		tape->door_locked = DOOR_EXPLICITLY_LOCKED;
 		return 0;
 	case MTUNLOCK:
-		if (!idetape_create_prevent_cmd(drive, &pc, 0))
-			return 0;
-		retval = idetape_queue_pc_tail(drive, ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

* Add IDE_PC_BUFFER_SIZE define.

* Add ide_init_pc() and convert ide-{floppy,tape}.c to use it
  instead of ide*_init_pc().

* Remove no longer used IDE*_PC_BUFFER_SIZE and ide*_init_pc().

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |    8 ++++++++
 drivers/ide/ide-floppy.c |   31 +++++++++----------------------
 drivers/ide/ide-tape.c   |   44 +++++++++++++-------------------------------
 include/linux/ide.h      |   10 +++++++++-
 4 files changed, 39 insertions(+), 54 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -111,6 +111,14 @@ int ide_io_buffers(ide_drive_t *drive, s
 }
 EXPORT_SYMBOL_GPL(ide_io_buffers);
 
+void ide_init_pc(struct ide_atapi_pc *pc)
+{
+	memset(pc, 0, sizeof(*pc));
+	pc->buf = pc->pc_buf;
+	pc->buf_size = IDE_PC_BUFFER_SIZE;
+}
+EXPORT_SYMBOL_GPL(ide_init_pc);
+
 /* TODO: unify the code thus making some arguments go away */
 ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
 	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -68,12 +68,6 @@
  */
 #define IDEFLOPPY_MAX_PC_RETRIES	3
 
-/*
- * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
- * bytes.
- */
-#define IDEFLOPPY_PC_BUFFER_SIZE	256
-
 /* format capacities descriptor codes */
 #define CAPACITY_INVALID	0x00
 #define CAPACITY_UNFORMATTED	0x01
@@ -273,16 +267,9 @@ static void ide_floppy_callback(ide_driv
 	idefloppy_end_request(drive, uptodate, 0);
 }
 
-static void idefloppy_init_pc(struct ide_atapi_pc *pc)
-{
-	memset(pc, 0, sizeof(*pc));
-	pc->buf = ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

* Move REQ_IDETAPE_* enums to <linux/ide.h>.

* Add ide_queue_pc_head() and convert ide-{floppy,tape}.c to use it
  instead of ide*_queue_pc_head().

* Remove no longer used ide*_queue_pc_head().

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   20 ++++++++++++++++++++
 drivers/ide/ide-floppy.c |   21 +--------------------
 drivers/ide/ide-tape.c   |   36 +-----------------------------------
 include/linux/ide.h      |   16 ++++++++++++++++
 4 files changed, 38 insertions(+), 55 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -119,6 +119,26 @@ void ide_init_pc(struct ide_atapi_pc *pc
 }
 EXPORT_SYMBOL_GPL(ide_init_pc);
 
+/*
+ * Generate a new packet command request in front of the request queue, before
+ * the current request, so that it will be processed immediately, on the next
+ * pass through the driver.
+ */
+void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
+		       struct ide_atapi_pc *pc, struct request *rq)
+{
+	blk_rq_init(NULL, rq);
+	rq->cmd_type = REQ_TYPE_SPECIAL;
+	rq->cmd_flags |= REQ_PREEMPT;
+	rq->buffer = (char *)pc;
+	rq->rq_disk = disk;
+	memcpy(rq->cmd, pc->c, 12);
+	if (drive->media == ide_tape)
+		rq->cmd[13] = REQ_IDETAPE_PC1;
+	ide_do_drive_cmd(drive, rq);
+}
+EXPORT_SYMBOL_GPL(ide_queue_pc_head);
+
 /* TODO: unify the code thus making some arguments go away */
 ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
 	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -211,25 +211,6 @@ static void idefloppy_update_buffers(ide
 ...
From: Sergei Shtylyov
Date: Saturday, August 23, 2008 - 2:57 pm

Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

MBR, Sergei


--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

* Add ide_queue_pc_tail() and convert ide-{floppy,tape}.c to use it
  instead of ide*_queue_pc_tail().

* Remove no longer used ide*_queue_pc_tail().

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   23 +++++++++++++++
 drivers/ide/ide-floppy.c |   49 +++++++++++----------------------
 drivers/ide/ide-tape.c   |   69 +++++++++++++++++++----------------------------
 include/linux/ide.h      |    1 
 4 files changed, 69 insertions(+), 73 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -139,6 +139,29 @@ void ide_queue_pc_head(ide_drive_t *driv
 }
 EXPORT_SYMBOL_GPL(ide_queue_pc_head);
 
+/*
+ * Add a special packet command request to the tail of the request queue,
+ * and wait for it to be serviced.
+ */
+int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
+		      struct ide_atapi_pc *pc)
+{
+	struct request *rq;
+	int error;
+
+	rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
+	rq->cmd_type = REQ_TYPE_SPECIAL;
+	rq->buffer = (char *)pc;
+	memcpy(rq->cmd, pc->c, 12);
+	if (drive->media == ide_tape)
+		rq->cmd[13] = REQ_IDETAPE_PC1;
+	error = blk_execute_rq(drive->queue, disk, rq, 0);
+	blk_put_request(rq);
+
+	return error;
+}
+EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
+
 /* TODO: unify the code thus making some arguments go away */
 ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
 	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -553,32 +553,13 @@ static ide_startstop_t idefloppy_do_requ
 }
 
 /*
- * Add a special packet command request to the tail of the ...
From: Sergei Shtylyov
Date: Saturday, August 23, 2008 - 2:58 pm

Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

MBR, Sergei


--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

Add IDE_AFLAG_{SRFP,WP} drive->atapi_flags and use them
instead of ->{srfp,wp} struct ide_floppy_obj fields.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-floppy.c |   24 ++++++++++++++----------
 include/linux/ide.h      |   16 ++++++++++------
 2 files changed, 24 insertions(+), 16 deletions(-)

Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -109,10 +109,6 @@ typedef struct ide_floppy_obj {
 	u8 cap_desc[8];
 	/* Copy of the flexible disk page */
 	u8 flexible_disk_page[32];
-	/* Write protect */
-	int wp;
-	/* Supports format progress report */
-	int srfp;
 } idefloppy_floppy_t;
 
 #define IDEFLOPPY_TICKS_DELAY	HZ/20	/* default delay for ZIP 100 (50ms) */
@@ -573,8 +569,14 @@ static int ide_floppy_get_flexible_disk_
 				" parameters\n");
 		return 1;
 	}
-	floppy->wp = !!(pc.buf[3] & 0x80);
-	set_disk_ro(disk, floppy->wp);
+
+	if (pc.buf[3] & 0x80)
+		drive->atapi_flags |= IDE_AFLAG_WP;
+	else
+		drive->atapi_flags &= ~IDE_AFLAG_WP;
+
+	set_disk_ro(disk, !!(drive->atapi_flags & IDE_AFLAG_WP));
+
 	page = &pc.buf[8];
 
 	transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
@@ -613,7 +615,7 @@ static int idefloppy_get_sfrp_bit(ide_dr
 	idefloppy_floppy_t *floppy = drive->driver_data;
 	struct ide_atapi_pc pc;
 
-	floppy->srfp = 0;
+	drive->atapi_flags &= ~IDE_AFLAG_SRFP;
 
 	idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE);
 	pc.flags |= PC_FLAG_SUPPRESS_ERROR;
@@ -621,7 +623,9 @@ static int idefloppy_get_sfrp_bit(ide_dr
 	if (ide_queue_pc_tail(drive, floppy->disk, &pc))
 		return 1;
 
-	floppy->srfp = pc.buf[8 + 2] & 0x40;
+	if (pc.buf[8 + 2] & 0x40)
+		drive->atapi_flags |= IDE_AFLAG_SRFP;
+
 	return 0;
 }
 
@@ -819,7 +823,7 @@ static int ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

While at it:

- idefloppy_create_read_capacity_cmd() -> ide_floppy_create_read_capacity_cmd()
- idefloppy_create_mode_sense_cmd() -> ide_floppy_create_mode_sense_cmd()
- idefloppy_create_request_sense_cmd() -> ide_floppy_create_request_sense_cmd()
- idefloppy_create_format_unit_cmd() -> ide_floppy_create_format_unit_cmd()
- idefloppy_get_sfrp_bit() -> ide_floppy_get_sfrp_bit()

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/Makefile           |    3 
 drivers/ide/ide-floppy.c       |  296 +----------------------------------------
 drivers/ide/ide-floppy.h       |   63 ++++++++
 drivers/ide/ide-floppy_ioctl.c |  243 +++++++++++++++++++++++++++++++++
 4 files changed, 317 insertions(+), 288 deletions(-)

Index: b/drivers/ide/Makefile
===================================================================
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -37,11 +37,12 @@ obj-$(CONFIG_IDE_GENERIC)		+= ide-generi
 obj-$(CONFIG_BLK_DEV_IDEPNP)		+= ide-pnp.o
 
 ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
+ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
 
 obj-$(CONFIG_BLK_DEV_IDEDISK)		+= ide-disk.o
 obj-$(CONFIG_BLK_DEV_IDECD)		+= ide-cd_mod.o
+obj-$(CONFIG_BLK_DEV_IDEFLOPPY)		+= ide-floppy_mod.o
 obj-$(CONFIG_BLK_DEV_IDETAPE)		+= ide-tape.o
-obj-$(CONFIG_BLK_DEV_IDEFLOPPY)		+= ide-floppy.o
 
 ifeq ($(CONFIG_BLK_DEV_IDECS), y)
 	ide-cs-core-y += legacy/ide-cs.o
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -45,6 +45,8 @@
 #include <linux/io.h>
 #include <asm/unaligned.h>
 
+#include "ide-floppy.h"
+
 /* define to see debug info */
 #define IDEFLOPPY_DEBUG_LOG		0
 
@@ -74,61 +76,11 @@
 #define CAPACITY_CURRENT	0x02
 #define CAPACITY_NO_CARTRIDGE	0x03
 
-/*
- * Most of our global data which we need to save even as we leave the driver
- * due to an ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

* Set IDE_AFLAG_NO_DOORLOCK in idetape_get_mode_sense_result(), check it
  in ide_tape_set_media_lock() and cleanup idetape_create_prevent_cmd().

* Set IDE_AFLAG_NO_DOORLOCK in ide_floppy_create_read_capacity_cmd() and
  check it instead of IDE_AFLAG_CLIK_DRIVE in ide_floppy_set_media_lock().

* Add ide_set_media_lock() helper and convert ide-{floppy,tape}.c to use it.

* Remove no longer used ide*_create_prevent_cmd()/ide*_set_media_lock().

* Update comment in <linux/ide.h> accordingly.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   15 +++++++++++++++
 drivers/ide/ide-floppy.c |   32 +++++++-------------------------
 drivers/ide/ide-tape.c   |   41 ++++++++++-------------------------------
 include/linux/ide.h      |    6 ++++--
 4 files changed, 36 insertions(+), 58 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -162,6 +162,21 @@ int ide_queue_pc_tail(ide_drive_t *drive
 }
 EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
 
+int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
+{
+	struct ide_atapi_pc pc;
+
+	if (drive->atapi_flags & IDE_AFLAG_NO_DOORLOCK)
+		return 0;
+
+	ide_init_pc(&pc);
+	pc.c[0] = ALLOW_MEDIUM_REMOVAL;
+	pc.c[4] = on;
+
+	return ide_queue_pc_tail(drive, disk, &pc);
+}
+EXPORT_SYMBOL_GPL(ide_set_media_lock);
+
 /* TODO: unify the code thus making some arguments go away */
 ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
 	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -324,15 +324,6 @@ static ide_startstop_t idefloppy_issue_p
 			    IDEFLOPPY_WAIT_CMD, NULL);
 }
 
-static void ...
From: Borislav Petkov
Date: Sunday, August 10, 2008 - 11:02 pm

Hi,


Are we switching to SCSI opcodes? What about the generic packet commands in

-- 
Regards/Gruss,
    Boris.
--

From: Bartlomiej Zolnierkiewicz
Date: Tuesday, August 12, 2008 - 2:05 am

I prefer to use them when possible but there is no strict policy.

[ SCSI defines are shorter, one of the drivers was using them already
  and it also makes easier for comparing code with SCSI. ]
--

From: Boris Petkov
Date: Tuesday, August 12, 2008 - 6:37 am

I still think we should stick to one format or the other. All
the drivers' functions, for example, comply with a naming scheme
(ide_cd/ide_floppy/...) so opcodes shouldn't be an exception, imho...

-- 
Regards/Gruss,
Boris
--

From: Bartlomiej Zolnierkiewicz
Date: Tuesday, August 12, 2008 - 10:48 am

Some opcodes are only in <linux/cdrom.h> while the other ones only
in <scsi/scsi.h> so it is not that simple without additional effort.

I don't have a time for it at the moment (+ I consider it a low-prio
task).  However if you would like to look into it, please go ahead.

Thanks,
Bart
--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:36 am

* Add ide_do_start_stop() helper and convert ide-{floppy,tape}.c
  to use it.

* Remove no longer used idefloppy_create_start_stop_cmd()
  and idetape_create_load_unload_cmd().

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   15 +++++++++++++++
 drivers/ide/ide-floppy.c |   19 ++++---------------
 drivers/ide/ide-tape.c   |   24 ++++--------------------
 include/linux/ide.h      |    1 +
 4 files changed, 24 insertions(+), 35 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -162,6 +162,21 @@ int ide_queue_pc_tail(ide_drive_t *drive
 }
 EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
 
+int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
+{
+	struct ide_atapi_pc pc;
+
+	ide_init_pc(&pc);
+	pc.c[0] = START_STOP;
+	pc.c[4] = start;
+
+	if (drive->media == ide_tape)
+		pc.flags |= PC_FLAG_WAIT_FOR_DSC;
+
+	return ide_queue_pc_tail(drive, disk, &pc);
+}
+EXPORT_SYMBOL_GPL(ide_do_start_stop);
+
 int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
 {
 	struct ide_atapi_pc pc;
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -358,13 +358,6 @@ void ide_floppy_create_mode_sense_cmd(st
 	pc->req_xfer = length;
 }
 
-static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
-{
-	ide_init_pc(pc);
-	pc->c[0] = GPCMD_START_STOP_UNIT;
-	pc->c[4] = start;
-}
-
 static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
 				    struct ide_atapi_pc *pc, struct request *rq,
 				    unsigned long sector)
@@ -799,10 +792,8 @@ static int idefloppy_open(struct inode *
 		ide_init_pc(&pc);
 		pc.c[0] = ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

* Add ide_do_test_unit_ready() helper and convert ide-{floppy,tape}.c
  to use it.

* Remove no longer used idetape_create_test_unit_ready_cmd().

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   11 +++++++++++
 drivers/ide/ide-floppy.c |    6 +-----
 drivers/ide/ide-tape.c   |   10 +---------
 include/linux/ide.h      |    1 +
 4 files changed, 14 insertions(+), 14 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -162,6 +162,17 @@ int ide_queue_pc_tail(ide_drive_t *drive
 }
 EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
 
+int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
+{
+	struct ide_atapi_pc pc;
+
+	ide_init_pc(&pc);
+	pc.c[0] = TEST_UNIT_READY;
+
+	return ide_queue_pc_tail(drive, disk, &pc);
+}
+EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
+
 int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
 {
 	struct ide_atapi_pc pc;
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -772,7 +772,6 @@ static int idefloppy_open(struct inode *
 	struct gendisk *disk = inode->i_bdev->bd_disk;
 	struct ide_floppy_obj *floppy;
 	ide_drive_t *drive;
-	struct ide_atapi_pc pc;
 	int ret = 0;
 
 	debug_log("Reached %s\n", __func__);
@@ -789,10 +788,7 @@ static int idefloppy_open(struct inode *
 		drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
 		/* Just in case */
 
-		ide_init_pc(&pc);
-		pc.c[0] = GPCMD_TEST_UNIT_READY;
-
-		if (ide_queue_pc_tail(drive, disk, &pc))
+		if (ide_do_test_unit_ready(drive, disk))
 			ide_do_start_stop(drive, disk, 1);
 
 		if (ide_floppy_get_capacity(drive)
Index: ...
From: Sergei Shtylyov
Date: Saturday, August 23, 2008 - 2:31 pm

Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

MBR, Sergei


--

From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

While at it:

* IDE{FLOPPY,TAPE}_WAIT_CMD -> WAIT_{FLOPPY,TAPE}_CMD

* Use enum for WAIT_* defines.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-floppy.c |   13 ++++---------
 drivers/ide/ide-tape.c   |   13 +++----------
 include/linux/ide.h      |   28 ++++++++++++++++++++++------
 3 files changed, 29 insertions(+), 25 deletions(-)

Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -60,10 +60,6 @@
 #define debug_log(fmt, args...) do {} while (0)
 #endif
 
-
-/* Some drives require a longer irq timeout. */
-#define IDEFLOPPY_WAIT_CMD		(5 * WAIT_CMD)
-
 /*
  * After each failed packet command we issue a request sense command and retry
  * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
@@ -225,7 +221,7 @@ static ide_startstop_t idefloppy_pc_intr
 	idefloppy_floppy_t *floppy = drive->driver_data;
 
 	return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
-			   IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers,
+			   WAIT_FLOPPY_CMD, NULL, idefloppy_update_buffers,
 			   idefloppy_retry_pc, NULL, ide_io_buffers);
 }
 
@@ -243,10 +239,9 @@ static int idefloppy_transfer_pc(ide_dri
 	drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
 
 	/* Timeout for the packet command */
-	return IDEFLOPPY_WAIT_CMD;
+	return WAIT_FLOPPY_CMD;
 }
 
-
 /*
  * Called as an interrupt (or directly). When the device says it's ready for a
  * packet, we schedule the packet transfer to occur about 2-3 ticks later in
@@ -271,7 +266,7 @@ static ide_startstop_t idefloppy_start_p
 		timeout = floppy->ticks;
 		expiry = &idefloppy_transfer_pc;
 	} else {
-		timeout = IDEFLOPPY_WAIT_CMD;
+		timeout = WAIT_FLOPPY_CMD;
 		expiry = NULL;
 	}
 
@@ -321,7 +316,7 @@ static ide_startstop_t idefloppy_issue_p
 ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

* Add 'int dsc' argument to ->pc_callback method.

* Call ide_tape_handle_dsc() internally in ide_tape_callback()
  if dsc argument is set and update ide_pc_intr() accordingly.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   16 +++++++---------
 drivers/ide/ide-floppy.c |    6 +++---
 drivers/ide/ide-tape.c   |   13 +++++++++----
 drivers/scsi/ide-scsi.c  |    5 ++---
 include/linux/ide.h      |    4 ++--
 5 files changed, 23 insertions(+), 21 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(ide_set_media_lock);
 ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
 	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
 	void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
-	void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
+	void (*retry_pc)(ide_drive_t *),
 	int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
 {
 	ide_hwif_t *hwif = drive->hwif;
@@ -216,12 +216,12 @@ ide_startstop_t ide_pc_intr(ide_drive_t 
 	xfer_func_t *xferfunc;
 	unsigned int temp;
 	u16 bcount;
-	u8 stat, ireason, scsi = drive->scsi;
+	u8 stat, ireason, scsi = drive->scsi, dsc = 0;
 
 	debug_log("Enter %s - interrupt handler\n", __func__);
 
 	if (pc->flags & PC_FLAG_TIMEDOUT) {
-		drive->pc_callback(drive);
+		drive->pc_callback(drive, 0);
 		return ide_stopped;
 	}
 
@@ -283,14 +283,12 @@ ide_startstop_t ide_pc_intr(ide_drive_t 
 		}
 cmd_finished:
 		pc->error = 0;
-		if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) &&
-		    (stat & ATA_DSC) == 0) {
-			dsc_handle(drive);
-			return ide_stopped;
-		}
+
+		if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
+			dsc = 1;
 
 		/* ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

* Add pointer to the current packet command (struct ide_atapi_pc *pc)
  to ide_drive_t and use it instead of the pointer in struct ide_*_obj.

* Use drive->pc in ide_{issue,transfer}_pc() and ide_pc_intr()
  instead of 'pc' argument.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |    9 ++++---
 drivers/ide/ide-floppy.c |   20 ++++++----------
 drivers/ide/ide-floppy.h |    2 -
 drivers/ide/ide-tape.c   |   31 ++++++++-----------------
 drivers/scsi/ide-scsi.c  |   58 ++++++++++++++++++++++-------------------------
 include/linux/ide.h      |   10 +++++---
 6 files changed, 60 insertions(+), 70 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -204,12 +204,13 @@ int ide_set_media_lock(ide_drive_t *driv
 EXPORT_SYMBOL_GPL(ide_set_media_lock);
 
 /* TODO: unify the code thus making some arguments go away */
-ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
+ide_startstop_t ide_pc_intr(ide_drive_t *drive,
 	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
 	void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
 	void (*retry_pc)(ide_drive_t *),
 	int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
 {
+	struct ide_atapi_pc *pc = drive->pc;
 	ide_hwif_t *hwif = drive->hwif;
 	struct request *rq = hwif->hwgroup->rq;
 	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
@@ -416,10 +417,11 @@ static u8 ide_wait_ireason(ide_drive_t *
 	return ireason;
 }
 
-ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
+ide_startstop_t ide_transfer_pc(ide_drive_t *drive,
 				ide_handler_t *handler, unsigned int timeout,
 				ide_expiry_t *expiry)
 {
+	struct ide_atapi_pc *pc = drive->pc;
 	ide_hwif_t *hwif = ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

* Move idescsi_expiry() to ide-atapi.c.

* Move get_timeout() to <linux/ide.h>.

* Drop 'timeout' and 'expiry' arguments from ide_pc_intr().

While at it:

* idescsi_expiry() -> ide_scsi_expiry()

* get_timeout() -> ide_scsi_get_timeout()

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   34 +++++++++++++++++++++++++++-------
 drivers/ide/ide-floppy.c |    3 +--
 drivers/ide/ide-tape.c   |    5 ++---
 drivers/scsi/ide-scsi.c  |   25 ++++---------------------
 include/linux/ide.h      |   10 ++++++++--
 5 files changed, 42 insertions(+), 35 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -203,9 +203,21 @@ int ide_set_media_lock(ide_drive_t *driv
 }
 EXPORT_SYMBOL_GPL(ide_set_media_lock);
 
+int ide_scsi_expiry(ide_drive_t *drive)
+{
+	struct ide_atapi_pc *pc = drive->pc;
+
+	debug_log("%s called for %lu at %lu\n", __func__,
+		  pc->scsi_cmd->serial_number, jiffies);
+
+	pc->flags |= PC_FLAG_TIMEDOUT;
+
+	return 0; /* we do not want the IDE subsystem to retry */
+}
+EXPORT_SYMBOL_GPL(ide_scsi_expiry);
+
 /* TODO: unify the code thus making some arguments go away */
-ide_startstop_t ide_pc_intr(ide_drive_t *drive,
-	ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
+ide_startstop_t ide_pc_intr(ide_drive_t *drive, ide_handler_t *handler,
 	void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
 	void (*retry_pc)(ide_drive_t *),
 	int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
@@ -215,12 +227,22 @@ ide_startstop_t ide_pc_intr(ide_drive_t 
 	struct request *rq = hwif->hwgroup->rq;
 	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
 	xfer_func_t *xferfunc;
-	unsigned int temp;
+	ide_expiry_t *expiry;
+	unsigned int timeout, temp;
 	u16 ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

Add 'struct ide_atapi_pc request_sense_pc' and 'request request_sense_rq' to
ide_drive_t and use them instead of fields in struct ide_{floppy,tape}_obj.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-floppy.c |    4 -
 drivers/ide/ide-floppy.h |    3 -
 drivers/ide/ide-tape.c   |    7 --
 include/linux/ide.h      |  134 +++++++++++++++++++++++------------------------
 4 files changed, 72 insertions(+), 76 deletions(-)

Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -207,8 +207,8 @@ void ide_floppy_create_request_sense_cmd
 static void idefloppy_retry_pc(ide_drive_t *drive)
 {
 	struct ide_floppy_obj *floppy = drive->driver_data;
-	struct request *rq = &floppy->request_sense_rq;
-	struct ide_atapi_pc *pc = &floppy->request_sense_pc;
+	struct request *rq = &drive->request_sense_rq;
+	struct ide_atapi_pc *pc = &drive->request_sense_pc;
 
 	(void)ide_read_error(drive);
 	ide_floppy_create_request_sense_cmd(pc);
Index: b/drivers/ide/ide-floppy.h
===================================================================
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -18,9 +18,6 @@ typedef struct ide_floppy_obj {
 	/* used for blk_{fs,pc}_request() requests */
 	struct ide_atapi_pc queued_pc;
 
-	struct ide_atapi_pc request_sense_pc;
-	struct request request_sense_rq;
-
 	/* Last error information */
 	u8 sense_key, asc, ascq;
 	/* delay this long before sending packet command */
Index: b/drivers/ide/ide-tape.c
===================================================================
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -182,9 +182,6 @@ typedef struct ide_tape_obj {
 	/* used by REQ_IDETAPE_{READ,WRITE} requests */
 	struct ide_atapi_pc queued_pc;
 
-	struct ide_atapi_pc ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

* Add ide_create_request_sense_cmd() and ide_retry_pc() helpers
  and convert ide-{atapi,floppy,tape}.c to use them.

* Remove no longer used ide*_create_request_sense_cmd(),
  ide*_retry_pc() and 'retry_pc' argument from ide_pc_intr().

* Make ide_queue_pc_head() static.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c        |   39 ++++++++++++++++++++++++++++++++++-----
 drivers/ide/ide-floppy.c       |   25 +------------------------
 drivers/ide/ide-floppy.h       |    1 -
 drivers/ide/ide-floppy_ioctl.c |    2 +-
 drivers/ide/ide-tape.c         |   29 ++---------------------------
 drivers/scsi/ide-scsi.c        |    2 +-
 include/linux/ide.h            |    5 ++---
 7 files changed, 41 insertions(+), 62 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -124,8 +124,8 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
  * the current request, so that it will be processed immediately, on the next
  * pass through the driver.
  */
-void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
-		       struct ide_atapi_pc *pc, struct request *rq)
+static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
+			      struct ide_atapi_pc *pc, struct request *rq)
 {
 	blk_rq_init(NULL, rq);
 	rq->cmd_type = REQ_TYPE_SPECIAL;
@@ -137,7 +137,6 @@ void ide_queue_pc_head(ide_drive_t *driv
 		rq->cmd[13] = REQ_IDETAPE_PC1;
 	ide_do_drive_cmd(drive, rq);
 }
-EXPORT_SYMBOL_GPL(ide_queue_pc_head);
 
 /*
  * Add a special packet command request to the tail of the request queue,
@@ -203,6 +202,37 @@ int ide_set_media_lock(ide_drive_t *driv
 }
 EXPORT_SYMBOL_GPL(ide_set_media_lock);
 
+void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
+{
+	ide_init_pc(pc);
+	pc->c[0] = ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

Add ->pc_{update,io}_buffers methods to ide_drive_t and use
them instead of {update,io}_buffers ide_pc_intr() arguments.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   14 ++++++--------
 drivers/ide/ide-floppy.c |    7 ++++---
 drivers/ide/ide-tape.c   |    7 ++++---
 drivers/scsi/ide-scsi.c  |    6 ++++--
 include/linux/ide.h      |    9 +++++----
 5 files changed, 23 insertions(+), 20 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -246,10 +246,7 @@ int ide_scsi_expiry(ide_drive_t *drive)
 }
 EXPORT_SYMBOL_GPL(ide_scsi_expiry);
 
-/* TODO: unify the code thus making some arguments go away */
-ide_startstop_t ide_pc_intr(ide_drive_t *drive, ide_handler_t *handler,
-	void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
-	int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
+ide_startstop_t ide_pc_intr(ide_drive_t *drive, ide_handler_t *handler)
 {
 	struct ide_atapi_pc *pc = drive->pc;
 	ide_hwif_t *hwif = drive->hwif;
@@ -290,8 +287,8 @@ ide_startstop_t ide_pc_intr(ide_drive_t 
 			pc->flags |= PC_FLAG_DMA_ERROR;
 		} else {
 			pc->xferred = pc->req_xfer;
-			if (update_buffers)
-				update_buffers(drive, pc);
+			if (drive->pc_update_buffers)
+				drive->pc_update_buffers(drive, pc);
 		}
 		debug_log("%s: DMA finished\n", drive->name);
 	}
@@ -386,7 +383,8 @@ cmd_finished:
 					temp = 0;
 				if (temp) {
 					if (pc->sg)
-						io_buffers(drive, pc, temp, 0);
+						drive->pc_io_buffers(drive, pc,
+								     temp, 0);
 					else
 						tp_ops->input_data(drive, NULL,
 							pc->cur_pos, temp);
@@ -410,7 +408,7 @@ cmd_finished:
 	if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
 	    (drive->media == ide_tape && !scsi && pc->bh) ||
 	 ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:37 am

* Always use ide_pc_intr as a handler in ide_pc_intr().

* Remove no longer used ide*_pc_intr() and 'handler'
  argument from ide_{transfer_pc,pc_intr}().

* Make ide_pc_intr() static.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   15 +++++++++------
 drivers/ide/ide-floppy.c |   10 ++--------
 drivers/ide/ide-tape.c   |   18 +++---------------
 drivers/scsi/ide-scsi.c  |   11 +----------
 include/linux/ide.h      |    4 +---
 5 files changed, 16 insertions(+), 42 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -246,7 +246,12 @@ int ide_scsi_expiry(ide_drive_t *drive)
 }
 EXPORT_SYMBOL_GPL(ide_scsi_expiry);
 
-ide_startstop_t ide_pc_intr(ide_drive_t *drive, ide_handler_t *handler)
+/*
+ * This is the usual interrupt handler which will be called during a packet
+ * command.  We will transfer some of the data (as requested by the drive)
+ * and will re-point interrupt handler to us.
+ */
+static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 {
 	struct ide_atapi_pc *pc = drive->pc;
 	ide_hwif_t *hwif = drive->hwif;
@@ -425,10 +430,9 @@ cmd_finished:
 		  rq->cmd[0], bcount);
 next_irq:
 	/* And set the interrupt handler again */
-	ide_set_handler(drive, handler, timeout, expiry);
+	ide_set_handler(drive, ide_pc_intr, timeout, expiry);
 	return ide_started;
 }
-EXPORT_SYMBOL_GPL(ide_pc_intr);
 
 static u8 ide_read_ireason(ide_drive_t *drive)
 {
@@ -464,8 +468,7 @@ static u8 ide_wait_ireason(ide_drive_t *
 	return ireason;
 }
 
-ide_startstop_t ide_transfer_pc(ide_drive_t *drive,
-				ide_handler_t *handler, unsigned int timeout,
+ide_startstop_t ide_transfer_pc(ide_drive_t *drive, unsigned int timeout,
 				ide_expiry_t *expiry)
 {
 	struct ide_atapi_pc *pc = drive->pc;
@@ ...
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:38 am

* Move ->ticks field from struct ide_floppy_obj to ide_drive_t.

* Move idefloppy_transfer_pc() to ide-atapi.c and make
  ide_transfer_pc() use it.

* Always use ide_transfer_pc as a handler in ide_issue_pc().

* Remove no longer used idefloppy_start_pc_transfer(),
  ide*_transfer_pc() and 'handler' argument from ide_issue_pc().

* Make ide_transfer_pc() static.

While at it:

* idefloppy_transfer_pc() -> ide_delayed_transfer_pc()

* IDEFLOPPY_TICKS_DELAY -> IDEFLOPPY_PC_DELAY

* ->ticks -> ->pc_delay

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-atapi.c  |   41 ++++++++++++++++++++++----
 drivers/ide/ide-floppy.c |   72 +++++------------------------------------------
 drivers/ide/ide-floppy.h |    3 -
 drivers/ide/ide-tape.c   |    6 ---
 drivers/scsi/ide-scsi.c  |    9 -----
 include/linux/ide.h      |    7 ++--
 6 files changed, 49 insertions(+), 89 deletions(-)

Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -468,12 +468,22 @@ static u8 ide_wait_ireason(ide_drive_t *
 	return ireason;
 }
 
-ide_startstop_t ide_transfer_pc(ide_drive_t *drive, unsigned int timeout,
-				ide_expiry_t *expiry)
+static int ide_delayed_transfer_pc(ide_drive_t *drive)
+{
+	/* Send the actual packet */
+	drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
+
+	/* Timeout for the packet command */
+	return WAIT_FLOPPY_CMD;
+}
+
+static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
 {
 	struct ide_atapi_pc *pc = drive->pc;
 	ide_hwif_t *hwif = drive->hwif;
 	struct request *rq = hwif->hwgroup->rq;
+	ide_expiry_t *expiry;
+	unsigned int timeout;
 	ide_startstop_t startstop;
 	u8 ireason;
 
@@ -493,6 +503,25 @@ ide_startstop_t ide_transfer_pc(ide_driv
 		return ide_do_reset(drive);
 	}
 
+	/*
+	 * ...
From: Borislav Petkov
Date: Sunday, August 10, 2008 - 11:36 pm

ACK 1-14, looks good so far. Will review the rest of them later and do some
testing.

-- 
Regards/Gruss,
    Boris.
--

Previous thread: TIOCGWINSZ retuns old pty size after receiving SIGWINCH by Ico Doornekamp on Sunday, August 10, 2008 - 8:08 am. (10 messages)

Next thread: [PATCH] ide: fix support for IDE PCI controllers using MMIO on frv by Bartlomiej Zolnierkiewicz on Sunday, August 10, 2008 - 8:44 am. (1 message)