Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / scsi / pmcraid.c
index f7c70e2..c44e4ab 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * pmcraid.c -- driver for PMC Sierra MaxRAID controller adapters
  *
- * Written By: PMC Sierra Corporation
+ * Written By: Anil Ravindranath<anil_ravindranath@pmc-sierra.com>
+ *             PMC-Sierra Inc
  *
  * Copyright (C) 2008, 2009 PMC Sierra Inc
  *
@@ -40,6 +41,7 @@
 #include <linux/hdreg.h>
 #include <linux/version.h>
 #include <linux/io.h>
+#include <linux/slab.h>
 #include <asm/irq.h>
 #include <asm/processor.h>
 #include <linux/libata.h>
@@ -79,7 +81,7 @@ DECLARE_BITMAP(pmcraid_minor, PMCRAID_MAX_ADAPTERS);
 /*
  * Module parameters
  */
-MODULE_AUTHOR("PMC Sierra Corporation, anil_ravindranath@pmc-sierra.com");
+MODULE_AUTHOR("Anil Ravindranath<anil_ravindranath@pmc-sierra.com>");
 MODULE_DESCRIPTION("PMC Sierra MaxRAID Controller Driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(PMCRAID_DRIVER_VERSION);
@@ -162,10 +164,10 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
        spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
        list_for_each_entry(temp, &pinstance->used_res_q, queue) {
 
-               /* do not expose VSETs with order-ids >= 240 */
+               /* do not expose VSETs with order-ids > MAX_VSET_TARGETS */
                if (RES_IS_VSET(temp->cfg_entry)) {
                        target = temp->cfg_entry.unique_flags1;
-                       if (target >= PMCRAID_MAX_VSET_TARGETS)
+                       if (target > PMCRAID_MAX_VSET_TARGETS)
                                continue;
                        bus = PMCRAID_VSET_BUS_ID;
                        lun = 0;
@@ -234,7 +236,7 @@ static int pmcraid_slave_configure(struct scsi_device *scsi_dev)
                scsi_dev->allow_restart = 1;
                blk_queue_rq_timeout(scsi_dev->request_queue,
                                     PMCRAID_VSET_IO_TIMEOUT);
-               blk_queue_max_sectors(scsi_dev->request_queue,
+               blk_queue_max_hw_sectors(scsi_dev->request_queue,
                                      PMCRAID_VSET_MAX_SECTORS);
        }
 
@@ -278,12 +280,17 @@ static void pmcraid_slave_destroy(struct scsi_device *scsi_dev)
  * pmcraid_change_queue_depth - Change the device's queue depth
  * @scsi_dev: scsi device struct
  * @depth: depth to set
+ * @reason: calling context
  *
  * Return value
  *     actual depth set
  */
-static int pmcraid_change_queue_depth(struct scsi_device *scsi_dev, int depth)
+static int pmcraid_change_queue_depth(struct scsi_device *scsi_dev, int depth,
+                                     int reason)
 {
+       if (reason != SCSI_QDEPTH_DEFAULT)
+               return -EOPNOTSUPP;
+
        if (depth > PMCRAID_MAX_CMD_PER_LUN)
                depth = PMCRAID_MAX_CMD_PER_LUN;
 
@@ -1071,7 +1078,7 @@ static struct pmcraid_cmd *pmcraid_init_hcam
 
        ioarcb->data_transfer_length = cpu_to_le32(rcb_size);
 
-       ioadl[0].flags |= cpu_to_le32(IOADL_FLAGS_READ_LAST);
+       ioadl[0].flags |= IOADL_FLAGS_READ_LAST;
        ioadl[0].data_len = cpu_to_le32(rcb_size);
        ioadl[0].address = cpu_to_le32(dma);
 
@@ -1205,7 +1212,7 @@ static int pmcraid_expose_resource(struct pmcraid_config_table_entry *cfgte)
        int retval = 0;
 
        if (cfgte->resource_type == RES_TYPE_VSET)
-               retval = ((cfgte->unique_flags1 & 0xFF) < 0xFE);
+               retval = ((cfgte->unique_flags1 & 0x80) == 0);
        else if (cfgte->resource_type == RES_TYPE_GSCSI)
                retval = (RES_BUS(cfgte->resource_address) !=
                                PMCRAID_VIRTUAL_ENCL_BUS_ID);
@@ -1356,6 +1363,7 @@ static int pmcraid_notify_aen(struct pmcraid_instance *pinstance, u8 type)
  * Return value:
  *  none
  */
+
 static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
 {
        struct pmcraid_config_table_entry *cfg_entry;
@@ -1363,9 +1371,10 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
        struct pmcraid_cmd *cmd;
        struct pmcraid_cmd *cfgcmd;
        struct pmcraid_resource_entry *res = NULL;
-       u32 new_entry = 1;
        unsigned long lock_flags;
        unsigned long host_lock_flags;
+       u32 new_entry = 1;
+       u32 hidden_entry = 0;
        int rc;
 
        ccn_hcam = (struct pmcraid_hcam_ccn *)pinstance->ccn.hcam;
@@ -1401,9 +1410,15 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
        }
 
        /* If this resource is not going to be added to mid-layer, just notify
-        * applications and return
+        * applications and return. If this notification is about hiding a VSET
+        * resource, check if it was exposed already.
         */
-       if (!pmcraid_expose_resource(cfg_entry))
+       if (pinstance->ccn.hcam->notification_type ==
+           NOTIFICATION_TYPE_ENTRY_CHANGED &&
+           cfg_entry->resource_type == RES_TYPE_VSET &&
+           cfg_entry->unique_flags1 & 0x80) {
+               hidden_entry = 1;
+       } else if (!pmcraid_expose_resource(cfg_entry))
                goto out_notify_apps;
 
        spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
@@ -1419,6 +1434,12 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
 
        if (new_entry) {
 
+               if (hidden_entry) {
+                       spin_unlock_irqrestore(&pinstance->resource_lock,
+                                               lock_flags);
+                       goto out_notify_apps;
+               }
+
                /* If there are more number of resources than what driver can
                 * manage, do not notify the applications about the CCN. Just
                 * ignore this notifications and re-register the same HCAM
@@ -1449,8 +1470,9 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
                sizeof(struct pmcraid_config_table_entry));
 
        if (pinstance->ccn.hcam->notification_type ==
-           NOTIFICATION_TYPE_ENTRY_DELETED) {
+           NOTIFICATION_TYPE_ENTRY_DELETED || hidden_entry) {
                if (res->scsi_dev) {
+                       res->cfg_entry.unique_flags1 &= 0x7F;
                        res->change_detected = RES_CHANGE_DEL;
                        res->cfg_entry.resource_handle =
                                PMCRAID_INVALID_RES_HANDLE;
@@ -2251,7 +2273,7 @@ static void pmcraid_request_sense(struct pmcraid_cmd *cmd)
 
        ioadl->address = cpu_to_le64(cmd->sense_buffer_dma);
        ioadl->data_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE);
-       ioadl->flags = cpu_to_le32(IOADL_FLAGS_LAST_DESC);
+       ioadl->flags = IOADL_FLAGS_LAST_DESC;
 
        /* request sense might be called as part of error response processing
         * which runs in tasklets context. It is possible that mid-layer might
@@ -2462,14 +2484,12 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
                        sense_copied = 1;
                }
 
-               if (RES_IS_GSCSI(res->cfg_entry)) {
+               if (RES_IS_GSCSI(res->cfg_entry))
                        pmcraid_cancel_all(cmd, sense_copied);
-               } else if (sense_copied) {
+               else if (sense_copied)
                        pmcraid_erp_done(cmd);
-                       return 0;
-               } else  {
+               else
                        pmcraid_request_sense(cmd);
-               }
 
                return 1;
 
@@ -3017,7 +3037,7 @@ static int pmcraid_build_ioadl(
                ioadl[i].flags = 0;
        }
        /* setup last descriptor */
-       ioadl[i - 1].flags = cpu_to_le32(IOADL_FLAGS_LAST_DESC);
+       ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC;
 
        return 0;
 }
@@ -3342,7 +3362,7 @@ static int pmcraid_chr_fasync(int fd, struct file *filep, int mode)
  * @direction : data transfer direction
  *
  * Return value
- *  0 on sucess, non-zero error code on failure
+ *  0 on success, non-zero error code on failure
  */
 static int pmcraid_build_passthrough_ioadls(
        struct pmcraid_cmd *cmd,
@@ -3387,7 +3407,7 @@ static int pmcraid_build_passthrough_ioadls(
        }
 
        /* setup the last descriptor */
-       ioadl[i - 1].flags = cpu_to_le32(IOADL_FLAGS_LAST_DESC);
+       ioadl[i - 1].flags = IOADL_FLAGS_LAST_DESC;
 
        return 0;
 }
@@ -3401,7 +3421,7 @@ static int pmcraid_build_passthrough_ioadls(
  * @direction: data transfer direction
  *
  * Return value
- *  0 on sucess, non-zero error code on failure
+ *  0 on success, non-zero error code on failure
  */
 static void pmcraid_release_passthrough_ioadls(
        struct pmcraid_cmd *cmd,
@@ -3429,7 +3449,7 @@ static void pmcraid_release_passthrough_ioadls(
  * @arg: pointer to pmcraid_passthrough_buffer user buffer
  *
  * Return value
- *  0 on sucess, non-zero error code on failure
+ *  0 on success, non-zero error code on failure
  */
 static long pmcraid_ioctl_passthrough(
        struct pmcraid_instance *pinstance,
@@ -3731,12 +3751,6 @@ static int pmcraid_check_ioctl_buffer(
                return -EINVAL;
        }
 
-       /* buffer length can't be negetive */
-       if (hdr->buffer_length < 0) {
-               pmcraid_err("ioctl: invalid buffer length specified\n");
-               return -EINVAL;
-       }
-
        /* check for appropriate buffer access */
        if ((_IOC_DIR(cmd) & _IOC_READ) == _IOC_READ)
                access = VERIFY_WRITE;
@@ -5314,7 +5328,7 @@ static void pmcraid_querycfg(struct pmcraid_cmd *cmd)
                cpu_to_le32(sizeof(struct pmcraid_config_table));
 
        ioadl = &(ioarcb->add_data.u.ioadl[0]);
-       ioadl->flags = cpu_to_le32(IOADL_FLAGS_LAST_DESC);
+       ioadl->flags = IOADL_FLAGS_LAST_DESC;
        ioadl->address = cpu_to_le64(pinstance->cfg_table_bus_addr);
        ioadl->data_len = cpu_to_le32(sizeof(struct pmcraid_config_table));