Re: Inquiry data and emulated SG devices

2007-10-17 Thread Jeff Garzik

Robert Hancock wrote:

This doesn't seem a very reliable way to identify an IDE device, as all
that 0 means is that the device does not claim conformance to any
standard. I would think it would be legitimate for an IDE device to put
a value like 5 in there as well, if it complies with SPC-4..


Via the this-doesnt-really-matter-but-it-should-be-noted department:

According to the latest on t10.org, MMC retroactively permitted SCSI 
version to be zero, for MMC-compliant USB and ATAPI devices.




In the case of libata though, that appears to be due to this code in
drivers/ata/libata-scsi.c:

/* ATAPI devices typically report zero for their SCSI version,
 * and sometimes deviate from the spec WRT response data
 * format.  If SCSI version is reported as zero like normal,
 * then we make the following fixups:  1) Fake MMC-5 version,
 * to indicate to the Linux scsi midlayer this is a modern
 * device.  2) Ensure response data format / ATAPI information
 * are always correct.
 */
if (buf[2] == 0) {
buf[2] = 0x5;
buf[3] = 0x32;
}

This technically seems to go against what the SCSI/ATA Translation (SAT)
spec says regarding INQUIRY on ATAPI devices: "the SATL shall use the
ATA PACKET Command feature set to pass all INQUIRY commands and
parameter data to the ATAPI device without altering the INQUIRY
commands or the parameter data." However, it might realistically be
needed if the SCSI layer in the kernel has problems with a device
indicating it supports no SCSI version..


The above tweak is entirely software->software communication...  as the 
comment you quoted notes, it's just a signal to the SCSI midlayer.


At the moment, the SCSI midlayer assumes any device that reports scsi 
version as less than 2 is forced to SCSI version 2.  Ultimately that's 
incorrect behavior for all ATAPI devices (and later MMC revisions).


At the time, libata simply worked around this SCSI buglet in its own 
code, since that was easier than auditing all SCSI code paths to ensure 
new ATAPI/USB MMC logic does not break ancient devices.


But if someone is motivated enough to revisit this...

Jeff


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 27/32] scsi_data_buffer

2007-10-17 Thread Matthew Wilcox
On Wed, Oct 17, 2007 at 08:21:15PM +0200, Boaz Harrosh wrote:
>   - Group all IO members of scsi_cmnd into a scsi_data_buffer
> structure.

> +struct scsi_data_buffer {
> + unsigned length;
> + int resid;
> + unsigned short sg_count;
> + unsigned short alloc_sg_count;
> + struct scatterlist* sglist;
> +};

This has exactly the problems I thought it would have.  Due to alignment
rules, it grows the scsi_cmnd from 368 to 376 bytes on x86-64.
It remains at 272 bytes on i386 though, which is some consolation.
By porting the patch I had for shrinking the scsi_cmnd, I can get it
down to 352 bytes, but not as far as the 344 bytes I had it at before.

The problem is the padding at the *end* of scsi_data_buffer (er, after I
rearrange it in the patch below).  There's nothing we can realistically
put in it, given that we don't want to expand scsi_data_buffer's size on
32-bit machines.  I have a fix ... but I don't think you'll like it.
I certainly don't.  But it does get us back down to 344 bytes.

Updated patch below.  I'm fully expecting the 'result' shenanigan to get
it NACKed, but I'd like to see if it inspires anyone else to a more
creative way of saving this space.

---

Thanks to acme's pahole utility, I found some places where we can save
a lot of bytes in scsi_cmnd, just by rearranging struct elements and
reducing the size of some elements.  We go from 272 to 260 bytes on x86
and from 368 to 344 bytes on x86-64.

 - eh_eflags had a 4-byte hole after it on 64-bit.  In fact, this has
   value 0 or 1, so reduce it to an unsigned char, and put it with the
   other chars in scsi_cmnd.  Saves 8 bytes on 64-bit.
 - sc_data_direction has a value from 0-3, so make it an unsigned char
   rather than an enum.  Saves at least 4 bytes.
 - Putting 'tag' with the other char elements saves another 4 bytes
 - Moving 'result' into the union with the deprecated members saves 8
   bytes on 64-bit.

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 047ffe6..2b10779 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -13,22 +13,21 @@ struct Scsi_Host;
 struct scsi_device;
 
 struct scsi_data_buffer {
+   struct scatterlist* sglist;
unsigned length;
int resid;
unsigned short sg_count;
unsigned short alloc_sg_count;
-   struct scatterlist* sglist;
 };
 
 /* embedded in scsi_cmnd */
 struct scsi_pointer {
char *ptr;  /* data pointer */
-   int this_residual;  /* left in this buffer */
struct scatterlist *buffer; /* which buffer */
+   dma_addr_t dma_handle;
+   int this_residual;  /* left in this buffer */
int buffers_residual;   /* how many buffers left */
 
-dma_addr_t dma_handle;
-
volatile int Status;
volatile int Message;
volatile int have_data_in;
@@ -40,7 +39,6 @@ struct scsi_cmnd {
struct scsi_device *device;
struct list_head list;  /* scsi_cmnd participates in queue lists */
struct list_head eh_entry; /* entry for the host eh_cmd_q */
-   int eh_eflags;  /* Used by error handlr */
 
/*
 * A SCSI Command is assigned a nonzero serial_number before passed
@@ -64,7 +62,9 @@ struct scsi_cmnd {
int timeout_per_command;
 
unsigned char cmd_len;
-   enum dma_data_direction sc_data_direction;
+   unsigned char eh_eflags;/* Used by error handler */
+   unsigned char sc_data_direction;/* enum dma_data_direction */
+   unsigned char tag;  /* SCSI-II queued command tag */
 
/* These elements define the operation we are about to perform */
 #define MAX_COMMAND_SIZE   16
@@ -109,10 +109,6 @@ struct scsi_cmnd {
 * obtained by scsi_malloc is guaranteed
 * to be at an address < 16Mb). */
 
-   int result; /* Status code from lower level driver */
-
-   unsigned char tag;  /* SCSI-II queued command tag */
-
union {
struct scsi_data_buffer sdb;
/*
@@ -121,11 +117,12 @@ struct scsi_cmnd {
 *of struct scsi_data_buffer members.
 */
struct {
+   void __deprecated *request_buffer;
unsigned __deprecated request_bufflen;
int __deprecated resid;
unsigned short __deprecated use_sg;
unsigned short __deprecated place_holder_sg_alloc;
-   void __deprecated *request_buffer;
+   int result; /* Status code from lower level driver */
};
};
 };

-- 
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."
-

Re: [patchset 0/33] scsi_data_buffer for after the last driver is converted

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 19:14:46 +0200
Boaz Harrosh <[EMAIL PROTECTED]> wrote:

> This is a resend of all the remaining drivers rebased
> to latest code. And once the entire tree is converted,
> move to scsi_data_buffer in scsi_cmnd.
> 
> The work is on top of Jens's for-linus branch which
> is effectively sglist-arch (+ last minute fixes)
> This is because sglist-arch was already rebased to
> latest scsi-misc through linus tree, merged with 
> the extra work done there on scsi-ml (and the drivers)
> (Thanks Jens)
> 
> summery of patches:
> 
> left over from scsi_eh last change
>   [PATCH 01/32] arm: fas216 Use scsi_eh API for REQUEST_SENSE invocation
> 
> lots and lots of drivers left:
>   [PATCH 02/32] isd200.c: use one-element sg list in issuing commands
>   [PATCH 03/32] usb: transport - convert to accessors and !use_sg code path 
> removal
>   [PATCH 04/32] usb: protocol.c - convert to accessors and !use_sg code path 
> removal
>   [PATCH 05/32] usb: shuttle_usbat.c - convert to accessors and !use_sg code 
> path removal
>   [PATCH 06/32] usb: freecom.c & sddr09.c - convert to accessors and !use_sg 
> cleanup
>   [PATCH 07/32] NCR5380 familly convert to accessors & !use_sg cleanup
>   [PATCH 08/32] arm: scsi convert to accessors and !use_sg cleanup
>   [PATCH 09/32] nsp_cs.c convert to data accessors and !use_sg cleanup
>   [PATCH 10/32] eata_pio.c: convert to accessors and !use_sg cleanup
>   [PATCH 11/32] a2091.c: convert to accessors and !use_sg cleanup
>   [PATCH 12/32] a3000.c: convert to accessors and !use_sg cleanup
>   [PATCH 13/32] aha1542.c: convert to accessors and !use_sg cleanup
>   [PATCH 14/32] atp870u.c: convert to accessors and !use_sg cleanup
>   [PATCH 15/32] fd_mcs.c: convert to accessors and !use_sg cleanup
>   [PATCH 16/32] imm.c: convert to accessors and !use_sg cleanup
>   [PATCH 17/32] ppa.c: convert to accessors and !use_sg cleanup
>   [PATCH 18/32] wd32c93.c: convert to accessors and !use_sg cleanup
>   [PATCH 19/32] qlogicpti.c: convert to accessors and !use_sg cleanup
>   [PATCH 20/32] in2000.c: convert to accessors and !use_sg cleanup
>   [PATCH 21/32] scsi_debug: convert to use the data buffer accessors
> 
> Tomo's patch cleaned up:
>[PATCH 22/32] qla1280: convert to use the data buffer accessors
>[PATCH 23/32] qla1280: Indentation fix
> 
>  I separated the indentation from the real change make
>  the patch humanly readable.

It doesn't hurt but I'm not sure how useful the separation is.

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 27/32] scsi_data_buffer

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 20:21:15 +0200
Boaz Harrosh <[EMAIL PROTECTED]> wrote:

> 
>   In preparation for bidi we abstract all IO members of scsi_cmnd,
>   that will need to duplicate, into a substructure.
> 
>   - Group all IO members of scsi_cmnd into a scsi_data_buffer
> structure.
>   - Adjust accessors to new members.
>   - scsi_{alloc,free}_sgtable receive a scsi_data_buffer instead of
> scsi_cmnd. And work on it.
>   - Adjust scsi_init_io() and  scsi_release_buffers() for above
> change.
>   - Fix other parts of scsi_lib/scsi.c to members migration. Use
> accessors where appropriate.
> 
>   - Old I/O members are kept for backward compatibility, since
> not all of scsi-ml/ul is converted yet. Once done they will
> be removed in a closing patch. (Other wise the patchset will
> not be bisectable)

(snip)

> @@ -114,6 +112,22 @@ struct scsi_cmnd {
>   int result; /* Status code from lower level driver */
>  
>   unsigned char tag;  /* SCSI-II queued command tag */
> +
> + union {
> + struct scsi_data_buffer sdb;
> + /*
> +  * FIXME: Here for compatibility with unconverted drivers.
> +  *Must be kept in sync with exact type and order
> +  *of struct scsi_data_buffer members.
> +  */
> + struct {
> + unsigned __deprecated request_bufflen;
> + int __deprecated resid;
> + unsigned short __deprecated use_sg;
> + unsigned short __deprecated place_holder_sg_alloc;
> + void __deprecated *request_buffer;
> + };
> + };
>  };

If we add something like this, why couldn't we merge the
scsi_data_buffer patchset when I submitted last month?

I thought that I wait you to fix all the old LLDs, then will send a
clean scsi_data_buffer patchset.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: What still uses the block layer?

2007-10-17 Thread Bill Davidsen

Jeff Garzik wrote:


But again, please remember that these USB devices are really SCSI
devices.  Same for SATA devices.  There is a reason they are using the
SCSI layer, and it isn't just because the developers felt like it :)


/somewhat/ true I'm afraid:  libata uses the SCSI layer for ATAPI 
devices because they are essentially bridges to SCSI devices.  It uses 
the SCSI layer for ATA devices because the SCSI layer provided a huge 
amount of infrastructure that would need to have been otherwise 
duplicated, /then/ massaged into coordinating between layer> and  when dealing with ATAPI.


There is also a detail that was of /huge/ value when introducing a new 
device class:  distro installers automatically work, if you use SCSI. If 
you use a new block device type, that behaves differently from other 
types and is on a different major, you have to poke the distros into 
action or do it yourself.


IOW, it was the high Just Works(tm) value of the SCSI layer when it came 
to ATA (not ATAPI) devices.


For the future, ATA will eventually be more independent (though the SCSI 
simulator will be available as an option, for compat), but the value is 
big enough to put that task on the back-burner.


I remember being told that I didn't understand the problem when I 
suggested using ide-scsi for everything and just hiding the transport. I 
get great pleasure from having been (mostly) right on that one. I still 
have old systems running ZIP drives as scsi...


--
Bill Davidsen <[EMAIL PROTECTED]>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: SCSI target drivers?

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 10:27:54 -0400
Jeff Garzik <[EMAIL PROTECTED]> wrote:

> Where can one find patches/code that illustrates target mode support?

I think that the srp class and ibmvstgt (drivers/ibmvscsi/ibmvstgt)
are useful.

The fc class and qla2xxx are useful too but more complicated than
ibmvstgt:

- fc_transport: add target driver support

http://marc.info/?l=linux-scsi&m=118857984316539&w=2

- qla2xxx: add target mode support

http://marc.info/?l=linux-scsi&m=118857984513557&w=2


The former patch is in mainline and the latter has been reviewed by
Qlogic.


> Marvell 6440 ("mvsas") supports target mode for both SAS and SATA, and I 
> would like to prepare the driver as best I can for target mode.

Great! It would be really nice to have SAS target support.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 20:37:58 +0900
FUJITA Tomonori <[EMAIL PROTECTED]> wrote:

> On Wed, 17 Oct 2007 13:01:42 +0200
> Jens Axboe <[EMAIL PROTECTED]> wrote:
> 
> > On Wed, Oct 17 2007, Jens Axboe wrote:
> > > On Wed, Oct 17 2007, David Miller wrote:
> > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > > > 
> > > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > > > 
> > > > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > > > 
> > > > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > > > > 
> > > > > > -   struct scatterlist *sg_end = sg + nelems;
> > > > > > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> > > > > >  ...
> > > > > > -   while (sg < sg_end &&
> > > > > > +   while (sg != sg_end &&
> > > > > 
> > > > > Auch indeed. That'd probably be better as a
> > > > > 
> > > > > do {
> > > > > ...
> > > > > } while (sg != sg_end);
> > > > 
> > > > Ok, next bug, introduced by this change:
> > > > 
> > > > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > > > Author: Jens Axboe <[EMAIL PROTECTED]>
> > > > Date:   Fri Sep 21 10:44:19 2007 +0200
> > > > 
> > > > block: convert to using sg helpers
> > > > 
> > > > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
> > > > 
> > > > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > > > 
> > > > Specifically this part:
> > > > 
> > > >  new_segment:
> > > > -   memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > > > -   sg[nsegs].page = bvec->bv_page;
> > > > -   sg[nsegs].length = nbytes;
> > > > -   sg[nsegs].offset = bvec->bv_offset;
> > > > +   sg = next_sg;
> > > > +   next_sg = sg_next(sg);
> > > >  
> > > > +   sg->page = bvec->bv_page;
> > > > +   sg->length = nbytes;
> > > > +   sg->offset = bvec->bv_offset;
> > > > 
> > > > You can't remove that memset(), it's there for a reason.  The IOMMU
> > > > layers depended upon the code zero'ing out the whole scatterlist
> > > > struct, there might be more to it than page, length and offset :-)
> > > 
> > > I realize that, and I was pretty worried about this specific change. But
> > > there's only been one piece of fallout because if it until now - well
> > > two, with the sparc64 stuff.
> > > 
> > > The problem is that you cannot zero the entire sg entry, because then
> > > you'd potentially overwrite the chain pointer.
> > > 
> > > I'd propose just adding a
> > > 
> > > sg_dma_address(sg) = 0;
> > > sg_dma_len(sg) = 0;
> > > 
> > > there for now, or provide an arch_clear_sg_entry() helper if we need
> > > more killed.
> > 
> > Actually, just clearing AFTER sg_next() would be fine, since we know
> > that is not a link entry. Duh...
> > 
> > diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
> > index 9eabac9..1014d34 100644
> > --- a/block/ll_rw_blk.c
> > +++ b/block/ll_rw_blk.c
> > @@ -1352,6 +1352,7 @@ new_segment:
> > sg = next_sg;
> > next_sg = sg_next(sg);
> >  
> > +   memset(sg, 0, sizeof(*sg));
> > sg->page = bvec->bv_page;
> > sg->length = nbytes;
> > sg->offset = bvec->bv_offset;
> > 
> > -- 
> 
> So now how about removing zero'ing out sglist in scsi-ml?

Really sorry, I must have been stoned.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 22/32] qla1280: Indentation fix

2007-10-17 Thread Matthew Wilcox
On Wed, Oct 17, 2007 at 08:10:09PM +0200, Boaz Harrosh wrote:
> 
>   - Indentation fix of last patch. Don't be fooled by diff,
> all I did was back-indent from open-bracket to close-bracket,
> and remove the brackets.

Applying 'qla1280: Indentation fix'

Adds trailing whitespace.
.dotest/patch:90: sn_pci_set_vchan(ha->pdev, 
warning: 1 line adds trailing whitespaces.

-- 
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."
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: What still uses the block layer?

2007-10-17 Thread david

On Wed, 17 Oct 2007, Gabor Gombas wrote:


On Tue, Oct 16, 2007 at 01:55:07PM -0700, [EMAIL PROTECTED] wrote:


why is this any different from the external enclosures? they have always
appeared as the type of device that connects them to the motherboard, (and
even with SCSI, there are some controllers that don't generate sdX devices)


In the past enclosures supported only one kind of connector so this
assumption was fine. But nowadays an external disk may have several
connectors (like USB, Firewire and eSata). Why should the disk's name
depend on what type of cable did I manage to grab first? It is the
_same_ disk regardless of the cable type.


the right type for the type of cable you choose to use. yes it's the same 
disk, but by choosing to hook it up in a different way you get different 
results from it (different performance, different predictability)


again, if you want to have a udev rule that then maps these different name 
onto the same name, more power to you, but why do you insist on makeing 
_everyone_ work that way (or go to significant extra effort to find the 
info in the changing directory structure of sysfs to track down the info 
that you throw away)



There is one thing however that could be improved: renaming a disk in an
udev rule should propagate the new name back to the kernel, just like
renaming an ethernet interface does. That way mapping error messages to
physical disk locations could be made much easier.


definantly.

David Lang
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Matthew Wilcox
On Wed, Oct 17, 2007 at 08:46:48PM +0200, Willy Tarreau wrote:
> Sincere thanks for your help and review. I'll apply this patch in
> 2.4.36-pre2 and in next 2.4.35.X. An ugly fix is clearly better than
> a massive change at this stage.

You're most welcome.  I have no desire to act as maintainer for sym2 in
2.4 at this point, but if you've got any other related bugs, feel free
to point me at them.

-- 
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."
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Willy Tarreau
On Wed, Oct 17, 2007 at 10:27:47AM -0600, Matthew Wilcox wrote:
> On Wed, Oct 17, 2007 at 10:53:06AM -0400, Tony Battersby wrote:
> > After looking at it carefully, this is true of pci_map_mem, but not
> > pci_unmap_mem.  pci_unmap_mem can be called from both ->detect and
> > ->release.  io_request_lock is held in ->detect but not in ->release.
> > So, your patch locks up the system on module unload.
> 
> My mistake.  I should have checked the iorl was held over ->release too.
> 
> This is a pretty ugly patch, but I think the three alternatives are
> worse:
> 
>  - Drop the iorl at the beginning of ->detect and reacquire it at exit.
>We don't know what else the iorl might be protecting.  Probably
>nothing, but I don't want to audit it.
>  - Convert sym2 back to old error handling so the midlayer doesn't
>acquire the iorl for us in ->detect.
>  - Acquire the iorl in ->release.  We might deadlock on something.
> 
> So, sure, apply this patch.

Matthew,

Sincere thanks for your help and review. I'll apply this patch in
2.4.36-pre2 and in next 2.4.35.X. An ugly fix is clearly better than
a massive change at this stage.

Natalie, if you want, you can close the bug right now, I've queued the
patch for both branches.

Best regards,
Willy

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 32/32] isd200.c - use of scsi_data_buffer

2007-10-17 Thread Boaz Harrosh

  - This driver still bags on scsi_cmnd IO members, so need changing

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/usb/storage/isd200.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index a624b4e..15e844d 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -415,14 +415,14 @@ static void isd200_set_srb(struct isd200_info *info,
sg_init_one(&info->sg, buff, bufflen);
 
srb->sc_data_direction = dir;
-   srb->request_buffer = buff ? &info->sg : NULL;
-   srb->request_bufflen = bufflen;
-   srb->use_sg = buff ? 1 : 0;
+   srb->sdb.sglist = buff ? &info->sg : NULL;
+   srb->sdb.length = bufflen;
+   srb->sdb.sg_count = buff ? 1 : 0;
 }
 
 static void isd200_srb_set_bufflen(struct scsi_cmnd *srb, unsigned bufflen)
 {
-   srb->request_bufflen = bufflen;
+   srb->sdb.length = bufflen;
 }
 
 
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 31/32] tgt: convert ibmvstgt and libsrp to use scsi_data_buffer

