block: implement blk_rq_pos/[cur_]sectors() and convert obvious ones
[linux-2.6.git] / drivers / block / ps3disk.c
index 8953e7c..c238867 100644 (file)
@@ -102,19 +102,17 @@ static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
                dev_dbg(&dev->sbd.core,
                        "%s:%u: bio %u: %u segs %u sectors from %lu\n",
                        __func__, __LINE__, i, bio_segments(iter.bio),
-                       bio_sectors(iter.bio),
-                       (unsigned long)iter.bio->bi_sector);
-
-                       size = bvec->bv_len;
-                       buf = bvec_kmap_irq(bvec, &flags);
-                       if (gather)
-                               memcpy(dev->bounce_buf+offset, buf, size);
-                       else
-                               memcpy(buf, dev->bounce_buf+offset, size);
-                       offset += size;
-                       flush_kernel_dcache_page(bvec->bv_page);
-                       bvec_kunmap_irq(bvec, &flags);
+                       bio_sectors(iter.bio), iter.bio->bi_sector);
 
+               size = bvec->bv_len;
+               buf = bvec_kmap_irq(bvec, &flags);
+               if (gather)
+                       memcpy(dev->bounce_buf+offset, buf, size);
+               else
+                       memcpy(buf, dev->bounce_buf+offset, size);
+               offset += size;
+               flush_kernel_dcache_page(bvec->bv_page);
+               bvec_kunmap_irq(bvec, &flags);
                i++;
        }
 }
@@ -138,12 +136,12 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
        dev_dbg(&dev->sbd.core,
                "%s:%u: %s req has %u bvecs for %lu sectors %lu hard sectors\n",
                __func__, __LINE__, op, n, req->nr_sectors,
-               req->hard_nr_sectors);
+               blk_rq_sectors(req));
 #endif
 
        start_sector = req->sector * priv->blocking_factor;
        sectors = req->nr_sectors * priv->blocking_factor;
-       dev_dbg(&dev->sbd.core, "%s:%u: %s %lu sectors starting at %lu\n",
+       dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
                __func__, __LINE__, op, sectors, start_sector);
 
        if (write) {
@@ -160,7 +158,7 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
        if (res) {
                dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
                        __LINE__, op, res);
-               end_request(req, 0);
+               __blk_end_request_cur(req, -EIO);
                return 0;
        }
 
@@ -180,9 +178,9 @@ static int ps3disk_submit_flush_request(struct ps3_storage_device *dev,
                                              LV1_STORAGE_ATA_HDDOUT, 0, 0, 0,
                                              0, &dev->tag);
        if (res) {
-               dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%lx\n",
+               dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n",
                        __func__, __LINE__, res);
-               end_request(req, 0);
+               __blk_end_request_cur(req, -EIO);
                return 0;
        }
 
@@ -201,12 +199,13 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
                if (blk_fs_request(req)) {
                        if (ps3disk_submit_request_sg(dev, req))
                                break;
-               } else if (req->cmd_type == REQ_TYPE_FLUSH) {
+               } else if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
+                          req->cmd[0] == REQ_LB_OP_FLUSH) {
                        if (ps3disk_submit_flush_request(dev, req))
                                break;
                } else {
                        blk_dump_rq_flags(req, DEVICE_NAME " bad request");
-                       end_request(req, 0);
+                       __blk_end_request_cur(req, -EIO);
                        continue;
                }
        }
@@ -230,20 +229,19 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
        struct ps3_storage_device *dev = data;
        struct ps3disk_private *priv;
        struct request *req;
-       int res, read, uptodate;
+       int res, read, error;
        u64 tag, status;
-       unsigned long num_sectors;
        const char *op;
 
        res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
 
        if (tag != dev->tag)
                dev_err(&dev->sbd.core,
-                       "%s:%u: tag mismatch, got %lx, expected %lx\n",
+                       "%s:%u: tag mismatch, got %llx, expected %llx\n",
                        __func__, __LINE__, tag, dev->tag);
 
        if (res) {
-               dev_err(&dev->sbd.core, "%s:%u: res=%d status=0x%lx\n",
+               dev_err(&dev->sbd.core, "%s:%u: res=%d status=0x%llx\n",
                        __func__, __LINE__, res, status);
                return IRQ_HANDLED;
        }
@@ -259,33 +257,28 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
                return IRQ_HANDLED;
        }
 
-       if (req->cmd_type == REQ_TYPE_FLUSH) {
+       if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
+           req->cmd[0] == REQ_LB_OP_FLUSH) {
                read = 0;
-               num_sectors = req->hard_cur_sectors;
                op = "flush";
        } else {
                read = !rq_data_dir(req);
-               num_sectors = req->nr_sectors;
                op = read ? "read" : "write";
        }
        if (status) {
-               dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%lx\n", __func__,
+               dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
                        __LINE__, op, status);
