Subject: SCSI Scatter-Gather buffer command
To: tech-kern@NetBSD.ORG <tech-kern@NetBSD.ORG>
From: Dante Profeta <>
List: tech-kern
Date: 06/30/1998 23:32:49
Hi folks,

I hope I'm not boring you, but... yes, I'm still trying to port Linux
AdvanSys driver...

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.

scatterlist structures has two fields: address and length.

The first meaning is ok by me: there are equivalent fields into NetBSD
scsipi_xfer structure.
My problems (...well, some of my problems...) lies with the second
meaning of 'use_sg'.

The following related code...

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_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?

Thanks for your patience,