Commit 4a98f896 authored by Finn Thain's avatar Finn Thain Committed by Martin K. Petersen
Browse files

scsi: ncr5380: Use correct types for DMA routines



Apply prototypes to get consistent function signatures for the DMA
functions implemented in the board-specific drivers. To avoid using
macros to alter actual parameters, some of those functions are reworked
slightly.

This is a step toward the goal of passing the board-specific routines
to the core driver using an ops struct (as in a platform driver or
library module).

This also helps fix some inconsistent types: where the core driver uses
ints (cmd->SCp.this_residual and hostdata->dma_len) for keeping track of
transfers, certain board-specific routines used unsigned long.

While we are fixing these function signatures, pass the hostdata pointer
to DMA routines instead of a Scsi_Host pointer, for shorter and faster
code.

Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
Tested-by: default avatarOndrej Zary <linux@rainbow-software.org>
Tested-by: default avatarMichael Schmitz <schmitzmic@gmail.com>
Acked-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 7c606631
Loading
Loading
Loading
Loading
+41 −33
Original line number Diff line number Diff line
@@ -121,9 +121,10 @@
 *
 * Either real DMA *or* pseudo DMA may be implemented
 *
 * NCR5380_dma_write_setup(instance, src, count) - initialize
 * NCR5380_dma_read_setup(instance, dst, count) - initialize
 * NCR5380_dma_residual(instance); - residual count
 * NCR5380_dma_xfer_len   - determine size of DMA/PDMA transfer
 * NCR5380_dma_send_setup - execute DMA/PDMA from memory to 5380
 * NCR5380_dma_recv_setup - execute DMA/PDMA from 5380 to memory
 * NCR5380_dma_residual   - residual byte count
 *
 * The generic driver is initialized by calling NCR5380_init(instance),
 * after setting the appropriate host specific fields and ID.  If the
@@ -871,7 +872,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
	NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
	NCR5380_read(RESET_PARITY_INTERRUPT_REG);

	transferred = hostdata->dma_len - NCR5380_dma_residual(instance);
	transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata);
	hostdata->dma_len = 0;

	data = (unsigned char **)&hostdata->connected->SCp.ptr;
@@ -1578,9 +1579,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
		 * starting the NCR. This is also the cleaner way for the TT.
		 */
		if (p & SR_IO)
			result = NCR5380_dma_recv_setup(instance, d, c);
			result = NCR5380_dma_recv_setup(hostdata, d, c);
		else
			result = NCR5380_dma_send_setup(instance, d, c);
			result = NCR5380_dma_send_setup(hostdata, d, c);
	}

	/*
@@ -1612,9 +1613,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
		 * NCR access, else the DMA setup gets trashed!
		 */
		if (p & SR_IO)
			result = NCR5380_dma_recv_setup(instance, d, c);
			result = NCR5380_dma_recv_setup(hostdata, d, c);
		else
			result = NCR5380_dma_send_setup(instance, d, c);
			result = NCR5380_dma_send_setup(hostdata, d, c);
	}

	/* On failure, NCR5380_dma_xxxx_setup() returns a negative int. */
@@ -1754,22 +1755,26 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
				NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
			}
