[PATCH 1/1] scsi: megaraid_sas - Fix random failure of DCDB cmds with sense info

2007-11-20 Thread bo yang
Sense buffer ptr data type in the ioctl path is reverted back to u32 *
for x86 and x86_64 as in previous versions of driver. For IA64 it will
be unsigned long *. Compile time flag added for ia64 for this.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
Documentation/scsi/ChangeLog.megaraid_sas |   15 +++
drivers/scsi/megaraid/megaraid_sas.c  |   14 ++
drivers/scsi/megaraid/megaraid_sas.h  |6 +++---
 3 files changed, 28 insertions(+), 7 deletions(-)

diff -rupN linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 
linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas
--- linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 2007-11-20 
17:50:13.0 -0500
+++ linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas  2007-11-20 
21:37:16.0 -0500
@@ -1,3 +1,18 @@
+1 Release Date: Thur. Nov. 19 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+       Bo Yang
+
+2 Current Version : 00.00.03.17-RC1
+3 Older Version   : 00.00.03.16
+
+1. Fix random failure of DCDB cmds with sense info.
+
+Fix:   sense buffer ptr data type in the ioctl path is reverted back
+   to u32 * for x86, x86_64 as in previous versions of driver.
+   For IA64 it will be unsigned long *. Compile time flag added
+   for ia64 for this.
+
 1 Release Date: Thur. Nov. 07 16:30:43 PST 2007 -
(emaild-id:[EMAIL PROTECTED])
Sumant Patro
diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-11-20 
17:50:13.0 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-11-20 
17:50:13.0 -0500
@@ -10,7 +10,7 @@
  *2 of the License, or (at your option) any later version.
  *
  * FILE: megaraid_sas.c
- * Version : v00.00.03.16-rc1
+ * Version : v00.00.03.17-rc1
  *
  * Authors:
  * (email-id : [EMAIL PROTECTED])
@@ -3020,10 +3020,16 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
 * sense buffer address
 */
sense_buff = (unsigned long *) ((unsigned long)ioc->frame.raw +
-   ioc->sense_off);
-
-   if (copy_to_user((void __user *)(unsigned long)(*sense_buff),
+   ioc->sense_off);
+   sense_ptr = (u32 *) ((unsigned long)ioc->frame.raw +
+   ioc->sense_off);
+#if defined(__ia64__)
+   if (copy_to_user((void __user *)((unsigned long)(*sense_buff)),
+   sense, ioc->sense_len)) {
+#else
+   if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
sense, ioc->sense_len)) {
+#endif
printk(KERN_ERR "megasas: Failed to copy out to user "
"sense data\n");
error = -EFAULT;
diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h  2007-11-20 
17:50:13.0 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h   2007-11-20 
17:50:13.0 -0500
@@ -18,9 +18,9 @@
 /*
  * MegaRAID SAS Driver meta data
  */
-#define MEGASAS_VERSION"00.00.03.16-rc1"
-#define MEGASAS_RELDATE"Nov. 07, 2007"
-#define MEGASAS_EXT_VERSION"Thu. Nov. 07 10:09:32 PDT 2007"
+#define MEGASAS_VERSION"00.00.03.17-rc1"
+#define MEGASAS_RELDATE"Nov. 19, 2007"
+#define MEGASAS_EXT_VERSION"Mon. Nov. 19 10:09:32 PDT 2007"
 
 /*
  * Device IDs

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


PATCH 6/6] scsi: megaraid_sas - Update version and changelog

2007-11-09 Thread bo yang
Update version and changelog

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 Documentation/scsi/ChangeLog.megaraid_sas |  155 
 drivers/scsi/megaraid/megaraid_sas.c  |   10 -
 drivers/scsi/megaraid/megaraid_sas.h  |8 -
 3 files changed, 164 insertions(+), 9 deletions(-)

diff -rupN linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 
linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas
--- linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 2007-11-07 
02:42:15.908757968 -0500
+++ linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas  2007-11-07 
02:51:31.273329720 -0500
@@ -1,3 +1,158 @@
+1 Release Date: Thur. Nov. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+       Bo Yang 
+
+2 Current Version : 00.00.03.16
+3 Older Version   : 00.00.03.15
+
+1. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
+   respond to the INIT cmd.
+
+1 Release Date: Fri. Sep. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+       Bo Yang 
+
+2 Current Version : 00.00.03.15
+3 Older Version   : 00.00.03.14
+
+1. Added module parameter "poll_mode_io" to support for "polling" (reduced 
interrupt operation).
+   In this mode, IO completion interrupts are delayed. At the end of 
initiating IOs,
+   the driver schedules for cmd completion if there are pending cmds to be 
completed.
+   A timer-based interrupt has also been added to prevent IO completion 
processing from
+   being delayed indefinitely in the case that no new IOs are initiated.
+
+1 Release Date: Fri. Sep. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.14
+3 Older Version   : 00.00.03.13
+
+1. Setting the max_sectors_per_req based on max SGL supported by the FW. Prior 
versions calculated 
+   this value from controller info (max_sectors_1, max_sectors_2). For 
certain controllers/FW,
+   this was resulting in a value greater than max SGL supported by the FW. 
Issue was first
+   reported by users running LUKS+XFS with megaraid_sas.
+   Thanks to RB for providing the logs and duplication steps that helped 
to get to the root 
+   cause of the issue.
+2. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
+   respond to the INIT cmd.
+
+1 Release Date: Fri. June. 15 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.13
+3 Older Version   : 00.00.03.12
+
+1. Added the megasas_reset_timer routine to intercept cmd timeout and throttle 
io.
+
+On Fri, 2007-03-16 at 16:44 -0600, James Bottomley wrote:
+It looks like megaraid_sas at least needs this to throttle its commands
+> as they begin to time out.  The code keeps the existing transport
+> template use of eh_timed_out (and allows the transport to override the
+> host if they both have this callback).
+> 
+> James
+
+1 Release Date: Sat May. 12 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+       Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.12
+3 Older Version   : 00.00.03.11
+
+1.  When MegaSAS driver receives reset call from OS, driver waits in reset
+routine for max 3 minutes for all pending command completion. Now driver will
+call completion routine every 5 seconds from the reset routine instead of
+waiting for depending on cmd completion from isr path.
+
+1 Release Date: Mon Apr. 30 10:25:52 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+       Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.11
+3 Older Version   : 00.00.03.09
+
+   1. Memory Manager for IOCTL removed for 2.6 kernels.
+  pci_alloc_consistent replaced by dma_alloc_coherent. With this 
+  change there is no need of memory manager in the driver code
+
+   On Wed, 2007-02-07 at 13:30 -0800, Andrew Morton wrote:
+   > I suspect all this horror is due to stupidity in the DMA API.
+   >
+   > pci_alloc_consistent() just goes and assumes GFP_ATOMIC, whereas
+   > the caller (megasas_mgmt_fw_ioctl) would have been perfectly happy
+   > to use GFP_KERNEL.
+   >
+   > I bet this fixes it
+
+   It does, but the DMA API was expanded to cope with this exact case, so
+   use dma_alloc_coherent() directly in the megaraid code instead.  The dev
+   is just &pci_dev->dev.
+
+   James <[EMAIL PROTECTED]>
+
+   3. SYNCHRONIZE_CACHE is not supported by FW

[PATCH 5/6] scsi: megaraid_sas - support for poll_mode_io (reducedinterrupt)

2007-11-09 Thread bo yang
Added module parameter "poll_mode_io" to support for "polling" (reduced 
interrupt operation).
In this mode, IO completion interrupts are delayed. At the end of 
initiating IOs,
the driver schedules for cmd completion if there are pending cmds.
A timer-based interrupt has also been added to prevent IO completion 
from
being delayed indefinitely in the case that no new IOs are initiated. 
Some formatting issues in resume, suspend comment block also corrected

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  152 -
 drivers/scsi/megaraid/megaraid_sas.h |3
 2 files changed, 149 insertions(+), 6 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-11-07 
02:37:20.964596296 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-11-07 
02:37:52.930736704 -0500
@@ -46,6 +46,14 @@
 #include 
 #include "megaraid_sas.h"
 
+/*
+ * poll_mode_io:1- schedule complete completion from q cmd
+ */
+static unsigned int poll_mode_io;
+module_param_named(poll_mode_io, poll_mode_io, int, 0);
+MODULE_PARM_DESC(poll_mode_io,
+   "Complete cmds from IO path, (default=0)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -859,6 +867,12 @@ megasas_queue_command(struct scsi_cmnd *
atomic_inc(&instance->fw_outstanding);
 
instance->instancet->fire_cmd(cmd->frame_phys_addr 
,cmd->frame_count-1,instance->reg_set);
+   /*
+* Check if we have pend cmds to be completed
+*/
+   if (poll_mode_io && atomic_read(&instance->fw_outstanding))
+   tasklet_schedule(&instance->isr_tasklet);
+
 
return 0;
 
@@ -1891,6 +1905,47 @@ fail_fw_init:
 }
 
 /**
+ * megasas_start_timer - Initializes a timer object
+ * @instance:  Adapter soft state
+ * @timer: timer object to be initialized
+ * @fn:timer function
+ * @interval:  time interval between timer function call
+ */
+static inline void
+megasas_start_timer(struct megasas_instance *instance,
+   struct timer_list *timer,
+   void *fn, unsigned long interval)
+{
+   init_timer(timer);
+   timer->expires = jiffies + interval;
+   timer->data = (unsigned long)instance;
+   timer->function = fn;
+   add_timer(timer);
+}
+
+/**
+ * megasas_io_completion_timer - Timer fn
+ * @instance_addr: Address of adapter soft state
+ *
+ * Schedules tasklet for cmd completion
+ * if poll_mode_io is set
+ */
+static void
+megasas_io_completion_timer(unsigned long instance_addr)
+{
+   struct megasas_instance *instance =
+   (struct megasas_instance *)instance_addr;
+
+   if (atomic_read(&instance->fw_outstanding))
+   tasklet_schedule(&instance->isr_tasklet);
+
+   /* Restart timer */
+   if (poll_mode_io)
+   mod_timer(&instance->io_completion_timer,
+   jiffies + MEGASAS_COMPLETION_TIMER_INTERVAL);
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -2016,8 +2071,14 @@ static int megasas_init_mfi(struct megas
* Setup tasklet for cmd completion
*/
 
-tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc,
-(unsigned long)instance);
+   tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc,
+   (unsigned long)instance);
+
+   /* Initialize the cmd completion timer */
+   if (poll_mode_io)
+   megasas_start_timer(instance, &instance->io_completion_timer,
+   megasas_io_completion_timer,
+   MEGASAS_COMPLETION_TIMER_INTERVAL);
return 0;
 
   fail_fw_init:
@@ -2577,8 +2638,8 @@ static void megasas_shutdown_controller(
 }
 
 /**
- * megasas_suspend -driver suspend entry point
- * @pdev:   PCI device structure
+ * megasas_suspend -   driver suspend entry point
+ * @pdev:  PCI device structure
  * @state: PCI power state to suspend routine
  */
 static int __devinit
@@ -2590,6 +2651,9 @@ megasas_suspend(struct pci_dev *pdev, pm
instance = pci_get_drvdata(pdev);
host = instance->host;
 
+   if (poll_mode_io)
+   del_timer_sync(&instance->io_completion_timer);
+
megasas_flush_cache(instance);
megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
tasklet_kill(&instance->isr_tasklet);
@@ -2676,6 +2740,11 @@ megasas_resume(struct pci_dev *pdev)
   

[PATCH 4/6] scsi: megaraid_sas - call cmd completion from reset

2007-11-09 Thread bo yang
Driver will call cmd completion routine from Reset path without waiting for cmd 
completion from isr context.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  122 +
 drivers/scsi/megaraid/megaraid_sas.h |2
 2 files changed, 70 insertions(+), 54 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-11-07 
02:33:01.252078600 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-11-07 
02:33:32.746290752 -0500
@@ -76,6 +76,10 @@ static DEFINE_MUTEX(megasas_async_queue_
 
 static u32 megasas_dbg_lvl;
 
+static void
+megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd 
*cmd,
+u8 alt_status);
+
 /**
  * megasas_get_cmd -   Get a command from the free pool
  * @instance:  Adapter soft state
@@ -886,6 +890,64 @@ static int megasas_slave_configure(struc
 }
 
 /**
+ * megasas_complete_cmd_dpc -  Returns FW's controller structure
+ * @instance_addr: Address of adapter soft state
+ *
+ * Tasklet to complete cmds
+ */
+static void megasas_complete_cmd_dpc(unsigned long instance_addr)
+{
+   u32 producer;
+   u32 consumer;
+   u32 context;
+   struct megasas_cmd *cmd;
+   struct megasas_instance *instance =
+   (struct megasas_instance *)instance_addr;
+   unsigned long flags;
+
+   /* If we have already declared adapter dead, donot complete cmds */
+   if (instance->hw_crit_error)
+   return;
+
+   spin_lock_irqsave(&instance->completion_lock, flags);
+
+   producer = *instance->producer;
+   consumer = *instance->consumer;
+
+   while (consumer != producer) {
+   context = instance->reply_queue[consumer];
+
+   cmd = instance->cmd_list[context];
+
+   megasas_complete_cmd(instance, cmd, DID_OK);
+
+   consumer++;
+   if (consumer == (instance->max_fw_cmds + 1)) {
+   consumer = 0;
+   }
+   }
+
+   *instance->consumer = producer;
+
+   spin_unlock_irqrestore(&instance->completion_lock, flags);
+
+   /*
+* Check if we can restore can_queue
+*/
+   if (instance->flag & MEGASAS_FW_BUSY
+   && time_after(jiffies, instance->last_time + 5 * HZ)
+   && atomic_read(&instance->fw_outstanding) < 17) {
+
+   spin_lock_irqsave(instance->host->host_lock, flags);
+   instance->flag &= ~MEGASAS_FW_BUSY;
+   instance->host->can_queue =
+   instance->max_fw_cmds - MEGASAS_INT_CMDS;
+
+   spin_unlock_irqrestore(instance->host->host_lock, flags);
+   }
+}
+
+/**
  * megasas_wait_for_outstanding -  Wait for all outstanding cmds
  * @instance:  Adapter soft state
  *
@@ -908,6 +970,11 @@ static int megasas_wait_for_outstanding(
if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
   "commands to complete\n",i,outstanding);
+   /*
+* Call cmd completion routine. Cmd to be
+* be completed directly without depending on isr.
+*/
+   megasas_complete_cmd_dpc((unsigned long)instance);
}
 
msleep(1000);
@@ -1749,60 +1816,6 @@ megasas_get_ctrl_info(struct megasas_ins
 }
 
 /**
- * megasas_complete_cmd_dpc -  Returns FW's controller structure
- * @instance_addr: Address of adapter soft state
- *
- * Tasklet to complete cmds
- */
-static void megasas_complete_cmd_dpc(unsigned long instance_addr)
-{
-   u32 producer;
-   u32 consumer;
-   u32 context;
-   struct megasas_cmd *cmd;
-   struct megasas_instance *instance = (struct megasas_instance 
*)instance_addr;
-   unsigned long flags;
-
-   /* If we have already declared adapter dead, donot complete cmds */
-   if (instance->hw_crit_error)
-   return;
-
-   producer = *instance->producer;
-   consumer = *instance->consumer;
-
-   while (consumer != producer) {
-   context = instance->reply_queue[consumer];
-
-   cmd = instance->cmd_list[context];
-
-   megasas_complete_cmd(instance, cmd, DID_OK);
-
-   consumer++;
-   if (consumer == (instance->max_fw_cmds + 1)) {
-   consumer = 0;
-   }
-   }
-
-   *instance->consumer = producer;
-
-   /*
-* Ch

[PATCH 3/6] scsi: megaraid_sas - using unsigned long for sense_buff ptr

2007-11-09 Thread bo yang
MegaRAID utilities expect sense_buff to be of type unsigned long.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-11-07 
02:28:21.206651976 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-11-07 
02:29:11.219048936 -0500
@@ -2824,6 +2824,7 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
void *sense = NULL;
dma_addr_t sense_handle;
u32 *sense_ptr;
+   unsigned long *sense_buff;
 
memset(kbuff_arr, 0, sizeof(kbuff_arr));
 
@@ -2928,14 +2929,16 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
 */
if (ioc->sense_len) {
/*
-* sense_ptr points to the location that has the user
+* sense_buff points to the location that has the user
 * sense buffer address
 */
-   sense_ptr = (u32 *) ((unsigned long)ioc->frame.raw +
-ioc->sense_off);
+   sense_buff = (unsigned long *) ((unsigned long)ioc->frame.raw +
+   ioc->sense_off);
 
-   if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
-sense, ioc->sense_len)) {
+   if (copy_to_user((void __user *)(unsigned long)(*sense_buff),
+   sense, ioc->sense_len)) {
+   printk(KERN_ERR "megasas: Failed to copy out to user "
+   "sense data\n");
error = -EFAULT;
goto out;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/6] scsi: megaraid_sas - check max_sgl reported by FW forsetting max_sectors_per_req

2007-11-09 Thread bo yang
1. Setting the max_sectors_per_req based on max SGL supported by the FW. Prior 
versions calculated 
this value from controller info's max_sectors_1, max_sectors_2. For 
certain controllers/FW,
this was resulting in a value greater than max SGL supported by the FW. 
Now we take the min 
of max sgl from FW and max_sectors calculation.

2. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
respond to the INIT cmd.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   14 +-
 drivers/scsi/megaraid/megaraid_sas.h |2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-11-07 
02:01:52.687143648 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-11-07 
02:26:01.144944592 -0500
@@ -1889,6 +1889,7 @@ static int megasas_init_mfi(struct megas
u32 reply_q_sz;
u32 max_sectors_1;
u32 max_sectors_2;
+   u32 tmp_sectors;
struct megasas_register_set __iomem *reg_set;
struct megasas_ctrl_info *ctrl_info;
/*
@@ -1981,17 +1982,20 @@ static int megasas_init_mfi(struct megas
 * Note that older firmwares ( < FW ver 30) didn't report information
 * to calculate max_sectors_1. So the number ended up as zero always.
 */
+   tmp_sectors = 0;
if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) {
 
max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) *
ctrl_info->max_strips_per_io;
max_sectors_2 = ctrl_info->max_request_size;
 
-   instance->max_sectors_per_req = (max_sectors_1 < max_sectors_2)
-   ? max_sectors_1 : max_sectors_2;
-   } else
-   instance->max_sectors_per_req = instance->max_num_sge *
-   PAGE_SIZE / 512;
+   tmp_sectors = min_t(u32, max_sectors_1 , max_sectors_2);
+   }
+
+   instance->max_sectors_per_req = instance->max_num_sge *
+   PAGE_SIZE / 512;
+   if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors))
+   instance->max_sectors_per_req = tmp_sectors;
 
