aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/um/drivers/ubd_kern.c2
-rw-r--r--drivers/ata/libata-core.c10
-rw-r--r--drivers/ata/libata-scsi.c2
-rw-r--r--drivers/block/DAC960.c2
-rw-r--r--drivers/block/cciss.c4
-rw-r--r--drivers/block/cpqarray.c3
-rw-r--r--drivers/block/cryptoloop.c12
-rw-r--r--drivers/block/sunvdc.c1
-rw-r--r--drivers/block/sx8.c1
-rw-r--r--drivers/block/ub.c11
-rw-r--r--drivers/block/viodasd.c2
-rw-r--r--drivers/ide/cris/ide-cris.c4
-rw-r--r--drivers/ide/ide-probe.c4
-rw-r--r--drivers/ide/ide-taskfile.c2
-rw-r--r--drivers/ide/mips/au1xxx-ide.c6
-rw-r--r--drivers/ieee1394/dma.c2
-rw-r--r--drivers/ieee1394/sbp2.c2
-rw-r--r--drivers/infiniband/core/umem.c11
-rw-r--r--drivers/infiniband/hw/ipath/ipath_dma.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_mr.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c24
-rw-r--r--drivers/infiniband/ulp/iser/iser_memory.c8
-rw-r--r--drivers/md/dm-crypt.c21
-rw-r--r--drivers/media/common/saa7146_core.c3
-rw-r--r--drivers/media/video/ivtv/ivtv-udma.c4
-rw-r--r--drivers/media/video/videobuf-dma-sg.c8
-rw-r--r--drivers/mmc/card/queue.c15
-rw-r--r--drivers/mmc/host/at91_mci.c8
-rw-r--r--drivers/mmc/host/au1xmmc.c11
-rw-r--r--drivers/mmc/host/imxmmc.c2
-rw-r--r--drivers/mmc/host/mmc_spi.c8
-rw-r--r--drivers/mmc/host/omap.c4
-rw-r--r--drivers/mmc/host/sdhci.c2
-rw-r--r--drivers/mmc/host/tifm_sd.c8
-rw-r--r--drivers/mmc/host/wbsd.c6
-rw-r--r--drivers/net/mlx4/icm.c14
-rw-r--r--drivers/net/ppp_mppe.c6
-rw-r--r--drivers/scsi/3w-9xxx.c4
-rw-r--r--drivers/scsi/3w-xxxx.c2
-rw-r--r--drivers/scsi/NCR5380.c6
-rw-r--r--drivers/scsi/NCR53C9x.c4
-rw-r--r--drivers/scsi/NCR53c406a.c6
-rw-r--r--drivers/scsi/aacraid/aachba.c2
-rw-r--r--drivers/scsi/aha152x.c2
-rw-r--r--drivers/scsi/aha1542.c8
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c4
-rw-r--r--drivers/scsi/atari_NCR5380.c6
-rw-r--r--drivers/scsi/eata_pio.c4
-rw-r--r--drivers/scsi/fd_mcs.c6
-rw-r--r--drivers/scsi/fdomain.c7
-rw-r--r--drivers/scsi/gdth.c6
-rw-r--r--drivers/scsi/ibmmca.c2
-rw-r--r--drivers/scsi/ide-scsi.c12
-rw-r--r--drivers/scsi/imm.c8
-rw-r--r--drivers/scsi/in2000.c4
-rw-r--r--drivers/scsi/ipr.c19
-rw-r--r--drivers/scsi/ips.c6
-rw-r--r--drivers/scsi/iscsi_tcp.c15
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c12
-rw-r--r--drivers/scsi/oktagon_esp.c6
-rw-r--r--drivers/scsi/osst.c32
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.h2
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c6
-rw-r--r--drivers/scsi/ppa.c7
-rw-r--r--drivers/scsi/ps3rom.c6
-rw-r--r--drivers/scsi/qlogicfas408.c2
-rw-r--r--drivers/scsi/scsi_debug.c4
-rw-r--r--drivers/scsi/scsi_lib.c13
-rw-r--r--drivers/scsi/seagate.c8
-rw-r--r--drivers/scsi/sg.c30
-rw-r--r--drivers/scsi/st.c8
-rw-r--r--drivers/scsi/sun3_NCR5380.c3
-rw-r--r--drivers/scsi/sym53c416.c2
-rw-r--r--drivers/scsi/tmscsim.c5
-rw-r--r--drivers/scsi/ultrastor.c2
-rw-r--r--drivers/scsi/wd33c93.c6
-rw-r--r--drivers/scsi/wd7000.c2
-rw-r--r--drivers/usb/core/message.c6
-rw-r--r--drivers/usb/image/microtek.c5
-rw-r--r--drivers/usb/misc/usbtest.c4
-rw-r--r--drivers/usb/storage/protocol.c2
82 files changed, 278 insertions, 275 deletions
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 25b248a02507..3a8cd3dfb51c 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1115,7 +1115,7 @@ static void do_ubd_request(struct request_queue *q)
1115 } 1115 }
1116 prepare_request(req, io_req, 1116 prepare_request(req, io_req,
1117 (unsigned long long) req->sector << 9, 1117 (unsigned long long) req->sector << 9,
1118 sg->offset, sg->length, sg->page); 1118 sg->offset, sg->length, sg_page(sg));
1119 1119
1120 last_sectors = sg->length >> 9; 1120 last_sectors = sg->length >> 9;
1121 n = os_write_file(thread_fd, &io_req, 1121 n = os_write_file(thread_fd, &io_req,
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 629eadbd0ec0..69092bce1ada 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4296,7 +4296,7 @@ void ata_sg_clean(struct ata_queued_cmd *qc)
4296 sg_last(sg, qc->orig_n_elem)->length += qc->pad_len; 4296 sg_last(sg, qc->orig_n_elem)->length += qc->pad_len;
4297 if (pad_buf) { 4297 if (pad_buf) {
4298 struct scatterlist *psg = &qc->pad_sgent; 4298 struct scatterlist *psg = &qc->pad_sgent;
4299 void *addr = kmap_atomic(psg->page, KM_IRQ0); 4299 void *addr = kmap_atomic(sg_page(psg), KM_IRQ0);
4300 memcpy(addr + psg->offset, pad_buf, qc->pad_len); 4300 memcpy(addr + psg->offset, pad_buf, qc->pad_len);
4301 kunmap_atomic(addr, KM_IRQ0); 4301 kunmap_atomic(addr, KM_IRQ0);
4302 } 4302 }
@@ -4686,11 +4686,11 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
4686 * data in this function or read data in ata_sg_clean. 4686 * data in this function or read data in ata_sg_clean.
4687 */ 4687 */
4688 offset = lsg->offset + lsg->length - qc->pad_len; 4688 offset = lsg->offset + lsg->length - qc->pad_len;
4689 psg->page = nth_page(lsg->page, offset >> PAGE_SHIFT); 4689 sg_set_page(psg, nth_page(sg_page(lsg), offset >> PAGE_SHIFT));
4690 psg->offset = offset_in_page(offset); 4690 psg->offset = offset_in_page(offset);
4691 4691
4692 if (qc->tf.flags & ATA_TFLAG_WRITE) { 4692 if (qc->tf.flags & ATA_TFLAG_WRITE) {
4693 void *addr = kmap_atomic(psg->page, KM_IRQ0); 4693 void *addr = kmap_atomic(sg_page(psg), KM_IRQ0);
4694 memcpy(pad_buf, addr + psg->offset, qc->pad_len); 4694 memcpy(pad_buf, addr + psg->offset, qc->pad_len);
4695 kunmap_atomic(addr, KM_IRQ0); 4695 kunmap_atomic(addr, KM_IRQ0);
4696 } 4696 }
@@ -4836,7 +4836,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
4836 if (qc->curbytes == qc->nbytes - qc->sect_size) 4836 if (qc->curbytes == qc->nbytes - qc->sect_size)
4837 ap->hsm_task_state = HSM_ST_LAST; 4837 ap->hsm_task_state = HSM_ST_LAST;
4838 4838
4839 page = qc->cursg->page; 4839 page = sg_page(qc->cursg);
4840 offset = qc->cursg->offset + qc->cursg_ofs; 4840 offset = qc->cursg->offset + qc->cursg_ofs;
4841 4841
4842 /* get the current page and offset */ 4842 /* get the current page and offset */
@@ -4988,7 +4988,7 @@ next_sg:
4988 4988
4989 sg = qc->cursg; 4989 sg = qc->cursg;
4990 4990
4991 page = sg->page; 4991 page = sg_page(sg);
4992 offset = sg->offset + qc->cursg_ofs; 4992 offset = sg->offset + qc->cursg_ofs;
4993 4993
4994 /* get the current page and offset */ 4994 /* get the current page and offset */
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 9fbb39cd0f58..5b758b9ad0b8 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1544,7 +1544,7 @@ static unsigned int ata_scsi_rbuf_get(struct scsi_cmnd *cmd, u8 **buf_out)
1544 struct scatterlist *sg = scsi_sglist(cmd); 1544 struct scatterlist *sg = scsi_sglist(cmd);
1545 1545
1546 if (sg) { 1546 if (sg) {
1547 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1547 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1548 buflen = sg->length; 1548 buflen = sg->length;
1549 } else { 1549 } else {
1550 buf = NULL; 1550 buf = NULL;
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 84d6aa500e26..53505422867c 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -345,6 +345,7 @@ static bool DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
345 Command->V1.ScatterGatherList = 345 Command->V1.ScatterGatherList =
346 (DAC960_V1_ScatterGatherSegment_T *)ScatterGatherCPU; 346 (DAC960_V1_ScatterGatherSegment_T *)ScatterGatherCPU;
347 Command->V1.ScatterGatherListDMA = ScatterGatherDMA; 347 Command->V1.ScatterGatherListDMA = ScatterGatherDMA;
348 sg_init_table(Command->cmd_sglist, DAC960_V1_ScatterGatherLimit);
348 } else { 349 } else {
349 Command->cmd_sglist = Command->V2.ScatterList; 350 Command->cmd_sglist = Command->V2.ScatterList;
350 Command->V2.ScatterGatherList = 351 Command->V2.ScatterGatherList =
@@ -353,6 +354,7 @@ static bool DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
353 Command->V2.RequestSense = 354 Command->V2.RequestSense =
354 (DAC960_SCSI_RequestSense_T *)RequestSenseCPU; 355 (DAC960_SCSI_RequestSense_T *)RequestSenseCPU;
355 Command->V2.RequestSenseDMA = RequestSenseDMA; 356 Command->V2.RequestSenseDMA = RequestSenseDMA;
357 sg_init_table(Command->cmd_sglist, DAC960_V2_ScatterGatherLimit);
356 } 358 }
357 } 359 }
358 return true; 360 return true;
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 7c2cfde08f18..5a6fe17fc638 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -2610,7 +2610,7 @@ static void do_cciss_request(struct request_queue *q)
2610 (int)creq->nr_sectors); 2610 (int)creq->nr_sectors);
2611#endif /* CCISS_DEBUG */ 2611#endif /* CCISS_DEBUG */
2612 2612
2613 memset(tmp_sg, 0, sizeof(tmp_sg)); 2613 sg_init_table(tmp_sg, MAXSGENTRIES);
2614 seg = blk_rq_map_sg(q, creq, tmp_sg); 2614 seg = blk_rq_map_sg(q, creq, tmp_sg);
2615 2615
2616 /* get the DMA records for the setup */ 2616 /* get the DMA records for the setup */
@@ -2621,7 +2621,7 @@ static void do_cciss_request(struct request_queue *q)
2621 2621
2622 for (i = 0; i < seg; i++) { 2622 for (i = 0; i < seg; i++) {
2623 c->SG[i].Len = tmp_sg[i].length; 2623 c->SG[i].Len = tmp_sg[i].length;
2624 temp64.val = (__u64) pci_map_page(h->pdev, tmp_sg[i].page, 2624 temp64.val = (__u64) pci_map_page(h->pdev, sg_page(&tmp_sg[i]),
2625 tmp_sg[i].offset, 2625 tmp_sg[i].offset,
2626 tmp_sg[i].length, dir); 2626 tmp_sg[i].length, dir);
2627 c->SG[i].Addr.lower = temp64.val32.lower; 2627 c->SG[i].Addr.lower = temp64.val32.lower;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 568603d3043e..efab27fa1083 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -918,6 +918,7 @@ queue_next:
918DBGPX( 918DBGPX(
919 printk("sector=%d, nr_sectors=%d\n", creq->sector, creq->nr_sectors); 919 printk("sector=%d, nr_sectors=%d\n", creq->sector, creq->nr_sectors);
920); 920);
921 sg_init_table(tmp_sg, SG_MAX);
921 seg = blk_rq_map_sg(q, creq, tmp_sg); 922 seg = blk_rq_map_sg(q, creq, tmp_sg);
922 923
923 /* Now do all the DMA Mappings */ 924 /* Now do all the DMA Mappings */
@@ -929,7 +930,7 @@ DBGPX(
929 { 930 {
930 c->req.sg[i].size = tmp_sg[i].length; 931 c->req.sg[i].size = tmp_sg[i].length;
931 c->req.sg[i].addr = (__u32) pci_map_page(h->pci_dev, 932 c->req.sg[i].addr = (__u32) pci_map_page(h->pci_dev,
932 tmp_sg[i].page, 933 sg_page(&tmp_sg[i]),
933 tmp_sg[i].offset, 934 tmp_sg[i].offset,
934 tmp_sg[i].length, dir); 935 tmp_sg[i].length, dir);
935 } 936 }
diff --git a/drivers/block/cryptoloop.c b/drivers/block/cryptoloop.c
index 40535036e893..1b58b010797f 100644
--- a/drivers/block/cryptoloop.c
+++ b/drivers/block/cryptoloop.c
@@ -26,6 +26,7 @@
26#include <linux/crypto.h> 26#include <linux/crypto.h>
27#include <linux/blkdev.h> 27#include <linux/blkdev.h>
28#include <linux/loop.h> 28#include <linux/loop.h>
29#include <linux/scatterlist.h>
29#include <asm/semaphore.h> 30#include <asm/semaphore.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31 32
@@ -119,14 +120,17 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
119 .tfm = tfm, 120 .tfm = tfm,
120 .flags = CRYPTO_TFM_REQ_MAY_SLEEP, 121 .flags = CRYPTO_TFM_REQ_MAY_SLEEP,
121 }; 122 };
122 struct scatterlist sg_out = { NULL, }; 123 struct scatterlist sg_out;
123 struct scatterlist sg_in = { NULL, }; 124 struct scatterlist sg_in;
124 125
125 encdec_cbc_t encdecfunc; 126 encdec_cbc_t encdecfunc;
126 struct page *in_page, *out_page; 127 struct page *in_page, *out_page;
127 unsigned in_offs, out_offs; 128 unsigned in_offs, out_offs;
128 int err; 129 int err;
129 130
131 sg_init_table(&sg_out, 1);
132 sg_init_table(&sg_in, 1);
133
130 if (cmd == READ) { 134 if (cmd == READ) {
131 in_page = raw_page; 135 in_page = raw_page;
132 in_offs = raw_off; 136 in_offs = raw_off;
@@ -146,11 +150,11 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
146 u32 iv[4] = { 0, }; 150 u32 iv[4] = { 0, };
147 iv[0] = cpu_to_le32(IV & 0xffffffff); 151 iv[0] = cpu_to_le32(IV & 0xffffffff);
148 152
149 sg_in.page = in_page; 153 sg_set_page(&sg_in, in_page);
150 sg_in.offset = in_offs; 154 sg_in.offset = in_offs;
151 sg_in.length = sz; 155 sg_in.length = sz;
152 156
153 sg_out.page = out_page; 157 sg_set_page(&sg_out, out_page);
154 sg_out.offset = out_offs; 158 sg_out.offset = out_offs;
155 sg_out.length = sz; 159 sg_out.length = sz;
156 160
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 317a790c153b..7276f7d207c2 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -388,6 +388,7 @@ static int __send_request(struct request *req)
388 op = VD_OP_BWRITE; 388 op = VD_OP_BWRITE;
389 } 389 }
390 390
391 sg_init_table(sg, port->ring_cookies);
391 nsg = blk_rq_map_sg(req->q, req, sg); 392 nsg = blk_rq_map_sg(req->q, req, sg);
392 393
393 len = 0; 394 len = 0;
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index 402209fec59a..282a69558e8a 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -522,6 +522,7 @@ static struct carm_request *carm_get_request(struct carm_host *host)
522 host->n_msgs++; 522 host->n_msgs++;
523 523
524 assert(host->n_msgs <= CARM_MAX_REQ); 524 assert(host->n_msgs <= CARM_MAX_REQ);
525 sg_init_table(crq->sg, CARM_MAX_REQ_SG);
525 return crq; 526 return crq;
526 } 527 }
527 528
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index c57dd2b3a0c8..14143f2c484d 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -25,6 +25,7 @@
25#include <linux/usb_usual.h> 25#include <linux/usb_usual.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/timer.h> 27#include <linux/timer.h>
28#include <linux/scatterlist.h>
28#include <scsi/scsi.h> 29#include <scsi/scsi.h>
29 30
30#define DRV_NAME "ub" 31#define DRV_NAME "ub"
@@ -656,6 +657,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
656 if ((cmd = ub_get_cmd(lun)) == NULL) 657 if ((cmd = ub_get_cmd(lun)) == NULL)
657 return -1; 658 return -1;
658 memset(cmd, 0, sizeof(struct ub_scsi_cmd)); 659 memset(cmd, 0, sizeof(struct ub_scsi_cmd));
660 sg_init_table(cmd->sgv, UB_MAX_REQ_SG);
659 661
660 blkdev_dequeue_request(rq); 662 blkdev_dequeue_request(rq);
661 663
@@ -1309,9 +1311,8 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1309 else 1311 else
1310 pipe = sc->send_bulk_pipe; 1312 pipe = sc->send_bulk_pipe;
1311 sc->last_pipe = pipe; 1313 sc->last_pipe = pipe;
1312 usb_fill_bulk_urb(&sc->work_urb, sc->dev, pipe, 1314 usb_fill_bulk_urb(&sc->work_urb, sc->dev, pipe, sg_virt(sg),
1313 page_address(sg->page) + sg->offset, sg->length, 1315 sg->length, ub_urb_complete, sc);
1314 ub_urb_complete, sc);
1315 sc->work_urb.actual_length = 0; 1316 sc->work_urb.actual_length = 0;
1316 sc->work_urb.error_count = 0; 1317 sc->work_urb.error_count = 0;
1317 sc->work_urb.status = 0; 1318 sc->work_urb.status = 0;
@@ -1427,7 +1428,7 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1427 scmd->state = UB_CMDST_INIT; 1428 scmd->state = UB_CMDST_INIT;
1428 scmd->nsg = 1; 1429 scmd->nsg = 1;
1429 sg = &scmd->sgv[0]; 1430 sg = &scmd->sgv[0];
1430 sg->page = virt_to_page(sc->top_sense); 1431 sg_set_page(sg, virt_to_page(sc->top_sense));
1431 sg->offset = (unsigned long)sc->top_sense & (PAGE_SIZE-1); 1432 sg->offset = (unsigned long)sc->top_sense & (PAGE_SIZE-1);
1432 sg->length = UB_SENSE_SIZE; 1433 sg->length = UB_SENSE_SIZE;
1433 scmd->len = UB_SENSE_SIZE; 1434 scmd->len = UB_SENSE_SIZE;
@@ -1863,7 +1864,7 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
1863 cmd->state = UB_CMDST_INIT; 1864 cmd->state = UB_CMDST_INIT;
1864 cmd->nsg = 1; 1865 cmd->nsg = 1;
1865 sg = &cmd->sgv[0]; 1866 sg = &cmd->sgv[0];
1866 sg->page = virt_to_page(p); 1867 sg_set_page(sg, virt_to_page(p));
1867 sg->offset = (unsigned long)p & (PAGE_SIZE-1); 1868 sg->offset = (unsigned long)p & (PAGE_SIZE-1);
1868 sg->length = 8; 1869 sg->length = 8;
1869 cmd->len = 8; 1870 cmd->len = 8;
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index e824b672e05a..ab5d404faa11 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -41,6 +41,7 @@
41#include <linux/dma-mapping.h> 41#include <linux/dma-mapping.h>
42#include <linux/completion.h> 42#include <linux/completion.h>
43#include <linux/device.h> 43#include <linux/device.h>
44#include <linux/scatterlist.h>
44 45
45#include <asm/uaccess.h> 46#include <asm/uaccess.h>
46#include <asm/vio.h> 47#include <asm/vio.h>
@@ -270,6 +271,7 @@ static int send_request(struct request *req)
270 d = req->rq_disk->private_data; 271 d = req->rq_disk->private_data;
271 272
272 /* Now build the scatter-gather list */ 273 /* Now build the scatter-gather list */
274 sg_init_table(sg, VIOMAXBLOCKDMA);
273 nsg = blk_rq_map_sg(req->q, req, sg); 275 nsg = blk_rq_map_sg(req->q, req, sg);
274 nsg = dma_map_sg(d->dev, sg, nsg, direction); 276 nsg = dma_map_sg(d->dev, sg, nsg, direction);
275 277
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index ff20377b4c82..e196aefa2070 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -935,11 +935,11 @@ static int cris_ide_build_dmatable (ide_drive_t *drive)
935 * than two possibly non-adjacent physical 4kB pages. 935 * than two possibly non-adjacent physical 4kB pages.
936 */ 936 */
937 /* group sequential buffers into one large buffer */ 937 /* group sequential buffers into one large buffer */
938 addr = page_to_phys(sg->page) + sg->offset; 938 addr = sg_phys(sg);
939 size = sg_dma_len(sg); 939 size = sg_dma_len(sg);
940 while (--i) { 940 while (--i) {
941 sg = sg_next(sg); 941 sg = sg_next(sg);
942 if ((addr + size) != page_to_phys(sg->page) + sg->offset) 942 if ((addr + size) != sg_phys(sg))
943 break; 943 break;
944 size += sg_dma_len(sg); 944 size += sg_dma_len(sg);
945 } 945 }
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index d5146c57e5b3..ec55a173c08a 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1317,12 +1317,14 @@ static int hwif_init(ide_hwif_t *hwif)
1317 if (!hwif->sg_max_nents) 1317 if (!hwif->sg_max_nents)
1318 hwif->sg_max_nents = PRD_ENTRIES; 1318 hwif->sg_max_nents = PRD_ENTRIES;
1319 1319
1320 hwif->sg_table = kzalloc(sizeof(struct scatterlist)*hwif->sg_max_nents, 1320 hwif->sg_table = kmalloc(sizeof(struct scatterlist)*hwif->sg_max_nents,
1321 GFP_KERNEL); 1321 GFP_KERNEL);
1322 if (!hwif->sg_table) { 1322 if (!hwif->sg_table) {
1323 printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name); 1323 printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name);
1324 goto out; 1324 goto out;
1325 } 1325 }
1326
1327 sg_init_table(hwif->sg_table, hwif->sg_max_nents);
1326 1328
1327 if (init_irq(hwif) == 0) 1329 if (init_irq(hwif) == 0)
1328 goto done; 1330 goto done;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 73ef6bf5fbcc..d066546f2831 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -261,7 +261,7 @@ static void ide_pio_sector(ide_drive_t *drive, unsigned int write)
261 hwif->cursg = sg; 261 hwif->cursg = sg;
262 } 262 }
263 263
264 page = cursg->page; 264 page = sg_page(cursg);
265 offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE; 265 offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE;
266 266
267 /* get the current page and offset */ 267 /* get the current page and offset */
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 1de58566e5b6..a4ce3ba15d61 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -276,8 +276,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
276 276
277 if (iswrite) { 277 if (iswrite) {
278 if(!put_source_flags(ahwif->tx_chan, 278 if(!put_source_flags(ahwif->tx_chan,
279 (void*)(page_address(sg->page) 279 (void*) sg_virt(sg),
280 + sg->offset),
281 tc, flags)) { 280 tc, flags)) {
282 printk(KERN_ERR "%s failed %d\n", 281 printk(KERN_ERR "%s failed %d\n",
283 __FUNCTION__, __LINE__); 282 __FUNCTION__, __LINE__);
@@ -285,8 +284,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
285 } else 284 } else
286 { 285 {
287 if(!put_dest_flags(ahwif->rx_chan, 286 if(!put_dest_flags(ahwif->rx_chan,
288 (void*)(page_address(sg->page) 287 (void*) sg_virt(sg),
289 + sg->offset),
290 tc, flags)) { 288 tc, flags)) {
291 printk(KERN_ERR "%s failed %d\n", 289 printk(KERN_ERR "%s failed %d\n",
292 __FUNCTION__, __LINE__); 290 __FUNCTION__, __LINE__);
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c
index 45d605581922..25e113b50d86 100644
--- a/drivers/ieee1394/dma.c
+++ b/drivers/ieee1394/dma.c
@@ -111,7 +111,7 @@ int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
111 unsigned long va = 111 unsigned long va =
112 (unsigned long)dma->kvirt + (i << PAGE_SHIFT); 112 (unsigned long)dma->kvirt + (i << PAGE_SHIFT);
113 113
114 dma->sglist[i].page = vmalloc_to_page((void *)va); 114 sg_set_page(&dma->sglist[i], vmalloc_to_page((void *)va));
115 dma->sglist[i].length = PAGE_SIZE; 115 dma->sglist[i].length = PAGE_SIZE;
116 } 116 }
117 117
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 1b353b964b33..d5dfe11aa5c6 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -1466,7 +1466,7 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1466 cmd->dma_size = sgpnt[0].length; 1466 cmd->dma_size = sgpnt[0].length;
1467 cmd->dma_type = CMD_DMA_PAGE; 1467 cmd->dma_type = CMD_DMA_PAGE;
1468 cmd->cmd_dma = dma_map_page(hi->host->device.parent, 1468 cmd->cmd_dma = dma_map_page(hi->host->device.parent,
1469 sgpnt[0].page, sgpnt[0].offset, 1469 sg_page(&sgpnt[0]), sgpnt[0].offset,
1470 cmd->dma_size, cmd->dma_dir); 1470 cmd->dma_size, cmd->dma_dir);
1471 1471
1472 orb->data_descriptor_lo = cmd->cmd_dma; 1472 orb->data_descriptor_lo = cmd->cmd_dma;
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 2f54e29dc7a6..14159ff29408 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -55,9 +55,11 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
55 ib_dma_unmap_sg(dev, chunk->page_list, 55 ib_dma_unmap_sg(dev, chunk->page_list,
56 chunk->nents, DMA_BIDIRECTIONAL); 56 chunk->nents, DMA_BIDIRECTIONAL);
57 for (i = 0; i < chunk->nents; ++i) { 57 for (i = 0; i < chunk->nents; ++i) {
58 struct page *page = sg_page(&chunk->page_list[i]);
59
58 if (umem->writable && dirty) 60 if (umem->writable && dirty)
59 set_page_dirty_lock(chunk->page_list[i].page); 61 set_page_dirty_lock(page);
60 put_page(chunk->page_list[i].page); 62 put_page(page);
61 } 63 }
62 64
63 kfree(chunk); 65 kfree(chunk);
@@ -164,11 +166,12 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
164 } 166 }
165 167
166 chunk->nents = min_t(int, ret, IB_UMEM_MAX_PAGE_CHUNK); 168 chunk->nents = min_t(int, ret, IB_UMEM_MAX_PAGE_CHUNK);
169 sg_init_table(chunk->page_list, chunk->nents);
167 for (i = 0; i < chunk->nents; ++i) { 170 for (i = 0; i < chunk->nents; ++i) {
168 if (vma_list && 171 if (vma_list &&
169 !is_vm_hugetlb_page(vma_list[i + off])) 172 !is_vm_hugetlb_page(vma_list[i + off]))
170 umem->hugetlb = 0; 173 umem->hugetlb = 0;
171 chunk->page_list[i].page = page_list[i + off]; 174 sg_set_page(&chunk->page_list[i], page_list[i + off]);
172 chunk->page_list[i].offset = 0; 175 chunk->page_list[i].offset = 0;
173 chunk->page_list[i].length = PAGE_SIZE; 176 chunk->page_list[i].length = PAGE_SIZE;
174 } 177 }
@@ -179,7 +182,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
179 DMA_BIDIRECTIONAL); 182 DMA_BIDIRECTIONAL);
180 if (chunk->nmap <= 0) { 183 if (chunk->nmap <= 0) {
181 for (i = 0; i < chunk->nents; ++i) 184 for (i = 0; i < chunk->nents; ++i)
182 put_page(chunk->page_list[i].page); 185 put_page(sg_page(&chunk->page_list[i]));
183 kfree(chunk); 186 kfree(chunk);
184 187
185 ret = -ENOMEM; 188 ret = -ENOMEM;
diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
index 22709a4f8fc8..e90a0ea538a0 100644
--- a/drivers/infiniband/hw/ipath/ipath_dma.c
+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
@@ -108,7 +108,7 @@ static int ipath_map_sg(struct ib_device *dev, struct scatterlist *sgl,
108 BUG_ON(!valid_dma_direction(direction)); 108 BUG_ON(!valid_dma_direction(direction));
109 109
110 for_each_sg(sgl, sg, nents, i) { 110 for_each_sg(sgl, sg, nents, i) {
111 addr = (u64) page_address(sg->page); 111 addr = (u64) page_address(sg_page(sg));
112 /* TODO: handle highmem pages */ 112 /* TODO: handle highmem pages */
113 if (!addr) { 113 if (!addr) {
114 ret = 0; 114 ret = 0;
@@ -127,7 +127,7 @@ static void ipath_unmap_sg(struct ib_device *dev,
127 127
128static u64 ipath_sg_dma_address(struct ib_device *dev, struct scatterlist *sg) 128static u64 ipath_sg_dma_address(struct ib_device *dev, struct scatterlist *sg)
129{ 129{
130 u64 addr = (u64) page_address(sg->page); 130 u64 addr = (u64) page_address(sg_page(sg));
131 131
132 if (addr) 132 if (addr)
133 addr += sg->offset; 133 addr += sg->offset;
diff --git a/drivers/infiniband/hw/ipath/ipath_mr.c b/drivers/infiniband/hw/ipath/ipath_mr.c
index e442470a2375..db4ba92f79fc 100644
--- a/drivers/infiniband/hw/ipath/ipath_mr.c
+++ b/drivers/infiniband/hw/ipath/ipath_mr.c
@@ -225,7 +225,7 @@ struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
225 for (i = 0; i < chunk->nents; i++) { 225 for (i = 0; i < chunk->nents; i++) {
226 void *vaddr; 226 void *vaddr;
227 227
228 vaddr = page_address(chunk->page_list[i].page); 228 vaddr = page_address(sg_page(&chunk->page_list[i]));
229 if (!vaddr) { 229 if (!vaddr) {
230 ret = ERR_PTR(-EINVAL); 230 ret = ERR_PTR(-EINVAL);
231 goto bail; 231 goto bail;
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index e61f3e626980..007b38157fc4 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -71,7 +71,7 @@ static void mthca_free_icm_pages(struct mthca_dev *dev, struct mthca_icm_chunk *
71 PCI_DMA_BIDIRECTIONAL); 71 PCI_DMA_BIDIRECTIONAL);
72 72
73 for (i = 0; i < chunk->npages; ++i) 73 for (i = 0; i < chunk->npages; ++i)
74 __free_pages(chunk->mem[i].page, 74 __free_pages(sg_page(&chunk->mem[i]),
75 get_order(chunk->mem[i].length)); 75 get_order(chunk->mem[i].length));
76} 76}
77 77
@@ -81,7 +81,7 @@ static void mthca_free_icm_coherent(struct mthca_dev *dev, struct mthca_icm_chun
81 81
82 for (i = 0; i < chunk->npages; ++i) { 82 for (i = 0; i < chunk->npages; ++i) {
83 dma_free_coherent(&dev->pdev->dev, chunk->mem[i].length, 83 dma_free_coherent(&dev->pdev->dev, chunk->mem[i].length,
84 lowmem_page_address(chunk->mem[i].page), 84 lowmem_page_address(sg_page(&chunk->mem[i])),
85 sg_dma_address(&chunk->mem[i])); 85 sg_dma_address(&chunk->mem[i]));
86 } 86 }
87} 87}
@@ -107,10 +107,13 @@ void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm, int coherent)
107 107
108static int mthca_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_mask) 108static int mthca_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_mask)
109{ 109{
110 mem->page = alloc_pages(gfp_mask, order); 110 struct page *page;
111 if (!mem->page) 111
112 page = alloc_pages(gfp_mask, order);
113 if (!page)
112 return -ENOMEM; 114 return -ENOMEM;
113 115
116 sg_set_page(mem, page);
114 mem->length = PAGE_SIZE << order; 117 mem->length = PAGE_SIZE << order;
115 mem->offset = 0; 118 mem->offset = 0;
116 return 0; 119 return 0;
@@ -157,6 +160,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
157 if (!chunk) 160 if (!chunk)
158 goto fail; 161 goto fail;
159 162
163 sg_init_table(chunk->mem, MTHCA_ICM_CHUNK_LEN);
160 chunk->npages = 0; 164 chunk->npages = 0;
161 chunk->nsg = 0; 165 chunk->nsg = 0;
162 list_add_tail(&chunk->list, &icm->chunk_list); 166 list_add_tail(&chunk->list, &icm->chunk_list);
@@ -304,7 +308,7 @@ void *mthca_table_find(struct mthca_icm_table *table, int obj, dma_addr_t *dma_h
304 * so if we found the page, dma_handle has already 308 * so if we found the page, dma_handle has already
305 * been assigned to. */ 309 * been assigned to. */
306 if (chunk->mem[i].length > offset) { 310 if (chunk->mem[i].length > offset) {
307 page = chunk->mem[i].page; 311 page = sg_page(&chunk->mem[i]);
308 goto out; 312 goto out;
309 } 313 }
310 offset -= chunk->mem[i].length; 314 offset -= chunk->mem[i].length;
@@ -445,6 +449,7 @@ static u64 mthca_uarc_virt(struct mthca_dev *dev, struct mthca_uar *uar, int pag
445int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, 449int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
446 struct mthca_user_db_table *db_tab, int index, u64 uaddr) 450 struct mthca_user_db_table *db_tab, int index, u64 uaddr)
447{ 451{
452 struct page *pages[1];
448 int ret = 0; 453 int ret = 0;
449 u8 status; 454 u8 status;
450 int i; 455 int i;
@@ -472,16 +477,17 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
472 } 477 }
473 478
474 ret = get_user_pages(current, current->mm, uaddr & PAGE_MASK, 1, 1, 0, 479 ret = get_user_pages(current, current->mm, uaddr & PAGE_MASK, 1, 1, 0,
475 &db_tab->page[i].mem.page, NULL); 480 pages, NULL);
476 if (ret < 0) 481 if (ret < 0)
477 goto out; 482 goto out;
478 483
484 sg_set_page(&db_tab->page[i].mem, pages[0]);
479 db_tab->page[i].mem.length = MTHCA_ICM_PAGE_SIZE; 485 db_tab->page[i].mem.length = MTHCA_ICM_PAGE_SIZE;
480 db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK; 486 db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK;
481 487
482 ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE); 488 ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
483 if (ret < 0) { 489 if (ret < 0) {
484 put_page(db_tab->page[i].mem.page); 490 put_page(pages[0]);
485 goto out; 491 goto out;
486 } 492 }
487 493
@@ -491,7 +497,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
491 ret = -EINVAL; 497 ret = -EINVAL;
492 if (ret) { 498 if (ret) {
493 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE); 499 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
494 put_page(db_tab->page[i].mem.page); 500 put_page(sg_page(&db_tab->page[i].mem));
495 goto out; 501 goto out;
496 } 502 }
497 503
@@ -557,7 +563,7 @@ void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
557 if (db_tab->page[i].uvirt) { 563 if (db_tab->page[i].uvirt) {
558 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1, &status); 564 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1, &status);
559 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE); 565 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
560 put_page(db_tab->page[i].mem.page); 566 put_page(sg_page(&db_tab->page[i].mem));
561 } 567 }
562 } 568 }
563 569
diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c
index f3529b6f0a33..d68798061795 100644
--- a/drivers/infiniband/ulp/iser/iser_memory.c
+++ b/drivers/infiniband/ulp/iser/iser_memory.c
@@ -131,7 +131,7 @@ static int iser_start_rdma_unaligned_sg(struct iscsi_iser_cmd_task *iser_ctask,
131 131
132 p = mem; 132 p = mem;
133 for_each_sg(sgl, sg, data->size, i) { 133 for_each_sg(sgl, sg, data->size, i) {
134 from = kmap_atomic(sg->page, KM_USER0); 134 from = kmap_atomic(sg_page(sg), KM_USER0);
135 memcpy(p, 135 memcpy(p,
136 from + sg->offset, 136 from + sg->offset,
137 sg->length); 137 sg->length);
@@ -191,7 +191,7 @@ void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_cmd_task *iser_ctask,
191 191
192 p = mem; 192 p = mem;
193 for_each_sg(sgl, sg, sg_size, i) { 193 for_each_sg(sgl, sg, sg_size, i) {
194 to = kmap_atomic(sg->page, KM_SOFTIRQ0); 194 to = kmap_atomic(sg_page(sg), KM_SOFTIRQ0);
195 memcpy(to + sg->offset, 195 memcpy(to + sg->offset,
196 p, 196 p,
197 sg->length); 197 sg->length);
@@ -300,7 +300,7 @@ static unsigned int iser_data_buf_aligned_len(struct iser_data_buf *data,
300 for_each_sg(sgl, sg, data->dma_nents, i) { 300 for_each_sg(sgl, sg, data->dma_nents, i) {
301 /* iser_dbg("Checking sg iobuf [%d]: phys=0x%08lX " 301 /* iser_dbg("Checking sg iobuf [%d]: phys=0x%08lX "
302 "offset: %ld sz: %ld\n", i, 302 "offset: %ld sz: %ld\n", i,
303 (unsigned long)page_to_phys(sg->page), 303 (unsigned long)sg_phys(sg),
304 (unsigned long)sg->offset, 304 (unsigned long)sg->offset,
305 (unsigned long)sg->length); */ 305 (unsigned long)sg->length); */
306 end_addr = ib_sg_dma_address(ibdev, sg) + 306 end_addr = ib_sg_dma_address(ibdev, sg) +
@@ -336,7 +336,7 @@ static void iser_data_buf_dump(struct iser_data_buf *data,
336 iser_err("sg[%d] dma_addr:0x%lX page:0x%p " 336 iser_err("sg[%d] dma_addr:0x%lX page:0x%p "
337 "off:0x%x sz:0x%x dma_len:0x%x\n", 337 "off:0x%x sz:0x%x dma_len:0x%x\n",
338 i, (unsigned long)ib_sg_dma_address(ibdev, sg), 338 i, (unsigned long)ib_sg_dma_address(ibdev, sg),
339 sg->page, sg->offset, 339 sg_page(sg), sg->offset,
340 sg->length, ib_sg_dma_len(ibdev, sg)); 340 sg->length, ib_sg_dma_len(ibdev, sg));
341} 341}
342 342
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 0eb5416798bd..ac54f697c508 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -348,16 +348,17 @@ static int crypt_convert(struct crypt_config *cc,
348 ctx->idx_out < ctx->bio_out->bi_vcnt) { 348 ctx->idx_out < ctx->bio_out->bi_vcnt) {
349 struct bio_vec *bv_in = bio_iovec_idx(ctx->bio_in, ctx->idx_in); 349 struct bio_vec *bv_in = bio_iovec_idx(ctx->bio_in, ctx->idx_in);
350 struct bio_vec *bv_out = bio_iovec_idx(ctx->bio_out, ctx->idx_out); 350 struct bio_vec *bv_out = bio_iovec_idx(ctx->bio_out, ctx->idx_out);
351 struct scatterlist sg_in = { 351 struct scatterlist sg_in, sg_out;
352 .page = bv_in->bv_page, 352
353 .offset = bv_in->bv_offset + ctx->offset_in, 353 sg_init_table(&sg_in, 1);
354 .length = 1 << SECTOR_SHIFT 354 sg_set_page(&sg_in, bv_in->bv_page);
355 }; 355 sg_in.offset = bv_in->bv_offset + ctx->offset_in;
356 struct scatterlist sg_out = { 356 sg_in.length = 1 << SECTOR_SHIFT;
357 .page = bv_out->bv_page, 357
358 .offset = bv_out->bv_offset + ctx->offset_out, 358 sg_init_table(&sg_out, 1);
359 .length = 1 << SECTOR_SHIFT 359 sg_set_page(&sg_out, bv_out->bv_page);
360 }; 360 sg_out.offset = bv_out->bv_offset + ctx->offset_out;
361 sg_out.length = 1 << SECTOR_SHIFT;
361 362
362 ctx->offset_in += sg_in.length; 363 ctx->offset_in += sg_in.length;
363 if (ctx->offset_in >= bv_in->bv_len) { 364 if (ctx->offset_in >= bv_in->bv_len) {
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 365a22118a09..2b1f8b4be00a 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -112,12 +112,13 @@ static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
112 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL); 112 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
113 if (NULL == sglist) 113 if (NULL == sglist)
114 return NULL; 114 return NULL;
115 sg_init_table(sglist, nr_pages);
115 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) { 116 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
116 pg = vmalloc_to_page(virt); 117 pg = vmalloc_to_page(virt);
117 if (NULL == pg) 118 if (NULL == pg)
118 goto err; 119 goto err;
119 BUG_ON(PageHighMem(pg)); 120 BUG_ON(PageHighMem(pg));
120 sglist[i].page = pg; 121 sg_set_page(&sglist[i], pg);
121 sglist[i].length = PAGE_SIZE; 122 sglist[i].length = PAGE_SIZE;
122 } 123 }
123 return sglist; 124 return sglist;
diff --git a/drivers/media/video/ivtv/ivtv-udma.c b/drivers/media/video/ivtv/ivtv-udma.c
index c4626d1cdf41..912b424e5204 100644
--- a/drivers/media/video/ivtv/ivtv-udma.c
+++ b/drivers/media/video/ivtv/ivtv-udma.c
@@ -63,10 +63,10 @@ int ivtv_udma_fill_sg_list (struct ivtv_user_dma *dma, struct ivtv_dma_page_info
63 memcpy(page_address(dma->bouncemap[map_offset]) + offset, src, len); 63 memcpy(page_address(dma->bouncemap[map_offset]) + offset, src, len);
64 kunmap_atomic(src, KM_BOUNCE_READ); 64 kunmap_atomic(src, KM_BOUNCE_READ);
65 local_irq_restore(flags); 65 local_irq_restore(flags);
66 dma->SGlist[map_offset].page = dma->bouncemap[map_offset]; 66 sg_set_page(&dma->SGlist[map_offset], dma->bouncemap[map_offset]);
67 } 67 }
68 else { 68 else {
69 dma->SGlist[map_offset].page = dma->map[map_offset]; 69 sg_set_page(&dma->SGlist[map_offset], dma->map[map_offset]);
70 } 70 }
71 offset = 0; 71 offset = 0;
72 map_offset++; 72 map_offset++;
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 3eb6123227b2..0a18286279d3 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -60,12 +60,13 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
60 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL); 60 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
61 if (NULL == sglist) 61 if (NULL == sglist)
62 return NULL; 62 return NULL;
63 sg_init_table(sglist, nr_pages);
63 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) { 64 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
64 pg = vmalloc_to_page(virt); 65 pg = vmalloc_to_page(virt);
65 if (NULL == pg) 66 if (NULL == pg)
66 goto err; 67 goto err;
67 BUG_ON(PageHighMem(pg)); 68 BUG_ON(PageHighMem(pg));
68 sglist[i].page = pg; 69 sg_set_page(&sglist[i], pg);
69 sglist[i].length = PAGE_SIZE; 70 sglist[i].length = PAGE_SIZE;
70 } 71 }
71 return sglist; 72 return sglist;
@@ -86,13 +87,14 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
86 sglist = kcalloc(nr_pages, sizeof(*sglist), GFP_KERNEL); 87 sglist = kcalloc(nr_pages, sizeof(*sglist), GFP_KERNEL);
87 if (NULL == sglist) 88 if (NULL == sglist)
88 return NULL; 89 return NULL;
90 sg_init_table(sglist, nr_pages);
89 91
90 if (NULL == pages[0]) 92 if (NULL == pages[0])
91 goto nopage; 93 goto nopage;
92 if (PageHighMem(pages[0])) 94 if (PageHighMem(pages[0]))
93 /* DMA to highmem pages might not work */ 95 /* DMA to highmem pages might not work */
94 goto highmem; 96 goto highmem;
95 sglist[0].page = pages[0]; 97 sg_set_page(&sglist[0], pages[0]);
96 sglist[0].offset = offset; 98 sglist[0].offset = offset;
97 sglist[0].length = PAGE_SIZE - offset; 99 sglist[0].length = PAGE_SIZE - offset;
98 for (i = 1; i < nr_pages; i++) { 100 for (i = 1; i < nr_pages; i++) {
@@ -100,7 +102,7 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
100 goto nopage; 102 goto nopage;
101 if (PageHighMem(pages[i])) 103 if (PageHighMem(pages[i]))
102 goto highmem; 104 goto highmem;
103 sglist[i].page = pages[i]; 105 sg_set_page(&sglist[i], pages[i]);
104 sglist[i].length = PAGE_SIZE; 106 sglist[i].length = PAGE_SIZE;
105 } 107 }
106 return sglist; 108 return sglist;
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index a5d0354bbbda..9203a0b221b3 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -13,6 +13,7 @@
13#include <linux/blkdev.h> 13#include <linux/blkdev.h>
14#include <linux/freezer.h> 14#include <linux/freezer.h>
15#include <linux/kthread.h> 15#include <linux/kthread.h>
16#include <linux/scatterlist.h>
16 17
17#include <linux/mmc/card.h> 18#include <linux/mmc/card.h>
18#include <linux/mmc/host.h> 19#include <linux/mmc/host.h>
@@ -153,19 +154,21 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
153 blk_queue_max_hw_segments(mq->queue, bouncesz / 512); 154 blk_queue_max_hw_segments(mq->queue, bouncesz / 512);
154 blk_queue_max_segment_size(mq->queue, bouncesz); 155 blk_queue_max_segment_size(mq->queue, bouncesz);
155 156
156 mq->sg = kzalloc(sizeof(struct scatterlist), 157 mq->sg = kmalloc(sizeof(struct scatterlist),
157 GFP_KERNEL); 158 GFP_KERNEL);
158 if (!mq->sg) { 159 if (!mq->sg) {
159 ret = -ENOMEM; 160 ret = -ENOMEM;
160 goto cleanup_queue; 161 goto cleanup_queue;
161 } 162 }
163 sg_init_table(mq->sg, 1);
162 164
163 mq->bounce_sg = kzalloc(sizeof(struct scatterlist) * 165 mq->bounce_sg = kmalloc(sizeof(struct scatterlist) *
164 bouncesz / 512, GFP_KERNEL); 166 bouncesz / 512, GFP_KERNEL);
165 if (!mq->bounce_sg) { 167 if (!mq->bounce_sg) {
166 ret = -ENOMEM; 168 ret = -ENOMEM;
167 goto cleanup_queue; 169 goto cleanup_queue;
168 } 170 }
171 sg_init_table(mq->bounce_sg, bouncesz / 512);
169 } 172 }
170 } 173 }
171#endif 174#endif
@@ -302,12 +305,12 @@ static void copy_sg(struct scatterlist *dst, unsigned int dst_len,
302 BUG_ON(dst_len == 0); 305 BUG_ON(dst_len == 0);
303 306
304 if (dst_size == 0) { 307 if (dst_size == 0) {
305 dst_buf = page_address(dst->page) + dst->offset; 308 dst_buf = sg_virt(dst);
306 dst_size = dst->length; 309 dst_size = dst->length;
307 } 310 }
308 311
309 if (src_size == 0) { 312 if (src_size == 0) {
310 src_buf = page_address(src->page) + src->offset; 313 src_buf = sg_virt(dst);
311 src_size = src->length; 314 src_size = src->length;
312 } 315 }
313 316
@@ -353,9 +356,7 @@ unsigned int mmc_queue_map_sg(struct mmc_queue *mq)
353 return 1; 356 return 1;
354 } 357 }
355 358
356 mq->sg[0].page = virt_to_page(mq->bounce_buf); 359 sg_init_one(mq->sg, mq->bounce_buf, 0);
357 mq->sg[0].offset = offset_in_page(mq->bounce_buf);
358 mq->sg[0].length = 0;
359 360
360 while (sg_len) { 361 while (sg_len) {
361 mq->sg[0].length += mq->bounce_sg[sg_len - 1].length; 362 mq->sg[0].length += mq->bounce_sg[sg_len - 1].length;
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index 7a452c2ad1f9..b1edcefdd4f9 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -149,7 +149,7 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
149 149
150 sg = &data->sg[i]; 150 sg = &data->sg[i];
151 151
152 sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset; 152 sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
153 amount = min(size, sg->length); 153 amount = min(size, sg->length);
154 size -= amount; 154 size -= amount;
155 155
@@ -226,7 +226,7 @@ static void at91_mci_pre_dma_read(struct at91mci_host *host)
226 sg = &data->sg[host->transfer_index++]; 226 sg = &data->sg[host->transfer_index++];
227 pr_debug("sg = %p\n", sg); 227 pr_debug("sg = %p\n", sg);
228 228
229 sg->dma_address = dma_map_page(NULL, sg->page, sg->offset, sg->length, DMA_FROM_DEVICE); 229 sg->dma_address = dma_map_page(NULL, sg_page(sg), sg->offset, sg->length, DMA_FROM_DEVICE);
230 230
231 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length); 231 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
232 232
@@ -283,7 +283,7 @@ static void at91_mci_post_dma_read(struct at91mci_host *host)
283 int index; 283 int index;
284 284
285 /* Swap the contents of the buffer */ 285 /* Swap the contents of the buffer */
286 buffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset; 286 buffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
287 pr_debug("buffer = %p, length = %d\n", buffer, sg->length); 287 pr_debug("buffer = %p, length = %d\n", buffer, sg->length);
288 288
289 for (index = 0; index < (sg->length / 4); index++) 289 for (index = 0; index < (sg->length / 4); index++)
@@ -292,7 +292,7 @@ static void at91_mci_post_dma_read(struct at91mci_host *host)
292 kunmap_atomic(buffer, KM_BIO_SRC_IRQ); 292 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
293 } 293 }
294 294
295 flush_dcache_page(sg->page); 295 flush_dcache_page(sg_page(sg));
296 } 296 }
297 297
298 /* Is there another transfer to trigger? */ 298 /* Is there another transfer to trigger? */
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index 92c4d0dfee43..bcbb6d247bf7 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -340,7 +340,7 @@ static void au1xmmc_send_pio(struct au1xmmc_host *host)
340 340
341 /* This is the pointer to the data buffer */ 341 /* This is the pointer to the data buffer */
342 sg = &data->sg[host->pio.index]; 342 sg = &data->sg[host->pio.index];
343 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset; 343 sg_ptr = sg_virt(sg) + host->pio.offset;
344 344
345 /* This is the space left inside the buffer */ 345 /* This is the space left inside the buffer */
346 sg_len = data->sg[host->pio.index].length - host->pio.offset; 346 sg_len = data->sg[host->pio.index].length - host->pio.offset;
@@ -400,7 +400,7 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host)
400 400
401 if (host->pio.index < host->dma.len) { 401 if (host->pio.index < host->dma.len) {
402 sg = &data->sg[host->pio.index]; 402 sg = &data->sg[host->pio.index];
403 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset; 403 sg_ptr = sg_virt(sg) + host->pio.offset;
404 404
405 /* This is the space left inside the buffer */ 405 /* This is the space left inside the buffer */
406 sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset; 406 sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
@@ -613,14 +613,11 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
613 613
614 if (host->flags & HOST_F_XMIT){ 614 if (host->flags & HOST_F_XMIT){
615 ret = au1xxx_dbdma_put_source_flags(channel, 615 ret = au1xxx_dbdma_put_source_flags(channel,
616 (void *) (page_address(sg->page) + 616 (void *) sg_virt(sg), len, flags);
617 sg->offset),
618 len, flags);
619 } 617 }
620 else { 618 else {
621 ret = au1xxx_dbdma_put_dest_flags(channel, 619 ret = au1xxx_dbdma_put_dest_flags(channel,
622 (void *) (page_address(sg->page) + 620 (void *) sg_virt(sg),
623 sg->offset),
624 len, flags); 621 len, flags);
625 } 622 }
626 623
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c
index 6ebc41e7592c..fc72e1fadb6a 100644
--- a/drivers/mmc/host/imxmmc.c
+++ b/drivers/mmc/host/imxmmc.c
@@ -262,7 +262,7 @@ static void imxmci_setup_data(struct imxmci_host *host, struct mmc_data *data)
262 } 262 }
263 263
264 /* Convert back to virtual address */ 264 /* Convert back to virtual address */
265 host->data_ptr = (u16*)(page_address(data->sg->page) + data->sg->offset); 265 host->data_ptr = (u16*)sg_virt(sg);
266 host->data_cnt = 0; 266 host->data_cnt = 0;
267 267
268 clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events); 268 clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events);
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 7ae18eaed6c5..12c2d807c145 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -813,7 +813,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
813 && dir == DMA_FROM_DEVICE) 813 && dir == DMA_FROM_DEVICE)
814 dir = DMA_BIDIRECTIONAL; 814 dir = DMA_BIDIRECTIONAL;
815 815
816 dma_addr = dma_map_page(dma_dev, sg->page, 0, 816 dma_addr = dma_map_page(dma_dev, sg_page(sg), 0,
817 PAGE_SIZE, dir); 817 PAGE_SIZE, dir);
818 if (direction == DMA_TO_DEVICE) 818 if (direction == DMA_TO_DEVICE)
819 t->tx_dma = dma_addr + sg->offset; 819 t->tx_dma = dma_addr + sg->offset;
@@ -822,7 +822,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
822 } 822 }
823 823
824 /* allow pio too; we don't allow highmem */ 824 /* allow pio too; we don't allow highmem */
825 kmap_addr = kmap(sg->page); 825 kmap_addr = kmap(sg_page(sg));
826 if (direction == DMA_TO_DEVICE) 826 if (direction == DMA_TO_DEVICE)
827 t->tx_buf = kmap_addr + sg->offset; 827 t->tx_buf = kmap_addr + sg->offset;
828 else 828 else
@@ -855,8 +855,8 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
855 855
856 /* discard mappings */ 856 /* discard mappings */
857 if (direction == DMA_FROM_DEVICE) 857 if (direction == DMA_FROM_DEVICE)
858 flush_kernel_dcache_page(sg->page); 858 flush_kernel_dcache_page(sg_page(sg));
859 kunmap(sg->page); 859 kunmap(sg_page(sg));
860 if (dma_dev) 860 if (dma_dev)
861 dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir); 861 dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir);
862 862
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 60a67dfcda6a..971e18b91f4a 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -24,10 +24,10 @@
24#include <linux/mmc/host.h> 24#include <linux/mmc/host.h>
25#include <linux/mmc/card.h> 25#include <linux/mmc/card.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/scatterlist.h>
27 28
28#include <asm/io.h> 29#include <asm/io.h>
29#include <asm/irq.h> 30#include <asm/irq.h>
30#include <asm/scatterlist.h>
31#include <asm/mach-types.h> 31#include <asm/mach-types.h>
32 32
33#include <asm/arch/board.h> 33#include <asm/arch/board.h>
@@ -383,7 +383,7 @@ mmc_omap_sg_to_buf(struct mmc_omap_host *host)
383 383
384 sg = host->data->sg + host->sg_idx; 384 sg = host->data->sg + host->sg_idx;
385 host->buffer_bytes_left = sg->length; 385 host->buffer_bytes_left = sg->length;
386 host->buffer = page_address(sg->page) + sg->offset; 386 host->buffer = sg_virt(sg);
387 if (host->buffer_bytes_left > host->total_bytes_left) 387 if (host->buffer_bytes_left > host->total_bytes_left)
388 host->buffer_bytes_left = host->total_bytes_left; 388 host->buffer_bytes_left = host->total_bytes_left;
389} 389}
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index b397121b947d..0db837e44b77 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -231,7 +231,7 @@ static void sdhci_deactivate_led(struct sdhci_host *host)
231 231
232static inline char* sdhci_sg_to_buffer(struct sdhci_host* host) 232static inline char* sdhci_sg_to_buffer(struct sdhci_host* host)
233{ 233{
234 return page_address(host->cur_sg->page) + host->cur_sg->offset; 234 return sg_virt(host->cur_sg);
235} 235}
236 236
237static inline int sdhci_next_sg(struct sdhci_host* host) 237static inline int sdhci_next_sg(struct sdhci_host* host)
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 9b904795eb77..c11a3d256051 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -192,7 +192,7 @@ static void tifm_sd_transfer_data(struct tifm_sd *host)
192 } 192 }
193 off = sg[host->sg_pos].offset + host->block_pos; 193 off = sg[host->sg_pos].offset + host->block_pos;
194 194
195 pg = nth_page(sg[host->sg_pos].page, off >> PAGE_SHIFT); 195 pg = nth_page(sg_page(&sg[host->sg_pos]), off >> PAGE_SHIFT);
196 p_off = offset_in_page(off); 196 p_off = offset_in_page(off);
197 p_cnt = PAGE_SIZE - p_off; 197 p_cnt = PAGE_SIZE - p_off;
198 p_cnt = min(p_cnt, cnt); 198 p_cnt = min(p_cnt, cnt);
@@ -241,18 +241,18 @@ static void tifm_sd_bounce_block(struct tifm_sd *host, struct mmc_data *r_data)
241 } 241 }
242 off = sg[host->sg_pos].offset + host->block_pos; 242 off = sg[host->sg_pos].offset + host->block_pos;
243 243
244 pg = nth_page(sg[host->sg_pos].page, off >> PAGE_SHIFT); 244 pg = nth_page(sg_page(&sg[host->sg_pos]), off >> PAGE_SHIFT);
245 p_off = offset_in_page(off); 245 p_off = offset_in_page(off);
246 p_cnt = PAGE_SIZE - p_off; 246 p_cnt = PAGE_SIZE - p_off;
247 p_cnt = min(p_cnt, cnt); 247 p_cnt = min(p_cnt, cnt);
248 p_cnt = min(p_cnt, t_size); 248 p_cnt = min(p_cnt, t_size);
249 249
250 if (r_data->flags & MMC_DATA_WRITE) 250 if (r_data->flags & MMC_DATA_WRITE)
251 tifm_sd_copy_page(host->bounce_buf.page, 251 tifm_sd_copy_page(sg_page(&host->bounce_buf),
252 r_data->blksz - t_size, 252 r_data->blksz - t_size,
253 pg, p_off, p_cnt); 253 pg, p_off, p_cnt);
254 else if (r_data->flags & MMC_DATA_READ) 254 else if (r_data->flags & MMC_DATA_READ)
255 tifm_sd_copy_page(pg, p_off, host->bounce_buf.page, 255 tifm_sd_copy_page(pg, p_off, sg_page(&host->bounce_buf),
256 r_data->blksz - t_size, p_cnt); 256 r_data->blksz - t_size, p_cnt);
257 257
258 t_size -= p_cnt; 258 t_size -= p_cnt;
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index 80db11c05f2a..fa4c8c53cc7a 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -269,7 +269,7 @@ static inline int wbsd_next_sg(struct wbsd_host *host)
269 269
270static inline char *wbsd_sg_to_buffer(struct wbsd_host *host) 270static inline char *wbsd_sg_to_buffer(struct wbsd_host *host)
271{ 271{
272 return page_address(host->cur_sg->page) + host->cur_sg->offset; 272 return sg_virt(host->cur_sg);
273} 273}
274 274
275static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data) 275static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data)
@@ -283,7 +283,7 @@ static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data)
283 len = data->sg_len; 283 len = data->sg_len;
284 284
285 for (i = 0; i < len; i++) { 285 for (i = 0; i < len; i++) {
286 sgbuf = page_address(sg[i].page) + sg[i].offset; 286 sgbuf = sg_virt(&sg[i]);
287 memcpy(dmabuf, sgbuf, sg[i].length); 287 memcpy(dmabuf, sgbuf, sg[i].length);
288 dmabuf += sg[i].length; 288 dmabuf += sg[i].length;
289 } 289 }
@@ -300,7 +300,7 @@ static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data)
300 len = data->sg_len; 300 len = data->sg_len;
301 301
302 for (i = 0; i < len; i++) { 302 for (i = 0; i < len; i++) {
303 sgbuf = page_address(sg[i].page) + sg[i].offset; 303 sgbuf = sg_virt(&sg[i]);
304 memcpy(sgbuf, dmabuf, sg[i].length); 304 memcpy(sgbuf, dmabuf, sg[i].length);
305 dmabuf += sg[i].length; 305 dmabuf += sg[i].length;
306 } 306 }
diff --git a/drivers/net/mlx4/icm.c b/drivers/net/mlx4/icm.c
index 4b3c109d5eae..887633b207d9 100644
--- a/drivers/net/mlx4/icm.c
+++ b/drivers/net/mlx4/icm.c
@@ -60,7 +60,7 @@ static void mlx4_free_icm_pages(struct mlx4_dev *dev, struct mlx4_icm_chunk *chu
60 PCI_DMA_BIDIRECTIONAL); 60 PCI_DMA_BIDIRECTIONAL);
61 61
62 for (i = 0; i < chunk->npages; ++i) 62 for (i = 0; i < chunk->npages; ++i)
63 __free_pages(chunk->mem[i].page, 63 __free_pages(sg_page(&chunk->mem[i]),
64 get_order(chunk->mem[i].length)); 64 get_order(chunk->mem[i].length));
65} 65}
66 66
@@ -70,7 +70,7 @@ static void mlx4_free_icm_coherent(struct mlx4_dev *dev, struct mlx4_icm_chunk *
70 70
71 for (i = 0; i < chunk->npages; ++i) 71 for (i = 0; i < chunk->npages; ++i)
72 dma_free_coherent(&dev->pdev->dev, chunk->mem[i].length, 72 dma_free_coherent(&dev->pdev->dev, chunk->mem[i].length,
73 lowmem_page_address(chunk->mem[i].page), 73 lowmem_page_address(sg_page(&chunk->mem[i])),
74 sg_dma_address(&chunk->mem[i])); 74 sg_dma_address(&chunk->mem[i]));
75} 75}
76 76
@@ -95,10 +95,13 @@ void mlx4_free_icm(struct mlx4_dev *dev, struct mlx4_icm *icm, int coherent)
95 95
96static int mlx4_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_mask) 96static int mlx4_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_mask)
97{ 97{
98 mem->page = alloc_pages(gfp_mask, order); 98 struct page *page;
99 if (!mem->page) 99
100 page = alloc_pages(gfp_mask, order);
101 if (!page)
100 return -ENOMEM; 102 return -ENOMEM;
101 103
104 sg_set_page(mem, page);
102 mem->length = PAGE_SIZE << order; 105 mem->length = PAGE_SIZE << order;
103 mem->offset = 0; 106 mem->offset = 0;
104 return 0; 107 return 0;
@@ -145,6 +148,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,
145 if (!chunk) 148 if (!chunk)
146 goto fail; 149 goto fail;
147 150
151 sg_init_table(chunk->mem, MLX4_ICM_CHUNK_LEN);
148 chunk->npages = 0; 152 chunk->npages = 0;
149 chunk->nsg = 0; 153 chunk->nsg = 0;
150 list_add_tail(&chunk->list, &icm->chunk_list); 154 list_add_tail(&chunk->list, &icm->chunk_list);
@@ -334,7 +338,7 @@ void *mlx4_table_find(struct mlx4_icm_table *table, int obj, dma_addr_t *dma_han
334 * been assigned to. 338 * been assigned to.
335 */ 339 */
336 if (chunk->mem[i].length > offset) { 340 if (chunk->mem[i].length > offset) {
337 page = chunk->mem[i].page; 341 page = sg_page(&chunk->mem[i]);
338 goto out; 342 goto out;
339 } 343 }
340 offset -= chunk->mem[i].length; 344 offset -= chunk->mem[i].length;
diff --git a/drivers/net/ppp_mppe.c b/drivers/net/ppp_mppe.c
index c0b6d19d1457..bcb0885011c8 100644
--- a/drivers/net/ppp_mppe.c
+++ b/drivers/net/ppp_mppe.c
@@ -55,7 +55,7 @@
55#include <linux/mm.h> 55#include <linux/mm.h>
56#include <linux/ppp_defs.h> 56#include <linux/ppp_defs.h>
57#include <linux/ppp-comp.h> 57#include <linux/ppp-comp.h>
58#include <asm/scatterlist.h> 58#include <linux/scatterlist.h>
59 59
60#include "ppp_mppe.h" 60#include "ppp_mppe.h"
61 61
@@ -68,9 +68,7 @@ MODULE_VERSION("1.0.2");
68static unsigned int 68static unsigned int
69setup_sg(struct scatterlist *sg, const void *address, unsigned int length) 69setup_sg(struct scatterlist *sg, const void *address, unsigned int length)
70{ 70{
71 sg[0].page = virt_to_page(address); 71 sg_init_one(sg, address, length);
72 sg[0].offset = offset_in_page(address);
73 sg[0].length = length;
74 return length; 72 return length;
75} 73}
76 74
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index fb14014ee16e..afb262b4be15 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1840,7 +1840,7 @@ static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
1840 (scsi_bufflen(srb) < TW_MIN_SGL_LENGTH)) { 1840 (scsi_bufflen(srb) < TW_MIN_SGL_LENGTH)) {
1841 if (srb->sc_data_direction == DMA_TO_DEVICE || srb->sc_data_direction == DMA_BIDIRECTIONAL) { 1841 if (srb->sc_data_direction == DMA_TO_DEVICE || srb->sc_data_direction == DMA_BIDIRECTIONAL) {
1842 struct scatterlist *sg = scsi_sglist(srb); 1842 struct scatterlist *sg = scsi_sglist(srb);
1843 char *buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1843 char *buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1844 memcpy(tw_dev->generic_buffer_virt[request_id], buf, sg->length); 1844 memcpy(tw_dev->generic_buffer_virt[request_id], buf, sg->length);
1845 kunmap_atomic(buf - sg->offset, KM_IRQ0); 1845 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1846 } 1846 }
@@ -1919,7 +1919,7 @@ static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int re
1919 char *buf; 1919 char *buf;
1920 unsigned long flags = 0; 1920 unsigned long flags = 0;
1921 local_irq_save(flags); 1921 local_irq_save(flags);
1922 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1922 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1923 memcpy(buf, tw_dev->generic_buffer_virt[request_id], sg->length); 1923 memcpy(buf, tw_dev->generic_buffer_virt[request_id], sg->length);
1924 kunmap_atomic(buf - sg->offset, KM_IRQ0); 1924 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1925 local_irq_restore(flags); 1925 local_irq_restore(flags);
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index a64153b96034..59716ebeb10c 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1469,7 +1469,7 @@ static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1469 struct scatterlist *sg = scsi_sglist(cmd); 1469 struct scatterlist *sg = scsi_sglist(cmd);
1470 1470
1471 local_irq_save(flags); 1471 local_irq_save(flags);
1472 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1472 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1473 transfer_len = min(sg->length, len); 1473 transfer_len = min(sg->length, len);
1474 1474
1475 memcpy(buf, data, transfer_len); 1475 memcpy(buf, data, transfer_len);
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 988f0bc5eda5..2597209183d0 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -298,8 +298,7 @@ static __inline__ void initialize_SCp(Scsi_Cmnd * cmd)
298 if (cmd->use_sg) { 298 if (cmd->use_sg) {
299 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer; 299 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
300 cmd->SCp.buffers_residual = cmd->use_sg - 1; 300 cmd->SCp.buffers_residual = cmd->use_sg - 1;
301 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page)+ 301 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
302 cmd->SCp.buffer->offset;
303 cmd->SCp.this_residual = cmd->SCp.buffer->length; 302 cmd->SCp.this_residual = cmd->SCp.buffer->length;
304 } else { 303 } else {
305 cmd->SCp.buffer = NULL; 304 cmd->SCp.buffer = NULL;
@@ -2143,8 +2142,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2143 ++cmd->SCp.buffer; 2142 ++cmd->SCp.buffer;
2144 --cmd->SCp.buffers_residual; 2143 --cmd->SCp.buffers_residual;
2145 cmd->SCp.this_residual = cmd->SCp.buffer->length; 2144 cmd->SCp.this_residual = cmd->SCp.buffer->length;
2146 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page)+ 2145 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
2147 cmd->SCp.buffer->offset;
2148 dprintk(NDEBUG_INFORMATION, ("scsi%d : %d bytes and %d buffers left\n", instance->host_no, cmd->SCp.this_residual, cmd->SCp.buffers_residual)); 2146 dprintk(NDEBUG_INFORMATION, ("scsi%d : %d bytes and %d buffers left\n", instance->host_no, cmd->SCp.this_residual, cmd->SCp.buffers_residual));
2149 } 2147 }
2150 /* 2148 /*
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
index 96e8e29aa05d..5b0efc903918 100644
--- a/drivers/scsi/NCR53C9x.c
+++ b/drivers/scsi/NCR53C9x.c
@@ -927,7 +927,7 @@ static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
927 esp->dma_mmu_get_scsi_sgl(esp, sp); 927 esp->dma_mmu_get_scsi_sgl(esp, sp);
928 else 928 else
929 sp->SCp.ptr = 929 sp->SCp.ptr =
930 (char *) virt_to_phys((page_address(sp->SCp.buffer->page) + sp->SCp.buffer->offset)); 930 (char *) virt_to_phys(sg_virt(sp->SCp.buffer));
931 } 931 }
932} 932}
933 933
@@ -1748,7 +1748,7 @@ static inline void advance_sg(struct NCR_ESP *esp, Scsi_Cmnd *sp)
1748 if (esp->dma_advance_sg) 1748 if (esp->dma_advance_sg)
1749 esp->dma_advance_sg (sp); 1749 esp->dma_advance_sg (sp);
1750 else 1750 else
1751 sp->SCp.ptr = (char *) virt_to_phys((page_address(sp->SCp.buffer->page) + sp->SCp.buffer->offset)); 1751 sp->SCp.ptr = (char *) virt_to_phys(sg_virt(sp->SCp.buffer));
1752 1752
1753} 1753}
1754 1754
diff --git a/drivers/scsi/NCR53c406a.c b/drivers/scsi/NCR53c406a.c
index 3168a1794849..137d065db3da 100644
--- a/drivers/scsi/NCR53c406a.c
+++ b/drivers/scsi/NCR53c406a.c
@@ -875,8 +875,7 @@ static void NCR53c406a_intr(void *dev_id)
875 outb(TRANSFER_INFO | DMA_OP, CMD_REG); 875 outb(TRANSFER_INFO | DMA_OP, CMD_REG);
876#if USE_PIO 876#if USE_PIO
877 scsi_for_each_sg(current_SC, sg, scsi_sg_count(current_SC), i) { 877 scsi_for_each_sg(current_SC, sg, scsi_sg_count(current_SC), i) {
878 NCR53c406a_pio_write(page_address(sg->page) + sg->offset, 878 NCR53c406a_pio_write(sg_virt(sg), sg->length);
879 sg->length);
880 } 879 }
881 REG0; 880 REG0;
882#endif /* USE_PIO */ 881#endif /* USE_PIO */
@@ -897,8 +896,7 @@ static void NCR53c406a_intr(void *dev_id)
897 outb(TRANSFER_INFO | DMA_OP, CMD_REG); 896 outb(TRANSFER_INFO | DMA_OP, CMD_REG);
898#if USE_PIO 897#if USE_PIO
899 scsi_for_each_sg(current_SC, sg, scsi_sg_count(current_SC), i) { 898 scsi_for_each_sg(current_SC, sg, scsi_sg_count(current_SC), i) {
900 NCR53c406a_pio_read(page_address(sg->page) + sg->offset, 899 NCR53c406a_pio_read(sg_virt(sg), sg->length);
901 sg->length);
902 } 900 }
903 REG0; 901 REG0;
904#endif /* USE_PIO */ 902#endif /* USE_PIO */
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 80e448d0f3db..a77ab8d693d4 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -356,7 +356,7 @@ static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigne
356 int transfer_len; 356 int transfer_len;
357 struct scatterlist *sg = scsi_sglist(scsicmd); 357 struct scatterlist *sg = scsi_sglist(scsicmd);
358 358
359 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 359 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
360 transfer_len = min(sg->length, len + offset); 360 transfer_len = min(sg->length, len + offset);
361 361
362 transfer_len -= offset; 362 transfer_len -= offset;
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index a58c265dc8af..ea8c69947644 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -613,7 +613,7 @@ struct aha152x_scdata {
613#define SCNEXT(SCpnt) SCDATA(SCpnt)->next 613#define SCNEXT(SCpnt) SCDATA(SCpnt)->next
614#define SCSEM(SCpnt) SCDATA(SCpnt)->done 614#define SCSEM(SCpnt) SCDATA(SCpnt)->done
615 615
616#define SG_ADDRESS(buffer) ((char *) (page_address((buffer)->page)+(buffer)->offset)) 616#define SG_ADDRESS(buffer) ((char *) sg_virt((buffer)))
617 617
618/* state handling */ 618/* state handling */
619static void seldi_run(struct Scsi_Host *shpnt); 619static void seldi_run(struct Scsi_Host *shpnt);
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 961a1882cb7e..bbcc2c52d79f 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -49,7 +49,7 @@
49#include "aha1542.h" 49#include "aha1542.h"
50 50
51#define SCSI_BUF_PA(address) isa_virt_to_bus(address) 51#define SCSI_BUF_PA(address) isa_virt_to_bus(address)
52#define SCSI_SG_PA(sgent) (isa_page_to_bus((sgent)->page) + (sgent)->offset) 52#define SCSI_SG_PA(sgent) (isa_page_to_bus(sg_page((sgent))) + (sgent)->offset)
53 53
54static void BAD_DMA(void *address, unsigned int length) 54static void BAD_DMA(void *address, unsigned int length)
55{ 55{
@@ -66,8 +66,7 @@ static void BAD_SG_DMA(Scsi_Cmnd * SCpnt,
66 int badseg) 66 int badseg)
67{ 67{
68 printk(KERN_CRIT "sgpnt[%d:%d] page %p/0x%llx length %u\n", 68 printk(KERN_CRIT "sgpnt[%d:%d] page %p/0x%llx length %u\n",
69 badseg, nseg, 69 badseg, nseg, sg_virt(sgp),
70 page_address(sgp->page) + sgp->offset,
71 (unsigned long long)SCSI_SG_PA(sgp), 70 (unsigned long long)SCSI_SG_PA(sgp),
72 sgp->length); 71 sgp->length);
73 72
@@ -712,8 +711,7 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
712 printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i); 711 printk(KERN_CRIT "Bad segment list supplied to aha1542.c (%d, %d)\n", SCpnt->use_sg, i);
713 scsi_for_each_sg(SCpnt, sg, SCpnt->use_sg, i) { 712 scsi_for_each_sg(SCpnt, sg, SCpnt->use_sg, i) {
714 printk(KERN_CRIT "%d: %p %d\n", i, 713 printk(KERN_CRIT "%d: %p %d\n", i,
715 (page_address(sg->page) + 714 sg_virt(sg), sg->length);
716 sg->offset), sg->length);
717 }; 715 };
718 printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr); 716 printk(KERN_CRIT "cptr %x: ", (unsigned int) cptr);
719 ptr = (unsigned char *) &cptr[i]; 717 ptr = (unsigned char *) &cptr[i];
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index f81777586b8f..f7a252885a5c 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1343,7 +1343,7 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
1343 /* 4 bytes: Areca io control code */ 1343 /* 4 bytes: Areca io control code */
1344 1344
1345 sg = scsi_sglist(cmd); 1345 sg = scsi_sglist(cmd);
1346 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1346 buffer = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1347 if (scsi_sg_count(cmd) > 1) { 1347 if (scsi_sg_count(cmd) > 1) {
1348 retvalue = ARCMSR_MESSAGE_FAIL; 1348 retvalue = ARCMSR_MESSAGE_FAIL;
1349 goto message_out; 1349 goto message_out;
@@ -1593,7 +1593,7 @@ static void arcmsr_handle_virtual_command(struct AdapterControlBlock *acb,
1593 strncpy(&inqdata[32], "R001", 4); /* Product Revision */ 1593 strncpy(&inqdata[32], "R001", 4); /* Product Revision */
1594 1594
1595 sg = scsi_sglist(cmd); 1595 sg = scsi_sglist(cmd);
1596 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1596 buffer = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1597 1597
1598 memcpy(buffer, inqdata, sizeof(inqdata)); 1598 memcpy(buffer, inqdata, sizeof(inqdata));
1599 sg = scsi_sglist(cmd); 1599 sg = scsi_sglist(cmd);
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 52d0b87e9aa4..d1780980fb20 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -515,8 +515,7 @@ static inline void initialize_SCp(Scsi_Cmnd *cmd)
515 if (cmd->use_sg) { 515 if (cmd->use_sg) {
516 cmd->SCp.buffer = (struct scatterlist *)cmd->request_buffer; 516 cmd->SCp.buffer = (struct scatterlist *)cmd->request_buffer;
517 cmd->SCp.buffers_residual = cmd->use_sg - 1; 517 cmd->SCp.buffers_residual = cmd->use_sg - 1;
518 cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page) + 518 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
519 cmd->SCp.buffer->offset;
520 cmd->SCp.this_residual = cmd->SCp.buffer->length; 519 cmd->SCp.this_residual = cmd->SCp.buffer->length;
521 /* ++roman: Try to merge some scatter-buffers if they are at 520 /* ++roman: Try to merge some scatter-buffers if they are at
522 * contiguous physical addresses. 521 * contiguous physical addresses.
@@ -2054,8 +2053,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2054 ++cmd->SCp.buffer; 2053 ++cmd->SCp.buffer;
2055 --cmd->SCp.buffers_residual; 2054 --cmd->SCp.buffers_residual;
2056 cmd->SCp.this_residual = cmd->SCp.buffer->length; 2055 cmd->SCp.this_residual = cmd->SCp.buffer->length;
2057 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 2056 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
2058 cmd->SCp.buffer->offset;
2059 /* ++roman: Try to merge some scatter-buffers if 2057 /* ++roman: Try to merge some scatter-buffers if
2060 * they are at contiguous physical addresses. 2058 * they are at contiguous physical addresses.
2061 */ 2059 */
diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c
index 96180bb47e41..982c5092be11 100644
--- a/drivers/scsi/eata_pio.c
+++ b/drivers/scsi/eata_pio.c
@@ -172,7 +172,7 @@ static void IncStat(struct scsi_pointer *SCp, unsigned int Increment)
172 SCp->Status = 0; 172 SCp->Status = 0;
173 else { 173 else {
174 SCp->buffer++; 174 SCp->buffer++;
175 SCp->ptr = page_address(SCp->buffer->page) + SCp->buffer->offset; 175 SCp->ptr = sg_virt(SCp->buffer);
176 SCp->this_residual = SCp->buffer->length; 176 SCp->this_residual = SCp->buffer->length;
177 } 177 }
178 } 178 }
@@ -410,7 +410,7 @@ static int eata_pio_queue(struct scsi_cmnd *cmd,
410 } else { 410 } else {
411 cmd->SCp.buffer = cmd->request_buffer; 411 cmd->SCp.buffer = cmd->request_buffer;
412 cmd->SCp.buffers_residual = cmd->use_sg; 412 cmd->SCp.buffers_residual = cmd->use_sg;
413 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset; 413 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
414 cmd->SCp.this_residual = cmd->SCp.buffer->length; 414 cmd->SCp.this_residual = cmd->SCp.buffer->length;
415 } 415 }
416 cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes 416 cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes
diff --git a/drivers/scsi/fd_mcs.c b/drivers/scsi/fd_mcs.c
index 668569e8856b..8335b608e571 100644
--- a/drivers/scsi/fd_mcs.c
+++ b/drivers/scsi/fd_mcs.c
@@ -973,7 +973,7 @@ static irqreturn_t fd_mcs_intr(int irq, void *dev_id)
973 if (current_SC->SCp.buffers_residual) { 973 if (current_SC->SCp.buffers_residual) {
974 --current_SC->SCp.buffers_residual; 974 --current_SC->SCp.buffers_residual;
975 ++current_SC->SCp.buffer; 975 ++current_SC->SCp.buffer;
976 current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset; 976 current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
977 current_SC->SCp.this_residual = current_SC->SCp.buffer->length; 977 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
978 } else 978 } else
979 break; 979 break;
@@ -1006,7 +1006,7 @@ static irqreturn_t fd_mcs_intr(int irq, void *dev_id)
1006 if (!current_SC->SCp.this_residual && current_SC->SCp.buffers_residual) { 1006 if (!current_SC->SCp.this_residual && current_SC->SCp.buffers_residual) {
1007 --current_SC->SCp.buffers_residual; 1007 --current_SC->SCp.buffers_residual;
1008 ++current_SC->SCp.buffer; 1008 ++current_SC->SCp.buffer;
1009 current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset; 1009 current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
1010 current_SC->SCp.this_residual = current_SC->SCp.buffer->length; 1010 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1011 } 1011 }
1012 } 1012 }
@@ -1109,7 +1109,7 @@ static int fd_mcs_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
1109 1109
1110 if (current_SC->use_sg) { 1110 if (current_SC->use_sg) {
1111 current_SC->SCp.buffer = (struct scatterlist *) current_SC->request_buffer; 1111 current_SC->SCp.buffer = (struct scatterlist *) current_SC->request_buffer;
1112 current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset; 1112 current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
1113 current_SC->SCp.this_residual = current_SC->SCp.buffer->length; 1113 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1114 current_SC->SCp.buffers_residual = current_SC->use_sg - 1; 1114 current_SC->SCp.buffers_residual = current_SC->use_sg - 1;
1115 } else { 1115 } else {
diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c
index 5d282e6a6ae1..2cd6b4959eb2 100644
--- a/drivers/scsi/fdomain.c
+++ b/drivers/scsi/fdomain.c
@@ -1321,7 +1321,7 @@ static irqreturn_t do_fdomain_16x0_intr(int irq, void *dev_id)
1321 if (current_SC->SCp.buffers_residual) { 1321 if (current_SC->SCp.buffers_residual) {
1322 --current_SC->SCp.buffers_residual; 1322 --current_SC->SCp.buffers_residual;
1323 ++current_SC->SCp.buffer; 1323 ++current_SC->SCp.buffer;
1324 current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset; 1324 current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
1325 current_SC->SCp.this_residual = current_SC->SCp.buffer->length; 1325 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1326 } else 1326 } else
1327 break; 1327 break;
@@ -1354,7 +1354,7 @@ static irqreturn_t do_fdomain_16x0_intr(int irq, void *dev_id)
1354 && current_SC->SCp.buffers_residual) { 1354 && current_SC->SCp.buffers_residual) {
1355 --current_SC->SCp.buffers_residual; 1355 --current_SC->SCp.buffers_residual;
1356 ++current_SC->SCp.buffer; 1356 ++current_SC->SCp.buffer;
1357 current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) + current_SC->SCp.buffer->offset; 1357 current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
1358 current_SC->SCp.this_residual = current_SC->SCp.buffer->length; 1358 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1359 } 1359 }
1360 } 1360 }
@@ -1439,8 +1439,7 @@ static int fdomain_16x0_queue(struct scsi_cmnd *SCpnt,
1439 1439
1440 if (scsi_sg_count(current_SC)) { 1440 if (scsi_sg_count(current_SC)) {
1441 current_SC->SCp.buffer = scsi_sglist(current_SC); 1441 current_SC->SCp.buffer = scsi_sglist(current_SC);
1442 current_SC->SCp.ptr = page_address(current_SC->SCp.buffer->page) 1442 current_SC->SCp.ptr = sg_virt(current_SC->SCp.buffer);
1443 + current_SC->SCp.buffer->offset;
1444 current_SC->SCp.this_residual = current_SC->SCp.buffer->length; 1443 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1445 current_SC->SCp.buffers_residual = scsi_sg_count(current_SC) - 1; 1444 current_SC->SCp.buffers_residual = scsi_sg_count(current_SC) - 1;
1446 } else { 1445 } else {
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 3ac080ee6e2f..5ab3ce762485 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -2374,18 +2374,18 @@ static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
2374 if (cpsum+cpnow > cpcount) 2374 if (cpsum+cpnow > cpcount)
2375 cpnow = cpcount - cpsum; 2375 cpnow = cpcount - cpsum;
2376 cpsum += cpnow; 2376 cpsum += cpnow;
2377 if (!sl->page) { 2377 if (!sg_page(sl)) {
2378 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n", 2378 printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
2379 ha->hanum); 2379 ha->hanum);
2380 return; 2380 return;
2381 } 2381 }
2382 local_irq_save(flags); 2382 local_irq_save(flags);
2383 address = kmap_atomic(sl->page, KM_BIO_SRC_IRQ) + sl->offset; 2383 address = kmap_atomic(sg_page(sl), KM_BIO_SRC_IRQ) + sl->offset;
2384 if (to_buffer) 2384 if (to_buffer)
2385 memcpy(buffer, address, cpnow); 2385 memcpy(buffer, address, cpnow);
2386 else 2386 else
2387 memcpy(address, buffer, cpnow); 2387 memcpy(address, buffer, cpnow);
2388 flush_dcache_page(sl->page); 2388 flush_dcache_page(sg_page(sl));
2389 kunmap_atomic(address, KM_BIO_SRC_IRQ); 2389 kunmap_atomic(address, KM_BIO_SRC_IRQ);
2390 local_irq_restore(flags); 2390 local_irq_restore(flags);
2391 if (cpsum == cpcount) 2391 if (cpsum == cpcount)
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index 714e6273a70d..db004a450732 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -1828,7 +1828,7 @@ static int ibmmca_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1828 BUG_ON(scsi_sg_count(cmd) > 16); 1828 BUG_ON(scsi_sg_count(cmd) > 16);
1829 1829
1830 scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) { 1830 scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) {
1831 ld(shpnt)[ldn].sge[i].address = (void *) (isa_page_to_bus(sg->page) + sg->offset); 1831 ld(shpnt)[ldn].sge[i].address = (void *) (isa_page_to_bus(sg_page(sg)) + sg->offset);
1832 ld(shpnt)[ldn].sge[i].byte_length = sg->length; 1832 ld(shpnt)[ldn].sge[i].byte_length = sg->length;
1833 } 1833 }
1834 scb->enable |= IM_POINTER_TO_LIST; 1834 scb->enable |= IM_POINTER_TO_LIST;
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 252d1806467f..8d0244c2e7d4 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -175,18 +175,18 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
175 175
176 while (bcount) { 176 while (bcount) {
177 count = min(pc->sg->length - pc->b_count, bcount); 177 count = min(pc->sg->length - pc->b_count, bcount);
178 if (PageHighMem(pc->sg->page)) { 178 if (PageHighMem(sg_page(pc->sg))) {
179 unsigned long flags; 179 unsigned long flags;
180 180
181 local_irq_save(flags); 181 local_irq_save(flags);
182 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + 182 buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
183 pc->sg->offset; 183 pc->sg->offset;
184 drive->hwif->atapi_input_bytes(drive, 184 drive->hwif->atapi_input_bytes(drive,
185 buf + pc->b_count, count); 185 buf + pc->b_count, count);
186 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0); 186 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
187 local_irq_restore(flags); 187 local_irq_restore(flags);
188 } else { 188 } else {
189 buf = page_address(pc->sg->page) + pc->sg->offset; 189 buf = sg_virt(pc->sg);
190 drive->hwif->atapi_input_bytes(drive, 190 drive->hwif->atapi_input_bytes(drive,
191 buf + pc->b_count, count); 191 buf + pc->b_count, count);
192 } 192 }
@@ -212,18 +212,18 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
212 212
213 while (bcount) { 213 while (bcount) {
214 count = min(pc->sg->length - pc->b_count, bcount); 214 count = min(pc->sg->length - pc->b_count, bcount);
215 if (PageHighMem(pc->sg->page)) { 215 if (PageHighMem(sg_page(pc->sg))) {
216 unsigned long flags; 216 unsigned long flags;
217 217
218 local_irq_save(flags); 218 local_irq_save(flags);
219 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + 219 buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
220 pc->sg->offset; 220 pc->sg->offset;
221 drive->hwif->atapi_output_bytes(drive, 221 drive->hwif->atapi_output_bytes(drive,
222 buf + pc->b_count, count); 222 buf + pc->b_count, count);
223 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0); 223 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
224 local_irq_restore(flags); 224 local_irq_restore(flags);
225 } else { 225 } else {
226 buf = page_address(pc->sg->page) + pc->sg->offset; 226 buf = sg_virt(pc->sg);
227 drive->hwif->atapi_output_bytes(drive, 227 drive->hwif->atapi_output_bytes(drive,
228 buf + pc->b_count, count); 228 buf + pc->b_count, count);
229 } 229 }
diff --git a/drivers/scsi/imm.c b/drivers/scsi/imm.c
index 74cdc1f0a78f..a3d0c6b14958 100644
--- a/drivers/scsi/imm.c
+++ b/drivers/scsi/imm.c
@@ -705,9 +705,7 @@ static int imm_completion(struct scsi_cmnd *cmd)
705 cmd->SCp.buffer++; 705 cmd->SCp.buffer++;
706 cmd->SCp.this_residual = 706 cmd->SCp.this_residual =
707 cmd->SCp.buffer->length; 707 cmd->SCp.buffer->length;
708 cmd->SCp.ptr = 708 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
709 page_address(cmd->SCp.buffer->page) +
710 cmd->SCp.buffer->offset;
711 709
712 /* 710 /*
713 * Make sure that we transfer even number of bytes 711 * Make sure that we transfer even number of bytes
@@ -844,9 +842,7 @@ static int imm_engine(imm_struct *dev, struct scsi_cmnd *cmd)
844 cmd->SCp.buffer = 842 cmd->SCp.buffer =
845 (struct scatterlist *) cmd->request_buffer; 843 (struct scatterlist *) cmd->request_buffer;
846 cmd->SCp.this_residual = cmd->SCp.buffer->length; 844 cmd->SCp.this_residual = cmd->SCp.buffer->length;
847 cmd->SCp.ptr = 845 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
848 page_address(cmd->SCp.buffer->page) +
849 cmd->SCp.buffer->offset;
850 } else { 846 } else {
851 /* else fill the only available buffer */ 847 /* else fill the only available buffer */
852 cmd->SCp.buffer = NULL; 848 cmd->SCp.buffer = NULL;
diff --git a/drivers/scsi/in2000.c b/drivers/scsi/in2000.c
index ab7cbf3449ce..c8b452f2878c 100644
--- a/drivers/scsi/in2000.c
+++ b/drivers/scsi/in2000.c
@@ -372,7 +372,7 @@ static int in2000_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
372 if (cmd->use_sg) { 372 if (cmd->use_sg) {
373 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer; 373 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
374 cmd->SCp.buffers_residual = cmd->use_sg - 1; 374 cmd->SCp.buffers_residual = cmd->use_sg - 1;
375 cmd->SCp.ptr = (char *) page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset; 375 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
376 cmd->SCp.this_residual = cmd->SCp.buffer->length; 376 cmd->SCp.this_residual = cmd->SCp.buffer->length;
377 } else { 377 } else {
378 cmd->SCp.buffer = NULL; 378 cmd->SCp.buffer = NULL;
@@ -764,7 +764,7 @@ static void transfer_bytes(Scsi_Cmnd * cmd, int data_in_dir)
764 ++cmd->SCp.buffer; 764 ++cmd->SCp.buffer;
765 --cmd->SCp.buffers_residual; 765 --cmd->SCp.buffers_residual;
766 cmd->SCp.this_residual = cmd->SCp.buffer->length; 766 cmd->SCp.this_residual = cmd->SCp.buffer->length;
767 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset; 767 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
768 } 768 }
769 769
770/* Set up hardware registers */ 770/* Set up hardware registers */
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index c316a0bcae6c..439b97a6a269 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -2872,6 +2872,7 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2872 } 2872 }
2873 2873
2874 scatterlist = sglist->scatterlist; 2874 scatterlist = sglist->scatterlist;
2875 sg_init_table(scatterlist, num_elem);
2875 2876
2876 sglist->order = order; 2877 sglist->order = order;
2877 sglist->num_sg = num_elem; 2878 sglist->num_sg = num_elem;
@@ -2884,12 +2885,12 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2884 2885
2885 /* Free up what we already allocated */ 2886 /* Free up what we already allocated */
2886 for (j = i - 1; j >= 0; j--) 2887 for (j = i - 1; j >= 0; j--)
2887 __free_pages(scatterlist[j].page, order); 2888 __free_pages(sg_page(&scatterlist[j]), order);
2888 kfree(sglist); 2889 kfree(sglist);
2889 return NULL; 2890 return NULL;
2890 } 2891 }
2891 2892
2892 scatterlist[i].page = page; 2893 sg_set_page(&scatterlist[i], page);
2893 } 2894 }
2894 2895
2895 return sglist; 2896 return sglist;
@@ -2910,7 +2911,7 @@ static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2910 int i; 2911 int i;
2911 2912
2912 for (i = 0; i < sglist->num_sg; i++) 2913 for (i = 0; i < sglist->num_sg; i++)
2913 __free_pages(sglist->scatterlist[i].page, sglist->order); 2914 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
2914 2915
2915 kfree(sglist); 2916 kfree(sglist);
2916} 2917}
@@ -2940,9 +2941,11 @@ static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2940 scatterlist = sglist->scatterlist; 2941 scatterlist = sglist->scatterlist;
2941 2942
2942 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) { 2943 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2943 kaddr = kmap(scatterlist[i].page); 2944 struct page *page = sg_page(&scatterlist[i]);
2945
2946 kaddr = kmap(page);
2944 memcpy(kaddr, buffer, bsize_elem); 2947 memcpy(kaddr, buffer, bsize_elem);
2945 kunmap(scatterlist[i].page); 2948 kunmap(page);
2946 2949
2947 scatterlist[i].length = bsize_elem; 2950 scatterlist[i].length = bsize_elem;
2948 2951
@@ -2953,9 +2956,11 @@ static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2953 } 2956 }
2954 2957
2955 if (len % bsize_elem) { 2958 if (len % bsize_elem) {
2956 kaddr = kmap(scatterlist[i].page); 2959 struct page *page = sg_page(&scatterlist[i]);
2960
2961 kaddr = kmap(page);
2957 memcpy(kaddr, buffer, len % bsize_elem); 2962 memcpy(kaddr, buffer, len % bsize_elem);
2958 kunmap(scatterlist[i].page); 2963 kunmap(page);
2959 2964
2960 scatterlist[i].length = len % bsize_elem; 2965 scatterlist[i].length = len % bsize_elem;
2961 } 2966 }
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index edaac2714c5a..5c5a9b2628fc 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -1515,7 +1515,7 @@ static int ips_is_passthru(struct scsi_cmnd *SC)
1515 /* kmap_atomic() ensures addressability of the user buffer.*/ 1515 /* kmap_atomic() ensures addressability of the user buffer.*/
1516 /* local_irq_save() protects the KM_IRQ0 address slot. */ 1516 /* local_irq_save() protects the KM_IRQ0 address slot. */
1517 local_irq_save(flags); 1517 local_irq_save(flags);
1518 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1518 buffer = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
1519 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' && 1519 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1520 buffer[2] == 'P' && buffer[3] == 'P') { 1520 buffer[2] == 'P' && buffer[3] == 'P') {
1521 kunmap_atomic(buffer - sg->offset, KM_IRQ0); 1521 kunmap_atomic(buffer - sg->offset, KM_IRQ0);
@@ -3523,7 +3523,7 @@ ips_scmd_buf_write(struct scsi_cmnd *scmd, void *data, unsigned int count)
3523 /* kmap_atomic() ensures addressability of the data buffer.*/ 3523 /* kmap_atomic() ensures addressability of the data buffer.*/
3524 /* local_irq_save() protects the KM_IRQ0 address slot. */ 3524 /* local_irq_save() protects the KM_IRQ0 address slot. */
3525 local_irq_save(flags); 3525 local_irq_save(flags);
3526 buffer = kmap_atomic(sg[i].page, KM_IRQ0) + sg[i].offset; 3526 buffer = kmap_atomic(sg_page(&sg[i]), KM_IRQ0) + sg[i].offset;
3527 memcpy(buffer, &cdata[xfer_cnt], min_cnt); 3527 memcpy(buffer, &cdata[xfer_cnt], min_cnt);
3528 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0); 3528 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
3529 local_irq_restore(flags); 3529 local_irq_restore(flags);
@@ -3556,7 +3556,7 @@ ips_scmd_buf_read(struct scsi_cmnd *scmd, void *data, unsigned int count)
3556 /* kmap_atomic() ensures addressability of the data buffer.*/ 3556 /* kmap_atomic() ensures addressability of the data buffer.*/
3557 /* local_irq_save() protects the KM_IRQ0 address slot. */ 3557 /* local_irq_save() protects the KM_IRQ0 address slot. */
3558 local_irq_save(flags); 3558 local_irq_save(flags);
3559 buffer = kmap_atomic(sg[i].page, KM_IRQ0) + sg[i].offset; 3559 buffer = kmap_atomic(sg_page(&sg[i]), KM_IRQ0) + sg[i].offset;
3560 memcpy(&cdata[xfer_cnt], buffer, min_cnt); 3560 memcpy(&cdata[xfer_cnt], buffer, min_cnt);
3561 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0); 3561 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
3562 local_irq_restore(flags); 3562 local_irq_restore(flags);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index a21455d0274c..6ce4109efdf3 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -70,9 +70,7 @@ module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
70static inline void 70static inline void
71iscsi_buf_init_iov(struct iscsi_buf *ibuf, char *vbuf, int size) 71iscsi_buf_init_iov(struct iscsi_buf *ibuf, char *vbuf, int size)
72{ 72{
73 ibuf->sg.page = virt_to_page(vbuf); 73 sg_init_one(&ibuf->sg, vbuf, size);
74 ibuf->sg.offset = offset_in_page(vbuf);
75 ibuf->sg.length = size;
76 ibuf->sent = 0; 74 ibuf->sent = 0;
77 ibuf->use_sendmsg = 1; 75 ibuf->use_sendmsg = 1;
78} 76}
@@ -80,13 +78,14 @@ iscsi_buf_init_iov(struct iscsi_buf *ibuf, char *vbuf, int size)
80static inline void 78static inline void
81iscsi_buf_init_sg(struct iscsi_buf *ibuf, struct scatterlist *sg) 79iscsi_buf_init_sg(struct iscsi_buf *ibuf, struct scatterlist *sg)
82{ 80{
83 ibuf->sg.page = sg->page; 81 sg_init_table(&ibuf->sg, 1);
82 sg_set_page(&ibuf->sg, sg_page(sg));
84 ibuf->sg.offset = sg->offset; 83 ibuf->sg.offset = sg->offset;
85 ibuf->sg.length = sg->length; 84 ibuf->sg.length = sg->length;
86 /* 85 /*
87 * Fastpath: sg element fits into single page 86 * Fastpath: sg element fits into single page
88 */ 87 */
89 if (sg->length + sg->offset <= PAGE_SIZE && !PageSlab(sg->page)) 88 if (sg->length + sg->offset <= PAGE_SIZE && !PageSlab(sg_page(sg)))
90 ibuf->use_sendmsg = 0; 89 ibuf->use_sendmsg = 0;
91 else 90 else
92 ibuf->use_sendmsg = 1; 91 ibuf->use_sendmsg = 1;
@@ -716,7 +715,7 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
716 for (i = tcp_ctask->sg_count; i < scsi_sg_count(sc); i++) { 715 for (i = tcp_ctask->sg_count; i < scsi_sg_count(sc); i++) {
717 char *dest; 716 char *dest;
718 717
719 dest = kmap_atomic(sg[i].page, KM_SOFTIRQ0); 718 dest = kmap_atomic(sg_page(&sg[i]), KM_SOFTIRQ0);
720 rc = iscsi_ctask_copy(tcp_conn, ctask, dest + sg[i].offset, 719 rc = iscsi_ctask_copy(tcp_conn, ctask, dest + sg[i].offset,
721 sg[i].length, offset); 720 sg[i].length, offset);
722 kunmap_atomic(dest, KM_SOFTIRQ0); 721 kunmap_atomic(dest, KM_SOFTIRQ0);
@@ -1103,9 +1102,9 @@ iscsi_send(struct iscsi_conn *conn, struct iscsi_buf *buf, int size, int flags)
1103 * slab case. 1102 * slab case.
1104 */ 1103 */
1105 if (buf->use_sendmsg) 1104 if (buf->use_sendmsg)
1106 res = sock_no_sendpage(sk, buf->sg.page, offset, size, flags); 1105 res = sock_no_sendpage(sk, sg_page(&buf->sg), offset, size, flags);
1107 else 1106 else
1108 res = tcp_conn->sendpage(sk, buf->sg.page, offset, size, flags); 1107 res = tcp_conn->sendpage(sk, sg_page(&buf->sg), offset, size, flags);
1109 1108
1110 if (res >= 0) { 1109 if (res >= 0) {
1111 conn->txdata_octets += res; 1110 conn->txdata_octets += res;
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 10d1aff9938a..66c652035730 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -658,7 +658,7 @@ mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy)
658 struct scatterlist *sg; 658 struct scatterlist *sg;
659 659
660 sg = scsi_sglist(cmd); 660 sg = scsi_sglist(cmd);
661 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 661 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
662 662
663 memset(buf, 0, cmd->cmnd[4]); 663 memset(buf, 0, cmd->cmnd[4]);
664 kunmap_atomic(buf - sg->offset, KM_IRQ0); 664 kunmap_atomic(buf - sg->offset, KM_IRQ0);
@@ -1542,10 +1542,8 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
1542 if( cmd->cmnd[0] == INQUIRY && !islogical ) { 1542 if( cmd->cmnd[0] == INQUIRY && !islogical ) {
1543 1543
1544 sgl = scsi_sglist(cmd); 1544 sgl = scsi_sglist(cmd);
1545 if( sgl->page ) { 1545 if( sg_page(sgl) ) {
1546 c = *(unsigned char *) 1546 c = *(unsigned char *) sg_virt(&sgl[0]);
1547 page_address((&sgl[0])->page) +
1548 (&sgl[0])->offset;
1549 } else { 1547 } else {
1550 printk(KERN_WARNING 1548 printk(KERN_WARNING
1551 "megaraid: invalid sg.\n"); 1549 "megaraid: invalid sg.\n");
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 78779209ac89..c8923108183a 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -1584,10 +1584,8 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
1584 caddr_t vaddr; 1584 caddr_t vaddr;
1585 1585
1586 sgl = scsi_sglist(scp); 1586 sgl = scsi_sglist(scp);
1587 if (sgl->page) { 1587 if (sg_page(sgl)) {
1588 vaddr = (caddr_t) 1588 vaddr = (caddr_t) sg_virt(&sgl[0]);
1589 (page_address((&sgl[0])->page)
1590 + (&sgl[0])->offset);
1591 1589
1592 memset(vaddr, 0, scp->cmnd[4]); 1590 memset(vaddr, 0, scp->cmnd[4]);
1593 } 1591 }
@@ -2328,10 +2326,8 @@ megaraid_mbox_dpc(unsigned long devp)
2328 && IS_RAID_CH(raid_dev, scb->dev_channel)) { 2326 && IS_RAID_CH(raid_dev, scb->dev_channel)) {
2329 2327
2330 sgl = scsi_sglist(scp); 2328 sgl = scsi_sglist(scp);
2331 if (sgl->page) { 2329 if (sg_page(sgl)) {
2332 c = *(unsigned char *) 2330 c = *(unsigned char *) sg_virt(&sgl[0]);
2333 (page_address((&sgl[0])->page) +
2334 (&sgl[0])->offset);
2335 } else { 2331 } else {
2336 con_log(CL_ANN, (KERN_WARNING 2332 con_log(CL_ANN, (KERN_WARNING
2337 "megaraid mailbox: invalid sg:%d\n", 2333 "megaraid mailbox: invalid sg:%d\n",
diff --git a/drivers/scsi/oktagon_esp.c b/drivers/scsi/oktagon_esp.c
index 26a6d55faf3e..8e5eadbd5c51 100644
--- a/drivers/scsi/oktagon_esp.c
+++ b/drivers/scsi/oktagon_esp.c
@@ -550,8 +550,7 @@ void dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp)
550 550
551void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp) 551void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp)
552{ 552{
553 sp->SCp.ptr = page_address(sp->SCp.buffer->page)+ 553 sp->SCp.ptr = sg_virt(sp->SCp.buffer);
554 sp->SCp.buffer->offset;
555} 554}
556 555
557void dma_mmu_release_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp) 556void dma_mmu_release_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp)
@@ -564,8 +563,7 @@ void dma_mmu_release_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp)
564 563
565void dma_advance_sg(Scsi_Cmnd *sp) 564void dma_advance_sg(Scsi_Cmnd *sp)
566{ 565{
567 sp->SCp.ptr = page_address(sp->SCp.buffer->page)+ 566 sp->SCp.ptr = sg_virt(sp->SCp.buffer);
568 sp->SCp.buffer->offset;
569} 567}
570 568
571 569
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 331b789937c4..1c5c4b68f20f 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -542,7 +542,7 @@ static int osst_verify_frame(struct osst_tape * STp, int frame_seq_number, int q
542 if (STp->raw) { 542 if (STp->raw) {
543 if (STp->buffer->syscall_result) { 543 if (STp->buffer->syscall_result) {
544 for (i=0; i < STp->buffer->sg_segs; i++) 544 for (i=0; i < STp->buffer->sg_segs; i++)
545 memset(page_address(STp->buffer->sg[i].page), 545 memset(page_address(sg_page(&STp->buffer->sg[i])),
546 0, STp->buffer->sg[i].length); 546 0, STp->buffer->sg[i].length);
547 strcpy(STp->buffer->b_data, "READ ERROR ON FRAME"); 547 strcpy(STp->buffer->b_data, "READ ERROR ON FRAME");
548 } else 548 } else
@@ -4437,7 +4437,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
4437 for (i = 0, b_size = 0; 4437 for (i = 0, b_size = 0;
4438 (i < STp->buffer->sg_segs) && ((b_size + STp->buffer->sg[i].length) <= OS_DATA_SIZE); 4438 (i < STp->buffer->sg_segs) && ((b_size + STp->buffer->sg[i].length) <= OS_DATA_SIZE);
4439 b_size += STp->buffer->sg[i++].length); 4439 b_size += STp->buffer->sg[i++].length);
4440 STp->buffer->aux = (os_aux_t *) (page_address(STp->buffer->sg[i].page) + OS_DATA_SIZE - b_size); 4440 STp->buffer->aux = (os_aux_t *) (page_address(sg_page(&STp->buffer->sg[i])) + OS_DATA_SIZE - b_size);
4441#if DEBUG 4441#if DEBUG
4442 printk(OSST_DEB_MSG "%s:D: b_data points to %p in segment 0 at %p\n", name, 4442 printk(OSST_DEB_MSG "%s:D: b_data points to %p in segment 0 at %p\n", name,
4443 STp->buffer->b_data, page_address(STp->buffer->sg[0].page)); 4443 STp->buffer->b_data, page_address(STp->buffer->sg[0].page));
@@ -5252,25 +5252,26 @@ static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma)
5252 /* Try to allocate the first segment up to OS_DATA_SIZE and the others 5252 /* Try to allocate the first segment up to OS_DATA_SIZE and the others
5253 big enough to reach the goal (code assumes no segments in place) */ 5253 big enough to reach the goal (code assumes no segments in place) */
5254 for (b_size = OS_DATA_SIZE, order = OSST_FIRST_ORDER; b_size >= PAGE_SIZE; order--, b_size /= 2) { 5254 for (b_size = OS_DATA_SIZE, order = OSST_FIRST_ORDER; b_size >= PAGE_SIZE; order--, b_size /= 2) {
5255 STbuffer->sg[0].page = alloc_pages(priority, order); 5255 struct page *page = alloc_pages(priority, order);
5256
5256 STbuffer->sg[0].offset = 0; 5257 STbuffer->sg[0].offset = 0;
5257 if (STbuffer->sg[0].page != NULL) { 5258 if (page != NULL) {
5259 sg_set_page(&STbuffer->sg[0], page);
5258 STbuffer->sg[0].length = b_size; 5260 STbuffer->sg[0].length = b_size;
5259 STbuffer->b_data = page_address(STbuffer->sg[0].page); 5261 STbuffer->b_data = page_address(page);
5260 break; 5262 break;
5261 } 5263 }
5262 } 5264 }
5263 if (STbuffer->sg[0].page == NULL) { 5265 if (sg_page(&STbuffer->sg[0]) == NULL) {
5264 printk(KERN_NOTICE "osst :I: Can't allocate tape buffer main segment.\n"); 5266 printk(KERN_NOTICE "osst :I: Can't allocate tape buffer main segment.\n");
5265 return 0; 5267 return 0;
5266 } 5268 }
5267 /* Got initial segment of 'bsize,order', continue with same size if possible, except for AUX */ 5269 /* Got initial segment of 'bsize,order', continue with same size if possible, except for AUX */
5268 for (segs=STbuffer->sg_segs=1, got=b_size; 5270 for (segs=STbuffer->sg_segs=1, got=b_size;
5269 segs < max_segs && got < OS_FRAME_SIZE; ) { 5271 segs < max_segs && got < OS_FRAME_SIZE; ) {
5270 STbuffer->sg[segs].page = 5272 struct page *page = alloc_pages(priority, (OS_FRAME_SIZE - got <= PAGE_SIZE) ? 0 : order);
5271 alloc_pages(priority, (OS_FRAME_SIZE - got <= PAGE_SIZE) ? 0 : order);
5272 STbuffer->sg[segs].offset = 0; 5273 STbuffer->sg[segs].offset = 0;
5273 if (STbuffer->sg[segs].page == NULL) { 5274 if (page == NULL) {
5274 if (OS_FRAME_SIZE - got <= (max_segs - segs) * b_size / 2 && order) { 5275 if (OS_FRAME_SIZE - got <= (max_segs - segs) * b_size / 2 && order) {
5275 b_size /= 2; /* Large enough for the rest of the buffers */ 5276 b_size /= 2; /* Large enough for the rest of the buffers */
5276 order--; 5277 order--;
@@ -5284,6 +5285,7 @@ static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma)
5284 normalize_buffer(STbuffer); 5285 normalize_buffer(STbuffer);
5285 return 0; 5286 return 0;
5286 } 5287 }
5288 sg_set_page(&STbuffer->sg[segs], page);
5287 STbuffer->sg[segs].length = (OS_FRAME_SIZE - got <= PAGE_SIZE / 2) ? (OS_FRAME_SIZE - got) : b_size; 5289 STbuffer->sg[segs].length = (OS_FRAME_SIZE - got <= PAGE_SIZE / 2) ? (OS_FRAME_SIZE - got) : b_size;
5288 got += STbuffer->sg[segs].length; 5290 got += STbuffer->sg[segs].length;
5289 STbuffer->buffer_size = got; 5291 STbuffer->buffer_size = got;
@@ -5316,7 +5318,7 @@ static void normalize_buffer(struct osst_buffer *STbuffer)
5316 b_size < STbuffer->sg[i].length; 5318 b_size < STbuffer->sg[i].length;
5317 b_size *= 2, order++); 5319 b_size *= 2, order++);
5318 5320
5319 __free_pages(STbuffer->sg[i].page, order); 5321 __free_pages(sg_page(&STbuffer->sg[i]), order);
5320 STbuffer->buffer_size -= STbuffer->sg[i].length; 5322 STbuffer->buffer_size -= STbuffer->sg[i].length;
5321 } 5323 }
5322#if DEBUG 5324#if DEBUG
@@ -5344,7 +5346,7 @@ static int append_to_buffer(const char __user *ubp, struct osst_buffer *st_bp, i
5344 for ( ; i < st_bp->sg_segs && do_count > 0; i++) { 5346 for ( ; i < st_bp->sg_segs && do_count > 0; i++) {
5345 cnt = st_bp->sg[i].length - offset < do_count ? 5347 cnt = st_bp->sg[i].length - offset < do_count ?
5346 st_bp->sg[i].length - offset : do_count; 5348 st_bp->sg[i].length - offset : do_count;
5347 res = copy_from_user(page_address(st_bp->sg[i].page) + offset, ubp, cnt); 5349 res = copy_from_user(page_address(sg_page(&st_bp->sg[i])) + offset, ubp, cnt);
5348 if (res) 5350 if (res)
5349 return (-EFAULT); 5351 return (-EFAULT);
5350 do_count -= cnt; 5352 do_count -= cnt;
@@ -5377,7 +5379,7 @@ static int from_buffer(struct osst_buffer *st_bp, char __user *ubp, int do_count
5377 for ( ; i < st_bp->sg_segs && do_count > 0; i++) { 5379 for ( ; i < st_bp->sg_segs && do_count > 0; i++) {
5378 cnt = st_bp->sg[i].length - offset < do_count ? 5380 cnt = st_bp->sg[i].length - offset < do_count ?
5379 st_bp->sg[i].length - offset : do_count; 5381 st_bp->sg[i].length - offset : do_count;
5380 res = copy_to_user(ubp, page_address(st_bp->sg[i].page) + offset, cnt); 5382 res = copy_to_user(ubp, page_address(sg_page(&st_bp->sg[i])) + offset, cnt);
5381 if (res) 5383 if (res)
5382 return (-EFAULT); 5384 return (-EFAULT);
5383 do_count -= cnt; 5385 do_count -= cnt;
@@ -5410,7 +5412,7 @@ static int osst_zero_buffer_tail(struct osst_buffer *st_bp)
5410 i < st_bp->sg_segs && do_count > 0; i++) { 5412 i < st_bp->sg_segs && do_count > 0; i++) {
5411 cnt = st_bp->sg[i].length - offset < do_count ? 5413 cnt = st_bp->sg[i].length - offset < do_count ?
5412 st_bp->sg[i].length - offset : do_count ; 5414 st_bp->sg[i].length - offset : do_count ;
5413 memset(page_address(st_bp->sg[i].page) + offset, 0, cnt); 5415 memset(page_address(sg_page(&st_bp->sg[i])) + offset, 0, cnt);
5414 do_count -= cnt; 5416 do_count -= cnt;
5415 offset = 0; 5417 offset = 0;
5416 } 5418 }
@@ -5430,7 +5432,7 @@ static int osst_copy_to_buffer(struct osst_buffer *st_bp, unsigned char *ptr)
5430 for (i = 0; i < st_bp->sg_segs && do_count > 0; i++) { 5432 for (i = 0; i < st_bp->sg_segs && do_count > 0; i++) {
5431 cnt = st_bp->sg[i].length < do_count ? 5433 cnt = st_bp->sg[i].length < do_count ?
5432 st_bp->sg[i].length : do_count ; 5434 st_bp->sg[i].length : do_count ;
5433 memcpy(page_address(st_bp->sg[i].page), ptr, cnt); 5435 memcpy(page_address(sg_page(&st_bp->sg[i])), ptr, cnt);
5434 do_count -= cnt; 5436 do_count -= cnt;
5435 ptr += cnt; 5437 ptr += cnt;
5436 } 5438 }
@@ -5451,7 +5453,7 @@ static int osst_copy_from_buffer(struct osst_buffer *st_bp, unsigned char *ptr)
5451 for (i = 0; i < st_bp->sg_segs && do_count > 0; i++) { 5453 for (i = 0; i < st_bp->sg_segs && do_count > 0; i++) {
5452 cnt = st_bp->sg[i].length < do_count ? 5454 cnt = st_bp->sg[i].length < do_count ?
5453 st_bp->sg[i].length : do_count ; 5455 st_bp->sg[i].length : do_count ;
5454 memcpy(ptr, page_address(st_bp->sg[i].page), cnt); 5456 memcpy(ptr, page_address(sg_page(&st_bp->sg[i])), cnt);
5455 do_count -= cnt; 5457 do_count -= cnt;
5456 ptr += cnt; 5458 ptr += cnt;
5457 } 5459 }
diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h
index 98397559c53b..7db28cd49446 100644
--- a/drivers/scsi/pcmcia/nsp_cs.h
+++ b/drivers/scsi/pcmcia/nsp_cs.h
@@ -393,7 +393,7 @@ enum _burst_mode {
393#define MSG_EXT_SDTR 0x01 393#define MSG_EXT_SDTR 0x01
394 394
395/* scatter-gather table */ 395/* scatter-gather table */
396# define BUFFER_ADDR ((char *)((unsigned int)(SCpnt->SCp.buffer->page) + SCpnt->SCp.buffer->offset)) 396# define BUFFER_ADDR ((char *)((sg_virt(SCpnt->SCp.buffer))))
397 397
398#endif /*__nsp_cs__*/ 398#endif /*__nsp_cs__*/
399/* end */ 399/* end */
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 190e2a7d7067..969b9387a0c3 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -443,8 +443,7 @@ SYM53C500_intr(int irq, void *dev_id)
443 443
444 scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) { 444 scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
445 SYM53C500_pio_write(fast_pio, port_base, 445 SYM53C500_pio_write(fast_pio, port_base,
446 page_address(sg->page) + sg->offset, 446 sg_virt(sg), sg->length);
447 sg->length);
448 } 447 }
449 REG0(port_base); 448 REG0(port_base);
450 } 449 }
@@ -463,8 +462,7 @@ SYM53C500_intr(int irq, void *dev_id)
463 462
464 scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) { 463 scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
465 SYM53C500_pio_read(fast_pio, port_base, 464 SYM53C500_pio_read(fast_pio, port_base,
466 page_address(sg->page) + sg->offset, 465 sg_virt(sg), sg->length);
467 sg->length);
468 } 466 }
469 REG0(port_base); 467 REG0(port_base);
470 } 468 }
diff --git a/drivers/scsi/ppa.c b/drivers/scsi/ppa.c
index 67b6d76a6c8d..67ee51a3d7e1 100644
--- a/drivers/scsi/ppa.c
+++ b/drivers/scsi/ppa.c
@@ -608,9 +608,7 @@ static int ppa_completion(struct scsi_cmnd *cmd)
608 cmd->SCp.buffer++; 608 cmd->SCp.buffer++;
609 cmd->SCp.this_residual = 609 cmd->SCp.this_residual =
610 cmd->SCp.buffer->length; 610 cmd->SCp.buffer->length;
611 cmd->SCp.ptr = 611 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
612 page_address(cmd->SCp.buffer->page) +
613 cmd->SCp.buffer->offset;
614 } 612 }
615 } 613 }
616 /* Now check to see if the drive is ready to comunicate */ 614 /* Now check to see if the drive is ready to comunicate */
@@ -756,8 +754,7 @@ static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
756 /* if many buffers are available, start filling the first */ 754 /* if many buffers are available, start filling the first */
757 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer; 755 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
758 cmd->SCp.this_residual = cmd->SCp.buffer->length; 756 cmd->SCp.this_residual = cmd->SCp.buffer->length;
759 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 757 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
760 cmd->SCp.buffer->offset;
761 } else { 758 } else {
762 /* else fill the only available buffer */ 759 /* else fill the only available buffer */
763 cmd->SCp.buffer = NULL; 760 cmd->SCp.buffer = NULL;
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index 0f43d1d046d9..03f19b8d19c9 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -111,14 +111,14 @@ static int fill_from_dev_buffer(struct scsi_cmnd *cmd, const void *buf)
111 req_len = act_len = 0; 111 req_len = act_len = 0;
112 scsi_for_each_sg(cmd, sgpnt, scsi_sg_count(cmd), k) { 112 scsi_for_each_sg(cmd, sgpnt, scsi_sg_count(cmd), k) {
113 if (active) { 113 if (active) {
114 kaddr = kmap_atomic(sgpnt->page, KM_IRQ0); 114 kaddr = kmap_atomic(sg_page(sgpnt), KM_IRQ0);
115 len = sgpnt->length; 115 len = sgpnt->length;
116 if ((req_len + len) > buflen) { 116 if ((req_len + len) > buflen) {
117 active = 0; 117 active = 0;
118 len = buflen - req_len; 118 len = buflen - req_len;
119 } 119 }
120 memcpy(kaddr + sgpnt->offset, buf + req_len, len); 120 memcpy(kaddr + sgpnt->offset, buf + req_len, len);
121 flush_kernel_dcache_page(sgpnt->page); 121 flush_kernel_dcache_page(sg_page(sgpnt));
122 kunmap_atomic(kaddr, KM_IRQ0); 122 kunmap_atomic(kaddr, KM_IRQ0);
123 act_len += len; 123 act_len += len;
124 } 124 }
@@ -147,7 +147,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd *cmd, void *buf)
147 147
148 req_len = fin = 0; 148 req_len = fin = 0;
149 scsi_for_each_sg(cmd, sgpnt, scsi_sg_count(cmd), k) { 149 scsi_for_each_sg(cmd, sgpnt, scsi_sg_count(cmd), k) {
150 kaddr = kmap_atomic(sgpnt->page, KM_IRQ0); 150 kaddr = kmap_atomic(sg_page(sgpnt->page), KM_IRQ0);
151 len = sgpnt->length; 151 len = sgpnt->length;
152 if ((req_len + len) > buflen) { 152 if ((req_len + len) > buflen) {
153 len = buflen - req_len; 153 len = buflen - req_len;
diff --git a/drivers/scsi/qlogicfas408.c b/drivers/scsi/qlogicfas408.c
index 2bfbf26c00ed..de7b3bc2cbc9 100644
--- a/drivers/scsi/qlogicfas408.c
+++ b/drivers/scsi/qlogicfas408.c
@@ -317,7 +317,7 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
317 return ((priv->qabort == 1 ? 317 return ((priv->qabort == 1 ?
318 DID_ABORT : DID_RESET) << 16); 318 DID_ABORT : DID_RESET) << 16);
319 } 319 }
320 buf = page_address(sg->page) + sg->offset; 320 buf = sg_virt(sg);
321 if (ql_pdma(priv, phase, buf, sg->length)) 321 if (ql_pdma(priv, phase, buf, sg->length))
322 break; 322 break;
323 } 323 }
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 72ee4c9cfb1a..46cae5a212de 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -625,7 +625,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
625 scsi_for_each_sg(scp, sg, scp->use_sg, k) { 625 scsi_for_each_sg(scp, sg, scp->use_sg, k) {
626 if (active) { 626 if (active) {
627 kaddr = (unsigned char *) 627 kaddr = (unsigned char *)
628 kmap_atomic(sg->page, KM_USER0); 628 kmap_atomic(sg_page(sg), KM_USER0);
629 if (NULL == kaddr) 629 if (NULL == kaddr)
630 return (DID_ERROR << 16); 630 return (DID_ERROR << 16);
631 kaddr_off = (unsigned char *)kaddr + sg->offset; 631 kaddr_off = (unsigned char *)kaddr + sg->offset;
@@ -672,7 +672,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
672 sg = scsi_sglist(scp); 672 sg = scsi_sglist(scp);
673 req_len = fin = 0; 673 req_len = fin = 0;
674 for (k = 0; k < scp->use_sg; ++k, sg = sg_next(sg)) { 674 for (k = 0; k < scp->use_sg; ++k, sg = sg_next(sg)) {
675 kaddr = (unsigned char *)kmap_atomic(sg->page, KM_USER0); 675 kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
676 if (NULL == kaddr) 676 if (NULL == kaddr)
677 return -1; 677 return -1;
678 kaddr_off = (unsigned char *)kaddr + sg->offset; 678 kaddr_off = (unsigned char *)kaddr + sg->offset;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index aac8a02cbe80..61fdaf02f251 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -295,7 +295,7 @@ static int scsi_req_map_sg(struct request *rq, struct scatterlist *sgl,
295 int i, err, nr_vecs = 0; 295 int i, err, nr_vecs = 0;
296 296
297 for_each_sg(sgl, sg, nsegs, i) { 297 for_each_sg(sgl, sg, nsegs, i) {
298 page = sg->page; 298 page = sg_page(sg);
299 off = sg->offset; 299 off = sg->offset;
300 len = sg->length; 300 len = sg->length;
301 data_len += len; 301 data_len += len;
@@ -764,7 +764,7 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
764 if (unlikely(!sgl)) 764 if (unlikely(!sgl))
765 goto enomem; 765 goto enomem;
766 766
767 memset(sgl, 0, sizeof(*sgl) * sgp->size); 767 sg_init_table(sgl, sgp->size);
768 768
769 /* 769 /*
770 * first loop through, set initial index and return value 770 * first loop through, set initial index and return value
@@ -781,6 +781,13 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
781 sg_chain(prev, SCSI_MAX_SG_SEGMENTS, sgl); 781 sg_chain(prev, SCSI_MAX_SG_SEGMENTS, sgl);
782 782
783 /* 783 /*
784 * if we have nothing left, mark the last segment as
785 * end-of-list
786 */
787 if (!left)
788 sg_mark_end(sgl, this);
789
790 /*
784 * don't allow subsequent mempool allocs to sleep, it would 791 * don't allow subsequent mempool allocs to sleep, it would
785 * violate the mempool principle. 792 * violate the mempool principle.
786 */ 793 */
@@ -2353,7 +2360,7 @@ void *scsi_kmap_atomic_sg(struct scatterlist *sgl, int sg_count,
2353 *offset = *offset - len_complete + sg->offset; 2360 *offset = *offset - len_complete + sg->offset;
2354 2361
2355 /* Assumption: contiguous pages can be accessed as "page + i" */ 2362 /* Assumption: contiguous pages can be accessed as "page + i" */
2356 page = nth_page(sg->page, (*offset >> PAGE_SHIFT)); 2363 page = nth_page(sg_page(sg), (*offset >> PAGE_SHIFT));
2357 *offset &= ~PAGE_MASK; 2364 *offset &= ~PAGE_MASK;
2358 2365
2359 /* Bytes in this sg-entry from *offset to the end of the page */ 2366 /* Bytes in this sg-entry from *offset to the end of the page */
diff --git a/drivers/scsi/seagate.c b/drivers/scsi/seagate.c
index ce80fa9ad815..b11324479b5b 100644
--- a/drivers/scsi/seagate.c
+++ b/drivers/scsi/seagate.c
@@ -999,14 +999,14 @@ connect_loop:
999 for (i = 0; i < nobuffs; ++i) 999 for (i = 0; i < nobuffs; ++i)
1000 printk("scsi%d : buffer %d address = %p length = %d\n", 1000 printk("scsi%d : buffer %d address = %p length = %d\n",
1001 hostno, i, 1001 hostno, i,
1002 page_address(buffer[i].page) + buffer[i].offset, 1002 sg_virt(&buffer[i]),
1003 buffer[i].length); 1003 buffer[i].length);
1004 } 1004 }
1005#endif 1005#endif
1006 1006
1007 buffer = (struct scatterlist *) SCint->request_buffer; 1007 buffer = (struct scatterlist *) SCint->request_buffer;
1008 len = buffer->length; 1008 len = buffer->length;
1009 data = page_address(buffer->page) + buffer->offset; 1009 data = sg_virt(buffer);
1010 } else { 1010 } else {
1011 DPRINTK (DEBUG_SG, "scsi%d : scatter gather not requested.\n", hostno); 1011 DPRINTK (DEBUG_SG, "scsi%d : scatter gather not requested.\n", hostno);
1012 buffer = NULL; 1012 buffer = NULL;
@@ -1239,7 +1239,7 @@ connect_loop:
1239 --nobuffs; 1239 --nobuffs;
1240 ++buffer; 1240 ++buffer;
1241 len = buffer->length; 1241 len = buffer->length;
1242 data = page_address(buffer->page) + buffer->offset; 1242 data = sg_virt(buffer);
1243 DPRINTK (DEBUG_SG, 1243 DPRINTK (DEBUG_SG,
1244 "scsi%d : next scatter-gather buffer len = %d address = %08x\n", 1244 "scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1245 hostno, len, data); 1245 hostno, len, data);
@@ -1396,7 +1396,7 @@ connect_loop:
1396 --nobuffs; 1396 --nobuffs;
1397 ++buffer; 1397 ++buffer;
1398 len = buffer->length; 1398 len = buffer->length;
1399 data = page_address(buffer->page) + buffer->offset; 1399 data = sg_virt(buffer);
1400 DPRINTK (DEBUG_SG, "scsi%d : next scatter-gather buffer len = %d address = %08x\n", hostno, len, data); 1400 DPRINTK (DEBUG_SG, "scsi%d : next scatter-gather buffer len = %d address = %08x\n", hostno, len, data);
1401 } 1401 }
1402 break; 1402 break;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 7238b2dfc497..cc1971002846 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1169,7 +1169,7 @@ sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
1169 len = vma->vm_end - sa; 1169 len = vma->vm_end - sa;
1170 len = (len < sg->length) ? len : sg->length; 1170 len = (len < sg->length) ? len : sg->length;
1171 if (offset < len) { 1171 if (offset < len) {
1172 page = virt_to_page(page_address(sg->page) + offset); 1172 page = virt_to_page(page_address(sg_page(sg)) + offset);
1173 get_page(page); /* increment page count */ 1173 get_page(page); /* increment page count */
1174 break; 1174 break;
1175 } 1175 }
@@ -1717,13 +1717,13 @@ st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
1717 goto out_unlock; */ 1717 goto out_unlock; */
1718 } 1718 }
1719 1719
1720 sgl[0].page = pages[0]; 1720 sg_set_page(sgl, pages[0]);
1721 sgl[0].offset = uaddr & ~PAGE_MASK; 1721 sgl[0].offset = uaddr & ~PAGE_MASK;
1722 if (nr_pages > 1) { 1722 if (nr_pages > 1) {
1723 sgl[0].length = PAGE_SIZE - sgl[0].offset; 1723 sgl[0].length = PAGE_SIZE - sgl[0].offset;
1724 count -= sgl[0].length; 1724 count -= sgl[0].length;
1725 for (i=1; i < nr_pages ; i++) { 1725 for (i=1; i < nr_pages ; i++) {
1726 sgl[i].page = pages[i]; 1726 sg_set_page(&sgl[i], pages[i]);
1727 sgl[i].length = count < PAGE_SIZE ? count : PAGE_SIZE; 1727 sgl[i].length = count < PAGE_SIZE ? count : PAGE_SIZE;
1728 count -= PAGE_SIZE; 1728 count -= PAGE_SIZE;
1729 } 1729 }
@@ -1754,7 +1754,7 @@ st_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_pages,
1754 int i; 1754 int i;
1755 1755
1756 for (i=0; i < nr_pages; i++) { 1756 for (i=0; i < nr_pages; i++) {
1757 struct page *page = sgl[i].page; 1757 struct page *page = sg_page(&sgl[i]);
1758 1758
1759 if (dirtied) 1759 if (dirtied)
1760 SetPageDirty(page); 1760 SetPageDirty(page);
@@ -1854,7 +1854,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
1854 scatter_elem_sz_prev = ret_sz; 1854 scatter_elem_sz_prev = ret_sz;
1855 } 1855 }
1856 } 1856 }
1857 sg->page = p; 1857 sg_set_page(sg, p);
1858 sg->length = (ret_sz > num) ? num : ret_sz; 1858 sg->length = (ret_sz > num) ? num : ret_sz;
1859 1859
1860 SCSI_LOG_TIMEOUT(5, printk("sg_build_indirect: k=%d, num=%d, " 1860 SCSI_LOG_TIMEOUT(5, printk("sg_build_indirect: k=%d, num=%d, "
@@ -1907,14 +1907,14 @@ sg_write_xfer(Sg_request * srp)
1907 onum = 1; 1907 onum = 1;
1908 1908
1909 ksglen = sg->length; 1909 ksglen = sg->length;
1910 p = page_address(sg->page); 1910 p = page_address(sg_page(sg));
1911 for (j = 0, k = 0; j < onum; ++j) { 1911 for (j = 0, k = 0; j < onum; ++j) {
1912 res = sg_u_iovec(hp, iovec_count, j, 1, &usglen, &up); 1912 res = sg_u_iovec(hp, iovec_count, j, 1, &usglen, &up);
1913 if (res) 1913 if (res)
1914 return res; 1914 return res;
1915 1915
1916 for (; p; sg = sg_next(sg), ksglen = sg->length, 1916 for (; p; sg = sg_next(sg), ksglen = sg->length,
1917 p = page_address(sg->page)) { 1917 p = page_address(sg_page(sg))) {
1918 if (usglen <= 0) 1918 if (usglen <= 0)
1919 break; 1919 break;
1920 if (ksglen > usglen) { 1920 if (ksglen > usglen) {
@@ -1991,12 +1991,12 @@ sg_remove_scat(Sg_scatter_hold * schp)
1991 } else { 1991 } else {
1992 int k; 1992 int k;
1993 1993
1994 for (k = 0; (k < schp->k_use_sg) && sg->page; 1994 for (k = 0; (k < schp->k_use_sg) && sg_page(sg);
1995 ++k, sg = sg_next(sg)) { 1995 ++k, sg = sg_next(sg)) {
1996 SCSI_LOG_TIMEOUT(5, printk( 1996 SCSI_LOG_TIMEOUT(5, printk(
1997 "sg_remove_scat: k=%d, pg=0x%p, len=%d\n", 1997 "sg_remove_scat: k=%d, pg=0x%p, len=%d\n",
1998 k, sg->page, sg->length)); 1998 k, sg_page(sg), sg->length));
1999 sg_page_free(sg->page, sg->length); 1999 sg_page_free(sg_page(sg), sg->length);
2000 } 2000 }
2001 } 2001 }
2002 kfree(schp->buffer); 2002 kfree(schp->buffer);
@@ -2038,7 +2038,7 @@ sg_read_xfer(Sg_request * srp)
2038 } else 2038 } else
2039 onum = 1; 2039 onum = 1;
2040 2040
2041 p = page_address(sg->page); 2041 p = page_address(sg_page(sg));
2042 ksglen = sg->length; 2042 ksglen = sg->length;
2043 for (j = 0, k = 0; j < onum; ++j) { 2043 for (j = 0, k = 0; j < onum; ++j) {
2044 res = sg_u_iovec(hp, iovec_count, j, 0, &usglen, &up); 2044 res = sg_u_iovec(hp, iovec_count, j, 0, &usglen, &up);
@@ -2046,7 +2046,7 @@ sg_read_xfer(Sg_request * srp)
2046 return res; 2046 return res;
2047 2047
2048 for (; p; sg = sg_next(sg), ksglen = sg->length, 2048 for (; p; sg = sg_next(sg), ksglen = sg->length,
2049 p = page_address(sg->page)) { 2049 p = page_address(sg_page(sg))) {
2050 if (usglen <= 0) 2050 if (usglen <= 0)
2051 break; 2051 break;
2052 if (ksglen > usglen) { 2052 if (ksglen > usglen) {
@@ -2092,15 +2092,15 @@ sg_read_oxfer(Sg_request * srp, char __user *outp, int num_read_xfer)
2092 if ((!outp) || (num_read_xfer <= 0)) 2092 if ((!outp) || (num_read_xfer <= 0))
2093 return 0; 2093 return 0;
2094 2094
2095 for (k = 0; (k < schp->k_use_sg) && sg->page; ++k, sg = sg_next(sg)) { 2095 for (k = 0; (k < schp->k_use_sg) && sg_page(sg); ++k, sg = sg_next(sg)) {
2096 num = sg->length; 2096 num = sg->length;
2097 if (num > num_read_xfer) { 2097 if (num > num_read_xfer) {
2098 if (__copy_to_user(outp, page_address(sg->page), 2098 if (__copy_to_user(outp, page_address(sg_page(sg)),
2099 num_read_xfer)) 2099 num_read_xfer))
2100 return -EFAULT; 2100 return -EFAULT;
2101 break; 2101 break;
2102 } else { 2102 } else {
2103 if (__copy_to_user(outp, page_address(sg->page), 2103 if (__copy_to_user(outp, page_address(sg_page(sg)),
2104 num)) 2104 num))
2105 return -EFAULT; 2105 return -EFAULT;
2106 num_read_xfer -= num; 2106 num_read_xfer -= num;
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 73c44cbdea47..ce69b9efc102 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -3797,7 +3797,7 @@ static void buf_to_sg(struct st_buffer *STbp, unsigned int length)
3797 sg = &(STbp->sg[0]); 3797 sg = &(STbp->sg[0]);
3798 frp = STbp->frp; 3798 frp = STbp->frp;
3799 for (i=count=0; count < length; i++) { 3799 for (i=count=0; count < length; i++) {
3800 sg[i].page = frp[i].page; 3800 sg_set_page(&sg[i], frp[i].page);
3801 if (length - count > frp[i].length) 3801 if (length - count > frp[i].length)
3802 sg[i].length = frp[i].length; 3802 sg[i].length = frp[i].length;
3803 else 3803 else
@@ -4446,14 +4446,14 @@ static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pa
4446 } 4446 }
4447 4447
4448 /* Populate the scatter/gather list */ 4448 /* Populate the scatter/gather list */
4449 sgl[0].page = pages[0]; 4449 sg_set_page(&sgl[0], pages[0]);
4450 sgl[0].offset = uaddr & ~PAGE_MASK; 4450 sgl[0].offset = uaddr & ~PAGE_MASK;
4451 if (nr_pages > 1) { 4451 if (nr_pages > 1) {
4452 sgl[0].length = PAGE_SIZE - sgl[0].offset; 4452 sgl[0].length = PAGE_SIZE - sgl[0].offset;
4453 count -= sgl[0].length; 4453 count -= sgl[0].length;
4454 for (i=1; i < nr_pages ; i++) { 4454 for (i=1; i < nr_pages ; i++) {
4455 sg_set_page(&sgl[i], pages[i]);;
4455 sgl[i].offset = 0; 4456 sgl[i].offset = 0;
4456 sgl[i].page = pages[i];
4457 sgl[i].length = count < PAGE_SIZE ? count : PAGE_SIZE; 4457 sgl[i].length = count < PAGE_SIZE ? count : PAGE_SIZE;
4458 count -= PAGE_SIZE; 4458 count -= PAGE_SIZE;
4459 } 4459 }
@@ -4483,7 +4483,7 @@ static int sgl_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_p
4483 int i; 4483 int i;
4484 4484
4485 for (i=0; i < nr_pages; i++) { 4485 for (i=0; i < nr_pages; i++) {
4486 struct page *page = sgl[i].page; 4486 struct page *page = sg_page(&sgl[i]);
4487 4487
4488 if (dirtied) 4488 if (dirtied)
4489 SetPageDirty(page); 4489 SetPageDirty(page);
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 4aafe89b557f..2dcde373b20e 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -272,8 +272,7 @@ static struct scsi_host_template *the_template = NULL;
272#define HOSTNO instance->host_no 272#define HOSTNO instance->host_no
273#define H_NO(cmd) (cmd)->device->host->host_no 273#define H_NO(cmd) (cmd)->device->host->host_no
274 274
275#define SGADDR(buffer) (void *)(((unsigned long)page_address((buffer)->page)) + \ 275#define SGADDR(buffer) (void *)(((unsigned long)sg_virt(((buffer)))))
276 (buffer)->offset)
277 276
278#ifdef SUPPORT_TAGS 277#ifdef SUPPORT_TAGS
279 278
diff --git a/drivers/scsi/sym53c416.c b/drivers/scsi/sym53c416.c
index 8befab7e9839..90cee94d9522 100644
--- a/drivers/scsi/sym53c416.c
+++ b/drivers/scsi/sym53c416.c
@@ -196,7 +196,7 @@ static unsigned int sym53c416_base_3[2] = {0,0};
196 196
197#define MAXHOSTS 4 197#define MAXHOSTS 4
198 198
199#define SG_ADDRESS(buffer) ((char *) (page_address((buffer)->page)+(buffer)->offset)) 199#define SG_ADDRESS(buffer) ((char *) sg_virt((buffer)))
200 200
201enum phases 201enum phases
202{ 202{
diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c
index 5c72ca31a47a..44193049c4ae 100644
--- a/drivers/scsi/tmscsim.c
+++ b/drivers/scsi/tmscsim.c
@@ -430,10 +430,7 @@ static __inline__ void dc390_Going_remove (struct dc390_dcb* pDCB, struct dc390_
430 430
431static struct scatterlist* dc390_sg_build_single(struct scatterlist *sg, void *addr, unsigned int length) 431static struct scatterlist* dc390_sg_build_single(struct scatterlist *sg, void *addr, unsigned int length)
432{ 432{
433 memset(sg, 0, sizeof(struct scatterlist)); 433 sg_init_one(sg, addr, length);
434 sg->page = virt_to_page(addr);
435 sg->length = length;
436 sg->offset = (unsigned long)addr & ~PAGE_MASK;
437 return sg; 434 return sg;
438} 435}
439 436
diff --git a/drivers/scsi/ultrastor.c b/drivers/scsi/ultrastor.c
index ea72bbeb8f9d..6d1f0edd7985 100644
--- a/drivers/scsi/ultrastor.c
+++ b/drivers/scsi/ultrastor.c
@@ -681,7 +681,7 @@ static inline void build_sg_list(struct mscp *mscp, struct scsi_cmnd *SCpnt)
681 681
682 max = scsi_sg_count(SCpnt); 682 max = scsi_sg_count(SCpnt);
683 scsi_for_each_sg(SCpnt, sg, max, i) { 683 scsi_for_each_sg(SCpnt, sg, max, i) {
684 mscp->sglist[i].address = isa_page_to_bus(sg->page) + sg->offset; 684 mscp->sglist[i].address = isa_page_to_bus(sg_page(sg)) + sg->offset;
685 mscp->sglist[i].num_bytes = sg->length; 685 mscp->sglist[i].num_bytes = sg->length;
686 transfer_length += sg->length; 686 transfer_length += sg->length;
687 } 687 }
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 0e8e642fd3b0..fdbb92d1f722 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -410,8 +410,7 @@ wd33c93_queuecommand(struct scsi_cmnd *cmd,
410 if (cmd->use_sg) { 410 if (cmd->use_sg) {
411 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer; 411 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
412 cmd->SCp.buffers_residual = cmd->use_sg - 1; 412 cmd->SCp.buffers_residual = cmd->use_sg - 1;
413 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 413 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
414 cmd->SCp.buffer->offset;
415 cmd->SCp.this_residual = cmd->SCp.buffer->length; 414 cmd->SCp.this_residual = cmd->SCp.buffer->length;
416 } else { 415 } else {
417 cmd->SCp.buffer = NULL; 416 cmd->SCp.buffer = NULL;
@@ -745,8 +744,7 @@ transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
745 ++cmd->SCp.buffer; 744 ++cmd->SCp.buffer;
746 --cmd->SCp.buffers_residual; 745 --cmd->SCp.buffers_residual;
747 cmd->SCp.this_residual = cmd->SCp.buffer->length; 746 cmd->SCp.this_residual = cmd->SCp.buffer->length;
748 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 747 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
749 cmd->SCp.buffer->offset;
750 } 748 }
751 if (!cmd->SCp.this_residual) /* avoid bogus setups */ 749 if (!cmd->SCp.this_residual) /* avoid bogus setups */
752 return; 750 return;
diff --git a/drivers/scsi/wd7000.c b/drivers/scsi/wd7000.c
index 255c611e78b8..03cd44f231df 100644
--- a/drivers/scsi/wd7000.c
+++ b/drivers/scsi/wd7000.c
@@ -1123,7 +1123,7 @@ static int wd7000_queuecommand(struct scsi_cmnd *SCpnt,
1123 any2scsi(scb->maxlen, nseg * sizeof(Sgb)); 1123 any2scsi(scb->maxlen, nseg * sizeof(Sgb));
1124 1124
1125 scsi_for_each_sg(SCpnt, sg, nseg, i) { 1125 scsi_for_each_sg(SCpnt, sg, nseg, i) {
1126 any2scsi(sgb[i].ptr, isa_page_to_bus(sg->page) + sg->offset); 1126 any2scsi(sgb[i].ptr, isa_page_to_bus(sg_page(sg)) + sg->offset);
1127 any2scsi(sgb[i].len, sg->length); 1127 any2scsi(sgb[i].len, sg->length);
1128 } 1128 }
1129 } else { 1129 } else {
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 8dd5a6afd513..90d64a808464 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -437,13 +437,11 @@ int usb_sg_init (
437#if defined(CONFIG_HIGHMEM) || defined(CONFIG_IOMMU) 437#if defined(CONFIG_HIGHMEM) || defined(CONFIG_IOMMU)
438 io->urbs[i]->transfer_buffer = NULL; 438 io->urbs[i]->transfer_buffer = NULL;
439#else 439#else
440 io->urbs[i]->transfer_buffer = 440 io->urbs[i]->transfer_buffer = sg_virt(&sg[i]);
441 page_address(sg[i].page) + sg[i].offset;
442#endif 441#endif
443 } else { 442 } else {
444 /* hc may use _only_ transfer_buffer */ 443 /* hc may use _only_ transfer_buffer */
445 io->urbs [i]->transfer_buffer = 444 io->urbs [i]->transfer_buffer = sg_virt(&sg[i]);
446 page_address (sg [i].page) + sg [i].offset;
447 len = sg [i].length; 445 len = sg [i].length;
448 } 446 }
449 447
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index e7d982a71548..91e999c9f680 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -519,8 +519,7 @@ static void mts_do_sg (struct urb* transfer)
519 context->fragment++; 519 context->fragment++;
520 mts_int_submit_urb(transfer, 520 mts_int_submit_urb(transfer,
521 context->data_pipe, 521 context->data_pipe,
522 page_address(sg[context->fragment].page) + 522 sg_virt(&sg[context->fragment]),
523 sg[context->fragment].offset,
524 sg[context->fragment].length, 523 sg[context->fragment].length,
525 context->fragment + 1 == scsi_sg_count(context->srb) ? 524 context->fragment + 1 == scsi_sg_count(context->srb) ?
526 mts_data_done : mts_do_sg); 525 mts_data_done : mts_do_sg);
@@ -557,7 +556,7 @@ mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
557 return; 556 return;
558 } else { 557 } else {
559 sg = scsi_sglist(srb); 558 sg = scsi_sglist(srb);
560 desc->context.data = page_address(sg[0].page) + sg[0].offset; 559 desc->context.data = sg_virt(&sg[0]);
561 desc->context.data_length = sg[0].length; 560 desc->context.data_length = sg[0].length;
562 } 561 }
563 562
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index e901d31e051b..ea3162146481 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -360,9 +360,9 @@ static void free_sglist (struct scatterlist *sg, int nents)
360 if (!sg) 360 if (!sg)
361 return; 361 return;
362 for (i = 0; i < nents; i++) { 362 for (i = 0; i < nents; i++) {
363 if (!sg [i].page) 363 if (!sg_page(&sg[i]))
364 continue; 364 continue;
365 kfree (page_address (sg [i].page) + sg [i].offset); 365 kfree (sg_virt(&sg[i]));
366 } 366 }
367 kfree (sg); 367 kfree (sg);
368} 368}
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index cc8f7c52c729..889622baac20 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -195,7 +195,7 @@ unsigned int usb_stor_access_xfer_buf(unsigned char *buffer,
195 * the *offset and *index values for the next loop. */ 195 * the *offset and *index values for the next loop. */
196 cnt = 0; 196 cnt = 0;
197 while (cnt < buflen) { 197 while (cnt < buflen) {
198 struct page *page = sg->page + 198 struct page *page = sg_page(sg) +
199 ((sg->offset + *offset) >> PAGE_SHIFT); 199 ((sg->offset + *offset) >> PAGE_SHIFT);
200 unsigned int poff = 200 unsigned int poff =
201 (sg->offset + *offset) & (PAGE_SIZE-1); 201 (sg->offset + *offset) & (PAGE_SIZE-1);