/* We try to reduce the number of interrupts caused by unexpected phase changes due to disconnects. A typical harddisk may disconnect before ANY block. If we wanted to avoid unexpected phase changes at all we had to use a break point every 512 bytes. Of course the number of scatter/gather blocks is limited. Under Linux, the scatter/gatter blocks are provided by the generic driver. We just have to copy addresses and sizes to the data segment array.  */
static int ncr_scatter(struct ncb *np, struct ccb *cp, struct scsi_cmnd *cmd)
/* We try to reduce the number of interrupts caused by unexpected phase changes due to disconnects. A typical harddisk may disconnect before ANY block. If we wanted to avoid unexpected phase changes at all we had to use a break point every 512 bytes. Of course the number of scatter/gather blocks is limited. Under Linux, the scatter/gatter blocks are provided by the generic driver. We just have to copy addresses and sizes to the data segment array.  */
static int ncr_scatter(struct ncb *np, struct ccb *cp, struct scsi_cmnd *cmd)
{
	int segment	= 0;
	int use_sg	= scsi_sg_count(cmd);
	cp->data_len	= 0;
	use_sg = map_scsi_sg_data(np, cmd);
	if (use_sg > 0) {
		struct scatterlist *sg;
		struct scr_tblmove *data;
		if (use_sg > MAX_SCATTER) {
			unmap_scsi_data(np, cmd);
			return -1;
		}
		data = &cp->phys.data[MAX_SCATTER - use_sg];
		scsi_for_each_sg(cmd, sg, use_sg, segment) {
			dma_addr_t baddr = sg_dma_address(sg);
			unsigned int len = sg_dma_len(sg);
			ncr_build_sge(np, &data[segment], baddr, len);
			cp->data_len += len;
		}
	} else
		segment = -2;
	return segment;
}