kfree(ctrl_info);
 
diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h  2007-11-07 
02:01:52.687143648 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h   2007-11-07 
02:21:17.349088120 -0500
@@ -571,7 +571,7 @@ struct megasas_ctrl_info {
 #define IS_DMA64   (sizeof(dma_addr_t) == 8)
 
 #define MFI_OB_INTR_STATUS_MASK0x0002
-#define MFI_POLL_TIMEOUT_SECS  10
+#define MFI_POLL_TIMEOUT_SECS  60
 
 #define MFI_REPLY_1078_MESSAGE_INTERRUPT   0x8000
 

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/6] scsi: megaraid_sas - add hibernation support

2007-11-09 Thread bo yang
Adding hibernation support. suspend, resume routine implemented.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  302 +++--
 drivers/scsi/megaraid/megaraid_sas.h |1
 2 files changed, 233 insertions(+), 70 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-11-07 
01:37:18.129310512 -0500
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-11-07 
01:36:25.261347664 -0500
@@ -1803,6 +1803,81 @@ static void megasas_complete_cmd_dpc(uns
 }
 
 /**
+ * megasas_issue_init_mfi -Initializes the FW
+ * @instance:  Adapter soft state
+ *
+ * Issues the INIT MFI cmd
+ */
+static int
+megasas_issue_init_mfi(struct megasas_instance *instance)
+{
+   u32 context;
+
+   struct megasas_cmd *cmd;
+
+   struct megasas_init_frame *init_frame;
+   struct megasas_init_queue_info *initq_info;
+   dma_addr_t init_frame_h;
+   dma_addr_t initq_info_h;
+
+   /*
+* Prepare a init frame. Note the init frame points to queue info
+* structure. Each frame has SGL allocated after first 64 bytes. For
+* this frame - since we don't need any SGL - we use SGL's space as
+* queue info structure
+*
+* We will not get a NULL command below. We just created the pool.
+*/
+   cmd = megasas_get_cmd(instance);
+
+   init_frame = (struct megasas_init_frame *)cmd->frame;
+   initq_info = (struct megasas_init_queue_info *)
+   ((unsigned long)init_frame + 64);
+
+   init_frame_h = cmd->frame_phys_addr;
+   initq_info_h = init_frame_h + 64;
+
+   context = init_frame->context;
+   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
+   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
+   init_frame->context = context;
+
+   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
+   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
+
+   initq_info->producer_index_phys_addr_lo = instance->producer_h;
+   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
+
+   init_frame->cmd = MFI_CMD_INIT;
+   init_frame->cmd_status = 0xFF;
+   init_frame->queue_info_new_phys_addr_lo = initq_info_h;
+
+   init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info);
+
+   /*
+* disable the intr before firing the init frame to FW
+*/
+   instance->instancet->disable_intr(instance->reg_set);
+
+   /*
+* Issue the init frame in polled mode
+*/
+
+   if (megasas_issue_polled(instance, cmd)) {
+   printk(KERN_ERR "megasas: Failed to init firmware\n");
+   megasas_return_cmd(instance, cmd);
+   goto fail_fw_init;
+   }
+
+   megasas_return_cmd(instance, cmd);
+
+   return 0;
+
+fail_fw_init:
+   return -EINVAL;
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -1815,15 +1890,7 @@ static int megasas_init_mfi(struct megas
u32 max_sectors_1;
u32 max_sectors_2;
struct megasas_register_set __iomem *reg_set;
-
-   struct megasas_cmd *cmd;
struct megasas_ctrl_info *ctrl_info;
-
-   struct megasas_init_frame *init_frame;
-   struct megasas_init_queue_info *initq_info;
-   dma_addr_t init_frame_h;
-   dma_addr_t initq_info_h;
-
/*
 * Map the message registers
 */
@@ -1900,52 +1967,8 @@ static int megasas_init_mfi(struct megas
goto fail_reply_queue;
}
 
-   /*
-* Prepare a init frame. Note the init frame points to queue info
-* structure. Each frame has SGL allocated after first 64 bytes. For
-* this frame - since we don't need any SGL - we use SGL's space as
-* queue info structure
-*
-* We will not get a NULL command below. We just created the pool.
-*/
-   cmd = megasas_get_cmd(instance);
-
-   init_frame = (struct megasas_init_frame *)cmd->frame;
-   initq_info = (struct megasas_init_queue_info *)
-   ((unsigned long)init_frame + 64);
-
-   init_frame_h = cmd->frame_phys_addr;
-   initq_info_h = init_frame_h + 64;
-
-   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
-   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
-
-   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
-   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
-
-   initq_info->producer_index_phys_addr_lo = instance->producer_h;
-   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
-
-   init_frame->cmd = MFI_CMD_INI

[PATCH 8/8] scsi: megaraid_sas - Update version and changelog

2007-10-03 Thread bo yang
Update version and changelog. 
Updated "LSI Logic" to new name "LSI"

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 Documentation/scsi/ChangeLog.megaraid_sas |  160 
 drivers/scsi/megaraid/megaraid_sas.c  |   10 -
 drivers/scsi/megaraid/megaraid_sas.h  |8 -
 3 files changed, 169 insertions(+), 9 deletions(-)

diff -uprN linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 
linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas
--- linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 2007-10-01 
00:03:59.0 -0700
+++ linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas  2007-10-01 
00:03:59.0 -0700
@@ -1,3 +1,163 @@
+1 Release Date: Thur. Sep. 27 10:09:32 PDT 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.16-rc1
+3 Older Version   : 00.00.03.15
+
+1. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
+   respond to the INIT cmd.
+
+1 Release Date: Fri. Sep. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.15
+3 Older Version   : 00.00.03.14
+
+1. Added module parameter "poll_mode_io" to support for "polling" (reduced 
interrupt operation).
+   In this mode, IO completion interrupts are delayed. At the end of 
initiating IOs,
+   the driver schedules for cmd completion if there are pending cmds to be 
completed.
+   A timer-based interrupt has also been added to prevent IO completion 
processing from
+   being delayed indefinitely in the case that no new IOs are initiated.
+
+1 Release Date: Fri. Sep. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+       Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.14
+3 Older Version   : 00.00.03.13
+
+1. Setting the max_sectors_per_req based on max SGL supported by the FW. Prior 
versions calculated 
+   this value from controller info (max_sectors_1, max_sectors_2). For 
certain controllers/FW,
+   this was resulting in a value greater than max SGL supported by the FW. 
Issue was first
+   reported by users running LUKS+XFS with megaraid_sas.
+   Thanks to RB for providing the logs and duplication steps that helped 
to get to the root 
+   cause of the issue.
+2. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
+   respond to the INIT cmd.
+
+1 Release Date: Fri. June. 15 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+       Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.13
+3 Older Version   : 00.00.03.12
+
+1. Added the megasas_reset_timer routine to intercept cmd timeout and throttle 
io.
+
+On Fri, 2007-03-16 at 16:44 -0600, James Bottomley wrote:
+It looks like megaraid_sas at least needs this to throttle its commands
+> as they begin to time out.  The code keeps the existing transport
+> template use of eh_timed_out (and allows the transport to override the
+> host if they both have this callback).
+> 
+> James
+
+1 Release Date: Sat May. 12 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.12
+3 Older Version   : 00.00.03.11
+
+1.  When MegaSAS driver receives reset call from OS, driver waits in reset
+routine for max 3 minutes for all pending command completion. Now driver will
+call completion routine every 5 seconds from the reset routine instead of
+waiting for depending on cmd completion from isr path.
+
+1 Release Date: Mon Apr. 30 10:25:52 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.11
+3 Older Version   : 00.00.03.09
+
+   1. Following module parameters added -
+   fast_load: Faster loading of the driver, skips physical devices 
scanning thereby
+   reducing the time to load driver.
+   cmd_per_lun: Maximum number of commands per logical unit
+   max_sectors: Maximum number of sectors per IO command
+   2. Memory Manager for IOCTL removed for 2.6 kernels.
+  pci_alloc_consistent replaced by dma_alloc_coherent. With this 
+  change there is no need of memory manager in the driver code
+
+   On Wed, 2007-02-07 at 13:30 -0800, Andrew Morton wrote:
+   > I suspect all this horror is due to stupidity in the DMA API.
+   >
+   > pci_alloc_consistent() just goes and assumes GFP_ATOMIC, whereas
+   > the caller (megasas_m

[PATCH 7/8] scsi: megaraid_sas - support for poll_mode_io (reduced interrupt)

2007-10-03 Thread bo yang
Added module parameter "poll_mode_io" to support for "polling" (reduced 
interrupt operation). 
In this mode, IO completion interrupts are delayed. At the end of 
initiating IOs, the 
driver schedules for cmd completion if there are pending cmds. A 
timer-based interrupt 
has also been added to prevent IO completion from being delayed 
indefinitely in the 
case that no new IOs are initiated.  The user is expected to tune the 
interrupt 
throttling parameters using MegaRAID utility and then set poll_mode_io. 
Some formatting 
issues in resume, suspend comment block also corrected

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  152 -
 drivers/scsi/megaraid/megaraid_sas.h |3
 2 files changed, 149 insertions(+), 6 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-02 
23:33:02.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-02 
23:32:34.0 -0700
@@ -79,6 +79,14 @@ module_param_named(cmd_per_lun, cmd_per_
 MODULE_PARM_DESC(cmd_per_lun,
"Maximum number of commands per logical unit (default=128)");
 
+/*
+ * poll_mode_io:1- schedule complete completion from q cmd
+ */
+static unsigned int poll_mode_io;
+module_param_named(poll_mode_io, poll_mode_io, int, 0);
+MODULE_PARM_DESC(poll_mode_io,
+   "Complete cmds from IO path, (default=0)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -892,6 +900,12 @@ megasas_queue_command(struct scsi_cmnd *
atomic_inc(&instance->fw_outstanding);
 
instance->instancet->fire_cmd(cmd->frame_phys_addr 
,cmd->frame_count-1,instance->reg_set);
+   /*
+* Check if we have pend cmds to be completed
+*/
+   if (poll_mode_io && atomic_read(&instance->fw_outstanding))
+   tasklet_schedule(&instance->isr_tasklet);
+
 
return 0;
 
@@ -1981,6 +1995,47 @@ fail_fw_init:
 }
 
 /**
+ * megasas_start_timer - Initializes a timer object
+ * @instance:  Adapter soft state
+ * @timer: timer object to be initialized
+ * @fn:timer function
+ * @interval:  time interval between timer function call
+ */
+static inline void
+megasas_start_timer(struct megasas_instance *instance,
+   struct timer_list *timer,
+   void *fn, unsigned long interval)
+{
+   init_timer(timer);
+   timer->expires = jiffies + interval;
+   timer->data = (unsigned long)instance;
+   timer->function = fn;
+   add_timer(timer);
+}
+
+/**
+ * megasas_io_completion_timer - Timer fn
+ * @instance_addr: Address of adapter soft state
+ *
+ * Schedules tasklet for cmd completion
+ * if poll_mode_io is set
+ */
+static void
+megasas_io_completion_timer(unsigned long instance_addr)
+{
+   struct megasas_instance *instance =
+   (struct megasas_instance *)instance_addr;
+
+   if (atomic_read(&instance->fw_outstanding))
+   tasklet_schedule(&instance->isr_tasklet);
+
+   /* Restart timer */
+   if (poll_mode_io)
+   mod_timer(&instance->io_completion_timer,
+   jiffies + MEGASAS_COMPLETION_TIMER_INTERVAL);
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -2106,8 +2161,14 @@ static int megasas_init_mfi(struct megas
* Setup tasklet for cmd completion
*/
 
-tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc,
-(unsigned long)instance);
+   tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc,
+   (unsigned long)instance);
+
+   /* Initialize the cmd completion timer */
+   if (poll_mode_io)
+   megasas_start_timer(instance, &instance->io_completion_timer,
+   megasas_io_completion_timer,
+   MEGASAS_COMPLETION_TIMER_INTERVAL);
return 0;
 
   fail_fw_init:
@@ -2695,8 +2756,8 @@ static void megasas_shutdown_controller(
 }
 
 /**
- * megasas_suspend -driver suspend entry point
- * @pdev:   PCI device structure
+ * megasas_suspend -   driver suspend entry point
+ * @pdev:  PCI device structure
  * @state: PCI power state to suspend routine
  */
 static int __devinit
@@ -2708,6 +2769,9 @@ megasas_suspend(struct pci_dev *pdev, pm
instance = pci_get_drvdata(pdev);
host = instance->host;
 
+   if (poll_mode_io)
+   del_timer_sync(&instance->io_completion_timer);
+

[PATCH 6/8] scsi: megaraid_sas - call cmd completion from reset

2007-10-03 Thread bo yang
Driver will call cmd completion routine from Reset path without waiting for cmd 
completion from isr context.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  122 +
 drivers/scsi/megaraid/megaraid_sas.h |2
 2 files changed, 70 insertions(+), 54 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-02 
22:41:39.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-02 
23:32:05.0 -0700
@@ -109,6 +109,10 @@ static DEFINE_MUTEX(megasas_async_queue_
 
 static u32 megasas_dbg_lvl;
 
+static void
+megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd 
*cmd,
+u8 alt_status);
+
 /**
  * megasas_get_cmd -   Get a command from the free pool
  * @instance:  Adapter soft state
@@ -919,6 +923,64 @@ static int megasas_slave_configure(struc
 }
 
 /**
+ * megasas_complete_cmd_dpc -  Returns FW's controller structure
+ * @instance_addr: Address of adapter soft state
+ *
+ * Tasklet to complete cmds
+ */
+static void megasas_complete_cmd_dpc(unsigned long instance_addr)
+{
+   u32 producer;
+   u32 consumer;
+   u32 context;
+   struct megasas_cmd *cmd;
+   struct megasas_instance *instance =
+   (struct megasas_instance *)instance_addr;
+   unsigned long flags;
+
+   /* If we have already declared adapter dead, donot complete cmds */
+   if (instance->hw_crit_error)
+   return;
+
+   spin_lock_irqsave(&instance->completion_lock, flags);
+
+   producer = *instance->producer;
+   consumer = *instance->consumer;
+
+   while (consumer != producer) {
+   context = instance->reply_queue[consumer];
+
+   cmd = instance->cmd_list[context];
+
+   megasas_complete_cmd(instance, cmd, DID_OK);
+
+   consumer++;
+   if (consumer == (instance->max_fw_cmds + 1)) {
+   consumer = 0;
+   }
+   }
+
+   *instance->consumer = producer;
+
+   spin_unlock_irqrestore(&instance->completion_lock, flags);
+
+   /*
+* Check if we can restore can_queue
+*/
+   if (instance->flag & MEGASAS_FW_BUSY
+   && time_after(jiffies, instance->last_time + 5 * HZ)
+   && atomic_read(&instance->fw_outstanding) < 17) {
+
+   spin_lock_irqsave(instance->host->host_lock, flags);
+   instance->flag &= ~MEGASAS_FW_BUSY;
+   instance->host->can_queue =
+   instance->max_fw_cmds - MEGASAS_INT_CMDS;
+
+   spin_unlock_irqrestore(instance->host->host_lock, flags);
+   }
+}
+
+/**
  * megasas_wait_for_outstanding -  Wait for all outstanding cmds
  * @instance:  Adapter soft state
  *
@@ -941,6 +1003,11 @@ static int megasas_wait_for_outstanding(
if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
   "commands to complete\n",i,outstanding);
+   /*
+* Call cmd completion routine. Cmd to be
+* be completed directly without depending on isr.
+*/
+   megasas_complete_cmd_dpc((unsigned long)instance);
}
 
msleep(1000);
@@ -1839,60 +1906,6 @@ megasas_get_ctrl_info(struct megasas_ins
 }
 
 /**
- * megasas_complete_cmd_dpc -  Returns FW's controller structure
- * @instance_addr: Address of adapter soft state
- *
- * Tasklet to complete cmds
- */
-static void megasas_complete_cmd_dpc(unsigned long instance_addr)
-{
-   u32 producer;
-   u32 consumer;
-   u32 context;
-   struct megasas_cmd *cmd;
-   struct megasas_instance *instance = (struct megasas_instance 
*)instance_addr;
-   unsigned long flags;
-
-   /* If we have already declared adapter dead, donot complete cmds */
-   if (instance->hw_crit_error)
-   return;
-
-   producer = *instance->producer;
-   consumer = *instance->consumer;
-
-   while (consumer != producer) {
-   context = instance->reply_queue[consumer];
-
-   cmd = instance->cmd_list[context];
-
-   megasas_complete_cmd(instance, cmd, DID_OK);
-
-   consumer++;
-   if (consumer == (instance->max_fw_cmds + 1)) {
-   consumer = 0;
-   }
-   }
-
-   *instance->consumer = producer;
-
-   /*
-* Ch

[PATCH 5/8] scsi: megaraid_sas - using unsigned long for sense_buff ptr

2007-10-03 Thread bo yang
MegaRAID utilities expect sense_buff to be of type unsigned long.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-01 
05:20:03.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-02 
22:40:22.0 -0700
@@ -2942,6 +2942,7 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
void *sense = NULL;
dma_addr_t sense_handle;
u32 *sense_ptr;
+   unsigned long *sense_buff;
 
memset(kbuff_arr, 0, sizeof(kbuff_arr));
 
@@ -3046,14 +3047,16 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
 */
if (ioc->sense_len) {
/*
-* sense_ptr points to the location that has the user
+* sense_buff points to the location that has the user
 * sense buffer address
 */
-   sense_ptr = (u32 *) ((unsigned long)ioc->frame.raw +
-ioc->sense_off);
+   sense_buff = (unsigned long *) ((unsigned long)ioc->frame.raw +
+   ioc->sense_off);
 
-   if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
-sense, ioc->sense_len)) {
+   if (copy_to_user((void __user *)(unsigned long)(*sense_buff),
+   sense, ioc->sense_len)) {
+   printk(KERN_ERR "megasas: Failed to copy out to user "
+   "sense data\n");
error = -EFAULT;
goto out;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/8] scsi: megaraid_sas - check max_sgl reported by FW for setting max_sectors_per_req

2007-10-03 Thread bo yang
1. Setting the max_sectors_per_req based on max SGL supported by the FW. Prior 
versions calculated  
this value from controller info's max_sectors_1, max_sectors_2. For 
certain controllers/FW, 
this was resulting in a value greater than max SGL supported by the FW. 
Now we take the min  
of max sgl from FW and max_sectors calculation.

2. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to  
respond to the INIT cmd.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   14 +-
 drivers/scsi/megaraid/megaraid_sas.h |2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-01 
02:42:25.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-01 
05:19:06.0 -0700
@@ -1979,6 +1979,7 @@ static int megasas_init_mfi(struct megas
u32 reply_q_sz;
u32 max_sectors_1;
u32 max_sectors_2;
+   u32 tmp_sectors;
struct megasas_register_set __iomem *reg_set;
struct megasas_ctrl_info *ctrl_info;
/*
@@ -2071,17 +2072,20 @@ static int megasas_init_mfi(struct megas
 * Note that older firmwares ( < FW ver 30) didn't report information
 * to calculate max_sectors_1. So the number ended up as zero always.
 */
+   tmp_sectors = 0;
if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) {
 
max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) *
ctrl_info->max_strips_per_io;
max_sectors_2 = ctrl_info->max_request_size;
 
-   instance->max_sectors_per_req = (max_sectors_1 < max_sectors_2)
-   ? max_sectors_1 : max_sectors_2;
-   } else
-   instance->max_sectors_per_req = instance->max_num_sge *
-   PAGE_SIZE / 512;
+   tmp_sectors = min_t(u32, max_sectors_1 , max_sectors_2);
+   }
+
+   instance->max_sectors_per_req = instance->max_num_sge *
+   PAGE_SIZE / 512;
+   if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors))
+   instance->max_sectors_per_req = tmp_sectors;
 
