[PATCH 05/40] ide-scsi: merge idescsi_input_buffers() and idescsi_output_buffers()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Bartlomiej Zolnierkiewicz
Date: Sunday, May 18, 2008 - 11:55 am

* Merge idescsi_input_buffers() and idescsi_output_buffers()
  into ide_scsi_io_buffers() helper.

While at it:

* Log device name instead of driver name on error.

* Use xfer_func_t.

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

Index: b/drivers/scsi/ide-scsi.c
===================================================================
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -129,51 +129,15 @@ static inline idescsi_scsi_t *drive_to_i
 #define IDESCSI_PC_RQ			90
 
 /*
- *	PIO data transfer routines using the scatter gather table.
+ *	PIO data transfer routine using the scatter gather table.
  */
-static void idescsi_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
-		unsigned int bcount)
+static void ide_scsi_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
+				unsigned int bcount, int write)
 {
 	ide_hwif_t *hwif = drive->hwif;
-	int count;
+	xfer_func_t *xf = write ? hwif->output_data : hwif->input_data;
 	char *buf;
-
-	while (bcount) {
-		count = min(pc->sg->length - pc->b_count, bcount);
-		if (PageHighMem(sg_page(pc->sg))) {
-			unsigned long flags;
-
-			local_irq_save(flags);
-			buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
-					pc->sg->offset;
-			hwif->input_data(drive, NULL, buf + pc->b_count, count);
-			kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
-			local_irq_restore(flags);
-		} else {
-			buf = sg_virt(pc->sg);
-			hwif->input_data(drive, NULL, buf + pc->b_count, count);
-		}
-		bcount -= count; pc->b_count += count;
-		if (pc->b_count == pc->sg->length) {
-			if (!--pc->sg_cnt)
-				break;
-			pc->sg = sg_next(pc->sg);
-			pc->b_count = 0;
-		}
-	}
-
-	if (bcount) {
-		printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n");
-		ide_pad_transfer(drive, 0, bcount);
-	}
-}
-
-static void idescsi_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
-		unsigned int bcount)
-{
-	ide_hwif_t *hwif = drive->hwif;
 	int count;
-	char *buf;
 
 	while (bcount) {
 		count = min(pc->sg->length - pc->b_count, bcount);
@@ -182,13 +146,13 @@ static void idescsi_output_buffers(ide_d
 
 			local_irq_save(flags);
 			buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
-						pc->sg->offset;
-			hwif->output_data(drive, NULL, buf + pc->b_count, count);
+					  pc->sg->offset;
+			xf(drive, NULL, buf + pc->b_count, count);
 			kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
 			local_irq_restore(flags);
 		} else {
 			buf = sg_virt(pc->sg);
-			hwif->output_data(drive, NULL, buf + pc->b_count, count);
+			xf(drive, NULL, buf + pc->b_count, count);
 		}
 		bcount -= count; pc->b_count += count;
 		if (pc->b_count == pc->sg->length) {
@@ -200,8 +164,10 @@ static void idescsi_output_buffers(ide_d
 	}
 
 	if (bcount) {
-		printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n");
-		ide_pad_transfer(drive, 1, bcount);
+		printk(KERN_ERR "%s: scatter gather table too small, %s\n",
+				drive->name, write ? "padding with zeros"
+						   : "discarding data");
+		ide_pad_transfer(drive, write, bcount);
 	}
 }
 
@@ -370,6 +336,7 @@ static ide_startstop_t idescsi_pc_intr (
 	ide_hwif_t *hwif = drive->hwif;
 	struct ide_atapi_pc *pc = scsi->pc;
 	struct request *rq = pc->rq;
+	xfer_func_t *xferfunc;
 	unsigned int temp;
 	u16 bcount;
 	u8 stat, ireason;
@@ -445,8 +412,8 @@ static ide_startstop_t idescsi_pc_intr (
 				temp = pc->buf_size - pc->xferred;
 				if (temp) {
 					if (pc->sg)
-						idescsi_input_buffers(drive, pc,
-									temp);
+						ide_scsi_io_buffers(drive, pc,
+								    temp, 0);
 					else
 						hwif->input_data(drive, NULL,
 							pc->cur_pos, temp);
@@ -464,16 +431,16 @@ static ide_startstop_t idescsi_pc_intr (
 			printk (KERN_NOTICE "ide-scsi: The scsi wants to send us more data than expected - allowing transfer\n");
 #endif /* IDESCSI_DEBUG_LOG */
 		}
-		if (pc->sg)
-			idescsi_input_buffers(drive, pc, bcount);
-		else
-			hwif->input_data(drive, NULL, pc->cur_pos, bcount);
-	} else {
-		if (pc->sg)
-			idescsi_output_buffers(drive, pc, bcount);
-		else
-			hwif->output_data(drive, NULL, pc->cur_pos, bcount);
-	}
+		xferfunc = hwif->input_data;
+	} else
+		xferfunc = hwif->output_data;
+
+	if (pc->sg)
+		ide_scsi_io_buffers(drive, pc, bcount,
+				    !!(pc->flags & PC_FLAG_WRITING));
+	else
+		xferfunc(drive, NULL, pc->cur_pos, bcount);
+
 	/* Update the current position */
 	pc->xferred += bcount;
 	pc->cur_pos += bcount;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/40] ide: generic ATAPI support, Bartlomiej Zolnierki ..., (Sun May 18, 11:54 am)
[PATCH 01/40] ide-scsi: fix race in idescsi_transfer_pc(), Bartlomiej Zolnierki ..., (Sun May 18, 11:54 am)
[PATCH 02/40] ide-scsi: fix DRQ checking for DMA transfers ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:54 am)
[PATCH 03/40] ide-scsi: fix handling of DMA errors in ides ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:54 am)
[PATCH 04/40] ide-scsi: fix Interrupt Reason checking in i ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 05/40] ide-scsi: merge idescsi_input_buffers() and ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 06/40] ide-scsi: remove superfluous BUG_ON() from i ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 07/40] ide-scsi: add debug_log() macro, Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 08/40] ide-tape: idetape_pc_intr() should use local ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 09/40] ide-tape: remove superfluous error message f ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 10/40] ide-tape: remove superfluous warning message ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:55 am)
[PATCH 11/40] ide-tape: remove unneeded CONFIG_BLK_DEV_IDE ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:56 am)
[PATCH 12/40] ide-tape: remove stale comments from idetape ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:56 am)
[PATCH 13/40] ide-tape: remove SIMULATE_ERRORS debug code, Bartlomiej Zolnierki ..., (Sun May 18, 11:56 am)
[PATCH 14/40] ide-floppy: merge idefloppy_transfer_pc() an ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:56 am)
[PATCH 15/40] ide-{floppy,tape,scsi}: log device name inst ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:56 am)
[PATCH 16/40] ide-tape: make idetape_retry_pc() void, Bartlomiej Zolnierki ..., (Sun May 18, 11:56 am)
[PATCH 17/40] ide-tape: merge callbacks, Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 18/40] ide-tape: make pc-&gt;idetape_callback void, Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 19/40] ide-floppy: merge callbacks, Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 20/40] ide-{floppy,tape}: merge pc-&gt;idefloppy_callb ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 21/40] ide-{floppy,tape}: PC_FLAG_DMA_RECOMMENDED - ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 22/40] ide-floppy: start DMA engine in idefloppy_tr ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 23/40] ide-tape: set PC_FLAG_DMA_IN_PROGRESS flag i ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:57 am)
[PATCH 24/40] ide-tape: factor out waiting for good ireaso ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 25/40] ide: add PC_FLAG_ZIP_DRIVE pc flag, Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 26/40] ide-{cd,floppy,tape}: remove checking for dr ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 27/40] ide-scsi: set drive-&gt;scsi flag for devices h ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 28/40] ide: add ide_transfer_pc() helper, Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 29/40] ide-scsi: move idescsi_map_sg() call out fro ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 30/40] ide: add PC_FLAG_DRQ_INTERRUPT pc flag, Bartlomiej Zolnierki ..., (Sun May 18, 11:58 am)
[PATCH 31/40] ide: add ide_issue_pc() helper, Bartlomiej Zolnierki ..., (Sun May 18, 11:59 am)
[PATCH 32/40] ide-{floppy,tape}: move checking of -&gt;failed ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:59 am)
[PATCH 33/40] ide-tape: factor out DSC handling from ideta ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:59 am)
[PATCH 34/40] ide-tape: add ide_tape_io_buffers() helper, Bartlomiej Zolnierki ..., (Sun May 18, 11:59 am)
[PATCH 35/40] ide-tape: always log debug info in idetape_p ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:59 am)
[PATCH 36/40] ide-floppy: add more debugging to idefloppy_ ..., Bartlomiej Zolnierki ..., (Sun May 18, 11:59 am)
[PATCH 37/40] ide-scsi: use pc-&gt;callback, Bartlomiej Zolnierki ..., (Sun May 18, 12:00 pm)
[PATCH 38/40] ide-scsi: add more debugging to idescsi_pc_i ..., Bartlomiej Zolnierki ..., (Sun May 18, 12:00 pm)
[PATCH 39/40] ide-{floppy,scsi}: read Status Register befo ..., Bartlomiej Zolnierki ..., (Sun May 18, 12:00 pm)
[PATCH 40/40] ide: add ide_pc_intr() helper, Bartlomiej Zolnierki ..., (Sun May 18, 12:00 pm)
Re: [PATCH 04/40] ide-scsi: fix Interrupt Reason checking ..., Borislav Petkov, (Sun May 18, 10:10 pm)
Re: [PATCH 00/40] ide: generic ATAPI support, Borislav Petkov, (Thu May 22, 12:43 am)
Re: [PATCH 00/40] ide: generic ATAPI support, Bartlomiej Zolnierki ..., (Sun May 25, 6:23 am)
Re: [PATCH 04/40] ide-scsi: fix Interrupt Reason checking ..., Bartlomiej Zolnierki ..., (Tue May 27, 11:30 am)
Re: [PATCH 14/40] ide-floppy: merge idefloppy_transfer_pc( ..., Bartlomiej Zolnierki ..., (Tue May 27, 11:57 am)
Re: [PATCH 22/40] ide-floppy: start DMA engine in ideflopp ..., Bartlomiej Zolnierki ..., (Tue May 27, 11:58 am)
Re: [PATCH 14/40] ide-floppy: merge idefloppy_transfer_pc( ..., Bartlomiej Zolnierki ..., (Thu May 29, 4:01 pm)