#ifdef CONFIG_SUN3
			if (phase == PHASE_CMDOUT) {
				void *d;
				unsigned long count;
			if (phase == PHASE_CMDOUT &&
			    sun3_dma_setup_done != cmd) {
				int count;

				if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
					count = cmd->SCp.buffer->length;
					d = sg_virt(cmd->SCp.buffer);
				} else {
					count = cmd->SCp.this_residual;
					d = cmd->SCp.ptr;
					++cmd->SCp.buffer;
					--cmd->SCp.buffers_residual;
					cmd->SCp.this_residual = cmd->SCp.buffer->length;
					cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
				}

				if (sun3_dma_setup_done != cmd &&
				    sun3scsi_dma_xfer_len(count, cmd) > 0) {
					sun3scsi_dma_setup(instance, d, count,
					                   rq_data_dir(cmd->request));
				count = sun3scsi_dma_xfer_len(hostdata, cmd);

				if (count > 0) {
					if (rq_data_dir(cmd->request))
						sun3scsi_dma_send_setup(hostdata,
						                        cmd->SCp.ptr, count);
					else
						sun3scsi_dma_recv_setup(hostdata,
						                        cmd->SCp.ptr, count);
					sun3_dma_setup_done = cmd;
				}
#ifdef SUN3_SCSI_VME
@@ -1830,7 +1835,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)

				transfersize = 0;
				if (!cmd->device->borken)
					transfersize = NCR5380_dma_xfer_len(instance, cmd, phase);
					transfersize = NCR5380_dma_xfer_len(hostdata, cmd);

				if (transfersize > 0) {
					len = transfersize;
@@ -2207,22 +2212,25 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
	}

#ifdef CONFIG_SUN3
	{
		void *d;
		unsigned long count;
	if (sun3_dma_setup_done != tmp) {
		int count;

		if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
			count = tmp->SCp.buffer->length;
			d = sg_virt(tmp->SCp.buffer);
		} else {
			count = tmp->SCp.this_residual;
			d = tmp->SCp.ptr;
			++tmp->SCp.buffer;
			--tmp->SCp.buffers_residual;
			tmp->SCp.this_residual = tmp->SCp.buffer->length;
			tmp->SCp.ptr = sg_virt(tmp->SCp.buffer);
		}

		if (sun3_dma_setup_done != tmp &&
		    sun3scsi_dma_xfer_len(count, tmp) > 0) {
			sun3scsi_dma_setup(instance, d, count,
			                   rq_data_dir(tmp->request));
		count = sun3scsi_dma_xfer_len(hostdata, tmp);

		if (count > 0) {
			if (rq_data_dir(tmp->request))
				sun3scsi_dma_send_setup(hostdata,
				                        tmp->SCp.ptr, count);
			else
				sun3scsi_dma_recv_setup(hostdata,
				                        tmp->SCp.ptr, count);
			sun3_dma_setup_done = tmp;
		}
	}
+25 −0
Original line number Diff line number Diff line
@@ -317,5 +317,30 @@ static inline int NCR5380_poll_politely(struct NCR5380_hostdata *hostdata,
						reg, bit, val, wait);
}

static int NCR5380_dma_xfer_len(struct NCR5380_hostdata *,
                                struct scsi_cmnd *);
static int NCR5380_dma_send_setup(struct NCR5380_hostdata *,
                                  unsigned char *, int);
static int NCR5380_dma_recv_setup(struct NCR5380_hostdata *,
                                  unsigned char *, int);
static int NCR5380_dma_residual(struct NCR5380_hostdata *);

static inline int NCR5380_dma_xfer_none(struct NCR5380_hostdata *hostdata,
                                        struct scsi_cmnd *cmd)
{
	return 0;
}

static inline int NCR5380_dma_setup_none(struct NCR5380_hostdata *hostdata,
                                         unsigned char *data, int count)
{
	return 0;
}

static inline int NCR5380_dma_residual_none(struct NCR5380_hostdata *hostdata)
{
	return 0;
}

#endif				/* __KERNEL__ */
#endif				/* NCR5380_H */
+16 −10
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@
#define NCR5380_read(reg)		cumanascsi_read(hostdata, reg)
#define NCR5380_write(reg, value)	cumanascsi_write(hostdata, reg, value)

#define NCR5380_dma_xfer_len(instance, cmd, phase)	(cmd->transfersize)
#define NCR5380_dma_xfer_len		cumanascsi_dma_xfer_len
#define NCR5380_dma_recv_setup		cumanascsi_pread
#define NCR5380_dma_send_setup		cumanascsi_pwrite
#define NCR5380_dma_residual(instance)	(0)
#define NCR5380_dma_residual		NCR5380_dma_residual_none

#define NCR5380_intr			cumanascsi_intr
#define NCR5380_queue_command		cumanascsi_queue_command
@@ -40,12 +40,12 @@ static void cumanascsi_write(struct NCR5380_hostdata *, unsigned int, u8);
#define L(v)	(((v)<<16)|((v) & 0x0000ffff))
#define H(v)	(((v)>>16)|((v) & 0xffff0000))

static inline int cumanascsi_pwrite(struct Scsi_Host *host,
static inline int cumanascsi_pwrite(struct NCR5380_hostdata *hostdata,
                                    unsigned char *addr, int len)
{
  unsigned long *laddr;
  u8 __iomem *base = priv(host)->io;
  u8 __iomem *dma = priv(host)->pdma_io + 0x2000;
  u8 __iomem *base = hostdata->io;
  u8 __iomem *dma = hostdata->pdma_io + 0x2000;

  if(!len) return 0;

@@ -100,19 +100,19 @@ static inline int cumanascsi_pwrite(struct Scsi_Host *host,
    }
  }
end:
  writeb(priv(host)->ctrl | 0x40, base + CTRL);
  writeb(hostdata->ctrl | 0x40, base + CTRL);

	if (len)
		return -1;
	return 0;
}

static inline int cumanascsi_pread(struct Scsi_Host *host,
static inline int cumanascsi_pread(struct NCR5380_hostdata *hostdata,
                                   unsigned char *addr, int len)
{
  unsigned long *laddr;
  u8 __iomem *base = priv(host)->io;
  u8 __iomem *dma = priv(host)->pdma_io + 0x2000;
  u8 __iomem *base = hostdata->io;
  u8 __iomem *dma = hostdata->pdma_io + 0x2000;

  if(!len) return 0;

@@ -166,13 +166,19 @@ static inline int cumanascsi_pread(struct Scsi_Host *host,
    }
  }
end:
  writeb(priv(host)->ctrl | 0x40, base + CTRL);
  writeb(hostdata->ctrl | 0x40, base + CTRL);

	if (len)
		return -1;
	return 0;
}

static int cumanascsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                   struct scsi_cmnd *cmd)
{
	return cmd->transfersize;
}

