All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Albert Lee" <albertcc@tw.ibm.com>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
	Doug Maxey <dwm@maxeymade.com>,
	IDE Linux <linux-ide@vger.kernel.org>,
	"Mudama, Eric" <eric_mudama@Maxtor.com>,
	Mark Lord <mlord@pobox.com>
Subject: Re: [PATCH libata-dev-2.6 1/3] Add CHS support
Date: Mon, 14 Feb 2005 19:23:50 +0800	[thread overview]
Message-ID: <00a101c51287$ac4c65a0$6401a8c0@tw.ibm.com> (raw)
In-Reply-To: 008e01c51286$d2f8b740$6401a8c0@tw.ibm.com

[-- Attachment #1: Type: text/plain, Size: 5954 bytes --]

> 2) Patch #3 needs to be split up into three patches:
>   a) rename variables (s/sector/block/),
>   b) reorganize read/write translation
>   c) add CHS support
> 

Patch 3-3: 
 - add CHS support to ata_scsi_verify_xlat(), ata_scsi_rw_xlat() and ata_scsiop_read_cap().

Albert

Signed-off-by: Albert Lee <albertcc@tw.ibm.com>
------------------------------------------------------------------
--- libata-dev-2.6/drivers/scsi/libata-scsi.c 2005-02-14 17:18:22.000000000 +0800
+++ libata-dev-2.6-mod/drivers/scsi/libata-scsi.c 2005-02-14 17:25:43.000000000 +0800
@@ -689,6 +689,8 @@
 static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
 {
  struct ata_taskfile *tf = &qc->tf;
+ struct ata_device *dev = qc->dev;
+ unsigned int lba   = tf->flags & ATA_TFLAG_LBA;
  unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;
  u64 dev_sectors = qc->dev->n_sectors;
  u64 block = 0;
@@ -696,7 +698,6 @@
 
  tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
  tf->protocol = ATA_PROT_NODATA;
- tf->device |= ATA_LBA;
 
  if (scsicmd[0] == VERIFY) {
   block |= ((u64)scsicmd[2]) << 24;
@@ -741,25 +742,53 @@
    return 1;
  }
 
- if (lba48) {
-  tf->command = ATA_CMD_VERIFY_EXT;
+ if (lba) {
+  if (lba48) {
+   tf->command = ATA_CMD_VERIFY_EXT;
+
+   tf->hob_nsect = (n_block >> 8) & 0xff;
+
+   tf->hob_lbah = (block >> 40) & 0xff;
+   tf->hob_lbam = (block >> 32) & 0xff;
+   tf->hob_lbal = (block >> 24) & 0xff;
+  } else {
+   tf->command = ATA_CMD_VERIFY;
 
-  tf->hob_nsect = (n_block >> 8) & 0xff;
+   tf->device |= (block >> 24) & 0xf;
+  }
 
-  tf->hob_lbah = (block >> 40) & 0xff;
-  tf->hob_lbam = (block >> 32) & 0xff;
-  tf->hob_lbal = (block >> 24) & 0xff;
- } else {
-  tf->command = ATA_CMD_VERIFY;
+  tf->nsect = n_block & 0xff;
 
-  tf->device |= (block >> 24) & 0xf;
- }
+  tf->lbah = (block >> 16) & 0xff;
+  tf->lbam = (block >> 8) & 0xff;
+  tf->lbal = block & 0xff;
 
- tf->nsect = n_block & 0xff;
+  tf->device |= ATA_LBA;
+ } else {
+  /* CHS */
+  u32 sect, head, cyl, track;
 
- tf->lbah = (block >> 16) & 0xff;
- tf->lbam = (block >> 8) & 0xff;
- tf->lbal = block & 0xff;
+  /* Convert LBA to CHS */
+  track = (u32)block / dev->sectors;
+  cyl   = track / dev->heads;
+  head  = track % dev->heads;
+  sect  = (u32)block % dev->sectors + 1;
+
+  DPRINTK("block[%u] track[%u] cyl[%u] head[%u] sect[%u] \n", (u32)block, track, cyl, head, sect);
+  
+  /* Check whether the converted CHS can fit. 
+     Cylinder: 0-65535 
+     Head: 0-15
+     Sector: 1-255*/
+  if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 
+   return 1;
+  
+  tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
+  tf->lbal = sect;
+  tf->lbam = cyl;
+  tf->lbah = cyl >> 8;
+  tf->device |= head;
+ }
 
  return 0;
 }
