linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Randy Dunlap <randy.dunlap@oracle.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
	kyle@canonical.com
Subject: Re: HPA patches
Date: Fri, 23 Mar 2007 11:24:11 -0700	[thread overview]
Message-ID: <20070323112411.f6a8a762.randy.dunlap@oracle.com> (raw)
In-Reply-To: <20070323191321.5d00887a@lxorguk.ukuu.org.uk>

On Fri, 23 Mar 2007 19:13:21 +0000 Alan Cox wrote:

> For reference this is what I am currently using with 2.6.21-rc4-mm1 and
> it is working for all my test cases so far: Its basically Kyle's patch
> with a libata switch to turn it on/off and some minor fixups from
> the original patch as posted
> 
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.21-rc4-mm1/drivers/ata/libata-core.c linux-2.6.21-rc4-mm1/drivers/ata/libata-core.c
> --- linux.vanilla-2.6.21-rc4-mm1/drivers/ata/libata-core.c	2007-03-23 11:49:49.000000000 +0000
> +++ linux-2.6.21-rc4-mm1/drivers/ata/libata-core.c	2007-03-23 13:05:15.000000000 +0000
> @@ -89,6 +89,10 @@
>  module_param_named(fua, libata_fua, int, 0444);
>  MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
>  
> +static int ata_ignore_hpa = 0;

Don't init to 0.  Not needed, bloats binary files.

> +module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644);
> +MODULE_PARM_DESC(ignore_hpa, "Ignore HPA (0=off 1=on)");

So 1 = on = ignore, right?

