linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: linux-ide@vger.kernel.org
Cc: Borislav Petkov <petkovbb@gmail.com>,
	Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 05/40] ide-scsi: merge idescsi_input_buffers() and idescsi_output_buffers()
Date: Sun, 18 May 2008 20:55:12 +0200	[thread overview]
Message-ID: <20080518185512.5636.28587.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20080518185428.5636.77234.sendpatchset@localhost.localdomain>

* 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;

  parent reply	other threads:[~2008-05-18 18:37 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-18 18:54 [PATCH 00/40] ide: generic ATAPI support Bartlomiej Zolnierkiewicz
2008-05-18 18:54 ` [PATCH 01/40] ide-scsi: fix race in idescsi_transfer_pc() Bartlomiej Zolnierkiewicz
2008-05-18 18:54 ` [PATCH 02/40] ide-scsi: fix DRQ checking for DMA transfers in idescsi_pc_intr() Bartlomiej Zolnierkiewicz
2008-05-18 18:54 ` [PATCH 03/40] ide-scsi: fix handling of DMA errors " Bartlomiej Zolnierkiewicz
2008-05-18 18:55 ` [PATCH 04/40] ide-scsi: fix Interrupt Reason checking " Bartlomiej Zolnierkiewicz
2008-05-19  5:10   ` Borislav Petkov
2008-05-27 18:30     ` Bartlomiej Zolnierkiewicz
2008-05-18 18:55 ` Bartlomiej Zolnierkiewicz [this message]
2008-05-18 18:55 ` [PATCH 06/40] ide-scsi: remove superfluous BUG_ON() from idescsi_transfer_pc() Bartlomiej Zolnierkiewicz
2008-05-18 18:55 ` [PATCH 07/40] ide-scsi: add debug_log() macro Bartlomiej Zolnierkiewicz
2008-05-18 18:55 ` [PATCH 08/40] ide-tape: idetape_pc_intr() should use local_irq_enable_in_hardirq() Bartlomiej Zolnierkiewicz
2008-05-18 18:55 ` [PATCH 09/40] ide-tape: remove superfluous error message from idetape_pc_intr() Bartlomiej Zolnierkiewicz
2008-05-18 18:55 ` [PATCH 10/40] ide-tape: remove superfluous warning message from idetape_issue_pc() Bartlomiej Zolnierkiewicz
2008-05-18 18:56 ` [PATCH 11/40] ide-tape: remove unneeded CONFIG_BLK_DEV_IDEDMA ifdef Bartlomiej Zolnierkiewicz
2008-05-18 18:56 ` [PATCH 12/40] ide-tape: remove stale comments from idetape_pc_intr() Bartlomiej Zolnierkiewicz
2008-05-18 18:56 ` [PATCH 13/40] ide-tape: remove SIMULATE_ERRORS debug code Bartlomiej Zolnierkiewicz
2008-05-18 18:56 ` [PATCH 14/40] ide-floppy: merge idefloppy_transfer_pc() and idefloppy_transfer_pc1() Bartlomiej Zolnierkiewicz
2008-05-21  5:24   ` Borislav Petkov
2008-05-27 18:57     ` Bartlomiej Zolnierkiewicz
2008-05-27  5:37       ` Borislav Petkov
2008-05-29 23:01         ` Bartlomiej Zolnierkiewicz
2008-05-18 18:56 ` [PATCH 15/40] ide-{floppy,tape,scsi}: log device name instead of driver name Bartlomiej Zolnierkiewicz
2008-05-18 18:56 ` [PATCH 16/40] ide-tape: make idetape_retry_pc() void Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 17/40] ide-tape: merge callbacks Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 18/40] ide-tape: make pc->idetape_callback void Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 19/40] ide-floppy: merge callbacks Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 20/40] ide-{floppy,tape}: merge pc->idefloppy_callback and pc->idetape_callback Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 21/40] ide-{floppy,tape}: PC_FLAG_DMA_RECOMMENDED -> PC_FLAG_DMA_OK Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 22/40] ide-floppy: start DMA engine in idefloppy_transfer_pc1() Bartlomiej Zolnierkiewicz
2008-05-20 11:00   ` Sergei Shtylyov
2008-05-27 18:58     ` Bartlomiej Zolnierkiewicz
2008-05-18 18:57 ` [PATCH 23/40] ide-tape: set PC_FLAG_DMA_IN_PROGRESS flag in idetape_transfer_pc() Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 24/40] ide-tape: factor out waiting for good ireason from idetape_transfer_pc() Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 25/40] ide: add PC_FLAG_ZIP_DRIVE pc flag Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 26/40] ide-{cd,floppy,tape}: remove checking for drive->scsi Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 27/40] ide-scsi: set drive->scsi flag for devices handled by the driver Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 28/40] ide: add ide_transfer_pc() helper Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 29/40] ide-scsi: move idescsi_map_sg() call out from idescsi_issue_pc() Bartlomiej Zolnierkiewicz
2008-05-18 18:58 ` [PATCH 30/40] ide: add PC_FLAG_DRQ_INTERRUPT pc flag Bartlomiej Zolnierkiewicz
2008-05-18 18:59 ` [PATCH 31/40] ide: add ide_issue_pc() helper Bartlomiej Zolnierkiewicz
2008-05-18 18:59 ` [PATCH 32/40] ide-{floppy,tape}: move checking of ->failed_pc to ->callback Bartlomiej Zolnierkiewicz
2008-05-18 18:59 ` [PATCH 33/40] ide-tape: factor out DSC handling from idetape_pc_intr() Bartlomiej Zolnierkiewicz
2008-05-18 18:59 ` [PATCH 34/40] ide-tape: add ide_tape_io_buffers() helper Bartlomiej Zolnierkiewicz
2008-05-18 18:59 ` [PATCH 35/40] ide-tape: always log debug info in idetape_pc_intr() if debugging is enabled Bartlomiej Zolnierkiewicz
2008-05-18 18:59 ` [PATCH 36/40] ide-floppy: add more debugging to idefloppy_pc_intr() Bartlomiej Zolnierkiewicz
2008-05-18 19:00 ` [PATCH 37/40] ide-scsi: use pc->callback Bartlomiej Zolnierkiewicz
2008-05-18 19:00 ` [PATCH 38/40] ide-scsi: add more debugging to idescsi_pc_intr() Bartlomiej Zolnierkiewicz
2008-05-18 19:00 ` [PATCH 39/40] ide-{floppy,scsi}: read Status Register before stopping DMA engine Bartlomiej Zolnierkiewicz
2008-05-18 19:00 ` [PATCH 40/40] ide: add ide_pc_intr() helper Bartlomiej Zolnierkiewicz
2008-05-22  7:43 ` [PATCH 00/40] ide: generic ATAPI support Borislav Petkov
2008-05-25 13:23   ` Bartlomiej Zolnierkiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080518185512.5636.28587.sendpatchset@localhost.localdomain \
    --to=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=petkovbb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).