@@ -787,6 +816,8 @@
 static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
 {
  struct ata_taskfile *tf = &qc->tf;
+ struct ata_device *dev = qc->dev;
+ unsigned int lba   = tf->flags & ATA_TFLAG_LBA;
  unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;
  u64 block = 0;
  u32 n_block = 0;
@@ -845,34 +876,66 @@
   /* In ATA, sector count 0 are 256 or 65536 sectors, not 0 sectors. */
   return 1;
 
- if (lba48) {
-  /* The request -may- be too large for LBA48. */
-  if ((block >> 48) || (n_block > 65536))
-   return 1;
+ if (lba) {
+  if (lba48) {
+   /* The request -may- be too large for LBA48. */
+   if ((block >> 48) || (n_block > 65536))
+    return 1;
+
+   tf->hob_nsect = (n_block >> 8) & 0xff;
+
+   tf->hob_lbah = (block >> 40) & 0xff;
+   tf->hob_lbam = (block >> 32) & 0xff;
+   tf->hob_lbal = (block >> 24) & 0xff;
+  } else { 
+   /* LBA28 */
+
+   /* The request -may- be too large for LBA28. */
+   if ((block >> 28) || (n_block > 256))
+    return 1;
+
+   tf->device |= (block >> 24) & 0xf;
+  }
+ 
+  qc->nsect = n_block;
+  tf->nsect = n_block & 0xff;
 
-  tf->hob_nsect = (n_block >> 8) & 0xff;
+  tf->lbah = (block >> 16) & 0xff;
+  tf->lbam = (block >> 8) & 0xff;
+  tf->lbal = block & 0xff;
 
-  tf->hob_lbah = (block >> 40) & 0xff;
-  tf->hob_lbam = (block >> 32) & 0xff;
-  tf->hob_lbal = (block >> 24) & 0xff;
+  tf->device |= ATA_LBA;
  } else { 
-  /* LBA28 */
+  /* CHS */
+  u32 sect, head, cyl, track;
 
-  /* The request -may- be too large for LBA28. */
+  /* The request -may- be too large for CHS addressing. */
   if ((block >> 28) || (n_block > 256))
    return 1;
-
-  tf->device |= (block >> 24) & 0xf;
+   
+  /* Convert LBA to CHS */
+  track = (u32)block / dev->sectors;
+  cyl   = track / dev->heads;
+  head  = track % dev->heads;
+  sect  = (u32)block % dev->sectors + 1;
+
+  DPRINTK("block[%u] track[%u] cyl[%u] head[%u] sect[%u] \n", 
+   (u32)block, track, cyl, head, sect);
+  
+  /* Check whether the converted CHS can fit. 
+     Cylinder: 0-65535 
+     Head: 0-15
+     Sector: 1-255*/
+  if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 
+   return 1;
+  
+  qc->nsect = n_block;
+  tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
+  tf->lbal = sect;
+  tf->lbam = cyl;
+  tf->lbah = cyl >> 8;
+  tf->device |= head;
  }
- 
- qc->nsect = n_block;
- tf->nsect = n_block & 0xff;
-
- tf->lbah = (block >> 16) & 0xff;
- tf->lbam = (block >> 8) & 0xff;
- tf->lbal = block & 0xff;
-
- tf->device |= ATA_LBA;
 
  return 0;
 }
@@ -1427,10 +1490,20 @@
 
  VPRINTK("ENTER\n");
 
- if (ata_id_has_lba48(args->id))
-  n_sectors = ata_id_u64(args->id, 100);
- else
-  n_sectors = ata_id_u32(args->id, 60);
+ if (ata_id_has_lba(args->id)) {
+  if (ata_id_has_lba48(args->id))
+   n_sectors = ata_id_u64(args->id, 100);
+  else
+   n_sectors = ata_id_u32(args->id, 60);
+ } else {
+  /* CHS default translation */
+  n_sectors = args->id[1] * args->id[3] * args->id[6];
+
+  if (ata_id_current_chs_valid(args->id))
+   /* CHS current translation */
+   n_sectors = ata_id_u32(args->id, 57);
+ }
+
  n_sectors--;  /* ATA TotalUserSectors - 1 */
 
  tmp = n_sectors; /* note: truncates, if lba48 */

[-- Attachment #2: chs3-3.diff --]
[-- Type: application/octet-stream, Size: 5769 bytes --]

--- libata-dev-2.6/drivers/scsi/libata-scsi.c	2005-02-14 17:18:22.000000000 +0800
+++ libata-dev-2.6-mod/drivers/scsi/libata-scsi.c	2005-02-14 17:25:43.000000000 +0800
@@ -689,6 +689,8 @@
 static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
 {
 	struct ata_taskfile *tf = &qc->tf;
+	struct ata_device *dev = qc->dev;
+	unsigned int lba   = tf->flags & ATA_TFLAG_LBA;
 	unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;
 	u64 dev_sectors = qc->dev->n_sectors;
 	u64 block = 0;
@@ -696,7 +698,6 @@
 
 	tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
 	tf->protocol = ATA_PROT_NODATA;
-	tf->device |= ATA_LBA;
 
 	if (scsicmd[0] == VERIFY) {
 		block |= ((u64)scsicmd[2]) << 24;
@@ -741,25 +742,53 @@
 			return 1;
 	}
 
-	if (lba48) {
-		tf->command = ATA_CMD_VERIFY_EXT;
+	if (lba) {
+		if (lba48) {
+			tf->command = ATA_CMD_VERIFY_EXT;
+
+			tf->hob_nsect = (n_block >> 8) & 0xff;
+
+			tf->hob_lbah = (block >> 40) & 0xff;
+			tf->hob_lbam = (block >> 32) & 0xff;
+			tf->hob_lbal = (block >> 24) & 0xff;
+		} else {
+			tf->command = ATA_CMD_VERIFY;
 
-		tf->hob_nsect = (n_block >> 8) & 0xff;
+			tf->device |= (block >> 24) & 0xf;
+		}
 
-		tf->hob_lbah = (block >> 40) & 0xff;
-		tf->hob_lbam = (block >> 32) & 0xff;
-		tf->hob_lbal = (block >> 24) & 0xff;
-	} else {
-		tf->command = ATA_CMD_VERIFY;
+		tf->nsect = n_block & 0xff;
 
-		tf->device |= (block >> 24) & 0xf;
-	}
+		tf->lbah = (block >> 16) & 0xff;
+		tf->lbam = (block >> 8) & 0xff;
+		tf->lbal = block & 0xff;
 
-	tf->nsect = n_block & 0xff;
+		tf->device |= ATA_LBA;
+	} else {
+		/* CHS */
+		u32 sect, head, cyl, track;
 
-	tf->lbah = (block >> 16) & 0xff;
-	tf->lbam = (block >> 8) & 0xff;
-	tf->lbal = block & 0xff;
+		/* Convert LBA to CHS */
+		track = (u32)block / dev->sectors;
+		cyl   = track / dev->heads;
+		head  = track % dev->heads;
+		sect  = (u32)block % dev->sectors + 1;
+
+		DPRINTK("block[%u] track[%u] cyl[%u] head[%u] sect[%u] \n", (u32)block, track, cyl, head, sect);
+		
+		/* Check whether the converted CHS can fit. 
+		   Cylinder: 0-65535 
+		   Head: 0-15
+		   Sector: 1-255*/
+		if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 
+			return 1;
+		
+		tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
+		tf->lbal = sect;
+		tf->lbam = cyl;
+		tf->lbah = cyl >> 8;
+		tf->device |= head;
+	}
 
 	return 0;
 }
@@ -787,6 +816,8 @@
 static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
 {
 	struct ata_taskfile *tf = &qc->tf;
+	struct ata_device *dev = qc->dev;
+	unsigned int lba   = tf->flags & ATA_TFLAG_LBA;
 	unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;
 	u64 block = 0;
 	u32 n_block = 0;
@@ -845,34 +876,66 @@
 		/* In ATA, sector count 0 are 256 or 65536 sectors, not 0 sectors. */
 		return 1;
 
-	if (lba48) {
-		/* The request -may- be too large for LBA48. */
-		if ((block >> 48) || (n_block > 65536))
-			return 1;
+	if (lba) {
+		if (lba48) {
+			/* The request -may- be too large for LBA48. */
+			if ((block >> 48) || (n_block > 65536))
+				return 1;
+
+			tf->hob_nsect = (n_block >> 8) & 0xff;
+
+			tf->hob_lbah = (block >> 40) & 0xff;
+			tf->hob_lbam = (block >> 32) & 0xff;
+			tf->hob_lbal = (block >> 24) & 0xff;
+		} else { 
+			/* LBA28 */
+
+			/* The request -may- be too large for LBA28. */
+			if ((block >> 28) || (n_block > 256))
+				return 1;
+
+			tf->device |= (block >> 24) & 0xf;
+		}
+	
+		qc->nsect = n_block;
+		tf->nsect = n_block & 0xff;
 
-		tf->hob_nsect = (n_block >> 8) & 0xff;
+		tf->lbah = (block >> 16) & 0xff;
+		tf->lbam = (block >> 8) & 0xff;
+		tf->lbal = block & 0xff;
 
-		tf->hob_lbah = (block >> 40) & 0xff;
-		tf->hob_lbam = (block >> 32) & 0xff;
-		tf->hob_lbal = (block >> 24) & 0xff;
+		tf->device |= ATA_LBA;
 	} else { 
-		/* LBA28 */
+		/* CHS */
+		u32 sect, head, cyl, track;
 
-		/* The request -may- be too large for LBA28. */
+		/* The request -may- be too large for CHS addressing. */
 		if ((block >> 28) || (n_block > 256))
 			return 1;
-
-		tf->device |= (block >> 24) & 0xf;
+			
+		/* Convert LBA to CHS */
+		track = (u32)block / dev->sectors;
+		cyl   = track / dev->heads;
+		head  = track % dev->heads;
+		sect  = (u32)block % dev->sectors + 1;
+
+		DPRINTK("block[%u] track[%u] cyl[%u] head[%u] sect[%u] \n", 
+			(u32)block, track, cyl, head, sect);
+		
+		/* Check whether the converted CHS can fit. 
+		   Cylinder: 0-65535 
+		   Head: 0-15
+		   Sector: 1-255*/
+		if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 
+			return 1;
+		
+		qc->nsect = n_block;
+		tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
+		tf->lbal = sect;
+		tf->lbam = cyl;
+		tf->lbah = cyl >> 8;
+		tf->device |= head;
 	}
-	
-	qc->nsect = n_block;
-	tf->nsect = n_block & 0xff;
-
-	tf->lbah = (block >> 16) & 0xff;
-	tf->lbam = (block >> 8) & 0xff;
-	tf->lbal = block & 0xff;
-
-	tf->device |= ATA_LBA;
 
 	return 0;
 }
@@ -1427,10 +1490,20 @@
 
 	VPRINTK("ENTER\n");
 
-	if (ata_id_has_lba48(args->id))
-		n_sectors = ata_id_u64(args->id, 100);
-	else
-		n_sectors = ata_id_u32(args->id, 60);
+	if (ata_id_has_lba(args->id)) {
+		if (ata_id_has_lba48(args->id))
+			n_sectors = ata_id_u64(args->id, 100);
+		else
+			n_sectors = ata_id_u32(args->id, 60);
+	} else {
+		/* CHS default translation */
+		n_sectors = args->id[1] * args->id[3] * args->id[6];
+
+		if (ata_id_current_chs_valid(args->id))
+			/* CHS current translation */
+			n_sectors = ata_id_u32(args->id, 57);
+	}
+
 	n_sectors--;		/* ATA TotalUserSectors - 1 */
 
 	tmp = n_sectors;	/* note: truncates, if lba48 */

  reply	other threads:[~2005-02-14 11:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-06  6:02 [PATCH libata-dev-2.6 1/3] Add CHS support Albert Lee
2005-02-06  6:26 ` Jeff Garzik
2005-02-06 14:41   ` Mark Lord
2005-02-06 15:00     ` Jeff Garzik
2005-02-06 22:02       ` Mark Lord
2005-02-14 11:09   ` Albert Lee
2005-02-14 11:17     ` Albert Lee
2005-02-14 11:23       ` Albert Lee [this message]
2005-02-18 23:40 ` Jeff Garzik
2005-02-22  3:35   ` Albert Lee
2005-02-23 11:25   ` [PATCH libata-dev-2.6] Issue INITIALIZE DEVICE PARAMETERS for CHS only devices Albert Lee
2005-02-23 14:48     ` Mark Lord
2005-02-24  2:36       ` Albert Lee
2005-02-24  2:53         ` Jeff Garzik
2005-02-24  5:29           ` Albert Lee
2005-02-24  5:35             ` Jeff Garzik
2005-02-24  6:41               ` Albert Lee
2005-02-24  6:48                 ` Jeff Garzik
2005-02-24  7:01                   ` Albert Lee
2005-02-24  7:48                     ` Jeff Garzik
2005-02-25  5:01                       ` Albert Lee
2005-02-25  5:22                         ` Albert Lee
2005-02-25  5:40                         ` Jeff Garzik
2005-02-24  3:10         ` Mark Lord
2005-02-24  3:15           ` Jeff Garzik
2005-02-24  3:35             ` Mark Lord
2005-02-23 16:50     ` Bartlomiej Zolnierkiewicz
2005-02-24  3:05       ` Albert Lee

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='00a101c51287$ac4c65a0$6401a8c0@tw.ibm.com' \
    --to=albertcc@tw.ibm.com \
    --cc=bzolnier@gmail.com \
    --cc=dwm@maxeymade.com \
    --cc=eric_mudama@Maxtor.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=mlord@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.