-               uptodate = 0;
+               error = -EIO;
        } else {
                dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__,
                        __LINE__, op);
-               uptodate = 1;
+               error = 0;
                if (read)
                        ps3disk_scatter_gather(dev, req, 0);
        }
 
        spin_lock(&priv->lock);
-       if (!end_that_request_first(req, uptodate, num_sectors)) {
-               add_disk_randomness(req->rq_disk);
-               blkdev_dequeue_request(req);
-               end_that_request_last(req, uptodate);
-       }
+       __blk_end_request_all(req, error);
        priv->req = NULL;
        ps3disk_do_request(dev, priv->queue);
        spin_unlock(&priv->lock);
@@ -301,7 +294,7 @@ static int ps3disk_sync_cache(struct ps3_storage_device *dev)
 
        res = ps3stor_send_command(dev, LV1_STORAGE_ATA_HDDOUT, 0, 0, 0, 0);
        if (res) {
-               dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%lx\n",
+               dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n",
                        __func__, __LINE__, res);
                return -EIO;
        }
@@ -392,7 +385,7 @@ static int ps3disk_identify(struct ps3_storage_device *dev)
                                   sizeof(ata_cmnd), ata_cmnd.buffer,
                                   ata_cmnd.arglen);
        if (res) {
-               dev_err(&dev->sbd.core, "%s:%u: identify disk failed 0x%lx\n",
+               dev_err(&dev->sbd.core, "%s:%u: identify disk failed 0x%llx\n",
                        __func__, __LINE__, res);
                return -EIO;
        }
@@ -411,30 +404,10 @@ static void ps3disk_prepare_flush(struct request_queue *q, struct request *req)
 
        dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
 
-       memset(req->cmd, 0, sizeof(req->cmd));
-       req->cmd_type = REQ_TYPE_FLUSH;
-}
-
-static int ps3disk_issue_flush(struct request_queue *q, struct gendisk *gendisk,
-                              sector_t *sector)
-{
-       struct ps3_storage_device *dev = q->queuedata;
-       struct request *req;
-       int res;
-
-       dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
-
-       req = blk_get_request(q, WRITE, __GFP_WAIT);
-       ps3disk_prepare_flush(q, req);
-       res = blk_execute_rq(q, gendisk, req, 0);
-       if (res)
-               dev_err(&dev->sbd.core, "%s:%u: flush request failed %d\n",
-                       __func__, __LINE__, res);
-       blk_put_request(req);
-       return res;
+       req->cmd_type = REQ_TYPE_LINUX_BLOCK;
+       req->cmd[0] = REQ_LB_OP_FLUSH;
 }
 
-
 static unsigned long ps3disk_mask;
 
 static DEFINE_MUTEX(ps3disk_mask_mutex);
@@ -450,7 +423,7 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
 
        if (dev->blk_size < 512) {
                dev_err(&dev->sbd.core,
-                       "%s:%u: cannot handle block size %lu\n", __func__,
+                       "%s:%u: cannot handle block size %llu\n", __func__,
                        __LINE__, dev->blk_size);
                return -EINVAL;
        }
@@ -507,7 +480,6 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
        blk_queue_dma_alignment(queue, dev->blk_size-1);
        blk_queue_hardsect_size(queue, dev->blk_size);
 
-       blk_queue_issue_flush_fn(queue, ps3disk_issue_flush);
        blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH,
                          ps3disk_prepare_flush);
 
@@ -537,7 +509,7 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
                     dev->regions[dev->region_idx].size*priv->blocking_factor);
 
        dev_info(&dev->sbd.core,
-                "%s is a %s (%lu MiB total, %lu MiB for OtherOS)\n",
+                "%s is a %s (%llu MiB total, %lu MiB for OtherOS)\n",
                 gendisk->disk_name, priv->model, priv->raw_capacity >> 11,
                 get_capacity(gendisk) >> 11);
 
@@ -566,7 +538,7 @@ static int ps3disk_remove(struct ps3_system_bus_device *_dev)
        struct ps3disk_private *priv = dev->sbd.core.driver_data;
 
        mutex_lock(&ps3disk_mask_mutex);
-       __clear_bit(priv->gendisk->first_minor / PS3DISK_MINORS,
+       __clear_bit(MINOR(disk_devt(priv->gendisk)) / PS3DISK_MINORS,
                    &ps3disk_mask);
        mutex_unlock(&ps3disk_mask_mutex);
        del_gendisk(priv->gendisk);