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

[SCSI] usb: protocol - convert to accessors and !use_sg code path removal

- Use scsi data accessors and remove of !use_sg code path

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Acked-by: Matthew Dharm <mdharm-scsi@one-eyed-alien.net>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>

authored by

Boaz Harrosh and committed by
James Bottomley
dd829d23 caa1e8c3

+48 -68
+48 -68
drivers/usb/storage/protocol.c
··· 149 149 ***********************************************************************/ 150 150 151 151 /* Copy a buffer of length buflen to/from the srb's transfer buffer. 152 - * (Note: for scatter-gather transfers (srb->use_sg > 0), srb->request_buffer 153 - * points to a list of s-g entries and we ignore srb->request_bufflen. 154 - * For non-scatter-gather transfers, srb->request_buffer points to the 155 - * transfer buffer itself and srb->request_bufflen is the buffer's length.) 156 - * Update the *index and *offset variables so that the next copy will 152 + * Update the **sgptr and *offset variables so that the next copy will 157 153 * pick up from where this one left off. */ 158 154 159 155 unsigned int usb_stor_access_xfer_buf(unsigned char *buffer, ··· 158 162 { 159 163 unsigned int cnt; 160 164 161 - /* If not using scatter-gather, just transfer the data directly. 162 - * Make certain it will fit in the available buffer space. */ 163 - if (srb->use_sg == 0) { 164 - if (*offset >= srb->request_bufflen) 165 - return 0; 166 - cnt = min(buflen, srb->request_bufflen - *offset); 167 - if (dir == TO_XFER_BUF) 168 - memcpy((unsigned char *) srb->request_buffer + *offset, 169 - buffer, cnt); 170 - else 171 - memcpy(buffer, (unsigned char *) srb->request_buffer + 172 - *offset, cnt); 173 - *offset += cnt; 174 - 175 - /* Using scatter-gather. We have to go through the list one entry 165 + /* We have to go through the list one entry 176 166 * at a time. Each s-g entry contains some number of pages, and 177 167 * each page has to be kmap()'ed separately. If the page is already 178 168 * in kernel-addressable memory then kmap() will return its address. 179 169 * If the page is not directly accessible -- such as a user buffer 180 170 * located in high memory -- then kmap() will map it to a temporary 181 171 * position in the kernel's virtual address space. */ 182 - } else { 183 - struct scatterlist *sg = *sgptr; 172 + struct scatterlist *sg = *sgptr; 184 173 185 - if (!sg) 186 - sg = (struct scatterlist *) srb->request_buffer; 174 + if (!sg) 175 + sg = scsi_sglist(srb); 187 176 188 - /* This loop handles a single s-g list entry, which may 189 - * include multiple pages. Find the initial page structure 190 - * and the starting offset within the page, and update 191 - * the *offset and *index values for the next loop. */ 192 - cnt = 0; 193 - while (cnt < buflen) { 194 - struct page *page = sg_page(sg) + 195 - ((sg->offset + *offset) >> PAGE_SHIFT); 196 - unsigned int poff = 197 - (sg->offset + *offset) & (PAGE_SIZE-1); 198 - unsigned int sglen = sg->length - *offset; 177 + /* This loop handles a single s-g list entry, which may 178 + * include multiple pages. Find the initial page structure 179 + * and the starting offset within the page, and update 180 + * the *offset and **sgptr values for the next loop. */ 181 + cnt = 0; 182 + while (cnt < buflen) { 183 + struct page *page = sg_page(sg) + 184 + ((sg->offset + *offset) >> PAGE_SHIFT); 185 + unsigned int poff = 186 + (sg->offset + *offset) & (PAGE_SIZE-1); 187 + unsigned int sglen = sg->length - *offset; 199 188 200 - if (sglen > buflen - cnt) { 189 + if (sglen > buflen - cnt) { 201 190 202 - /* Transfer ends within this s-g entry */ 203 - sglen = buflen - cnt; 204 - *offset += sglen; 205 - } else { 191 + /* Transfer ends within this s-g entry */ 192 + sglen = buflen - cnt; 193 + *offset += sglen; 194 + } else { 206 195 207 - /* Transfer continues to next s-g entry */ 208 - *offset = 0; 209 - sg = sg_next(sg); 210 - } 211 - 212 - /* Transfer the data for all the pages in this 213 - * s-g entry. For each page: call kmap(), do the 214 - * transfer, and call kunmap() immediately after. */ 215 - while (sglen > 0) { 216 - unsigned int plen = min(sglen, (unsigned int) 217 - PAGE_SIZE - poff); 218 - unsigned char *ptr = kmap(page); 219 - 220 - if (dir == TO_XFER_BUF) 221 - memcpy(ptr + poff, buffer + cnt, plen); 222 - else 223 - memcpy(buffer + cnt, ptr + poff, plen); 224 - kunmap(page); 225 - 226 - /* Start at the beginning of the next page */ 227 - poff = 0; 228 - ++page; 229 - cnt += plen; 230 - sglen -= plen; 231 - } 196 + /* Transfer continues to next s-g entry */ 197 + *offset = 0; 198 + sg = sg_next(sg); 232 199 } 233 - *sgptr = sg; 200 + 201 + /* Transfer the data for all the pages in this 202 + * s-g entry. For each page: call kmap(), do the 203 + * transfer, and call kunmap() immediately after. */ 204 + while (sglen > 0) { 205 + unsigned int plen = min(sglen, (unsigned int) 206 + PAGE_SIZE - poff); 207 + unsigned char *ptr = kmap(page); 208 + 209 + if (dir == TO_XFER_BUF) 210 + memcpy(ptr + poff, buffer + cnt, plen); 211 + else 212 + memcpy(buffer + cnt, ptr + poff, plen); 213 + kunmap(page); 214 + 215 + /* Start at the beginning of the next page */ 216 + poff = 0; 217 + ++page; 218 + cnt += plen; 219 + sglen -= plen; 220 + } 234 221 } 222 + *sgptr = sg; 235 223 236 224 /* Return the amount actually transferred */ 237 225 return cnt; ··· 231 251 232 252 usb_stor_access_xfer_buf(buffer, buflen, srb, &sg, &offset, 233 253 TO_XFER_BUF); 234 - if (buflen < srb->request_bufflen) 235 - srb->resid = srb->request_bufflen - buflen; 254 + if (buflen < scsi_bufflen(srb)) 255 + scsi_set_resid(srb, scsi_bufflen(srb) - buflen); 236 256 }