kfree(ctrl_info);
 
diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h  2007-10-01 
00:03:59.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h   2007-10-01 
00:03:59.0 -0700
@@ -572,7 +572,7 @@ struct megasas_ctrl_info {
 #define IS_DMA64   (sizeof(dma_addr_t) == 8)
 
 #define MFI_OB_INTR_STATUS_MASK0x0002
-#define MFI_POLL_TIMEOUT_SECS  10
+#define MFI_POLL_TIMEOUT_SECS  60
 
 #define MFI_REPLY_1078_MESSAGE_INTERRUPT   0x8000
 



-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/8] scsi: megaraid_sas - add module param max_sectors, cmd_per_lun

2007-10-03 Thread bo yang
Adding module parameters to configure max sectors per request & # of cmds per 
lun.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   68 -
 drivers/scsi/megaraid/megaraid_sas.h |2
 2 files changed, 68 insertions(+), 2 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-01 
00:14:29.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-01 
02:15:16.0 -0700
@@ -62,6 +62,23 @@ MODULE_PARM_DESC(fast_load,
"megasas: Faster loading of the driver, skips physical devices! "\
"(default = 0)");
 
+/*
+ * Number of sectors per IO command will be set in megasas_init_mfi
+ * if user does not provide
+ */
+static unsigned int max_sectors;
+module_param_named(max_sectors, max_sectors, int, 0);
+MODULE_PARM_DESC(max_sectors,
+   "Maximum number of sectors per IO command");
+
+/*
+ * Number of cmds per logical unit
+ */
+static unsigned int cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
+module_param_named(cmd_per_lun, cmd_per_lun, int, 0);
+MODULE_PARM_DESC(cmd_per_lun,
+   "Maximum number of commands per logical unit (default=128)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -1148,6 +1165,24 @@ static int megasas_slave_alloc(struct sc
return 0;
 }
 
