Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / block / cpqarray.c
index 53e90fc..00efcf0 100644 (file)
  *    along with this program; if not, write to the Free Software
  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- *    Questions/Comments/Bugfixes to Cpqarray-discuss@lists.sourceforge.net
+ *    Questions/Comments/Bugfixes to iss_storagedev@hp.com
  *
  */
 #include <linux/config.h>      /* CONFIG_PROC_FS */
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/types.h>
 #include <linux/pci.h>
 #include <linux/bio.h>
@@ -53,6 +52,7 @@
 /* Original author Chris Frantz - Compaq Computer Corporation */
 MODULE_AUTHOR("Compaq Computer Corporation");
 MODULE_DESCRIPTION("Driver for Compaq Smart2 Array Controllers version 2.6.0");
+MODULE_VERSION("2.6.0");
 MODULE_LICENSE("GPL");
 
 #include "cpqarray.h"
@@ -73,11 +73,11 @@ static ctlr_info_t *hba[MAX_CTLR];
 
 static int eisa[8];
 
-#define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
+#define NR_PRODUCTS ARRAY_SIZE(products)
 
 /*  board_id = Subsystem Device ID & Vendor ID
  *  product = Marketing Name for the board
- *  access = Address of the struct of function pointers 
+ *  access = Address of the struct of function pointers
  */
 static struct board_type products[] = {
        { 0x0040110E, "IDA",                    &smart1_access },
@@ -98,7 +98,7 @@ static struct board_type products[] = {
 };
 
 /* define the PCI info for the PCI cards this driver can control */
-const struct pci_device_id cpqarray_pci_device_id[] =
+static const struct pci_device_id cpqarray_pci_device_id[] =
 {
        { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_COMPAQ_42XX,
                0x0E11, 0x4058, 0, 0, 0},       /* SA431 */
@@ -136,9 +136,8 @@ static struct gendisk *ida_gendisk[MAX_CTLR][NWD];
 /* Debug Extra Paranoid... */
 #define DBGPX(s) do { } while(0)
 
-int cpqarray_init_step2(void);
 static int cpqarray_pci_init(ctlr_info_t *c, struct pci_dev *pdev);
-static void *remap_pci_mem(ulong base, ulong size);
+static void __iomem *remap_pci_mem(ulong base, ulong size);
 static int cpqarray_eisa_detect(void);
 static int pollcomplete(int ctlr);
 static void getgeometry(int ctlr);
@@ -162,6 +161,7 @@ static int sendcmd(
 static int ida_open(struct inode *inode, struct file *filep);
 static int ida_release(struct inode *inode, struct file *filep);
 static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg);
+static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo);
 static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io);
 
 static void do_ida_request(request_queue_t *q);
@@ -201,6 +201,7 @@ static struct block_device_operations ida_fops  = {
        .open           = ida_open,
        .release        = ida_release,
        .ioctl          = ida_ioctl,
+       .getgeo         = ida_getgeo,
        .revalidate_disk= ida_revalidate,
 };
 
@@ -311,15 +312,7 @@ static int ida_proc_get_info(char *buffer, char **start, off_t offset, int lengt
 }
 #endif /* CONFIG_PROC_FS */
 
