public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org,
	joerg@dorchain.net, geert@linux-m68k.org, donari75@gmail.com,
	davem@davemloft.net, jdike@linux.intel.com,
	benh@kernel.crashing.org, Laurent@lvivier.info
Subject: Re: [RFC PATCHSET linux-2.6-block#for-2.6.31] block: lld cleanup patches
Date: Wed, 29 Apr 2009 07:36:20 +0900	[thread overview]
Message-ID: <49F784E4.9040009@kernel.org> (raw)
In-Reply-To: <200904282038.31075.bzolnier@gmail.com>

Bartlomiej Zolnierkiewicz wrote:
> Fine with me and thanks for handling it.  BTW do you still have version this
> patch re-synced on top of other changes around?

Yeap, inlined below.

From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Subject: mg_disk: fix issue with data integrity on error in mg_write()

We cannot acknowledge the sector write before checking its status
(which is done on the next loop iteration) and we also need to do
the final status register check after writing the last sector.

Fix mg_write() to match mg_write_intr() in this regard.

While at it:
- add mg_read_one() and mg_write_one() helpers
- always use MG_SECTOR_SIZE and remove MG_STORAGE_BUFFER_SIZE

Cc: unsik Kim <donari75@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/block/mg_disk.c |   85 ++++++++++++++++++++++++++----------------------
 1 file changed, 47 insertions(+), 38 deletions(-)

Index: block/drivers/block/mg_disk.c
===================================================================
--- block.orig/drivers/block/mg_disk.c
+++ block/drivers/block/mg_disk.c
@@ -37,7 +37,6 @@
 
 /* Register offsets */
 #define MG_BUFF_OFFSET			0x8000
-#define MG_STORAGE_BUFFER_SIZE		0x200
 #define MG_REG_OFFSET			0xC000
 #define MG_REG_FEATURE			(MG_REG_OFFSET + 2)	/* write case */
 #define MG_REG_ERROR			(MG_REG_OFFSET + 2)	/* read case */
@@ -488,9 +487,18 @@ static unsigned int mg_out(struct mg_hos
 	return MG_ERR_NONE;
 }
 
+static void mg_read_one(struct mg_host *host, struct request *req)
+{
+	u16 *buff = (u16 *)req->buffer;
+	u32 i;
+
+	for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
+		*buff++ = inw((unsigned long)host->dev_base + MG_BUFF_OFFSET +
+			      (i << 1));
+}
+
 static void mg_read(struct request *req)
 {
-	u32 j;
 	struct mg_host *host = req->rq_disk->private_data;
 
 	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, NULL) !=
@@ -501,26 +509,33 @@ static void mg_read(struct request *req)
 	       req->nr_sectors, req->sector, req->buffer);
 
 	do {
-		u16 *buff = (u16 *)req->buffer;
-
 		if (mg_wait(host, ATA_DRQ,
 			    MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
 			mg_bad_rw_intr(host);
 			return;
 		}
-		for (j = 0; j < MG_SECTOR_SIZE >> 1; j++)
-			*buff++ = inw((unsigned long)host->dev_base +
-				      MG_BUFF_OFFSET + (j << 1));
+
+		mg_read_one(host, req);
 
 		outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base +
 				MG_REG_COMMAND);
 	} while (__blk_end_request(req, 0, MG_SECTOR_SIZE));
 }
 
+static void mg_write_one(struct mg_host *host, struct request *req)
+{
+	u16 *buff = (u16 *)req->buffer;
+	u32 i;
+
+	for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
+		outw(*buff++, (unsigned long)host->dev_base + MG_BUFF_OFFSET +
+		     (i << 1));
+}
+
 static void mg_write(struct request *req)
 {
-	u32 j;
 	struct mg_host *host = req->rq_disk->private_data;
+	bool rem;
 
 	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, NULL) !=
 			MG_ERR_NONE) {
@@ -531,20 +546,31 @@ static void mg_write(struct request *req
 	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
 	       req->nr_sectors, req->sector, req->buffer);
 
-	do {
-		u16 *buff = (u16 *)req->buffer;
+	if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ,
+		    MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
+		mg_bad_rw_intr(host);
+		return;
+	}
+
+	mg_write_one(host, req);
+
+	outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
 
-	if (mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
+	do {
+		if ((req->nr_sectors > 1) &&
+		     mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ,
+			     MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
 			mg_bad_rw_intr(host);
 			return;
 		}
-		for (j = 0; j < MG_SECTOR_SIZE >> 1; j++)
-			outw(*buff++, (unsigned long)host->dev_base +
-				      MG_BUFF_OFFSET + (j << 1));
 
-		outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
-				MG_REG_COMMAND);
-	} while (__blk_end_request(req, 0, MG_SECTOR_SIZE));
+		rem = __blk_end_request(req, 0, MG_SECTOR_SIZE);
+		if (rem)
+			mg_write_one(host, req);
+
+		outb(MG_CMD_WR_CONF,
+		     (unsigned long)host->dev_base + MG_REG_COMMAND);
+	} while (rem);
 }
 
 static void mg_read_intr(struct mg_host *host)
