mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sshtylyov@mvista.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
	Jeff Garzik <jgarzik@pobox.com>
Subject: Re: [PATCH v2 2/2] ata: implement MODE SELECT command
Date: Thu, 05 Jul 2012 15:42:34 +0400	[thread overview]
Message-ID: <4FF57DAA.8010405@mvista.com> (raw)
In-Reply-To: <1341481235-12708-3-git-send-email-pbonzini@redhat.com>

Hello.

On 05-07-2012 13:40, Paolo Bonzini wrote:

> The cache_type file in sysfs lets users configure the disk cache in
> write-through or write-back modes.  However, ata disks do not support
> writing to the file because they do not implement the MODE SELECT
> command.

> This patch adds a translation from MODE SELECT (for the caching page
> only) to the ATA SET FEATURES command.  The set of changeable parameters
> answered by MODE SENSE is also adjusted accordingly.

> Cc: Sergei Shtylyov <sshtylyov@mvista.com>
> Cc: Jeff Garzik <jgarzik@pobox.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   drivers/ata/libata-scsi.c |  185 +++++++++++++++++++++++++++++++++++++++++++--
>   1 files changed, 179 insertions(+), 6 deletions(-)

> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index d5aeb26..1cb88df 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
[...]
> +/**
> + *	ata_scsiop_mode_select - Simulate MODE SELECT 6, 10 commands
> + *	@qc: Storage for translated ATA taskfile
> + *
> + *	Converts a MODE SELECT command to an ATA SET FEATURES taskfile.
> + *	Assume this is invoked for direct access devices (e.g. disks) only.
> + *	There should be no block descriptor for other device types.
> + *
> + *	LOCKING:
> + *	spin_lock_irqsave(host lock)
> + */
> +static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)
> +{
> +	struct scsi_cmnd *scmd = qc->scsicmd;
> +	const u8 *cdb = scmd->cmnd;
> +	const u8 *p;
> +	u8 pg, spg;
> +	unsigned six_byte, pg_len, hdr_len;
> +	int len;
> +
> +	VPRINTK("ENTER\n");
> +
> +	six_byte = (cdb[0] == MODE_SELECT);
> +	if (six_byte) {
> +		if (scmd->cmd_len < 5)
> +			goto invalid_fld;

    Strictly speaking, it should be "invalid phase" error.

> +
> +		len = cdb[4];
> +	} else {
> +		if (scmd->cmd_len < 9)
> +			goto invalid_fld;

    The same.

> +
> +		len = (cdb[7] << 8) + cdb[8];
> +	}
> +	/* Test early for possible overrun.  */
> +	if (!scsi_sg_count(scmd) || scsi_sglist(scmd)->length < len)
> +		goto invalid_param_len;

     Strictly speaking, it's "data underrun" error.

> +	p = page_address(sg_page(scsi_sglist(scmd)));

    What if the S/G list spans multiple non-consecutive pages?

> +
> +	/* Move past header and block descriptors.  */
> +	if (six_byte)
> +		hdr_len = p[3] + 4;
> +	else
> +		hdr_len = (p[6] << 8) + p[7] + 8;
> +
> +	if (len < hdr_len)
> +		goto invalid_param_len;
> +
> +	len -= hdr_len;
> +	p += hdr_len;
> +	if (len == 0)
> +		goto skip;
> +
> +	/* Parse both possible formats for the mode page headers.  */
> +	pg = p[0] & 0x3f;
> +	if (p[0] & 0x40) {
> +		if (len < 4)
> +			goto invalid_param_len;
> +
> +		spg = p[1];
> +		pg_len = (p[2] << 8) | p[3];
> +		p += 4;
> +		len -= 4;
> +	} else {
> +		if (len < 2)
> +			goto invalid_param_len;
> +
> +		spg = 0;
> +		pg_len = p[1];
> +		p += 2;
> +		len -= 2;
> +	}
> +
> +	/*
> +	 * Only one page has changeable data, so we only support setting one
> +	 * page at a time.
> +	 */
> +	if (len < pg_len)
> +		goto invalid_param;

     Not 'invalid_param_len'?

> +
> +	/*
> +	 * No mode subpages supported (yet) but asking for _all_
> +	 * subpages may be valid
> +	 */
> +	if (spg && (spg != ALL_SUB_MPAGES))
> +		goto invalid_param;

    Rather "paramater not supported" (0x26/0x01)...

> +	if (pg_len > len)
> +		goto invalid_param_len;

    We have just checked this.

> +	switch (pg) {
> +	case CACHE_MPAGE:
> +		if (ata_mselect_caching(qc, p, pg_len) < 0)
> +			goto invalid_param;

    Rather "parameter not supported"?

> +		break;
> +
> +	default:		/* invalid page code */
> +		goto invalid_param;

    Rather "paramater not supported"...

> +	}
> +
> +	return 0;

MBR, Sergei

  reply	other threads:[~2012-07-05 11:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05  9:40 [PATCH v2 0/2] ata: MODE SELECT implementation Paolo Bonzini
2012-07-05  9:40 ` [PATCH v2 1/2] ata: support MODE SENSE request for changeable and default parameters Paolo Bonzini
2012-07-05  9:40 ` [PATCH v2 2/2] ata: implement MODE SELECT command Paolo Bonzini
2012-07-05 11:42   ` Sergei Shtylyov [this message]
2012-07-05 12:05     ` Paolo Bonzini
2012-07-05 19:42       ` Sergei Shtylyov
2012-07-26  7:25 ` [PATCH v2 0/2] ata: MODE SELECT implementation Paolo Bonzini
2012-07-26 13:47   ` Jeff Garzik
2012-07-26 13:55     ` Paolo Bonzini

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=4FF57DAA.8010405@mvista.com \
    --to=sshtylyov@mvista.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.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

Powered by JetHome