-MODULE_PARM(eisa, "1-8i");
-
-/* This is a bit of a hack,
- * necessary to support both eisa and pci
- */
-int __init cpqarray_init(void)
-{
-       return (cpqarray_init_step2());
-}
+module_param_array(eisa, int, NULL, 0);
 
 static void release_io_mem(ctlr_info_t *c)
 {
@@ -418,7 +411,8 @@ static int cpqarray_register_ctlr( int i, struct pci_dev *pdev)
        }
        hba[i]->access.set_intr_mask(hba[i], 0);
        if (request_irq(hba[i]->intr, do_ida_intr,
-               SA_INTERRUPT|SA_SHIRQ, hba[i]->devname, hba[i]))
+               SA_INTERRUPT|SA_SHIRQ|SA_SAMPLE_RANDOM,
+               hba[i]->devname, hba[i]))
        {
                printk(KERN_ERR "cpqarray: Unable to get irq %d for %s\n",
                                hba[i]->intr, hba[i]->devname);
@@ -550,17 +544,17 @@ static int __init cpqarray_init_one( struct pci_dev *pdev,
 }
 
 static struct pci_driver cpqarray_pci_driver = {
-       name:   "cpqarray",
-       probe:  cpqarray_init_one,
-       remove:  __devexit_p(cpqarray_remove_one_pci),
-       id_table:  cpqarray_pci_device_id,
+       .name = "cpqarray",
+       .probe = cpqarray_init_one,
+       .remove = __devexit_p(cpqarray_remove_one_pci),
+       .id_table = cpqarray_pci_device_id,
 };
 
 /*
  *  This is it.  Find all the controllers and register them.
  *  returns the number of block devices registered.
  */
-int __init cpqarray_init_step2(void)
+static int __init cpqarray_init(void)
 {
        int num_cntlrs_reg = 0;
        int i;
@@ -568,9 +562,9 @@ int __init cpqarray_init_step2(void)
 
        /* detect controllers */
        printk(DRIVER_NAME "\n");
-/* TODO: If it's an eisa only system, will rc return negative? */
+
        rc = pci_register_driver(&cpqarray_pci_driver);
-       if (rc < 0)
+       if (rc)
                return rc;
        cpqarray_eisa_detect();
        
@@ -721,17 +715,16 @@ DBGINFO(
 /*
  * Map (physical) PCI mem into (virtual) kernel space
  */
-static void *remap_pci_mem(ulong base, ulong size)
+static void __iomem *remap_pci_mem(ulong base, ulong size)
 {
         ulong page_base        = ((ulong) base) & PAGE_MASK;
         ulong page_offs        = ((ulong) base) - page_base;
-        void *page_remapped    = ioremap(page_base, page_offs+size);
+        void __iomem *page_remapped    = ioremap(page_base, page_offs+size);
 
         return (page_remapped ? (page_remapped + page_offs) : NULL);
 }
 
 #ifndef MODULE
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
 /*
  * Config string is a comma separated set of i/o addresses of EISA cards.
  */
@@ -748,18 +741,6 @@ static int cpqarray_setup(char *str)
 
 __setup("smart2=", cpqarray_setup);
 
-#else
-
-/*
- * Copy the contents of the ints[] array passed to us by init.
- */
-void cpqarray_setup(char *str, int *ints)
-{
-       int i;
-       for(i=0; i<ints[0] && i<8; i++)
-               eisa[i] = ints[i+1];
-}
-#endif
 #endif
 
 /*
@@ -926,8 +907,7 @@ queue_next:
        if (!creq)
                goto startio;
 
-       if (creq->nr_phys_segments > SG_MAX)
-               BUG();
+       BUG_ON(creq->nr_phys_segments > SG_MAX);
 
        if ((c = cmd_alloc(h,1)) == NULL)
                goto startio;
@@ -1058,7 +1038,7 @@ static inline void complete_command(cmdlist_t *cmd, int timeout)
        complete_buffers(cmd->rq->bio, ok);
 
         DBGPX(printk("Done with %p\n", cmd->rq););
-       end_that_request_last(cmd->rq);
+       end_that_request_last(cmd->rq, ok ? 1 : -EIO);
 }
 
 /*
@@ -1146,6 +1126,23 @@ static void ida_timer(unsigned long tdata)
        h->misc_tflags = 0;
 }
 
+static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+       drv_info_t *drv = get_drv(bdev->bd_disk);
+
+       if (drv->cylinders) {
+               geo->heads = drv->heads;
+               geo->sectors = drv->sectors;
+               geo->cylinders = drv->cylinders;
+       } else {
+               geo->heads = 0xff;
+               geo->sectors = 0x3f;
+               geo->cylinders = drv->nr_blks / (0xff*0x3f);
+       }
+
+       return 0;
+}
+
 /*
  *  ida_ioctl does some miscellaneous stuff like reporting drive geometry,
  *  setting readahead and submitting commands from userspace to the controller.
@@ -1155,27 +1152,10 @@ static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
        drv_info_t *drv = get_drv(inode->i_bdev->bd_disk);
        ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
        int error;
-       int diskinfo[4];
-       struct hd_geometry *geo = (struct hd_geometry *)arg;
-       ida_ioctl_t *io = (ida_ioctl_t*)arg;
+       ida_ioctl_t __user *io = (ida_ioctl_t __user *)arg;
        ida_ioctl_t *my_io;
 
        switch(cmd) {
-       case HDIO_GETGEO:
-               if (drv->cylinders) {
-                       diskinfo[0] = drv->heads;
-                       diskinfo[1] = drv->sectors;
-                       diskinfo[2] = drv->cylinders;
-               } else {
-                       diskinfo[0] = 0xff;
-                       diskinfo[1] = 0x3f;
-                       diskinfo[2] = drv->nr_blks / (0xff*0x3f);
-               }
-               put_user(diskinfo[0], &geo->heads);
-               put_user(diskinfo[1], &geo->sectors);
-               put_user(diskinfo[2], &geo->cylinders);
-               put_user(get_start_sect(inode->i_bdev), &geo->start);
-               return 0;
        case IDAGETDRVINFO:
                if (copy_to_user(&io->c.drv, drv, sizeof(drv_info_t)))
                        return -EFAULT;
@@ -1193,7 +1173,7 @@ static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
                if (error)
                        goto out_passthru;
                error = -EFAULT;
-               if (copy_to_user(io, &my_io, sizeof(*my_io)))
+               if (copy_to_user(io, my_io, sizeof(*my_io)))
                        goto out_passthru;
                error = 0;
 out_passthru:
@@ -1201,7 +1181,7 @@ out_passthru:
                return error;
        case IDAGETCTLRSIG:
                if (!arg) return -EINVAL;
-               put_user(host->ctlr_sig, (int*)arg);
+               put_user(host->ctlr_sig, (int __user *)arg);
                return 0;
        case IDAREVALIDATEVOLS:
                if (iminor(inode) != 0)
@@ -1209,7 +1189,7 @@ out_passthru:
                return revalidate_allvol(host);
        case IDADRIVERVERSION:
                if (!arg) return -EINVAL;
-               put_user(DRIVER_VERSION, (unsigned long*)arg);
+               put_user(DRIVER_VERSION, (unsigned long __user *)arg);
                return 0;
        case IDAGETPCIINFO:
        {
@@ -1220,7 +1200,7 @@ out_passthru:
                pciinfo.bus = host->pci_dev->bus->number;
                pciinfo.dev_fn = host->pci_dev->devfn;
                pciinfo.board_id = host->board_id;
-               if(copy_to_user((void *) arg, &pciinfo,  
+               if(copy_to_user((void __user *) arg, &pciinfo,  
                        sizeof( ida_pci_info_struct)))
                                return -EFAULT;
                return(0);
@@ -1271,7 +1251,7 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io)
                        cmd_free(h, c, 0); 
                        return(error);
                }
-               if (copy_from_user(p, (void*)io->sg[0].addr, io->sg[0].size)) {
+               if (copy_from_user(p, io->sg[0].addr, io->sg[0].size)) {
                        kfree(p);
                        cmd_free(h, c, 0); 
                        return -EFAULT;
@@ -1312,7 +1292,7 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io)
                         cmd_free(h, c, 0);
                         return(error);
                 }
-               if (copy_from_user(p, (void*)io->sg[0].addr, io->sg[0].size)) {
+               if (copy_from_user(p, io->sg[0].addr, io->sg[0].size)) {
                        kfree(p);
                         cmd_free(h, c, 0);
                        return -EFAULT;
@@ -1353,7 +1333,7 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io)
        case DIAG_PASS_THRU:
        case SENSE_CONTROLLER_PERFORMANCE:
        case READ_FLASH_ROM:
-               if (copy_to_user((void*)io->sg[0].addr, p, io->sg[0].size)) {
+               if (copy_to_user(io->sg[0].addr, p, io->sg[0].size)) {
                        kfree(p);
                        return -EFAULT;
                }