2007-10-17 Thread Boaz Harrosh
From: FUJITA Tomonori <[EMAIL PROTECTED]>

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
---
 drivers/scsi/ibmvscsi/ibmvstgt.c |2 +-
 drivers/scsi/libsrp.c|   27 ++-
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvstgt.c b/drivers/scsi/ibmvscsi/ibmvstgt.c
index 82bcab6..d63f11e 100644
--- a/drivers/scsi/ibmvscsi/ibmvstgt.c
+++ b/drivers/scsi/ibmvscsi/ibmvstgt.c
@@ -292,7 +292,7 @@ static int ibmvstgt_cmd_done(struct scsi_cmnd *sc,
dprintk("%p %p %x %u\n", iue, target, vio_iu(iue)->srp.cmd.cdb[0],
cmd->usg_sg);
 
-   if (sc->use_sg)
+   if (scsi_sg_count(sc))
err = srp_transfer_data(sc, &vio_iu(iue)->srp.cmd, 
ibmvstgt_rdma, 1, 1);
 
spin_lock_irqsave(&target->lock, flags);
diff --git a/drivers/scsi/libsrp.c b/drivers/scsi/libsrp.c
index 2ad0a27..8a8562a 100644
--- a/drivers/scsi/libsrp.c
+++ b/drivers/scsi/libsrp.c
@@ -192,18 +192,18 @@ static int srp_direct_data(struct scsi_cmnd *sc, struct 
srp_direct_buf *md,
 
if (dma_map) {
iue = (struct iu_entry *) sc->SCp.ptr;
-   sg = sc->request_buffer;
+   sg = scsi_sglist(sc);
 
-   dprintk("%p %u %u %d\n", iue, sc->request_bufflen,
-   md->len, sc->use_sg);
+   dprintk("%p %u %u %d\n", iue, scsi_bufflen(sc),
+   md->len, scsi_sg_count(sc));
 
-   nsg = dma_map_sg(iue->target->dev, sg, sc->use_sg,
+   nsg = dma_map_sg(iue->target->dev, sg, scsi_sg_count(sc),
 DMA_BIDIRECTIONAL);
if (!nsg) {
-   printk("fail to map %p %d\n", iue, sc->use_sg);
+   printk("fail to map %p %d\n", iue, scsi_sg_count(sc));
return 0;
}
-   len = min(sc->request_bufflen, md->len);
+   len = min(scsi_bufflen(sc), md->len);
} else
len = md->len;
 
@@ -229,10 +229,10 @@ static int srp_indirect_data(struct scsi_cmnd *sc, struct 
srp_cmd *cmd,
 
if (dma_map || ext_desc) {
iue = (struct iu_entry *) sc->SCp.ptr;
-   sg = sc->request_buffer;
+   sg = scsi_sglist(sc);
 
dprintk("%p %u %u %d %d\n",
-   iue, sc->request_bufflen, id->len,
+   iue, scsi_bufflen(sc), id->len,
cmd->data_in_desc_cnt, cmd->data_out_desc_cnt);
}
 
@@ -268,13 +268,14 @@ static int srp_indirect_data(struct scsi_cmnd *sc, struct 
srp_cmd *cmd,
 
 rdma:
if (dma_map) {
-   nsg = dma_map_sg(iue->target->dev, sg, sc->use_sg, 
DMA_BIDIRECTIONAL);
+   nsg = dma_map_sg(iue->target->dev, sg, scsi_sg_count(sc),
+DMA_BIDIRECTIONAL);
if (!nsg) {
-   eprintk("fail to map %p %d\n", iue, sc->use_sg);
+   eprintk("fail to map %p %d\n", iue, scsi_sg_count(sc));
err = -EIO;
goto free_mem;
}
-   len = min(sc->request_bufflen, id->len);
+   len = min(scsi_bufflen(sc), id->len);
} else
len = id->len;
 
@@ -425,8 +426,8 @@ int srp_cmd_queue(struct Scsi_Host *shost, struct srp_cmd 
*cmd, void *info,
 
sc->SCp.ptr = info;
memcpy(sc->cmnd, cmd->cdb, MAX_COMMAND_SIZE);
-   sc->request_bufflen = len;
-   sc->request_buffer = (void *) (unsigned long) addr;
+   sc->sdb.length = len;
+   sc->sdb.sglist = (void *) (unsigned long) addr;
sc->tag = tag;
err = scsi_tgt_queue_command(sc, itn_id, (struct scsi_lun *)&cmd->lun,
 cmd->tag);
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 30/32] tgt: convert to use scsi_data_buffer

2007-10-17 Thread Boaz Harrosh
From: FUJITA Tomonori <[EMAIL PROTECTED]>

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/scsi_tgt_if.c  |2 +-
 drivers/scsi/scsi_tgt_lib.c |   43 ---
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index 9815a1a..d2557db 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -112,7 +112,7 @@ int scsi_tgt_uspace_send_cmd(struct scsi_cmnd *cmd, u64 
itn_id,
memset(&ev, 0, sizeof(ev));
ev.p.cmd_req.host_no = shost->host_no;
ev.p.cmd_req.itn_id = itn_id;
-   ev.p.cmd_req.data_len = cmd->request_bufflen;
+   ev.p.cmd_req.data_len = scsi_bufflen(cmd);
memcpy(ev.p.cmd_req.scb, cmd->cmnd, sizeof(ev.p.cmd_req.scb));
memcpy(ev.p.cmd_req.lun, lun, sizeof(ev.p.cmd_req.lun));
ev.p.cmd_req.attribute = cmd->tag;
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
index b4b3af5..c2e776d 100644
--- a/drivers/scsi/scsi_tgt_lib.c
+++ b/drivers/scsi/scsi_tgt_lib.c
@@ -60,24 +60,6 @@ struct scsi_tgt_queuedata {
spinlock_t cmd_hash_lock;
 };
 
-/* FIXME Begin: Shim API until tgt is converted to use sdb */
-static struct scatterlist *tgt_scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t 
flags)
-{
-   if (scsi_alloc_sgtable(&cmd->sdb, cmd->use_sg, flags))
-   return NULL;
-   return cmd->sdb.sglist;
-}
-
-static void tgt_scsi_free_sgtable(struct scsi_cmnd *cmd)
-{
-   scsi_free_sgtable(&cmd->sdb);
-}
-#define scsi_alloc_sgtable tgt_scsi_alloc_sgtable
-#define scsi_free_sgtable tgt_scsi_free_sgtable
-
-/* FIXME End: Shim API until tgt is converted to use sdb */
-
-
 /*
  * Function:   scsi_host_get_command()
  *
@@ -349,8 +331,8 @@ static void scsi_tgt_cmd_done(struct scsi_cmnd *cmd)
 
scsi_tgt_uspace_send_status(cmd, tcmd->itn_id, tcmd->tag);
 
-   if (cmd->request_buffer)
-   scsi_free_sgtable(cmd);
+   if (cmd->sdb.sglist)
+   scsi_free_sgtable(&cmd->sdb);
 
queue_work(scsi_tgtd, &tcmd->work);
 }
@@ -374,24 +356,23 @@ static int scsi_tgt_transfer_response(struct scsi_cmnd 
*cmd)
 static int scsi_tgt_init_cmd(struct scsi_cmnd *cmd, gfp_t gfp_mask)
 {
struct request *rq = cmd->request;
+   struct scsi_data_buffer *sdb = &cmd->sdb;
int count;
 
-   cmd->use_sg = rq->nr_phys_segments;
-   cmd->request_buffer = scsi_alloc_sgtable(cmd, gfp_mask);
-   if (!cmd->request_buffer)
+   if (scsi_alloc_sgtable(sdb, rq->nr_phys_segments, gfp_mask))
return -ENOMEM;
 
-   cmd->request_bufflen = rq->data_len;
+   sdb->length = rq->data_len;
 
-   dprintk("cmd %p cnt %d %lu\n", cmd, cmd->use_sg, rq_data_dir(rq));
-   count = blk_rq_map_sg(rq->q, rq, cmd->request_buffer);
-   if (likely(count <= cmd->use_sg)) {
-   cmd->use_sg = count;
+   dprintk("cmd %p cnt %d %lu\n", cmd, scsi_sg_count(cmd), 
rq_data_dir(rq));
+   count = blk_rq_map_sg(rq->q, rq, sdb->sglist);
+   if (likely(count <= sdb->sg_count)) {
+   sdb->sg_count = count;
return 0;
}
 
-   eprintk("cmd %p cnt %d\n", cmd, cmd->use_sg);
-   scsi_free_sgtable(cmd);
+   eprintk("cmd %p cnt %d\n", cmd, scsi_sg_count(cmd));
+   scsi_free_sgtable(&cmd->sdb);
return -EINVAL;
 }
 
@@ -515,7 +496,7 @@ int scsi_tgt_kspace_exec(int host_no, u64 itn_id, int 
result, u64 tag,
cmd = rq->special;
 
dprintk("cmd %p scb %x result %d len %d bufflen %u %lu %x\n",
-   cmd, cmd->cmnd[0], result, len, cmd->request_bufflen,
+   cmd, cmd->cmnd[0], result, len, scsi_bufflen(cmd),
rq_data_dir(rq), cmd->cmnd[0]);
 
if (result == TASK_ABORTED) {
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 29/32] scsi_data_buffer - sd.c and sr.c

2007-10-17 Thread Boaz Harrosh

  - sd and sr would adjust IO size to align on device's block
size so code needs to change once we move to scsi_data_buff
implementation.
  - Convert code to use scsi_for_each_sg
  - Use data accessors where appropriate.
  - Remove dead code (req_data_dir() != READ && != WRITE)

 Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/sd.c |7 ++-
 drivers/scsi/sr.c |   28 +---
 2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 69f542c..c241f7e 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -448,9 +448,6 @@ static int sd_prep_fn(struct request_queue *q, struct 
request *rq)
} else if (rq_data_dir(rq) == READ) {
SCpnt->cmnd[0] = READ_6;
SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-   } else {
-   scmd_printk(KERN_ERR, SCpnt, "Unknown command %x\n", 
rq->cmd_flags);
-   goto out;
}
 
SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
@@ -510,7 +507,7 @@ static int sd_prep_fn(struct request_queue *q, struct 
request *rq)
SCpnt->cmnd[4] = (unsigned char) this_count;
SCpnt->cmnd[5] = 0;
}
-   SCpnt->request_bufflen = this_count * sdp->sector_size;
+   SCpnt->sdb.length = this_count * sdp->sector_size;
 
/*
 * We shouldn't disconnect in the middle of a sector, so with a dumb
@@ -904,7 +901,7 @@ static struct block_device_operations sd_fops = {
 static int sd_done(struct scsi_cmnd *SCpnt)
 {
int result = SCpnt->result;
-   unsigned int xfer_size = SCpnt->request_bufflen;
+   unsigned int xfer_size = scsi_bufflen(SCpnt);
unsigned int good_bytes = result ? 0 : xfer_size;
u64 start_lba = SCpnt->request->sector;
u64 bad_lba;
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index c619990..0375ad2 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -218,7 +218,7 @@ static int sr_media_change(struct cdrom_device_info *cdi, 
int slot)
 static int sr_done(struct scsi_cmnd *SCpnt)
 {
int result = SCpnt->result;
-   int this_count = SCpnt->request_bufflen;
+   int this_count = scsi_bufflen(SCpnt);
int good_bytes = (result == 0 ? this_count : 0);
int block_sectors = 0;
long error_sector;
@@ -360,23 +360,21 @@ static int sr_prep_fn(struct request_queue *q, struct 
request *rq)
} else if (rq_data_dir(rq) == READ) {
SCpnt->cmnd[0] = READ_10;
SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-   } else {
-   blk_dump_rq_flags(rq, "Unknown sr command");
-   goto out;
}
 
{
-   struct scatterlist *sg = SCpnt->request_buffer;
-   int i, size = 0;
-   for (i = 0; i < SCpnt->use_sg; i++)
-   size += sg[i].length;
+   struct scatterlist *sg;
+   int i, size = 0, sg_count = scsi_sg_count(SCpnt);
+
+   scsi_for_each_sg (SCpnt, sg, sg_count, i)
+   size += sg->length;
 
-   if (size != SCpnt->request_bufflen && SCpnt->use_sg) {
+   if (size != scsi_bufflen(SCpnt)) {
scmd_printk(KERN_ERR, SCpnt,
"mismatch count %d, bytes %d\n",
-   size, SCpnt->request_bufflen);
-   if (SCpnt->request_bufflen > size)
-   SCpnt->request_bufflen = size;
+   size, scsi_bufflen(SCpnt));
+   if (scsi_bufflen(SCpnt) > size)
+   SCpnt->sdb.length = size;
}
}
 
@@ -384,12 +382,12 @@ static int sr_prep_fn(struct request_queue *q, struct 
request *rq)
 * request doesn't start on hw block boundary, add scatter pads
 */
if (((unsigned int)rq->sector % (s_size >> 9)) ||
-   (SCpnt->request_bufflen % s_size)) {
+   (scsi_bufflen(SCpnt) % s_size)) {
scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
goto out;
}
 
-   this_count = (SCpnt->request_bufflen >> 9) / (s_size >> 9);
+   this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9);
 
 
SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
@@ -403,7 +401,7 @@ static int sr_prep_fn(struct request_queue *q, struct 
request *rq)
 
if (this_count > 0x) {
this_count = 0x;
-   SCpnt->request_bufflen = this_count * s_size;
+   SCpnt->sdb.length = this_count * s_size;
}
 
SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 28/32] scsi_data_buffer - scsi_error.c

2007-10-17 Thread Boaz Harrosh

 - Changed needed members of struct scsi_eh_save.
 - Careful considerations in scsi_eh_prep/restore_cmnd.

 Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/scsi_error.c |   28 ++--
 include/scsi/scsi_eh.h|6 +-
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index d29f846..c07b2a0 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -618,29 +618,25 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct 
scsi_eh_save *ses,
ses->cmd_len = scmd->cmd_len;
memcpy(ses->cmnd, scmd->cmnd, sizeof(scmd->cmnd));
ses->data_direction = scmd->sc_data_direction;
-   ses->bufflen = scmd->request_bufflen;
-   ses->buffer = scmd->request_buffer;
-   ses->use_sg = scmd->use_sg;
-   ses->resid = scmd->resid;
+   ses->sdb = scmd->sdb;
ses->result = scmd->result;
 
+   memset(&scmd->sdb, 0, sizeof(scmd->sdb));
+
if (sense_bytes) {
-   scmd->request_bufflen = min_t(unsigned,
+   scmd->sdb.length = min_t(unsigned,
   sizeof(scmd->sense_buffer), sense_bytes);
sg_init_one(&ses->sense_sgl, scmd->sense_buffer,
-  scmd->request_bufflen);
-   scmd->request_buffer = &ses->sense_sgl;
+  scmd->sdb.length);
+   scmd->sdb.sglist = &ses->sense_sgl;
scmd->sc_data_direction = DMA_FROM_DEVICE;
-   scmd->use_sg = 1;
+   scmd->sdb.sg_count = 1;
memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
scmd->cmnd[0] = REQUEST_SENSE;
-   scmd->cmnd[4] = scmd->request_bufflen;
+   scmd->cmnd[4] = scmd->sdb.length;
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
} else {
-   scmd->request_buffer = NULL;
-   scmd->request_bufflen = 0;
scmd->sc_data_direction = DMA_NONE;
-   scmd->use_sg = 0;
if (cmnd) {
memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
memcpy(scmd->cmnd, cmnd, cmnd_size);
@@ -677,10 +673,7 @@ void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct 
scsi_eh_save *ses)
scmd->cmd_len = ses->cmd_len;
memcpy(scmd->cmnd, ses->cmnd, sizeof(scmd->cmnd));
scmd->sc_data_direction = ses->data_direction;
-   scmd->request_bufflen = ses->bufflen;
-   scmd->request_buffer = ses->buffer;
-   scmd->use_sg = ses->use_sg;
-   scmd->resid = ses->resid;
+   scmd->sdb = ses->sdb;
scmd->result = ses->result;
 }
 EXPORT_SYMBOL(scsi_eh_restore_cmnd);
@@ -1700,8 +1693,7 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd));
 
scmd->scsi_done = scsi_reset_provider_done_command;
-   scmd->request_buffer= NULL;
-   scmd->request_bufflen   = 0;
+   memset(&scmd->sdb, 0, sizeof(scmd->sdb));
 
scmd->cmd_len   = 0;
 
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index 44224ba..17b4b19 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -71,11 +71,7 @@ struct scsi_eh_save {
unsigned char cmd_len;
unsigned char cmnd[MAX_COMMAND_SIZE];
 
-   void *buffer;
-   unsigned bufflen;
-   unsigned short use_sg;
-   int resid;
-
+   struct scsi_data_buffer sdb;
struct scatterlist sense_sgl;
 };
 
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 27/32] scsi_data_buffer

2007-10-17 Thread Boaz Harrosh

  In preparation for bidi we abstract all IO members of scsi_cmnd,
  that will need to duplicate, into a substructure.

  - Group all IO members of scsi_cmnd into a scsi_data_buffer
structure.
  - Adjust accessors to new members.
  - scsi_{alloc,free}_sgtable receive a scsi_data_buffer instead of
scsi_cmnd. And work on it.
  - Adjust scsi_init_io() and  scsi_release_buffers() for above
change.
  - Fix other parts of scsi_lib/scsi.c to members migration. Use
accessors where appropriate.

  - Old I/O members are kept for backward compatibility, since
not all of scsi-ml/ul is converted yet. Once done they will
be removed in a closing patch. (Other wise the patchset will
not be bisectable)

  - fix Documentation about scsi_cmnd in scsi_host.h
  - Small API shim in scsi_tgt_lib (to be removed in
tgt patch)

 Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
 Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
---
 drivers/scsi/scsi.c |2 +-
 drivers/scsi/scsi_lib.c |   80 ---
 drivers/scsi/scsi_tgt_lib.c |   18 ++
 include/scsi/scsi_cmnd.h|   57 ++
 include/scsi/scsi_host.h|4 +-
 5 files changed, 92 insertions(+), 69 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 1929488..73d2216 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -698,7 +698,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
"Notifying upper driver of completion "
"(result %x)\n", cmd->result));
 
-   good_bytes = cmd->request_bufflen;
+   good_bytes = scsi_bufflen(cmd);
 if (cmd->request->cmd_type != REQ_TYPE_BLOCK_PC) {
drv = scsi_cmd_to_driver(cmd);
if (drv->done)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index aac8a02..ce59cfe 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -438,7 +438,7 @@ EXPORT_SYMBOL_GPL(scsi_execute_async);
 static void scsi_init_cmd_errh(struct scsi_cmnd *cmd)
 {
cmd->serial_number = 0;
-   cmd->resid = 0;
+   scsi_set_resid(cmd, 0);
memset(cmd->sense_buffer, 0, sizeof cmd->sense_buffer);
if (cmd->cmd_len == 0)
cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]);
@@ -737,16 +737,15 @@ static inline unsigned int scsi_sgtable_index(unsigned 
short nents)
return index;
 }
 
-struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
+int scsi_alloc_sgtable(struct scsi_data_buffer * sdb, unsigned short sg_count,
+   gfp_t gfp_mask)
 {
struct scsi_host_sg_pool *sgp;
struct scatterlist *sgl, *prev, *ret;
unsigned int index;
int this, left;
 
-   BUG_ON(!cmd->use_sg);
-
-   left = cmd->use_sg;
+   left = sg_count;
ret = prev = NULL;
do {
this = left;
@@ -793,8 +792,9 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd 
*cmd, gfp_t gfp_mask)
 * ->use_sg may get modified after dma mapping has potentially
 * shrunk the number of segments, so keep a copy of it for free.
 */
-   cmd->__use_sg = cmd->use_sg;
-   return ret;
+   sdb->alloc_sg_count = sdb->sg_count = sg_count;
+   sdb->sglist = ret;
+   return 0;
 enomem:
if (ret) {
/*
@@ -813,26 +813,25 @@ enomem:
 
mempool_free(prev, sgp->pool);
}
-   return NULL;
+   return -1;
 }
-
 EXPORT_SYMBOL(scsi_alloc_sgtable);
 
-void scsi_free_sgtable(struct scsi_cmnd *cmd)
+void scsi_free_sgtable(struct scsi_data_buffer *sdb)
 {
-   struct scatterlist *sgl = cmd->request_buffer;
+   struct scatterlist *sgl = sdb->sglist;
struct scsi_host_sg_pool *sgp;
 
/*
 * if this is the biggest size sglist, check if we have
 * chained parts we need to free
 */
-   if (cmd->__use_sg > SCSI_MAX_SG_SEGMENTS) {
+   if (sdb->alloc_sg_count > SCSI_MAX_SG_SEGMENTS) {
unsigned short this, left;
struct scatterlist *next;
unsigned int index;
 
-   left = cmd->__use_sg - (SCSI_MAX_SG_SEGMENTS - 1);
+   left = sdb->alloc_sg_count - (SCSI_MAX_SG_SEGMENTS - 1);
next = sg_chain_ptr(&sgl[SCSI_MAX_SG_SEGMENTS - 1]);
while (left && next) {
sgl = next;
@@ -856,14 +855,13 @@ void scsi_free_sgtable(struct scsi_cmnd *cmd)
/*
 * Restore original, will be freed below
 */
-   sgl = cmd->request_buffer;
+   sgl = sdb->sglist;
sgp = scsi_sg_pools + SG_MEMPOOL_NR - 1;
} else
-   sgp = scsi_sg_pools + scsi_sgtable_index(cmd->__use_sg);
+   sgp = scsi_sg_pools + scsi_sgtable_index(sdb->sg_count);
 
mempool_free(sgl, sgp->pool);
 }
-
 EXP

[PATCH 26/32] Remove of seagate.c driver

2007-10-17 Thread Boaz Harrosh

  - Apparently no one wonts this driver, and no one
is willing to fix it for future changes to SCSI.
So remove it, and if someone wants it in the future
He can revive it with the needed fixes.

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/Kconfig   |   15 -
 drivers/scsi/Makefile  |2 -
 drivers/scsi/seagate.c | 1667 
 3 files changed, 0 insertions(+), 1684 deletions(-)
 delete mode 100644 drivers/scsi/seagate.c

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 0480f6b..4afb65b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1348,21 +1348,6 @@ config SCSI_LPFC
   This lpfc driver supports the Emulex LightPulse
   Family of Fibre Channel PCI host adapters.
 
-config SCSI_SEAGATE
-   tristate "Seagate ST-02 and Future Domain TMC-8xx SCSI support"
-   depends on X86 && ISA && SCSI
-   select CHECK_SIGNATURE
-   ---help---
- These are 8-bit SCSI controllers; the ST-01 is also supported by
- this driver.  It is explained in section 3.9 of the SCSI-HOWTO,
- available from .  If it
- doesn't work out of the box, you may have to change some macros at
- compiletime, which are described in .
-
- To compile this driver as a module, choose M here: the
- module will be called seagate.
-
-# definitely looks not 64bit safe:
 config SCSI_SIM710
tristate "Simple 53c710 SCSI support (Compaq, NCR machines)"
depends on (EISA || MCA) && SCSI
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index ffb800d..56db32a 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -16,7 +16,6 @@
 
 CFLAGS_aha152x.o =   -DAHA152X_STAT -DAUTOCONF
 CFLAGS_gdth.o= # -DDEBUG_GDTH=2 -D__SERIAL__ -D__COM2__ -DGDTH_STATISTICS
-CFLAGS_seagate.o =   -DARBITRATE -DPARITY -DSEAGATE_USE_ASM
 
 subdir-$(CONFIG_PCMCIA)+= pcmcia
 
@@ -89,7 +88,6 @@ obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx/
 obj-$(CONFIG_SCSI_QLA_ISCSI)   += qla4xxx/
 obj-$(CONFIG_SCSI_LPFC)+= lpfc/
 obj-$(CONFIG_SCSI_PAS16)   += pas16.o
-obj-$(CONFIG_SCSI_SEAGATE) += seagate.o
 obj-$(CONFIG_SCSI_T128)+= t128.o
 obj-$(CONFIG_SCSI_DMX3191D)+= dmx3191d.o
 obj-$(CONFIG_SCSI_DTC3280) += dtc.o
diff --git a/drivers/scsi/seagate.c b/drivers/scsi/seagate.c
deleted file mode 100644
index ce80fa9..000
--- a/drivers/scsi/seagate.c
+++ /dev/null
@@ -1,1667 +0,0 @@
-/*
- *seagate.c Copyright (C) 1992, 1993 Drew Eckhardt
- *  low level scsi driver for ST01/ST02, Future Domain TMC-885,
- *  TMC-950 by Drew Eckhardt <[EMAIL PROTECTED]>
- *
- *  Note : TMC-880 boards don't work because they have two bits in
- *  the status register flipped, I'll fix this "RSN"
- * [why do I have strong feeling that above message is from 1993? :-)
- * [EMAIL PROTECTED]
- *
- *  This card does all the I/O via memory mapped I/O, so there is no need
- *  to check or allocate a region of the I/O address space.
- */
-
-/* 1996 - to use new read{b,w,l}, write{b,w,l}, and phys_to_virt
- * macros, replaced assembler routines with C. There's probably a
- * performance hit, but I only have a cdrom and can't tell. Define
- * SEAGATE_USE_ASM if you want the old assembler code -- SJT
- *
- * 1998-jul-29 - created DPRINTK macros and made it work under 
- * linux 2.1.112, simplified some #defines etc. <[EMAIL PROTECTED]>
- *
- * Aug 2000 - aeb - deleted seagate_st0x_biosparam(). It would try to
- * read the physical disk geometry, a bad mistake. Of course it doesn't
- * matter much what geometry one invents, but on large disks it
- * returned 256 (or more) heads, causing all kind of failures.
- * Of course this means that people might see a different geometry now,
- * so boot parameters may be necessary in some cases.
- */
-
-/*
- * Configuration :
- * To use without BIOS -DOVERRIDE=base_address -DCONTROLLER=FD or SEAGATE
- * -DIRQ will override the default of 5.
- * Note: You can now set these options from the kernel's "command line".
- * The syntax is:
- *
- * st0x=ADDRESS,IRQ(for a Seagate controller)
- * or:
- * tmc8xx=ADDRESS,IRQ  (for a TMC-8xx or TMC-950 controller)
- * eg:
- * tmc8xx=0xC8000,15
- *
- * will configure the driver for a TMC-8xx style controller using IRQ 15
- * with a base address of 0xC8000.
- *
- * -DARBITRATE 
- *  Will cause the host adapter to arbitrate for the
- *  bus for better SCSI-II compatibility, rather than just
- *  waiting for BUS FREE and then doing its thing.  Should
- *  let us do one command per Lun when I integrate my
- *  reorganization changes into the distribution sources.
- *
- * -DDEBUG=65535
- *  Will activate debug code.
- *
- * -DFAST or -DFAST32 
- *  Will use blind transfers where possible
- *
- * -DPARITY  
- *  This will e

[PATCH 25/32] Remove psi240i driver from kernel

2007-10-17 Thread Boaz Harrosh

  The psi240i driver is still written for cmnd->request_buffer
  as a char pointer to actual data. There was never any attempt
  to use the scatterlist option.

  - remove all source files (3) from drivers/scsi
  - Remove from Makefile and Kconfig

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/Kconfig|   11 -
 drivers/scsi/Makefile   |1 -
 drivers/scsi/psi240i.c  |  689 ---
 drivers/scsi/psi240i.h  |  315 -
 drivers/scsi/psi_chip.h |  195 -
 5 files changed, 0 insertions(+), 1211 deletions(-)
 delete mode 100644 drivers/scsi/psi240i.c
 delete mode 100644 drivers/scsi/psi240i.h
 delete mode 100644 drivers/scsi/psi_chip.h

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 30905ce..0480f6b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1288,17 +1288,6 @@ config SCSI_PAS16
  To compile this driver as a module, choose M here: the
  module will be called pas16.
 
-config SCSI_PSI240I
-   tristate "PSI240i support"
-   depends on ISA && SCSI
-   help
- This is support for the PSI240i EIDE interface card which acts as a
- SCSI host adapter.  Please read the SCSI-HOWTO, available from
- .
-
- To compile this driver as a module, choose M here: the
- module will be called psi240i.
-
 config SCSI_QLOGIC_FAS
tristate "Qlogic FAS SCSI support"
depends on ISA && SCSI
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 6141389..ffb800d 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -59,7 +59,6 @@ obj-$(CONFIG_MVME16x_SCSI)+= 53c700.o mvme16x_scsi.o
 obj-$(CONFIG_BVME6000_SCSI)+= 53c700.o bvme6000_scsi.o
 obj-$(CONFIG_SCSI_SIM710)  += 53c700.o sim710.o
 obj-$(CONFIG_SCSI_ADVANSYS)+= advansys.o
-obj-$(CONFIG_SCSI_PSI240I) += psi240i.o
 obj-$(CONFIG_SCSI_BUSLOGIC)+= BusLogic.o
 obj-$(CONFIG_SCSI_DPT_I2O) += dpt_i2o.o
 obj-$(CONFIG_SCSI_U14_34F) += u14-34f.o
diff --git a/drivers/scsi/psi240i.c b/drivers/scsi/psi240i.c
deleted file mode 100644
index 899e89d..000
--- a/drivers/scsi/psi240i.c
+++ /dev/null
@@ -1,689 +0,0 @@
-/*+M*
- * Perceptive Solutions, Inc. PSI-240I device driver proc support for Linux.
- *
- * Copyright (c) 1997 Perceptive Solutions, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING.  If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- * File Name:  psi240i.c
- *
- * Description:SCSI driver for the PSI240I EIDE interface card.
- *
- *-M*/
-
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include "scsi.h"
-#include 
-
-#include "psi240i.h"
-#include "psi_chip.h"
-
-//#define DEBUG 1
-
-#ifdef DEBUG
-#define DEB(x) x
-#else
-#define DEB(x)
-#endif
-
-#define MAXBOARDS 6/* Increase this and the sizes of the arrays below, if 
you need more. */
-
-#definePORT_DATA   0
-#definePORT_ERROR  1
-#definePORT_SECTOR_COUNT   2
-#definePORT_LBA_0  3
-#definePORT_LBA_8  4
-#definePORT_LBA_16 5
-#definePORT_LBA_24 6
-#definePORT_STAT_CMD   7
-#definePORT_SEL_FAIL   8
-#definePORT_IRQ_STATUS 9
-#definePORT_ADDRESS10
-#definePORT_FAIL   11
-#definePORT_ALT_STAT   12
-
-typedef struct
-   {
-   UCHAR   device; // device code
-   UCHAR   byte6;  // device 
select register image
-   UCHAR   spigot; // spigot number
-   UCHAR   expectingIRQ;   // flag for expecting 
and interrupt
-   USHORT  sectors;// number of 

[PATCH 24/32] wd7000.c - proper fix for boards without sg support

2007-10-17 Thread Boaz Harrosh

  - code used to set sg_tablesize to zero for board revision
less than 6. This is no longer supported, therefore I
use sg_tablesize=1 and open code the sg handling for that case.
  - Get rid of use of SG_NONE which will be removed soon.

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/wd7000.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/wd7000.c b/drivers/scsi/wd7000.c
index 255c611..3887640 100644
--- a/drivers/scsi/wd7000.c
+++ b/drivers/scsi/wd7000.c
@@ -1108,13 +1108,10 @@ static int wd7000_queuecommand(struct scsi_cmnd *SCpnt,
scb->host = host;
 
nseg = scsi_sg_count(SCpnt);
-   if (nseg) {
+   if (nseg > 1) {
struct scatterlist *sg;
unsigned i;
 
-   if (SCpnt->device->host->sg_tablesize == SG_NONE) {
-   panic("wd7000_queuecommand: scatter/gather not 
supported.\n");
-   }
dprintk("Using scatter/gather with %d elements.\n", nseg);
 
sgb = scb->sgb;
@@ -1128,7 +1125,10 @@ static int wd7000_queuecommand(struct scsi_cmnd *SCpnt,
}
} else {
scb->op = 0;
-   any2scsi(scb->dataptr, isa_virt_to_bus(scsi_sglist(SCpnt)));
+   if (nseg) {
+   struct scatterlist *sg = scsi_sglist(SCpnt);
+   any2scsi(scb->dataptr, isa_page_to_bus(sg->page) + 
sg->offset);
+   }
any2scsi(scb->maxlen, scsi_bufflen(SCpnt));
}
 
@@ -1524,7 +1524,7 @@ static __init int wd7000_detect(struct scsi_host_template 
*tpnt)
 *  For boards before rev 6.0, scatter/gather 
isn't supported.
 */
if (host->rev1 < 6)
-   sh->sg_tablesize = SG_NONE;
+   sh->sg_tablesize = 1;
 
present++;  /* count it */
 
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 23/32] scsi_debug: convert to use the data buffer accessors

2007-10-17 Thread Boaz Harrosh

  - remove the unnecessary map_single path.
  - convert to use the new accessors for the sg lists and the
parameters.

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
Signed-off-by: Douglas Gilbert <[EMAIL PROTECTED]>
---
 drivers/scsi/scsi_debug.c |   36 ++--
 1 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 72ee4c9..c08ebf4 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -329,7 +329,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, 
done_funct_t done)
if (done == NULL)
return 0;   /* assume mid level reprocessing command */
 
-   SCpnt->resid = 0;
+   scsi_set_resid(SCpnt, 0);
if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) {
printk(KERN_INFO "scsi_debug: cmd ");
for (k = 0, len = SCpnt->cmd_len; k < len; ++k)
@@ -603,26 +603,16 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, 
unsigned char * arr,
void * kaddr_off;
struct scatterlist * sg;
 
-   if (0 == scp->request_bufflen)
+   if (0 == scsi_bufflen(scp))
return 0;
-   if (NULL == scp->request_buffer)
+   if (NULL == scsi_sglist(scp))
return (DID_ERROR << 16);
if (! ((scp->sc_data_direction == DMA_BIDIRECTIONAL) ||
  (scp->sc_data_direction == DMA_FROM_DEVICE)))
return (DID_ERROR << 16);
-   if (0 == scp->use_sg) {
-   req_len = scp->request_bufflen;
-   act_len = (req_len < arr_len) ? req_len : arr_len;
-   memcpy(scp->request_buffer, arr, act_len);
-   if (scp->resid)
-   scp->resid -= act_len;
-   else
-   scp->resid = req_len - act_len;
-   return 0;
-   }
active = 1;
req_len = act_len = 0;
-   scsi_for_each_sg(scp, sg, scp->use_sg, k) {
+   scsi_for_each_sg(scp, sg, scsi_sg_count(scp), k) {
if (active) {
kaddr = (unsigned char *)
kmap_atomic(sg->page, KM_USER0);
@@ -640,10 +630,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, 
unsigned char * arr,
}
req_len += sg->length;
}
-   if (scp->resid)
-   scp->resid -= act_len;
+   if (scsi_get_resid(scp))
+   scsi_set_resid(scp, scsi_get_resid(scp) - act_len);
else
-   scp->resid = req_len - act_len;
+   scsi_set_resid(scp, req_len - act_len);
return 0;
 }
 
@@ -656,22 +646,16 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, 
unsigned char * arr,
void * kaddr_off;
struct scatterlist * sg;
 
-   if (0 == scp->request_bufflen)
+   if (0 == scsi_bufflen(scp))
return 0;
-   if (NULL == scp->request_buffer)
+   if (NULL == scsi_sglist(scp))
return -1;
if (! ((scp->sc_data_direction == DMA_BIDIRECTIONAL) ||
  (scp->sc_data_direction == DMA_TO_DEVICE)))
return -1;
-   if (0 == scp->use_sg) {
-   req_len = scp->request_bufflen;
-   len = (req_len < max_arr_len) ? req_len : max_arr_len;
-   memcpy(arr, scp->request_buffer, len);
-   return len;
-   }
sg = scsi_sglist(scp);
req_len = fin = 0;
-   for (k = 0; k < scp->use_sg; ++k, sg = sg_next(sg)) {
+   for (k = 0; k < scsi_sg_count(scp); ++k, sg = sg_next(sg)) {
kaddr = (unsigned char *)kmap_atomic(sg->page, KM_USER0);
if (NULL == kaddr)
return -1;
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/32] qla1280: Indentation fix

2007-10-17 Thread Boaz Harrosh

  - Indentation fix of last patch. Don't be fooled by diff,
all I did was back-indent from open-bracket to close-bracket,
and remove the brackets.

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/qla1280.c |  290 
 1 files changed, 143 insertions(+), 147 deletions(-)

diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 7a18b1a..bf07b17 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -2882,99 +2882,97 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
/* Setup packet address segment pointer. */
dword_ptr = (u32 *)&pkt->dseg_0_address;
 
-   {   /* FIXME:Indentation in next patch */
-   /* Load command entry data segments. */
-   for_each_sg(sg, s, seg_cnt, cnt) {
-   if (cnt == 2)
+   /* Load command entry data segments. */
+   for_each_sg(sg, s, seg_cnt, cnt) {
+   if (cnt == 2)
+   break;
+   dma_handle = sg_dma_address(s);
+#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
+   if (ha->flags.use_pci_vchannel)
+   sn_pci_set_vchan(ha->pdev,
+   (unsigned long *)&dma_handle,
+SCSI_BUS_32(cmd));
+#endif
+   *dword_ptr++ =
+   cpu_to_le32(pci_dma_lo32(dma_handle));
+   *dword_ptr++ =
+   cpu_to_le32(pci_dma_hi32(dma_handle));
+   *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
+   dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
+   cpu_to_le32(pci_dma_hi32(dma_handle)),
+   cpu_to_le32(pci_dma_lo32(dma_handle)),
+   cpu_to_le32(sg_dma_len(sg_next(s;
+   remseg--;
+   }
+   dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
+   "command packet data - b %i, t %i, l %i \n",
+   SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
+   SCSI_LUN_32(cmd));
+   qla1280_dump_buffer(5, (char *)pkt,
+   REQUEST_ENTRY_SIZE);
+
+   /*
+* Build continuation packets.
+*/
+   dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
+   "remains\n", seg_cnt);
+
+   while (remseg > 0) {
+   /* Update sg start */
+   sg = s;
+   /* Adjust ring index. */
+   ha->req_ring_index++;
+   if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
+   ha->req_ring_index = 0;
+   ha->request_ring_ptr =
+   ha->request_ring;
+   } else
+   ha->request_ring_ptr++;
+
+   pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
+
+   /* Zero out packet. */
+   memset(pkt, 0, REQUEST_ENTRY_SIZE);
+
+   /* Load packet defaults. */
+   ((struct cont_a64_entry *) pkt)->entry_type =
+   CONTINUE_A64_TYPE;
+   ((struct cont_a64_entry *) pkt)->entry_count = 1;
+   ((struct cont_a64_entry *) pkt)->sys_define =
+   (uint8_t)ha->req_ring_index;
+   /* Setup packet address segment pointer. */
+   dword_ptr =
+   (u32 *)&((struct cont_a64_entry *) 
pkt)->dseg_0_address;
+
+   /* Load continuation entry data segments. */
+   for_each_sg(sg, s, remseg, cnt) {
+   if (cnt == 5)
break;
dma_handle = sg_dma_address(s);
 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
-   if (ha->flags.use_pci_vchannel)
-   sn_pci_set_vchan(ha->pdev,
-   (unsigned long 
*)&dma_handle,
-SCSI_BUS_32(cmd));
+   if (ha->flags.use_pci_vchannel)
+   sn_pci_set_vchan(ha->pdev, 
+   (unsigned long *)&dma_handle,
+SCSI_BUS_32(cmd));
 #endif
*dword_ptr++ =
   

[PATCH 21/32] qla1280: convert to use the data buffer accessors

2007-10-17 Thread Boaz Harrosh
From: FUJITA Tomonori <[EMAIL PROTECTED]>

  - remove the unnecessary map_single path.
  - convert to use the new accessors for the sg lists and the parameters.
  - NOTE: Indentation fix is in next patch. Otherwise this patch
becomes totally impossible to read (and easily breakable)

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/qla1280.c |  101 +---
 1 files changed, 19 insertions(+), 82 deletions(-)

diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 76089cf..7a18b1a 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1310,14 +1310,7 @@ qla1280_done(struct scsi_qla_host *ha)
}
 
/* Release memory used for this I/O */
-   if (cmd->use_sg) {
-   pci_unmap_sg(ha->pdev, cmd->request_buffer,
-   cmd->use_sg, cmd->sc_data_direction);
-   } else if (cmd->request_bufflen) {
-   pci_unmap_single(ha->pdev, sp->saved_dma_handle,
-   cmd->request_bufflen,
-   cmd->sc_data_direction);
-   }
+   scsi_dma_unmap(cmd);
 
/* Call the mid-level driver interrupt handler */
CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
@@ -1406,14 +1399,14 @@ qla1280_return_status(struct response * sts, struct 
scsi_cmnd *cp)
break;
 
case CS_DATA_UNDERRUN:
-   if ((cp->request_bufflen - residual_length) <
+   if ((scsi_bufflen(cp) - residual_length) <
cp->underflow) {
printk(KERN_WARNING
   "scsi: Underflow detected - retrying "
   "command.\n");
host_status = DID_ERROR;
} else {
-   cp->resid = residual_length;
+   scsi_set_resid(cp, residual_length);
host_status = DID_OK;
}
break;
@@ -2781,27 +2774,23 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
int status = 0;
int cnt;
int req_cnt;
-   u16 seg_cnt;
+   int seg_cnt;
u8 dir;
 
ENTER("qla1280_64bit_start_scsi:");
 
/* Calculate number of entries and segments required. */
req_cnt = 1;
-   if (cmd->use_sg) {
-   sg = (struct scatterlist *) cmd->request_buffer;
-   seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
-cmd->sc_data_direction);
-
+   seg_cnt = scsi_dma_map(cmd);
+   if (seg_cnt > 0) {
if (seg_cnt > 2) {
req_cnt += (seg_cnt - 2) / 5;
if ((seg_cnt - 2) % 5)
req_cnt++;
}
-   } else if (cmd->request_bufflen) {  /* If data transfer. */
-   seg_cnt = 1;
-   } else {
-   seg_cnt = 0;
+   } else if (seg_cnt < 0) {
+   status = 1;
+   goto out;
}
 
if ((req_cnt + 2) >= ha->req_q_cnt) {
@@ -2893,7 +2882,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct 
srb * sp)
/* Setup packet address segment pointer. */
dword_ptr = (u32 *)&pkt->dseg_0_address;
 
-   if (cmd->use_sg) {  /* If scatter gather */
+   {   /* FIXME:Indentation in next patch */
/* Load command entry data segments. */
for_each_sg(sg, s, seg_cnt, cnt) {
if (cnt == 2)
@@ -2986,29 +2975,6 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
qla1280_dump_buffer(5, (char *)pkt,
REQUEST_ENTRY_SIZE);
}
-   } else {/* No scatter gather data transfer */
-   dma_handle = pci_map_single(ha->pdev,
-   cmd->request_buffer,
-   cmd->request_bufflen,
-   cmd->sc_data_direction);
-
-   sp->saved_dma_handle = dma_handle;
-#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
-   if (ha->flags.use_pci_vchannel)
-   sn_pci_set_vchan(ha->pdev, 
-   (unsigned long *)&dma_handle,
-SCSI_BUS_32(cmd));
-#endif
-   *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
-   *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
-   *dword_ptr = cpu_to_le32(cmd->request_b

[PATCH 20/32] in2000.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/in2000.c |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/in2000.c b/drivers/scsi/in2000.c
index ab7cbf3..ced38de 100644
--- a/drivers/scsi/in2000.c
+++ b/drivers/scsi/in2000.c
@@ -369,16 +369,16 @@ static int in2000_queuecommand(Scsi_Cmnd * cmd, void 
(*done) (Scsi_Cmnd *))
  *  - SCp.phase records this command's SRCID_ER bit setting
  */
 
-   if (cmd->use_sg) {
-   cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
-   cmd->SCp.buffers_residual = cmd->use_sg - 1;
+   if (scsi_bufflen(cmd)) {
+   cmd->SCp.buffer = scsi_sglist(cmd);
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.ptr = (char *) page_address(cmd->SCp.buffer->page) + 
cmd->SCp.buffer->offset;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
} else {
cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
-   cmd->SCp.ptr = (char *) cmd->request_buffer;
-   cmd->SCp.this_residual = cmd->request_bufflen;
+   cmd->SCp.ptr = NULL;
+   cmd->SCp.this_residual = 0;
}
cmd->SCp.have_data_in = 0;
 
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/32] wd33c93.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/wd33c93.c |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 0e8e642..1a772b8 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -407,17 +407,17 @@ wd33c93_queuecommand(struct scsi_cmnd *cmd,
  *  - SCp.phase records this command's SRCID_ER bit setting
  */
 
-   if (cmd->use_sg) {
-   cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
-   cmd->SCp.buffers_residual = cmd->use_sg - 1;
+   if (scsi_bufflen(cmd)) {
+   cmd->SCp.buffer = scsi_sglist(cmd);
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
} else {
cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
-   cmd->SCp.ptr = (char *) cmd->request_buffer;
-   cmd->SCp.this_residual = cmd->request_bufflen;
+   cmd->SCp.ptr = NULL;
+   cmd->SCp.this_residual = 0;
}
 
 /* WD docs state that at the conclusion of a "LEVEL2" command, the
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 19/32] qlogicpti.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/qlogicpti.c |   29 +++--
 1 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index 7a2e798..5bc8831 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -871,11 +871,12 @@ static inline int load_cmd(struct scsi_cmnd *Cmnd, struct 
Command_Entry *cmd,
struct scatterlist *sg, *s;
int i, n;
 
-   if (Cmnd->use_sg) {
+   if (scsi_bufflen(Cmnd)) {
int sg_count;
 
-   sg = (struct scatterlist *) Cmnd->request_buffer;
-   sg_count = sbus_map_sg(qpti->sdev, sg, Cmnd->use_sg, 
Cmnd->sc_data_direction);
+   sg = scsi_sglist(Cmnd);
+   sg_count = sbus_map_sg(qpti->sdev, sg, scsi_sg_count(Cmnd),
+ Cmnd->sc_data_direction);
 
ds = cmd->dataseg;
cmd->segment_cnt = sg_count;
@@ -914,16 +915,6 @@ static inline int load_cmd(struct scsi_cmnd *Cmnd, struct 
Command_Entry *cmd,
}
sg_count -= n;
}
-   } else if (Cmnd->request_bufflen) {
-   Cmnd->SCp.ptr = (char *)(unsigned long)
-   sbus_map_single(qpti->sdev,
-   Cmnd->request_buffer,
-   Cmnd->request_bufflen,
-   Cmnd->sc_data_direction);
-
-   cmd->dataseg[0].d_base = (u32) ((unsigned long)Cmnd->SCp.ptr);
-   cmd->dataseg[0].d_count = Cmnd->request_bufflen;
-   cmd->segment_cnt = 1;
} else {
cmd->dataseg[0].d_base = 0;
cmd->dataseg[0].d_count = 0;
@@ -1159,17 +1150,11 @@ static struct scsi_cmnd *qlogicpti_intr_handler(struct 
qlogicpti *qpti)
else
Cmnd->result = DID_ERROR << 16;
 
-   if (Cmnd->use_sg) {
+   if (scsi_bufflen(Cmnd))
sbus_unmap_sg(qpti->sdev,
- (struct scatterlist 
*)Cmnd->request_buffer,
- Cmnd->use_sg,
+ scsi_sglist(Cmnd), scsi_sg_count(Cmnd),
  Cmnd->sc_data_direction);
-   } else if (Cmnd->request_bufflen) {
-   sbus_unmap_single(qpti->sdev,
- (__u32)((unsigned long)Cmnd->SCp.ptr),
- Cmnd->request_bufflen,
- Cmnd->sc_data_direction);
-   }
+
qpti->cmd_count[Cmnd->device->id]--;
sbus_writew(out_ptr, qpti->qregs + MBOX5);
Cmnd->host_scribble = (unsigned char *) done_queue;
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 17/32] ppa.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh
[PATCH 17/32] ppa.c: convert to accessors and !use_sg cleanup

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/ppa.c |   12 +---
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/ppa.c b/drivers/scsi/ppa.c
index 67b6d76..f9fdc8a 100644
--- a/drivers/scsi/ppa.c
+++ b/drivers/scsi/ppa.c
@@ -752,19 +752,17 @@ static int ppa_engine(ppa_struct *dev, struct scsi_cmnd 
*cmd)
cmd->SCp.phase++;
 
case 4: /* Phase 4 - Setup scatter/gather buffers */
-   if (cmd->use_sg) {
-   /* if many buffers are available, start filling the 
first */
-   cmd->SCp.buffer = (struct scatterlist *) 
cmd->request_buffer;
+   if (scsi_bufflen(cmd)) {
+   cmd->SCp.buffer = scsi_sglist(cmd);
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
} else {
-   /* else fill the only available buffer */
cmd->SCp.buffer = NULL;
-   cmd->SCp.this_residual = cmd->request_bufflen;
-   cmd->SCp.ptr = cmd->request_buffer;
+   cmd->SCp.this_residual = 0;
+   cmd->SCp.ptr = NULL;
}
-   cmd->SCp.buffers_residual = cmd->use_sg - 1;
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.phase++;
 
case 5: /* Phase 5 - Data transfer stage */
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/32] imm.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup
 - Not ready for sg-chaining

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/imm.c |   13 +
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/imm.c b/drivers/scsi/imm.c
index 74cdc1f..84bcc1d 100644
--- a/drivers/scsi/imm.c
+++ b/drivers/scsi/imm.c
@@ -839,21 +839,18 @@ static int imm_engine(imm_struct *dev, struct scsi_cmnd 
*cmd)
 
/* Phase 4 - Setup scatter/gather buffers */
case 4:
-   if (cmd->use_sg) {
-   /* if many buffers are available, start filling the 
first */
-   cmd->SCp.buffer =
-   (struct scatterlist *) cmd->request_buffer;
+   if (scsi_bufflen(cmd)) {
+   cmd->SCp.buffer = scsi_sglist(cmd);
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr =
page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
} else {
-   /* else fill the only available buffer */
cmd->SCp.buffer = NULL;
-   cmd->SCp.this_residual = cmd->request_bufflen;
-   cmd->SCp.ptr = cmd->request_buffer;
+   cmd->SCp.this_residual = 0;
+   cmd->SCp.ptr = NULL;
}
-   cmd->SCp.buffers_residual = cmd->use_sg - 1;
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.phase++;
if (cmd->SCp.this_residual & 0x01)
cmd->SCp.this_residual++;
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/32] fd_mcs.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup
 - Not ready for sg-chaining

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/fd_mcs.c |   36 +++-
 1 files changed, 11 insertions(+), 25 deletions(-)

diff --git a/drivers/scsi/fd_mcs.c b/drivers/scsi/fd_mcs.c
index 668569e..3a5df96 100644
--- a/drivers/scsi/fd_mcs.c
+++ b/drivers/scsi/fd_mcs.c
@@ -1017,24 +1017,6 @@ static irqreturn_t fd_mcs_intr(int irq, void *dev_id)
printk(" ** IN DONE %d ** ", current_SC->SCp.have_data_in);
 #endif
 
-#if ERRORS_ONLY
-   if (current_SC->cmnd[0] == REQUEST_SENSE && 
!current_SC->SCp.Status) {
-   if ((unsigned char) (*((char *) 
current_SC->request_buffer + 2)) & 0x0f) {
-   unsigned char key;
-   unsigned char code;
-   unsigned char qualifier;
-
-   key = (unsigned char) (*((char *) 
current_SC->request_buffer + 2)) & 0x0f;
-   code = (unsigned char) (*((char *) 
current_SC->request_buffer + 12));
-   qualifier = (unsigned char) (*((char *) 
current_SC->request_buffer + 13));
-
-   if (key != UNIT_ATTENTION && !(key == NOT_READY 
&& code == 0x04 && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
-   && !(key == ILLEGAL_REQUEST && (code == 
0x25 || code == 0x24 || !code)))
-
-   printk("fd_mcs: REQUEST SENSE " "Key = 
%x, Code = %x, Qualifier = %x\n", key, code, qualifier);
-   }
-   }
-#endif
 #if EVERY_ACCESS
printk("BEFORE MY_DONE. . .");
 #endif
@@ -1097,7 +1079,9 @@ static int fd_mcs_queue(Scsi_Cmnd * SCpnt, void (*done) 
(Scsi_Cmnd *))
panic("fd_mcs: fd_mcs_queue() NOT REENTRANT!\n");
}
 #if EVERY_ACCESS
-   printk("queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n", 
SCpnt->target, *(unsigned char *) SCpnt->cmnd, SCpnt->use_sg, 
SCpnt->request_bufflen);
+   printk("queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
+   SCpnt->target, *(unsigned char *) SCpnt->cmnd,
+   scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
 #endif
 
fd_mcs_make_bus_idle(shpnt);
@@ -1107,14 +1091,14 @@ static int fd_mcs_queue(Scsi_Cmnd * SCpnt, void (*done) 
(Scsi_Cmnd *))
 
/* Initialize static data */
 
-   if (current_SC->use_sg) {
-   current_SC->SCp.buffer = (struct scatterlist *) 
current_SC->request_buffer;
+   if (scsi_bufflen(current_SC)) {
+   current_SC->SCp.buffer = scsi_sglist(current_SC);
current_SC->SCp.ptr = 
page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset;
current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
-   current_SC->SCp.buffers_residual = current_SC->use_sg - 1;
+   current_SC->SCp.buffers_residual = scsi_sg_count(current_SC) - 
1;
} else {
-   current_SC->SCp.ptr = (char *) current_SC->request_buffer;
-   current_SC->SCp.this_residual = current_SC->request_bufflen;
+   current_SC->SCp.ptr = NULL;
+   current_SC->SCp.this_residual = 0;
current_SC->SCp.buffer = NULL;
current_SC->SCp.buffers_residual = 0;
}
@@ -1166,7 +1150,9 @@ static void fd_mcs_print_info(Scsi_Cmnd * SCpnt)
break;
}
 
-   printk("(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n", 
SCpnt->SCp.phase, SCpnt->device->id, *(unsigned char *) SCpnt->cmnd, 
SCpnt->use_sg, SCpnt->request_bufflen);
+   printk("(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
+   SCpnt->SCp.phase, SCpnt->device->id, *(unsigned char *) 
SCpnt->cmnd,
+   scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
printk("sent_command = %d, have_data_in = %d, timeout = %d\n", 
SCpnt->SCp.sent_command, SCpnt->SCp.have_data_in, SCpnt->timeout);
 #if DEBUG_RACE
printk("in_interrupt_flag = %d\n", in_interrupt_flag);
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/32] atp870u.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup
 - Probably not ready for sg-chaining

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/atp870u.c |  102 
 1 files changed, 17 insertions(+), 85 deletions(-)

diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index fec58cc..db6de5e 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -471,18 +471,8 @@ go_42:
/*
 *  Complete the command
 */
-   if (workreq->use_sg) {
-   pci_unmap_sg(dev->pdev,
-   (struct scatterlist 
*)workreq->request_buffer,
-   workreq->use_sg,
-   workreq->sc_data_direction);
-   } else if (workreq->request_bufflen &&
-   workreq->sc_data_direction != DMA_NONE) 
{
-   pci_unmap_single(dev->pdev,
-   workreq->SCp.dma_handle,
-   workreq->request_bufflen,
-   workreq->sc_data_direction);
-   }   
+   scsi_dma_unmap(workreq);
+
spin_lock_irqsave(dev->host->host_lock, flags);
(*workreq->scsi_done) (workreq);
 #ifdef ED_DBGP
@@ -624,7 +614,7 @@ static int atp870u_queuecommand(struct scsi_cmnd * req_p,
 
c = scmd_channel(req_p);
req_p->sense_buffer[0]=0;
-   req_p->resid = 0;
+   scsi_set_resid(req_p, 0);
if (scmd_channel(req_p) > 1) {
req_p->result = 0x0004;
done(req_p);
@@ -722,7 +712,6 @@ static void send_s870(struct atp_unit *dev,unsigned char c)
unsigned short int tmpcip, w;
unsigned long l, bttl = 0;
unsigned int workport;
-   struct scatterlist *sgpnt;
unsigned long  sg_count;
 
if (dev->in_snd[c] != 0) {
@@ -793,6 +782,8 @@ oktosend:
}
printk("\n");
 #endif 
+   l = scsi_bufflen(workreq);
+
if (dev->dev_id == ATP885_DEVID) {
j = inb(dev->baseport + 0x29) & 0xfe;
outb(j, dev->baseport + 0x29);
@@ -800,12 +791,11 @@ oktosend:
}

if (workreq->cmnd[0] == READ_CAPACITY) {
-   if (workreq->request_bufflen > 8) {
-   workreq->request_bufflen = 0x08;
-   }
+   if (l > 8)
+   l = 8;
}
if (workreq->cmnd[0] == 0x00) {
-   workreq->request_bufflen = 0;
+   l = 0;
}
 
tmport = workport + 0x1b;
@@ -852,40 +842,8 @@ oktosend:
 #ifdef ED_DBGP 
printk("dev->id[%d][%d].devsp = 
%2x\n",c,target_id,dev->id[c][target_id].devsp);
 #endif
-   /*
-*  Figure out the transfer size
-*/
-   if (workreq->use_sg) {
-#ifdef ED_DBGP
-   printk("Using SGL\n");
-#endif 
-   l = 0;
-   
-   sgpnt = (struct scatterlist *) workreq->request_buffer;
-   sg_count = pci_map_sg(dev->pdev, sgpnt, workreq->use_sg,
-   workreq->sc_data_direction);
-   
-   for (i = 0; i < workreq->use_sg; i++) {
-   if (sgpnt[i].length == 0 || workreq->use_sg > 
ATP870U_SCATTER) {
-   panic("Fod fight!");
-   }
-   l += sgpnt[i].length;
-   }
-#ifdef ED_DBGP 
-   printk( "send_s870: workreq->use_sg %d, sg_count %d l %8ld\n", 
workreq->use_sg, sg_count, l);
-#endif
-   } else if(workreq->request_bufflen && workreq->sc_data_direction != 
PCI_DMA_NONE) {
-#ifdef ED_DBGP
-   printk("Not using SGL\n");
-#endif 
-   workreq->SCp.dma_handle = pci_map_single(dev->pdev, 
workreq->request_buffer,
-   workreq->request_bufflen,
-   workreq->sc_data_direction);
-   l = workreq->request_bufflen;
-#ifdef ED_DBGP 
-   printk( "send_s870: workreq->use_sg %d, l %8ld\n", 
workreq->use_sg, l);
-#endif
-   } else l = 0;
+
+   sg_count = scsi_dma_map(workreq);
/*
 *  Write transfer size
 */
@@ -938,16 +896,16 @@ oktosend:
 *  a linear chain.
 */
 
-   if (workreq->use_sg) {
-   sgpnt = (struct scatterlist *) workreq->request_buffer;
+   if (l) {
+   struct scatterlist *sgpnt;
i = 0;
-   for (j = 0; j < workreq->use_sg; j++) {
-   bttl = sg_dma_address(&sgpnt[j]);
-   l=sg_dma_len(&sgpnt[j

[PATCH 13/32] aha1542.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/aha1542.c |   46 ++
 1 files changed, 10 insertions(+), 36 deletions(-)

diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 961a188..3eab68f 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -51,15 +51,6 @@
 #define SCSI_BUF_PA(address)   isa_virt_to_bus(address)
 #define SCSI_SG_PA(sgent)  (isa_page_to_bus((sgent)->page) + 
(sgent)->offset)
 
-static void BAD_DMA(void *address, unsigned int length)
-{
-   printk(KERN_CRIT "buf vaddress %p paddress 0x%lx length %d\n",
-  address,
-  SCSI_BUF_PA(address),
-  length);
-   panic("Buffer at physical address > 16Mb used for aha1542");
-}
-
 static void BAD_SG_DMA(Scsi_Cmnd * SCpnt,
   struct scatterlist *sgp,
   int nseg,
@@ -598,8 +589,7 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void 
(*done) (Scsi_Cmnd *))
unchar target = SCpnt->device->id;
unchar lun = SCpnt->device->lun;
unsigned long flags;
-   void *buff = SCpnt->request_buffer;
-   int bufflen = SCpnt->request_bufflen;
+   int bufflen = scsi_bufflen(SCpnt);
int mbo;
struct mailbox *mb;
struct ccb *ccb;
@@ -690,43 +680,29 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void 
(*done) (Scsi_Cmnd *))
 
memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
 
-   if (SCpnt->use_sg) {
+   if (bufflen) {
struct scatterlist *sg;
struct chain *cptr;
 #ifdef DEBUG
unsigned char *ptr;
 #endif
-   int i;
+   int i, sg_count = scsi_sg_count(SCpnt);
ccb[mbo].op = 2;/* SCSI Initiator Command  
w/scatter-gather */
-   SCpnt->host_scribble = kmalloc(512, GFP_KERNEL | GFP_DMA);
+   SCpnt->host_scribble = kmalloc(sizeof(*cptr)*sg_count,
+GFP_KERNEL | GFP_DMA);
cptr = (struct chain *) SCpnt->host_scribble;
if (cptr == NULL) {
/* free the claimed mailbox slot */
HOSTDATA(SCpnt->device->host)->SCint[mbo] = NULL;
return SCSI_MLQUEUE_HOST_BUSY;
}
-   scsi_for_each_sg(SCpnt, sg, SCpnt->use_sg, i) {
-   if (sg->length == 0 || SCpnt->use_sg > 16 ||
-   (((int) sg->offset) & 1) || (sg->length & 1)) {
-   unsigned char *ptr;
-   printk(KERN_CRIT "Bad segment list supplied to 
aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
-   scsi_for_each_sg(SCpnt, sg, SCpnt->use_sg, i) {
-   printk(KERN_CRIT "%d: %p %d\n", i,
-  (page_address(sg->page) +
-   sg->offset), sg->length);
-   };
-   printk(KERN_CRIT "cptr %x: ", (unsigned int) 
cptr);
-   ptr = (unsigned char *) &cptr[i];
-   for (i = 0; i < 18; i++)
-   printk("%02x ", ptr[i]);
-   panic("Fod fight!");
-   };
+   scsi_for_each_sg(SCpnt, sg, sg_count, i) {
any2scsi(cptr[i].dataptr, SCSI_SG_PA(sg));
if (SCSI_SG_PA(sg) + sg->length - 1 > ISA_DMA_THRESHOLD)
-   BAD_SG_DMA(SCpnt, sg, SCpnt->use_sg, i);
+   BAD_SG_DMA(SCpnt, scsi_sglist(SCpnt), sg_count, 
i);
any2scsi(cptr[i].datalen, sg->length);
};
-   any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct 
chain));
+   any2scsi(ccb[mbo].datalen, sg_count * sizeof(struct chain));
any2scsi(ccb[mbo].dataptr, SCSI_BUF_PA(cptr));
 #ifdef DEBUG
printk("cptr %x: ", cptr);
@@ -737,10 +713,8 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void 
(*done) (Scsi_Cmnd *))
} else {
ccb[mbo].op = 0;/* SCSI Initiator Command */
SCpnt->host_scribble = NULL;
-   any2scsi(ccb[mbo].datalen, bufflen);
-   if (buff && SCSI_BUF_PA(buff + bufflen - 1) > ISA_DMA_THRESHOLD)
-   BAD_DMA(buff, bufflen);
-   any2scsi(ccb[mbo].dataptr, SCSI_BUF_PA(buff));
+   any2scsi(ccb[mbo].datalen, 0);
+   any2scsi(ccb[mbo].dataptr, 0);
};
ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7); /*SCSI 
Target Id */
ccb[mbo].rsalen = 16;
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe 

[PATCH 12/32] a3000.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/a3000.c |   15 +++
 1 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/a3000.c b/drivers/scsi/a3000.c
index 796f1c4..d7255c8 100644
--- a/drivers/scsi/a3000.c
+++ b/drivers/scsi/a3000.c
@@ -70,12 +70,8 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
 
if (!dir_in) {
/* copy to bounce buffer for a write */
-   if (cmd->use_sg) {
-   memcpy (HDATA(a3000_host)->dma_bounce_buffer,
-   cmd->SCp.ptr, cmd->SCp.this_residual);
-   } else
-   memcpy (HDATA(a3000_host)->dma_bounce_buffer,
-   cmd->request_buffer, cmd->request_bufflen);
+   memcpy (HDATA(a3000_host)->dma_bounce_buffer,
+   cmd->SCp.ptr, cmd->SCp.this_residual);
}
 
addr = virt_to_bus(HDATA(a3000_host)->dma_bounce_buffer);
@@ -146,7 +142,7 @@ static void dma_stop(struct Scsi_Host *instance, struct 
scsi_cmnd *SCpnt,
 
 /* copy from a bounce buffer, if necessary */
 if (status && HDATA(instance)->dma_bounce_buffer) {
-   if (SCpnt && SCpnt->use_sg) {
+   if (SCpnt) {
if (HDATA(instance)->dma_dir && SCpnt)
memcpy (SCpnt->SCp.ptr,
HDATA(instance)->dma_bounce_buffer,
@@ -155,11 +151,6 @@ static void dma_stop(struct Scsi_Host *instance, struct 
scsi_cmnd *SCpnt,
HDATA(instance)->dma_bounce_buffer = NULL;
HDATA(instance)->dma_bounce_len = 0;
} else {
-   if (HDATA(instance)->dma_dir && SCpnt)
-   memcpy (SCpnt->request_buffer,
-   HDATA(instance)->dma_bounce_buffer,
-   SCpnt->request_bufflen);
-
kfree (HDATA(instance)->dma_bounce_buffer);
HDATA(instance)->dma_bounce_buffer = NULL;
HDATA(instance)->dma_bounce_len = 0;
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/32] a2091.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/a2091.c |   36 +---
 1 files changed, 5 insertions(+), 31 deletions(-)

diff --git a/drivers/scsi/a2091.c b/drivers/scsi/a2091.c
index b7c5385..23f27c9 100644
--- a/drivers/scsi/a2091.c
+++ b/drivers/scsi/a2091.c
@@ -73,18 +73,9 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
}
 
if (!dir_in) {
-   /* copy to bounce buffer for a write */
-   if (cmd->use_sg)
-#if 0
-   panic ("scsi%ddma: incomplete s/g support",
-  instance->host_no);
-#else
+   /* copy to bounce buffer for a write */
memcpy (HDATA(instance)->dma_bounce_buffer,
cmd->SCp.ptr, cmd->SCp.this_residual);
-#endif
-   else
-   memcpy (HDATA(instance)->dma_bounce_buffer,
-   cmd->request_buffer, cmd->request_bufflen);
}
 }
 
@@ -144,30 +135,13 @@ static void dma_stop(struct Scsi_Host *instance, struct 
scsi_cmnd *SCpnt,
 
 /* copy from a bounce buffer, if necessary */
 if (status && HDATA(instance)->dma_bounce_buffer) {
-   if (SCpnt && SCpnt->use_sg) {
-#if 0
-   panic ("scsi%d: incomplete s/g support",
-  instance->host_no);
-#else
-   if( HDATA(instance)->dma_dir )
+   if( HDATA(instance)->dma_dir )
memcpy (SCpnt->SCp.ptr, 
HDATA(instance)->dma_bounce_buffer,
SCpnt->SCp.this_residual);
-   kfree (HDATA(instance)->dma_bounce_buffer);
-   HDATA(instance)->dma_bounce_buffer = NULL;
-   HDATA(instance)->dma_bounce_len = 0;
-   
-#endif
-   } else {
-   if (HDATA(instance)->dma_dir && SCpnt)
-   memcpy (SCpnt->request_buffer,
-   HDATA(instance)->dma_bounce_buffer,
-   SCpnt->request_bufflen);
-
-   kfree (HDATA(instance)->dma_bounce_buffer);
-   HDATA(instance)->dma_bounce_buffer = NULL;
-   HDATA(instance)->dma_bounce_len = 0;
-   }
+   kfree (HDATA(instance)->dma_bounce_buffer);
+   HDATA(instance)->dma_bounce_buffer = NULL;
+   HDATA(instance)->dma_bounce_len = 0;
 }
 }
 
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/32] eata_pio.c: convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/eata_pio.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c
index 96180bb..e6d5138 100644
--- a/drivers/scsi/eata_pio.c
+++ b/drivers/scsi/eata_pio.c
@@ -385,7 +385,7 @@ static int eata_pio_queue(struct scsi_cmnd *cmd,
cp->DataIn = 0; /* Input mode  */
 
cp->Interpret = (cmd->device->id == hd->hostid);
-   cp->cp_datalen = cpu_to_be32(cmd->request_bufflen);
+   cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd));
cp->Auto_Req_Sen = 0;
cp->cp_reqDMA = 0;
cp->reqlen = 0;
@@ -402,14 +402,14 @@ static int eata_pio_queue(struct scsi_cmnd *cmd,
cp->cmd = cmd;
cmd->host_scribble = (char *) &hd->ccb[y];
 
-   if (cmd->use_sg == 0) {
+   if (!scsi_bufflen(cmd)) {
cmd->SCp.buffers_residual = 1;
-   cmd->SCp.ptr = cmd->request_buffer;
-   cmd->SCp.this_residual = cmd->request_bufflen;
+   cmd->SCp.ptr = NULL;
+   cmd->SCp.this_residual = 0;
cmd->SCp.buffer = NULL;
} else {
-   cmd->SCp.buffer = cmd->request_buffer;
-   cmd->SCp.buffers_residual = cmd->use_sg;
+   cmd->SCp.buffer = scsi_sglist(cmd);
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd);
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 
cmd->SCp.buffer->offset;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
}
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 9/32] nsp_cs.c convert to data accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh
[PATCH 9/32] nsp_cs.c convert to data accessors and !use_sg cleanup

  - use scsi data accessors
  - cleanup !use_sg code paths
  - TODO: use next_sg() for Jens's sglist branch. Look for 2
places with "SCp.buffer++"

 Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/pcmcia/nsp_cs.c |   54 ++---
 1 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index a45d89b..5082ca3 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -135,6 +135,11 @@ static nsp_hw_data nsp_data_base; /* attach <-> detect 
glue */
 
 #define NSP_DEBUG_BUF_LEN  150
 
+static inline void nsp_inc_resid(struct scsi_cmnd *SCpnt, int residInc)
+{
+   scsi_set_resid(SCpnt, scsi_get_resid(SCpnt) + residInc);
+}
+
 static void nsp_cs_message(const char *func, int line, char *type, char *fmt, 
...)
 {
va_list args;
@@ -192,8 +197,10 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
 #endif
nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
 
-   nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "SCpnt=0x%p target=%d lun=%d buff=0x%p 
bufflen=%d use_sg=%d",
-  SCpnt, target, SCpnt->device->lun, SCpnt->request_buffer, 
SCpnt->request_bufflen, SCpnt->use_sg);
+   nsp_dbg(NSP_DEBUG_QUEUECOMMAND,
+   "SCpnt=0x%p target=%d lun=%d sglist=0x%p bufflen=%d 
sg_count=%d",
+   SCpnt, target, SCpnt->device->lun, scsi_sglist(SCpnt),
+   scsi_bufflen(SCpnt), scsi_sg_count(SCpnt));
//nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "before CurrentSC=0x%p", 
data->CurrentSC);
 
SCpnt->scsi_done= done;
@@ -225,7 +232,7 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
SCpnt->SCp.have_data_in = IO_UNKNOWN;
SCpnt->SCp.sent_command = 0;
SCpnt->SCp.phase= PH_UNDETERMINED;
-   SCpnt->resid= SCpnt->request_bufflen;
+   scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
 
/* setup scratch area
   SCp.ptr  : buffer pointer
@@ -233,14 +240,14 @@ static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
   SCp.buffer   : next buffer
   SCp.buffers_residual : left buffers in list
   SCp.phase: current state of the command */
-   if (SCpnt->use_sg) {
-   SCpnt->SCp.buffer   = (struct scatterlist *) 
SCpnt->request_buffer;
+   if (scsi_bufflen(SCpnt)) {
+   SCpnt->SCp.buffer   = scsi_sglist(SCpnt);
SCpnt->SCp.ptr  = BUFFER_ADDR;
SCpnt->SCp.this_residual= SCpnt->SCp.buffer->length;
-   SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
+   SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
} else {
-   SCpnt->SCp.ptr  = (char *) SCpnt->request_buffer;
-   SCpnt->SCp.this_residual= SCpnt->request_bufflen;
+   SCpnt->SCp.ptr  = NULL;
+   SCpnt->SCp.this_residual= 0;
SCpnt->SCp.buffer   = NULL;
SCpnt->SCp.buffers_residual = 0;
}
@@ -721,7 +728,9 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt)
ocount = data->FifoCount;
 
nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p resid=%d ocount=%d ptr=0x%p 
this_residual=%d buffers=0x%p nbuf=%d",
-   SCpnt, SCpnt->resid, ocount, SCpnt->SCp.ptr, 
SCpnt->SCp.this_residual, SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual);
+   SCpnt, scsi_get_resid(SCpnt), ocount, SCpnt->SCp.ptr,
+   SCpnt->SCp.this_residual, SCpnt->SCp.buffer,
+   SCpnt->SCp.buffers_residual);
 
time_out = 1000;
 
@@ -771,7 +780,7 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt)
return;
}
 
-   SCpnt->resid -= res;
+   nsp_inc_resid(SCpnt, -res);
SCpnt->SCp.ptr   += res;
SCpnt->SCp.this_residual -= res;
ocount   += res;
@@ -795,10 +804,12 @@ static void nsp_pio_read(struct scsi_cmnd *SCpnt)
 
if (time_out == 0) {
nsp_msg(KERN_DEBUG, "pio read timeout resid=%d this_residual=%d 
buffers_residual=%d",
-   SCpnt->resid, SCpnt->SCp.this_residual, 
SCpnt->SCp.buffers_residual);
+   scsi_get_resid(SCpnt), SCpnt->SCp.this_residual,
+   SCpnt->SCp.buffers_residual);
}
nsp_dbg(NSP_DEBUG_DATA_IO, "read ocount=0x%x", ocount);
-   nsp_dbg(NSP_DEBUG_DATA_IO, "r cmd=%d resid=0x%x\n", data->CmdId, 
SCpnt->resid);
+   nsp_dbg(NSP_DEBUG_DATA_IO, "r cmd=%d resid=0x%x\n", data->CmdId,
+   scsi_get_resid(SCpnt));
 }
 
 /*
@@ -816,7 +827,9 @@ static void nsp_pio_write(struct scsi_cmnd *SCpnt)
   

[PATCH 8/32] arm: scsi convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - convert to accessors and !use_sg cleanup

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/arm/acornscsi.c |   14 +++---
 drivers/scsi/arm/scsi.h  |   34 +++---
 2 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index eceacf6..3bedf24 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -1790,7 +1790,7 @@ int acornscsi_starttransfer(AS_Host *host)
return 0;
 }
 
-residual = host->SCpnt->request_bufflen - host->scsi.SCp.scsi_xferred;
+residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
 
 sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, 
host->device[host->SCpnt->device->id].sync_xfer);
 sbic_arm_writenext(host->scsi.io_port, residual >> 16);
@@ -2270,7 +2270,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
case 0x4b:  /* -> PHASE_STATUSIN
*/
case 0x8b:  /* -> PHASE_STATUSIN
*/
/* DATA IN -> STATUS */
-   host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+   host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  acornscsi_sbic_xfcount(host);
acornscsi_dma_stop(host);
acornscsi_readstatusbyte(host);
@@ -2281,7 +2281,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
case 0x4e:  /* -> PHASE_MSGOUT  
*/
case 0x8e:  /* -> PHASE_MSGOUT  
*/
/* DATA IN -> MESSAGE OUT */
-   host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+   host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  acornscsi_sbic_xfcount(host);
acornscsi_dma_stop(host);
acornscsi_sendmessage(host);
@@ -2291,7 +2291,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
case 0x4f:  /* message in   
*/
case 0x8f:  /* message in   
*/
/* DATA IN -> MESSAGE IN */
-   host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+   host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  acornscsi_sbic_xfcount(host);
acornscsi_dma_stop(host);
acornscsi_message(host);/* -> PHASE_MSGIN, PHASE_DISCONNECT 
*/
@@ -2319,7 +2319,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
case 0x4b:  /* -> PHASE_STATUSIN
*/
case 0x8b:  /* -> PHASE_STATUSIN
*/
/* DATA OUT -> STATUS */
-   host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+   host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  acornscsi_sbic_xfcount(host);
acornscsi_dma_stop(host);
acornscsi_dma_adjust(host);
@@ -2331,7 +2331,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
case 0x4e:  /* -> PHASE_MSGOUT  
*/
case 0x8e:  /* -> PHASE_MSGOUT  
*/
/* DATA OUT -> MESSAGE OUT */
-   host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+   host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  acornscsi_sbic_xfcount(host);
acornscsi_dma_stop(host);
acornscsi_dma_adjust(host);
@@ -2342,7 +2342,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
case 0x4f:  /* message in   
*/
case 0x8f:  /* message in   
*/
/* DATA OUT -> MESSAGE IN */
-   host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+   host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  acornscsi_sbic_xfcount(host);
acornscsi_dma_stop(host);
acornscsi_dma_adjust(host);
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h
index 21ba571..95cfb21 100644
--- a/drivers/scsi/arm/scsi.h
+++ b/drivers/scsi/arm/scsi.h
@@ -70,48 +70,36 @@ static inline void init_SCp(struct scsi_cmnd *SCpnt)
 {
memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer));
 
-   if (SCpnt->use_sg) {
+   if (scsi_bufflen(SCpnt)) {
unsigned long len = 0;
int buf;
 
-   SCpnt->SCp.buffer = (struct scatterlist *) 
SCpnt->request_buffer;
-

[PATCH 7/32] NCR5380 familly convert to accessors & !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

  - convert to accessors and !use_sg cleanup
  - FIXME: Not sg-chain ready look for ++cmd->SCp.buffer

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/NCR5380.c   |   14 +++---
 drivers/scsi/atari_NCR5380.c |   22 +++---
 drivers/scsi/sun3_NCR5380.c  |   22 +++---
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 988f0bc..47ee320 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -295,17 +295,17 @@ static __inline__ void initialize_SCp(Scsi_Cmnd * cmd)
 * various queues are valid.
 */
 
-   if (cmd->use_sg) {
-   cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
-   cmd->SCp.buffers_residual = cmd->use_sg - 1;
+   if (scsi_bufflen(cmd)) {
+   cmd->SCp.buffer = scsi_sglist(cmd);
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page)+
   cmd->SCp.buffer->offset;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
} else {
cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
-   cmd->SCp.ptr = (char *) cmd->request_buffer;
-   cmd->SCp.this_residual = cmd->request_bufflen;
+   cmd->SCp.ptr = NULL;
+   cmd->SCp.this_residual = 0;
}
 }
 
@@ -976,14 +976,14 @@ static int NCR5380_queue_command(Scsi_Cmnd * cmd, void 
(*done) (Scsi_Cmnd *))
case WRITE_6:
case WRITE_10:
hostdata->time_write[cmd->device->id] -= (jiffies - 
hostdata->timebase);
-   hostdata->bytes_write[cmd->device->id] += 
cmd->request_bufflen;
+   hostdata->bytes_write[cmd->device->id] += 
scsi_bufflen(cmd);
hostdata->pendingw++;
break;
case READ:
case READ_6:
case READ_10:
hostdata->time_read[cmd->device->id] -= (jiffies - 
hostdata->timebase);
-   hostdata->bytes_read[cmd->device->id] += 
cmd->request_bufflen;
+   hostdata->bytes_read[cmd->device->id] += 
scsi_bufflen(cmd);
hostdata->pendingr++;
break;
}
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 52d0b87..062d8aa 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -512,9 +512,9 @@ static inline void initialize_SCp(Scsi_Cmnd *cmd)
 * various queues are valid.
 */
 
-   if (cmd->use_sg) {
-   cmd->SCp.buffer = (struct scatterlist *)cmd->request_buffer;
-   cmd->SCp.buffers_residual = cmd->use_sg - 1;
+   if (scsi_bufflen(cmd)) {
+   cmd->SCp.buffer = scsi_sglist(cmd);
+   cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page) +
   cmd->SCp.buffer->offset;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
@@ -525,8 +525,8 @@ static inline void initialize_SCp(Scsi_Cmnd *cmd)
} else {
cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
-   cmd->SCp.ptr = (char *)cmd->request_buffer;
-   cmd->SCp.this_residual = cmd->request_bufflen;
+   cmd->SCp.ptr = NULL;
+   cmd->SCp.this_residual = 0;
}
 }
 
@@ -938,21 +938,21 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void 
(*done)(Scsi_Cmnd *))
}
 # endif
 # ifdef NCR5380_STAT_LIMIT
-   if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
+   if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
 # endif
switch (cmd->cmnd[0]) {
case WRITE:
case WRITE_6:
case WRITE_10:
hostdata->time_write[cmd->device->id] -= (jiffies - 
hostdata->timebase);
-   hostdata->bytes_write[cmd->device->id] += 
cmd->request_bufflen;
+   hostdata->bytes_write[cmd->device->id] += 
scsi_bufflen(cmd);
hostdata->pendingw++;
break;
case READ:
case READ_6:
case READ_10:
hostdata->time_read[cmd->device->id] -= (jiffies - 
hostdata->timebase);
-   hostdata->bytes_read[cmd->device->id] += 
cmd->request_bufflen;
+   hostdata->bytes_read[cmd->device->id] += 
scsi_bufflen(cmd);
hostdata->pendingr++;
break;
}
@@ -1354,21 +1354,21 @@ static irqreturn_t NCR5380_intr(int irq, void *dev_id)
 static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd *cmd)

[PATCH 6/32] usb: freecom.c & sddr09.c - convert to accessors and !use_sg cleanup

2007-10-17 Thread Boaz Harrosh

 - Use scsi data accessors and remove of !use_sg code path
 - This patch is dependent on cleanup patch to usb transport.c/h

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/usb/storage/freecom.c |   14 ++
 drivers/usb/storage/sddr09.c  |9 +++--
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index 88aa59a..f5a4e8d 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -132,8 +132,7 @@ freecom_readdata (struct scsi_cmnd *srb, struct us_data *us,
 
/* Now transfer all of our blocks. */
US_DEBUGP("Start of read\n");
-   result = usb_stor_bulk_transfer_sg(us, ipipe, srb->request_buffer,
-   count, srb->use_sg, &srb->resid);
+   result = usb_stor_bulk_srb(us, ipipe, srb);
US_DEBUGP("freecom_readdata done!\n");
 
if (result > USB_STOR_XFER_SHORT)
@@ -166,8 +165,7 @@ freecom_writedata (struct scsi_cmnd *srb, struct us_data 
*us,
 
/* Now transfer all of our blocks. */
US_DEBUGP("Start of write\n");
-   result = usb_stor_bulk_transfer_sg(us, opipe, srb->request_buffer,
-   count, srb->use_sg, &srb->resid);
+   result = usb_stor_bulk_srb(us, opipe, srb);
 
US_DEBUGP("freecom_writedata done!\n");
if (result > USB_STOR_XFER_SHORT)
@@ -281,7 +279,7 @@ int freecom_transport(struct scsi_cmnd *srb, struct us_data 
*us)
 * and such will hang. */
US_DEBUGP("Device indicates that it has %d bytes available\n",
le16_to_cpu (fst->Count));
-   US_DEBUGP("SCSI requested %d\n", srb->request_bufflen);
+   US_DEBUGP("SCSI requested %d\n", scsi_bufflen(srb));
 
/* Find the length we desire to read. */
switch (srb->cmnd[0]) {
@@ -292,12 +290,12 @@ int freecom_transport(struct scsi_cmnd *srb, struct 
us_data *us)
length = le16_to_cpu(fst->Count);
break;
default:
-   length = srb->request_bufflen;
+   length = scsi_bufflen(srb);
}
 
/* verify that this amount is legal */
-   if (length > srb->request_bufflen) {
-   length = srb->request_bufflen;
+   if (length > scsi_bufflen(srb)) {
+   length = scsi_bufflen(srb);
US_DEBUGP("Truncating request to match buffer length: %d\n", 
length);
}
 
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index b12202c..8972b17 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -1623,7 +1623,7 @@ int sddr09_transport(struct scsi_cmnd *srb, struct 
us_data *us)
return USB_STOR_TRANSPORT_ERROR;
}
 
-   if (srb->request_bufflen == 0)
+   if (scsi_bufflen(srb) == 0)
return USB_STOR_TRANSPORT_GOOD;
 
if (srb->sc_data_direction == DMA_TO_DEVICE ||
@@ -1634,12 +1634,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct 
us_data *us)
US_DEBUGP("SDDR09: %s %d bytes\n",
  (srb->sc_data_direction == DMA_TO_DEVICE) ?
  "sending" : "receiving",
- srb->request_bufflen);
+ scsi_bufflen(srb));
 
-   result = usb_stor_bulk_transfer_sg(us, pipe,
-   srb->request_buffer,
-   srb->request_bufflen,
-   srb->use_sg, &srb->resid);
+   result = usb_stor_bulk_srb(us, pipe, srb);
 
return (result == USB_STOR_XFER_GOOD ?
USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/32] usb: shuttle_usbat.c - convert to accessors and !use_sg code path removal

2007-10-17 Thread Boaz Harrosh

 - functions that received char* but where passed scatterlist* mostly
   were changed to receive void*
 - Use scsi data accessors and remove of !use_sg code path

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/usb/storage/shuttle_usbat.c |   68 +-
 1 files changed, 26 insertions(+), 42 deletions(-)

diff --git a/drivers/usb/storage/shuttle_usbat.c 
b/drivers/usb/storage/shuttle_usbat.c
index cb22a9a..570c125 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -130,7 +130,7 @@ static int usbat_write(struct us_data *us,
  * Convenience function to perform a bulk read
  */
 static int usbat_bulk_read(struct us_data *us,
-  unsigned char *data,
+  void* buf,
   unsigned int len,
   int use_sg)
 {
@@ -138,14 +138,14 @@ static int usbat_bulk_read(struct us_data *us,
return USB_STOR_XFER_GOOD;
 
US_DEBUGP("usbat_bulk_read: len = %d\n", len);
-   return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, data, len, 
use_sg, NULL);
+   return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, 
use_sg, NULL);
 }
 
 /*
  * Convenience function to perform a bulk write
  */
 static int usbat_bulk_write(struct us_data *us,
-   unsigned char *data,
+   void* buf,
unsigned int len,
int use_sg)
 {
@@ -153,7 +153,7 @@ static int usbat_bulk_write(struct us_data *us,
return USB_STOR_XFER_GOOD;
 
US_DEBUGP("usbat_bulk_write:  len = %d\n", len);
-   return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, data, len, 
use_sg, NULL);
+   return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, 
use_sg, NULL);
 }
 
 /*
@@ -314,7 +314,7 @@ static int usbat_wait_not_busy(struct us_data *us, int 
minutes)
  * Read block data from the data register
  */
 static int usbat_read_block(struct us_data *us,
-   unsigned char *content,
+   void* buf,
unsigned short len,
int use_sg)
 {
@@ -337,7 +337,7 @@ static int usbat_read_block(struct us_data *us,
if (result != USB_STOR_XFER_GOOD)
return USB_STOR_TRANSPORT_ERROR;
 
-   result = usbat_bulk_read(us, content, len, use_sg);
+   result = usbat_bulk_read(us, buf, len, use_sg);
return (result == USB_STOR_XFER_GOOD ?
USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
 }
@@ -347,7 +347,7 @@ static int usbat_read_block(struct us_data *us,
  */
 static int usbat_write_block(struct us_data *us,
 unsigned char access,
-unsigned char *content,
+void* buf,
 unsigned short len,
 int minutes,
 int use_sg)
@@ -372,7 +372,7 @@ static int usbat_write_block(struct us_data *us,
if (result != USB_STOR_XFER_GOOD)
return USB_STOR_TRANSPORT_ERROR;
 
-   result = usbat_bulk_write(us, content, len, use_sg);
+   result = usbat_bulk_write(us, buf, len, use_sg);
if (result != USB_STOR_XFER_GOOD)
return USB_STOR_TRANSPORT_ERROR;
 
@@ -392,7 +392,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
   unsigned char timeout,
   unsigned char qualifier,
   int direction,
-  unsigned char *content,
+  void *buf,
   unsigned short len,
   int use_sg,
   int minutes)
@@ -472,7 +472,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
}
 
result = usb_stor_bulk_transfer_sg(us,
-   pipe, content, len, use_sg, NULL);
+   pipe, buf, len, use_sg, NULL);
 
/*
 * If we get a stall on the bulk download, we'll retry
@@ -606,7 +606,7 @@ static int usbat_multiple_write(struct us_data *us,
  * other related details) are defined beforehand with _set_shuttle_features().
  */
 static int usbat_read_blocks(struct us_data *us,
-unsigned char *buffer,
+void* buffer,
 int len,
 int use_sg)
 {
@@ -648,7 +648,7 @@ static int usbat_read_blocks(struct us_data *us,
  * other related details) are defined beforehand with _set_shuttle_features().
  */
 static int usbat_write_blocks(struct us_data *us,
- unsigned char *buffer,
+

[PATCH 4/32] usb: protocol.c - convert to accessors and !use_sg code path removal

2007-10-17 Thread Boaz Harrosh

 - Use scsi data accessors and remove of !use_sg code path

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/usb/storage/protocol.c |  126 +---
 1 files changed, 53 insertions(+), 73 deletions(-)

diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index cc8f7c5..6a11caf 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -149,11 +149,7 @@ void usb_stor_transparent_scsi_command(struct scsi_cmnd 
*srb,
  ***/
 
 /* Copy a buffer of length buflen to/from the srb's transfer buffer.
- * (Note: for scatter-gather transfers (srb->use_sg > 0), srb->request_buffer
- * points to a list of s-g entries and we ignore srb->request_bufflen.
- * For non-scatter-gather transfers, srb->request_buffer points to the
- * transfer buffer itself and srb->request_bufflen is the buffer's length.)
- * Update the *index and *offset variables so that the next copy will
+ * Update the **sgptr and *offset variables so that the next copy will
  * pick up from where this one left off. */
 
 unsigned int usb_stor_access_xfer_buf(unsigned char *buffer,
@@ -162,80 +158,64 @@ unsigned int usb_stor_access_xfer_buf(unsigned char 
*buffer,
 {
unsigned int cnt;
 
-   /* If not using scatter-gather, just transfer the data directly.
-* Make certain it will fit in the available buffer space. */
-   if (srb->use_sg == 0) {
-   if (*offset >= srb->request_bufflen)
-   return 0;
-   cnt = min(buflen, srb->request_bufflen - *offset);
-   if (dir == TO_XFER_BUF)
-   memcpy((unsigned char *) srb->request_buffer + *offset,
-   buffer, cnt);
-   else
-   memcpy(buffer, (unsigned char *) srb->request_buffer +
-   *offset, cnt);
-   *offset += cnt;
-
-   /* Using scatter-gather.  We have to go through the list one entry
+   /* We have to go through the list one entry
 * at a time.  Each s-g entry contains some number of pages, and
 * each page has to be kmap()'ed separately.  If the page is already
 * in kernel-addressable memory then kmap() will return its address.
 * If the page is not directly accessible -- such as a user buffer
 * located in high memory -- then kmap() will map it to a temporary
 * position in the kernel's virtual address space. */
-   } else {
-   struct scatterlist *sg = *sgptr;
-
-   if (!sg)
-   sg = (struct scatterlist *) srb->request_buffer;
-
-   /* This loop handles a single s-g list entry, which may
-* include multiple pages.  Find the initial page structure
-* and the starting offset within the page, and update
-* the *offset and *index values for the next loop. */
-   cnt = 0;
-   while (cnt < buflen) {
-   struct page *page = sg->page +
-   ((sg->offset + *offset) >> PAGE_SHIFT);
-   unsigned int poff =
-   (sg->offset + *offset) & (PAGE_SIZE-1);
-   unsigned int sglen = sg->length - *offset;
-
-   if (sglen > buflen - cnt) {
-
-   /* Transfer ends within this s-g entry */
-   sglen = buflen - cnt;
-   *offset += sglen;
-   } else {
-
-   /* Transfer continues to next s-g entry */
-   *offset = 0;
-   sg = sg_next(sg);
-   }
-
-   /* Transfer the data for all the pages in this
-* s-g entry.  For each page: call kmap(), do the
-* transfer, and call kunmap() immediately after. */
-   while (sglen > 0) {
-   unsigned int plen = min(sglen, (unsigned int)
-   PAGE_SIZE - poff);
-   unsigned char *ptr = kmap(page);
-
-   if (dir == TO_XFER_BUF)
-   memcpy(ptr + poff, buffer + cnt, plen);
-   else
-   memcpy(buffer + cnt, ptr + poff, plen);
-   kunmap(page);
-
-   /* Start at the beginning of the next page */
-   poff = 0;
-   ++page;
-   cnt += plen;
-   sglen -= plen;
-   }
+   struct scatterlist *sg = *sgptr;
+

[PATCH 3/32] usb: transport - convert to accessors and !use_sg code path removal

2007-10-17 Thread Boaz Harrosh

  - Use scsi data accessors and remove of !use_sg code path.
  - New usb_stor_bulk_srb() for use by drivers

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/usb/storage/transport.c |   44 +++---
 drivers/usb/storage/transport.h |2 +
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index c646750..d3a84a2 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -459,6 +459,21 @@ static int usb_stor_bulk_transfer_sglist(struct us_data 
*us, unsigned int pipe,
 }
 
 /*
+ * Common used function. Transfer a complete command
+ * via usb_stor_bulk_transfer_sglist() above. Set cmnd resid
+ */
+int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
+ struct scsi_cmnd* srb)
+{
+   int resid = scsi_get_resid(srb);
+   int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
+ scsi_sg_count(srb), scsi_bufflen(srb),
+ &resid);
+   scsi_set_resid(srb, resid);
+   return result;
+}
+
+/*
  * Transfer an entire SCSI command's worth of data payload over the bulk
  * pipe.
  *
@@ -508,7 +523,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, 
struct us_data *us)
int result;
 
/* send the command to the transport layer */
-   srb->resid = 0;
+   scsi_set_resid(srb, 0);
result = us->transport(srb, us);
 
/* if the command gets aborted by the higher layers, we need to
@@ -568,7 +583,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, 
struct us_data *us)
 * A short transfer on a command where we don't expect it
 * is unusual, but it doesn't mean we need to auto-sense.
 */
-   if ((srb->resid > 0) &&
+   if ((scsi_get_resid(srb) > 0) &&
!((srb->cmnd[0] == REQUEST_SENSE) ||
  (srb->cmnd[0] == INQUIRY) ||
  (srb->cmnd[0] == MODE_SENSE) ||
@@ -593,7 +608,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, 
struct us_data *us)
srb->cmd_len = 12;
 
/* issue the auto-sense command */
-   srb->resid = 0;
+   scsi_set_resid(srb, 0);
temp_result = us->transport(us->srb, us);
 
/* let's clean up right away */
@@ -649,7 +664,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, 
struct us_data *us)
 
/* Did we transfer less than the minimum amount required? */
if (srb->result == SAM_STAT_GOOD &&
-   srb->request_bufflen - srb->resid < srb->underflow)
+   scsi_bufflen(srb) - scsi_get_resid(srb) < 
srb->underflow)
srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24);
 
return;
@@ -708,7 +723,7 @@ void usb_stor_stop_transport(struct us_data *us)
 
 int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us)
 {
-   unsigned int transfer_length = srb->request_bufflen;
+   unsigned int transfer_length = scsi_bufflen(srb);
unsigned int pipe = 0;
int result;
 
@@ -737,9 +752,7 @@ int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct 
us_data *us)
if (transfer_length) {
pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 
us->recv_bulk_pipe : us->send_bulk_pipe;
-   result = usb_stor_bulk_transfer_sg(us, pipe,
-   srb->request_buffer, transfer_length,
-   srb->use_sg, &srb->resid);
+   result = usb_stor_bulk_srb(us, pipe, srb);
US_DEBUGP("CBI data stage result is 0x%x\n", result);
 
/* if we stalled the data transfer it means command failed */
@@ -808,7 +821,7 @@ int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct 
us_data *us)
  */
 int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
 {
-   unsigned int transfer_length = srb->request_bufflen;
+   unsigned int transfer_length = scsi_bufflen(srb);
int result;
 
/* COMMAND STAGE */
@@ -836,9 +849,7 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct 
us_data *us)
if (transfer_length) {
unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 
us->recv_bulk_pipe : us->send_bulk_pipe;
-   result = usb_stor_bulk_transfer_sg(us, pipe,
-   srb->request_buffer, transfer_length,
-   srb->use_sg, &srb->resid);
+   result = usb_stor_bulk_srb(us, pipe, srb);
US_DEBUGP("CB data stage result is 0x%x\n", result);
 
/* if we stalled the data transfer it means command failed */
@@ -904,7 +915,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct 
us_data *us)

Re: What still uses the block layer?

2007-10-17 Thread Stefan Richter
Gabor Gombas wrote:
> On Tue, Oct 16, 2007 at 01:55:07PM -0700, [EMAIL PROTECTED] wrote:
>> why is this any different from the external enclosures? they have always 
>> appeared as the type of device that connects them to the motherboard, (and 
>> even with SCSI, there are some controllers that don't generate sdX devices)
> 
> In the past enclosures supported only one kind of connector so this
> assumption was fine. But nowadays an external disk may have several
> connectors (like USB, Firewire and eSata). Why should the disk's name
> depend on what type of cable did I manage to grab first? It is the
> _same_ disk regardless of the cable type.

Yes, but even udev won't give you one and the same symlink to the disk's
device file then.¹  There isn't a persistent unique target/unit property
which all of these transports have in common.

The only thing that could be common in the best case is the symlink to
the partition's device file, based on filesystem UUID or filesystem label.

¹) unless you write your own rule specific to this on particular enclosure
-- 
Stefan Richter
-=-=-=== =-=- =---=
http://arcgraph.de/sr/
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/32] isd200.c: use one-element sg list in issuing commands

2007-10-17 Thread Boaz Harrosh

  - This patch should be commited before:
usb: transport - convert to accessors and !use_sg code path removal

  - isd200_action() was still using direct liniar pointers in issuing
commands to the USB transport level. This is no longer supported,
use one-element scatterlist instead.
  - Adjustment of command's length in the case of scsi-to-ata translation
is now restored before return to queuecommand, since other wise it can
leak BIOs.
  - isd200_action() return Error on unknown requests. Used to print an error
but still try to send garbage cdb.
  - convert few places to scsi data accessors.
  - Todo: This file will need to be changed when scsi_cmnd changes to
scsi_data_buffer or any other solution.

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/usb/storage/isd200.c |   66 +
 1 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 6831dca..a624b4e 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -287,6 +288,7 @@ struct isd200_info {
/* maximum number of LUNs supported */
unsigned char MaxLUNs;
struct scsi_cmnd srb;
+   struct scatterlist sg;
 };
 
 
@@ -398,6 +400,31 @@ static void isd200_build_sense(struct us_data *us, struct 
scsi_cmnd *srb)
  * Transport routines
  ***/
 
+/**
+ *  isd200_set_srb(), isd200_srb_set_bufflen()
+ *
+ * Two helpers to facilitate in initialization of scsi_cmnd structure
+ * Will need to change when struct scsi_cmnd changes
+ */
+static void isd200_set_srb(struct isd200_info *info,
+   enum dma_data_direction dir, void* buff, unsigned bufflen)
+{
+   struct scsi_cmnd *srb = &info->srb;
+
+   if (buff)
+   sg_init_one(&info->sg, buff, bufflen);
+
+   srb->sc_data_direction = dir;
+   srb->request_buffer = buff ? &info->sg : NULL;
+   srb->request_bufflen = bufflen;
+   srb->use_sg = buff ? 1 : 0;
+}
+
+static void isd200_srb_set_bufflen(struct scsi_cmnd *srb, unsigned bufflen)
+{
+   srb->request_bufflen = bufflen;
+}
+
 
 /**
  *  isd200_action
@@ -432,9 +459,7 @@ static int isd200_action( struct us_data *us, int action,
ata.generic.RegisterSelect =
  REG_CYLINDER_LOW | REG_CYLINDER_HIGH |
  REG_STATUS | REG_ERROR;
-   srb->sc_data_direction = DMA_FROM_DEVICE;
-   srb->request_buffer = pointer;
-   srb->request_bufflen = value;
+   isd200_set_srb(info, DMA_FROM_DEVICE, pointer, value);
break;
 
case ACTION_ENUM:
@@ -444,7 +469,7 @@ static int isd200_action( struct us_data *us, int action,
   ACTION_SELECT_5;
ata.generic.RegisterSelect = REG_DEVICE_HEAD;
ata.write.DeviceHeadByte = value;
-   srb->sc_data_direction = DMA_NONE;
+   isd200_set_srb(info, DMA_NONE, NULL, 0);
break;
 
case ACTION_RESET:
@@ -453,7 +478,7 @@ static int isd200_action( struct us_data *us, int action,
   ACTION_SELECT_3|ACTION_SELECT_4;
ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
ata.write.DeviceControlByte = ATA_DC_RESET_CONTROLLER;
-   srb->sc_data_direction = DMA_NONE;
+   isd200_set_srb(info, DMA_NONE, NULL, 0);
break;
 
case ACTION_REENABLE:
@@ -462,7 +487,7 @@ static int isd200_action( struct us_data *us, int action,
   ACTION_SELECT_3|ACTION_SELECT_4;
ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
ata.write.DeviceControlByte = ATA_DC_REENABLE_CONTROLLER;
-   srb->sc_data_direction = DMA_NONE;
+   isd200_set_srb(info, DMA_NONE, NULL, 0);
break;
 
case ACTION_SOFT_RESET:
@@ -471,21 +496,20 @@ static int isd200_action( struct us_data *us, int action,
ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND;
ata.write.DeviceHeadByte = info->DeviceHead;
ata.write.CommandByte = WIN_SRST;
-   srb->sc_data_direction = DMA_NONE;
+   isd200_set_srb(info, DMA_NONE, NULL, 0);
break;
 
case ACTION_IDENTIFY:
US_DEBUGP("   isd200_action(IDENTIFY)\n");
ata.generic.RegisterSelect = REG_COMMAND;
ata.write.CommandByte = WIN_IDENTIFY;
-   srb->sc_data_direction = DMA_FROM_DEVICE;
-   srb->request_buffer = (void *) info->id;

[PATCH 1/32] arm: fas216 Use scsi_eh API for REQUEST_SENSE invocation

2007-10-17 Thread Boaz Harrosh

  - Use new scsi_eh_prep/restor_cmnd() for synchronous
REQUEST_SENSE invocation.

Signed-off-by: Boaz Harrosh <[EMAIL PROTECTED]>
---
 drivers/scsi/arm/fas216.c |   16 +++-
 drivers/scsi/arm/fas216.h |3 +++
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index fb5f202..a715632 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2018,6 +2018,7 @@ static void fas216_rq_sns_done(FAS216_Info *info, struct 
scsi_cmnd *SCpnt,
 * the upper layers to process.  This would have been set
 * correctly by fas216_std_done.
 */
+   scsi_eh_restore_cmnd(SCpnt, &info->ses);
SCpnt->scsi_done(SCpnt);
 }
 
@@ -2103,23 +2104,12 @@ request_sense:
if (SCpnt->cmnd[0] == REQUEST_SENSE)
goto done;
 
+   scsi_eh_prep_cmnd(SCpnt, &info->ses, NULL, 0, ~0);
fas216_log_target(info, LOG_CONNECT, SCpnt->device->id,
  "requesting sense");
-   memset(SCpnt->cmnd, 0, sizeof (SCpnt->cmnd));
-   SCpnt->cmnd[0] = REQUEST_SENSE;
-   SCpnt->cmnd[1] = SCpnt->device->lun << 5;
-   SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
-   SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
-   SCpnt->SCp.buffer = NULL;
-   SCpnt->SCp.buffers_residual = 0;
-   SCpnt->SCp.ptr = (char *)SCpnt->sense_buffer;
-   SCpnt->SCp.this_residual = sizeof(SCpnt->sense_buffer);
-   SCpnt->SCp.phase = sizeof(SCpnt->sense_buffer);
+   init_SCp(SCpnt);
SCpnt->SCp.Message = 0;
SCpnt->SCp.Status = 0;
-   SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
-   SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-   SCpnt->use_sg = 0;
SCpnt->tag = 0;
SCpnt->host_scribble = (void *)fas216_rq_sns_done;
 
diff --git a/drivers/scsi/arm/fas216.h b/drivers/scsi/arm/fas216.h
index 00e5f05..3e73e26 100644
--- a/drivers/scsi/arm/fas216.h
+++ b/drivers/scsi/arm/fas216.h
@@ -16,6 +16,8 @@
 #define NO_IRQ 255
 #endif
 
+#include 
+
 #include "queue.h"
 #include "msgqueue.h"
 
@@ -311,6 +313,7 @@ typedef struct {
 
/* miscellaneous */
int internal_done;  /* flag to indicate 
request done */
+   struct scsi_eh_save *ses;   /* holds request sense restore 
info */
unsigned long   magic_end;
 } FAS216_Info;
 
-- 
1.5.3.1


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patchset 0/33] scsi_data_buffer for after the last driver is converted

2007-10-17 Thread Boaz Harrosh
This is a resend of all the remaining drivers rebased
to latest code. And once the entire tree is converted,
move to scsi_data_buffer in scsi_cmnd.

The work is on top of Jens's for-linus branch which
is effectively sglist-arch (+ last minute fixes)
This is because sglist-arch was already rebased to
latest scsi-misc through linus tree, merged with 
the extra work done there on scsi-ml (and the drivers)
(Thanks Jens)

summery of patches:

left over from scsi_eh last change
  [PATCH 01/32] arm: fas216 Use scsi_eh API for REQUEST_SENSE invocation

lots and lots of drivers left:
  [PATCH 02/32] isd200.c: use one-element sg list in issuing commands
  [PATCH 03/32] usb: transport - convert to accessors and !use_sg code path 
removal
  [PATCH 04/32] usb: protocol.c - convert to accessors and !use_sg code path 
removal
  [PATCH 05/32] usb: shuttle_usbat.c - convert to accessors and !use_sg code 
path removal
  [PATCH 06/32] usb: freecom.c & sddr09.c - convert to accessors and !use_sg 
cleanup
  [PATCH 07/32] NCR5380 familly convert to accessors & !use_sg cleanup
  [PATCH 08/32] arm: scsi convert to accessors and !use_sg cleanup
  [PATCH 09/32] nsp_cs.c convert to data accessors and !use_sg cleanup
  [PATCH 10/32] eata_pio.c: convert to accessors and !use_sg cleanup
  [PATCH 11/32] a2091.c: convert to accessors and !use_sg cleanup
  [PATCH 12/32] a3000.c: convert to accessors and !use_sg cleanup
  [PATCH 13/32] aha1542.c: convert to accessors and !use_sg cleanup
  [PATCH 14/32] atp870u.c: convert to accessors and !use_sg cleanup
  [PATCH 15/32] fd_mcs.c: convert to accessors and !use_sg cleanup
  [PATCH 16/32] imm.c: convert to accessors and !use_sg cleanup
  [PATCH 17/32] ppa.c: convert to accessors and !use_sg cleanup
  [PATCH 18/32] wd32c93.c: convert to accessors and !use_sg cleanup
  [PATCH 19/32] qlogicpti.c: convert to accessors and !use_sg cleanup
  [PATCH 20/32] in2000.c: convert to accessors and !use_sg cleanup
  [PATCH 21/32] scsi_debug: convert to use the data buffer accessors

Tomo's patch cleaned up:
   [PATCH 22/32] qla1280: convert to use the data buffer accessors
   [PATCH 23/32] qla1280: Indentation fix

 I separated the indentation from the real change make
 the patch humanly readable.

A small fix:
  [PATCH 24/32] wd7000.c - proper fix for boards without sg support
  
Remove broken drivers:
  [PATCH 25/32] Remove psi240i driver from kernel
  [PATCH 26/32] Remove of seagate.c driver
  (pluto/fc was removed by Matthew.)

Move to scsi_data_buffer:

  [PATCH 27/32] scsi_data_buffer
  [PATCH 28/32] scsi_data_buffer - scsi_error.c
  [PATCH 29/32] scsi_data_buffer - sd.c and sr.c
  [PATCH 30/32] tgt: convert to use scsi_data_buffer
  [PATCH 31/32] tgt: convert ibmvstgt and libsrp to use scsi_data_buffer
  [PATCH 32/32] isd200.c - use of scsi_data_buffer

 It used to be that the tgt was broken between scsi_data_buffer patch
 and the patch to tgt, because of the API change to scsi_alloc/free_sgtable().
 I have added a shim in scsi_tgt_lib.c so it can compile and run. The shim is 
 later removed in the tgt patch.

 Did I miss any maintainers in the To: fields?

Boaz


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch 3/7] qla2xxx printk fixes

2007-10-17 Thread Andrew Vasquez
On Tue, 16 Oct 2007, [EMAIL PROTECTED] wrote:

> From: Andrew Morton <[EMAIL PROTECTED]>
> 
> drivers/scsi/qla2xxx/qla_sup.c: In function 'qla24xx_write_flash_data':
> drivers/scsi/qla2xxx/qla_sup.c:655: warning: format '%llx' expects type 'long 
> long unsigned int', but argument 6 has type 'dma_addr_t'
> drivers/scsi/qla2xxx/qla_sup.c: In function 'qla25xx_read_optrom_data':
> drivers/scsi/qla2xxx/qla_sup.c:1853: warning: format '%llx' expects type 
> 'long long unsigned int', but argument 6 has type 'dma_addr_t'
> 
> Cc: James Bottomley <[EMAIL PROTECTED]>
> Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>

Acked-by: Andrew Vasquez <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Matthew Wilcox
On Wed, Oct 17, 2007 at 10:53:06AM -0400, Tony Battersby wrote:
> After looking at it carefully, this is true of pci_map_mem, but not
> pci_unmap_mem.  pci_unmap_mem can be called from both ->detect and
> ->release.  io_request_lock is held in ->detect but not in ->release.
> So, your patch locks up the system on module unload.

My mistake.  I should have checked the iorl was held over ->release too.

This is a pretty ugly patch, but I think the three alternatives are
worse:

 - Drop the iorl at the beginning of ->detect and reacquire it at exit.
   We don't know what else the iorl might be protecting.  Probably
   nothing, but I don't want to audit it.
 - Convert sym2 back to old error handling so the midlayer doesn't
   acquire the iorl for us in ->detect.
 - Acquire the iorl in ->release.  We might deadlock on something.

So, sure, apply this patch.

-- 
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."
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kill warnings in mptbase.h on parisc64

2007-10-17 Thread Kyle McMartin
Verified all the arches necessary select the CONFIG_64BIT symbol. This
also kills the warning (since it was using the 32-bit case) on parisc64
and mips64.

Signed-off-by: Kyle McMartin <[EMAIL PROTECTED]>

---
Index: linux-2.6/drivers/message/fusion/mptbase.h
===
--- linux-2.6.orig/drivers/message/fusion/mptbase.h 2007-10-12 
00:17:22.0 -0700
+++ linux-2.6/drivers/message/fusion/mptbase.h  2007-10-12 00:28:45.0 
-0700
@@ -890,7 +890,7 @@
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 #endif /* } __KERNEL__ */
 
-#if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || 
defined(__x86_64__) || defined(__powerpc__)
+#ifdef CONFIG_64BIT
 #define CAST_U32_TO_PTR(x) ((void *)(u64)x)
 #define CAST_PTR_TO_U32(x) ((u32)(u64)x)
 #else
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Tony Battersby
This patch fixes two problems with sym53c8xx_2.o in 2.4.x kernels:

1) A system hang when loading sym53c8xx_2.o on a SMP system with two
dual-channel LSI HBAs (http://bugzilla.kernel.org/show_bug.cgi?id=3680)

2) A function improperly marked __init.

Signed-off-by: Tony Battersby <[EMAIL PROTECTED]>
---
--- linux-2.4.35/drivers/scsi/sym53c8xx_2/sym_glue.c.orig   2007-10-17 
12:07:37.0 -0400
+++ linux-2.4.35/drivers/scsi/sym53c8xx_2/sym_glue.c2007-10-17 
12:08:32.0 -0400
@@ -224,15 +224,26 @@ static u_long __init pci_map_mem(u_long 
 {
u_long page_base= ((u_long) base) & PAGE_MASK;
u_long page_offs= ((u_long) base) - page_base;
-   u_long page_remapped= (u_long) ioremap(page_base, page_offs+size);
+   u_long page_remapped;
+
+   spin_unlock_irq(&io_request_lock);
+   page_remapped = (u_long) ioremap(page_base, page_offs+size);
+   spin_lock_irq(&io_request_lock);
 
return page_remapped? (page_remapped + page_offs) : 0UL;
 }
 
-static void __init pci_unmap_mem(u_long vaddr, u_long size)
-{
-   if (vaddr)
+static void pci_unmap_mem(u_long vaddr,
+  u_long size,
+  int holding_io_request_lock)
+{
+   if (vaddr) {
+   if (holding_io_request_lock)
+   spin_unlock_irq(&io_request_lock);
iounmap((void *) (vaddr & PAGE_MASK));
+   if (holding_io_request_lock)
+   spin_lock_irq(&io_request_lock);
+   }
 }
 #endif
 
@@ -1840,7 +1851,7 @@ static int sym53c8xx_proc_info(char *buf
 /*
  * Free controller resources.
  */
-static void sym_free_resources(hcb_p np)
+static void sym_free_resources(hcb_p np, int holding_io_request_lock)
 {
/*
 *  Free O/S specific resources.
@@ -1851,9 +1862,13 @@ static void sym_free_resources(hcb_p np)
release_region(np->s.io_port, np->s.io_ws);
 #ifndef SYM_OPT_NO_BUS_MEMORY_MAPPING
if (np->s.mmio_va)
-   pci_unmap_mem(np->s.mmio_va, np->s.io_ws);
+   pci_unmap_mem(np->s.mmio_va,
+ np->s.io_ws,
+ holding_io_request_lock);
if (np->s.ram_va)
-   pci_unmap_mem(np->s.ram_va, np->ram_ws);
+   pci_unmap_mem(np->s.ram_va,
+ np->ram_ws,
+ holding_io_request_lock);
 #endif
/*
 *  Free O/S independant resources.
@@ -2155,7 +2170,7 @@ attach_failed:
if (!instance) return -1;
printf_info("%s: giving up ...\n", sym_name(np));
if (np)
-   sym_free_resources(np);
+   sym_free_resources(np, 1);
scsi_unregister(instance);
 
 return -1;
@@ -2197,7 +2212,7 @@ static void __init sym_get_nvram(sym_dev
 #ifdef SYM_CONF_IOMAPPED
release_region(devp->s.io_port, 128);
 #else
-   pci_unmap_mem((u_long) devp->s.mmio_va, 128ul);
+   pci_unmap_mem((u_long) devp->s.mmio_va, 128ul, 1);
 #endif
 }
 #endif /* SYM_CONF_NVRAM_SUPPORT */
@@ -2551,7 +2566,7 @@ sym53c8xx_pci_init(Scsi_Host_Template *t
ram_ptr = pci_map_mem(base_2_c, ram_size);
if (ram_ptr) {
ram_val = readl_raw(ram_ptr + ram_size - 16);
-   pci_unmap_mem(ram_ptr, ram_size);
+   pci_unmap_mem(ram_ptr, ram_size, 1);
if (ram_val == 0x52414944) {
printf_info("%s: not initializing, "
"driven by RAID controller.\n",
@@ -2980,7 +2995,7 @@ static int sym_detach(hcb_p np)
/*
 *  Free host resources
 */
-   sym_free_resources(np);
+   sym_free_resources(np, 0);
 
return 1;
 }


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Willy Tarreau
On Wed, Oct 17, 2007 at 11:44:08AM -0400, Tony Battersby wrote:
> In 2.4, include/linux/init.h has the following:
> 
> #ifndef MODULE
> #define __init  __attribute__ ((__section__ (".text.init")))
> #else
> #define __init
> #endif
> 
> So __init has an effect only if it is built-in.

Ah yes, you're right.

> Apparently 2.6 also
> discards __init sections in modules after loading, but 2.4 doesn't.  Of
> course, it is still a bug.
> 
> Do you want me to redo the patch with __init taken out?

It would be better. As a general rule of thumb, an __init function should
not be called from a non __init, otherwise it is very hard to track the
call path.

Thanks,
Willy

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Willy Tarreau
On Wed, Oct 17, 2007 at 10:53:06AM -0400, Tony Battersby wrote:
> > So we should unconditionally drop the lock (and re-enable
> > interrupts) and re-acquire it.
> 
> After looking at it carefully, this is true of pci_map_mem, but not
> pci_unmap_mem.  pci_unmap_mem can be called from both ->detect and
> ->release.  io_request_lock is held in ->detect but not in ->release.
> So, your patch locks up the system on module unload.
> 
> I have put together and tested a new patch which does it correctly,
> while still trying to make only minimal changes.
> If you approve, this can go into the next 2.4.x release.

(...)

> -static void __init pci_unmap_mem(u_long vaddr, u_long size)
> -{
> - if (vaddr)
> +static void __init pci_unmap_mem(u_long vaddr,
> + u_long size,
> + int holding_io_request_lock)

This is marked __init, and pci_unmap_mem() is called from
sym_free_resources(), which in turn is called from sym_detach(),
called from sym53c8xx_release() when unloading module. So the section
may not be there anymore upon unload. I wonder how this can work right
now. I'm surely missing something :-/

Willy

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Tony Battersby
Willy Tarreau wrote:
> On Wed, Oct 17, 2007 at 10:53:06AM -0400, Tony Battersby wrote:
>   
>>> So we should unconditionally drop the lock (and re-enable
>>> interrupts) and re-acquire it.
>>>   
>> After looking at it carefully, this is true of pci_map_mem, but not
>> pci_unmap_mem.  pci_unmap_mem can be called from both ->detect and
>> ->release.  io_request_lock is held in ->detect but not in ->release.
>> So, your patch locks up the system on module unload.
>>
>> I have put together and tested a new patch which does it correctly,
>> while still trying to make only minimal changes.
>> If you approve, this can go into the next 2.4.x release.
>> 
>
> (...)
>
>   
>> -static void __init pci_unmap_mem(u_long vaddr, u_long size)
>> -{
>> -if (vaddr)
>> +static void __init pci_unmap_mem(u_long vaddr,
>> + u_long size,
>> + int holding_io_request_lock)
>> 
>
> This is marked __init, and pci_unmap_mem() is called from
> sym_free_resources(), which in turn is called from sym_detach(),
> called from sym53c8xx_release() when unloading module. So the section
> may not be there anymore upon unload. I wonder how this can work right
> now. I'm surely missing something :-/
>
> Willy
>   
In 2.4, include/linux/init.h has the following:

#ifndef MODULE
#define __init  __attribute__ ((__section__ (".text.init")))
#else
#define __init
#endif

So __init has an effect only if it is built-in.  Apparently 2.6 also
discards __init sections in modules after loading, but 2.4 doesn't.  Of
course, it is still a bug.

Do you want me to redo the patch with __init taken out?

Tony

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Bug 3680] sym53c8xx_2 SMP deadlock on driver load

2007-10-17 Thread Tony Battersby
> So we should unconditionally drop the lock (and re-enable
> interrupts) and re-acquire it.

After looking at it carefully, this is true of pci_map_mem, but not
pci_unmap_mem.  pci_unmap_mem can be called from both ->detect and
->release.  io_request_lock is held in ->detect but not in ->release.
So, your patch locks up the system on module unload.

I have put together and tested a new patch which does it correctly,
while still trying to make only minimal changes.
If you approve, this can go into the next 2.4.x release.

Signed-off-by: Tony Battersby <[EMAIL PROTECTED]>
---
--- linux-2.4.35/drivers/scsi/sym53c8xx_2/sym_glue.c.orig   2007-10-17 
10:16:07.0 -0400
+++ linux-2.4.35/drivers/scsi/sym53c8xx_2/sym_glue.c2007-10-17 
10:24:42.0 -0400
@@ -224,15 +224,26 @@ static u_long __init pci_map_mem(u_long 
 {
u_long page_base= ((u_long) base) & PAGE_MASK;
u_long page_offs= ((u_long) base) - page_base;
-   u_long page_remapped= (u_long) ioremap(page_base, page_offs+size);
+   u_long page_remapped;
+
+   spin_unlock_irq(&io_request_lock);
+   page_remapped = (u_long) ioremap(page_base, page_offs+size);
+   spin_lock_irq(&io_request_lock);
 
return page_remapped? (page_remapped + page_offs) : 0UL;
 }
 
-static void __init pci_unmap_mem(u_long vaddr, u_long size)
-{
-   if (vaddr)
+static void __init pci_unmap_mem(u_long vaddr,
+ u_long size,
+ int holding_io_request_lock)
+{
+   if (vaddr) {
+   if (holding_io_request_lock)
+   spin_unlock_irq(&io_request_lock);
iounmap((void *) (vaddr & PAGE_MASK));
+   if (holding_io_request_lock)
+   spin_lock_irq(&io_request_lock);
+   }
 }
 #endif
 
@@ -1840,7 +1851,7 @@ static int sym53c8xx_proc_info(char *buf
 /*
  * Free controller resources.
  */
-static void sym_free_resources(hcb_p np)
+static void sym_free_resources(hcb_p np, int holding_io_request_lock)
 {
/*
 *  Free O/S specific resources.
@@ -1851,9 +1862,13 @@ static void sym_free_resources(hcb_p np)
release_region(np->s.io_port, np->s.io_ws);
 #ifndef SYM_OPT_NO_BUS_MEMORY_MAPPING
if (np->s.mmio_va)
-   pci_unmap_mem(np->s.mmio_va, np->s.io_ws);
+   pci_unmap_mem(np->s.mmio_va,
+ np->s.io_ws,
+ holding_io_request_lock);
if (np->s.ram_va)
-   pci_unmap_mem(np->s.ram_va, np->ram_ws);
+   pci_unmap_mem(np->s.ram_va,
+ np->ram_ws,
+ holding_io_request_lock);
 #endif
/*
 *  Free O/S independant resources.
@@ -2155,7 +2170,7 @@ attach_failed:
if (!instance) return -1;
printf_info("%s: giving up ...\n", sym_name(np));
if (np)
-   sym_free_resources(np);
+   sym_free_resources(np, 1);
scsi_unregister(instance);
 
 return -1;
@@ -2197,7 +2212,7 @@ static void __init sym_get_nvram(sym_dev
 #ifdef SYM_CONF_IOMAPPED
release_region(devp->s.io_port, 128);
 #else
-   pci_unmap_mem((u_long) devp->s.mmio_va, 128ul);
+   pci_unmap_mem((u_long) devp->s.mmio_va, 128ul, 1);
 #endif
 }
 #endif /* SYM_CONF_NVRAM_SUPPORT */
@@ -2551,7 +2566,7 @@ sym53c8xx_pci_init(Scsi_Host_Template *t
ram_ptr = pci_map_mem(base_2_c, ram_size);
if (ram_ptr) {
ram_val = readl_raw(ram_ptr + ram_size - 16);
-   pci_unmap_mem(ram_ptr, ram_size);
+   pci_unmap_mem(ram_ptr, ram_size, 1);
if (ram_val == 0x52414944) {
printf_info("%s: not initializing, "
"driven by RAID controller.\n",
@@ -2980,7 +2995,7 @@ static int sym_detach(hcb_p np)
/*
 *  Free host resources
 */
-   sym_free_resources(np);
+   sym_free_resources(np, 0);
 
return 1;
 }



-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Add suspend/resume support for aic7xxx/aic79xx

2007-10-17 Thread Jeff Garzik

Hannes Reinecke wrote:

Hi James,

due to popular demand I've clobbered together a patch for
suspend/resume support in aic79xx/aic7xxx.

Looks reasonable enough, boots, but now I'd need someone
to actually test it :-)

As usual, comments, results, fixes, etc. welcome.


Looks good to me...  nice work.

Jeff



-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Add suspend/resume support for aic7xxx/aic79xx

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, Jens Axboe wrote:
> On Wed, Oct 17 2007, Hannes Reinecke wrote:
> > Hi James,
> > 
> > due to popular demand I've clobbered together a patch for
> > suspend/resume support in aic79xx/aic7xxx.
> > 
> > Looks reasonable enough, boots, but now I'd need someone
> > to actually test it :-)
> > 
> > As usual, comments, results, fixes, etc. welcome.
> 
> As it so happens, I run aic7xxx on my desktop. I'll give it a spin.

I just successfully suspended to disk (easy) AND suspended to ram on my
quad core workstation! To be honest, I don't know if this worked before
as I have never tried. But the disk is alive and doing well, so the
patch can get my:

Tested-by: Jens Axboe <[EMAIL PROTECTED]>

Unfortunately my video is crap after suspend to ram, so I'm typing this
ssh'ing into the machine. Perhaps some of the video options for s2ram
can help me out.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Add suspend/resume support for aic7xxx/aic79xx

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, Hannes Reinecke wrote:
> Hi James,
> 
> due to popular demand I've clobbered together a patch for
> suspend/resume support in aic79xx/aic7xxx.
> 
> Looks reasonable enough, boots, but now I'd need someone
> to actually test it :-)
> 
> As usual, comments, results, fixes, etc. welcome.

As it so happens, I run aic7xxx on my desktop. I'll give it a spin.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> > I think that it would be better that IOMMU code handles uninitialized
> > sg entries (sg list can be pretty large). Execpt for sparc64, the
> > IOMMU code can do, I think.
> 
> And I think that with this patch, sparc64 can handle it:
> 
> http://marc.info/?l=linux-scsi&m=119261920425120&w=2

I would tend to agree. Get davem to ack that patch, and we can move it
forward.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


SCSI target drivers?

2007-10-17 Thread Jeff Garzik

Where can one find patches/code that illustrates target mode support?

Marvell 6440 ("mvsas") supports target mode for both SAS and SATA, and I 
would like to prepare the driver as best I can for target mode.


Thanks,

Jeff


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Add suspend/resume support for aic7xxx/aic79xx

2007-10-17 Thread Hannes Reinecke
Hi James,

due to popular demand I've clobbered together a patch for
suspend/resume support in aic79xx/aic7xxx.

Looks reasonable enough, boots, but now I'd need someone
to actually test it :-)

As usual, comments, results, fixes, etc. welcome.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries & Storage
[EMAIL PROTECTED] +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)
aic7xxx: Add suspend/resume support

The existing code already had some fragments for suspend/resume
support, so it's actually quite straigtforward to implement it.

Signed-off-by: Hannes Reinecke <[EMAIL PROTECTED]>

diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index 27adbb2..f183c43 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -1003,8 +1003,16 @@ struct ahd_suspend_channel_state {
uint8_t seqctl;
 };
 
+struct ahd_suspend_pci_state {
+   uint32_t  devconfig;
+   uint16_t  targcrccnt;
+   uint8_t   command;
+   uint8_t   csize_lattime;
+};
+
 struct ahd_suspend_state {
struct  ahd_suspend_channel_state channel[2];
+   struct  ahd_suspend_pci_state pci_state;
uint8_t optionmode;
uint8_t dscommand0;
uint8_t dspcistatus;
@@ -1333,6 +1341,8 @@ structahd_pci_identity 
*ahd_find_pci_device(ahd_dev_softc_t);
 int  ahd_pci_config(struct ahd_softc *,
 struct ahd_pci_identity *);
 intahd_pci_test_register_access(struct ahd_softc *);
+void   ahd_pci_suspend(struct ahd_softc *);
+void   ahd_pci_resume(struct ahd_softc *);
 
 /** SCB and SCB queue management 
**/
 void   ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
@@ -1343,6 +1353,8 @@ struct ahd_softc  *ahd_alloc(void *platform_arg, char 
*name);
 int ahd_softc_init(struct ahd_softc *);
 voidahd_controller_info(struct ahd_softc *ahd, char *buf);
 int ahd_init(struct ahd_softc *ahd);
+int ahd_suspend(struct ahd_softc *ahd);
+voidahd_resume(struct ahd_softc *ahd);
 int ahd_default_config(struct ahd_softc *ahd);
 int ahd_parse_vpddata(struct ahd_softc *ahd,
   struct vpd_config *vpd);
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c 
b/drivers/scsi/aic7xxx/aic79xx_core.c
index 05f692b..a7dd8cd 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -7175,7 +7175,6 @@ ahd_pause_and_flushwork(struct ahd_softc *ahd)
ahd->flags &= ~AHD_ALL_INTERRUPTS;
 }
 
-#if 0
 int
 ahd_suspend(struct ahd_softc *ahd)
 {
@@ -7189,19 +7188,15 @@ ahd_suspend(struct ahd_softc *ahd)
ahd_shutdown(ahd);
return (0);
 }
-#endif  /*  0  */
 
-#if 0
-int
+void
 ahd_resume(struct ahd_softc *ahd)
 {
 
ahd_reset(ahd, /*reinit*/TRUE);
ahd_intr_enable(ahd, TRUE); 
ahd_restart(ahd);
-   return (0);
 }
-#endif  /*  0  */
 
 /** Busy Target Table 
*/
 /*
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c 
b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
index c62ce41..66f0259 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
@@ -50,6 +50,8 @@ static intahd_linux_pci_reserve_io_regions(struct 
ahd_softc *ahd,
 static int ahd_linux_pci_reserve_mem_region(struct ahd_softc *ahd,
 u_long *bus_addr,
 uint8_t __iomem **maddr);
+static int ahd_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t 
mesg);
+static int ahd_linux_pci_dev_resume(struct pci_dev *pdev);
 static voidahd_linux_pci_dev_remove(struct pci_dev *pdev);
 
 /* Define the macro locally since it's different for different class of chips.
@@ -86,10 +88,58 @@ MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
 static struct pci_driver aic79xx_pci_driver = {
.name   = "aic79xx",
.probe  = ahd_linux_pci_dev_probe,
+#ifdef CONFIG_PM
+   .suspend= ahd_linux_pci_dev_suspend,
+   .resume = ahd_linux_pci_dev_resume,
+#endif
.remove = ahd_linux_pci_dev_remove,
.id_table   = ahd_linux_pci_id_table
 };
 
+static int
+ahd_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
+{
+   struct ahd_softc *ahd = pci_get_drvdata(pdev);
+   int rc;
+
+   if ((rc = ahd_suspend(ahd)))
+   return rc;
+
+   ahd_pci_suspend(ahd);
+
+   pci_save_state(pdev);
+   pci_disable_device(pdev);
+
+   if (mesg.event == PM_EVENT_SUSPEND)
+   pci_set_power_state(pdev, PCI_D3hot);
+
+   return rc;
+}
+
+static int
+ahd_linux_pci_dev_resume(stru

[PATCH] qla1280: convert to use the data buffer accessors

2007-10-17 Thread FUJITA Tomonori
Any chance to send this for 2.6.24?

This is a data buffer accessor cleanup dependent on sg chaining. Now
it can cleanly applied to the latest Linus tree.


qla1280: convert to use the data buffer accessors

- remove the unnecessary map_single path.

- convert to use the new accessors for the sg lists and the parameters.

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
---
 drivers/scsi/qla1280.c |  376 
 1 files changed, 157 insertions(+), 219 deletions(-)

diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 76089cf..1744244 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1310,14 +1310,7 @@ qla1280_done(struct scsi_qla_host *ha)
}
 
/* Release memory used for this I/O */
-   if (cmd->use_sg) {
-   pci_unmap_sg(ha->pdev, cmd->request_buffer,
-   cmd->use_sg, cmd->sc_data_direction);
-   } else if (cmd->request_bufflen) {
-   pci_unmap_single(ha->pdev, sp->saved_dma_handle,
-   cmd->request_bufflen,
-   cmd->sc_data_direction);
-   }
+   scsi_dma_unmap(cmd);
 
/* Call the mid-level driver interrupt handler */
CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
@@ -1406,14 +1399,14 @@ qla1280_return_status(struct response * sts, struct 
scsi_cmnd *cp)
break;
 
case CS_DATA_UNDERRUN:
-   if ((cp->request_bufflen - residual_length) <
+   if ((scsi_bufflen(cp) - residual_length) <
cp->underflow) {
printk(KERN_WARNING
   "scsi: Underflow detected - retrying "
   "command.\n");
host_status = DID_ERROR;
} else {
-   cp->resid = residual_length;
+   scsi_set_resid(cp, residual_length);
host_status = DID_OK;
}
break;
@@ -2781,27 +2774,23 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
int status = 0;
int cnt;
int req_cnt;
-   u16 seg_cnt;
+   int seg_cnt;
u8 dir;
 
ENTER("qla1280_64bit_start_scsi:");
 
/* Calculate number of entries and segments required. */
req_cnt = 1;
-   if (cmd->use_sg) {
-   sg = (struct scatterlist *) cmd->request_buffer;
-   seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
-cmd->sc_data_direction);
-
+   seg_cnt = scsi_dma_map(cmd);
+   if (seg_cnt > 0) {
if (seg_cnt > 2) {
req_cnt += (seg_cnt - 2) / 5;
if ((seg_cnt - 2) % 5)
req_cnt++;
}
-   } else if (cmd->request_bufflen) {  /* If data transfer. */
-   seg_cnt = 1;
-   } else {
-   seg_cnt = 0;
+   } else if (seg_cnt < 0) {
+   status = 1;
+   goto out;
}
 
if ((req_cnt + 2) >= ha->req_q_cnt) {
@@ -2893,120 +2882,95 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
/* Setup packet address segment pointer. */
dword_ptr = (u32 *)&pkt->dseg_0_address;
 
-   if (cmd->use_sg) {  /* If scatter gather */
-   /* Load command entry data segments. */
-   for_each_sg(sg, s, seg_cnt, cnt) {
-   if (cnt == 2)
+   /* Load command entry data segments. */
+   for_each_sg(sg, s, seg_cnt, cnt) {
+   if (cnt == 2)
+   break;
+   dma_handle = sg_dma_address(s);
+#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
+   if (ha->flags.use_pci_vchannel)
+   sn_pci_set_vchan(ha->pdev,
+(unsigned long *)&dma_handle,
+SCSI_BUS_32(cmd));
+#endif
+   *dword_ptr++ =
+   cpu_to_le32(pci_dma_lo32(dma_handle));
+   *dword_ptr++ =
+   cpu_to_le32(pci_dma_hi32(dma_handle));
+   *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
+   dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
+   cpu_to_le32(pci_dma_hi32(dma_handle)),
+   cpu_to_le32(pci_dma_lo32(dma_handle)),
+   cpu_to_le32(sg_dma_len(sg_next(s;
+   remseg--;
+   }
+   dprintk(5, "qla1280_64bit_start_scsi: Scatte

Re: [patch 1/7] git-scsi-misc gdth fix

2007-10-17 Thread James Bottomley
On Tue, 2007-10-16 at 14:28 -0700, [EMAIL PROTECTED] wrote:
> From: James Bottomley <[EMAIL PROTECTED]>
> 
> On Sun, 2007-10-14 at 12:21 -0700, Andrew Morton wrote:
> > On Sun, 14 Oct 2007 22:45:47 +0400 "Dave Milter" <[EMAIL PROTECTED]> wrote:
> >
> > > I build linux-2.6.23-mm1 and try to boot it using qemu,
> > > and it crashed with trace like this:
> > > do_page_fault
> > > error_code
> > > lock_acquire
> > > _spin_lock_irqsave
> > > gdth_timeout
> > > run_timer_softirq
> > > __do_softirq
> > > do_softirq
> > >
> > > I have screenshot, but have no idea, is it legal to include it, if I
> > > sent copy to lkml.
> > > config of kernel in attachment,
> > > I apply all three patches from hot-fixes.
> > >
> >
> > The screenshot is here:  http://userweb.kernel.org/~akpm/crash.png
> >
> > It would appear that gdth_timeout() is passing a bad pointer into
> > spin_lock_irqsave().
> 
> There's a bug in the gdth rework in that the instance can be deleted
> from the list before the actual timer is stopped.  This can be worked
> around I think by the following patch; although we really should be
> stopping the timer from firing when the list goes empty.
> 
> 
> 
> Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
> ---
> 
>  drivers/scsi/gdth.c |3 +++
>  1 file changed, 3 insertions(+)
> 
> diff -puN drivers/scsi/gdth.c~git-scsi-misc-gdth-fix drivers/scsi/gdth.c
> --- a/drivers/scsi/gdth.c~git-scsi-misc-gdth-fix
> +++ a/drivers/scsi/gdth.c
> @@ -3793,6 +3793,9 @@ static void gdth_timeout(ulong data)
>  gdth_ha_str *ha;
>  ulong flags;
>  
> +if (list_empty(&gdth_instances))
> + return;
> +
>  ha = list_first_entry(&gdth_instances, gdth_ha_str, list);
>  spin_lock_irqsave(&ha->smp_lock, flags);
>  

This is almost certainly the wrong fix for real hardware.  Although it
kills the timer when the list goes empty, nothing will ever restart it
when the list fills again.

Boaz, since you touched all of this, you get to fix it.  The correct fix
will be to control the timer along with the actual list instead of at
entry/exit time.  If you're not going to add this empty check to the
timer routine, make sure you use del_timer_sync() before removing the
last element from the list.

James


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [GIT PATCH] SCSI updates for 2.6.24

2007-10-17 Thread James Bottomley
On Wed, 2007-10-17 at 13:20 +0900, FUJITA Tomonori wrote:
> On Mon, 15 Oct 2007 00:09:41 -0400
> James Bottomley <[EMAIL PROTECTED]> wrote:
> 
> > This is the accumulated updates queued for 2.6.24.  It contains the
> > usual slew of driver updates, plus some gdth and advansys rewrites.  We
> > still have some outstanding bugs in gdth and fc4 for which I'm hoping to
> > sweep fixes into the next update.
> > 
> > The patch is available here:
> > 
> > master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
> > 
> > The short changelog is:
> 
> (snip)
> 
> > James Bottomley (4):
> >   Fix device not ready printk
> >   sg: use idr to replace static arrays
> >   move ULD attachment into the prep function
> >   arcmsr: fix compile problems
> 
> The patch to beautify supported_mode and active_mode in sysfs?
> 
> http://marc.info/?l=linux-kernel&m=119077857701415&w=2

Well, I suppose losing your own patches is a sign of fairness in patch
loss ... OK I'll stick them in.

James


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 20:57:17 +0900
FUJITA Tomonori <[EMAIL PROTECTED]> wrote:

> On Wed, 17 Oct 2007 13:41:17 +0200
> Jens Axboe <[EMAIL PROTECTED]> wrote:
> 
> > On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> > > On Wed, 17 Oct 2007 13:01:42 +0200
> > > Jens Axboe <[EMAIL PROTECTED]> wrote:
> > > 
> > > > On Wed, Oct 17 2007, Jens Axboe wrote:
> > > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > > > > > 
> > > > > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > > > > > 
> > > > > > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > > > > > 
> > > > > > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > > > > > transformation in the sparc64 sg chaining patch is not 
> > > > > > > > equilavent:
> > > > > > > > 
> > > > > > > > -   struct scatterlist *sg_end = sg + nelems;
> > > > > > > > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> > > > > > > >  ...
> > > > > > > > -   while (sg < sg_end &&
> > > > > > > > +   while (sg != sg_end &&
> > > > > > > 
> > > > > > > Auch indeed. That'd probably be better as a
> > > > > > > 
> > > > > > > do {
> > > > > > > ...
> > > > > > > } while (sg != sg_end);
> > > > > > 
> > > > > > Ok, next bug, introduced by this change:
> > > > > > 
> > > > > > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > > > > > Author: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > Date:   Fri Sep 21 10:44:19 2007 +0200
> > > > > > 
> > > > > > block: convert to using sg helpers
> > > > > > 
> > > > > > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper 
> > > > > > setup.
> > > > > > 
> > > > > > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > 
> > > > > > Specifically this part:
> > > > > > 
> > > > > >  new_segment:
> > > > > > -   memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > > > > > -   sg[nsegs].page = bvec->bv_page;
> > > > > > -   sg[nsegs].length = nbytes;
> > > > > > -   sg[nsegs].offset = bvec->bv_offset;
> > > > > > +   sg = next_sg;
> > > > > > +   next_sg = sg_next(sg);
> > > > > >  
> > > > > > +   sg->page = bvec->bv_page;
> > > > > > +   sg->length = nbytes;
> > > > > > +   sg->offset = bvec->bv_offset;
> > > > > > 
> > > > > > You can't remove that memset(), it's there for a reason.  The IOMMU
> > > > > > layers depended upon the code zero'ing out the whole scatterlist
> > > > > > struct, there might be more to it than page, length and offset :-)
> > > > > 
> > > > > I realize that, and I was pretty worried about this specific change. 
> > > > > But
> > > > > there's only been one piece of fallout because if it until now - well
> > > > > two, with the sparc64 stuff.
> > > > > 
> > > > > The problem is that you cannot zero the entire sg entry, because then
> > > > > you'd potentially overwrite the chain pointer.
> > > > > 
> > > > > I'd propose just adding a
> > > > > 
> > > > > sg_dma_address(sg) = 0;
> > > > > sg_dma_len(sg) = 0;
> > > > > 
> > > > > there for now, or provide an arch_clear_sg_entry() helper if we need
> > > > > more killed.
> > > > 
> > > > Actually, just clearing AFTER sg_next() would be fine, since we know
> > > > that is not a link entry. Duh...
> > > > 
> > > > diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
> > > > index 9eabac9..1014d34 100644
> > > > --- a/block/ll_rw_blk.c
> > > > +++ b/block/ll_rw_blk.c
> > > > @@ -1352,6 +1352,7 @@ new_segment:
> > > > sg = next_sg;
> > > > next_sg = sg_next(sg);
> > > >  
> > > > +   memset(sg, 0, sizeof(*sg));
> > > > sg->page = bvec->bv_page;
> > > > sg->length = nbytes;
> > > > sg->offset = bvec->bv_offset;
> > > > 
> > > > -- 
> > > 
> > > So now how about removing zero'ing out sglist in scsi-ml?
> > > 
> > > 
> > > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> > > index aac8a02..0c86be7 100644
> > > --- a/drivers/scsi/scsi_lib.c
> > > +++ b/drivers/scsi/scsi_lib.c
> > > @@ -764,8 +764,6 @@ struct scatterlist *scsi_alloc_sgtable(struct 
> > > scsi_cmnd *cmd, gfp_t gfp_mask)
> > >   if (unlikely(!sgl))
> > >   goto enomem;
> > >  
> > > - memset(sgl, 0, sizeof(*sgl) * sgp->size);
> > > -
> > >   /*
> > >* first loop through, set initial index and return value
> > >*/
> > 
> > Sure, that should be quite alright then. I'll add it.
> 
> Thanks, it would be. Before sg chaining, scsi-ml didn't zero out.

Oops, it should be.


> I think that it would be 

Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 13:41:17 +0200
Jens Axboe <[EMAIL PROTECTED]> wrote:

> On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> > On Wed, 17 Oct 2007 13:01:42 +0200
> > Jens Axboe <[EMAIL PROTECTED]> wrote:
> > 
> > > On Wed, Oct 17 2007, Jens Axboe wrote:
> > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > > > > 
> > > > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > > > > 
> > > > > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > > > > 
> > > > > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > > > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > > > > > 
> > > > > > > - struct scatterlist *sg_end = sg + nelems;
> > > > > > > + struct scatterlist *sg_end = sg_last(sg, nelems);
> > > > > > >  ...
> > > > > > > - while (sg < sg_end &&
> > > > > > > + while (sg != sg_end &&
> > > > > > 
> > > > > > Auch indeed. That'd probably be better as a
> > > > > > 
> > > > > > do {
> > > > > > ...
> > > > > > } while (sg != sg_end);
> > > > > 
> > > > > Ok, next bug, introduced by this change:
> > > > > 
> > > > > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > > > > Author: Jens Axboe <[EMAIL PROTECTED]>
> > > > > Date:   Fri Sep 21 10:44:19 2007 +0200
> > > > > 
> > > > > block: convert to using sg helpers
> > > > > 
> > > > > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper 
> > > > > setup.
> > > > > 
> > > > > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > > > > 
> > > > > Specifically this part:
> > > > > 
> > > > >  new_segment:
> > > > > - memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > > > > - sg[nsegs].page = bvec->bv_page;
> > > > > - sg[nsegs].length = nbytes;
> > > > > - sg[nsegs].offset = bvec->bv_offset;
> > > > > + sg = next_sg;
> > > > > + next_sg = sg_next(sg);
> > > > >  
> > > > > + sg->page = bvec->bv_page;
> > > > > + sg->length = nbytes;
> > > > > + sg->offset = bvec->bv_offset;
> > > > > 
> > > > > You can't remove that memset(), it's there for a reason.  The IOMMU
> > > > > layers depended upon the code zero'ing out the whole scatterlist
> > > > > struct, there might be more to it than page, length and offset :-)
> > > > 
> > > > I realize that, and I was pretty worried about this specific change. But
> > > > there's only been one piece of fallout because if it until now - well
> > > > two, with the sparc64 stuff.
> > > > 
> > > > The problem is that you cannot zero the entire sg entry, because then
> > > > you'd potentially overwrite the chain pointer.
> > > > 
> > > > I'd propose just adding a
> > > > 
> > > > sg_dma_address(sg) = 0;
> > > > sg_dma_len(sg) = 0;
> > > > 
> > > > there for now, or provide an arch_clear_sg_entry() helper if we need
> > > > more killed.
> > > 
> > > Actually, just clearing AFTER sg_next() would be fine, since we know
> > > that is not a link entry. Duh...
> > > 
> > > diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
> > > index 9eabac9..1014d34 100644
> > > --- a/block/ll_rw_blk.c
> > > +++ b/block/ll_rw_blk.c
> > > @@ -1352,6 +1352,7 @@ new_segment:
> > >   sg = next_sg;
> > >   next_sg = sg_next(sg);
> > >  
> > > + memset(sg, 0, sizeof(*sg));
> > >   sg->page = bvec->bv_page;
> > >   sg->length = nbytes;
> > >   sg->offset = bvec->bv_offset;
> > > 
> > > -- 
> > 
> > So now how about removing zero'ing out sglist in scsi-ml?
> > 
> > 
> > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> > index aac8a02..0c86be7 100644
> > --- a/drivers/scsi/scsi_lib.c
> > +++ b/drivers/scsi/scsi_lib.c
> > @@ -764,8 +764,6 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd 
> > *cmd, gfp_t gfp_mask)
> > if (unlikely(!sgl))
> > goto enomem;
> >  
> > -   memset(sgl, 0, sizeof(*sgl) * sgp->size);
> > -
> > /*
> >  * first loop through, set initial index and return value
> >  */
> 
> Sure, that should be quite alright then. I'll add it.

Thanks, it would be. Before sg chaining, scsi-ml didn't zero out.

I think that it would be better that IOMMU code handles uninitialized
sg entries (sg list can be pretty large). Execpt for sparc64, the
IOMMU code can do, I think.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> On Wed, 17 Oct 2007 13:01:42 +0200
> Jens Axboe <[EMAIL PROTECTED]> wrote:
> 
> > On Wed, Oct 17 2007, Jens Axboe wrote:
> > > On Wed, Oct 17 2007, David Miller wrote:
> > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > > > 
> > > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > > > 
> > > > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > > > 
> > > > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > > > > 
> > > > > > -   struct scatterlist *sg_end = sg + nelems;
> > > > > > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> > > > > >  ...
> > > > > > -   while (sg < sg_end &&
> > > > > > +   while (sg != sg_end &&
> > > > > 
> > > > > Auch indeed. That'd probably be better as a
> > > > > 
> > > > > do {
> > > > > ...
> > > > > } while (sg != sg_end);
> > > > 
> > > > Ok, next bug, introduced by this change:
> > > > 
> > > > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > > > Author: Jens Axboe <[EMAIL PROTECTED]>
> > > > Date:   Fri Sep 21 10:44:19 2007 +0200
> > > > 
> > > > block: convert to using sg helpers
> > > > 
> > > > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
> > > > 
> > > > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > > > 
> > > > Specifically this part:
> > > > 
> > > >  new_segment:
> > > > -   memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > > > -   sg[nsegs].page = bvec->bv_page;
> > > > -   sg[nsegs].length = nbytes;
> > > > -   sg[nsegs].offset = bvec->bv_offset;
> > > > +   sg = next_sg;
> > > > +   next_sg = sg_next(sg);
> > > >  
> > > > +   sg->page = bvec->bv_page;
> > > > +   sg->length = nbytes;
> > > > +   sg->offset = bvec->bv_offset;
> > > > 
> > > > You can't remove that memset(), it's there for a reason.  The IOMMU
> > > > layers depended upon the code zero'ing out the whole scatterlist
> > > > struct, there might be more to it than page, length and offset :-)
> > > 
> > > I realize that, and I was pretty worried about this specific change. But
> > > there's only been one piece of fallout because if it until now - well
> > > two, with the sparc64 stuff.
> > > 
> > > The problem is that you cannot zero the entire sg entry, because then
> > > you'd potentially overwrite the chain pointer.
> > > 
> > > I'd propose just adding a
> > > 
> > > sg_dma_address(sg) = 0;
> > > sg_dma_len(sg) = 0;
> > > 
> > > there for now, or provide an arch_clear_sg_entry() helper if we need
> > > more killed.
> > 
> > Actually, just clearing AFTER sg_next() would be fine, since we know
> > that is not a link entry. Duh...
> > 
> > diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
> > index 9eabac9..1014d34 100644
> > --- a/block/ll_rw_blk.c
> > +++ b/block/ll_rw_blk.c
> > @@ -1352,6 +1352,7 @@ new_segment:
> > sg = next_sg;
> > next_sg = sg_next(sg);
> >  
> > +   memset(sg, 0, sizeof(*sg));
> > sg->page = bvec->bv_page;
> > sg->length = nbytes;
> > sg->offset = bvec->bv_offset;
> > 
> > -- 
> 
> So now how about removing zero'ing out sglist in scsi-ml?
> 
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index aac8a02..0c86be7 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -764,8 +764,6 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd 
> *cmd, gfp_t gfp_mask)
>   if (unlikely(!sgl))
>   goto enomem;
>  
> - memset(sgl, 0, sizeof(*sgl) * sgp->size);
> -
>   /*
>* first loop through, set initial index and return value
>*/

Sure, that should be quite alright then. I'll add it.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 13:01:42 +0200
Jens Axboe <[EMAIL PROTECTED]> wrote:

> On Wed, Oct 17 2007, Jens Axboe wrote:
> > On Wed, Oct 17 2007, David Miller wrote:
> > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > > 
> > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > > 
> > > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > > 
> > > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > > > 
> > > > > - struct scatterlist *sg_end = sg + nelems;
> > > > > + struct scatterlist *sg_end = sg_last(sg, nelems);
> > > > >  ...
> > > > > - while (sg < sg_end &&
> > > > > + while (sg != sg_end &&
> > > > 
> > > > Auch indeed. That'd probably be better as a
> > > > 
> > > > do {
> > > > ...
> > > > } while (sg != sg_end);
> > > 
> > > Ok, next bug, introduced by this change:
> > > 
> > > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > > Author: Jens Axboe <[EMAIL PROTECTED]>
> > > Date:   Fri Sep 21 10:44:19 2007 +0200
> > > 
> > > block: convert to using sg helpers
> > > 
> > > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
> > > 
> > > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > > 
> > > Specifically this part:
> > > 
> > >  new_segment:
> > > - memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > > - sg[nsegs].page = bvec->bv_page;
> > > - sg[nsegs].length = nbytes;
> > > - sg[nsegs].offset = bvec->bv_offset;
> > > + sg = next_sg;
> > > + next_sg = sg_next(sg);
> > >  
> > > + sg->page = bvec->bv_page;
> > > + sg->length = nbytes;
> > > + sg->offset = bvec->bv_offset;
> > > 
> > > You can't remove that memset(), it's there for a reason.  The IOMMU
> > > layers depended upon the code zero'ing out the whole scatterlist
> > > struct, there might be more to it than page, length and offset :-)
> > 
> > I realize that, and I was pretty worried about this specific change. But
> > there's only been one piece of fallout because if it until now - well
> > two, with the sparc64 stuff.
> > 
> > The problem is that you cannot zero the entire sg entry, because then
> > you'd potentially overwrite the chain pointer.
> > 
> > I'd propose just adding a
> > 
> > sg_dma_address(sg) = 0;
> > sg_dma_len(sg) = 0;
> > 
> > there for now, or provide an arch_clear_sg_entry() helper if we need
> > more killed.
> 
> Actually, just clearing AFTER sg_next() would be fine, since we know
> that is not a link entry. Duh...
> 
> diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
> index 9eabac9..1014d34 100644
> --- a/block/ll_rw_blk.c
> +++ b/block/ll_rw_blk.c
> @@ -1352,6 +1352,7 @@ new_segment:
>   sg = next_sg;
>   next_sg = sg_next(sg);
>  
> + memset(sg, 0, sizeof(*sg));
>   sg->page = bvec->bv_page;
>   sg->length = nbytes;
>   sg->offset = bvec->bv_offset;
> 
> -- 

So now how about removing zero'ing out sglist in scsi-ml?


diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index aac8a02..0c86be7 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -764,8 +764,6 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd 
*cmd, gfp_t gfp_mask)
if (unlikely(!sgl))
goto enomem;
 
-   memset(sgl, 0, sizeof(*sgl) * sgp->size);
-
/*
 * first loop through, set initial index and return value
 */
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, David Miller wrote:
> From: Jens Axboe <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 13:11:46 +0200
> 
> > On Wed, Oct 17 2007, David Miller wrote:
> > > Jens, please also add the following on top of Fujita-san's most recent
> > > sparc64 patch and we should be good to go.
> > 
> > Awesome, thanks. And sorry for messing up sparc64.
> 
> Don't worry, I'll keep breaking your network interfaces
> just to keep things even :-)

It's a deal - I think I'm ahead so far, so I promise to smile politely
when/if my networking craps out :)

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: Jens Axboe <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 13:11:46 +0200

> On Wed, Oct 17 2007, David Miller wrote:
> > Jens, please also add the following on top of Fujita-san's most recent
> > sparc64 patch and we should be good to go.
> 
> Awesome, thanks. And sorry for messing up sparc64.

Don't worry, I'll keep breaking your network interfaces
just to keep things even :-)
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, Jens Axboe wrote:
> On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> > On Wed, 17 Oct 2007 02:45:47 -0700 (PDT)
> > David Miller <[EMAIL PROTECTED]> wrote:
> > 
> > > From: FUJITA Tomonori <[EMAIL PROTECTED]>
> > > Date: Wed, 17 Oct 2007 18:24:01 +0900
> > > 
> > > > On Wed, 17 Oct 2007 11:16:29 +0200
> > > > Jens Axboe <[EMAIL PROTECTED]> wrote:
> > > > 
> > > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > > I would suggest that other sg_last() uses be audited for the same 
> > > > > > bug.
> > > > > 
> > > > > Agree.
> > > > 
> > > > Only libata, I think.
> > > 
> > > There are a few other spots, like ide-scsi
> > 
> > Oops, I missed that. But seems that we have only three, ide-scsi,
> > libata, sparc64 iommu.
> 
> And now only ide-scsi and libata, Dave killed sg_last() in sparc64
> already. So less than I remember, I'd say kill it NOW...

libata remains.

diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index bd74f6c..fa7ba64 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -70,7 +70,7 @@ typedef struct idescsi_pc_s {
u8 *buffer; /* Data buffer */
u8 *current_position;   /* Pointer into the above 
buffer */
struct scatterlist *sg; /* Scatter gather table */
-   struct scatterlist *last_sg;/* Last sg element */
+   unsigned int sg_cnt;/* Number of entries in sg */
int b_count;/* Bytes transferred from 
current entry */
struct scsi_cmnd *scsi_cmd; /* SCSI command */
void (*done)(struct scsi_cmnd *);   /* Scsi completion routine */
@@ -192,7 +192,7 @@ static void idescsi_input_buffers (ide_drive_t *drive, 
idescsi_pc_t *pc, unsigne
}
bcount -= count; pc->b_count += count;
if (pc->b_count == pc->sg->length) {
-   if (pc->sg == pc->last_sg)
+   if (!--pc->sg_cnt)
break;
pc->sg = sg_next(pc->sg);
pc->b_count = 0;
@@ -229,7 +229,7 @@ static void idescsi_output_buffers (ide_drive_t *drive, 
idescsi_pc_t *pc, unsign
}
bcount -= count; pc->b_count += count;
if (pc->b_count == pc->sg->length) {
-   if (pc->sg == pc->last_sg)
+   if (!--pc->sg_cnt)
break;
pc->sg = sg_next(pc->sg);
pc->b_count = 0;
@@ -807,7 +807,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
pc->buffer = NULL;
pc->sg = scsi_sglist(cmd);
-   pc->last_sg = sg_last(pc->sg, scsi_sg_count(cmd));
+   pc->sg_cnt = scsi_sg_count(cmd);
pc->b_count = 0;
pc->request_transfer = pc->buffer_size = scsi_bufflen(cmd);
pc->scsi_cmd = cmd;

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> On Wed, 17 Oct 2007 02:45:47 -0700 (PDT)
> David Miller <[EMAIL PROTECTED]> wrote:
> 
> > From: FUJITA Tomonori <[EMAIL PROTECTED]>
> > Date: Wed, 17 Oct 2007 18:24:01 +0900
> > 
> > > On Wed, 17 Oct 2007 11:16:29 +0200
> > > Jens Axboe <[EMAIL PROTECTED]> wrote:
> > > 
> > > > On Wed, Oct 17 2007, David Miller wrote:
> > > > > I would suggest that other sg_last() uses be audited for the same bug.
> > > > 
> > > > Agree.
> > > 
> > > Only libata, I think.
> > 
> > There are a few other spots, like ide-scsi
> 
> Oops, I missed that. But seems that we have only three, ide-scsi,
> libata, sparc64 iommu.

And now only ide-scsi and libata, Dave killed sg_last() in sparc64
already. So less than I remember, I'd say kill it NOW...

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, David Miller wrote:
> From: Jens Axboe <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 13:01:42 +0200
> 
> > Actually, just clearing AFTER sg_next() would be fine, since we know
> > that is not a link entry. Duh...
> 
> Yes and I'm running a kernel successfully with this fix.

Great!

> Jens, please also add the following on top of Fujita-san's most recent
> sparc64 patch and we should be good to go.

Awesome, thanks. And sorry for messing up sparc64.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: Jens Axboe <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 13:01:42 +0200

> Actually, just clearing AFTER sg_next() would be fine, since we know
> that is not a link entry. Duh...

Yes and I'm running a kernel successfully with this fix.

Jens, please also add the following on top of Fujita-san's most recent
sparc64 patch and we should be good to go.

>From 0f6e2c3085ec57df78b249a8722323692f33a1b2 Mon Sep 17 00:00:00 2001
From: David S. Miller <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 04:08:48 -0700
Subject: [PATCH] [SPARC64]: Fix loop terminating conditions in fill_sg().

Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
---
 arch/sparc64/kernel/iommu.c |   12 +++-
 arch/sparc64/kernel/pci_sun4v.c |   15 ---
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/sparc64/kernel/iommu.c b/arch/sparc64/kernel/iommu.c
index 5d4e96d..29af777 100644
--- a/arch/sparc64/kernel/iommu.c
+++ b/arch/sparc64/kernel/iommu.c
@@ -475,12 +475,11 @@ static void dma_4u_unmap_single(struct device *dev, 
dma_addr_t bus_addr,
 #define SG_ENT_PHYS_ADDRESS(SG)\
(__pa(page_address((SG)->page)) + (SG)->offset)
 
-static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
-  int nused, int nelems,
-  unsigned long iopte_protection)
+static void fill_sg(iopte_t *iopte, struct scatterlist *sg,
+   int nused, int nelems,
+   unsigned long iopte_protection)
 {
struct scatterlist *dma_sg = sg;
-   struct scatterlist *sg_end = sg_last(sg, nelems);
int i;
 
for (i = 0; i < nused; i++) {
@@ -516,6 +515,7 @@ static inline void fill_sg(iopte_t *iopte, struct 
scatterlist *sg,
break;
}
sg = sg_next(sg);
+   nelems--;
}
 
pteval = iopte_protection | (pteval & IOPTE_PAGE);
@@ -529,18 +529,20 @@ static inline void fill_sg(iopte_t *iopte, struct 
scatterlist *sg,
 
pteval = (pteval & IOPTE_PAGE) + len;
sg = sg_next(sg);
+   nelems--;
 
/* Skip over any tail mappings we've fully mapped,
 * adjusting pteval along the way.  Stop when we
 * detect a page crossing event.
 */
-   while (sg != sg_end &&
+   while (nelems &&
   (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
   (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
   ((pteval ^
 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) 
>> IO_PAGE_SHIFT) == 0UL) {
pteval += sg->length;
sg = sg_next(sg);
+   nelems--;
}
if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
pteval = ~0UL;
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index 119f8ef..fe46ace 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -368,12 +368,11 @@ static void dma_4v_unmap_single(struct device *dev, 
dma_addr_t bus_addr,
 #define SG_ENT_PHYS_ADDRESS(SG)\
(__pa(page_address((SG)->page)) + (SG)->offset)
 
-static inline long fill_sg(long entry, struct device *dev,
-  struct scatterlist *sg,
-  int nused, int nelems, unsigned long prot)
+static long fill_sg(long entry, struct device *dev,
+   struct scatterlist *sg,
+   int nused, int nelems, unsigned long prot)
 {
struct scatterlist *dma_sg = sg;
-   struct scatterlist *sg_end = sg_last(sg, nelems);
unsigned long flags;
int i;
 
@@ -414,6 +413,7 @@ static inline long fill_sg(long entry, struct device *dev,
break;
}
sg = sg_next(sg);
+   nelems--;
}
 
pteval = (pteval & IOPTE_PAGE);
@@ -432,19 +432,20 @@ static inline long fill_sg(long entry, struct device *dev,
 
pteval = (pteval & IOPTE_PAGE) + len;
sg = sg_next(sg);
+   nelems--;
 
/* Skip over any tail mappings we've fully mapped,
 * adjusting pteval along the way.  Stop when we
 * detect a page crossing event.
 */
-   while ((pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
+   while (nelems &&
+  (pteval << (64 - IO_PAGE_SHIFT)) != 0

Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 02:45:47 -0700 (PDT)
David Miller <[EMAIL PROTECTED]> wrote:

> From: FUJITA Tomonori <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 18:24:01 +0900
> 
> > On Wed, 17 Oct 2007 11:16:29 +0200
> > Jens Axboe <[EMAIL PROTECTED]> wrote:
> > 
> > > On Wed, Oct 17 2007, David Miller wrote:
> > > > I would suggest that other sg_last() uses be audited for the same bug.
> > > 
> > > Agree.
> > 
> > Only libata, I think.
> 
> There are a few other spots, like ide-scsi

Oops, I missed that. But seems that we have only three, ide-scsi,
libata, sparc64 iommu.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 12:58:40 +0200
Jens Axboe <[EMAIL PROTECTED]> wrote:

> On Wed, Oct 17 2007, David Miller wrote:
> > From: Jens Axboe <[EMAIL PROTECTED]>
> > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > 
> > > On Wed, Oct 17 2007, David Miller wrote:
> > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > 
> > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > 
> > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > > 
> > > > -   struct scatterlist *sg_end = sg + nelems;
> > > > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> > > >  ...
> > > > -   while (sg < sg_end &&
> > > > +   while (sg != sg_end &&
> > > 
> > > Auch indeed. That'd probably be better as a
> > > 
> > > do {
> > > ...
> > > } while (sg != sg_end);
> > 
> > Ok, next bug, introduced by this change:
> > 
> > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > Author: Jens Axboe <[EMAIL PROTECTED]>
> > Date:   Fri Sep 21 10:44:19 2007 +0200
> > 
> > block: convert to using sg helpers
> > 
> > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
> > 
> > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > 
> > Specifically this part:
> > 
> >  new_segment:
> > -   memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > -   sg[nsegs].page = bvec->bv_page;
> > -   sg[nsegs].length = nbytes;
> > -   sg[nsegs].offset = bvec->bv_offset;
> > +   sg = next_sg;
> > +   next_sg = sg_next(sg);
> >  
> > +   sg->page = bvec->bv_page;
> > +   sg->length = nbytes;
> > +   sg->offset = bvec->bv_offset;
> > 
> > You can't remove that memset(), it's there for a reason.  The IOMMU
> > layers depended upon the code zero'ing out the whole scatterlist
> > struct, there might be more to it than page, length and offset :-)
> 
> I realize that, and I was pretty worried about this specific change. But
> there's only been one piece of fallout because if it until now - well
> two, with the sparc64 stuff.
> 
> The problem is that you cannot zero the entire sg entry, because then
> you'd potentially overwrite the chain pointer.
> 
> I'd propose just adding a
> 
> sg_dma_address(sg) = 0;
> sg_dma_len(sg) = 0;
> 
> there for now, or provide an arch_clear_sg_entry() helper if we need
> more killed.

Except for sparc64, the IOMMU implementations do something like this,
I think.

-
sparc64: zero out dma_length

zero out dma_length in the entry immediately following the last mapped
entry for unmap_sg.

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
---
 arch/sparc64/kernel/iommu_common.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/sparc64/kernel/iommu_common.c 
b/arch/sparc64/kernel/iommu_common.c
index d7ca900..836455d 100644
--- a/arch/sparc64/kernel/iommu_common.c
+++ b/arch/sparc64/kernel/iommu_common.c
@@ -234,6 +234,11 @@ unsigned long prepare_sg(struct scatterlist *sg, int nents)
dma_sg->dma_address = dent_addr;
dma_sg->dma_length = dent_len;
 
+   if (dma_sg != sg) {
+   dma_sg = next_sg(dma_sg);
+   dma_sg->dma_length = 0;
+   }
+
return ((unsigned long) dent_addr +
(unsigned long) dent_len +
(IO_PAGE_SIZE - 1UL)) >> IO_PAGE_SHIFT;
-- 
1.5.2.4


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: Jens Axboe <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 12:58:40 +0200

> The problem is that you cannot zero the entire sg entry, because then
> you'd potentially overwrite the chain pointer.
> 
> I'd propose just adding a
> 
> sg_dma_address(sg) = 0;
> sg_dma_len(sg) = 0;
> 
> there for now, or provide an arch_clear_sg_entry() helper if we need
> more killed.

The "chain pointer" is indicated by an sg->page with the low
bit set, but we're explicitly initializing it here to a
non-chain page pointer value.

What's the problem?
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, David Miller wrote:
> From: Jens Axboe <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 12:58:40 +0200
> 
> > The problem is that you cannot zero the entire sg entry, because then
> > you'd potentially overwrite the chain pointer.
> > 
> > I'd propose just adding a
> > 
> > sg_dma_address(sg) = 0;
> > sg_dma_len(sg) = 0;
> > 
> > there for now, or provide an arch_clear_sg_entry() helper if we need
> > more killed.
> 
> The "chain pointer" is indicated by an sg->page with the low
> bit set, but we're explicitly initializing it here to a
> non-chain page pointer value.
> 
> What's the problem?

See next mail :-)

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, Jens Axboe wrote:
> On Wed, Oct 17 2007, David Miller wrote:
> > From: Jens Axboe <[EMAIL PROTECTED]>
> > Date: Wed, 17 Oct 2007 11:16:29 +0200
> > 
> > > On Wed, Oct 17 2007, David Miller wrote:
> > > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > > 
> > > > > Righto, it's invalid to call sg_next() on the last entry!
> > > > 
> > > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > > 
> > > > -   struct scatterlist *sg_end = sg + nelems;
> > > > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> > > >  ...
> > > > -   while (sg < sg_end &&
> > > > +   while (sg != sg_end &&
> > > 
> > > Auch indeed. That'd probably be better as a
> > > 
> > > do {
> > > ...
> > > } while (sg != sg_end);
> > 
> > Ok, next bug, introduced by this change:
> > 
> > commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> > Author: Jens Axboe <[EMAIL PROTECTED]>
> > Date:   Fri Sep 21 10:44:19 2007 +0200
> > 
> > block: convert to using sg helpers
> > 
> > Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
> > 
> > Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> > 
> > Specifically this part:
> > 
> >  new_segment:
> > -   memset(&sg[nsegs],0,sizeof(struct scatterlist));
> > -   sg[nsegs].page = bvec->bv_page;
> > -   sg[nsegs].length = nbytes;
> > -   sg[nsegs].offset = bvec->bv_offset;
> > +   sg = next_sg;
> > +   next_sg = sg_next(sg);
> >  
> > +   sg->page = bvec->bv_page;
> > +   sg->length = nbytes;
> > +   sg->offset = bvec->bv_offset;
> > 
> > You can't remove that memset(), it's there for a reason.  The IOMMU
> > layers depended upon the code zero'ing out the whole scatterlist
> > struct, there might be more to it than page, length and offset :-)
> 
> I realize that, and I was pretty worried about this specific change. But
> there's only been one piece of fallout because if it until now - well
> two, with the sparc64 stuff.
> 
> The problem is that you cannot zero the entire sg entry, because then
> you'd potentially overwrite the chain pointer.
> 
> I'd propose just adding a
> 
> sg_dma_address(sg) = 0;
> sg_dma_len(sg) = 0;
> 
> there for now, or provide an arch_clear_sg_entry() helper if we need
> more killed.

Actually, just clearing AFTER sg_next() would be fine, since we know
that is not a link entry. Duh...

diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 9eabac9..1014d34 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -1352,6 +1352,7 @@ new_segment:
sg = next_sg;
next_sg = sg_next(sg);
 
+   memset(sg, 0, sizeof(*sg));
sg->page = bvec->bv_page;
sg->length = nbytes;
sg->offset = bvec->bv_offset;

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, David Miller wrote:
> From: Jens Axboe <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 11:16:29 +0200
> 
> > On Wed, Oct 17 2007, David Miller wrote:
> > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > 
> > > > Righto, it's invalid to call sg_next() on the last entry!
> > > 
> > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > 
> > > - struct scatterlist *sg_end = sg + nelems;
> > > + struct scatterlist *sg_end = sg_last(sg, nelems);
> > >  ...
> > > - while (sg < sg_end &&
> > > + while (sg != sg_end &&
> > 
> > Auch indeed. That'd probably be better as a
> > 
> > do {
> > ...
> > } while (sg != sg_end);
> 
> Ok, next bug, introduced by this change:
> 
> commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
> Author: Jens Axboe <[EMAIL PROTECTED]>
> Date:   Fri Sep 21 10:44:19 2007 +0200
> 
> block: convert to using sg helpers
> 
> Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.
> 
> Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>
> 
> Specifically this part:
> 
>  new_segment:
> - memset(&sg[nsegs],0,sizeof(struct scatterlist));
> - sg[nsegs].page = bvec->bv_page;
> - sg[nsegs].length = nbytes;
> - sg[nsegs].offset = bvec->bv_offset;
> + sg = next_sg;
> + next_sg = sg_next(sg);
>  
> + sg->page = bvec->bv_page;
> + sg->length = nbytes;
> + sg->offset = bvec->bv_offset;
> 
> You can't remove that memset(), it's there for a reason.  The IOMMU
> layers depended upon the code zero'ing out the whole scatterlist
> struct, there might be more to it than page, length and offset :-)

I realize that, and I was pretty worried about this specific change. But
there's only been one piece of fallout because if it until now - well
two, with the sparc64 stuff.

The problem is that you cannot zero the entire sg entry, because then
you'd potentially overwrite the chain pointer.

I'd propose just adding a

sg_dma_address(sg) = 0;
sg_dma_len(sg) = 0;

there for now, or provide an arch_clear_sg_entry() helper if we need
more killed.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: Jens Axboe <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 11:16:29 +0200

> On Wed, Oct 17 2007, David Miller wrote:
> > From: Jens Axboe <[EMAIL PROTECTED]>
> > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > 
> > > Righto, it's invalid to call sg_next() on the last entry!
> > 
> > Unfortunately, that's what the sparc64 code wanted to do, this
> > transformation in the sparc64 sg chaining patch is not equilavent:
> > 
> > -   struct scatterlist *sg_end = sg + nelems;
> > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> >  ...
> > -   while (sg < sg_end &&
> > +   while (sg != sg_end &&
> 
> Auch indeed. That'd probably be better as a
> 
> do {
> ...
> } while (sg != sg_end);

Ok, next bug, introduced by this change:

commit f565913ef8a8d0cfa46a1faaf8340cc357a46f3a
Author: Jens Axboe <[EMAIL PROTECTED]>
Date:   Fri Sep 21 10:44:19 2007 +0200

block: convert to using sg helpers

Convert the main rq mapper (blk_rq_map_sg()) to the sg helper setup.

Signed-off-by: Jens Axboe <[EMAIL PROTECTED]>

Specifically this part:

 new_segment:
-   memset(&sg[nsegs],0,sizeof(struct scatterlist));
-   sg[nsegs].page = bvec->bv_page;
-   sg[nsegs].length = nbytes;
-   sg[nsegs].offset = bvec->bv_offset;
+   sg = next_sg;
+   next_sg = sg_next(sg);
 
+   sg->page = bvec->bv_page;
+   sg->length = nbytes;
+   sg->offset = bvec->bv_offset;

You can't remove that memset(), it's there for a reason.  The IOMMU
layers depended upon the code zero'ing out the whole scatterlist
struct, there might be more to it than page, length and offset :-)

In sparc64's case, this zero'd the dma_address and dma_length members
and the mapping algorithms use that to their advantage.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: What still uses the block layer?

2007-10-17 Thread Gabor Gombas
On Tue, Oct 16, 2007 at 01:55:07PM -0700, [EMAIL PROTECTED] wrote:

> why is this any different from the external enclosures? they have always 
> appeared as the type of device that connects them to the motherboard, (and 
> even with SCSI, there are some controllers that don't generate sdX devices)

In the past enclosures supported only one kind of connector so this
assumption was fine. But nowadays an external disk may have several
connectors (like USB, Firewire and eSata). Why should the disk's name
depend on what type of cable did I manage to grab first? It is the
_same_ disk regardless of the cable type.

There is one thing however that could be improved: renaming a disk in an
udev rule should propagate the new name back to the kernel, just like
renaming an ethernet interface does. That way mapping error messages to
physical disk locations could be made much easier.

Gabor

-- 
 -
 MTA SZTAKI Computer and Automation Research Institute
Hungarian Academy of Sciences
 -
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: FUJITA Tomonori <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 18:24:01 +0900

> On Wed, 17 Oct 2007 11:16:29 +0200
> Jens Axboe <[EMAIL PROTECTED]> wrote:
> 
> > On Wed, Oct 17 2007, David Miller wrote:
> > > I would suggest that other sg_last() uses be audited for the same bug.
> > 
> > Agree.
> 
> Only libata, I think.

There are a few other spots, like ide-scsi
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> On Wed, 17 Oct 2007 11:16:29 +0200
> Jens Axboe <[EMAIL PROTECTED]> wrote:
> 
> > On Wed, Oct 17 2007, David Miller wrote:
> > > From: Jens Axboe <[EMAIL PROTECTED]>
> > > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > > 
> > > > Righto, it's invalid to call sg_next() on the last entry!
> > > 
> > > Unfortunately, that's what the sparc64 code wanted to do, this
> > > transformation in the sparc64 sg chaining patch is not equilavent:
> > > 
> > > - struct scatterlist *sg_end = sg + nelems;
> > > + struct scatterlist *sg_end = sg_last(sg, nelems);
> > >  ...
> > > - while (sg < sg_end &&
> > > + while (sg != sg_end &&
> > 
> > Auch indeed. That'd probably be better as a
> > 
> > do {
> > ...
> > } while (sg != sg_end);
> > 
> > > No, that's not what the code was doing.  The while loop
> > > has to process the last entry in the list,
> > > 
> > > We really needed "sg_end" to be "one past the last element",
> > > rather than "the last element".
> > > 
> > > Since you say that sg_next() on the last entry is illegal,
> > > and that's what this code would have done to try and reach
> > > loop termination (it doesn't actually derefrence that
> > > "end plus one" scatterlist entry) I'll try to code this up
> > > some other way.
> > > 
> > > Besides, sg_last() is so absurdly expensive, it has to walk the entire
> > > chain in the chaining case.  So better to implement this without it.
> > 
> > It is, sg_last() should really not be used a lot since it'll leaf
> > through the entire sg list. People should either keep count of the
> > number of entries so that they know when they are dealing with the last
> > valid entry. Or use the for_each_sg() loop helper, if possible.
> > 
> > Drivers are usually very simple, the iommu code does more sg tricks and
> > thus is more complex to audit.
> 
> Can we just remove sg_last?

I think that would be best, we don't want to encourage use of it, it's
not really clear to people how expensive it is unless they go and look
at it. The absolute worst case would be someone doing a

for_each_sg(sgl, sg, nents) {
...
if (sg == sg_last(sgl))
...
}

which would be absolutely awful.

But lets let things settle for a few days, then kill sg_last().

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread FUJITA Tomonori
On Wed, 17 Oct 2007 11:16:29 +0200
Jens Axboe <[EMAIL PROTECTED]> wrote:

> On Wed, Oct 17 2007, David Miller wrote:
> > From: Jens Axboe <[EMAIL PROTECTED]>
> > Date: Wed, 17 Oct 2007 10:45:28 +0200
> > 
> > > Righto, it's invalid to call sg_next() on the last entry!
> > 
> > Unfortunately, that's what the sparc64 code wanted to do, this
> > transformation in the sparc64 sg chaining patch is not equilavent:
> > 
> > -   struct scatterlist *sg_end = sg + nelems;
> > +   struct scatterlist *sg_end = sg_last(sg, nelems);
> >  ...
> > -   while (sg < sg_end &&
> > +   while (sg != sg_end &&
> 
> Auch indeed. That'd probably be better as a
> 
> do {
> ...
> } while (sg != sg_end);
> 
> > No, that's not what the code was doing.  The while loop
> > has to process the last entry in the list,
> > 
> > We really needed "sg_end" to be "one past the last element",
> > rather than "the last element".
> > 
> > Since you say that sg_next() on the last entry is illegal,
> > and that's what this code would have done to try and reach
> > loop termination (it doesn't actually derefrence that
> > "end plus one" scatterlist entry) I'll try to code this up
> > some other way.
> > 
> > Besides, sg_last() is so absurdly expensive, it has to walk the entire
> > chain in the chaining case.  So better to implement this without it.
> 
> It is, sg_last() should really not be used a lot since it'll leaf
> through the entire sg list. People should either keep count of the
> number of entries so that they know when they are dealing with the last
> valid entry. Or use the for_each_sg() loop helper, if possible.
> 
> Drivers are usually very simple, the iommu code does more sg tricks and
> thus is more complex to audit.

Can we just remove sg_last?


> > I would suggest that other sg_last() uses be audited for the same bug.
> 
> Agree.

Only libata, I think.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, David Miller wrote:
> From: Jens Axboe <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 10:45:28 +0200
> 
> > Righto, it's invalid to call sg_next() on the last entry!
> 
> Unfortunately, that's what the sparc64 code wanted to do, this
> transformation in the sparc64 sg chaining patch is not equilavent:
> 
> - struct scatterlist *sg_end = sg + nelems;
> + struct scatterlist *sg_end = sg_last(sg, nelems);
>  ...
> - while (sg < sg_end &&
> + while (sg != sg_end &&

Auch indeed. That'd probably be better as a

do {
...
} while (sg != sg_end);

> No, that's not what the code was doing.  The while loop
> has to process the last entry in the list,
> 
> We really needed "sg_end" to be "one past the last element",
> rather than "the last element".
> 
> Since you say that sg_next() on the last entry is illegal,
> and that's what this code would have done to try and reach
> loop termination (it doesn't actually derefrence that
> "end plus one" scatterlist entry) I'll try to code this up
> some other way.
> 
> Besides, sg_last() is so absurdly expensive, it has to walk the entire
> chain in the chaining case.  So better to implement this without it.

It is, sg_last() should really not be used a lot since it'll leaf
through the entire sg list. People should either keep count of the
number of entries so that they know when they are dealing with the last
valid entry. Or use the for_each_sg() loop helper, if possible.

Drivers are usually very simple, the iommu code does more sg tricks and
thus is more complex to audit.

> I would suggest that other sg_last() uses be audited for the same bug.

Agree.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: Jens Axboe <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 10:45:28 +0200

> Righto, it's invalid to call sg_next() on the last entry!

Unfortunately, that's what the sparc64 code wanted to do, this
transformation in the sparc64 sg chaining patch is not equilavent:

-   struct scatterlist *sg_end = sg + nelems;
+   struct scatterlist *sg_end = sg_last(sg, nelems);
 ...
-   while (sg < sg_end &&
+   while (sg != sg_end &&

No, that's not what the code was doing.  The while loop
has to process the last entry in the list,

We really needed "sg_end" to be "one past the last element",
rather than "the last element".

Since you say that sg_next() on the last entry is illegal,
and that's what this code would have done to try and reach
loop termination (it doesn't actually derefrence that
"end plus one" scatterlist entry) I'll try to code this up
some other way.

Besides, sg_last() is so absurdly expensive, it has to walk the entire
chain in the chaining case.  So better to implement this without it.

I would suggest that other sg_last() uses be audited for the same bug.
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] IA64: iommu uses sg_next with an invalid sg element

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> sg list elements might not be continuous.

Thanks, applied.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] IA64: iommu uses sg_next with an invalid sg element

2007-10-17 Thread FUJITA Tomonori
sg list elements might not be continuous.

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
---
 arch/ia64/hp/common/sba_iommu.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index 4338f41..3c95f41 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -1179,7 +1179,6 @@ sba_fill_pdir(
u64 *pdirp = NULL;
unsigned long dma_offset = 0;
 
-   dma_sg--;
while (nents-- > 0) {
int cnt = startsg->dma_length;
startsg->dma_length = 0;
@@ -1201,7 +1200,8 @@ sba_fill_pdir(
u32 pide = startsg->dma_address & ~PIDE_FLAG;
dma_offset = (unsigned long) pide & ~iovp_mask;
startsg->dma_address = 0;
-   dma_sg = sg_next(dma_sg);
+   if (n_mappings)
+   dma_sg = sg_next(dma_sg);
dma_sg->dma_address = pide | ioc->ibase;
pdirp = &(ioc->pdir_base[pide >> iovp_shift]);
n_mappings++;
-- 
1.5.2.4

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, David Miller wrote:
> From: David Miller <[EMAIL PROTECTED]>
> Date: Wed, 17 Oct 2007 01:33:25 -0700 (PDT)
> 
> > sg_next() gives you a NULL after the last entry, but tests have been
> > changed to compare against sg_last() which is likely not what we
> > want for those checks.
> 
> This of course isn't true, ignore me as I'm still learning how this
> new stuff works :-)

Righto, it's invalid to call sg_next() on the last entry! Let me know if
you need any help with debugging this, unfortunately I cannot test on
sparc64 myself...

(I can say that easily, since I know that davem will a) not rest until
this is fixed, and b) is a really good debugger and will not need my
help)

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: David Miller <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 01:33:25 -0700 (PDT)

> sg_next() gives you a NULL after the last entry, but tests have been
> changed to compare against sg_last() which is likely not what we
> want for those checks.

This of course isn't true, ignore me as I'm still learning how this
new stuff works :-)
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread David Miller
From: Jens Axboe <[EMAIL PROTECTED]>
Date: Wed, 17 Oct 2007 09:21:49 +0200

> On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> > Commit 2c941a204070ab32d92d40318a3196a7fb994c00 looks incomplete. The
> > helper functions like prepare_sg() need to support sg chaining too.
> 
> Thanks Tomo, applied. I'll get this pushed out later today with any
> other sg chaining fallout we may see.

I'm still debugging crashes on sparc64 early on boot even with this
latest fix applied.

I think there are still problems in functions like fill_sg().

There is a lot of confusion involving loop termination.  sg_next()
gives you a NULL after the last entry, but tests have been changed
to compare against sg_last() which is likely not what we want for
those checks.

I'll try to figure it out, just a heads up...
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] swiotlb: fix map_sg failure handling

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> sg list elements might not be continuous.
> 
> Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
> ---
>  lib/swiotlb.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/swiotlb.c b/lib/swiotlb.c
> index c419ecf..752fd95 100644
> --- a/lib/swiotlb.c
> +++ b/lib/swiotlb.c
> @@ -696,7 +696,7 @@ swiotlb_map_sg(struct device *hwdev, struct scatterlist 
> *sgl, int nelems,
>   /* Don't panic here, we expect map_sg users
>  to do proper error handling. */
>   swiotlb_full(hwdev, sg->length, dir, 0);
> - swiotlb_unmap_sg(hwdev, sg - i, i, dir);
> + swiotlb_unmap_sg(hwdev, sgl, i, dir);
>   sgl[0].dma_length = 0;
>   return 0;
>   }

Auch indeed, no math on sg entries! Applied.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] swiotlb: fix map_sg failure handling

2007-10-17 Thread FUJITA Tomonori
sg list elements might not be continuous.

Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
---
 lib/swiotlb.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index c419ecf..752fd95 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -696,7 +696,7 @@ swiotlb_map_sg(struct device *hwdev, struct scatterlist 
*sgl, int nelems,
/* Don't panic here, we expect map_sg users
   to do proper error handling. */
swiotlb_full(hwdev, sg->length, dir, 0);
-   swiotlb_unmap_sg(hwdev, sg - i, i, dir);
+   swiotlb_unmap_sg(hwdev, sgl, i, dir);
sgl[0].dma_length = 0;
return 0;
}
-- 
1.5.2.4

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] SPARC64: fix iommu sg chaining

2007-10-17 Thread Jens Axboe
On Wed, Oct 17 2007, FUJITA Tomonori wrote:
> Commit 2c941a204070ab32d92d40318a3196a7fb994c00 looks incomplete. The
> helper functions like prepare_sg() need to support sg chaining too.

Thanks Tomo, applied. I'll get this pushed out later today with any
other sg chaining fallout we may see.

-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html