> +
>  static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
>  module_param(ata_probe_timeout, int, 0444);
>  MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
> @@ -808,6 +812,202 @@
>  	*p = '\0';
>  }
>  
> +
> +/**
> + *	ata_read_native_max_address_ext	-	LBA48 native max query
> + *	@dev: Device to query
> + *
> + *	Performa an LBA48 size query upon the device in question. Return the

	Perform

> + *	actual LBA48 size or zero if the command fails.
> + */
> +
> +static u64 ata_read_native_max_address_ext(struct ata_device *dev)
> +{
> +	unsigned int err;
> +	struct ata_taskfile tf;
> +
> +	ata_tf_init(dev, &tf);
> +
> +	tf.command = ATA_CMD_READ_NATIVE_MAX_EXT;
> +	tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | ATA_TFLAG_ISADDR;
> +	tf.protocol |= ATA_PROT_NODATA;
> +	tf.device = 0x40;

What is 0x40?  can it be #defined (or enum-ed) instead of a magic
value?  please?  (more of same below)

> +
> +	err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
> +	if (err)
> +		return 0;
> +
> +	return ata_tf_to_lba48(&tf);
> +}
> +
> +/**
> + *	ata_read_native_max_address	-	LBA28 native max query
> + *	@dev: Device to query
> + *
> + *	Performa an LBA28 size query upon the device in question. Return the

	Perform

> + *	actual LBA28 size or zero if the command fails.
> + */
> +
> +static u64 ata_read_native_max_address(struct ata_device *dev)
> +{
> +	unsigned int err;
> +	struct ata_taskfile tf;
> +
> +	ata_tf_init(dev, &tf);
> +
> +	tf.command = ATA_CMD_READ_NATIVE_MAX;
> +	tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
> +	tf.protocol |= ATA_PROT_NODATA;
> +	tf.device = 0x40;
> +
> +	err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
> +	if (err)
> +		return 0;
> +
> +	return ata_tf_to_lba(&tf);
> +}
> +
> +/**
> + *	ata_set_native_max_address_ext	-	LBA48 native max set
> + *	@dev: Device to query
> + *
> + *	Perform an LBA48 size set max upon the device in question. Return the
> + *	actual LBA48 size or zero if the command fails.
> + */
> +
> +static u64 ata_set_native_max_address_ext(struct ata_device *dev, u64 new_sectors)
> +{
...
> +}
> +
> +/**
> + *	ata_set_native_max_address	-	LBA28 native max set
> + *	@dev: Device to query
> + *
> + *	Perform an LBA28 size set max upon the device in question. Return the
> + *	actual LBA28 size or zero if the command fails.
> + */
> +
> +static u64 ata_set_native_max_address(struct ata_device *dev, u64 new_sectors)
> +{
...
> +}
> +
> +/**
> + *	ata_hpa_resize		-	Resize a device with an HPA set
> + *	@dev: Device to resize
> + *
> + *	Read the size of an LBA28 or LBA48 disk with HPA features and resize
> + *	it if required to the full size of the media. The caller must check
> + *	the drive has the HPA feature set enabled.
> + */
> +
> +static u64 ata_hpa_resize(struct ata_device *dev)
> +{
> +	u64 sectors = dev->n_sectors;
> +	u64 hpa_sectors;
> +	
> +	if (ata_id_has_lba48(dev->id))
> +		hpa_sectors = ata_read_native_max_address_ext(dev);
> +	else
> +		hpa_sectors = ata_read_native_max_address(dev);
> +
> +	/* if no hpa, both should be equal */
> +	ata_dev_printk(dev, KERN_INFO, "%s 1: sectors = %lld, hpa_sectors = %lld\n",
> +		__FUNCTION__, sectors, hpa_sectors);

(long long) or (unsigned long long) on sectors and hpa_sectors...

> +
> +	if (hpa_sectors > sectors) {
> +		ata_dev_printk(dev, KERN_INFO,
> +			"Host Protected Area detected:\n"
> +			"\tcurrent size: %lld sectors\n"
> +			"\tnative size: %lld sectors\n",
> +			sectors, hpa_sectors);

printk format types ok?

> +
> +		if (ata_ignore_hpa) {
> +			if (ata_id_has_lba48(dev->id))
> +				hpa_sectors = ata_set_native_max_address_ext(dev, hpa_sectors);
> +			else
> +				hpa_sectors = ata_set_native_max_address(dev, hpa_sectors);
> +
> +			if (hpa_sectors) {
> +				ata_dev_printk(dev, KERN_INFO,
> +					"native size increased to %lld sectors\n", hpa_sectors);

Line lengths < 80 and printk format types?

> +				return hpa_sectors;
> +			}
> +		}
> +	}
> +	return sectors;
> +}
> +
>  static u64 ata_id_n_sectors(const u16 *id)
>  {
>  	if (ata_id_has_lba(id)) {
> @@ -1658,6 +1858,7 @@
>  			snprintf(revbuf, 7, "ATA-%d",  ata_id_major_version(id));
>  
>  		dev->n_sectors = ata_id_n_sectors(id);
> +		dev->n_sectors_boot = dev->n_sectors;
>  
>  		/* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
>  		ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
> @@ -1684,6 +1885,9 @@
>  					dev->flags |= ATA_DFLAG_FLUSH_EXT;
>  			}
>  
> +			if (ata_id_hpa_enabled(dev->id))
> +				dev->n_sectors = ata_hpa_resize(dev);
> +
>  			/* config NCQ */
>  			ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
>  
> @@ -3384,6 +3595,11 @@
>  			       "%llu != %llu\n",
>  			       (unsigned long long)dev->n_sectors,
>  			       (unsigned long long)new_n_sectors);
> +		/* Are we the boot time size - if so we appear to be the
> +		   same disk at this point and our HPA got reapplied */
> +		if (ata_ignore_hpa && dev->n_sectors_boot == new_n_sectors 
> +		    && ata_id_hpa_enabled(new_id))
> +			return 1;
>  		return 0;
>  	}


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

  reply	other threads:[~2007-03-23 18:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-23 19:13 HPA patches Alan Cox
2007-03-23 18:24 ` Randy Dunlap [this message]
2007-03-23 20:08   ` Alan Cox
2007-03-23 19:22     ` David Miller
2007-03-23 21:51       ` Alan Cox
2007-03-23 20:03     ` Randy Dunlap
2007-03-23 21:47       ` Alan Cox
2007-03-23 22:47         ` Chuck Ebbert
2007-04-13  3:16       ` Kyle McMartin
2007-04-13 10:56         ` Alan Cox
2007-03-23 20:56 ` Matthew Garrett
2007-03-27  5:00   ` Jeff Garzik
2007-03-26 20:45 ` Kyle McMartin
2007-03-28  0:08 ` Matthew Garrett
2007-03-28  0:16   ` Matthew Garrett
2007-03-28  1:16     ` ata_piix can't drive Mac hardware properly Matthew Garrett
2007-03-28  4:07       ` Matthew Garrett
2007-03-28  9:57   ` HPA patches Alan Cox
2007-03-28 20:08     ` Matthew Garrett
2007-03-28 21:54       ` Alan Cox
2007-03-28 21:28         ` Matthew Garrett
2007-03-28 21:30         ` Kyle McMartin

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=20070323112411.f6a8a762.randy.dunlap@oracle.com \
    --to=randy.dunlap@oracle.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=kyle@canonical.com \
    --cc=linux-ide@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).