include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / block / hd.c
index 3c11f06..034e6df 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/fs.h>
 #include <linux/kernel.h>
 #include <linux/genhd.h>
-#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
 
 static DEFINE_SPINLOCK(hd_lock);
 static struct request_queue *hd_queue;
-
-#define MAJOR_NR HD_MAJOR
-#define QUEUE (hd_queue)
-#define CURRENT elv_next_request(hd_queue)
+static struct request *hd_req;
 
 #define TIMEOUT_VALUE  (6*HZ)
 #define        HD_DELAY        0
@@ -195,11 +191,24 @@ static void __init hd_setup(char *str, int *ints)
        NR_HD = hdind+1;
 }
 
+static bool hd_end_request(int err, unsigned int bytes)
+{
+       if (__blk_end_request(hd_req, err, bytes))
+               return true;
+       hd_req = NULL;
+       return false;
+}
+
+static bool hd_end_request_cur(int err)
+{
+       return hd_end_request(err, blk_rq_cur_bytes(hd_req));
+}
+
 static void dump_status(const char *msg, unsigned int stat)
 {
        char *name = "hd?";
-       if (CURRENT)
-               name = CURRENT->rq_disk->disk_name;
+       if (hd_req)
+               name = hd_req->rq_disk->disk_name;
 
 #ifdef VERBOSE_ERRORS
        printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
@@ -227,8 +236,8 @@ static void dump_status(const char *msg, unsigned int stat)
                if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
                        printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL),
                                inb(HD_CURRENT) & 0xf, inb(HD_SECTOR));
-                       if (CURRENT)
-                               printk(", sector=%ld", CURRENT->sector);
+                       if (hd_req)
+                               printk(", sector=%ld", blk_rq_pos(hd_req));
                }
                printk("\n");
        }
@@ -406,11 +415,12 @@ static void unexpected_hd_interrupt(void)
  */
 static void bad_rw_intr(void)
 {
-       struct request *req = CURRENT;
+       struct request *req = hd_req;
+
        if (req != NULL) {
                struct hd_i_struct *disk = req->rq_disk->private_data;
                if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) {
-                       end_request(req, 0);
+                       hd_end_request_cur(-EIO);
                        disk->special_op = disk->recalibrate = 1;
                } else if (req->errors % RESET_FREQ == 0)
                        reset = 1;
@@ -452,37 +462,30 @@ static void read_intr(void)
        bad_rw_intr();
        hd_request();
        return;
+
 ok_to_read:
-       req = CURRENT;
+       req = hd_req;
        insw(HD_DATA, req->buffer, 256);
-       req->sector++;
-       req->buffer += 512;
-       req->errors = 0;
-       i = --req->nr_sectors;
-       --req->current_nr_sectors;
 #ifdef DEBUG
-       printk("%s: read: sector %ld, remaining = %ld, buffer=%p\n",
-               req->rq_disk->disk_name, req->sector, req->nr_sectors,
-               req->buffer+512);
+       printk("%s: read: sector %ld, remaining = %u, buffer=%p\n",
+              req->rq_disk->disk_name, blk_rq_pos(req) + 1,
+              blk_rq_sectors(req) - 1, req->buffer+512);
 #endif
-       if (req->current_nr_sectors <= 0)
-               end_request(req, 1);
-       if (i > 0) {
+       if (hd_end_request(0, 512)) {
                SET_HANDLER(&read_intr);
                return;
        }
+
        (void) inb_p(HD_STATUS);
 #if (HD_DELAY > 0)
        last_req = read_timer();
 #endif
-       if (elv_next_request(QUEUE))
-               hd_request();
-       return;
+       hd_request();
 }
 
 static void write_intr(void)
 {
-       struct request *req = CURRENT;
+       struct request *req = hd_req;
        int i;
        int retries = 100000;
 
@@ -492,31 +495,25 @@ static void write_intr(void)
                        continue;
                if (!OK_STATUS(i))
                        break;
-               if ((req->nr_sectors <= 1) || (i & DRQ_STAT))
+               if ((blk_rq_sectors(req) <= 1) || (i & DRQ_STAT))
                        goto ok_to_write;
        } while (--retries > 0);
        dump_status("write_intr", i);
        bad_rw_intr();
        hd_request();
        return;
+
 ok_to_write:
-       req->sector++;
-       i = --req->nr_sectors;
-       --req->current_nr_sectors;
-       req->buffer += 512;
-       if (!i || (req->bio && req->current_nr_sectors <= 0))
-               end_request(req, 1);
-       if (i > 0) {
+       if (hd_end_request(0, 512)) {
                SET_HANDLER(&write_intr);
                outsw(HD_DATA, req->buffer, 256);
-               local_irq_enable();
-       } else {
+               return;
+       }
+
 #if (HD_DELAY > 0)
-               last_req = read_timer();
+       last_req = read_timer();
 #endif
-               hd_request();
-       }
-       return;
+       hd_request();
 }
 
 static void recal_intr(void)
@@ -538,23 +535,21 @@ static void hd_times_out(unsigned long dummy)
 
        do_hd = NULL;
 