+static ssize_t
+megasas_sysfs_max_sectors_read(struct class_device *cdev, char *buf)
+{
+   struct Scsi_Host *shost = class_to_shost(cdev);
+   struct megasas_instance *instance =
+   (struct megasas_instance *)shost->hostdata;
+
+   return snprintf(buf, 8, "%u\n", instance->max_sectors_per_req);
+}
+
+CLASS_DEVICE_ATTR(max_sectors, S_IRUGO, megasas_sysfs_max_sectors_read,
+   NULL);
+
+static struct class_device_attribute *megasas_shost_attrs[] = {
+   &class_device_attr_max_sectors,
+   NULL,
+};
+
 /*
  * Scsi host template for megaraid_sas driver
  */
@@ -1165,6 +1200,7 @@ static struct scsi_host_template megasas
.eh_timed_out = megasas_reset_timer,
.bios_param = megasas_bios_param,
.use_clustering = ENABLE_CLUSTERING,
+   .shost_attrs = megasas_shost_attrs,
 };
 
 /**
@@ -2310,15 +2346,43 @@ static int megasas_io_attach(struct mega
struct Scsi_Host *host = instance->host;
 
/*
-* Export parameters required by SCSI mid-layer
+* Export host parameters required by SCSI
+* mid-layer
 */
host->irq = instance->pdev->irq;
host->unique_id = instance->unique_id;
host->can_queue = instance->max_fw_cmds - MEGASAS_INT_CMDS;
host->this_id = instance->init_id;
host->sg_tablesize = instance->max_num_sge;
+
+   /*
+* Check if the module parameter value for max_sectors can be used
+*/
+   if (max_sectors && max_sectors <= instance->max_sectors_per_req)
+   instance->max_sectors_per_req = max_sectors;
+   else if (max_sectors) {
+   printk(KERN_INFO
+   "megasas: max_sectors should be > 0 and <= %d\n",
+   instance->max_sectors_per_req);
+   }
+
host->max_sectors = instance->max_sectors_per_req;
-   host->cmd_per_lun = 128;
+
+   /*
+* Check if the module parameter value for cmd_per_lun can be used
+*/
+   instance->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
+   if (cmd_per_lun && cmd_per_lun <= MEGASAS_DEFAULT_CMD_PER_LUN)
+   instance->cmd_per_lun = cmd_per_lun;
+   else
+   printk(KERN_INFO "megasas: cmd_per_lun should be > 0 and "
+   "<= %d\n", MEGASAS_DEFAULT_CMD_PER_LUN);
+
+   host->cmd_per_lun = instance->cmd_per_lun;
+
+   printk(KERN_DEBUG "megasas: max_sectors : 0x%x, cmd_per_lun : 0x%x\n",
+   instance->max_sectors_per_req, instance->cmd_per_lun);
+
host->max_channel = MEGASAS_MAX_CHANNELS - 1;
host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL;
host->max_lun = MEGASAS_MAX_LUN;
diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h  2007-10-01 
00:03:59.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h   2007-10-01 
00:03:59.0 -0700
@@ -537,6 +537,7 @@ struct megasas_ctrl_info {
 #define MEGASAS_DEFAULT_INIT_ID-1
 #define MEGASAS_MAX_LUN8
 #define MEGASAS_MAX_LD  

PATCH [2/8] scsi: megaraid_sas - add module param fast_load

2007-10-03 Thread bo yang
Driver will skip physical devices scan for the first time if the fast_load is 
set. This is to reduce time for loading driver.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   69 +++--
 1 files changed, 55 insertions(+), 14 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-01 
00:03:59.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-01 
00:12:54.0 -0700
@@ -46,6 +46,22 @@
 #include 
 #include "megaraid_sas.h"
 
+/*
+ * Module parameters
+ */
+
+/*
+ * Fast driver load option, skip scanning for physical devices during
+ * load.  This would result in physical devices being skipped during
+ * driver load time. These can be later added though,
+ * using /proc/scsi/scsi
+ */
+static unsigned int fast_load;
+module_param_named(fast_load, fast_load, int, 0);
+MODULE_PARM_DESC(fast_load,
+   "megasas: Faster loading of the driver, skips physical devices! "\
+   "(default = 0)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -1094,6 +1110,44 @@ megasas_service_aen(struct megasas_insta
megasas_return_cmd(instance, cmd);
 }
 
+static struct megasas_instance *megasas_lookup_instance(u16 host_no)
+{
+   int i;
+
+   for (i = 0; i < megasas_mgmt_info.max_index; i++) {
+   if ((megasas_mgmt_info.instance[i]) &&
+   (megasas_mgmt_info.instance[i]->host->host_no
+   == host_no))
+   return megasas_mgmt_info.instance[i];
+   }
+
+   return NULL;
+}
+
+static int megasas_slave_alloc(struct scsi_device *sdev)
+{
+   struct megasas_instance *instance;
+   int tmp_fastload = fast_load;
+
+   instance = megasas_lookup_instance(sdev->host->host_no);
+
+   if (tmp_fastload && sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
+   if ((sdev->id == MEGASAS_MAX_DEV_PER_CHANNEL -1) &&
+   (sdev->channel == MEGASAS_MAX_PD_CHANNELS - 1)) {
+
+   /*
+* If fast load option was set and scan for last device is
+* over, reset the fast_load flag so that during a possible
+* next scan, devices can be made available
+*/
+   fast_load = 0;
+   }
+   return -ENXIO;
+   }
+
+   return 0;
+}
+
 /*
  * Scsi host template for megaraid_sas driver
  */
@@ -1103,6 +1157,7 @@ static struct scsi_host_template megasas
.name = "LSI Logic SAS based MegaRAID driver",
.proc_name = "megaraid_sas",
.slave_configure = megasas_slave_configure,
+   .slave_alloc = megasas_slave_alloc,
.queuecommand = megasas_queue_command,
.eh_device_reset_handler = megasas_reset_device,
.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -2961,20 +3016,6 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
return error;
 }
 
-static struct megasas_instance *megasas_lookup_instance(u16 host_no)
-{
-   int i;
-
-   for (i = 0; i < megasas_mgmt_info.max_index; i++) {
-
-   if ((megasas_mgmt_info.instance[i]) &&
-   (megasas_mgmt_info.instance[i]->host->host_no == host_no))
-   return megasas_mgmt_info.instance[i];
-   }
-
-   return NULL;
-}
-
 static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg)
 {
struct megasas_iocpacket __user *user_ioc =


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/8] scsi: megaraid_sas - add hibernation support

2007-10-03 Thread bo yang
Adding hibernation support. suspend, resume routine implemented.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  302 +++--
 drivers/scsi/megaraid/megaraid_sas.h |1
 2 files changed, 233 insertions(+), 70 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-10-01 