@@ -571,12 +597,9 @@ static void mg_read_intr(struct mg_host
 ok_to_read:
 	/* get current segment of request */
 	req = elv_next_request(host->breq);
-	buff = (u16 *)req->buffer;
 
 	/* read 1 sector */
-	for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
-		*buff++ = inw((unsigned long)host->dev_base + MG_BUFF_OFFSET +
-			      (i << 1));
+	mg_read_one(host, req);
 
 	MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
 			req->sector, req->nr_sectors - 1, req->buffer);
@@ -594,9 +617,8 @@ ok_to_read:
 
 static void mg_write_intr(struct mg_host *host)
 {
-	u32 i, j;
-	u16 *buff;
 	struct request *req;
+	u32 i;
 	bool rem;
 
 	/* get current segment of request */
@@ -620,12 +642,7 @@ static void mg_write_intr(struct mg_host
 ok_to_write:
 	if ((rem = __blk_end_request(req, 0, MG_SECTOR_SIZE))) {
 		/* write 1 sector and set handler if remains */
-		buff = (u16 *)req->buffer;
-		for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
-			outw(*buff, (unsigned long)host->dev_base +
-					MG_BUFF_OFFSET + (j << 1));
-			buff++;
-		}
+		mg_write_one(host, req);
 		MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
 				req->sector, req->nr_sectors, req->buffer);
 		host->mg_do_intr = mg_write_intr;
@@ -689,9 +706,6 @@ static unsigned int mg_issue_req(struct
 		unsigned int sect_num,
 		unsigned int sect_cnt)
 {
-	u16 *buff;
-	u32 i;
-
 	switch (rq_data_dir(req)) {
 	case READ:
 		if (mg_out(host, sect_num, sect_cnt, MG_CMD_RD, &mg_read_intr)
@@ -715,12 +729,7 @@ static unsigned int mg_issue_req(struct
 			mg_bad_rw_intr(host);
 			return host->error;
 		}
-		buff = (u16 *)req->buffer;
-		for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
-			outw(*buff, (unsigned long)host->dev_base +
-					MG_BUFF_OFFSET + (i << 1));
-			buff++;
-		}
+		mg_write_one(host, req);
 		mod_timer(&host->timer, jiffies + 3 * HZ);
 		outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
 				MG_REG_COMMAND);

-- 
tejun

      reply	other threads:[~2009-04-28 22:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-23 12:25 [RFC PATCHSET linux-2.6-block#for-2.6.31] block: lld cleanup patches Tejun Heo
2009-04-23 12:25 ` [PATCH 01/12] block-update-end_cur Tejun Heo
2009-04-23 12:25 ` [PATCH 02/12] block: don't init rq fields unnecessarily Tejun Heo
2009-04-23 12:25 ` [PATCH 03/12] amiflop,ataflop,xd,mg_disk: clean up unnecessary stuff from block drivers Tejun Heo
2009-04-23 12:25 ` [PATCH 04/12] ps3disk: simplify request completion Tejun Heo
2009-04-23 12:25 ` [PATCH 05/12] sunvdc: kill vdc_end_request() Tejun Heo
2009-04-23 13:33   ` David Miller
2009-04-28  2:54     ` Tejun Heo
2009-04-23 12:25 ` [PATCH 06/12] ubd: cleanup completion path Tejun Heo
2009-04-23 12:25 ` [PATCH 07/12] ubd: drop unnecessary rq->sector manipulation Tejun Heo
2009-04-23 12:25 ` [PATCH 08/12] hd: clean up request completion paths Tejun Heo
2009-04-23 12:25 ` [PATCH 09/12] swim3: " Tejun Heo
2009-04-23 12:25 ` [PATCH 10/12] swim: " Tejun Heo
2009-04-23 12:25 ` [PATCH 11/12] mg_disk: fold mg_disk.h into mg_disk.c Tejun Heo
2009-04-23 12:25 ` [PATCH 12/12] mg_disk: clean up request completion paths Tejun Heo
2009-04-24 19:41 ` [RFC PATCHSET linux-2.6-block#for-2.6.31] block: lld cleanup patches Bartlomiej Zolnierkiewicz
2009-04-28  3:44   ` Tejun Heo
2009-04-28 18:38     ` Bartlomiej Zolnierkiewicz
2009-04-28 22:36       ` Tejun Heo [this message]

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=49F784E4.9040009@kernel.org \
    --to=tj@kernel.org \
    --cc=Laurent@lvivier.info \
    --cc=axboe@kernel.dk \
    --cc=benh@kernel.crashing.org \
    --cc=bzolnier@gmail.com \
    --cc=davem@davemloft.net \
    --cc=donari75@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=jdike@linux.intel.com \
    --cc=joerg@dorchain.net \
    --cc=linux-kernel@vger.kernel.org \
    /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