Subject: Re: SCSI Scatter-Gather buffer command
To: Dante Profeta <dante@mclink.it>
From: Jason Thorpe <thorpej@nas.nasa.gov>
List: tech-kern
Date: 06/30/1998 22:59:51
On Tue, 30 Jun 1998 23:32:49 +0200
Dante Profeta <dante@mclink.it> wrote:
> It seems Linux SCSI commands could be issued in two different way
> according to the value of an Scsi_Cmnd field named 'use_sg'.
>
> - if 'use_sg' is zero, then 'request_buffer' points to the data buffer
> for the SCSI command, and 'request_bufflen' is the length of this buffer
> in bytes.
>
> - if 'use_sg' is grather then zero, then 'request_buffer' points to an
> array of scatterlist structures, and 'use_sg' will indicate how many
> such structures are in the array.
As you have probably guessed, NetBSD's SCSI code doesn't have any such
thing... it only uses linear buffers (that may change in the future, but
not right now).
So, you don't have to worry about "use_sg" for NetBSD ... only linear buffers,
which means only bus_dmamap_load(). (When we also allow uios to be passed
down, you'll use bus_dmamap_load_uio() for those...)
> slp = (struct scatterlist *) scp->request_buffer;
> for (sgcnt = 0; sgcnt < scp->use_sg; sgcnt++, slp++)
> {
> asc_sg_head.sg_list[sgcnt].addr = virt_to_bus(slp->address);
> asc_sg_head.sg_list[sgcnt].bytes = slp->length;
> }
>
>
> ...could be considered equivalent to the following one extracted from
> bha.c? ...
>
>
> /*
> * Load the hardware scatter/gather map with the
> * contents of the DMA map.
> */
> for (seg = 0; seg < ccb->dmamap_xfer->dm_nsegs; seg++)
> {
> ltophys(ccb->dmamap_xfer->dm_segs[seg].ds_addr,
> ccb->scat_gath[seg].seg_addr);
> ltophys(ccb->dmamap_xfer->dm_segs[seg].ds_len,
> ccb->scat_gath[seg].seg_len);
> }
>
> ltophys(ccb->dmamap_self->dm_segs[0].ds_addr +
> offsetof(struct bha_ccb, scat_gath), ccb->data_addr);
> ltophys(ccb->dmamap_xfer->dm_nsegs *
> sizeof(struct bha_scat_gath), ccb->data_length);
>
>
> ...Otherwise how should I manage this situation?
No, the two things are not the same. The code from bha.c that you're
quoting is the translation of the _linear buffer_ into DMA segments.
Linux would also have to translate linear buffers into DMA segments...
Basically, in NetBSD, the traversal of the "dmamap" would be the same
if a linear buffer or a uio (software scatter/gather) were provided to
the SCSI driver. Only the function that loads the "dmamap" would change.
Is that as clear as mud? :-)
Jason R. Thorpe thorpej@nas.nasa.gov
NASA Ames Research Center Home: +1 408 866 1912
NAS: M/S 258-5 Work: +1 650 604 0935
Moffett Field, CA 94035 Pager: +1 650 428 6939