Commit 63c651e4 authored by Matthew Dharm's avatar Matthew Dharm Committed by Greg Kroah-Hartman

[PATCH] USB storage: macro-ize address manipulation

This patch converts all uses of page_addres() to the sg_address() macro.
This will make backporting to 2.4 easier, as well as eliminate lots of
redundant code.
parent 48079d84
......@@ -189,7 +189,7 @@ void usb_stor_print_Scsi_Cmnd( Scsi_Cmnd* cmd )
US_DEBUGP("Buffer has %d scatterlists.\n", cmd->use_sg );
for ( i=0; i<cmd->use_sg; i++ )
{
char *adr = page_address(sg[i].page) + sg[i].offset;
char *adr = sg_address(sg[i]);
US_DEBUGP("Length of scatterlist %d is %d.\n",i,sg[i].length);
US_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x\n"
......
......@@ -48,7 +48,7 @@
#include <linux/kernel.h>
#include <linux/blk.h>
#include <linux/cdrom.h>
#include "scsi.h"
#include "usb.h"
#define USB_STORAGE "usb-storage: "
......
......@@ -148,11 +148,11 @@ static void us_transfer_freecom(Scsi_Cmnd *srb, struct us_data* us, int transfer
if (transfer_amount - total_transferred >=
sg[i].length) {
result = usb_stor_transfer_partial(us,
page_address(sg[i].page) + sg[i].offset, sg[i].length);
sg_address(sg[i]), sg[i].length);
total_transferred += sg[i].length;
} else {
result = usb_stor_transfer_partial(us,
page_address(sg[i].page) + sg[i].offset,
sg_address(sg[i]),
transfer_amount - total_transferred);
total_transferred += transfer_amount - total_transferred;
}
......
......@@ -501,13 +501,13 @@ static void isd200_transfer( struct us_data *us, Scsi_Cmnd *srb )
sg[i].length) {
result = isd200_transfer_partial(us,
srb->sc_data_direction,
page_address(sg[i].page) + sg[i].offset,
sg_address(sg[i]),
sg[i].length);
total_transferred += sg[i].length;
} else
result = isd200_transfer_partial(us,
srb->sc_data_direction,
page_address(sg[i].page) + sg[i].offset,
sg_address(sg[i]),
transfer_amount - total_transferred);
/* if we get an error, end the loop here */
......@@ -1409,10 +1409,10 @@ void isd200_data_copy(Scsi_Cmnd *srb, char * src, int length)
/* transfer the lesser of the next buffer or the
* remaining data */
if (len - total >= sg[i].length) {
memcpy(page_address(sg[i].page) + sg[i].offset, src + total, sg[i].length);
memcpy(sg_address(sg[i]), src + total, sg[i].length);
total += sg[i].length;
} else {
memcpy(page_address(sg[i].page) + sg[i].offset, src + total, len - total);
memcpy(sg_address(sg[i]), src + total, len - total);
total = len;
}
}
......
......@@ -65,7 +65,7 @@ find_data_location(Scsi_Cmnd *srb) {
struct scatterlist *sg;
sg = (struct scatterlist *) srb->request_buffer;
return (void *) page_address(sg[0].page) + sg[0].offset;
return (void *) sg_address(sg[0]);
} else
return (void *) srb->request_buffer;
}
......
......@@ -191,7 +191,7 @@ usb_storage_bulk_transport(struct us_data *us, int direction,
unsigned char *buf;
unsigned int length;
buf = page_address(sg[i].page) + sg[i].offset;
buf = sg_address(sg[i]);
length = len-transferred;
if (length > sg[i].length)
length = sg[i].length;
......@@ -261,7 +261,7 @@ us_copy_from_sgbuf(unsigned char *content, int len,
unsigned char *ptr;
unsigned int length, room;
ptr = page_address(sg[i].page) + sg[i].offset + *offset;
ptr = sg_address(sg[i]) + *offset;
room = sg[i].length - *offset;
length = len - transferred;
......@@ -310,7 +310,7 @@ us_copy_to_sgbuf(unsigned char *buffer, int buflen,
unsigned char *ptr;
unsigned int length, room;
ptr = page_address(sg[i].page) + sg[i].offset + *offset;
ptr = sg_address(sg[i]) + *offset;
room = sg[i].length - *offset;
length = buflen - transferred;
......
......@@ -563,8 +563,8 @@ int usb_stor_scsiSense10to6( Scsi_Cmnd* the10 )
/* copy one byte */
{
char *src = page_address(sg[sb].page) + sg[sb].offset + si;
char *dst = page_address(sg[db].page) + sg[db].offset + di;
char *src = sg_address(sg[sb]) + si;
char *dst = sg_address(sg[db]) + di;
*dst = *src;
}
......@@ -605,7 +605,7 @@ int usb_stor_scsiSense10to6( Scsi_Cmnd* the10 )
break;
}
*(char*)(page_address(sg[db].page) + sg[db].offset) = 0;
*(char*)(sg_address(sg[db])) = 0;
/* get next destination */
if ( sg[db].length-1 == di )
......@@ -756,8 +756,8 @@ int usb_stor_scsiSense6to10( Scsi_Cmnd* the6 )
/* copy one byte */
{
char *src = page_address(sg[sb].page) + sg[sb].offset + si;
char *dst = page_address(sg[db].page) + sg[db].offset + di;
char *src = sg_address(sg[sb]) + si;
char *dst = sg_address(sg[db]) + di;
*dst = *src;
}
......@@ -798,7 +798,7 @@ int usb_stor_scsiSense6to10( Scsi_Cmnd* the6 )
}
{
char *dst = page_address(sg[db].page) + sg[db].offset + di;
char *dst = sg_address(sg[db]) + di;
*dst = tempBuffer[element-USB_STOR_SCSI_SENSE_HDRSZ];
}
......@@ -852,17 +852,14 @@ void usb_stor_scsiSenseParseBuffer( Scsi_Cmnd* srb, Usb_Stor_Scsi_Sense_Hdr_u* t
if ( element < USB_STOR_SCSI_SENSE_HDRSZ )
{
/* fill in the pointers for both header types */
the6->array[element] = page_address(sg[i].page) +
sg[i].offset + j;
the10->array[element] = page_address(sg[i].page) +
sg[i].offset + j;
the6->array[element] = sg_address(sg[i]) + j;
the10->array[element] = sg_address(sg[i]) + j;
}
else if ( element < USB_STOR_SCSI_SENSE_10_HDRSZ )
{
/* only the longer headers still cares now */
the10->array[element] = page_address(sg[i].page) +
sg[i].offset + j;
the10->array[element] = sg_address(sg[i]) + j;
}
/* increase element counter */
......
......@@ -1091,25 +1091,23 @@ sddr09_read_map(struct us_data *us) {
return 0;
for (i=0; i<alloc_blocks; i++) {
if (i<alloc_blocks-1) {
char *vaddr = kmalloc(1 << 17, GFP_NOIO);
sg[i].page = virt_to_page(vaddr);
sg[i].offset = ((unsigned long)vaddr & ~PAGE_MASK);
sg[i].length = (1<<17);
} else {
char *vaddr = kmalloc(alloc_len, GFP_NOIO);
sg[i].page = virt_to_page(vaddr);
sg[i].offset = ((unsigned long)vaddr & ~PAGE_MASK);
sg[i].length = alloc_len;
}
alloc_len -= sg[i].length;
int alloc_req = (i < alloc_blocks-1 ? 1 << 17 : alloc_len);
char *vaddr = kmalloc(alloc_req, GFP_NOIO);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
sg[i].page = virt_to_page(vaddr);
sg[i].offset = ((unsigned long)vaddr & ~PAGE_MASK);
#else
sg[i].address = vaddr;
#endif
sg[i].length = alloc_req;
alloc_len -= alloc_req;
}
for (i=0; i<alloc_blocks; i++)
if (sg[i].page == NULL) {
for (i=0; i<alloc_blocks; i++)
if (sg[i].page != NULL)
kfree(page_address(sg[i].page) + sg[i].offset);
kfree(sg_address(sg[i]));
kfree(sg);
return 0;
}
......@@ -1120,7 +1118,7 @@ sddr09_read_map(struct us_data *us) {
(unsigned char *)sg, alloc_blocks);
if (result != USB_STOR_TRANSPORT_GOOD) {
for (i=0; i<alloc_blocks; i++)
kfree(page_address(sg[i].page) + sg[i].offset);
kfree(sg_address(sg[i]));
kfree(sg);
return -1;
}
......@@ -1136,7 +1134,7 @@ sddr09_read_map(struct us_data *us) {
info->lba_to_pba = NULL;
info->pba_to_lba = NULL;
for (i=0; i<alloc_blocks; i++)
kfree(page_address(sg[i].page) + sg[i].offset);
kfree(sg_address(sg[i]));
kfree(sg);
return 0;
}
......@@ -1144,7 +1142,7 @@ sddr09_read_map(struct us_data *us) {
for (i = 0; i < numblocks; i++)
info->lba_to_pba[i] = info->pba_to_lba[i] = UNDEF;
ptr = page_address(sg[0].page)+sg[0].offset;
ptr = sg_address(sg[0]);
/*
* Define lba-pba translation table
......@@ -1153,8 +1151,7 @@ sddr09_read_map(struct us_data *us) {
// scatterlist block i*64/128k = i*(2^6)*(2^-17) = i*(2^-11)
for (i=0; i<numblocks; i++) {
ptr = page_address(sg[i>>11].page) +
sg[i>>11].offset + ((i&0x7ff)<<6);
ptr = sg_address(sg[i>>11]) + ((i&0x7ff)<<6);
if (i == 0 || i == 1) {
info->pba_to_lba[i] = UNUSABLE;
......@@ -1264,7 +1261,7 @@ sddr09_read_map(struct us_data *us) {
US_DEBUGP("Found %d LBA's\n", lbact);
for (i=0; i<alloc_blocks; i++)
kfree(page_address(sg[i].page) + sg[i].offset);
kfree(sg_address(sg[i]));
kfree(sg);
return 0;
}
......
......@@ -641,11 +641,11 @@ void usb_stor_transfer(Scsi_Cmnd *srb, struct us_data* us)
if (transfer_amount - total_transferred >=
sg[i].length) {
result = usb_stor_transfer_partial(us,
page_address(sg[i].page) + sg[i].offset, sg[i].length);
sg_address(sg[i]), sg[i].length);
total_transferred += sg[i].length;
} else
result = usb_stor_transfer_partial(us,
page_address(sg[i].page) + sg[i].offset,
sg_address(sg[i]),
transfer_amount - total_transferred);
/* if we get an error, end the loop here */
......
......@@ -283,13 +283,13 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data,
if (us->srb->use_sg) {
sg = (struct scatterlist *)us->srb->request_buffer;
for (i=0; i<us->srb->use_sg; i++)
memset(page_address(sg[i].page) + sg[i].offset, 0, sg[i].length);
memset(sg_address(sg[i]), 0, sg[i].length);
for (i=0, transferred=0;
i<us->srb->use_sg && transferred < len;
i++) {
amt = sg[i].length > len-transferred ?
len-transferred : sg[i].length;
memcpy(page_address(sg[i].page) + sg[i].offset, data+transferred, amt);
memcpy(sg_address(sg[i]), data+transferred, amt);
transferred -= amt;
}
} else {
......
......@@ -206,7 +206,6 @@ extern void fill_inquiry_response(struct us_data *us,
* single queue element srb for write access */
#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
#define scsi_lock(host) spin_lock_irq(host->host_lock)
#define sg_address(psg) (page_address((psg)->page) + (psg)->offset)
#define sg_address(psg) (page_address((psg).page) + (psg).offset)
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment