summaryrefslogtreecommitdiff
path: root/drivers/scsi/arm/scsi.h
blob: 2f1b3f4bf954de455ff7bb23c6d93790d0a8f7d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 *  linux/drivers/acorn/scsi/scsi.h
 *
 *  Copyright (C) 2002 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  Commonly used scsi driver functions.
 */

#define BELT_AND_BRACES

/*
 * The scatter-gather list handling.  This contains all
 * the yucky stuff that needs to be fixed properly.
 */
static inline int copy_SCp_to_sg(struct scatterlist *sg, Scsi_Pointer *SCp, int max)
{
	int bufs = SCp->buffers_residual;

	BUG_ON(bufs + 1 > max);

	sg->page   = virt_to_page(SCp->ptr);
	sg->offset = offset_in_page(SCp->ptr);
	sg->length = SCp->this_residual;

	if (bufs)
		memcpy(sg + 1, SCp->buffer + 1,
		       sizeof(struct scatterlist) * bufs);
	return bufs + 1;
}

static inline int next_SCp(Scsi_Pointer *SCp)
{
	int ret = SCp->buffers_residual;
	if (ret) {
		SCp->buffer++;
		SCp->buffers_residual--;
		SCp->ptr = (char *)
			 (page_address(SCp->buffer->page) +
			  SCp->buffer->offset);
		SCp->this_residual = SCp->buffer->length;
	} else {
		SCp->ptr = NULL;
		SCp->this_residual = 0;
	}
	return ret;
}

static inline unsigned char get_next_SCp_byte(Scsi_Pointer *SCp)
{
	char c = *SCp->ptr;

	SCp->ptr += 1;
	SCp->this_residual -= 1;

	return c;
}

static inline void put_next_SCp_byte(Scsi_Pointer *SCp, unsigned char c)
{
	*SCp->ptr = c;
	SCp->ptr += 1;
	SCp->this_residual -= 1;
}

static inline void init_SCp(Scsi_Cmnd *SCpnt)
{
	memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer));

	if (SCpnt->use_sg) {
		unsigned long len = 0;
		int buf;

		SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->buffer;
		SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
		SCpnt->SCp.ptr = (char *)
			 (page_address(SCpnt->SCp.buffer->page) +
			  SCpnt->SCp.buffer->offset);
		SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;

#ifdef BELT_AND_BRACES
		/*
		 * Calculate correct buffer length.  Some commands
		 * come in with the wrong request_bufflen.
		 */
		for (buf = 0; buf <= SCpnt->SCp.buffers_residual; buf++)
			len += SCpnt->SCp.buffer[buf].length;

		if (SCpnt->request_bufflen != len)
			printk(KERN_WARNING "scsi%d.%c: bad request buffer "
			       "length %d, should be %ld\n", SCpnt->device->host->host_no,
			       '0' + SCpnt->device->id, SCpnt->request_bufflen, len);
		SCpnt->request_bufflen = len;
#endif
	} else {
		SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer;
		SCpnt->SCp.this_residual = SCpnt->request_bufflen;
	}

	/*
	 * If the upper SCSI layers pass a buffer, but zero length,
	 * we aren't interested in the buffer pointer.
	 */
	if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) {
#if 0 //def BELT_AND_BRACES
		printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for "
		       "command ", SCpnt->host->host_no, '0' + SCpnt->target);
		print_command(SCpnt->cmnd);
#endif
		SCpnt->SCp.ptr = NULL;
	}
}