diff options
author | Boaz Harrosh <bharrosh@panasas.com> | 2007-09-09 14:31:21 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-02-07 19:02:34 -0500 |
commit | 84ac86ca8c6787f9efff28bc04b1b65fe0a5c310 (patch) | |
tree | 5b3fb7216b94a693046e051b5ec741bdde04d98d /drivers/scsi/arm/scsi.h | |
parent | c9e86b8b1da8aea2cad6d3a825791c25ea67624d (diff) |
[SCSI] arm: convert to accessors and !use_sg cleanup
- convert to accessors and !use_sg cleanup
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Tested-by: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/arm/scsi.h')
-rw-r--r-- | drivers/scsi/arm/scsi.h | 87 |
1 files changed, 51 insertions, 36 deletions
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h index bb6550e31926..138a521ba1a8 100644 --- a/drivers/scsi/arm/scsi.h +++ b/drivers/scsi/arm/scsi.h | |||
@@ -18,17 +18,32 @@ | |||
18 | * The scatter-gather list handling. This contains all | 18 | * The scatter-gather list handling. This contains all |
19 | * the yucky stuff that needs to be fixed properly. | 19 | * the yucky stuff that needs to be fixed properly. |
20 | */ | 20 | */ |
21 | |||
22 | /* | ||
23 | * copy_SCp_to_sg() Assumes contiguous allocation at @sg of at-most @max | ||
24 | * entries of uninitialized memory. SCp is from scsi-ml and has a valid | ||
25 | * (possibly chained) sg-list | ||
26 | */ | ||
21 | static inline int copy_SCp_to_sg(struct scatterlist *sg, struct scsi_pointer *SCp, int max) | 27 | static inline int copy_SCp_to_sg(struct scatterlist *sg, struct scsi_pointer *SCp, int max) |
22 | { | 28 | { |
23 | int bufs = SCp->buffers_residual; | 29 | int bufs = SCp->buffers_residual; |
24 | 30 | ||
31 | /* FIXME: It should be easy for drivers to loop on copy_SCp_to_sg(). | ||
32 | * and to remove this BUG_ON. Use min() in-its-place | ||
33 | */ | ||
25 | BUG_ON(bufs + 1 > max); | 34 | BUG_ON(bufs + 1 > max); |
26 | 35 | ||
27 | sg_set_buf(sg, SCp->ptr, SCp->this_residual); | 36 | sg_set_buf(sg, SCp->ptr, SCp->this_residual); |
28 | 37 | ||
29 | if (bufs) | 38 | if (bufs) { |
30 | memcpy(sg + 1, SCp->buffer + 1, | 39 | struct scatterlist *src_sg; |
31 | sizeof(struct scatterlist) * bufs); | 40 | unsigned i; |
41 | |||
42 | for_each_sg(sg_next(SCp->buffer), src_sg, bufs, i) | ||
43 | *(++sg) = *src_sg; | ||
44 | sg_mark_end(sg); | ||
45 | } | ||
46 | |||
32 | return bufs + 1; | 47 | return bufs + 1; |
33 | } | 48 | } |
34 | 49 | ||
@@ -36,7 +51,7 @@ static inline int next_SCp(struct scsi_pointer *SCp) | |||
36 | { | 51 | { |
37 | int ret = SCp->buffers_residual; | 52 | int ret = SCp->buffers_residual; |
38 | if (ret) { | 53 | if (ret) { |
39 | SCp->buffer++; | 54 | SCp->buffer = sg_next(SCp->buffer); |
40 | SCp->buffers_residual--; | 55 | SCp->buffers_residual--; |
41 | SCp->ptr = sg_virt(SCp->buffer); | 56 | SCp->ptr = sg_virt(SCp->buffer); |
42 | SCp->this_residual = SCp->buffer->length; | 57 | SCp->this_residual = SCp->buffer->length; |
@@ -68,46 +83,46 @@ static inline void init_SCp(struct scsi_cmnd *SCpnt) | |||
68 | { | 83 | { |
69 | memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer)); | 84 | memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer)); |
70 | 85 | ||
71 | if (SCpnt->use_sg) { | 86 | if (scsi_bufflen(SCpnt)) { |
72 | unsigned long len = 0; | 87 | unsigned long len = 0; |
73 | int buf; | ||
74 | 88 | ||
75 | SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer; | 89 | SCpnt->SCp.buffer = scsi_sglist(SCpnt); |
76 | SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1; | 90 | SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1; |
77 | SCpnt->SCp.ptr = sg_virt(SCpnt->SCp.buffer); | 91 | SCpnt->SCp.ptr = sg_virt(SCpnt->SCp.buffer); |
78 | SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; | 92 | SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; |
79 | SCpnt->SCp.phase = SCpnt->request_bufflen; | 93 | SCpnt->SCp.phase = scsi_bufflen(SCpnt); |
80 | 94 | ||
81 | #ifdef BELT_AND_BRACES | 95 | #ifdef BELT_AND_BRACES |
82 | /* | 96 | { /* |
83 | * Calculate correct buffer length. Some commands | 97 | * Calculate correct buffer length. Some commands |
84 | * come in with the wrong request_bufflen. | 98 | * come in with the wrong scsi_bufflen. |
85 | */ | 99 | */ |
86 | for (buf = 0; buf <= SCpnt->SCp.buffers_residual; buf++) | 100 | struct scatterlist *sg; |
87 | len += SCpnt->SCp.buffer[buf].length; | 101 | unsigned i, sg_count = scsi_sg_count(SCpnt); |
88 | 102 | ||
89 | if (SCpnt->request_bufflen != len) | 103 | scsi_for_each_sg(SCpnt, sg, sg_count, i) |
90 | printk(KERN_WARNING "scsi%d.%c: bad request buffer " | 104 | len += sg->length; |
91 | "length %d, should be %ld\n", SCpnt->device->host->host_no, | 105 | |
92 | '0' + SCpnt->device->id, SCpnt->request_bufflen, len); | 106 | if (scsi_bufflen(SCpnt) != len) { |
93 | SCpnt->request_bufflen = len; | 107 | printk(KERN_WARNING |
108 | "scsi%d.%c: bad request buffer " | ||
109 | "length %d, should be %ld\n", | ||
110 | SCpnt->device->host->host_no, | ||
111 | '0' + SCpnt->device->id, | ||
112 | scsi_bufflen(SCpnt), len); | ||
113 | /* | ||
114 | * FIXME: Totaly naive fixup. We should abort | ||
115 | * with error | ||
116 | */ | ||
117 | SCpnt->SCp.phase = | ||
118 | min_t(unsigned long, len, | ||
119 | scsi_bufflen(SCpnt)); | ||
120 | } | ||
121 | } | ||
94 | #endif | 122 | #endif |
95 | } else { | 123 | } else { |
96 | SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer; | ||
97 | SCpnt->SCp.this_residual = SCpnt->request_bufflen; | ||
98 | SCpnt->SCp.phase = SCpnt->request_bufflen; | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * If the upper SCSI layers pass a buffer, but zero length, | ||
103 | * we aren't interested in the buffer pointer. | ||
104 | */ | ||
105 | if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) { | ||
106 | #if 0 //def BELT_AND_BRACES | ||
107 | printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for " | ||
108 | "command ", SCpnt->host->host_no, '0' + SCpnt->target); | ||
109 | __scsi_print_command(SCpnt->cmnd); | ||
110 | #endif | ||
111 | SCpnt->SCp.ptr = NULL; | 124 | SCpnt->SCp.ptr = NULL; |
125 | SCpnt->SCp.this_residual = 0; | ||
126 | SCpnt->SCp.phase = 0; | ||
112 | } | 127 | } |
113 | } | 128 | } |