static u8 cumanascsi_read(struct NCR5380_hostdata *hostdata,
                          unsigned int reg)
{
+7 −6
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@
#define NCR5380_read(reg)           readb(hostdata->io + ((reg) << 2))
#define NCR5380_write(reg, value)   writeb(value, hostdata->io + ((reg) << 2))

#define NCR5380_dma_xfer_len(instance, cmd, phase)	(0)
#define NCR5380_dma_xfer_len		NCR5380_dma_xfer_none
#define NCR5380_dma_recv_setup		oakscsi_pread
#define NCR5380_dma_send_setup		oakscsi_pwrite
#define NCR5380_dma_residual(instance)	(0)
#define NCR5380_dma_residual		NCR5380_dma_residual_none

#define NCR5380_queue_command		oakscsi_queue_command
#define NCR5380_info			oakscsi_info
@@ -37,10 +37,10 @@
#define STAT	((128 + 16) << 2)
#define DATA	((128 + 8) << 2)

static inline int oakscsi_pwrite(struct Scsi_Host *instance,
static inline int oakscsi_pwrite(struct NCR5380_hostdata *hostdata,
                                 unsigned char *addr, int len)
{
  u8 __iomem *base = priv(instance)->io;
  u8 __iomem *base = hostdata->io;

printk("writing %p len %d\n",addr, len);

@@ -52,10 +52,11 @@ printk("writing %p len %d\n",addr, len);
  return 0;
}

static inline int oakscsi_pread(struct Scsi_Host *instance,
static inline int oakscsi_pread(struct NCR5380_hostdata *hostdata,
                                unsigned char *addr, int len)
{
  u8 __iomem *base = priv(instance)->io;
  u8 __iomem *base = hostdata->io;

printk("reading %p len %d\n", addr, len);
  while(len > 0)
  {
+26 −19
Original line number Diff line number Diff line
@@ -67,14 +67,10 @@ static void (*atari_scsi_reg_write)(unsigned int, u8);
#define NCR5380_abort                   atari_scsi_abort
#define NCR5380_info                    atari_scsi_info

#define NCR5380_dma_recv_setup(instance, data, count) \
        atari_scsi_dma_setup(instance, data, count, 0)
#define NCR5380_dma_send_setup(instance, data, count) \
        atari_scsi_dma_setup(instance, data, count, 1)
#define NCR5380_dma_residual(instance) \
        atari_scsi_dma_residual(instance)
#define NCR5380_dma_xfer_len(instance, cmd, phase) \
        atari_dma_xfer_len(cmd->SCp.this_residual, cmd, !((phase) & SR_IO))
#define NCR5380_dma_xfer_len            atari_scsi_dma_xfer_len
#define NCR5380_dma_recv_setup          atari_scsi_dma_recv_setup
#define NCR5380_dma_send_setup          atari_scsi_dma_send_setup
#define NCR5380_dma_residual            atari_scsi_dma_residual

#define NCR5380_acquire_dma_irq(instance)      falcon_get_lock(instance)
#define NCR5380_release_dma_irq(instance)      falcon_release_lock()
@@ -457,15 +453,14 @@ static int __init atari_scsi_setup(char *str)
__setup("atascsi=", atari_scsi_setup);
#endif /* !MODULE */


static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance,
static unsigned long atari_scsi_dma_setup(struct NCR5380_hostdata *hostdata,
					  void *data, unsigned long count,
					  int dir)
{
	unsigned long addr = virt_to_phys(data);

	dprintk(NDEBUG_DMA, "scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, "
		   "dir = %d\n", instance->host_no, data, addr, count, dir);
	dprintk(NDEBUG_DMA, "scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, dir = %d\n",
	        hostdata->host->host_no, data, addr, count, dir);

	if (!IS_A_TT() && !STRAM_ADDR(addr)) {
		/* If we have a non-DMAable address on a Falcon, use the dribble
@@ -522,8 +517,19 @@ static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance,
	return count;
}

static inline int atari_scsi_dma_recv_setup(struct NCR5380_hostdata *hostdata,
                                            unsigned char *data, int count)
{
	return atari_scsi_dma_setup(hostdata, data, count, 0);
}

static inline int atari_scsi_dma_send_setup(struct NCR5380_hostdata *hostdata,
                                            unsigned char *data, int count)
{
	return atari_scsi_dma_setup(hostdata, data, count, 1);
}

static long atari_scsi_dma_residual(struct Scsi_Host *instance)
static int atari_scsi_dma_residual(struct NCR5380_hostdata *hostdata)
{
	return atari_dma_residual;
}
@@ -564,10 +570,11 @@ static int falcon_classify_cmd(struct scsi_cmnd *cmd)
 * the overrun problem, so this question is academic :-)
 */

static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
					struct scsi_cmnd *cmd, int write_flag)
static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                   struct scsi_cmnd *cmd)
{
	unsigned long	possible_len, limit;
	int wanted_len = cmd->SCp.this_residual;
	int possible_len, limit;

	if (wanted_len < DMA_MIN_SIZE)
		return 0;
@@ -604,7 +611,7 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
	 * use the dribble buffer and thus can do only STRAM_BUFFER_SIZE bytes.
	 */

	if (write_flag) {
	if (cmd->sc_data_direction == DMA_TO_DEVICE) {
		/* Write operation can always use the DMA, but the transfer size must
		 * be rounded up to the next multiple of 512 (atari_dma_setup() does
		 * this).
@@ -644,8 +651,8 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
		possible_len = limit;

	if (possible_len != wanted_len)
		dprintk(NDEBUG_DMA, "Sorry, must cut DMA transfer size to %ld bytes "
			   "instead of %ld\n", possible_len, wanted_len);
		dprintk(NDEBUG_DMA, "DMA transfer now %d bytes instead of %d\n",
		        possible_len, wanted_len);

	return possible_len;
}
Loading