00:03:59.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-10-01 
00:03:59.0 -0700
@@ -1802,6 +1802,81 @@ static void megasas_complete_cmd_dpc(uns
 }
 
 /**
+ * megasas_issue_init_mfi -Initializes the FW
+ * @instance:  Adapter soft state
+ *
+ * Issues the INIT MFI cmd
+ */
+static int
+megasas_issue_init_mfi(struct megasas_instance *instance)
+{
+   u32 context;
+
+   struct megasas_cmd *cmd;
+
+   struct megasas_init_frame *init_frame;
+   struct megasas_init_queue_info *initq_info;
+   dma_addr_t init_frame_h;
+   dma_addr_t initq_info_h;
+
+   /*
+* Prepare a init frame. Note the init frame points to queue info
+* structure. Each frame has SGL allocated after first 64 bytes. For
+* this frame - since we don't need any SGL - we use SGL's space as
+* queue info structure
+*
+* We will not get a NULL command below. We just created the pool.
+*/
+   cmd = megasas_get_cmd(instance);
+
+   init_frame = (struct megasas_init_frame *)cmd->frame;
+   initq_info = (struct megasas_init_queue_info *)
+   ((unsigned long)init_frame + 64);
+
+   init_frame_h = cmd->frame_phys_addr;
+   initq_info_h = init_frame_h + 64;
+
+   context = init_frame->context;
+   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
+   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
+   init_frame->context = context;
+
+   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
+   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
+
+   initq_info->producer_index_phys_addr_lo = instance->producer_h;
+   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
+
+   init_frame->cmd = MFI_CMD_INIT;
+   init_frame->cmd_status = 0xFF;
+   init_frame->queue_info_new_phys_addr_lo = initq_info_h;
+
+   init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info);
+
+   /*
+* disable the intr before firing the init frame to FW
+*/
+   instance->instancet->disable_intr(instance->reg_set);
+
+   /*
+* Issue the init frame in polled mode
+*/
+
+   if (megasas_issue_polled(instance, cmd)) {
+   printk(KERN_ERR "megasas: Failed to init firmware\n");
+   megasas_return_cmd(instance, cmd);
+   goto fail_fw_init;
+   }
+
+   megasas_return_cmd(instance, cmd);
+
+   return 0;
+
+fail_fw_init:
+   return -EINVAL;
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -1814,15 +1889,7 @@ static int megasas_init_mfi(struct megas
u32 max_sectors_1;
u32 max_sectors_2;
struct megasas_register_set __iomem *reg_set;
-
-   struct megasas_cmd *cmd;
struct megasas_ctrl_info *ctrl_info;
-
-   struct megasas_init_frame *init_frame;
-   struct megasas_init_queue_info *initq_info;
-   dma_addr_t init_frame_h;
-   dma_addr_t initq_info_h;
-
/*
 * Map the message registers
 */
@@ -1899,52 +1966,8 @@ static int megasas_init_mfi(struct megas
goto fail_reply_queue;
}
 
-   /*
-* Prepare a init frame. Note the init frame points to queue info
-* structure. Each frame has SGL allocated after first 64 bytes. For
-* this frame - since we don't need any SGL - we use SGL's space as
-* queue info structure
-*
-* We will not get a NULL command below. We just created the pool.
-*/
-   cmd = megasas_get_cmd(instance);
-
-   init_frame = (struct megasas_init_frame *)cmd->frame;
-   initq_info = (struct megasas_init_queue_info *)
-   ((unsigned long)init_frame + 64);
-
-   init_frame_h = cmd->frame_phys_addr;
-   initq_info_h = init_frame_h + 64;
-
-   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
-   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
-
-   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
-   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
-
-   initq_info->producer_index_phys_addr_lo = instance->producer_h;
-   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
-
-   init_frame->cmd = MFI_CMD_INI

[PATCH 8/8] scsi: megaraid_sas - Update version and changelog

2007-09-28 Thread bo yang
Update version and changelog

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 Documentation/scsi/ChangeLog.megaraid_sas |  160 
 drivers/scsi/megaraid/megaraid_sas.c  |2
 drivers/scsi/megaraid/megaraid_sas.h  |7
 3 files changed, 165 insertions(+), 4 deletions(-)

diff -uprN linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 
linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas
--- linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 2007-09-26 
15:58:40.0 -0700
+++ linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas  2007-09-27 
06:19:46.0 -0700
@@ -1,3 +1,163 @@
+1 Release Date: Thur. Sep. 27 10:09:32 PDT 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+       Bo Yang 
+
+2 Current Version : 00.00.03.16-rc1
+3 Older Version   : 00.00.03.15
+
+1. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
+   respond to the INIT cmd.
+
+1 Release Date: Fri. Sep. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+       Bo Yang 
+
+2 Current Version : 00.00.03.15
+3 Older Version   : 00.00.03.14
+
+1. Added module parameter "poll_mode_io" to support for "polling" (reduced 
interrupt operation).
+   In this mode, IO completion interrupts are delayed. At the end of 
initiating IOs,
+   the driver schedules for cmd completion if there are pending cmds to be 
completed.
+   A timer-based interrupt has also been added to prevent IO completion 
processing from
+   being delayed indefinitely in the case that no new IOs are initiated.
+
+1 Release Date: Fri. Sep. 07 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.14
+3 Older Version   : 00.00.03.13
+
+1. Setting the max_sectors_per_req based on max SGL supported by the FW. Prior 
versions calculated 
+   this value from controller info (max_sectors_1, max_sectors_2). For 
certain controllers/FW,
+   this was resulting in a value greater than max SGL supported by the FW. 
Issue was first
+   reported by users running LUKS+XFS with megaraid_sas.
+   Thanks to RB for providing the logs and duplication steps that helped 
to get to the root 
+   cause of the issue.
+2. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to 
+   respond to the INIT cmd.
+
+1 Release Date: Fri. June. 15 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.13
+3 Older Version   : 00.00.03.12
+
+1. Added the megasas_reset_timer routine to intercept cmd timeout and throttle 
io.
+
+On Fri, 2007-03-16 at 16:44 -0600, James Bottomley wrote:
+It looks like megaraid_sas at least needs this to throttle its commands
+> as they begin to time out.  The code keeps the existing transport
+> template use of eh_timed_out (and allows the transport to override the
+> host if they both have this callback).
+> 
+> James
+
+1 Release Date: Sat May. 12 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+       Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.12
+3 Older Version   : 00.00.03.11
+
+1.  When MegaSAS driver receives reset call from OS, driver waits in reset
+routine for max 3 minutes for all pending command completion. Now driver will
+call completion routine every 5 seconds from the reset routine instead of
+waiting for depending on cmd completion from isr path.
+
+1 Release Date: Mon Apr. 30 10:25:52 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+       Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.11
+3 Older Version   : 00.00.03.09
+
+   1. Following module parameters added -
+   fast_load: Faster loading of the driver, skips physical devices 
scanning thereby
+   reducing the time to load driver.
+   cmd_per_lun: Maximum number of commands per logical unit
+   max_sectors: Maximum number of sectors per IO command
+   2. Memory Manager for IOCTL removed for 2.6 kernels.
+  pci_alloc_consistent replaced by dma_alloc_coherent. With this 
+  change there is no need of memory manager in the driver code
+
+   On Wed, 2007-02-07 at 13:30 -0800, Andrew Morton wrote:
+   > I suspect all this horror is due to stupidity in the DMA API.
+   >
+   > pci_alloc_consistent() just goes and assumes GFP_ATOMIC, whereas
+   > the caller (megasas_mgmt_fw_ioctl) would have been perfectly happy
+   > to use GFP_KERN

[PATCH 7/8] scsi: megaraid_sas - support for poll_mode_io (reduced interrupt)

2007-09-28 Thread bo yang
Added module parameter "poll_mode_io" to support for "polling" (reduced 
interrupt operation). 
In this mode, IO completion interrupts are delayed. At the end of 
initiating IOs, 
the driver schedules for cmd completion if there are pending cmds. 
A timer-based interrupt has also been added to prevent IO completion 
from 
being delayed indefinitely in the case that no new IOs are initiated.  
Some formatting issues in resume, suspend comment block also corrected

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  152 -
 drivers/scsi/megaraid/megaraid_sas.h |3
 2 files changed, 149 insertions(+), 6 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-27 
21:32:23.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-27 
21:43:52.0 -0700
@@ -79,6 +79,14 @@ module_param_named(cmd_per_lun, cmd_per_
 MODULE_PARM_DESC(cmd_per_lun,
"Maximum number of commands per logical unit (default=128)");
 
+/*
+ * poll_mode_io:1- schedule complete completion from q cmd
+ */
+static unsigned int poll_mode_io;
+module_param_named(poll_mode_io, poll_mode_io, int, 0);
+MODULE_PARM_DESC(poll_mode_io,
+   "Complete cmds from IO path, (default=0)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -892,6 +900,12 @@ megasas_queue_command(struct scsi_cmnd *
atomic_inc(&instance->fw_outstanding);
 
instance->instancet->fire_cmd(cmd->frame_phys_addr 
,cmd->frame_count-1,instance->reg_set);
+   /*
+* Check if we have pend cmds to be completed
+*/
+   if (poll_mode_io && atomic_read(&instance->fw_outstanding))
+   tasklet_schedule(&instance->isr_tasklet);
+
 
return 0;
 
@@ -1947,6 +1961,47 @@ fail_fw_init:
 }
 
 /**
+ * megasas_start_timer - Initializes a timer object
+ * @instance:  Adapter soft state
+ * @timer: timer object to be initialized
+ * @fn:timer function
+ * @interval:  time interval between timer function call
+ */
+static inline void
+megasas_start_timer(struct megasas_instance *instance,
+   struct timer_list *timer,
+   void *fn, unsigned long interval)
+{
+   init_timer(timer);
+   timer->expires = jiffies + interval;
+   timer->data = (unsigned long)instance;
+   timer->function = fn;
+   add_timer(timer);
+}
+
+/**
+ * megasas_io_completion_timer - Timer fn
+ * @instance_addr: Address of adapter soft state
+ *
+ * Schedules tasklet for cmd completion
+ * if poll_mode_io is set
+ */
+static void
+megasas_io_completion_timer(unsigned long instance_addr)
+{
+   struct megasas_instance *instance =
+   (struct megasas_instance *)instance_addr;
+
+   if (atomic_read(&instance->fw_outstanding))
+   tasklet_schedule(&instance->isr_tasklet);
+
+   /* Restart timer */
+   if (poll_mode_io)
+   mod_timer(&instance->io_completion_timer,
+   jiffies + MEGASAS_COMPLETION_TIMER_INTERVAL);
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -2073,8 +2128,14 @@ static int megasas_init_mfi(struct megas
* Setup tasklet for cmd completion
*/
 
-tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc,
-(unsigned long)instance);
+   tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc,
+   (unsigned long)instance);
+
+   /* Initialize the cmd completion timer */
+   if (poll_mode_io)
+   megasas_start_timer(instance, &instance->io_completion_timer,
+   megasas_io_completion_timer,
+   MEGASAS_COMPLETION_TIMER_INTERVAL);
return 0;
 
   fail_fw_init:
@@ -2705,8 +2766,8 @@ static void megasas_shutdown_controller(
 }
 
 /**
- * megasas_suspend -driver suspend entry point
- * @pdev:   PCI device structure
+ * megasas_suspend -   driver suspend entry point
+ * @pdev:  PCI device structure
  * @state: PCI power state to suspend routine
  */
 static int __devinit
@@ -2718,6 +2779,9 @@ megasas_suspend(struct pci_dev *pdev, pm
instance = pci_get_drvdata(pdev);
host = instance->host;
 
+   if (poll_mode_io)
+   del_timer_sync(&instance->io_completion_timer);
+
megasas_flush_cache(instance);
megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
tasklet_kill(&a

[PATCH 6/8] scsi: megaraid_sas - call cmd completion from reset

2007-09-28 Thread bo yang
Driver will call cmd completion routine from Reset path without waiting for cmd 
completion from isr context.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  107 -
 drivers/scsi/megaraid/megaraid_sas.h |2
 2 files changed, 55 insertions(+), 54 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-27 
05:48:10.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-27 
21:31:34.0 -0700
@@ -109,6 +109,10 @@ static DEFINE_MUTEX(megasas_async_queue_
 
 static u32 megasas_dbg_lvl;
 
+static void
+megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd 
*cmd,
+u8 alt_status);
+
 /**
  * megasas_get_cmd -   Get a command from the free pool
  * @instance:  Adapter soft state
@@ -919,6 +923,49 @@ static int megasas_slave_configure(struc
 }
 
 /**
+ * megasas_complete_cmd_dpc -  Returns FW's controller structure
+ * @instance_addr: Address of adapter soft state
+ *
+ * Tasklet to complete cmds
+ */
+static void megasas_complete_cmd_dpc(unsigned long instance_addr)
+{
+   u32 producer;
+   u32 consumer;
+   u32 context;
+   struct megasas_cmd *cmd;
+   struct megasas_instance *instance =
+   (struct megasas_instance *)instance_addr;
+   unsigned long flags;
+
+   /* If we have already declared adapter dead, donot complete cmds */
+   if (instance->hw_crit_error)
+   return;
+
+   spin_lock_irqsave(&instance->completion_lock, flags);
+
+   producer = *instance->producer;
+   consumer = *instance->consumer;
+
+   while (consumer != producer) {
+   context = instance->reply_queue[consumer];
+
+   cmd = instance->cmd_list[context];
+
+   megasas_complete_cmd(instance, cmd, DID_OK);
+
+   consumer++;
+   if (consumer == (instance->max_fw_cmds + 1)) {
+   consumer = 0;
+   }
+   }
+
+   *instance->consumer = producer;
+
+   spin_unlock_irqrestore(&instance->completion_lock, flags);
+}
+
+/**
  * megasas_wait_for_outstanding -  Wait for all outstanding cmds
  * @instance:  Adapter soft state
  *
@@ -941,6 +988,11 @@ static int megasas_wait_for_outstanding(
if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
   "commands to complete\n",i,outstanding);
+   /*
+* Call cmd completion routine. Cmd to be
+* be completed directly without depending on isr.
+*/
+   megasas_complete_cmd_dpc((unsigned long)instance);
}
 
msleep(1000);
@@ -1820,60 +1872,6 @@ megasas_get_ctrl_info(struct megasas_ins
 }
 
 /**
- * megasas_complete_cmd_dpc -  Returns FW's controller structure
- * @instance_addr: Address of adapter soft state
- *
- * Tasklet to complete cmds
- */
-static void megasas_complete_cmd_dpc(unsigned long instance_addr)
-{
-   u32 producer;
-   u32 consumer;
-   u32 context;
-   struct megasas_cmd *cmd;
-   struct megasas_instance *instance = (struct megasas_instance 
*)instance_addr;
-   unsigned long flags;
-
-   /* If we have already declared adapter dead, donot complete cmds */
-   if (instance->hw_crit_error)
-   return;
-
-   producer = *instance->producer;
-   consumer = *instance->consumer;
-
-   while (consumer != producer) {
-   context = instance->reply_queue[consumer];
-
-   cmd = instance->cmd_list[context];
-
-   megasas_complete_cmd(instance, cmd, DID_OK);
-
-   consumer++;
-   if (consumer == (instance->max_fw_cmds + 1)) {
-   consumer = 0;
-   }
-   }
-
-   *instance->consumer = producer;
-
-   /*
-* Check if we can restore can_queue
-*/
-   if (instance->flag & MEGASAS_FW_BUSY
-   && time_after(jiffies, instance->last_time + 5 * HZ)
-   && atomic_read(&instance->fw_outstanding) < 17) {
-
-   spin_lock_irqsave(instance->host->host_lock, flags);
-   instance->flag &= ~MEGASAS_FW_BUSY;
-   instance->host->can_queue =
-   instance->max_fw_cmds - MEGASAS_INT_CMDS;
-
-   spin_unlock_irqrestore(instance->host->host_lock, flags);
-   }
-
-}
-
-/**
  

[PATCH 5/8] scsi: megaraid_sas - using unsigned long for sense_buff ptr

2007-09-28 Thread bo yang
MegaRAID utilities expect sense_buff to be of type unsigned long.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-27 
04:41:39.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-27 
04:50:14.0 -0700
@@ -2969,6 +2969,7 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
void *sense = NULL;
dma_addr_t sense_handle;
u32 *sense_ptr;
+   unsigned long *sense_buff;
 
memset(kbuff_arr, 0, sizeof(kbuff_arr));
 
@@ -3073,14 +3074,16 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
 */
if (ioc->sense_len) {
/*
-* sense_ptr points to the location that has the user
+* sense_buff points to the location that has the user
 * sense buffer address
 */
-   sense_ptr = (u32 *) ((unsigned long)ioc->frame.raw +
-ioc->sense_off);
+   sense_buff = (unsigned long *) ((unsigned long)ioc->frame.raw +
+   ioc->sense_off);
 
-   if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
-sense, ioc->sense_len)) {
+   if (copy_to_user((void __user *)(unsigned long)(*sense_buff),
+   sense, ioc->sense_len)) {
+   printk(KERN_ERR "megasas: Failed to copy out to user"
+   "sense data\n");
error = -EFAULT;
goto out;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/8] scsi: megaraid_sas - check max_sgl reported by FW for setting max_sectors_per_req

2007-09-28 Thread bo yang
1. Setting the max_sectors_per_req based on max SGL supported by the FW. Prior 
versions calculated  
this value from controller info's max_sectors_1, max_sectors_2. For 
certain controllers/FW, 
this was resulting in a value greater than max SGL supported by the FW. 
Now we take the min  
of max sgl from FW and max_sectors calculation.

2. Increased MFI_POLL_TIMEOUT_SECS to 60 seconds from 10. FW may take a max of 
60 seconds to  
respond to the INIT cmd.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   13 +
 drivers/scsi/megaraid/megaraid_sas.h |2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-27 
20:40:14.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-27 
04:39:44.0 -0700
@@ -1960,6 +1960,7 @@ static int megasas_init_mfi(struct megas
u32 reply_q_sz;
u32 max_sectors_1;
u32 max_sectors_2;
+   u32 tmp_sectors;
struct megasas_register_set __iomem *reg_set;
struct megasas_ctrl_info *ctrl_info;
/*
@@ -2052,17 +2053,21 @@ static int megasas_init_mfi(struct megas
 * Note that older firmwares ( < FW ver 30) didn't report information
 * to calculate max_sectors_1. So the number ended up as zero always.
 */
+   tmp_sectors = 0;
if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) {
 
max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) *
ctrl_info->max_strips_per_io;
max_sectors_2 = ctrl_info->max_request_size;
 
-   instance->max_sectors_per_req = (max_sectors_1 < max_sectors_2)
+   tmp_sectors = (max_sectors_1 < max_sectors_2)
? max_sectors_1 : max_sectors_2;
-   } else
-   instance->max_sectors_per_req = instance->max_num_sge *
-   PAGE_SIZE / 512;
+   }
+
+   instance->max_sectors_per_req = instance->max_num_sge *
+   PAGE_SIZE / 512;
+   if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors))
+   instance->max_sectors_per_req = tmp_sectors;
 