-       if (!CURRENT)
+       if (!hd_req)
                return;
 
-       disable_irq(HD_IRQ);
-       local_irq_enable();
+       spin_lock_irq(hd_queue->queue_lock);
        reset = 1;
-       name = CURRENT->rq_disk->disk_name;
+       name = hd_req->rq_disk->disk_name;
        printk("%s: timeout\n", name);
-       if (++CURRENT->errors >= MAX_ERRORS) {
+       if (++hd_req->errors >= MAX_ERRORS) {
 #ifdef DEBUG
                printk("%s: too many errors\n", name);
 #endif
-               end_request(CURRENT, 0);
+               hd_end_request_cur(-EIO);
        }
-       local_irq_disable();
        hd_request();
-       enable_irq(HD_IRQ);
+       spin_unlock_irq(hd_queue->queue_lock);
 }
 
 static int do_special_op(struct hd_i_struct *disk, struct request *req)
@@ -566,7 +561,7 @@ static int do_special_op(struct hd_i_struct *disk, struct request *req)
        }
        if (disk->head > 16) {
                printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name);
-               end_request(req, 0);
+               hd_end_request_cur(-EIO);
        }
        disk->special_op = 0;
        return 1;
@@ -592,27 +587,28 @@ static void hd_request(void)
                return;
 repeat:
        del_timer(&device_timer);
-       local_irq_enable();
 
-       req = CURRENT;
-       if (!req) {
-               do_hd = NULL;
-               return;
+       if (!hd_req) {
+               hd_req = blk_fetch_request(hd_queue);
+               if (!hd_req) {
+                       do_hd = NULL;
+                       return;
+               }
        }
+       req = hd_req;
 
        if (reset) {
-               local_irq_disable();
                reset_hd();
                return;
        }
        disk = req->rq_disk->private_data;
-       block = req->sector;
-       nsect = req->nr_sectors;
+       block = blk_rq_pos(req);
+       nsect = blk_rq_sectors(req);
        if (block >= get_capacity(req->rq_disk) ||
            ((block+nsect) > get_capacity(req->rq_disk))) {
                printk("%s: bad access: block=%d, count=%d\n",
                        req->rq_disk->disk_name, block, nsect);
-               end_request(req, 0);
+               hd_end_request_cur(-EIO);
                goto repeat;
        }
 
@@ -652,7 +648,7 @@ repeat:
                        break;
                default:
                        printk("unknown hd-command\n");
-                       end_request(req, 0);
+                       hd_end_request_cur(-EIO);
                        break;
                }
        }
@@ -660,9 +656,7 @@ repeat:
 
 static void do_hd_request(struct request_queue *q)
 {
-       disable_irq(HD_IRQ);
        hd_request();
-       enable_irq(HD_IRQ);
 }
 
 static int hd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
@@ -684,16 +678,20 @@ static irqreturn_t hd_interrupt(int irq, void *dev_id)
 {
        void (*handler)(void) = do_hd;
 
+       spin_lock(hd_queue->queue_lock);
+
        do_hd = NULL;
        del_timer(&device_timer);
        if (!handler)
                handler = unexpected_hd_interrupt;
        handler();
-       local_irq_enable();
+
+       spin_unlock(hd_queue->queue_lock);
+
        return IRQ_HANDLED;
 }
 
-static struct block_device_operations hd_fops = {
+static const struct block_device_operations hd_fops = {
        .getgeo =       hd_getgeo,
 };
 
@@ -711,19 +709,19 @@ static int __init hd_init(void)
 {
        int drive;
 
-       if (register_blkdev(MAJOR_NR, "hd"))
+       if (register_blkdev(HD_MAJOR, "hd"))
                return -1;
 
        hd_queue = blk_init_queue(do_hd_request, &hd_lock);
        if (!hd_queue) {
-               unregister_blkdev(MAJOR_NR, "hd");
+               unregister_blkdev(HD_MAJOR, "hd");
                return -ENOMEM;
        }
 
-       blk_queue_max_sectors(hd_queue, 255);
+       blk_queue_max_hw_sectors(hd_queue, 255);
        init_timer(&device_timer);
        device_timer.function = hd_times_out;
-       blk_queue_hardsect_size(hd_queue, 512);
+       blk_queue_logical_block_size(hd_queue, 512);
 
        if (!NR_HD) {
                /*
@@ -750,7 +748,7 @@ static int __init hd_init(void)
                struct hd_i_struct *p = &hd_info[drive];
                if (!disk)
                        goto Enomem;
-               disk->major = MAJOR_NR;
+               disk->major = HD_MAJOR;
                disk->first_minor = drive << 6;
                disk->fops = &hd_fops;
                sprintf(disk->disk_name, "hd%c", 'a'+drive);
@@ -794,7 +792,7 @@ out1:
        NR_HD = 0;
 out:
        del_timer(&device_timer);
-       unregister_blkdev(MAJOR_NR, "hd");
+       unregister_blkdev(HD_MAJOR, "hd");
        blk_cleanup_queue(hd_queue);
        return -1;
 Enomem: