linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Boaz Harrosh <bharrosh@panasas.com>
Cc: Jeff Garzik <jeff@garzik.org>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH] libata support for rotation speed
Date: Sun, 22 Jun 2008 07:31:06 -0600	[thread overview]
Message-ID: <20080622133105.GY4392@parisc-linux.org> (raw)
In-Reply-To: <485E4894.7000508@panasas.com>

On Sun, Jun 22, 2008 at 03:41:56PM +0300, Boaz Harrosh wrote:
> > +		rbuf[4] = args->id[217] >> 8;
> > +		rbuf[5] = args->id[217];
> 
> args->id of struct ata_scsi_args are defined as u16.
> Are they actually SWABed at this point? Are they LE? BE?

They're cpu-endian at this point, I believe.  See ata_dev_read_id() in
libata-core.c where it calls swap_buf_le16().

> if args->id are actually __be16 then above should be
>  +		put_unaligned(args->id[217], &rbuf[4]);
> else
>  +		put_unaligned_be16(args->id[217], &rbuf[4]);

But the buf isn't unaligned, nor the offset within it.  And I
get confused by all these macros anyway.  If we had something like
store_scsi_u16(unsigned char *, u16), I'd use that, but put_unaligned_be16
just doesn't make sense.

I actually wrote my own accessors for scsi_ram.  If they were to be more
generic, they ought to be renamed, but this is what I found useful:

/*
 * SCSI requires quantities to be written MSB.  They're frequently misaligned,
 * so don't mess about with cpu_to_beN, just access it byte-wise
 */
static void scsi_ram_put_u32(unsigned char *addr, unsigned int data)
{
        addr[0] = data >> 24;
        addr[1] = data >> 16;
        addr[2] = data >> 8;
        addr[3] = data;
}

static unsigned int scsi_ram_get_u16(unsigned char *addr)
{
        unsigned int data;
        data = addr[0] << 8;
        data |= addr[1];

        return data;
}

static unsigned int scsi_ram_get_u24(unsigned char *addr)
{
        unsigned int data;
        data = addr[0] << 16;
        data |= addr[1] << 8;
        data |= addr[2];

        return data;
}

static unsigned int scsi_ram_get_u32(unsigned char *addr)
{
        unsigned int data;
        data = addr[0] << 24;
        data |= addr[1] << 16;
        data |= addr[2] << 8;
        data |= addr[3];

        return data;
}

I'm sure a more fully-featured set would include put_u24 and put_u16 too.
For the curious, u24 is useful for implementing read6/write6.

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

  reply	other threads:[~2008-06-22 13:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-19 16:02 [PATCH] libata support for rotation speed Matthew Wilcox
2008-06-19 17:59 ` Matthew Wilcox
2008-06-19 18:24   ` James Bottomley
2008-06-19 18:31     ` Matthew Wilcox
2008-06-19 19:01       ` Jeff Garzik
2008-06-19 19:13         ` Matthew Wilcox
2008-06-22 12:41           ` Boaz Harrosh
2008-06-22 13:31             ` Matthew Wilcox [this message]
2008-06-22 13:44               ` James Bottomley
2008-06-22 14:18               ` Boaz Harrosh
2008-06-27  6:56           ` Jeff Garzik

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=20080622133105.GY4392@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=bharrosh@panasas.com \
    --cc=jeff@garzik.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@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).