kfree(ctrl_info);
 
diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.h  2007-09-26 
13:40:36.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.h   2007-09-26 
14:10:59.0 -0700
@@ -572,7 +572,7 @@ struct megasas_ctrl_info {
 #define IS_DMA64   (sizeof(dma_addr_t) == 8)
 
 #define MFI_OB_INTR_STATUS_MASK0x0002
-#define MFI_POLL_TIMEOUT_SECS  10
+#define MFI_POLL_TIMEOUT_SECS  60
 
 #define MFI_REPLY_1078_MESSAGE_INTERRUPT   0x8000
 

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/8] scsi: megaraid_sas - add module param max_sectors, cmd_per_lun

2007-09-28 Thread bo yang
Adding module parameters to configure max sectors per request & # of cmds per 
lun.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   94 -
 drivers/scsi/megaraid/megaraid_sas.h |2
 2 files changed, 94 insertions(+), 2 deletions(-)

diff -uprN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-26 
13:30:36.0 -0700
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-27 
20:37:11.0 -0700
@@ -62,6 +62,23 @@ MODULE_PARM_DESC(fast_load,
"megasas: Faster loading of the driver, skips physical devices! \
 (default = 0)");
 
+/*
+ * Number of sectors per IO command will be set in megasas_init_mfi
+ * if user does not provide
+ */
+static unsigned int max_sectors;
+module_param_named(max_sectors, max_sectors, int, 0);
+MODULE_PARM_DESC(max_sectors,
+   "Maximum number of sectors per IO command");
+
+/*
+ * Number of cmds per logical unit
+ */
+static unsigned int cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
+module_param_named(cmd_per_lun, cmd_per_lun, int, 0);
+MODULE_PARM_DESC(cmd_per_lun,
+   "Maximum number of commands per logical unit (default=128)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -2301,6 +2318,31 @@ static int megasas_start_aen(struct mega
class_locale.word);
 }
 
+static ssize_t
+sysfs_max_sectors_read(struct kobject *kobj,
+   struct bin_attribute *bin_attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct Scsi_Host *host = class_to_shost(container_of(kobj,
+   struct class_device, kobj));
+   struct megasas_instance *instance =
+   (struct megasas_instance *)host->hostdata;
+
+   count = sprintf(buf, "%u\n", instance->max_sectors_per_req);
+
+   return count+1;
+}
+
+static struct bin_attribute sysfs_max_sectors_attr = {
+   .attr = {
+   .name = "max_sectors",
+   .mode = S_IRUSR|S_IRGRP|S_IROTH,
+   .owner = THIS_MODULE,
+   },
+   .size = 7,
+   .read = sysfs_max_sectors_read,
+};
+
 /**
  * megasas_io_attach - Attaches this driver to SCSI mid-layer
  * @instance:  Adapter soft state
@@ -2308,17 +2350,48 @@ static int megasas_start_aen(struct mega
 static int megasas_io_attach(struct megasas_instance *instance)
 {
struct Scsi_Host *host = instance->host;
+   int error;
 
/*
-* Export parameters required by SCSI mid-layer
+* Export host parameters required by SCSI
+* mid-layer
 */
host->irq = instance->pdev->irq;
host->unique_id = instance->unique_id;
host->can_queue = instance->max_fw_cmds - MEGASAS_INT_CMDS;
host->this_id = instance->init_id;
host->sg_tablesize = instance->max_num_sge;
+
+   /*
+* Check if the module parameter value for max_sectors can be used
+*/
+   if (max_sectors && max_sectors <= instance->max_sectors_per_req)
+   instance->max_sectors_per_req = max_sectors;
+   else {
+   if (max_sectors)
+   printk(KERN_INFO
+   "megasas: max_sectors should be > 0 and"
+   "<= %d\n",
+   instance->max_sectors_per_req);
+   }
+
host->max_sectors = instance->max_sectors_per_req;
-   host->cmd_per_lun = 128;
+
+   /*
+* Check if the module parameter value for cmd_per_lun can be used
+*/
+   instance->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
+   if (cmd_per_lun && cmd_per_lun <= MEGASAS_DEFAULT_CMD_PER_LUN)
+   instance->cmd_per_lun = cmd_per_lun;
+   else
+   printk(KERN_INFO "megasas: cmd_per_lun should be > 0 and"
+   "<= %d\n", MEGASAS_DEFAULT_CMD_PER_LUN);
+
+   host->cmd_per_lun = instance->cmd_per_lun;
+
+   printk(KERN_DEBUG "megasas: max_sectors : 0x%x, cmd_per_lun : 0x%x\n",
+   instance->max_sectors_per_req, instance->cmd_per_lun);
+
host->max_channel = MEGASAS_MAX_CHANNELS - 1;
host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL;
host->max_lun = MEGASAS_MAX_LUN;
@@ -2333,10 +2406,25 @@ static int megasas_io_attach(struct mega
}
 
/*
+* Create sysfs entries for module paramaters
+*/
+   error = sysfs_create_bin_file(&instance->host->shost_classdev.kobj,
+   &am

PATCH [2/8] scsi: megaraid_sas - add module param fast_load

2007-09-28 Thread bo yang
Driver will skip physical devices scan for the first time if the fast_load is 
set. This is to reduce time for loading driver.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |   69 +++--
 1 files changed, 55 insertions(+), 14 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-26 
16:19:18.321402040 -0400
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-26 
16:20:52.915021624 -0400
@@ -46,6 +46,22 @@
 #include 
 #include "megaraid_sas.h"
 
+/*
+ * Module parameters
+ */
+
+/*
+ * Fast driver load option, skip scanning for physical devices during
+ * load.  This would result in physical devices being skipped during
+ * driver load time. These can be later added though,
+ * using /proc/scsi/scsi
+ */
+static unsigned int fast_load;
+module_param_named(fast_load, fast_load, int, 0);
+MODULE_PARM_DESC(fast_load,
+   "megasas: Faster loading of the driver, skips physical devices! \
+(default = 0)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -1094,6 +1110,44 @@ megasas_service_aen(struct megasas_insta
megasas_return_cmd(instance, cmd);
 }
 
+static struct megasas_instance *megasas_lookup_instance(u16 host_no)
+{
+   int i;
+
+   for (i = 0; i < megasas_mgmt_info.max_index; i++) {
+   if ((megasas_mgmt_info.instance[i]) &&
+   (megasas_mgmt_info.instance[i]->host->host_no
+   == host_no))
+   return megasas_mgmt_info.instance[i];
+   }
+
+   return NULL;
+}
+
+static int megasas_slave_alloc(struct scsi_device *sdev)
+{
+   struct megasas_instance *instance;
+   int tmp_fastload = fast_load;
+
+   instance = megasas_lookup_instance(sdev->host->host_no);
+
+   if (tmp_fastload && sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
+   if ((sdev->id == MEGASAS_MAX_DEV_PER_CHANNEL -1) &&
+   (sdev->channel == MEGASAS_MAX_PD_CHANNELS - 1)) {
+
+   /*
+* If fast load option was set and scan for last device is
+* over, reset the fast_load flag so that during a possible
+* next scan, devices can be made available
+*/
+   fast_load = 0;
+   }
+   return -ENXIO;
+   }
+
+   return 0;
+}
+
 /*
  * Scsi host template for megaraid_sas driver
  */
@@ -1103,6 +1157,7 @@ static struct scsi_host_template megasas
.name = "LSI Logic SAS based MegaRAID driver",
.proc_name = "megaraid_sas",
.slave_configure = megasas_slave_configure,
+   .slave_alloc = megasas_slave_alloc,
.queuecommand = megasas_queue_command,
.eh_device_reset_handler = megasas_reset_device,
.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -2961,20 +3016,6 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
return error;
 }
 
-static struct megasas_instance *megasas_lookup_instance(u16 host_no)
-{
-   int i;
-
-   for (i = 0; i < megasas_mgmt_info.max_index; i++) {
-
-   if ((megasas_mgmt_info.instance[i]) &&
-   (megasas_mgmt_info.instance[i]->host->host_no == host_no))
-   return megasas_mgmt_info.instance[i];
-   }
-
-   return NULL;
-}
-
 static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg)
 {
struct megasas_iocpacket __user *user_ioc =

-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/8] scsi: megaraid_sas - add hibernation support

2007-09-28 Thread bo yang
Adding hibernation support. suspend, resume routine implemented.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---
 drivers/scsi/megaraid/megaraid_sas.c |  302 +++--
 drivers/scsi/megaraid/megaraid_sas.h |1
 2 files changed, 233 insertions(+), 70 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c  2007-09-26 
