Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Boaz Harrosh and committed by
James Bottomley
84ac86ca c9e86b8b

+57 -42
+7 -7
drivers/scsi/arm/acornscsi.c
··· 1790 1790 return 0; 1791 1791 } 1792 1792 1793 - residual = host->SCpnt->request_bufflen - host->scsi.SCp.scsi_xferred; 1793 + residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred; 1794 1794 1795 1795 sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer); 1796 1796 sbic_arm_writenext(host->scsi.io_port, residual >> 16); ··· 2270 2270 case 0x4b: /* -> PHASE_STATUSIN */ 2271 2271 case 0x8b: /* -> PHASE_STATUSIN */ 2272 2272 /* DATA IN -> STATUS */ 2273 - host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2273 + host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) - 2274 2274 acornscsi_sbic_xfcount(host); 2275 2275 acornscsi_dma_stop(host); 2276 2276 acornscsi_readstatusbyte(host); ··· 2281 2281 case 0x4e: /* -> PHASE_MSGOUT */ 2282 2282 case 0x8e: /* -> PHASE_MSGOUT */ 2283 2283 /* DATA IN -> MESSAGE OUT */ 2284 - host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2284 + host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) - 2285 2285 acornscsi_sbic_xfcount(host); 2286 2286 acornscsi_dma_stop(host); 2287 2287 acornscsi_sendmessage(host); ··· 2291 2291 case 0x4f: /* message in */ 2292 2292 case 0x8f: /* message in */ 2293 2293 /* DATA IN -> MESSAGE IN */ 2294 - host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2294 + host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) - 2295 2295 acornscsi_sbic_xfcount(host); 2296 2296 acornscsi_dma_stop(host); 2297 2297 acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */ ··· 2319 2319 case 0x4b: /* -> PHASE_STATUSIN */ 2320 2320 case 0x8b: /* -> PHASE_STATUSIN */ 2321 2321 /* DATA OUT -> STATUS */ 2322 - host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2322 + host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) - 2323 2323 acornscsi_sbic_xfcount(host); 2324 2324 acornscsi_dma_stop(host); 2325 2325 acornscsi_dma_adjust(host); ··· 2331 2331 case 0x4e: /* -> PHASE_MSGOUT */ 2332 2332 case 0x8e: /* -> PHASE_MSGOUT */ 2333 2333 /* DATA OUT -> MESSAGE OUT */ 2334 - host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2334 + host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) - 2335 2335 acornscsi_sbic_xfcount(host); 2336 2336 acornscsi_dma_stop(host); 2337 2337 acornscsi_dma_adjust(host); ··· 2342 2342 case 0x4f: /* message in */ 2343 2343 case 0x8f: /* message in */ 2344 2344 /* DATA OUT -> MESSAGE IN */ 2345 - host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2345 + host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) - 2346 2346 acornscsi_sbic_xfcount(host); 2347 2347 acornscsi_dma_stop(host); 2348 2348 acornscsi_dma_adjust(host);
+50 -35
drivers/scsi/arm/scsi.h
··· 18 18 * The scatter-gather list handling. This contains all 19 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 27 static inline int copy_SCp_to_sg(struct scatterlist *sg, struct scsi_pointer *SCp, int max) 22 28 { 23 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 34 BUG_ON(bufs + 1 > max); 26 35 27 36 sg_set_buf(sg, SCp->ptr, SCp->this_residual); 28 37 29 - if (bufs) 30 - memcpy(sg + 1, SCp->buffer + 1, 31 - sizeof(struct scatterlist) * bufs); 38 + if (bufs) { 39 + struct scatterlist *src_sg; 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 47 return bufs + 1; 33 48 } 34 49 ··· 51 36 { 52 37 int ret = SCp->buffers_residual; 53 38 if (ret) { 54 - SCp->buffer++; 39 + SCp->buffer = sg_next(SCp->buffer); 55 40 SCp->buffers_residual--; 56 41 SCp->ptr = sg_virt(SCp->buffer); 57 42 SCp->this_residual = SCp->buffer->length; ··· 83 68 { 84 69 memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer)); 85 70 86 - if (SCpnt->use_sg) { 71 + if (scsi_bufflen(SCpnt)) { 87 72 unsigned long len = 0; 88 - int buf; 89 73 90 - SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer; 91 - SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1; 74 + SCpnt->SCp.buffer = scsi_sglist(SCpnt); 75 + SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1; 92 76 SCpnt->SCp.ptr = sg_virt(SCpnt->SCp.buffer); 93 77 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; 94 - SCpnt->SCp.phase = SCpnt->request_bufflen; 78 + SCpnt->SCp.phase = scsi_bufflen(SCpnt); 95 79 96 80 #ifdef BELT_AND_BRACES 97 - /* 98 - * Calculate correct buffer length. Some commands 99 - * come in with the wrong request_bufflen. 100 - */ 101 - for (buf = 0; buf <= SCpnt->SCp.buffers_residual; buf++) 102 - len += SCpnt->SCp.buffer[buf].length; 81 + { /* 82 + * Calculate correct buffer length. Some commands 83 + * come in with the wrong scsi_bufflen. 84 + */ 85 + struct scatterlist *sg; 86 + unsigned i, sg_count = scsi_sg_count(SCpnt); 103 87 104 - if (SCpnt->request_bufflen != len) 105 - printk(KERN_WARNING "scsi%d.%c: bad request buffer " 106 - "length %d, should be %ld\n", SCpnt->device->host->host_no, 107 - '0' + SCpnt->device->id, SCpnt->request_bufflen, len); 108 - SCpnt->request_bufflen = len; 88 + scsi_for_each_sg(SCpnt, sg, sg_count, i) 89 + len += sg->length; 90 + 91 + if (scsi_bufflen(SCpnt) != len) { 92 + printk(KERN_WARNING 93 + "scsi%d.%c: bad request buffer " 94 + "length %d, should be %ld\n", 95 + SCpnt->device->host->host_no, 96 + '0' + SCpnt->device->id, 97 + scsi_bufflen(SCpnt), len); 98 + /* 99 + * FIXME: Totaly naive fixup. We should abort 100 + * with error 101 + */ 102 + SCpnt->SCp.phase = 103 + min_t(unsigned long, len, 104 + scsi_bufflen(SCpnt)); 105 + } 106 + } 109 107 #endif 110 108 } else { 111 - SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer; 112 - SCpnt->SCp.this_residual = SCpnt->request_bufflen; 113 - SCpnt->SCp.phase = SCpnt->request_bufflen; 114 - } 115 - 116 - /* 117 - * If the upper SCSI layers pass a buffer, but zero length, 118 - * we aren't interested in the buffer pointer. 119 - */ 120 - if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) { 121 - #if 0 //def BELT_AND_BRACES 122 - printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for " 123 - "command ", SCpnt->host->host_no, '0' + SCpnt->target); 124 - __scsi_print_command(SCpnt->cmnd); 125 - #endif 126 109 SCpnt->SCp.ptr = NULL; 110 + SCpnt->SCp.this_residual = 0; 111 + SCpnt->SCp.phase = 0; 127 112 } 128 113 }