11:23:54.0 -0400
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c   2007-09-26 
16:17:14.954156712 -0400
@@ -1802,6 +1802,81 @@ static void megasas_complete_cmd_dpc(uns
 }
 
 /**
+ * megasas_issue_init_mfi -Initializes the FW
+ * @instance:  Adapter soft state
+ *
+ * Issues the INIT MFI cmd
+ */
+static int
+megasas_issue_init_mfi(struct megasas_instance *instance)
+{
+   u32 context;
+
+   struct megasas_cmd *cmd;
+
+   struct megasas_init_frame *init_frame;
+   struct megasas_init_queue_info *initq_info;
+   dma_addr_t init_frame_h;
+   dma_addr_t initq_info_h;
+
+   /*
+* Prepare a init frame. Note the init frame points to queue info
+* structure. Each frame has SGL allocated after first 64 bytes. For
+* this frame - since we don't need any SGL - we use SGL's space as
+* queue info structure
+*
+* We will not get a NULL command below. We just created the pool.
+*/
+   cmd = megasas_get_cmd(instance);
+
+   init_frame = (struct megasas_init_frame *)cmd->frame;
+   initq_info = (struct megasas_init_queue_info *)
+   ((unsigned long)init_frame + 64);
+
+   init_frame_h = cmd->frame_phys_addr;
+   initq_info_h = init_frame_h + 64;
+
+   context = init_frame->context;
+   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
+   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
+   init_frame->context = context;
+
+   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
+   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
+
+   initq_info->producer_index_phys_addr_lo = instance->producer_h;
+   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
+
+   init_frame->cmd = MFI_CMD_INIT;
+   init_frame->cmd_status = 0xFF;
+   init_frame->queue_info_new_phys_addr_lo = initq_info_h;
+
+   init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info);
+
+   /*
+* disable the intr before firing the init frame to FW
+*/
+   instance->instancet->disable_intr(instance->reg_set);
+
+   /*
+* Issue the init frame in polled mode
+*/
+
+   if (megasas_issue_polled(instance, cmd)) {
+   printk(KERN_ERR "megasas: Failed to init firmware\n");
+   megasas_return_cmd(instance, cmd);
+   goto fail_fw_init;
+   }
+
+   megasas_return_cmd(instance, cmd);
+
+   return 0;
+
+fail_fw_init:
+   return -EINVAL;
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -1814,15 +1889,7 @@ static int megasas_init_mfi(struct megas
u32 max_sectors_1;
u32 max_sectors_2;
struct megasas_register_set __iomem *reg_set;
-
-   struct megasas_cmd *cmd;
struct megasas_ctrl_info *ctrl_info;
-
-   struct megasas_init_frame *init_frame;
-   struct megasas_init_queue_info *initq_info;
-   dma_addr_t init_frame_h;
-   dma_addr_t initq_info_h;
-
/*
 * Map the message registers
 */
@@ -1899,52 +1966,8 @@ static int megasas_init_mfi(struct megas
goto fail_reply_queue;
}
 
-   /*
-* Prepare a init frame. Note the init frame points to queue info
-* structure. Each frame has SGL allocated after first 64 bytes. For
-* this frame - since we don't need any SGL - we use SGL's space as
-* queue info structure
-*
-* We will not get a NULL command below. We just created the pool.
-*/
-   cmd = megasas_get_cmd(instance);
-
-   init_frame = (struct megasas_init_frame *)cmd->frame;
-   initq_info = (struct megasas_init_queue_info *)
-   ((unsigned long)init_frame + 64);
-
-   init_frame_h = cmd->frame_phys_addr;
-   initq_info_h = init_frame_h + 64;
-
-   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
-   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
-
-   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
-   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
-
-   initq_info->producer_index_phys_addr_lo = instance->producer_h;
-   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
-
-   init_frame->cmd = MFI_CMD_INI

[PATCH 1/4] scsi: megaraid_sas -- add hibernation support

2007-07-03 Thread bo yang
The megaraid_sas driver doesn't support the hibernation, the
suspend/resume routine implemented to support the hibernation.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---

drivers/scsi/megaraid/megaraid_sas.c |  308 +++--
drivers/scsi/megaraid/megaraid_sas.h |1
2 files changed, 239 insertions(+), 70 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 2007-06-20
02:18:24.0 -0400
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c 2007-06-30
03:21:27.0 -0400
@@ -1804,6 +1804,81 @@ static void megasas_complete_cmd_dpc(uns
 }
 
 /**
+ * megasas_issue_init_mfi - Initializes the FW
+ * @instance:  Adapter soft state
+ *
+ * Issues the INIT MFI cmd
+ */
+static int
+megasas_issue_init_mfi(struct megasas_instance *instance)
+{
+ u32 context;
+
+ struct megasas_cmd *cmd;
+
+ struct megasas_init_frame *init_frame;
+ struct megasas_init_queue_info *initq_info;
+ dma_addr_t init_frame_h;
+ dma_addr_t initq_info_h;
+
+   /*
+* Prepare a init frame. Note the init frame points to queue info
+* structure. Each frame has SGL allocated after first 64 bytes. For
+* this frame - since we don't need any SGL - we use SGL's space as
+* queue info structure
+*
+* We will not get a NULL command below. We just created the pool.
+*/
+   cmd = megasas_get_cmd(instance);
+
+   init_frame = (struct megasas_init_frame *)cmd->frame;
+   initq_info = (struct megasas_init_queue_info *)
+   ((unsigned long)init_frame + 64);
+
+   init_frame_h = cmd->frame_phys_addr;
+   initq_info_h = init_frame_h + 64;
+
+   context = init_frame->context;
+   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
+   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
+   init_frame->context = context;
+
+   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
+   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
+
+   initq_info->producer_index_phys_addr_lo = instance->producer_h;
+   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
+
+   init_frame->cmd = MFI_CMD_INIT;
+   init_frame->cmd_status = 0xFF;
+   init_frame->queue_info_new_phys_addr_lo = initq_info_h;
+
+   init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info);
+
+   /*
+* disable the intr before firing the init frame to FW
+*/
+   instance->instancet->disable_intr(instance->reg_set);
+
+   /*
+* Issue the init frame in polled mode
+*/
+
+   if (megasas_issue_polled(instance, cmd)) {
+   printk(KERN_DEBUG "megasas: Failed to init firmware\n");
+   megasas_return_cmd(instance, cmd);
+   goto fail_fw_init;
+   }
+
+   megasas_return_cmd(instance, cmd);
+
+   return 0;
+
+   fail_fw_init:
+   return -EINVAL;
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -1816,15 +1891,7 @@ static int megasas_init_mfi(struct megas
u32 max_sectors_1;
u32 max_sectors_2;
struct megasas_register_set __iomem *reg_set;
-
-   struct megasas_cmd *cmd;
struct megasas_ctrl_info *ctrl_info;
-
-   struct megasas_init_frame *init_frame;
-   struct megasas_init_queue_info *initq_info;
-   dma_addr_t init_frame_h;
-   dma_addr_t initq_info_h;
-
/*
 * Map the message registers
 */
@@ -1901,52 +1968,8 @@ static int megasas_init_mfi(struct megas
goto fail_reply_queue;
}
 
-   /*
-* Prepare a init frame. Note the init frame points to queue info
-* structure. Each frame has SGL allocated after first 64 bytes. For
-* this frame - since we don't need any SGL - we use SGL's space as
-* queue info structure
-*
-* We will not get a NULL command below. We just created the pool.
-*/
-   cmd = megasas_get_cmd(instance);
-
-   init_frame = (struct megasas_init_frame *)cmd->frame;
-   initq_info = (struct megasas_init_queue_info *)
-   ((unsigned long)init_frame + 64);
-
-   init_frame_h = cmd->frame_phys_addr;
-   initq_info_h = init_frame_h + 64;
-
-   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
-   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
-
-   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
-   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
-
-   initq_info->producer_index_phys_addr_lo = instance->producer_h;
-   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
-
-   init_

[PATCH 4/4] scsi: megaraid_sas - update version and Changelog

2007-07-03 Thread bo yang
Update version and Changelog

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---

Documentation/scsi/ChangeLog.megaraid_sas |  211 
drivers/scsi/megaraid/megaraid_sas.c  |2
drivers/scsi/megaraid/megaraid_sas.h  |6
3 files changed, 215 insertions(+), 4 deletions(-)

diff -rupN linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 
linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas
--- linux-2.6.22_orig/Documentation/scsi/ChangeLog.megaraid_sas 2007-07-02 
21:37:20.229689864 -0400
+++ linux-2.6.22_new/Documentation/scsi/ChangeLog.megaraid_sas 2007-07-02 
21:37:20.149702024 -0400
@@ -1,3 +1,239 @@
+1 Release Date: Wed. June 20 11:25:21 PDT 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+
+2 Current Version : 00.00.03.14-RC1
+3 Older Version   : 00.00.03.13
+
+1. convert to use the data buffer accessors
+
+>From: James Bottomley [mailto:[EMAIL PROTECTED]
+>Sent: Thursday, May 31, 2007 3:40 PM
+>To: FUJITA Tomonori; Patro, Sumant; James Bottomley
+>Subject: Patch added to scsi-misc-2.6: [SCSI] megaraid_sas: convert to use 
the data buffer accessors  
+- remove the unnecessary map_single path.
+- convert to use the new accessors for the sg lists and the
+parameters.
+   
+2. Clean up the codes and take off the compile warning.
+
+1 Release Date: Thu. May. 31 11:25:21 PDT 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+
+2 Current Version : 00.00.03.13
+3 Older Version   : 00.00.03.12
+
+1. Added the megasas_reset_timer routine to intercept cmd timeout 
+   and throttle io.
+
+On Fri, 2007-03-16 at 16:44 -0600, James Bottomley wrote:
+It looks like megaraid_sas at least needs this to throttle its commands
+> as they begin to time out.  The code keeps the existing transport
+> template use of eh_timed_out (and allows the transport to override the
+> host if they both have this callback).
+> 
+> James
+
+1 Release Date: Sat. May. 14 16:30:43 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.12
+3 Older Version   : 00.00.03.11
+
+1.  When MegaSAS driver receives reset call from OS, driver waits in reset
+routine for max 3 minutes for all pending command completion. Now driver will
+call completion routine every 5 seconds from the reset routine instead of
+waiting for cmd completion from isr path.
+
+1 Release Date: Mon Apr. 30 10:25:52 PST 2007 -
+   (emaild-id:[EMAIL PROTECTED])
+   Sumant Patro
+   Bo Yang 
+
+2 Current Version : 00.00.03.11
+3 Older Version   : 00.00.03.10
+
+   1. Following module parameters added -
+   fast_load: Faster loading of the driver, skips physical devices
+   cmd_per_lun: Maximum number of commands per logical unit
+   max_sectors: Maximum number of sectors per IO command
+   2. Hibernation support added
+   3. Performing diskdump while running IO in RHEL 4 was failing. Fixed.
+   
+1 Release Date: Wed Mar. 28 10:25:52 PST 2007
+2 Current Version : 00.00.03.10
+3 Older Version   : 00.00.03.09
+
+i. Replaced pci_alloc_consistent with dma_alloc_coherent in ioctl path
+ii.eh_timed_out call back (megasas_reset_timer) is now used to throttle io 
to the
+   adapter when it is called the first time for a scmd.
+   The MEGASAS_FW_BUSY flag is set and can_queue reduced to 16. The 
can_queue is
+   restored from completion routine in following two conditions :
+   5 seconds has elapsed and the # of outstanding cmds in FW is < 17.
+   This implementation replaces the throttling mechanism of 3.08 ver.
+
+On Thu, 2007-02-15 at 19:53 -0700, Patro, Sumant wrote:
+> Hello James,
+>
+>   I re-submitted the patch yesterday with the "space" issue fixed
+> (adhering to coding guideline).
+>
+>   I will check for alternative to calculate the time driver have
+> been sending host busy to OS. Will check with time_before() as you have
+> suggested.
+>
+>   Throttling from megasas_generic_reset() handler did not help.
+> megaraid does not have feature to abort cmds. So, in the generic reset
+> routine, the driver just waits for cmd completion by FW. These timed-out
+> cmds gets retried by mid-layer with "retries" incremented by 1.
+> Eventually we see retries equals max_allowed followed by SCSI error with
+> "DRIVER_TIMEOUT".
+
+That's rather what worries me.  When the error handler activates (which
+it will on the first timeout), it waits for all commands to complete or
+time out before running.  Your reset handler does nothing other than
+wait for the firmware to complete the commands (now uselessly), so we
+now wait for the entire firmware command queue to drain, then you tell
+the mid layer everything is OK, so it loads you u

[PATCH 3/4] scsi: megaraid_sas - add module param max_sectors, cmd_per_lun

2007-07-03 Thread bo yang
Adding module parameters to configure max sectors per request & # of cmds for 
each lun.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---

drivers/scsi/megaraid/megaraid_sas.c |   87 -
drivers/scsi/megaraid/megaraid_sas.h |2
 2 files changed, 88 insertions(+), 1 deletion(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 2007-06-30
04:02:02.0 -0400
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c 2007-06-30
08:07:16.0 -0400
@@ -61,6 +61,23 @@ MODULE_PARM_DESC(fast_load,
  "megasas: Faster loading of the driver, skips physical devices! \
   (default=0)");
 
+/*
+ * Number of sectors per IO command
+ * Will be set in megasas_init_mfi if user does not provide
+ */
+static unsigned int max_sectors = 0;
+module_param_named(max_sectors, max_sectors, int, 0);
+MODULE_PARM_DESC(max_sectors,
+ "Maximum number of sectors per IO command");
+
+/*
+ * Number of cmds per logical unit
+ */
+static unsigned int cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
+module_param_named(cmd_per_lun, cmd_per_lun, int, 0);
+MODULE_PARM_DESC(cmd_per_lun,
+ "Maximum number of commands per logical unit (default=128)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -2298,6 +2315,30 @@ static int megasas_start_aen(struct mega
class_locale.word);
 }
 
+static ssize_t
+sysfs_max_sectors_read(struct kobject *kobj, char *buf,
+   loff_t off, size_t count)
+{
+   struct Scsi_Host *host = class_to_shost(container_of(kobj,
+   struct class_device, kobj));
+   struct megasas_instance *instance = 
+   (struct megasas_instance *)host->hostdata;
+
+   count = sprintf(buf,"%u\n", instance->max_sectors_per_req);
+
+   return count+1;
+}
+
+static struct bin_attribute sysfs_max_sectors_attr = {
+   .attr = {
+   .name = "max_sectors",
+   .mode = S_IRUSR|S_IRGRP|S_IROTH,
+   .owner = THIS_MODULE,
+   },
+   .size = 7,
+   .read = sysfs_max_sectors_read,
+};
+
 /**
  * megasas_io_attach - Attaches this driver to SCSI mid-layer
  * @instance:  Adapter soft state
@@ -2305,6 +2346,7 @@ static int megasas_start_aen(struct mega
 static int megasas_io_attach(struct megasas_instance *instance)
 {
struct Scsi_Host *host = instance->host;
+   int error;
 
/*
 * Export parameters required by SCSI mid-layer
@@ -2314,8 +2356,35 @@ static int megasas_io_attach(struct mega
host->can_queue = instance->max_fw_cmds - MEGASAS_INT_CMDS;
host->this_id = instance->init_id;
host->sg_tablesize = instance->max_num_sge;
+
+   /*
+* Check if the module parameter value for max_sectors can be used
+*/
+   if (max_sectors && max_sectors <= instance->max_sectors_per_req)
+   instance->max_sectors_per_req = max_sectors;
+   else {
+   if(max_sectors)
+   printk(KERN_INFO "megasas: max_sectors should be > 0 
and"
+   "<= %d\n",instance->max_sectors_per_req);
+   }
+
host->max_sectors = instance->max_sectors_per_req;
-   host->cmd_per_lun = 128;
+
+   /*
+* Check if the module parameter value for cmd_per_lun can be used
+*/
+   instance->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
+   if (cmd_per_lun && cmd_per_lun <= MEGASAS_DEFAULT_CMD_PER_LUN)
+   instance->cmd_per_lun = cmd_per_lun;
+   else
+   printk(KERN_INFO "megasas: cmd_per_lun should be > 0 and"
+   "<= %d\n",MEGASAS_DEFAULT_CMD_PER_LUN);
+
+   host->cmd_per_lun = instance->cmd_per_lun;
+
+   printk(KERN_DEBUG "megasas: max_sectors : 0x%x, cmd_per_lun : 0x%x\n",
+   instance->max_sectors_per_req, instance->cmd_per_lun);
+
host->max_channel = MEGASAS_MAX_CHANNELS - 1;
host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL;
host->max_lun = MEGASAS_MAX_LUN;
@@ -2330,10 +2399,25 @@ static int megasas_io_attach(struct mega
}
 
/*
+* Create sysfs entries for module paramaters
+*/
+   error = sysfs_create_bin_file(&instance->host->shost_classdev.kobj,
+   &sysfs_max_sectors_attr);
+   if (error) {
+   printk(KERN_INFO "megasas: Error in creating the sysfs entry"
+   " max_sectors.\n");
+   goto out_remove_host;
+   }
+
+   /*
   

[PATCH 2/4] scsi: megaraid_sas -- add module param fast_load

2007-07-03 Thread bo yang
Driver will skip physical devices scan for the first time if the
fast_load is set.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]>

---

drivers/scsi/megaraid/megaraid_sas.c |   64 +++--
 1 files changed, 50 insertions(+), 14 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 2007-06-30
03:36:39.0 -0400
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c 2007-06-30
03:59:27.0 -0400
@@ -46,6 +46,21 @@
 #include 
 #include "megaraid_sas.h"
 
+/*
+ * Modules parameters
+ */
+
+/*
+ * Fast driver load option, skip scanning for physical devices during
load.
+ * This would result in physical devices being skipped during driver
load
+ * time. These can be later added though, using /proc/scsi/scsi
+ */
+static unsigned int fast_load = 0;
+module_param_named(fast_load, fast_load, int, 0);
+MODULE_PARM_DESC(fast_load,
+ "megasas: Faster loading of the driver, skips physical devices! \
+  (default=0)");
+
 MODULE_LICENSE("GPL");
 MODULE_VERSION(MEGASAS_VERSION);
 MODULE_AUTHOR("[EMAIL PROTECTED]");
@@ -1094,6 +1109,40 @@ megasas_service_aen(struct megasas_insta
megasas_return_cmd(instance, cmd);
 }
 
+static struct megasas_instance *megasas_lookup_instance(u16 host_no)
+{
+   int i;
+
+   for (i = 0; i < megasas_mgmt_info.max_index; i++) {
+
+   if ((megasas_mgmt_info.instance[i]) &&
+   (megasas_mgmt_info.instance[i]->host->host_no == host_no))
+   return megasas_mgmt_info.instance[i];
+   }
+
+   return NULL;
+}
+
+static int megasas_slave_alloc(struct scsi_device *sdev) {
+   struct megasas_instance *instance ;
+   int tmp_fastload = fast_load;
+   instance = megasas_lookup_instance(sdev->host->host_no);
+
+   if (tmp_fastload && sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
+   if ((sdev->id == MEGASAS_MAX_DEV_PER_CHANNEL -1) &&
+   (sdev->channel == MEGASAS_MAX_PD_CHANNELS - 1)) {
+   /* If fast load option was set and scan for last device 
is
+* over, reset the fast_load flag so that during a 
possible
+* next scan, devices can be made available
+*/
+   fast_load = 0;
+   }
+   return -ENXIO;
+   }
+
+   return 0;
+}
+
 /*
  * Scsi host template for megaraid_sas driver
  */
@@ -1103,6 +1152,7 @@ static struct scsi_host_template megasas
.name = "LSI Logic SAS based MegaRAID driver",
.proc_name = "megaraid_sas",
.slave_configure = megasas_slave_configure,
+   .slave_alloc = megasas_slave_alloc,
.queuecommand = megasas_queue_command,
.eh_device_reset_handler = megasas_reset_device,
.eh_bus_reset_handler = megasas_reset_bus_host,
@@ -2969,20 +3019,6 @@ megasas_mgmt_fw_ioctl(struct megasas_ins
return error;
 }
 
-static struct megasas_instance *megasas_lookup_instance(u16 host_no)
-{
-   int i;
-
-   for (i = 0; i < megasas_mgmt_info.max_index; i++) {
-
-   if ((megasas_mgmt_info.instance[i]) &&
-  (megasas_mgmt_info.instance[i]->host->host_no == host_no))
-   return megasas_mgmt_info.instance[i];
- }
-
- return NULL;
-}
-
 static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg)
 {
struct megasas_iocpacket __user *user_ioc =



-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] scsi: megaraid_sas -- add hibernation support

2007-07-03 Thread bo yang

The megaraid_sas driver doesn't support the hibernation, the
suspend/resume routine implemented to support the hibernation.

Signed-off-by: Bo Yang <[EMAIL PROTECTED]> 

---

 drivers/scsi/megaraid/megaraid_sas.c |  308 +++--
 drivers/scsi/megaraid/megaraid_sas.h |1
 2 files changed, 239 insertions(+), 70 deletions(-)

diff -rupN linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c
linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c
--- linux-2.6.22_orig/drivers/scsi/megaraid/megaraid_sas.c 2007-06-20
02:18:24.0 -0400
+++ linux-2.6.22_new/drivers/scsi/megaraid/megaraid_sas.c 2007-06-30
03:21:27.0 -0400
@@ -1804,6 +1804,81 @@ static void megasas_complete_cmd_dpc(uns
 }
 
 /**
+ * megasas_issue_init_mfi - Initializes the FW
+ * @instance:  Adapter soft state
+ *
+ * Issues the INIT MFI cmd
+ */
+static int
+megasas_issue_init_mfi(struct megasas_instance *instance)
+{
+ u32 context;
+
+ struct megasas_cmd *cmd;
+
+ struct megasas_init_frame *init_frame;
+ struct megasas_init_queue_info *initq_info;
+ dma_addr_t init_frame_h;
+ dma_addr_t initq_info_h;
+
+   /*
+* Prepare a init frame. Note the init frame points to queue info
+* structure. Each frame has SGL allocated after first 64 bytes. For
+* this frame - since we don't need any SGL - we use SGL's space as
+* queue info structure
+*
+* We will not get a NULL command below. We just created the pool.
+*/
+   cmd = megasas_get_cmd(instance);
+
+   init_frame = (struct megasas_init_frame *)cmd->frame;
+   initq_info = (struct megasas_init_queue_info *)
+   ((unsigned long)init_frame + 64);
+
+   init_frame_h = cmd->frame_phys_addr;
+   initq_info_h = init_frame_h + 64;
+
+   context = init_frame->context;
+   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
+   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
+   init_frame->context = context;
+
+   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
+   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
+
+   initq_info->producer_index_phys_addr_lo = instance->producer_h;
+   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
+
+   init_frame->cmd = MFI_CMD_INIT;
+   init_frame->cmd_status = 0xFF;
+   init_frame->queue_info_new_phys_addr_lo = initq_info_h;
+
+   init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info);
+
+   /*
+* disable the intr before firing the init frame to FW
+*/
+   instance->instancet->disable_intr(instance->reg_set);
+
+   /*
+* Issue the init frame in polled mode
+*/
+
+   if (megasas_issue_polled(instance, cmd)) {
+   printk(KERN_DEBUG "megasas: Failed to init firmware\n");
+   megasas_return_cmd(instance, cmd);
+   goto fail_fw_init;
+   }
+
+   megasas_return_cmd(instance, cmd);
+
+   return 0;
+
+   fail_fw_init:
+   return -EINVAL;
+}
+
+/**
  * megasas_init_mfi -  Initializes the FW
  * @instance:  Adapter soft state
  *
@@ -1816,15 +1891,7 @@ static int megasas_init_mfi(struct megas
u32 max_sectors_1;
u32 max_sectors_2;
struct megasas_register_set __iomem *reg_set;
-
-   struct megasas_cmd *cmd;
struct megasas_ctrl_info *ctrl_info;
-
-   struct megasas_init_frame *init_frame;
-   struct megasas_init_queue_info *initq_info;
-   dma_addr_t init_frame_h;
-   dma_addr_t initq_info_h;
-
/*
 * Map the message registers
 */
@@ -1901,52 +1968,8 @@ static int megasas_init_mfi(struct megas
goto fail_reply_queue;
}
 
-   /*
-* Prepare a init frame. Note the init frame points to queue info
-* structure. Each frame has SGL allocated after first 64 bytes. For
-* this frame - since we don't need any SGL - we use SGL's space as
-* queue info structure
-*
-* We will not get a NULL command below. We just created the pool.
-*/
-   cmd = megasas_get_cmd(instance);
-
-   init_frame = (struct megasas_init_frame *)cmd->frame;
-   initq_info = (struct megasas_init_queue_info *)
-   ((unsigned long)init_frame + 64);
-
-   init_frame_h = cmd->frame_phys_addr;
-   initq_info_h = init_frame_h + 64;
-
-   memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
-   memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
-
-   initq_info->reply_queue_entries = instance->max_fw_cmds + 1;
-   initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h;
-
-   initq_info->producer_index_phys_addr_lo = instance->producer_h;
-   initq_info->consumer_index_phys_addr_lo = instance->consumer_h;
-
-   init_