Re: [PATCH 1/6] esas2r: remove initialization / cleanup dead wood

2018-03-23 Thread Bradley Grove


Looks fine.

Acked-by: Bradley Grove <bgr...@attotech.com>


On 03/19/2018 03:37 AM, Christoph Hellwig wrote:

esas2r has been converted to hotplug style initialization long ago, but
kept various remant of the old-style scsi_module.c initialization around.
Remove those.

Signed-off-by: Christoph Hellwig <h...@lst.de>
---
  drivers/scsi/esas2r/esas2r.h  |  2 --
  drivers/scsi/esas2r/esas2r_init.c | 21 
  drivers/scsi/esas2r/esas2r_main.c | 72 +++
  3 files changed, 4 insertions(+), 91 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index 1da6407ee142..858c3b33db78 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -962,7 +962,6 @@ struct esas2r_adapter {
   * Function Declarations
   * SCSI functions
   */
-int esas2r_release(struct Scsi_Host *);
  const char *esas2r_info(struct Scsi_Host *);
  int esas2r_write_params(struct esas2r_adapter *a, struct esas2r_request *rq,
struct esas2r_sas_nvram *data);
@@ -984,7 +983,6 @@ int esas2r_target_reset(struct scsi_cmnd *cmd);
  /* Internal functions */
  int esas2r_init_adapter(struct Scsi_Host *host, struct pci_dev *pcid,
int index);
-int esas2r_cleanup(struct Scsi_Host *host);
  int esas2r_read_fw(struct esas2r_adapter *a, char *buf, long off, int count);
  int esas2r_write_fw(struct esas2r_adapter *a, const char *buf, long off,
int count);
diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 5b14dd29b764..9dffcb28c9b7 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -661,27 +661,6 @@ void esas2r_kill_adapter(int i)
}
  }
  
-int esas2r_cleanup(struct Scsi_Host *host)

-{
-   struct esas2r_adapter *a;
-   int index;
-
-   if (host == NULL) {
-   int i;
-
-   esas2r_debug("esas2r_cleanup everything");
-   for (i = 0; i < MAX_ADAPTERS; i++)
-   esas2r_kill_adapter(i);
-   return -1;
-   }
-
-   esas2r_debug("esas2r_cleanup called for host %p", host);
-   a = (struct esas2r_adapter *)host->hostdata;
-   index = a->index;
-   esas2r_kill_adapter(index);
-   return index;
-}
-
  int esas2r_suspend(struct pci_dev *pdev, pm_message_t state)
  {
struct Scsi_Host *host = pci_get_drvdata(pdev);
diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index 4eb14301a497..e07eac5be087 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -235,7 +235,6 @@ static struct scsi_host_template driver_template = {
.module = THIS_MODULE,
.show_info  = esas2r_show_info,
.name   = ESAS2R_LONGNAME,
-   .release= esas2r_release,
.info   = esas2r_info,
.ioctl  = esas2r_ioctl,
.queuecommand   = esas2r_queuecommand,
@@ -520,44 +519,16 @@ static int esas2r_probe(struct pci_dev *pcid,
  
  static void esas2r_remove(struct pci_dev *pdev)

  {
-   struct Scsi_Host *host;
-   int index;
-
-   if (pdev == NULL) {
-   esas2r_log(ESAS2R_LOG_WARN, "esas2r_remove pdev==NULL");
-   return;
-   }
-
-   host = pci_get_drvdata(pdev);
-
-   if (host == NULL) {
-   /*
-* this can happen if pci_set_drvdata was already called
-* to clear the host pointer.  if this is the case, we
-* are okay; this channel has already been cleaned up.
-*/
-
-   return;
-   }
+   struct Scsi_Host *host = pci_get_drvdata(pdev);
+   struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
  
  	esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),

   "esas2r_remove(%p) called; "
   "host:%p", pdev,
   host);
  
-	index = esas2r_cleanup(host);

-
-   if (index < 0)
-   esas2r_log_dev(ESAS2R_LOG_WARN, &(pdev->dev),
-  "unknown host in %s",
-  __func__);
-
+   esas2r_kill_adapter(a->index);
found_adapters--;
-
-   /* if this was the last adapter, clean up the rest of the driver */
-
-   if (found_adapters == 0)
-   esas2r_cleanup(NULL);
  }
  
  static int __init esas2r_init(void)

@@ -638,30 +609,7 @@ static int __init esas2r_init(void)
for (i = 0; i < MAX_ADAPTERS; i++)
esas2r_adapters[i] = NULL;
  
-	/* initialize */

-
-   driver_template.module = THIS_MODULE;
-
-   if (pci_register_driver(_pci_driver) != 0)
-   esas2r_

Re: [PATCH 16/29] scsi: esas2r: constify pci_device_id.

2017-08-10 Thread Bradley Grove



Looks good.

Acked-by: Bradley Grove <bgr...@attotech.com>


On 07/30/2017 04:40 AM, Arvind Yadav wrote:

pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by  work with
const pci_device_id. So mark the non-const structs as const.

Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com>
---
  drivers/scsi/esas2r/esas2r_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index f2e9d8a..81f226b 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -309,7 +309,7 @@ MODULE_PARM_DESC(interrupt_mode,
 "Defines the interrupt mode to use.  0 for legacy"
 ", 1 for MSI.  Default is MSI (1).");
  
-static struct pci_device_id

+static const struct pci_device_id
esas2r_pci_table[] = {
{ ATTO_VENDOR_ID, 0x0049, ATTO_VENDOR_ID, 0x0049,
  0,






This electronic transmission and any attachments hereto are intended only for the use of the individual or entity to which it is addressed and may contain confidential information belonging to ATTO Technology, Inc. If you have reason to believe that you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this electronic transmission is strictly prohibited. If you have reason to believe that you have received this transmission in error, please notify ATTO immediately by return e-mail and delete and destroy this communication.   


Re: [PATCH] [SCSI] esas2r: remove redundant NULL check on buffer

2017-03-16 Thread Bradley Grove

On 03/15/2017 12:46 PM, Colin King wrote:

From: Colin Ian King <colin.k...@canonical.com>

buffer is a pointer to the static char array event_buffer and
therefore can never be null, so the check is redundant. Remove it.

Detected by CoverityScan, CID#1077556 ("Logically Dead Code")

Signed-off-by: Colin Ian King <colin.k...@canonical.com>
---
 drivers/scsi/esas2r/esas2r_log.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_log.c b/drivers/scsi/esas2r/esas2r_log.c
index a82030a..65fdf22 100644
--- a/drivers/scsi/esas2r/esas2r_log.c
+++ b/drivers/scsi/esas2r/esas2r_log.c
@@ -130,11 +130,6 @@ static int esas2r_log_master(const long level,

spin_lock_irqsave(_buffer_lock, flags);

-   if (buffer == NULL) {
-   spin_unlock_irqrestore(_buffer_lock, flags);
-   return -1;
-   }
-
memset(buffer, 0, buflen);

/*



Thanks,

Acked-by: Bradley Grove <bgr...@attotech.com>



This electronic transmission and any attachments hereto are intended only for the use of the individual or entity to which it is addressed and may contain confidential information belonging to ATTO Technology, Inc. If you have reason to believe that you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this electronic transmission is strictly prohibited. If you have reason to believe that you have received this transmission in error, please notify ATTO immediately by return e-mail and delete and destroy this communication.   


Re: [PATCH] scsi: not need to alloc zero buffer for local_atto_ioctl

2016-08-25 Thread Bradley Grove

Acked-by: Bradley Grove <bgr...@attotech.com>

On 08/20/2016 10:33 PM, Shawn Lin wrote:

We don't need to use kzalloc as we will always memset the
local_atto_ioctl later.

Signed-off-by: Shawn Lin <shawn@rock-chips.com>
---

 drivers/scsi/esas2r/esas2r_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index 2aca4d1..5092c82 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -194,7 +194,7 @@ static ssize_t write_hw(struct file *file, struct kobject 
*kobj,
int length = min(sizeof(struct atto_ioctl), count);

if (!a->local_atto_ioctl) {
-   a->local_atto_ioctl = kzalloc(sizeof(struct atto_ioctl),
+   a->local_atto_ioctl = kmalloc(sizeof(struct atto_ioctl),
  GFP_KERNEL);
if (a->local_atto_ioctl == NULL) {
esas2r_log(ESAS2R_LOG_WARN,





This electronic transmission and any attachments hereto are intended only for the use of the individual or entity to which it is addressed and may contain confidential information belonging to ATTO Technology, Inc. If you have reason to believe that you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this electronic transmission is strictly prohibited. If you have reason to believe that you have received this transmission in error, please notify ATTO immediately by return e-mail and delete and destroy this communication.   
--

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


Re: [PATCH] scsi: don't reinitialize adapter's req_table

2016-08-25 Thread Bradley Grove

Acked-by: Bradley Grove <bgr...@attotech.com>

On 08/20/2016 10:39 PM, Shawn Lin wrote:

req_table is allocate by kzalloc, so we don't need to
zero it again anyway.

Signed-off-by: Shawn Lin <shawn@rock-chips.com>
---

 drivers/scsi/esas2r/esas2r_init.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 78ce4d61..d6e53ae 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -963,10 +963,6 @@ bool esas2r_init_adapter_struct(struct esas2r_adapter *a,

/* initialize the allocated memory */
if (test_bit(AF_FIRST_INIT, >flags)) {
-   memset(a->req_table, 0,
-  (num_requests + num_ae_requests +
-   1) * sizeof(struct esas2r_request *));
-
esas2r_targ_db_initialize(a);

/* prime parts of the inbound list */






This electronic transmission and any attachments hereto are intended only for the use of the individual or entity to which it is addressed and may contain confidential information belonging to ATTO Technology, Inc. If you have reason to believe that you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this electronic transmission is strictly prohibited. If you have reason to believe that you have received this transmission in error, please notify ATTO immediately by return e-mail and delete and destroy this communication.   
--

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


Re: [PATCH 3/3] esas2r: fix an oversight in setting return value

2014-11-24 Thread Bradley Grove

Acked-by: Bradley Grove bgr...@attotech.com

Thanks,
Brad

On 11/16/2014 08:35 AM, Tomas Henzl wrote:

The patch moves an error code assigment to a 'default' case
in the previous switch statement.

Signed-off-by: Tomas Henzl the...@redhat.com
---
  drivers/scsi/esas2r/esas2r_ioctl.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
index c88b9f9491..baf913047b 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -1524,9 +1524,12 @@ ioctl_done:
case -EINVAL:
ioctl-header.return_code = IOCTL_INVALID_PARAM;
break;
+
+   default:
+   ioctl-header.return_code = IOCTL_GENERAL_ERROR;
+   break;
}

-   ioctl-header.return_code = IOCTL_GENERAL_ERROR;
}

/* Always copy the buffer back, if only to pick up the status */



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


Re: [PATCH 2/3] esas2r: fix an error path in esas2r_ioctl_handler

2014-11-24 Thread Bradley Grove


Acked-by: Bradley Grove bgr...@attotech.com

Thanks,
Brad


On 11/16/2014 08:35 AM, Tomas Henzl wrote:

Is seems strange to manipulate nvram_semaphore when in this place,
this patch fixes it.

Signed-off-by: Tomas Henzl the...@redhat.com
---
  drivers/scsi/esas2r/esas2r_ioctl.c | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
index 9ac8207554..c88b9f9491 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -1420,9 +1420,10 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void 
__user *arg)

rq = esas2r_alloc_request(a);
if (rq == NULL) {
-   up(a-nvram_semaphore);
-   ioctl-data.prw.code = 0;
-   break;
+   kfree(ioctl);
+   esas2r_log(ESAS2R_LOG_WARN,
+  could not allocate an internal request);
+   return -ENOMEM;
}

code = esas2r_write_params(a, rq,



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


Re: [PATCH 3/3] esas2r: fix an oversight in setting return value

2014-11-24 Thread Bradley Grove

Acked-by: Bradley Grove bgr...@attotech.com

Thanks,
Brad

On 11/16/2014 08:35 AM, Tomas Henzl wrote:

The patch moves an error code assigment to a 'default' case
in the previous switch statement.

Signed-off-by: Tomas Henzl the...@redhat.com
---
  drivers/scsi/esas2r/esas2r_ioctl.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
index c88b9f9491..baf913047b 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -1524,9 +1524,12 @@ ioctl_done:
case -EINVAL:
ioctl-header.return_code = IOCTL_INVALID_PARAM;
break;
+
+   default:
+   ioctl-header.return_code = IOCTL_GENERAL_ERROR;
+   break;
}

-   ioctl-header.return_code = IOCTL_GENERAL_ERROR;
}

/* Always copy the buffer back, if only to pick up the status */



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


Re: [PATCH 1/3] esas2r: fir error handling in do_fm_api

2014-11-24 Thread Bradley Grove


Looks good.

Acked-by: Bradley Grove bgr...@attotech.com

Thanks,
Brad

On 11/16/2014 08:35 AM, Tomas Henzl wrote:

This patch fixes an error path and rearranges error handling.

Signed-off-by: Tomas Henzl the...@redhat.com
---
  drivers/scsi/esas2r/esas2r_ioctl.c | 10 +-
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
index d89a0277a8..9ac8207554 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -117,9 +117,8 @@ static void do_fm_api(struct esas2r_adapter *a, struct 
esas2r_flash_img *fi)

rq = esas2r_alloc_request(a);
if (rq == NULL) {
-   up(a-fm_api_semaphore);
fi-status = FI_STAT_BUSY;
-   return;
+   goto free_sem;
}

if (fi == a-firmware.header) {
@@ -135,7 +134,7 @@ static void do_fm_api(struct esas2r_adapter *a, struct 
esas2r_flash_img *fi)
if (a-firmware.header_buff == NULL) {
esas2r_debug(failed to allocate header buffer!);
fi-status = FI_STAT_BUSY;
-   return;
+   goto free_req;
}

memcpy(a-firmware.header_buff, fi,
@@ -171,9 +170,10 @@ all_done:
  a-firmware.header_buff,
  (dma_addr_t)a-firmware.header_buff_phys);
}
-
-   up(a-fm_api_semaphore);
+free_req:
esas2r_free_request(a, (struct esas2r_request *)rq);
+free_sem:
+   up(a-fm_api_semaphore);
return;

  }



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


[PATCH V2] pm80xx: Fix hibernation issue

2014-06-19 Thread bradley . grove
From: Bradley Grove bgr...@attotech.com

During hibernation, the HBA firmware may lose power and forget the device
id info.   This causes the HBA to reject IO upon resume.   The fix is
to call the libsas power management routines to make the domain device
forgetful.

This fixes bug 76681: https://bugzilla.kernel.org/show_bug.cgi?id=76681

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/pm8001/pm8001_init.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index c4f31b21..86cf03a 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -957,6 +957,7 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, 
pm_message_t state)
int  i, j;
u32 device_state;
pm8001_ha = sha-lldd_ha;
+   sas_suspend_ha(sha);
flush_workqueue(pm8001_wq);
scsi_block_requests(pm8001_ha-shost);
if (!pdev-pm_cap) {
@@ -1006,6 +1007,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
int rc;
u8 i = 0, j;
u32 device_state;
+   DECLARE_COMPLETION_ONSTACK(completion);
pm8001_ha = sha-lldd_ha;
device_state = pdev-current_state;
 
@@ -1026,7 +1028,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
rc = pci_go_44(pdev);
if (rc)
goto err_out_disable;
-
+   sas_prep_resume_ha(sha);
/* chip soft rst only for spc */
if (pm8001_ha-chip_id == chip_8001) {
PM8001_CHIP_DISP-chip_soft_rst(pm8001_ha);
@@ -1058,7 +1060,13 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
for (i = 1; i  pm8001_ha-number_of_intr; i++)
PM8001_CHIP_DISP-interrupt_enable(pm8001_ha, i);
}
-   scsi_unblock_requests(pm8001_ha-shost);
+   pm8001_ha-flags = PM8001F_RUN_TIME;
+   for (i = 0; i  pm8001_ha-chip-n_phy; i++) {
+   pm8001_ha-phy[i].enable_completion = completion;
+   PM8001_CHIP_DISP-phy_start_req(pm8001_ha, i);
+   wait_for_completion(completion);
+   }
+   sas_resume_ha(sha);
return 0;
 
 err_out_disable:
-- 
1.9.3

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


Re: [PATCH] pm80xx: Fix hibernation issue

2014-06-17 Thread Bradley Grove


James,

The sleep is there to delay until the work kicked off by the scan start 
is complete.


Jack Wang and I are working on a different fix that won't require the delay.

Brad


On 06/16/2014 08:04 PM, James Bottomley wrote:

On Mon, 2014-06-16 at 15:30 -0400, bradley.gr...@gmail.com wrote:

From: Bradley Grove bgr...@attotech.com

During hibernation, the HBA firmware may lose power and forget the device
id info.   This causes the HBA to reject IO upon resume.   The fix is
to call the libsas power management routines to make the domain device
forgetful.

This patch also changes the value of pm8001_flags during resume to allow
completions to work.

This fixes bug 76681: https://bugzilla.kernel.org/show_bug.cgi?id=76681

Signed-off-by: Bradley Grove bgr...@attotech.com
---
  drivers/scsi/pm8001/pm8001_init.c | 8 +++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index c4f31b21..9f51a1f 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -957,6 +957,7 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, 
pm_message_t state)
int  i, j;
u32 device_state;
pm8001_ha = sha-lldd_ha;
+   sas_suspend_ha(sha);
flush_workqueue(pm8001_wq);
scsi_block_requests(pm8001_ha-shost);
if (!pdev-pm_cap) {
@@ -1026,7 +1027,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
rc = pci_go_44(pdev);
if (rc)
goto err_out_disable;
-
+   sas_prep_resume_ha(sha);
/* chip soft rst only for spc */
if (pm8001_ha-chip_id == chip_8001) {
PM8001_CHIP_DISP-chip_soft_rst(pm8001_ha);
@@ -1058,7 +1059,12 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
for (i = 1; i  pm8001_ha-number_of_intr; i++)
PM8001_CHIP_DISP-interrupt_enable(pm8001_ha, i);
}
+   pm8001_ha-flags = PM8001F_INIT_TIME;
scsi_unblock_requests(pm8001_ha-shost);
+   pm8001_scan_start(pm8001_ha-shost);
+   msleep(100);


What's the reason for the 0.1s sleep?  Something tells me it's to try to
ensure that all the work kicked off by the scan start is completed in
which case a sleep seems to be a bit racy.

James


+   sas_resume_ha(sha);
+   pm8001_ha-flags = PM8001F_RUN_TIME;
return 0;

  err_out_disable:





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


[PATCH] pm80xx: Fix hibernation issue

2014-06-16 Thread bradley . grove
From: Bradley Grove bgr...@attotech.com

During hibernation, the HBA firmware may lose power and forget the device
id info.   This causes the HBA to reject IO upon resume.   The fix is
to call the libsas power management routines to make the domain device
forgetful.

This patch also changes the value of pm8001_flags during resume to allow
completions to work.

This fixes bug 76681: https://bugzilla.kernel.org/show_bug.cgi?id=76681

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/pm8001/pm8001_init.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index c4f31b21..9f51a1f 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -957,6 +957,7 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, 
pm_message_t state)
int  i, j;
u32 device_state;
pm8001_ha = sha-lldd_ha;
+   sas_suspend_ha(sha);
flush_workqueue(pm8001_wq);
scsi_block_requests(pm8001_ha-shost);
if (!pdev-pm_cap) {
@@ -1026,7 +1027,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
rc = pci_go_44(pdev);
if (rc)
goto err_out_disable;
-
+   sas_prep_resume_ha(sha);
/* chip soft rst only for spc */
if (pm8001_ha-chip_id == chip_8001) {
PM8001_CHIP_DISP-chip_soft_rst(pm8001_ha);
@@ -1058,7 +1059,12 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
for (i = 1; i  pm8001_ha-number_of_intr; i++)
PM8001_CHIP_DISP-interrupt_enable(pm8001_ha, i);
}
+   pm8001_ha-flags = PM8001F_INIT_TIME;
scsi_unblock_requests(pm8001_ha-shost);
+   pm8001_scan_start(pm8001_ha-shost);
+   msleep(100);
+   sas_resume_ha(sha);
+   pm8001_ha-flags = PM8001F_RUN_TIME;
return 0;
 
 err_out_disable:
-- 
1.9.3

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


Re: [PATCH V2] [SCSI] esas2r: Fix comment

2014-04-23 Thread Bradley Grove


This looks fine to me.

Acked-by: Bradley Grove bgr...@attotech.com

Thanks,
Brad

On 04/22/2014 02:23 PM, Marek Vasut wrote:

Minor fix for a message in the driver so that it matches the function name.

Signed-off-by: Marek Vasut ma...@denx.de
Cc: James Bottomley jbottom...@parallels.com
Cc: Bradley Grove bgr...@attotech.com
Cc: Sergei Shtylyov sergei.shtyl...@cogentembedded.com
---
  drivers/scsi/esas2r/esas2r_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

V2: Post to linux-scsi, tweak the commit message.

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index f37f3e3..6504a19 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -390,7 +390,7 @@ static int esas2r_probe(struct pci_dev *pcid,
esas2r_log_dev(ESAS2R_LOG_INFO, (pcid-dev),
   pci_enable_device() OK);
esas2r_log_dev(ESAS2R_LOG_INFO, (pcid-dev),
-  after pci_device_enable() enable_cnt: %d,
+  after pci_enable_device() enable_cnt: %d,
   pcid-enable_cnt.counter);

host = scsi_host_alloc(driver_template, host_alloc_size);



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


Re: [PATCH 0/2] pm80xx: Fix ATTO pm8001 based HBA support

2014-02-17 Thread Bradley Grove


James,

There were a couple of patches that I expected to be added during the 
3.14-rc1 merge window that weren't.   Specifically:


http://marc.info/?l=linux-scsim=138753665607127w=2
http://marc.info/?l=linux-scsim=138738970431549w=2

Can you explain why they weren't included?

Brad

On 12/20/2013 05:50 AM, Jack Wang wrote:

On 12/19/2013 04:50 PM, Bradley Grove wrote:

Addresses issues that we uncovered during testing with our HBAs.
For the most part, we just enabled code that was already being used
for other vendor's HBAs.

Bradley Grove (2):
   pm80xx: Read saved WWN from NVMD for ATTO pm8001 based HBAs.
   pm80xx: Enable BAR shift to avoid BIOS conflict with MPI space for
 ATTO pm8001 based HBAs.

  drivers/scsi/pm8001/pm8001_hwi.c  |  6 +++---
  drivers/scsi/pm8001/pm8001_init.c | 10 +-
  2 files changed, 8 insertions(+), 8 deletions(-)


Looks fine, thanks
  Acked-by: Jack Wang xjtu...@gmail.com
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



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


[PATCH 1/2] pm80xx: Read saved WWN from NVMD for ATTO pm8001 based HBAs.

2013-12-19 Thread Bradley Grove
Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/pm8001/pm8001_init.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index 73a120d..cb89d15 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -625,7 +625,7 @@ static void pm8001_init_sas_add(struct pm8001_hba_info 
*pm8001_ha)
pm8001_ha-nvmd_completion = completion;
 
if (pm8001_ha-chip_id == chip_8001) {
-   if (deviceid == 0x8081) {
+   if (deviceid == 0x8081 || deviceid == 0x0042) {
payload.minor_function = 4;
payload.length = 4096;
} else {
@@ -646,6 +646,9 @@ static void pm8001_init_sas_add(struct pm8001_hba_info 
*pm8001_ha)
if (deviceid == 0x8081)
pm8001_ha-sas_addr[j] =
payload.func_specific[0x704 + i];
+   else if (deviceid == 0x0042)
+   pm8001_ha-sas_addr[j] =
+   payload.func_specific[0x010 + i];
} else
pm8001_ha-sas_addr[j] =
payload.func_specific[0x804 + i];
@@ -1072,10 +1075,7 @@ err_out_enable:
  */
 static struct pci_device_id pm8001_pci_table[] = {
{ PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
-   {
-   PCI_DEVICE(0x117c, 0x0042),
-   .driver_data = chip_8001
-   },
+   { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
/* Support for SPC/SPCv/SPCve controllers */
{ PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
{ PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
-- 
1.8.3.1

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


[PATCH 2/2] pm80xx: Enable BAR shift to avoid BIOS conflict with MPI space for ATTO pm8001 based HBAs.

2013-12-19 Thread Bradley Grove
Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/pm8001/pm8001_hwi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index 46ace52..561ca2c 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -644,7 +644,7 @@ static int pm8001_chip_init(struct pm8001_hba_info 
*pm8001_ha)
pci_read_config_word(pm8001_ha-pdev, PCI_DEVICE_ID, deviceid);
/* 8081 controllers need BAR shift to access MPI space
* as this is shared with BIOS data */
-   if (deviceid == 0x8081) {
+   if (deviceid == 0x8081 || deviceid == 0x0042) {
if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
PM8001_FAIL_DBG(pm8001_ha,
pm8001_printk(Shift Bar4 to 0x%x failed\n,
@@ -673,7 +673,7 @@ static int pm8001_chip_init(struct pm8001_hba_info 
*pm8001_ha)
for (i = 0; i  PM8001_MAX_OUTB_NUM; i++)
update_outbnd_queue_table(pm8001_ha, i);
/* 8081 controller donot require these operations */
-   if (deviceid != 0x8081) {
+   if (deviceid != 0x8081  deviceid != 0x0042) {
mpi_set_phys_g3_with_ssc(pm8001_ha, 0);
/* 7-130ms, 34-500ms, 119-1.5s */
mpi_set_open_retry_interval_reg(pm8001_ha, 119);
@@ -701,7 +701,7 @@ static int mpi_uninit_check(struct pm8001_hba_info 
*pm8001_ha)
u32 gst_len_mpistate;
u16 deviceid;
pci_read_config_word(pm8001_ha-pdev, PCI_DEVICE_ID, deviceid);
-   if (deviceid == 0x8081) {
+   if (deviceid == 0x8081 || deviceid == 0x0042) {
if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
PM8001_FAIL_DBG(pm8001_ha,
pm8001_printk(Shift Bar4 to 0x%x failed\n,
-- 
1.8.3.1

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


[PATCH 0/2] pm80xx: Fix ATTO pm8001 based HBA support

2013-12-19 Thread Bradley Grove
Addresses issues that we uncovered during testing with our HBAs.
For the most part, we just enabled code that was already being used 
for other vendor's HBAs.

Bradley Grove (2):
  pm80xx: Read saved WWN from NVMD for ATTO pm8001 based HBAs.
  pm80xx: Enable BAR shift to avoid BIOS conflict with MPI space for
ATTO pm8001 based HBAs.

 drivers/scsi/pm8001/pm8001_hwi.c  |  6 +++---
 drivers/scsi/pm8001/pm8001_init.c | 10 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

-- 
1.8.3.1

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


Re: [RESEND][PATCH] scsi: esas2r: fix potential format string flaw

2013-12-17 Thread Bradley Grove

Acked-by: Bradley Grove bgr...@attotech.com


On 12/17/2013 01:27 PM, Kees Cook wrote:

This makes sure format strings cannot leak into the printk call via the
constructed buffer.

Signed-off-by: Kees Cook keesc...@chromium.org
---
  drivers/scsi/esas2r/esas2r_log.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_log.c b/drivers/scsi/esas2r/esas2r_log.c
index 9bf285df58dd..61fc19d296bd 100644
--- a/drivers/scsi/esas2r/esas2r_log.c
+++ b/drivers/scsi/esas2r/esas2r_log.c
@@ -171,7 +171,7 @@ static int esas2r_log_master(const long level,
if (strlen(event_buffer)  buflen)
strcat(buffer, \n);

-   printk(event_buffer);
+   printk(%s, event_buffer);

spin_unlock_irqrestore(event_buffer_lock, flags);
}



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


[PATCH 1/4] esas2r: Directly call kernel functions for atomic bit operations

2013-10-01 Thread Bradley Grove
Previously the code embedded the kernel's test_bit/clear_bit
functions in wrappers that accepted u32 parameters.  The
wrapper cast these parameters to longs before passing them
to the kernel's bit functions.   This did not work properly
on platforms with 64-bit longs.

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r.h| 125 +++
 drivers/scsi/esas2r/esas2r_disc.c   |  55 +++---
 drivers/scsi/esas2r/esas2r_flash.c  |  34 +
 drivers/scsi/esas2r/esas2r_init.c   | 143 +---
 drivers/scsi/esas2r/esas2r_int.c|  97 
 drivers/scsi/esas2r/esas2r_io.c |  73 +-
 drivers/scsi/esas2r/esas2r_ioctl.c  |  28 +++
 drivers/scsi/esas2r/esas2r_main.c   |  34 -
 drivers/scsi/esas2r/esas2r_targdb.c |   2 +-
 drivers/scsi/esas2r/esas2r_vda.c|   6 +-
 10 files changed, 291 insertions(+), 306 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index 0838e26..d128c96 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -799,47 +799,47 @@ struct esas2r_adapter {
struct esas2r_target *targetdb_end;
unsigned char *regs;
unsigned char *data_window;
-   u32 volatile flags;
-   #define AF_PORT_CHANGE  (u32)(0x0001)
-   #define AF_CHPRST_NEEDED(u32)(0x0004)
-   #define AF_CHPRST_PENDING   (u32)(0x0008)
-   #define AF_CHPRST_DETECTED  (u32)(0x0010)
-   #define AF_BUSRST_NEEDED(u32)(0x0020)
-   #define AF_BUSRST_PENDING   (u32)(0x0040)
-   #define AF_BUSRST_DETECTED  (u32)(0x0080)
-   #define AF_DISABLED (u32)(0x0100)
-   #define AF_FLASH_LOCK   (u32)(0x0200)
-   #define AF_OS_RESET (u32)(0x2000)
-   #define AF_FLASHING (u32)(0x4000)
-   #define AF_POWER_MGT(u32)(0x8000)
-   #define AF_NVR_VALID(u32)(0x0001)
-   #define AF_DEGRADED_MODE(u32)(0x0002)
-   #define AF_DISC_PENDING (u32)(0x0004)
-   #define AF_TASKLET_SCHEDULED(u32)(0x0008)
-   #define AF_HEARTBEAT(u32)(0x0020)
-   #define AF_HEARTBEAT_ENB(u32)(0x0040)
-   #define AF_NOT_PRESENT  (u32)(0x0080)
-   #define AF_CHPRST_STARTED   (u32)(0x0100)
-   #define AF_FIRST_INIT   (u32)(0x0200)
-   #define AF_POWER_DOWN   (u32)(0x0400)
-   #define AF_DISC_IN_PROG (u32)(0x0800)
-   #define AF_COMM_LIST_TOGGLE (u32)(0x1000)
-   #define AF_LEGACY_SGE_MODE  (u32)(0x2000)
-   #define AF_DISC_POLLED  (u32)(0x4000)
-   u32 volatile flags2;
-   #define AF2_SERIAL_FLASH(u32)(0x0001)
-   #define AF2_DEV_SCAN(u32)(0x0002)
-   #define AF2_DEV_CNT_OK  (u32)(0x0004)
-   #define AF2_COREDUMP_AVAIL  (u32)(0x0008)
-   #define AF2_COREDUMP_SAVED  (u32)(0x0010)
-   #define AF2_VDA_POWER_DOWN  (u32)(0x0100)
-   #define AF2_THUNDERLINK (u32)(0x0200)
-   #define AF2_THUNDERBOLT (u32)(0x0400)
-   #define AF2_INIT_DONE   (u32)(0x0800)
-   #define AF2_INT_PENDING (u32)(0x1000)
-   #define AF2_TIMER_TICK  (u32)(0x2000)
-   #define AF2_IRQ_CLAIMED (u32)(0x4000)
-   #define AF2_MSI_ENABLED (u32)(0x8000)
+   long flags;
+   #define AF_PORT_CHANGE  0
+   #define AF_CHPRST_NEEDED1
+   #define AF_CHPRST_PENDING   2
+   #define AF_CHPRST_DETECTED  3
+   #define AF_BUSRST_NEEDED4
+   #define AF_BUSRST_PENDING   5
+   #define AF_BUSRST_DETECTED  6
+   #define AF_DISABLED 7
+   #define AF_FLASH_LOCK   8
+   #define AF_OS_RESET 9
+   #define AF_FLASHING 10
+   #define AF_POWER_MGT11
+   #define AF_NVR_VALID12
+   #define AF_DEGRADED_MODE13
+   #define AF_DISC_PENDING 14
+   #define AF_TASKLET_SCHEDULED15
+   #define AF_HEARTBEAT16
+   #define AF_HEARTBEAT_ENB17
+   #define AF_NOT_PRESENT  18
+   #define AF_CHPRST_STARTED   19
+   #define AF_FIRST_INIT   20
+   #define AF_POWER_DOWN   21
+   #define AF_DISC_IN_PROG 22
+   #define AF_COMM_LIST_TOGGLE 23
+   #define AF_LEGACY_SGE_MODE  24
+   #define AF_DISC_POLLED  25
+   long flags2;
+   #define AF2_SERIAL_FLASH0
+   #define AF2_DEV_SCAN1
+   #define AF2_DEV_CNT_OK  2
+   #define AF2_COREDUMP_AVAIL  3
+   #define AF2_COREDUMP_SAVED  4
+   #define AF2_VDA_POWER_DOWN  5
+   #define AF2_THUNDERLINK 6
+   #define AF2_THUNDERBOLT 7
+   #define AF2_INIT_DONE   8
+   #define AF2_INT_PENDING 9
+   #define AF2_TIMER_TICK  10
+   #define AF2_IRQ_CLAIMED 11
+   #define

[PATCH 2/4] esas2r: Fixes for big-endian platforms

2013-10-01 Thread Bradley Grove
In esas2r_format_init_msg(), sgl_page_size and epoch_time params
are converted to little endian and the firmware version read from
the hba is converted to cpu endianess.

In esas2r_rq_init_request, correct and simplify the construction
of the SCSI handle.

These fixes are the result of testing on a PPC64 machine.

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r.h  |  7 ++-
 drivers/scsi/esas2r/esas2r_init.c | 11 +++
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index d128c96..3fd305d 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -1207,7 +1207,6 @@ static inline void esas2r_rq_init_request(struct 
esas2r_request *rq,
  struct esas2r_adapter *a)
 {
union atto_vda_req *vrq = rq-vrq;
-   u32 handle;
 
INIT_LIST_HEAD(rq-sg_table_head);
rq-data_buf = (void *)(vrq + 1);
@@ -1243,11 +1242,9 @@ static inline void esas2r_rq_init_request(struct 
esas2r_request *rq,
 
/*
 * add a reference number to the handle to make it unique (until it
-* wraps of course) while preserving the upper word
+* wraps of course) while preserving the least significant word
 */
-
-   handle = be32_to_cpu(vrq-scsi.handle)  0x;
-   vrq-scsi.handle = cpu_to_be32(handle + a-cmd_ref_no++);
+   vrq-scsi.handle = (a-cmd_ref_no++  16) | (u16)vrq-scsi.handle;
 
/*
 * the following formats a SCSI request.  the caller can override as
diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 15d222b..8278819 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -1235,8 +1235,8 @@ static bool esas2r_format_init_msg(struct esas2r_adapter 
*a,
 0,
 NULL);
ci = (struct atto_vda_cfg_init *)rq-vrq-cfg.data.init;
-   ci-sgl_page_size = sgl_page_size;
-   ci-epoch_time = now.tv_sec;
+   ci-sgl_page_size = cpu_to_le32(sgl_page_size);
+   ci-epoch_time = cpu_to_le32(now.tv_sec);
rq-flags |= RF_FAILURE_OK;
a-init_msg = ESAS2R_INIT_MSG_INIT;
break;
@@ -1246,12 +1246,15 @@ static bool esas2r_format_init_msg(struct 
esas2r_adapter *a,
if (rq-req_stat == RS_SUCCESS) {
u32 major;
u32 minor;
+   u16 fw_release;
 
a-fw_version = le16_to_cpu(
rq-func_rsp.cfg_rsp.vda_version);
a-fw_build = rq-func_rsp.cfg_rsp.fw_build;
-   major = LOBYTE(rq-func_rsp.cfg_rsp.fw_release);
-   minor = HIBYTE(rq-func_rsp.cfg_rsp.fw_release);
+   fw_release = le16_to_cpu(
+   rq-func_rsp.cfg_rsp.fw_release);
+   major = LOBYTE(fw_release);
+   minor = HIBYTE(fw_release);
a-fw_version += (major  16) + (minor  24);
} else {
esas2r_hdebug(FAILED);
-- 
1.8.3.1

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


[PATCH 3/4] esas2r: Remove superfluous mask of pcie_cap_reg

2013-10-01 Thread Bradley Grove
Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 8278819..b9750e2 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -807,7 +807,7 @@ static void esas2r_init_pci_cfg_space(struct esas2r_adapter 
*a)
int pcie_cap_reg;
 
pcie_cap_reg = pci_find_capability(a-pcid, PCI_CAP_ID_EXP);
-   if (0x  pcie_cap_reg) {
+   if (pcie_cap_reg) {
u16 devcontrol;
 
pci_read_config_word(a-pcid, pcie_cap_reg + PCI_EXP_DEVCTL,
-- 
1.8.3.1

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


[PATCH 4/4] esas2r: Cleanup snprinf formatting of firmware version

2013-10-01 Thread Bradley Grove
Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_vda.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_vda.c b/drivers/scsi/esas2r/esas2r_vda.c
index 27e9721..30028e5 100644
--- a/drivers/scsi/esas2r/esas2r_vda.c
+++ b/drivers/scsi/esas2r/esas2r_vda.c
@@ -310,9 +310,9 @@ static void esas2r_complete_vda_ioctl(struct esas2r_adapter 
*a,
le32_to_cpu(rsp-vda_version);
cfg-data.init.fw_build = rsp-fw_build;
 
-   snprintf(buf, sizeof(buf), %1d.%02d,
-   (int)LOBYTE(le16_to_cpu(rsp-fw_release)),
-   (int)HIBYTE(le16_to_cpu(rsp-fw_release)));
+   snprintf(buf, sizeof(buf), %1.1u.%2.2u,
+(int)LOBYTE(le16_to_cpu(rsp-fw_release)),
+(int)HIBYTE(le16_to_cpu(rsp-fw_release)));
 
memcpy(cfg-data.init.fw_release, buf,
   sizeof(cfg-data.init.fw_release));
-- 
1.8.3.1

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


Re: [PATCH] scsi: esas2r: fix potential format string flaw

2013-09-11 Thread Bradley Grove

On 09/11/2013 12:38 AM, Kees Cook wrote:

This makes sure format strings cannot leak into the printk call via the
constructed buffer.

Signed-off-by: Kees Cook keesc...@chromium.org
---


Acked-by: Bradley Grove bgr...@attotech.com

Brad


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


[PATCH V2 6/7] SCSI: esas2r: coccinelle - Replace memcpy with struct assignment

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
index 45e353f..2ec3c23 100644
--- a/drivers/scsi/esas2r/esas2r_flash.c
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -1360,7 +1360,7 @@ void esas2r_nvram_set_defaults(struct esas2r_adapter *a)
u32 time = jiffies_to_msecs(jiffies);
 
esas2r_lock_clear_flags(a-flags, AF_NVR_VALID);
-   memcpy(n, default_sas_nvram, sizeof(struct esas2r_sas_nvram));
+   *n = default_sas_nvram;
n-sas_addr[3] |= 0x0F;
n-sas_addr[4] = HIBYTE(LOWORD(time));
n-sas_addr[5] = LOBYTE(LOWORD(time));
@@ -1378,7 +1378,7 @@ void esas2r_nvram_get_defaults(struct esas2r_adapter *a,
 * address out first.
 */
memcpy(sas_addr[0], a-nvram-sas_addr, 8);
-   memcpy(nvram, default_sas_nvram, sizeof(struct esas2r_sas_nvram));
+   *nvram = default_sas_nvram;
memcpy(nvram-sas_addr[0], sas_addr[0], 8);
 }
 
-- 
1.8.1.4

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


[PATCH V2 7/7] SCSI: esas2r: Remove null test for stack allocated fw_coredump_buffer

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 9aaad0d..da1869d 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -1551,8 +1551,7 @@ void esas2r_reset_chip(struct esas2r_adapter *a)
 * to not overwrite a previous crash that was saved.
 */
if ((a-flags2  AF2_COREDUMP_AVAIL)
-!(a-flags2  AF2_COREDUMP_SAVED)
-a-fw_coredump_buff) {
+!(a-flags2  AF2_COREDUMP_SAVED)) {
esas2r_read_mem_block(a,
  a-fw_coredump_buff,
  MW_DATA_ADDR_SRAM + 0x8,
-- 
1.8.1.4

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


[PATCH V2 1/7] SCSI: esas2r: smatch - Use biwise rather than logical AND for checking if any bit set

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 3a798e7..78b18c1 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -808,7 +808,7 @@ static void esas2r_init_pci_cfg_space(struct esas2r_adapter 
*a)
int pcie_cap_reg;
 
pcie_cap_reg = pci_find_capability(a-pcid, PCI_CAP_ID_EXP);
-   if (0x  pcie_cap_reg) {
+   if (0x  pcie_cap_reg) {
u16 devcontrol;
 
pci_read_config_word(a-pcid, pcie_cap_reg + PCI_EXP_DEVCTL,
-- 
1.8.1.4

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


[PATCH V2 0/7] SCSI: esas2r: Static check fixes

2013-09-05 Thread Bradley Grove
This series of patches fixes errors detected by smatch and coccinelle.

V2 adds an additional fix, removing a null check on a stack allocated
array.  The test was needed in older versions of the driver when the
buffer was allocated on the heap.   

Bradley Grove (7):
  SCSI: esas2r: smatch - Use biwise rather than logical AND for checking
if any bit set
  SCSI: esas2r: smatch - Fix dereference that occurs prior to check
  SCSI: esas2r: smatch - Fix dereference that occurs prior to check
  SCSI: esas2r: smatch - Fix overrun due to sprintf appending NULL
  SCSI: esas2r: smatch - Remove test for impossible condition (uint8 
255)
  SCSI: esas2r: coccinelle - Replace memcpy with struct assignment
  SCSI: esas2r: Remove null test for stack allocated fw_coredump_buffer

 drivers/scsi/esas2r/esas2r_flash.c | 11 ---
 drivers/scsi/esas2r/esas2r_init.c  |  8 
 drivers/scsi/esas2r/esas2r_ioctl.c |  2 +-
 drivers/scsi/esas2r/esas2r_vda.c   |  7 +--
 4 files changed, 18 insertions(+), 10 deletions(-)

-- 
1.8.1.4

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


[PATCH V2 2/7] SCSI: esas2r: smatch - Fix dereference that occurs prior to check

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 78b18c1..9aaad0d 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -665,7 +665,7 @@ void esas2r_kill_adapter(int i)
 
 int esas2r_cleanup(struct Scsi_Host *host)
 {
-   struct esas2r_adapter *a = (struct esas2r_adapter *)host-hostdata;
+   struct esas2r_adapter *a;
int index;
 
if (host == NULL) {
@@ -678,6 +678,7 @@ int esas2r_cleanup(struct Scsi_Host *host)
}
 
esas2r_debug(esas2r_cleanup called for host %p, host);
+   a = (struct esas2r_adapter *)host-hostdata;
index = a-index;
esas2r_kill_adapter(index);
return index;
-- 
1.8.1.4

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


[PATCH V2 4/7] SCSI: esas2r: smatch - Fix overrun due to sprintf appending NULL

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_vda.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_vda.c b/drivers/scsi/esas2r/esas2r_vda.c
index f8ec6d6..fd13928 100644
--- a/drivers/scsi/esas2r/esas2r_vda.c
+++ b/drivers/scsi/esas2r/esas2r_vda.c
@@ -302,6 +302,7 @@ static void esas2r_complete_vda_ioctl(struct esas2r_adapter 
*a,
if (vi-cmd.cfg.cfg_func == VDA_CFG_GET_INIT) {
struct atto_ioctl_vda_cfg_cmd *cfg = vi-cmd.cfg;
struct atto_vda_cfg_rsp *rsp = rq-func_rsp.cfg_rsp;
+   char buf[sizeof(cfg-data.init.fw_release) + 1];
 
cfg-data_length =
cpu_to_le32(sizeof(struct atto_vda_cfg_init));
@@ -309,11 +310,13 @@ static void esas2r_complete_vda_ioctl(struct 
esas2r_adapter *a,
le32_to_cpu(rsp-vda_version);
cfg-data.init.fw_build = rsp-fw_build;
 
-   sprintf((char *)cfg-data.init.fw_release,
-   %1d.%02d,
+   snprintf(buf, sizeof(buf), %1d.%02d,
(int)LOBYTE(le16_to_cpu(rsp-fw_release)),
(int)HIBYTE(le16_to_cpu(rsp-fw_release)));
 
+   memcpy(cfg-data.init.fw_release, buf,
+  sizeof(cfg-data.init.fw_release));
+
if (LOWORD(LOBYTE(cfg-data.init.fw_build)) == 'A')
cfg-data.init.fw_version =
cfg-data.init.fw_build;
-- 
1.8.1.4

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


[PATCH V2 5/7] SCSI: esas2r: smatch - Remove test for impossible condition (uint8 255)

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
index f3d0cb8..e5b0902 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -415,7 +415,7 @@ static int csmi_ioctl_callback(struct esas2r_adapter *a,
lun = tm-lun;
}
 
-   if (path  0 || tid  ESAS2R_MAX_ID) {
+   if (path  0) {
rq-func_rsp.ioctl_rsp.csmi.csmi_status = cpu_to_le32(
CSMI_STS_INV_PARAM);
return false;
-- 
1.8.1.4

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


[PATCH V2 3/7] SCSI: esas2r: smatch - Fix dereference that occurs prior to check

2013-09-05 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
index 8582929..45e353f 100644
--- a/drivers/scsi/esas2r/esas2r_flash.c
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -860,8 +860,13 @@ bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
return false;
}
 
+   if (fsc-command = cmdcnt) {
+   fs-status = ATTO_STS_INV_FUNC;
+   return false;
+   }
+
func = cmd_to_fls_func[fsc-command];
-   if (fsc-command = cmdcnt || func == 0xFF) {
+   if (func == 0xFF) {
fs-status = ATTO_STS_INV_FUNC;
return false;
}
-- 
1.8.1.4

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


ATTO 6G SAS/SATA HBA Driver

2013-09-03 Thread Bradley Grove


James,

Now that we are finishing up development for our esas2r driver, we are 
planning to start work on a kernel driver for our PM8001 based 6G 
SAS/SATA HBA product.  We have some questions about the best way to proceed.


While we haven't done thorough testing, our hardware appears to work 
with the existing PM8001 kernel driver.   The problem is that the 
existing kernel driver doesn't support all the features of the hardware 
or match the feature set of the current closed source driver.   For 
example, our closed source driver supports SES emulation over I2C and 
SGPIO.  Our closed source driver also has custom PHY settings to support 
longer cable lengths.   We also have a set of propriety management tools 
we'd like to work with the open source driver, though it looks like the 
PM8001's sysfs interface provides most of the functionality we need.


What are our options for supporting these features?  I see that Adaptec 
had an out-of-tree driver for their PM8001 card that supports additional 
features.   We'd prefer to have a kernel driver that fully supports our 
hardware, either based on the existing PM8001 driver or our closed 
source code base.   Is that possible?


--
Bradley Grove
System Software Engineer
ATTO Technology, Inc.
Phone:  +1.716.691.1999 ext. 144
Fax +1.716.691.9353
Powering the World's Networks  Storage
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/6] SCSI: esas2r: smatch - Fix dereference that occurs prior to check

2013-08-29 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 78b18c1..9aaad0d 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -665,7 +665,7 @@ void esas2r_kill_adapter(int i)
 
 int esas2r_cleanup(struct Scsi_Host *host)
 {
-   struct esas2r_adapter *a = (struct esas2r_adapter *)host-hostdata;
+   struct esas2r_adapter *a;
int index;
 
if (host == NULL) {
@@ -678,6 +678,7 @@ int esas2r_cleanup(struct Scsi_Host *host)
}
 
esas2r_debug(esas2r_cleanup called for host %p, host);
+   a = (struct esas2r_adapter *)host-hostdata;
index = a-index;
esas2r_kill_adapter(index);
return index;
-- 
1.8.1.4

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


[PATCH 3/6] SCSI: esas2r: smatch - Fix dereference that occurs prior to check

2013-08-29 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
index 8582929..45e353f 100644
--- a/drivers/scsi/esas2r/esas2r_flash.c
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -860,8 +860,13 @@ bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
return false;
}
 
+   if (fsc-command = cmdcnt) {
+   fs-status = ATTO_STS_INV_FUNC;
+   return false;
+   }
+
func = cmd_to_fls_func[fsc-command];
-   if (fsc-command = cmdcnt || func == 0xFF) {
+   if (func == 0xFF) {
fs-status = ATTO_STS_INV_FUNC;
return false;
}
-- 
1.8.1.4

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


[PATCH 4/6] SCSI: esas2r: smatch - Fix overrun due to sprintf appending NULL

2013-08-29 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_vda.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_vda.c b/drivers/scsi/esas2r/esas2r_vda.c
index f8ec6d6..fd13928 100644
--- a/drivers/scsi/esas2r/esas2r_vda.c
+++ b/drivers/scsi/esas2r/esas2r_vda.c
@@ -302,6 +302,7 @@ static void esas2r_complete_vda_ioctl(struct esas2r_adapter 
*a,
if (vi-cmd.cfg.cfg_func == VDA_CFG_GET_INIT) {
struct atto_ioctl_vda_cfg_cmd *cfg = vi-cmd.cfg;
struct atto_vda_cfg_rsp *rsp = rq-func_rsp.cfg_rsp;
+   char buf[sizeof(cfg-data.init.fw_release) + 1];
 
cfg-data_length =
cpu_to_le32(sizeof(struct atto_vda_cfg_init));
@@ -309,11 +310,13 @@ static void esas2r_complete_vda_ioctl(struct 
esas2r_adapter *a,
le32_to_cpu(rsp-vda_version);
cfg-data.init.fw_build = rsp-fw_build;
 
-   sprintf((char *)cfg-data.init.fw_release,
-   %1d.%02d,
+   snprintf(buf, sizeof(buf), %1d.%02d,
(int)LOBYTE(le16_to_cpu(rsp-fw_release)),
(int)HIBYTE(le16_to_cpu(rsp-fw_release)));
 
+   memcpy(cfg-data.init.fw_release, buf,
+  sizeof(cfg-data.init.fw_release));
+
if (LOWORD(LOBYTE(cfg-data.init.fw_build)) == 'A')
cfg-data.init.fw_version =
cfg-data.init.fw_build;
-- 
1.8.1.4

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


[PATCH 5/6] SCSI: esas2r: smatch - Remove test for impossible condition (uint8 255)

2013-08-29 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
index f3d0cb8..e5b0902 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -415,7 +415,7 @@ static int csmi_ioctl_callback(struct esas2r_adapter *a,
lun = tm-lun;
}
 
-   if (path  0 || tid  ESAS2R_MAX_ID) {
+   if (path  0) {
rq-func_rsp.ioctl_rsp.csmi.csmi_status = cpu_to_le32(
CSMI_STS_INV_PARAM);
return false;
-- 
1.8.1.4

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


[PATCH 0/6] SCSI: esas2r: Static check fixes

2013-08-29 Thread Bradley Grove
This series of patches fix errors detected by smatch and coccinelle.

Bradley Grove (6):
  SCSI: esas2r: smatch - Use biwise rather than logical AND for checking
if any bit set
  SCSI: esas2r: smatch - Fix dereference that occurs prior to check
  SCSI: esas2r: smatch - Fix dereference that occurs prior to check
  SCSI: esas2r: smatch - Fix overrun due to sprintf appending NULL
  SCSI: esas2r: smatch - Remove test for impossible condition (uint8 
255)
  SCSI: esas2r: coccinelle - Replace memcpy with struct assignment

 drivers/scsi/esas2r/esas2r_flash.c | 11 ---
 drivers/scsi/esas2r/esas2r_init.c  |  5 +++--
 drivers/scsi/esas2r/esas2r_ioctl.c |  2 +-
 drivers/scsi/esas2r/esas2r_vda.c   |  7 +--
 4 files changed, 17 insertions(+), 8 deletions(-)

-- 
1.8.1.4

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


[PATCH 6/6] SCSI: esas2r: coccinelle - Replace memcpy with struct assignment

2013-08-29 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
index 45e353f..2ec3c23 100644
--- a/drivers/scsi/esas2r/esas2r_flash.c
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -1360,7 +1360,7 @@ void esas2r_nvram_set_defaults(struct esas2r_adapter *a)
u32 time = jiffies_to_msecs(jiffies);
 
esas2r_lock_clear_flags(a-flags, AF_NVR_VALID);
-   memcpy(n, default_sas_nvram, sizeof(struct esas2r_sas_nvram));
+   *n = default_sas_nvram;
n-sas_addr[3] |= 0x0F;
n-sas_addr[4] = HIBYTE(LOWORD(time));
n-sas_addr[5] = LOBYTE(LOWORD(time));
@@ -1378,7 +1378,7 @@ void esas2r_nvram_get_defaults(struct esas2r_adapter *a,
 * address out first.
 */
memcpy(sas_addr[0], a-nvram-sas_addr, 8);
-   memcpy(nvram, default_sas_nvram, sizeof(struct esas2r_sas_nvram));
+   *nvram = default_sas_nvram;
memcpy(nvram-sas_addr[0], sas_addr[0], 8);
 }
 
-- 
1.8.1.4

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


[PATCH 1/6] SCSI: esas2r: smatch - Use biwise rather than logical AND for checking if any bit set

2013-08-29 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 3a798e7..78b18c1 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -808,7 +808,7 @@ static void esas2r_init_pci_cfg_space(struct esas2r_adapter 
*a)
int pcie_cap_reg;
 
pcie_cap_reg = pci_find_capability(a-pcid, PCI_CAP_ID_EXP);
-   if (0x  pcie_cap_reg) {
+   if (0x  pcie_cap_reg) {
u16 devcontrol;
 
pci_read_config_word(a-pcid, pcie_cap_reg + PCI_EXP_DEVCTL,
-- 
1.8.1.4

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


[PATCH v4 03/10] SCSI: esas2r: Add initialization functions

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 1773 +
 1 file changed, 1773 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
new file mode 100644
index 000..3a798e7
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -0,0 +1,1773 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_init.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)mpt3sas/mpt3sas_trigger_diag.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+static bool esas2r_initmem_alloc(struct esas2r_adapter *a,
+struct esas2r_mem_desc *mem_desc,
+u32 align)
+{
+   mem_desc-esas2r_param = mem_desc-size + align;
+   mem_desc-virt_addr = NULL;
+   mem_desc-phys_addr = 0;
+   mem_desc-esas2r_data = dma_alloc_coherent(a-pcid-dev,
+  (size_t)mem_desc-
+  esas2r_param,
+  (dma_addr_t *)mem_desc-
+  phys_addr,
+  GFP_KERNEL);
+
+   if (mem_desc-esas2r_data == NULL) {
+   esas2r_log(ESAS2R_LOG_CRIT,
+  failed to allocate %lu bytes of consistent memory!,
+  (long
+   unsigned
+   int)mem_desc-esas2r_param);
+   return false;
+   }
+
+   mem_desc-virt_addr = PTR_ALIGN(mem_desc-esas2r_data, align);
+   mem_desc-phys_addr = ALIGN(mem_desc-phys_addr, align);
+   memset(mem_desc-virt_addr, 0, mem_desc-size);
+   return true;
+}
+
+static void esas2r_initmem_free(struct esas2r_adapter *a,
+   struct esas2r_mem_desc *mem_desc)
+{
+   if (mem_desc-virt_addr == NULL)
+   return;
+
+   /*
+* Careful!  phys_addr and virt_addr may have been adjusted from the
+* original allocation in order to return the desired alignment.  That
+* means we have to use the original address (in esas2r_data) and size
+* (esas2r_param) and calculate the original physical address based on
+* the difference between the requested and actual allocation size.
+*/
+   if (mem_desc-phys_addr) {
+   int unalign = ((u8 *)mem_desc-virt_addr) -
+ ((u8 *)mem_desc-esas2r_data);
+
+   dma_free_coherent(a-pcid-dev,
+ (size_t)mem_desc-esas2r_param,
+ mem_desc-esas2r_data,
+ (dma_addr_t)(mem_desc-phys_addr - unalign));
+   } else {
+   kfree(mem_desc-esas2r_data);
+   }
+
+   mem_desc

[PATCH v4 02/10] SCSI: esas2r: Add main file

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_main.c | 2032 +
 1 file changed, 2032 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
new file mode 100644
index 000..4abf127
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -0,0 +1,2032 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_main.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+MODULE_DESCRIPTION(ESAS2R_DRVR_NAME :  ESAS2R_LONGNAME  driver);
+MODULE_AUTHOR(ATTO Technology, Inc.);
+MODULE_LICENSE(GPL);
+MODULE_VERSION(ESAS2R_VERSION_STR);
+
+/* global definitions */
+
+static int found_adapters;
+struct esas2r_adapter *esas2r_adapters[MAX_ADAPTERS];
+
+#define ESAS2R_VDA_EVENT_PORT1   54414
+#define ESAS2R_VDA_EVENT_PORT2   54415
+#define ESAS2R_VDA_EVENT_SOCK_COUNT  2
+
+static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj)
+{
+   struct device *dev = container_of(kobj, struct device, kobj);
+   struct Scsi_Host *host = class_to_shost(dev);
+
+   return (struct esas2r_adapter *)host-hostdata;
+}
+
+static ssize_t read_fw(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr,
+  char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_fw(a, buf, off, count);
+}
+
+static ssize_t write_fw(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_write_fw(a, buf, off, count);
+}
+
+static ssize_t read_fs(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr,
+  char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_fs(a, buf, off, count);
+}
+
+static ssize_t write_fs(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+   int length = min(sizeof(struct esas2r_ioctl_fs), count);
+   int result = 0;
+
+   result = esas2r_write_fs(a, buf, off, count);
+
+   if (result  0)
+   result = 0;
+
+   return length;
+}
+
+static ssize_t read_vda(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_vda(a, buf, off, count

[PATCH v4 00/10] SCSI: esas2r: ATTO Technology ExpressSAS 6G SAS/SATA RAID Adapter Driver

2013-08-23 Thread Bradley Grove

This is a new driver for ATTO Technology's ExpressSAS series of hardware RAID 
adapters.  It supports the following adapters:

- ExpressSAS R60F
- ExpressSAS R680
- ExpressSAS R608
- ExpressSAS R644

This patch is split into ten parts, all of which need to be applied to build 
the driver.

Changes Since V3:
- Addressed some warnings reported by checkpatch script, mostly whitespace

Changes since V2:

- Fix spurious ioctl error logging and memory corruption occuring with
non-IO VDA requests
- Use kernel's schedule_timeout_interruptable() rather than our own own 
stall function
- Removed a UDP socket based interface used by our closed source configuration 
tool

Changes since V1:

- We now use the kernel's list structs and alignment macros rather than our own 
implementations
- Fix to PCIe address size declaration when compiling on 32-bit architectures
- Use memcpy() instead opf memmove() where appropriate
- Fixes for big-endian architectures
- Removed unneeded MSI configuration code
- Simplified memory allocation during init
- Code formatting cleanup

Bradley Grove (10):
  SCSI: esas2r: Add main header file
  SCSI: esas2r: Add main file
  SCSI: esas2r: Add initialization functions
  SCSI: esas2r: Add device discovery and logging functions
  SCSI: esas2r: Add interrupt and IO functions
  SCSI: esas2r: Add flash and target database functions
  SCSI: esas2r: Add IOCTL header file
  SCSI: esas2r: Add IOCTL functions
  SCSI: esas2r: Add ATTO VDA Firmware API headers and functions.  This
API is used to control and manage the RAID adapter.
  SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

 MAINTAINERS |7 +
 drivers/scsi/Kconfig|1 +
 drivers/scsi/Makefile   |1 +
 drivers/scsi/esas2r/Kconfig |6 +
 drivers/scsi/esas2r/Makefile|5 +
 drivers/scsi/esas2r/atioctl.h   | 1254 +
 drivers/scsi/esas2r/atvda.h | 1320 ++
 drivers/scsi/esas2r/esas2r.h| 1441 
 drivers/scsi/esas2r/esas2r_disc.c   | 1190 
 drivers/scsi/esas2r/esas2r_flash.c  | 1514 +
 drivers/scsi/esas2r/esas2r_init.c   | 1773 +
 drivers/scsi/esas2r/esas2r_int.c|  941 
 drivers/scsi/esas2r/esas2r_io.c |  883 +++
 drivers/scsi/esas2r/esas2r_ioctl.c  | 2110 +++
 drivers/scsi/esas2r/esas2r_log.c|  255 +
 drivers/scsi/esas2r/esas2r_log.h|  118 ++
 drivers/scsi/esas2r/esas2r_main.c   | 2032 +
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +
 drivers/scsi/esas2r/esas2r_vda.c|  523 +
 19 files changed, 15680 insertions(+)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile
 create mode 100644 drivers/scsi/esas2r/atioctl.h
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r.h
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

-- 
1.8.1.4

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


[PATCH v4 06/10] SCSI: esas2r: Add flash and target database functions

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c  | 1514 +++
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +++
 2 files changed, 1820 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
new file mode 100644
index 000..a02fb62
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -0,0 +1,1512 @@
+
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_flash.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/* local macro defs */
+#define esas2r_nvramcalc_cksum(n) \
+   (esas2r_calc_byte_cksum((u8 *)(n), sizeof(struct esas2r_sas_nvram), \
+   SASNVR_CKSUM_SEED))
+#define esas2r_nvramcalc_xor_cksum(n)  \
+   (esas2r_calc_byte_xor_cksum((u8 *)(n), \
+   sizeof(struct esas2r_sas_nvram), 0))
+
+#define ESAS2R_FS_DRVR_VER 2
+
+static struct esas2r_sas_nvram default_sas_nvram = {
+   { 'E',  'S',  'A',  'S'  }, /* signature  */
+   SASNVR_VERSION, /* version*/
+   0,  /* checksum   */
+   31, /* max_lun_for_target */
+   SASNVR_PCILAT_MAX,  /* pci_latency*/
+   SASNVR1_BOOT_DRVR,  /* options1   */
+   SASNVR2_HEARTBEAT   | SASNVR2_SINGLE_BUS/* options2   */
+   | SASNVR2_SW_MUX_CTRL,
+   SASNVR_COAL_DIS,/* int_coalescing */
+   SASNVR_CMDTHR_NONE, /* cmd_throttle   */
+   3,  /* dev_wait_time  */
+   1,  /* dev_wait_count */
+   0,  /* spin_up_delay  */
+   0,  /* ssp_align_rate */
+   { 0x50, 0x01, 0x08, 0x60,   /* sas_addr   */
+ 0x00, 0x00, 0x00, 0x00 },
+   { SASNVR_SPEED_AUTO },  /* phy_speed  */
+   { SASNVR_MUX_DISABLED },/* SAS multiplexing   */
+   { 0 },  /* phy_flags  */
+   SASNVR_SORT_SAS_ADDR,   /* sort_type  */
+   3,  /* dpm_reqcmd_lmt */
+   3,  /* dpm_stndby_time*/
+   0,  /* dpm_active_time*/
+   { 0

[PATCH v4 05/10] SCSI: esas2r: Add interrupt and IO functions

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_int.c | 941 +++
 drivers/scsi/esas2r/esas2r_io.c  | 883 
 2 files changed, 1824 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c

diff --git a/drivers/scsi/esas2r/esas2r_int.c b/drivers/scsi/esas2r/esas2r_int.c
new file mode 100644
index 000..c2d4ff5
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_int.c
@@ -0,0 +1,941 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_int.c
+ *  esas2r interrupt handling
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Local function prototypes */
+static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell);
+static void esas2r_get_outbound_responses(struct esas2r_adapter *a);
+static void esas2r_process_bus_reset(struct esas2r_adapter *a);
+
+/*
+ * Poll the adapter for interrupts and service them.
+ * This function handles both legacy interrupts and MSI.
+ */
+void esas2r_polled_interrupt(struct esas2r_adapter *a)
+{
+   u32 intstat;
+   u32 doorbell;
+
+   esas2r_disable_chip_interrupts(a);
+
+   intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
+
+   if (intstat  MU_INTSTAT_POST_OUT) {
+   /* clear the interrupt */
+
+   esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT,
+   MU_OLIS_INT);
+   esas2r_flush_register_dword(a, MU_OUT_LIST_INT_STAT);
+
+   esas2r_get_outbound_responses(a);
+   }
+
+   if (intstat  MU_INTSTAT_DRBL) {
+   doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
+   if (doorbell != 0)
+   esas2r_doorbell_interrupt(a, doorbell);
+   }
+
+   esas2r_enable_chip_interrupts(a);
+
+   if (atomic_read(a-disable_cnt) == 0)
+   esas2r_do_deferred_processes(a);
+}
+
+/*
+ * Legacy and MSI interrupt handlers.  Note that the legacy interrupt handler
+ * schedules a TASKLET to process events, whereas the MSI handler just
+ * processes interrupt events directly.
+ */
+irqreturn_t esas2r_interrupt(int irq, void *dev_id)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)dev_id;
+
+   if (!esas2r_adapter_interrupt_pending(a))
+   return IRQ_NONE;
+
+   esas2r_lock_set_flags(a-flags2, AF2_INT_PENDING);
+   esas2r_schedule_tasklet(a);
+
+   return IRQ_HANDLED;
+}
+
+void esas2r_adapter_interrupt(struct esas2r_adapter *a)
+{
+   u32 doorbell;
+
+   if (likely(a-int_stat  MU_INTSTAT_POST_OUT)) {
+   /* clear the interrupt */
+   esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT

[PATCH v4 01/10] SCSI: esas2r: Add main header file

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r.h | 1441 ++
 1 file changed, 1441 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r.h

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
new file mode 100644
index 000..0838e26
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -0,0 +1,1441 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r.h
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include linux/kernel.h
+#include linux/delay.h
+#include linux/pci.h
+#include linux/proc_fs.h
+#include linux/workqueue.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/vmalloc.h
+#include scsi/scsi.h
+#include scsi/scsi_host.h
+#include scsi/scsi_cmnd.h
+#include scsi/scsi_device.h
+#include scsi/scsi_eh.h
+#include scsi/scsi_tcq.h
+
+#include esas2r_log.h
+#include atioctl.h
+#include atvda.h
+
+#ifndef ESAS2R_H
+#define ESAS2R_H
+
+/* Global Variables */
+extern struct esas2r_adapter *esas2r_adapters[];
+extern u8 *esas2r_buffered_ioctl;
+extern dma_addr_t esas2r_buffered_ioctl_addr;
+extern u32 esas2r_buffered_ioctl_size;
+extern struct pci_dev *esas2r_buffered_ioctl_pcid;
+#define SGL_PG_SZ_MIN   64
+#define SGL_PG_SZ_MAX   1024
+extern int sgl_page_size;
+#define NUM_SGL_MIN 8
+#define NUM_SGL_MAX 2048
+extern int num_sg_lists;
+#define NUM_REQ_MIN 4
+#define NUM_REQ_MAX 256
+extern int num_requests;
+#define NUM_AE_MIN  2
+#define NUM_AE_MAX  8
+extern int num_ae_requests;
+extern int cmd_per_lun;
+extern int can_queue;
+extern int esas2r_max_sectors;
+extern int sg_tablesize;
+extern int interrupt_mode;
+extern int num_io_requests;
+
+/* Macro defintions */
+#define ESAS2R_MAX_ID255
+#define MAX_ADAPTERS 32
+#define ESAS2R_DRVR_NAME esas2r
+#define ESAS2R_LONGNAME  ATTO ExpressSAS 6GB RAID Adapter
+#define ESAS2R_MAX_DEVICES 32
+#define ATTONODE_NAME ATTONode
+#define ESAS2R_MAJOR_REV   1
+#define ESAS2R_MINOR_REV   00
+#define ESAS2R_VERSION_STR DEFINED_NUM_TO_STR(ESAS2R_MAJOR_REV) . \
+   DEFINED_NUM_TO_STR(ESAS2R_MINOR_REV)
+#define ESAS2R_COPYRIGHT_YEARS 2001-2013
+#define ESAS2R_DEFAULT_SGL_PAGE_SIZE 384
+#define ESAS2R_DEFAULT_CMD_PER_LUN   64
+#define ESAS2R_DEFAULT_NUM_SG_LISTS 1024
+#define DEFINED_NUM_TO_STR(num) NUM_TO_STR(num)
+#define NUM_TO_STR(num) #num
+
+#define ESAS2R_SGL_ALIGN16
+#define ESAS2R_LIST_ALIGN   16
+#define ESAS2R_LIST_EXTRA   ESAS2R_NUM_EXTRA
+#define ESAS2R_DATA_BUF_LEN 256
+#define ESAS2R_DEFAULT_TMO  5000
+#define ESAS2R_DISC_BUF_LEN 512
+#define ESAS2R_FWCOREDUMP_SZ0x8
+#define ESAS2R_NUM_PHYS 8
+#define ESAS2R_TARG_ID_INV  0x
+#define ESAS2R_INT_STS_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_ENB_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_DIS_MASK 0

[PATCH v4 07/10] SCSI: esas2r: Add IOCTL header file

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atioctl.h | 1254 +
 1 file changed, 1254 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atioctl.h

diff --git a/drivers/scsi/esas2r/atioctl.h b/drivers/scsi/esas2r/atioctl.h
new file mode 100644
index 000..4aca3d5
--- /dev/null
+++ b/drivers/scsi/esas2r/atioctl.h
@@ -0,0 +1,1254 @@
+/*  linux/drivers/scsi/esas2r/atioctl.h
+ *  ATTO IOCTL Handling
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include atvda.h
+
+#ifndef ATIOCTL_H
+#define ATIOCTL_H
+
+#define EXPRESS_IOCTL_SIGNATUREExpress
+#define EXPRESS_IOCTL_SIGNATURE_SIZE   8
+
+/* structure definitions for IOCTls */
+
+struct __packed atto_express_ioctl_header {
+   u8 signature[EXPRESS_IOCTL_SIGNATURE_SIZE];
+   u8 return_code;
+
+#define IOCTL_SUCCESS   0
+#define IOCTL_ERR_INVCMD  101
+#define IOCTL_INIT_FAILED 102
+#define IOCTL_NOT_IMPLEMENTED 103
+#define IOCTL_BAD_CHANNEL 104
+#define IOCTL_TARGET_OVERRUN  105
+#define IOCTL_TARGET_NOT_ENABLED  106
+#define IOCTL_BAD_FLASH_IMGTYPE   107
+#define IOCTL_OUT_OF_RESOURCES108
+#define IOCTL_GENERAL_ERROR   109
+#define IOCTL_INVALID_PARAM   110
+
+   u8 channel;
+   u8 retries;
+   u8 pad[5];
+};
+
+/*
+ * NOTE - if channel == 0xFF, the request is
+ * handled on the adapter it came in on.
+ */
+#define MAX_NODE_NAMES  256
+
+struct __packed atto_firmware_rw_request {
+   u8 function;
+   #define FUNC_FW_DOWNLOAD0x09
+   #define FUNC_FW_UPLOAD  0x12
+
+   u8 img_type;
+   #define FW_IMG_FW   0x01
+   #define FW_IMG_BIOS 0x02
+   #define FW_IMG_NVR  0x03
+   #define FW_IMG_RAW  0x04
+   #define FW_IMG_FM_API   0x05
+   #define FW_IMG_FS_API   0x06
+
+   u8 pad[2];
+   u32 img_offset;
+   u32 img_size;
+   u8 image[0x8];
+};
+
+struct __packed atto_param_rw_request {
+   u16 code;
+   char data_buffer[512];
+};
+
+#define MAX_CHANNEL 256
+
+struct __packed atto_channel_list {
+   u32 num_channels;
+   u8 channel[MAX_CHANNEL];
+};
+
+struct __packed atto_channel_info {
+   u8 major_rev;
+   u8 minor_rev;
+   u8 IRQ;
+   u8 revision_id;
+   u8 pci_bus;
+   u8 pci_dev_func;
+   u8 core_rev;
+   u8 host_no;
+   u16 device_id;
+   u16 vendor_id;
+   u16 ven_dev_id;
+   u8 pad[3];
+   u32 hbaapi_rev;
+};
+
+/*
+ * CSMI control codes
+ * class independent
+ */
+#define CSMI_CC_GET_DRVR_INFO1
+#define CSMI_CC_GET_CNTLR_CFG2
+#define CSMI_CC_GET_CNTLR_STS3
+#define CSMI_CC_FW_DOWNLOAD  4
+
+/* RAID class */
+#define CSMI_CC_GET_RAID_INFO10

[PATCH v4 04/10] SCSI: esas2r: Add device discovery and logging functions

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_disc.c | 1190 +
 drivers/scsi/esas2r/esas2r_log.c  |  255 
 drivers/scsi/esas2r/esas2r_log.h  |  118 
 3 files changed, 1563 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h

diff --git a/drivers/scsi/esas2r/esas2r_disc.c 
b/drivers/scsi/esas2r/esas2r_disc.c
new file mode 100644
index 000..319ba9a
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_disc.c
@@ -0,0 +1,1189 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_disc.c
+ *  esas2r device discovery routines
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Miscellaneous internal discovery routines */
+static void esas2r_disc_abort(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_continue(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static void esas2r_disc_fix_curr_requests(struct esas2r_adapter *a);
+static u32 esas2r_disc_get_phys_addr(struct esas2r_sg_context *sgc, u64 *addr);
+static bool esas2r_disc_start_request(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+
+/* Internal discovery routines that process the states */
+static bool esas2r_disc_block_dev_scan(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static void esas2r_disc_block_dev_scan_cb(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_dev_add(struct esas2r_adapter *a,
+   struct esas2r_request *rq);
+static bool esas2r_disc_dev_remove(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static bool esas2r_disc_part_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_part_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_addr(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_addr_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_raid_grp_info(struct esas2r_adapter

[PATCH v4 08/10] SCSI: esas2r: Add IOCTL functions

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2110 
 1 file changed, 2110 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
new file mode 100644
index 000..f3d0cb8
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -0,0 +1,2110 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_ioctl.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/*
+ * Buffered ioctl handlers.  A buffered ioctl is one which requires that we
+ * allocate a DMA-able memory area to communicate with the firmware.  In
+ * order to prevent continually allocating and freeing consistent memory,
+ * we will allocate a global buffer the first time we need it and re-use
+ * it for subsequent ioctl calls that require it.
+ */
+
+u8 *esas2r_buffered_ioctl;
+dma_addr_t esas2r_buffered_ioctl_addr;
+u32 esas2r_buffered_ioctl_size;
+struct pci_dev *esas2r_buffered_ioctl_pcid;
+
+static DEFINE_SEMAPHORE(buffered_ioctl_semaphore);
+typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *,
+  struct esas2r_request *,
+  struct esas2r_sg_context *,
+  void *);
+typedef void (*BUFFERED_IOCTL_DONE_CALLBACK)(struct esas2r_adapter *,
+struct esas2r_request *, void *);
+
+struct esas2r_buffered_ioctl {
+   struct esas2r_adapter *a;
+   void *ioctl;
+   u32 length;
+   u32 control_code;
+   u32 offset;
+   BUFFERED_IOCTL_CALLBACK
+   callback;
+   void *context;
+   BUFFERED_IOCTL_DONE_CALLBACK
+   done_callback;
+   void *done_context;
+
+};
+
+static void complete_fm_api_req(struct esas2r_adapter *a,
+   struct esas2r_request *rq)
+{
+   a-fm_api_command_done = 1;
+   wake_up_interruptible(a-fm_api_waiter);
+}
+
+/* Callbacks for building scatter/gather lists for FM API requests */
+static u32 get_physaddr_fm_api(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.phys + offset;
+   return a-firmware.orig_len - offset;
+}
+
+static u32 get_physaddr_fm_api_header(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.header_buff_phys + offset;
+   return sizeof(struct esas2r_flash_img) - offset;
+}
+
+/* Handle EXPRESS_IOCTL_RW_FIRMWARE ioctl with img_type = FW_IMG_FM_API. */
+static void do_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi

[PATCH v4 10/10] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 MAINTAINERS  | 7 +++
 drivers/scsi/Kconfig | 1 +
 drivers/scsi/Makefile| 1 +
 drivers/scsi/esas2r/Kconfig  | 6 ++
 drivers/scsi/esas2r/Makefile | 5 +
 5 files changed, 20 insertions(+)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index 7cacc88..0a85613 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1547,6 +1547,13 @@ W:   http://atmelwlandriver.sourceforge.net/
 S: Maintained
 F: drivers/net/wireless/atmel*
 
+ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
+M:  Bradley Grove linuxdriv...@attotech.com
+L:  linux-scsi@vger.kernel.org
+W:  http://www.attotech.com
+S:  Supported
+F:  drivers/scsi/esas2r
+
 AUDIT SUBSYSTEM
 M: Al Viro v...@zeniv.linux.org.uk
 M: Eric Paris epa...@redhat.com
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 48b2918..c298b76 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -601,6 +601,7 @@ config SCSI_ARCMSR
  To compile this driver as a module, choose M here: the
  module will be called arcmsr (modprobe arcmsr).
 
+source drivers/scsi/esas2r/Kconfig
 source drivers/scsi/megaraid/Kconfig.megaraid
 source drivers/scsi/mpt2sas/Kconfig
 source drivers/scsi/mpt3sas/Kconfig
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index b607ba4..149bb6b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -141,6 +141,7 @@ obj-$(CONFIG_SCSI_CXGB3_ISCSI)  += libiscsi.o 
libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_CXGB4_ISCSI) += libiscsi.o libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_BNX2_ISCSI)  += libiscsi.o bnx2i/
 obj-$(CONFIG_BE2ISCSI) += libiscsi.o be2iscsi/
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r/
 obj-$(CONFIG_SCSI_PMCRAID) += pmcraid.o
 obj-$(CONFIG_SCSI_VIRTIO)  += virtio_scsi.o
 obj-$(CONFIG_VMWARE_PVSCSI)+= vmw_pvscsi.o
diff --git a/drivers/scsi/esas2r/Kconfig b/drivers/scsi/esas2r/Kconfig
new file mode 100644
index 000..80824f0
--- /dev/null
+++ b/drivers/scsi/esas2r/Kconfig
@@ -0,0 +1,5 @@
+config SCSI_ESAS2R
+   tristate ATTO Technology's ExpressSAS RAID adapter driver
+   depends on PCI  SCSI
+   ---help---
+ This driver supports the ATTO ExpressSAS R6xx SAS/SATA RAID 
controllers.
diff --git a/drivers/scsi/esas2r/Makefile b/drivers/scsi/esas2r/Makefile
new file mode 100644
index 000..c77160b
--- /dev/null
+++ b/drivers/scsi/esas2r/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r.o
+
+esas2r-objs := esas2r_log.o esas2r_disc.o esas2r_flash.o esas2r_init.o \
+esas2r_int.o esas2r_io.o esas2r_ioctl.o esas2r_targdb.o   \
+esas2r_vda.o esas2r_main.o
-- 
1.8.1.4

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


[PATCH v4 09/10] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. This API is used to control and manage the RAID adapter.

2013-08-23 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atvda.h  | 1320 ++
 drivers/scsi/esas2r/esas2r_vda.c |  523 +++
 2 files changed, 1843 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

diff --git a/drivers/scsi/esas2r/atvda.h b/drivers/scsi/esas2r/atvda.h
new file mode 100644
index 000..0f70c31
--- /dev/null
+++ b/drivers/scsi/esas2r/atvda.h
@@ -0,0 +1,1319 @@
+/*  linux/drivers/scsi/esas2r/atvda.h
+ *   ATTO VDA interface definitions
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+
+#ifndef ATVDA_H
+#define ATVDA_H
+
+struct __packed atto_dev_addr {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+  #define VDA_DEVADDRF_SATA   0x01
+  #define VDA_DEVADDRF_SSD0x02
+   u8 link_speed; /* VDALINKSPEED_xxx */
+   u8 pad[1];
+};
+
+/* dev_addr2 was added for 64-bit alignment */
+
+struct __packed atto_dev_addr2 {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+   u8 link_speed;
+   u8 pad[5];
+};
+
+struct __packed atto_vda_sge {
+   u32 length;
+   u64 address;
+};
+
+
+/* VDA request function codes */
+
+#define VDA_FUNC_SCSI 0x00
+#define VDA_FUNC_FLASH0x01
+#define VDA_FUNC_DIAG 0x02
+#define VDA_FUNC_AE   0x03
+#define VDA_FUNC_CLI  0x04
+#define VDA_FUNC_IOCTL0x05
+#define VDA_FUNC_CFG  0x06
+#define VDA_FUNC_MGT  0x07
+#define VDA_FUNC_GSV  0x08
+
+
+/* VDA request status values.  for host driver considerations, values for
+ * SCSI requests start at zero.  other requests may use these values as well. 
*/
+
+#define RS_SUCCESS  0x00/*! successful completion*/
+#define RS_INV_FUNC 0x01/*! invalid command function */
+#define RS_BUSY 0x02/*! insufficient resources   */
+#define RS_SEL  0x03/*! no target at target_id   */
+#define RS_NO_LUN   0x04/*! invalid LUN  */
+#define RS_TIMEOUT  0x05/*! request timeout  */
+#define RS_OVERRUN  0x06/*! data overrun */
+#define RS_UNDERRUN 0x07/*! data underrun*/
+#define RS_SCSI_ERROR   0x08/*! SCSI error occurred  */
+#define RS_ABORTED  0x0A/*! command aborted  */
+#define RS_RESID_MISM   0x0B/*! residual length incorrect*/
+#define RS_TM_FAILED0x0C/*! task management failed   */
+#define RS_RESET0x0D/*! aborted due to bus reset */
+#define RS_ERR_DMA_SG   0x0E/*! error reading SG list

Re: [PATCH v3 10/10] [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

2013-08-06 Thread Bradley Grove


James,

Do you have any comments on this last patch post?

I probably shouldn't have posted it as an RFC.  We've completed our 
internal testing of the driver, and I think it's probably ready to submit.


Brad


On 08/02/2013 12:59 PM, Bradley Grove wrote:


Signed-off-by: Bradley Grove bgr...@attotech.com
---
  MAINTAINERS  | 7 +++
  drivers/scsi/Kconfig | 1 +
  drivers/scsi/Makefile| 1 +
  drivers/scsi/esas2r/Kconfig  | 6 ++
  drivers/scsi/esas2r/Makefile | 5 +
  5 files changed, 20 insertions(+)
  create mode 100644 drivers/scsi/esas2r/Kconfig
  create mode 100644 drivers/scsi/esas2r/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index a26b10e..024bc9a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1542,6 +1542,13 @@ W:   http://atmelwlandriver.sourceforge.net/
  S:Maintained
  F:drivers/net/wireless/atmel*

+ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
+M:  Bradley Grove linuxdriv...@attotech.com
+L:  linux-scsi@vger.kernel.org
+W:  http://www.attotech.com
+S:  Supported
+F:  drivers/scsi/esas2r
+
  AUDIT SUBSYSTEM
  M:Al Viro v...@zeniv.linux.org.uk
  M:Eric Paris epa...@redhat.com
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 48b2918..c298b76 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -601,6 +601,7 @@ config SCSI_ARCMSR
  To compile this driver as a module, choose M here: the
  module will be called arcmsr (modprobe arcmsr).

+source drivers/scsi/esas2r/Kconfig
  source drivers/scsi/megaraid/Kconfig.megaraid
  source drivers/scsi/mpt2sas/Kconfig
  source drivers/scsi/mpt3sas/Kconfig
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index b607ba4..149bb6b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -141,6 +141,7 @@ obj-$(CONFIG_SCSI_CXGB3_ISCSI)  += libiscsi.o 
libiscsi_tcp.o cxgbi/
  obj-$(CONFIG_SCSI_CXGB4_ISCSI)+= libiscsi.o libiscsi_tcp.o cxgbi/
  obj-$(CONFIG_SCSI_BNX2_ISCSI) += libiscsi.o bnx2i/
  obj-$(CONFIG_BE2ISCSI)+= libiscsi.o be2iscsi/
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r/
  obj-$(CONFIG_SCSI_PMCRAID)+= pmcraid.o
  obj-$(CONFIG_SCSI_VIRTIO) += virtio_scsi.o
  obj-$(CONFIG_VMWARE_PVSCSI)   += vmw_pvscsi.o
diff --git a/drivers/scsi/esas2r/Kconfig b/drivers/scsi/esas2r/Kconfig
new file mode 100644
index 000..80824f0
--- /dev/null
+++ b/drivers/scsi/esas2r/Kconfig
@@ -0,0 +1,5 @@
+config SCSI_ESAS2R
+   tristate ATTO Technology's ExpressSAS RAID adapter driver
+   depends on PCI  SCSI
+   ---help---
+ This driver supports the ATTO ExpressSAS R6xx SAS/SATA RAID 
controllers.
diff --git a/drivers/scsi/esas2r/Makefile b/drivers/scsi/esas2r/Makefile
new file mode 100644
index 000..c77160b
--- /dev/null
+++ b/drivers/scsi/esas2r/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r.o
+
+esas2r-objs := esas2r_log.o esas2r_disc.o esas2r_flash.o esas2r_init.o \
+esas2r_int.o esas2r_io.o esas2r_ioctl.o esas2r_targdb.o   \
+esas2r_vda.o esas2r_main.o



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


[PATCH v3 00/10] [RFC] SCSI: esas2r: ATTO Technology ExpressSAS 6G SAS/SATA RAID Adapter Driver

2013-08-02 Thread Bradley Grove

This is a new driver for ATTO Technology's ExpressSAS series of hardware RAID 
adapters.  It supports the following adapters:

- ExpressSAS R60F
- ExpressSAS R680
- ExpressSAS R608
- ExpressSAS R644

This patch is split into ten parts, all of which need to be applied to build 
the driver.

Changes since V2:

- Fix spurious ioctl error logging and memory corruption occuring with
non-IO VDA requests
- Use kernel's schedule_timeout_interruptable() rather than our own own 
stall function
- Removed a UDP socket based interface used by our closed source configuration 
tool

Changes since V1:

- We now use the kernel's list structs and alignment macros rather than our own 
implementations
- Fix to PCIe address size declaration when compiling on 32-bit architectures
- Use memcpy() instead opf memmove() where appropriate
- Fixes for big-endian architectures
- Removed unneeded MSI configuration code
- Simplified memory allocation during init
- Code formatting cleanup

Bradley Grove (10):
  [RFC] SCSI: esas2r: Add main header file
  [RFC] SCSI: esas2r: Add main file
  [RFC] SCSI: esas2r: Add initialization functions
  [RFC] SCSI: esas2r: Add device discovery and logging functions
  [RFC] SCSI: esas2r: Add interrupt and IO functions
  [RFC] SCSI: esas2r: Add flash and target database functions
  [RFC] SCSI: esas2r: Add IOCTL header file
  [RFC] SCSI: esas2r: Add IOCTL functions
  [RFC] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. 
This API is used to control and manage the RAID adapter.
  [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

 MAINTAINERS |7 +
 drivers/scsi/Kconfig|1 +
 drivers/scsi/Makefile   |1 +
 drivers/scsi/esas2r/Kconfig |6 +
 drivers/scsi/esas2r/Makefile|5 +
 drivers/scsi/esas2r/atioctl.h   | 1254 +
 drivers/scsi/esas2r/atvda.h | 1320 ++
 drivers/scsi/esas2r/esas2r.h| 1441 
 drivers/scsi/esas2r/esas2r_disc.c   | 1190 
 drivers/scsi/esas2r/esas2r_flash.c  | 1514 +
 drivers/scsi/esas2r/esas2r_init.c   | 1773 +
 drivers/scsi/esas2r/esas2r_int.c|  941 
 drivers/scsi/esas2r/esas2r_io.c |  883 +++
 drivers/scsi/esas2r/esas2r_ioctl.c  | 2110 +++
 drivers/scsi/esas2r/esas2r_log.c|  255 +
 drivers/scsi/esas2r/esas2r_log.h|  118 ++
 drivers/scsi/esas2r/esas2r_main.c   | 2033 +
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +
 drivers/scsi/esas2r/esas2r_vda.c|  523 +
 19 files changed, 15681 insertions(+)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile
 create mode 100644 drivers/scsi/esas2r/atioctl.h
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r.h
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

-- 
1.8.1.4

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


[PATCH v3 05/10] [RFC] SCSI: esas2r: Add interrupt and IO functions

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_int.c | 941 +++
 drivers/scsi/esas2r/esas2r_io.c  | 883 
 2 files changed, 1824 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c

diff --git a/drivers/scsi/esas2r/esas2r_int.c b/drivers/scsi/esas2r/esas2r_int.c
new file mode 100644
index 000..c2d4ff5
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_int.c
@@ -0,0 +1,941 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_int.c
+ *  esas2r interrupt handling
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Local function prototypes */
+static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell);
+static void esas2r_get_outbound_responses(struct esas2r_adapter *a);
+static void esas2r_process_bus_reset(struct esas2r_adapter *a);
+
+/*
+ * Poll the adapter for interrupts and service them.
+ * This function handles both legacy interrupts and MSI.
+ */
+void esas2r_polled_interrupt(struct esas2r_adapter *a)
+{
+   u32 intstat;
+   u32 doorbell;
+
+   esas2r_disable_chip_interrupts(a);
+
+   intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
+
+   if (intstat  MU_INTSTAT_POST_OUT) {
+   /* clear the interrupt */
+
+   esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT,
+   MU_OLIS_INT);
+   esas2r_flush_register_dword(a, MU_OUT_LIST_INT_STAT);
+
+   esas2r_get_outbound_responses(a);
+   }
+
+   if (intstat  MU_INTSTAT_DRBL) {
+   doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
+   if (doorbell != 0)
+   esas2r_doorbell_interrupt(a, doorbell);
+   }
+
+   esas2r_enable_chip_interrupts(a);
+
+   if (atomic_read(a-disable_cnt) == 0)
+   esas2r_do_deferred_processes(a);
+}
+
+/*
+ * Legacy and MSI interrupt handlers.  Note that the legacy interrupt handler
+ * schedules a TASKLET to process events, whereas the MSI handler just
+ * processes interrupt events directly.
+ */
+irqreturn_t esas2r_interrupt(int irq, void *dev_id)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)dev_id;
+
+   if (!esas2r_adapter_interrupt_pending(a))
+   return IRQ_NONE;
+
+   esas2r_lock_set_flags(a-flags2, AF2_INT_PENDING);
+   esas2r_schedule_tasklet(a);
+
+   return IRQ_HANDLED;
+}
+
+void esas2r_adapter_interrupt(struct esas2r_adapter *a)
+{
+   u32 doorbell;
+
+   if (likely(a-int_stat  MU_INTSTAT_POST_OUT)) {
+   /* clear the interrupt */
+   esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT

[PATCH v3 08/10] [RFC] SCSI: esas2r: Add IOCTL functions

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2110 
 1 file changed, 2110 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
new file mode 100644
index 000..2d27dcf
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -0,0 +1,2110 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_ioctl.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/*
+ * Buffered ioctl handlers.  A buffered ioctl is one which requires that we
+ * allocate a DMA-able memory area to communicate with the firmware.  In
+ * order to prevent continually allocating and freeing consistent memory,
+ * we will allocate a global buffer the first time we need it and re-use
+ * it for subsequent ioctl calls that require it.
+ */
+
+u8 *esas2r_buffered_ioctl;
+dma_addr_t esas2r_buffered_ioctl_addr;
+u32 esas2r_buffered_ioctl_size;
+struct pci_dev *esas2r_buffered_ioctl_pcid;
+
+static DEFINE_SEMAPHORE(buffered_ioctl_semaphore);
+typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *,
+  struct esas2r_request *,
+  struct esas2r_sg_context *,
+  void *);
+typedef void (*BUFFERED_IOCTL_DONE_CALLBACK)(struct esas2r_adapter *,
+struct esas2r_request *, void *);
+
+struct esas2r_buffered_ioctl {
+   struct esas2r_adapter *a;
+   void *ioctl;
+   u32 length;
+   u32 control_code;
+   u32 offset;
+   BUFFERED_IOCTL_CALLBACK
+   callback;
+   void *context;
+   BUFFERED_IOCTL_DONE_CALLBACK
+   done_callback;
+   void *done_context;
+
+};
+
+static void complete_fm_api_req(struct esas2r_adapter *a,
+   struct esas2r_request *rq)
+{
+   a-fm_api_command_done = 1;
+   wake_up_interruptible(a-fm_api_waiter);
+}
+
+/* Callbacks for building scatter/gather lists for FM API requests */
+static u32 get_physaddr_fm_api(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.phys + offset;
+   return a-firmware.orig_len - offset;
+}
+
+static u32 get_physaddr_fm_api_header(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.header_buff_phys + offset;
+   return sizeof(struct esas2r_flash_img) - offset;
+}
+
+/* Handle EXPRESS_IOCTL_RW_FIRMWARE ioctl with img_type = FW_IMG_FM_API. */
+static void do_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi

[PATCH v3 07/10] [RFC] SCSI: esas2r: Add IOCTL header file

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atioctl.h | 1254 +
 1 file changed, 1254 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atioctl.h

diff --git a/drivers/scsi/esas2r/atioctl.h b/drivers/scsi/esas2r/atioctl.h
new file mode 100644
index 000..4aca3d5
--- /dev/null
+++ b/drivers/scsi/esas2r/atioctl.h
@@ -0,0 +1,1254 @@
+/*  linux/drivers/scsi/esas2r/atioctl.h
+ *  ATTO IOCTL Handling
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include atvda.h
+
+#ifndef ATIOCTL_H
+#define ATIOCTL_H
+
+#define EXPRESS_IOCTL_SIGNATUREExpress
+#define EXPRESS_IOCTL_SIGNATURE_SIZE   8
+
+/* structure definitions for IOCTls */
+
+struct __packed atto_express_ioctl_header {
+   u8 signature[EXPRESS_IOCTL_SIGNATURE_SIZE];
+   u8 return_code;
+
+#define IOCTL_SUCCESS   0
+#define IOCTL_ERR_INVCMD  101
+#define IOCTL_INIT_FAILED 102
+#define IOCTL_NOT_IMPLEMENTED 103
+#define IOCTL_BAD_CHANNEL 104
+#define IOCTL_TARGET_OVERRUN  105
+#define IOCTL_TARGET_NOT_ENABLED  106
+#define IOCTL_BAD_FLASH_IMGTYPE   107
+#define IOCTL_OUT_OF_RESOURCES108
+#define IOCTL_GENERAL_ERROR   109
+#define IOCTL_INVALID_PARAM   110
+
+   u8 channel;
+   u8 retries;
+   u8 pad[5];
+};
+
+/*
+ * NOTE - if channel == 0xFF, the request is
+ * handled on the adapter it came in on.
+ */
+#define MAX_NODE_NAMES  256
+
+struct __packed atto_firmware_rw_request {
+   u8 function;
+   #define FUNC_FW_DOWNLOAD0x09
+   #define FUNC_FW_UPLOAD  0x12
+
+   u8 img_type;
+   #define FW_IMG_FW   0x01
+   #define FW_IMG_BIOS 0x02
+   #define FW_IMG_NVR  0x03
+   #define FW_IMG_RAW  0x04
+   #define FW_IMG_FM_API   0x05
+   #define FW_IMG_FS_API   0x06
+
+   u8 pad[2];
+   u32 img_offset;
+   u32 img_size;
+   u8 image[0x8];
+};
+
+struct __packed atto_param_rw_request {
+   u16 code;
+   char data_buffer[512];
+};
+
+#define MAX_CHANNEL 256
+
+struct __packed atto_channel_list {
+   u32 num_channels;
+   u8 channel[MAX_CHANNEL];
+};
+
+struct __packed atto_channel_info {
+   u8 major_rev;
+   u8 minor_rev;
+   u8 IRQ;
+   u8 revision_id;
+   u8 pci_bus;
+   u8 pci_dev_func;
+   u8 core_rev;
+   u8 host_no;
+   u16 device_id;
+   u16 vendor_id;
+   u16 ven_dev_id;
+   u8 pad[3];
+   u32 hbaapi_rev;
+};
+
+/*
+ * CSMI control codes
+ * class independent
+ */
+#define CSMI_CC_GET_DRVR_INFO1
+#define CSMI_CC_GET_CNTLR_CFG2
+#define CSMI_CC_GET_CNTLR_STS3
+#define CSMI_CC_FW_DOWNLOAD  4
+
+/* RAID class */
+#define CSMI_CC_GET_RAID_INFO10

[PATCH v3 04/10] [RFC] SCSI: esas2r: Add device discovery and logging functions

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_disc.c | 1190 +
 drivers/scsi/esas2r/esas2r_log.c  |  255 
 drivers/scsi/esas2r/esas2r_log.h  |  118 
 3 files changed, 1563 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h

diff --git a/drivers/scsi/esas2r/esas2r_disc.c 
b/drivers/scsi/esas2r/esas2r_disc.c
new file mode 100644
index 000..319ba9a
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_disc.c
@@ -0,0 +1,1189 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_disc.c
+ *  esas2r device discovery routines
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Miscellaneous internal discovery routines */
+static void esas2r_disc_abort(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_continue(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static void esas2r_disc_fix_curr_requests(struct esas2r_adapter *a);
+static u32 esas2r_disc_get_phys_addr(struct esas2r_sg_context *sgc, u64 *addr);
+static bool esas2r_disc_start_request(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+
+/* Internal discovery routines that process the states */
+static bool esas2r_disc_block_dev_scan(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static void esas2r_disc_block_dev_scan_cb(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_dev_add(struct esas2r_adapter *a,
+   struct esas2r_request *rq);
+static bool esas2r_disc_dev_remove(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static bool esas2r_disc_part_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_part_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_addr(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_addr_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_raid_grp_info(struct esas2r_adapter

[PATCH v3 02/10] [RFC] SCSI: esas2r: Add main file

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_main.c | 2033 +
 1 file changed, 2033 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
new file mode 100644
index 000..cd2cd95
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -0,0 +1,2033 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_main.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+MODULE_DESCRIPTION(ESAS2R_DRVR_NAME :  ESAS2R_LONGNAME  driver);
+MODULE_AUTHOR(ATTO Technology, Inc.);
+MODULE_LICENSE(GPL);
+MODULE_VERSION(ESAS2R_VERSION_STR);
+
+/* global definitions */
+
+static int found_adapters;
+struct esas2r_adapter *esas2r_adapters[MAX_ADAPTERS];
+
+#define ESAS2R_VDA_EVENT_PORT1   54414
+#define ESAS2R_VDA_EVENT_PORT2   54415
+#define ESAS2R_VDA_EVENT_SOCK_COUNT  2
+
+static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj)
+{
+   struct device *dev = container_of(kobj, struct device, kobj);
+   struct Scsi_Host *host = class_to_shost(dev);
+
+   return (struct esas2r_adapter *)host-hostdata;
+}
+
+static ssize_t read_fw(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr,
+  char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_fw(a, buf, off, count);
+}
+
+static ssize_t write_fw(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_write_fw(a, buf, off, count);
+}
+
+static ssize_t read_fs(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr,
+  char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_fs(a, buf, off, count);
+}
+
+static ssize_t write_fs(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+   int length = min(sizeof(struct esas2r_ioctl_fs), count);
+   int result = 0;
+
+   result = esas2r_write_fs(a, buf, off, count);
+
+   if (result  0)
+   result = 0;
+
+   return length;
+}
+
+static ssize_t read_vda(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_vda(a, buf, off, count

[PATCH v3 03/10] [RFC] SCSI: esas2r: Add initialization functions

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 1773 +
 1 file changed, 1773 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
new file mode 100644
index 000..3a798e7
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -0,0 +1,1773 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_init.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)mpt3sas/mpt3sas_trigger_diag.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+static bool esas2r_initmem_alloc(struct esas2r_adapter *a,
+struct esas2r_mem_desc *mem_desc,
+u32 align)
+{
+   mem_desc-esas2r_param = mem_desc-size + align;
+   mem_desc-virt_addr = NULL;
+   mem_desc-phys_addr = 0;
+   mem_desc-esas2r_data = dma_alloc_coherent(a-pcid-dev,
+  (size_t)mem_desc-
+  esas2r_param,
+  (dma_addr_t *)mem_desc-
+  phys_addr,
+  GFP_KERNEL);
+
+   if (mem_desc-esas2r_data == NULL) {
+   esas2r_log(ESAS2R_LOG_CRIT,
+  failed to allocate %lu bytes of consistent memory!,
+  (long
+   unsigned
+   int)mem_desc-esas2r_param);
+   return false;
+   }
+
+   mem_desc-virt_addr = PTR_ALIGN(mem_desc-esas2r_data, align);
+   mem_desc-phys_addr = ALIGN(mem_desc-phys_addr, align);
+   memset(mem_desc-virt_addr, 0, mem_desc-size);
+   return true;
+}
+
+static void esas2r_initmem_free(struct esas2r_adapter *a,
+   struct esas2r_mem_desc *mem_desc)
+{
+   if (mem_desc-virt_addr == NULL)
+   return;
+
+   /*
+* Careful!  phys_addr and virt_addr may have been adjusted from the
+* original allocation in order to return the desired alignment.  That
+* means we have to use the original address (in esas2r_data) and size
+* (esas2r_param) and calculate the original physical address based on
+* the difference between the requested and actual allocation size.
+*/
+   if (mem_desc-phys_addr) {
+   int unalign = ((u8 *)mem_desc-virt_addr) -
+ ((u8 *)mem_desc-esas2r_data);
+
+   dma_free_coherent(a-pcid-dev,
+ (size_t)mem_desc-esas2r_param,
+ mem_desc-esas2r_data,
+ (dma_addr_t)(mem_desc-phys_addr - unalign));
+   } else {
+   kfree(mem_desc-esas2r_data);
+   }
+
+   mem_desc

[PATCH v3 09/10] [RFC] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. This API is used to control and manage the RAID adapter.

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atvda.h  | 1320 ++
 drivers/scsi/esas2r/esas2r_vda.c |  523 +++
 2 files changed, 1843 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

diff --git a/drivers/scsi/esas2r/atvda.h b/drivers/scsi/esas2r/atvda.h
new file mode 100644
index 000..0f70c31
--- /dev/null
+++ b/drivers/scsi/esas2r/atvda.h
@@ -0,0 +1,1319 @@
+/*  linux/drivers/scsi/esas2r/atvda.h
+ *   ATTO VDA interface definitions
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+
+#ifndef ATVDA_H
+#define ATVDA_H
+
+struct __packed atto_dev_addr {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+  #define VDA_DEVADDRF_SATA   0x01
+  #define VDA_DEVADDRF_SSD0x02
+   u8 link_speed; /* VDALINKSPEED_xxx */
+   u8 pad[1];
+};
+
+/* dev_addr2 was added for 64-bit alignment */
+
+struct __packed atto_dev_addr2 {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+   u8 link_speed;
+   u8 pad[5];
+};
+
+struct __packed atto_vda_sge {
+   u32 length;
+   u64 address;
+};
+
+
+/* VDA request function codes */
+
+#define VDA_FUNC_SCSI 0x00
+#define VDA_FUNC_FLASH0x01
+#define VDA_FUNC_DIAG 0x02
+#define VDA_FUNC_AE   0x03
+#define VDA_FUNC_CLI  0x04
+#define VDA_FUNC_IOCTL0x05
+#define VDA_FUNC_CFG  0x06
+#define VDA_FUNC_MGT  0x07
+#define VDA_FUNC_GSV  0x08
+
+
+/* VDA request status values.  for host driver considerations, values for
+ * SCSI requests start at zero.  other requests may use these values as well. 
*/
+
+#define RS_SUCCESS  0x00/*! successful completion*/
+#define RS_INV_FUNC 0x01/*! invalid command function */
+#define RS_BUSY 0x02/*! insufficient resources   */
+#define RS_SEL  0x03/*! no target at target_id   */
+#define RS_NO_LUN   0x04/*! invalid LUN  */
+#define RS_TIMEOUT  0x05/*! request timeout  */
+#define RS_OVERRUN  0x06/*! data overrun */
+#define RS_UNDERRUN 0x07/*! data underrun*/
+#define RS_SCSI_ERROR   0x08/*! SCSI error occurred  */
+#define RS_ABORTED  0x0A/*! command aborted  */
+#define RS_RESID_MISM   0x0B/*! residual length incorrect*/
+#define RS_TM_FAILED0x0C/*! task management failed   */
+#define RS_RESET0x0D/*! aborted due to bus reset */
+#define RS_ERR_DMA_SG   0x0E/*! error reading SG list

[PATCH v3 06/10] [RFC] SCSI: esas2r: Add flash and target database functions

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c  | 1514 +++
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +++
 2 files changed, 1820 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
new file mode 100644
index 000..a02fb62
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -0,0 +1,1512 @@
+
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_flash.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/* local macro defs */
+#define esas2r_nvramcalc_cksum(n) \
+   (esas2r_calc_byte_cksum((u8 *)(n), sizeof(struct esas2r_sas_nvram), \
+   SASNVR_CKSUM_SEED))
+#define esas2r_nvramcalc_xor_cksum(n)  \
+   (esas2r_calc_byte_xor_cksum((u8 *)(n), \
+   sizeof(struct esas2r_sas_nvram), 0))
+
+#define ESAS2R_FS_DRVR_VER 2
+
+static struct esas2r_sas_nvram default_sas_nvram = {
+   { 'E',  'S',  'A',  'S'  }, /* signature  */
+   SASNVR_VERSION, /* version*/
+   0,  /* checksum   */
+   31, /* max_lun_for_target */
+   SASNVR_PCILAT_MAX,  /* pci_latency*/
+   SASNVR1_BOOT_DRVR,  /* options1   */
+   SASNVR2_HEARTBEAT   | SASNVR2_SINGLE_BUS/* options2   */
+   | SASNVR2_SW_MUX_CTRL,
+   SASNVR_COAL_DIS,/* int_coalescing */
+   SASNVR_CMDTHR_NONE, /* cmd_throttle   */
+   3,  /* dev_wait_time  */
+   1,  /* dev_wait_count */
+   0,  /* spin_up_delay  */
+   0,  /* ssp_align_rate */
+   { 0x50, 0x01, 0x08, 0x60,   /* sas_addr   */
+ 0x00, 0x00, 0x00, 0x00 },
+   { SASNVR_SPEED_AUTO },  /* phy_speed  */
+   { SASNVR_MUX_DISABLED },/* SAS multiplexing   */
+   { 0 },  /* phy_flags  */
+   SASNVR_SORT_SAS_ADDR,   /* sort_type  */
+   3,  /* dpm_reqcmd_lmt */
+   3,  /* dpm_stndby_time*/
+   0,  /* dpm_active_time*/
+   { 0

[PATCH v3 01/10] [RFC] SCSI: esas2r: Add main header file

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r.h | 1441 ++
 1 file changed, 1441 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r.h

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
new file mode 100644
index 000..0838e26
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -0,0 +1,1441 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r.h
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include linux/kernel.h
+#include linux/delay.h
+#include linux/pci.h
+#include linux/proc_fs.h
+#include linux/workqueue.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/vmalloc.h
+#include scsi/scsi.h
+#include scsi/scsi_host.h
+#include scsi/scsi_cmnd.h
+#include scsi/scsi_device.h
+#include scsi/scsi_eh.h
+#include scsi/scsi_tcq.h
+
+#include esas2r_log.h
+#include atioctl.h
+#include atvda.h
+
+#ifndef ESAS2R_H
+#define ESAS2R_H
+
+/* Global Variables */
+extern struct esas2r_adapter *esas2r_adapters[];
+extern u8 *esas2r_buffered_ioctl;
+extern dma_addr_t esas2r_buffered_ioctl_addr;
+extern u32 esas2r_buffered_ioctl_size;
+extern struct pci_dev *esas2r_buffered_ioctl_pcid;
+#define SGL_PG_SZ_MIN   64
+#define SGL_PG_SZ_MAX   1024
+extern int sgl_page_size;
+#define NUM_SGL_MIN 8
+#define NUM_SGL_MAX 2048
+extern int num_sg_lists;
+#define NUM_REQ_MIN 4
+#define NUM_REQ_MAX 256
+extern int num_requests;
+#define NUM_AE_MIN  2
+#define NUM_AE_MAX  8
+extern int num_ae_requests;
+extern int cmd_per_lun;
+extern int can_queue;
+extern int esas2r_max_sectors;
+extern int sg_tablesize;
+extern int interrupt_mode;
+extern int num_io_requests;
+
+/* Macro defintions */
+#define ESAS2R_MAX_ID255
+#define MAX_ADAPTERS 32
+#define ESAS2R_DRVR_NAME esas2r
+#define ESAS2R_LONGNAME  ATTO ExpressSAS 6GB RAID Adapter
+#define ESAS2R_MAX_DEVICES 32
+#define ATTONODE_NAME ATTONode
+#define ESAS2R_MAJOR_REV   1
+#define ESAS2R_MINOR_REV   00
+#define ESAS2R_VERSION_STR DEFINED_NUM_TO_STR(ESAS2R_MAJOR_REV) . \
+   DEFINED_NUM_TO_STR(ESAS2R_MINOR_REV)
+#define ESAS2R_COPYRIGHT_YEARS 2001-2013
+#define ESAS2R_DEFAULT_SGL_PAGE_SIZE 384
+#define ESAS2R_DEFAULT_CMD_PER_LUN   64
+#define ESAS2R_DEFAULT_NUM_SG_LISTS 1024
+#define DEFINED_NUM_TO_STR(num) NUM_TO_STR(num)
+#define NUM_TO_STR(num) #num
+
+#define ESAS2R_SGL_ALIGN16
+#define ESAS2R_LIST_ALIGN   16
+#define ESAS2R_LIST_EXTRA   ESAS2R_NUM_EXTRA
+#define ESAS2R_DATA_BUF_LEN 256
+#define ESAS2R_DEFAULT_TMO  5000
+#define ESAS2R_DISC_BUF_LEN 512
+#define ESAS2R_FWCOREDUMP_SZ0x8
+#define ESAS2R_NUM_PHYS 8
+#define ESAS2R_TARG_ID_INV  0x
+#define ESAS2R_INT_STS_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_ENB_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_DIS_MASK 0

[PATCH v3 10/10] [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

2013-08-02 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 MAINTAINERS  | 7 +++
 drivers/scsi/Kconfig | 1 +
 drivers/scsi/Makefile| 1 +
 drivers/scsi/esas2r/Kconfig  | 6 ++
 drivers/scsi/esas2r/Makefile | 5 +
 5 files changed, 20 insertions(+)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index a26b10e..024bc9a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1542,6 +1542,13 @@ W:   http://atmelwlandriver.sourceforge.net/
 S: Maintained
 F: drivers/net/wireless/atmel*
 
+ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
+M:  Bradley Grove linuxdriv...@attotech.com
+L:  linux-scsi@vger.kernel.org
+W:  http://www.attotech.com
+S:  Supported
+F:  drivers/scsi/esas2r
+
 AUDIT SUBSYSTEM
 M: Al Viro v...@zeniv.linux.org.uk
 M: Eric Paris epa...@redhat.com
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 48b2918..c298b76 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -601,6 +601,7 @@ config SCSI_ARCMSR
  To compile this driver as a module, choose M here: the
  module will be called arcmsr (modprobe arcmsr).
 
+source drivers/scsi/esas2r/Kconfig
 source drivers/scsi/megaraid/Kconfig.megaraid
 source drivers/scsi/mpt2sas/Kconfig
 source drivers/scsi/mpt3sas/Kconfig
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index b607ba4..149bb6b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -141,6 +141,7 @@ obj-$(CONFIG_SCSI_CXGB3_ISCSI)  += libiscsi.o 
libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_CXGB4_ISCSI) += libiscsi.o libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_BNX2_ISCSI)  += libiscsi.o bnx2i/
 obj-$(CONFIG_BE2ISCSI) += libiscsi.o be2iscsi/
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r/
 obj-$(CONFIG_SCSI_PMCRAID) += pmcraid.o
 obj-$(CONFIG_SCSI_VIRTIO)  += virtio_scsi.o
 obj-$(CONFIG_VMWARE_PVSCSI)+= vmw_pvscsi.o
diff --git a/drivers/scsi/esas2r/Kconfig b/drivers/scsi/esas2r/Kconfig
new file mode 100644
index 000..80824f0
--- /dev/null
+++ b/drivers/scsi/esas2r/Kconfig
@@ -0,0 +1,5 @@
+config SCSI_ESAS2R
+   tristate ATTO Technology's ExpressSAS RAID adapter driver
+   depends on PCI  SCSI
+   ---help---
+ This driver supports the ATTO ExpressSAS R6xx SAS/SATA RAID 
controllers.
diff --git a/drivers/scsi/esas2r/Makefile b/drivers/scsi/esas2r/Makefile
new file mode 100644
index 000..c77160b
--- /dev/null
+++ b/drivers/scsi/esas2r/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r.o
+
+esas2r-objs := esas2r_log.o esas2r_disc.o esas2r_flash.o esas2r_init.o \
+esas2r_int.o esas2r_io.o esas2r_ioctl.o esas2r_targdb.o   \
+esas2r_vda.o esas2r_main.o
-- 
1.8.1.4

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


[PATCH v2 06/10] [RFC] SCSI: esas2r: Add flash and target database functions

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c  | 1516 +++
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +++
 2 files changed, 1822 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
new file mode 100644
index 000..61ef449
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -0,0 +1,1514 @@
+
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_flash.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/* local macro defs */
+#define esas2r_nvramcalc_cksum(n) \
+   (esas2r_calc_byte_cksum((u8 *)(n), sizeof(struct esas2r_sas_nvram), \
+   SASNVR_CKSUM_SEED))
+#define esas2r_nvramcalc_xor_cksum(n)  \
+   (esas2r_calc_byte_xor_cksum((u8 *)(n), \
+   sizeof(struct esas2r_sas_nvram), 0))
+
+#define ESAS2R_FS_DRVR_VER 2
+
+static struct esas2r_sas_nvram default_sas_nvram = {
+   { 'E',  'S',  'A',  'S'  },  /* signature  */
+   SASNVR_VERSION,  /* version*/
+   0,   /* checksum   */
+   31,  /* max_lun_for_target */
+   SASNVR_PCILAT_MAX,   /* pci_latency*/
+   SASNVR1_BOOT_DRVR,   /* options1   */
+   SASNVR2_HEARTBEAT   | SASNVR2_SINGLE_BUS /* options2   */
+   | SASNVR2_SW_MUX_CTRL,
+   SASNVR_COAL_DIS, /* int_coalescing */
+   SASNVR_CMDTHR_NONE,  /* cmd_throttle   */
+   3,   /* dev_wait_time  */
+   1,   /* dev_wait_count */
+   0,   /* spin_up_delay  */
+   0,   /* ssp_align_rate */
+   { 0x50, 0x01, 0x08, 0x60,/* sas_addr   */
+ 0x00, 0x00, 0x00, 0x00 },
+   { SASNVR_SPEED_AUTO },   /* phy_speed  */
+   { SASNVR_MUX_DISABLED }, /* SAS multiplexing   */
+   { 0 },   /* phy_flags  */
+   SASNVR_SORT_SAS_ADDR,/* sort_type  */
+   3,   /* dpm_reqcmd_lmt */
+   3,   /* dpm_stndby_time*/
+   0,   /* dpm_active_time*/
+   { 0 },   /* phy_target_id

[PATCH v2 09/10] [RFC] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. This API is used to control and manage the RAID adapter.

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atvda.h  | 1320 ++
 drivers/scsi/esas2r/esas2r_vda.c |  523 +++
 2 files changed, 1843 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

diff --git a/drivers/scsi/esas2r/atvda.h b/drivers/scsi/esas2r/atvda.h
new file mode 100644
index 000..0f70c31
--- /dev/null
+++ b/drivers/scsi/esas2r/atvda.h
@@ -0,0 +1,1319 @@
+/*  linux/drivers/scsi/esas2r/atvda.h
+ *   ATTO VDA interface definitions
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+
+#ifndef ATVDA_H
+#define ATVDA_H
+
+struct __packed atto_dev_addr {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+  #define VDA_DEVADDRF_SATA   0x01
+  #define VDA_DEVADDRF_SSD0x02
+   u8 link_speed; /* VDALINKSPEED_xxx */
+   u8 pad[1];
+};
+
+/* dev_addr2 was added for 64-bit alignment */
+
+struct __packed atto_dev_addr2 {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+   u8 link_speed;
+   u8 pad[5];
+};
+
+struct __packed atto_vda_sge {
+   u32 length;
+   u64 address;
+};
+
+
+/* VDA request function codes */
+
+#define VDA_FUNC_SCSI 0x00
+#define VDA_FUNC_FLASH0x01
+#define VDA_FUNC_DIAG 0x02
+#define VDA_FUNC_AE   0x03
+#define VDA_FUNC_CLI  0x04
+#define VDA_FUNC_IOCTL0x05
+#define VDA_FUNC_CFG  0x06
+#define VDA_FUNC_MGT  0x07
+#define VDA_FUNC_GSV  0x08
+
+
+/* VDA request status values.  for host driver considerations, values for
+ * SCSI requests start at zero.  other requests may use these values as well. 
*/
+
+#define RS_SUCCESS  0x00/*! successful completion*/
+#define RS_INV_FUNC 0x01/*! invalid command function */
+#define RS_BUSY 0x02/*! insufficient resources   */
+#define RS_SEL  0x03/*! no target at target_id   */
+#define RS_NO_LUN   0x04/*! invalid LUN  */
+#define RS_TIMEOUT  0x05/*! request timeout  */
+#define RS_OVERRUN  0x06/*! data overrun */
+#define RS_UNDERRUN 0x07/*! data underrun*/
+#define RS_SCSI_ERROR   0x08/*! SCSI error occurred  */
+#define RS_ABORTED  0x0A/*! command aborted  */
+#define RS_RESID_MISM   0x0B/*! residual length incorrect*/
+#define RS_TM_FAILED0x0C/*! task management failed   */
+#define RS_RESET0x0D/*! aborted due to bus reset */
+#define RS_ERR_DMA_SG   0x0E/*! error reading SG list

[PATCH v2 00/10] [RFC] SCSI: esas2r: ATTO Technology ExpressSAS 6G SAS/SATA RAID Adapter Driver

2013-07-16 Thread Bradley Grove

This is a new driver for ATTO Technology's ExpressSAS series of hardware RAID 
adapters.  It supports the following adapters:

- ExpressSAS R60F
- ExpressSAS R680
- ExpressSAS R608
- ExpressSAS R644

This patch is split into ten parts, all of which need to be applied to build 
the driver.

Changes since V1:

- We now use the kernel's list structs and alignment macros rather than our own 
implementations
- Fix to PCIe address size declaration when compiling on 32-bit architectures
- Use memcpy() instead opf memmove() where appropriate
- Fixes for big-endian architectures
- Removed unneeded MSI configuration code
- Simplified memory allocation during init
- Code formatting cleanup

Bradley Grove (10):
  [RFC] SCSI: esas2r: Add main header file
  [RFC] SCSI: esas2r: Add main file
  [RFC] SCSI: esas2r: Add initialization functions
  [RFC] SCSI: esas2r: Add device discovery and logging functions
  [RFC] SCSI: esas2r: Add interrupt and IO functions
  [RFC] SCSI: esas2r: Add flash and target database functions
  [RFC] SCSI: esas2r: Add IOCTL header file
  [RFC] SCSI: esas2r: Add IOCTL functions
  [RFC] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. 
This API is used to control and manage the RAID adapter.
  [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

 MAINTAINERS |7 +
 drivers/scsi/Kconfig|1 +
 drivers/scsi/Makefile   |1 +
 drivers/scsi/esas2r/Kconfig |6 +
 drivers/scsi/esas2r/Makefile|5 +
 drivers/scsi/esas2r/atioctl.h   | 1254 
 drivers/scsi/esas2r/atvda.h | 1320 +
 drivers/scsi/esas2r/esas2r.h| 1442 +++
 drivers/scsi/esas2r/esas2r_disc.c   | 1190 +++
 drivers/scsi/esas2r/esas2r_flash.c  | 1516 
 drivers/scsi/esas2r/esas2r_init.c   | 1775 
 drivers/scsi/esas2r/esas2r_int.c|  940 +++
 drivers/scsi/esas2r/esas2r_io.c |  883 ++
 drivers/scsi/esas2r/esas2r_ioctl.c  | 2108 ++
 drivers/scsi/esas2r/esas2r_log.c|  255 
 drivers/scsi/esas2r/esas2r_log.h|  118 ++
 drivers/scsi/esas2r/esas2r_main.c   | 2169 +++
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +
 drivers/scsi/esas2r/esas2r_vda.c|  523 +
 19 files changed, 15819 insertions(+)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile
 create mode 100644 drivers/scsi/esas2r/atioctl.h
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r.h
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

-- 
1.8.1.4

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


[PATCH v2 07/10] [RFC] SCSI: esas2r: Add IOCTL header file

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atioctl.h | 1254 +
 1 file changed, 1254 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atioctl.h

diff --git a/drivers/scsi/esas2r/atioctl.h b/drivers/scsi/esas2r/atioctl.h
new file mode 100644
index 000..4aca3d5
--- /dev/null
+++ b/drivers/scsi/esas2r/atioctl.h
@@ -0,0 +1,1254 @@
+/*  linux/drivers/scsi/esas2r/atioctl.h
+ *  ATTO IOCTL Handling
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include atvda.h
+
+#ifndef ATIOCTL_H
+#define ATIOCTL_H
+
+#define EXPRESS_IOCTL_SIGNATUREExpress
+#define EXPRESS_IOCTL_SIGNATURE_SIZE   8
+
+/* structure definitions for IOCTls */
+
+struct __packed atto_express_ioctl_header {
+   u8 signature[EXPRESS_IOCTL_SIGNATURE_SIZE];
+   u8 return_code;
+
+#define IOCTL_SUCCESS   0
+#define IOCTL_ERR_INVCMD  101
+#define IOCTL_INIT_FAILED 102
+#define IOCTL_NOT_IMPLEMENTED 103
+#define IOCTL_BAD_CHANNEL 104
+#define IOCTL_TARGET_OVERRUN  105
+#define IOCTL_TARGET_NOT_ENABLED  106
+#define IOCTL_BAD_FLASH_IMGTYPE   107
+#define IOCTL_OUT_OF_RESOURCES108
+#define IOCTL_GENERAL_ERROR   109
+#define IOCTL_INVALID_PARAM   110
+
+   u8 channel;
+   u8 retries;
+   u8 pad[5];
+};
+
+/*
+ * NOTE - if channel == 0xFF, the request is
+ * handled on the adapter it came in on.
+ */
+#define MAX_NODE_NAMES  256
+
+struct __packed atto_firmware_rw_request {
+   u8 function;
+   #define FUNC_FW_DOWNLOAD0x09
+   #define FUNC_FW_UPLOAD  0x12
+
+   u8 img_type;
+   #define FW_IMG_FW   0x01
+   #define FW_IMG_BIOS 0x02
+   #define FW_IMG_NVR  0x03
+   #define FW_IMG_RAW  0x04
+   #define FW_IMG_FM_API   0x05
+   #define FW_IMG_FS_API   0x06
+
+   u8 pad[2];
+   u32 img_offset;
+   u32 img_size;
+   u8 image[0x8];
+};
+
+struct __packed atto_param_rw_request {
+   u16 code;
+   char data_buffer[512];
+};
+
+#define MAX_CHANNEL 256
+
+struct __packed atto_channel_list {
+   u32 num_channels;
+   u8 channel[MAX_CHANNEL];
+};
+
+struct __packed atto_channel_info {
+   u8 major_rev;
+   u8 minor_rev;
+   u8 IRQ;
+   u8 revision_id;
+   u8 pci_bus;
+   u8 pci_dev_func;
+   u8 core_rev;
+   u8 host_no;
+   u16 device_id;
+   u16 vendor_id;
+   u16 ven_dev_id;
+   u8 pad[3];
+   u32 hbaapi_rev;
+};
+
+/*
+ * CSMI control codes
+ * class independent
+ */
+#define CSMI_CC_GET_DRVR_INFO1
+#define CSMI_CC_GET_CNTLR_CFG2
+#define CSMI_CC_GET_CNTLR_STS3
+#define CSMI_CC_FW_DOWNLOAD  4
+
+/* RAID class */
+#define CSMI_CC_GET_RAID_INFO10

[PATCH v2 02/10] [RFC] SCSI: esas2r: Add main file

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_main.c | 2169 +
 1 file changed, 2169 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
new file mode 100644
index 000..4f24aac
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -0,0 +1,2169 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_main.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+MODULE_DESCRIPTION(ESAS2R_DRVR_NAME :  ESAS2R_LONGNAME  driver);
+MODULE_AUTHOR(ATTO Technology, Inc.);
+MODULE_LICENSE(GPL);
+MODULE_VERSION(ESAS2R_VERSION_STR);
+
+/* global definitions */
+
+static int found_adapters;
+struct esas2r_adapter *esas2r_adapters[MAX_ADAPTERS];
+
+#define ESAS2R_VDA_EVENT_PORT1   54414
+#define ESAS2R_VDA_EVENT_PORT2   54415
+#define ESAS2R_VDA_EVENT_SOCK_COUNT  2
+
+static struct socket *event_socket[ESAS2R_VDA_EVENT_SOCK_COUNT];
+
+static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj)
+{
+   struct device *dev = container_of(kobj, struct device, kobj);
+   struct Scsi_Host *host = class_to_shost(dev);
+
+   return (struct esas2r_adapter *)host-hostdata;
+}
+
+static ssize_t read_fw(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr,
+  char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_fw(a, buf, off, count);
+}
+
+static ssize_t write_fw(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_write_fw(a, buf, off, count);
+}
+
+static ssize_t read_fs(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr,
+  char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+
+   return esas2r_read_fs(a, buf, off, count);
+}
+
+static ssize_t write_fs(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+   int length = min(sizeof(struct esas2r_ioctl_fs), count);
+   int result = 0;
+
+   result = esas2r_write_fs(a, buf, off, count);
+
+   if (result  0)
+   result = 0;
+
+   return length;
+}
+
+static ssize_t read_vda(struct file *file, struct kobject *kobj,
+   struct bin_attribute *attr,
+   char *buf, loff_t off, size_t count)
+{
+   struct esas2r_adapter

[PATCH v2 08/10] [RFC] SCSI: esas2r: Add IOCTL functions

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2108 
 1 file changed, 2108 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
new file mode 100644
index 000..34278ac
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -0,0 +1,2108 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_ioctl.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/*
+ * Buffered ioctl handlers.  A buffered ioctl is one which requires that we
+ * allocate a DMA-able memory area to communicate with the firmware.  In
+ * order to prevent continually allocating and freeing consistent memory,
+ * we will allocate a global buffer the first time we need it and re-use
+ * it for subsequent ioctl calls that require it.
+ */
+
+u8 *esas2r_buffered_ioctl;
+dma_addr_t esas2r_buffered_ioctl_addr;
+u32 esas2r_buffered_ioctl_size;
+struct pci_dev *esas2r_buffered_ioctl_pcid;
+
+static DEFINE_SEMAPHORE(buffered_ioctl_semaphore);
+typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *,
+  struct esas2r_request *,
+  struct esas2r_sg_context *,
+  void *);
+typedef void (*BUFFERED_IOCTL_DONE_CALLBACK)(struct esas2r_adapter *,
+struct esas2r_request *, void *);
+
+struct esas2r_buffered_ioctl {
+   struct esas2r_adapter *a;
+   void *ioctl;
+   u32 length;
+   u32 control_code;
+   u32 offset;
+   BUFFERED_IOCTL_CALLBACK
+   callback;
+   void *context;
+   BUFFERED_IOCTL_DONE_CALLBACK
+   done_callback;
+   void *done_context;
+
+};
+
+static void complete_fm_api_req(struct esas2r_adapter *a,
+   struct esas2r_request *rq)
+{
+   a-fm_api_command_done = 1;
+   wake_up_interruptible(a-fm_api_waiter);
+}
+
+/* Callbacks for building scatter/gather lists for FM API requests */
+static u32 get_physaddr_fm_api(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.phys + offset;
+   return a-firmware.orig_len - offset;
+}
+
+static u32 get_physaddr_fm_api_header(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.header_buff_phys + offset;
+   return sizeof(struct esas2r_flash_img) - offset;
+}
+
+/* Handle EXPRESS_IOCTL_RW_FIRMWARE ioctl with img_type = FW_IMG_FM_API. */
+static void do_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi

[PATCH v2 01/10] [RFC] SCSI: esas2r: Add main header file

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r.h | 1442 ++
 1 file changed, 1442 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r.h

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
new file mode 100644
index 000..b271822
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -0,0 +1,1442 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r.h
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include linux/kernel.h
+#include linux/delay.h
+#include linux/pci.h
+#include linux/proc_fs.h
+#include linux/workqueue.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/vmalloc.h
+#include scsi/scsi.h
+#include scsi/scsi_host.h
+#include scsi/scsi_cmnd.h
+#include scsi/scsi_device.h
+#include scsi/scsi_eh.h
+#include scsi/scsi_tcq.h
+#include net/sock.h
+
+#include esas2r_log.h
+#include atioctl.h
+#include atvda.h
+
+#ifndef ESAS2R_H
+#define ESAS2R_H
+
+/* Global Variables */
+extern struct esas2r_adapter *esas2r_adapters[];
+extern u8 *esas2r_buffered_ioctl;
+extern dma_addr_t esas2r_buffered_ioctl_addr;
+extern u32 esas2r_buffered_ioctl_size;
+extern struct pci_dev *esas2r_buffered_ioctl_pcid;
+#define SGL_PG_SZ_MIN   64
+#define SGL_PG_SZ_MAX   1024
+extern int sgl_page_size;
+#define NUM_SGL_MIN 8
+#define NUM_SGL_MAX 2048
+extern int num_sg_lists;
+#define NUM_REQ_MIN 4
+#define NUM_REQ_MAX 256
+extern int num_requests;
+#define NUM_AE_MIN  2
+#define NUM_AE_MAX  8
+extern int num_ae_requests;
+extern int cmd_per_lun;
+extern int can_queue;
+extern int esas2r_max_sectors;
+extern int sg_tablesize;
+extern int interrupt_mode;
+extern int num_io_requests;
+
+/* Macro defintions */
+#define ESAS2R_MAX_ID255
+#define MAX_ADAPTERS 32
+#define ESAS2R_DRVR_NAME esas2r
+#define ESAS2R_LONGNAME  ATTO ExpressSAS 6GB RAID Adapter
+#define ESAS2R_MAX_DEVICES 32
+#define ATTONODE_NAME ATTONode
+#define ESAS2R_MAJOR_REV   1
+#define ESAS2R_MINOR_REV   00
+#define ESAS2R_VERSION_STR DEFINED_NUM_TO_STR(ESAS2R_MAJOR_REV) . \
+   DEFINED_NUM_TO_STR(ESAS2R_MINOR_REV)
+#define ESAS2R_COPYRIGHT_YEARS 2001-2013
+#define ESAS2R_DEFAULT_SGL_PAGE_SIZE 384
+#define ESAS2R_DEFAULT_CMD_PER_LUN   64
+#define ESAS2R_DEFAULT_NUM_SG_LISTS 1024
+#define DEFINED_NUM_TO_STR(num) NUM_TO_STR(num)
+#define NUM_TO_STR(num) #num
+
+#define ESAS2R_SGL_ALIGN16
+#define ESAS2R_LIST_ALIGN   16
+#define ESAS2R_LIST_EXTRA   ESAS2R_NUM_EXTRA
+#define ESAS2R_DATA_BUF_LEN 256
+#define ESAS2R_DEFAULT_TMO  5000
+#define ESAS2R_DISC_BUF_LEN 512
+#define ESAS2R_FWCOREDUMP_SZ0x8
+#define ESAS2R_NUM_PHYS 8
+#define ESAS2R_TARG_ID_INV  0x
+#define ESAS2R_INT_STS_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_ENB_MASK MU_INTSTAT_MASK
+#define

[PATCH v2 04/10] [RFC] SCSI: esas2r: Add device discovery and logging functions

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_disc.c | 1190 +
 drivers/scsi/esas2r/esas2r_log.c  |  255 
 drivers/scsi/esas2r/esas2r_log.h  |  118 
 3 files changed, 1563 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h

diff --git a/drivers/scsi/esas2r/esas2r_disc.c 
b/drivers/scsi/esas2r/esas2r_disc.c
new file mode 100644
index 000..319ba9a
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_disc.c
@@ -0,0 +1,1189 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_disc.c
+ *  esas2r device discovery routines
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Miscellaneous internal discovery routines */
+static void esas2r_disc_abort(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_continue(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static void esas2r_disc_fix_curr_requests(struct esas2r_adapter *a);
+static u32 esas2r_disc_get_phys_addr(struct esas2r_sg_context *sgc, u64 *addr);
+static bool esas2r_disc_start_request(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+
+/* Internal discovery routines that process the states */
+static bool esas2r_disc_block_dev_scan(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static void esas2r_disc_block_dev_scan_cb(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_dev_add(struct esas2r_adapter *a,
+   struct esas2r_request *rq);
+static bool esas2r_disc_dev_remove(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static bool esas2r_disc_part_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_part_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_addr(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_addr_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_raid_grp_info(struct esas2r_adapter

[PATCH v2 03/10] [RFC] SCSI: esas2r: Add initialization functions

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 1775 +
 1 file changed, 1775 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
new file mode 100644
index 000..757d14d
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -0,0 +1,1775 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_init.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)mpt3sas/mpt3sas_trigger_diag.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+static bool esas2r_initmem_alloc(struct esas2r_adapter *a,
+struct esas2r_mem_desc *mem_desc,
+u32 align)
+{
+   mem_desc-esas2r_param = mem_desc-size + align;
+   mem_desc-virt_addr = NULL;
+   mem_desc-phys_addr = 0;
+   mem_desc-esas2r_data = dma_alloc_coherent(a-pcid-dev,
+  (size_t)mem_desc-
+  esas2r_param,
+  (dma_addr_t *)mem_desc-
+  phys_addr,
+  GFP_KERNEL);
+
+   if (mem_desc-esas2r_data == NULL) {
+   esas2r_log(ESAS2R_LOG_CRIT,
+  failed to allocate %lu bytes of consistent memory!,
+  (long
+   unsigned
+   int)mem_desc-esas2r_param);
+   return false;
+   }
+
+   mem_desc-virt_addr = PTR_ALIGN(mem_desc-esas2r_data, align);
+   mem_desc-phys_addr = ALIGN(mem_desc-phys_addr, align);
+   memset(mem_desc-virt_addr, 0, mem_desc-size);
+   return true;
+}
+
+static void esas2r_initmem_free(struct esas2r_adapter *a,
+   struct esas2r_mem_desc *mem_desc)
+{
+   if (mem_desc-virt_addr == NULL)
+   return;
+
+   /*
+* Careful!  phys_addr and virt_addr may have been adjusted from the
+* original allocation in order to return the desired alignment.  That
+* means we have to use the original address (in esas2r_data) and size
+* (esas2r_param) and calculate the original physical address based on
+* the difference between the requested and actual allocation size.
+*/
+   if (mem_desc-phys_addr) {
+   int unalign = ((u8 *)mem_desc-virt_addr) -
+ ((u8 *)mem_desc-esas2r_data);
+
+   dma_free_coherent(a-pcid-dev,
+ (size_t)mem_desc-esas2r_param,
+ mem_desc-esas2r_data,
+ (dma_addr_t)(mem_desc-phys_addr - unalign));
+   } else {
+   kfree(mem_desc-esas2r_data);
+   }
+
+   mem_desc

[PATCH v2 10/10] [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

2013-07-16 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 MAINTAINERS  | 7 +++
 drivers/scsi/Kconfig | 1 +
 drivers/scsi/Makefile| 1 +
 drivers/scsi/esas2r/Kconfig  | 6 ++
 drivers/scsi/esas2r/Makefile | 5 +
 5 files changed, 20 insertions(+)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index 50105f9..5f121dd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1540,6 +1540,13 @@ W:   http://atmelwlandriver.sourceforge.net/
 S: Maintained
 F: drivers/net/wireless/atmel*
 
+ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
+M:Bradley Grove linuxdriv...@attotech.com
+L:linux-scsi@vger.kernel.org
+W:http://www.attotech.com
+S:Supported
+F:drivers/scsi/esas2r
+
 AUDIT SUBSYSTEM
 M: Al Viro v...@zeniv.linux.org.uk
 M: Eric Paris epa...@redhat.com
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 48b2918..c298b76 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -601,6 +601,7 @@ config SCSI_ARCMSR
  To compile this driver as a module, choose M here: the
  module will be called arcmsr (modprobe arcmsr).
 
+source drivers/scsi/esas2r/Kconfig
 source drivers/scsi/megaraid/Kconfig.megaraid
 source drivers/scsi/mpt2sas/Kconfig
 source drivers/scsi/mpt3sas/Kconfig
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index b607ba4..149bb6b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -141,6 +141,7 @@ obj-$(CONFIG_SCSI_CXGB3_ISCSI)  += libiscsi.o 
libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_CXGB4_ISCSI) += libiscsi.o libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_BNX2_ISCSI)  += libiscsi.o bnx2i/
 obj-$(CONFIG_BE2ISCSI) += libiscsi.o be2iscsi/
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r/
 obj-$(CONFIG_SCSI_PMCRAID) += pmcraid.o
 obj-$(CONFIG_SCSI_VIRTIO)  += virtio_scsi.o
 obj-$(CONFIG_VMWARE_PVSCSI)+= vmw_pvscsi.o
diff --git a/drivers/scsi/esas2r/Kconfig b/drivers/scsi/esas2r/Kconfig
new file mode 100644
index 000..758ec48
--- /dev/null
+++ b/drivers/scsi/esas2r/Kconfig
@@ -0,0 +1,5 @@
+config SCSI_ESAS2R
+   tristate ATTO Technology's ExpressSAS RAID adapter driver
+   depends on PCI  SCSI  NET
+   ---help---
+ This driver supports the ATTO ExpressSAS R6xx SAS/SATA RAID 
controllers.
diff --git a/drivers/scsi/esas2r/Makefile b/drivers/scsi/esas2r/Makefile
new file mode 100644
index 000..c77160b
--- /dev/null
+++ b/drivers/scsi/esas2r/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r.o
+
+esas2r-objs := esas2r_log.o esas2r_disc.o esas2r_flash.o esas2r_init.o \
+esas2r_int.o esas2r_io.o esas2r_ioctl.o esas2r_targdb.o   \
+esas2r_vda.o esas2r_main.o
-- 
1.8.1.4

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


[PATCH 08/10] [RFC] SCSI: esas2r: Add IOCTL functions

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2110 
 1 file changed, 2110 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c 
b/drivers/scsi/esas2r/esas2r_ioctl.c
new file mode 100644
index 000..b2c5289
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -0,0 +1,2110 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_ioctl.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/*
+ * Buffered ioctl handlers.  A buffered ioctl is one which requires that we
+ * allocate a DMA-able memory area to communicate with the firmware.  In
+ * order to prevent continually allocating and freeing consistent memory,
+ * we will allocate a global buffer the first time we need it and re-use
+ * it for subsequent ioctl calls that require it.
+ */
+
+u8 *esas2r_buffered_ioctl;
+dma_addr_t esas2r_buffered_ioctl_addr;
+u32 esas2r_buffered_ioctl_size;
+struct pci_dev *esas2r_buffered_ioctl_pcid;
+
+static DEFINE_SEMAPHORE(buffered_ioctl_semaphore);
+typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *,
+  struct esas2r_request *,
+  struct esas2r_sg_context *,
+  void *);
+typedef void (*BUFFERED_IOCTL_DONE_CALLBACK)(struct esas2r_adapter *,
+struct esas2r_request *, void *);
+
+struct esas2r_buffered_ioctl {
+   struct esas2r_adapter *a;
+   void *ioctl;
+   u32 length;
+   u32 control_code;
+   u32 offset;
+   BUFFERED_IOCTL_CALLBACK
+   callback;
+   void *context;
+   BUFFERED_IOCTL_DONE_CALLBACK
+   done_callback;
+   void *done_context;
+
+};
+
+static void complete_fm_api_req(struct esas2r_adapter *a,
+   struct esas2r_request *rq)
+{
+   a-fm_api_command_done = 1;
+   wake_up_interruptible(a-fm_api_waiter);
+}
+
+/* Callbacks for building scatter/gather lists for FM API requests */
+static u32 get_physaddr_fm_api(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.phys + offset;
+   return a-firmware.orig_len - offset;
+}
+
+static u32 get_physaddr_fm_api_header(struct esas2r_sg_context *sgc, u64 *addr)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)sgc-adapter;
+   int offset = sgc-cur_offset - a-save_offset;
+
+   (*addr) = a-firmware.header_buff_phys + offset;
+   return sizeof(struct esas2r_flash_img) - offset;
+}
+
+/* Handle EXPRESS_IOCTL_RW_FIRMWARE ioctl with img_type = FW_IMG_FM_API. */
+static void do_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi

[PATCH 03/10] [RFC] SCSI: esas2r: Add initialization functions

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_init.c | 2019 +
 1 file changed, 2019 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
new file mode 100644
index 000..ec0386e
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -0,0 +1,2019 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_init.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)mpt3sas/mpt3sas_trigger_diag.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+#define ESAS2R_SGL_ALIGN16
+#define ESAS2R_LIST_ALIGN   16
+#define ESAS2R_LIST_EXTRA   ESAS2R_NUM_EXTRA
+
+static bool esas2r_initmem_alloc(struct esas2r_adapter *a,
+struct esas2r_mem_desc *mem_desc,
+u32 align)
+{
+   mem_desc-esas2r_param = mem_desc-size + align;
+   mem_desc-virt_addr = NULL;
+   mem_desc-phys_addr = 0;
+   mem_desc-esas2r_data = dma_alloc_coherent(a-pcid-dev,
+  (size_t)mem_desc-
+  esas2r_param,
+  (dma_addr_t *)mem_desc-
+  phys_addr,
+  GFP_KERNEL);
+
+   if (mem_desc-esas2r_data == NULL) {
+   esas2r_log(ESAS2R_LOG_CRIT,
+  failed to allocate %lu bytes of consistent memory!,
+  (long
+   unsigned
+   int)mem_desc-esas2r_param);
+   return false;
+   }
+
+   mem_desc-virt_addr = esas2r_align_addr(mem_desc-esas2r_data, align);
+   mem_desc-phys_addr = esas2r_align64(mem_desc-phys_addr, align);
+   memset(mem_desc-virt_addr, 0, mem_desc-size);
+   return true;
+}
+
+static bool alloc_vda_req(struct esas2r_adapter *a,
+ struct esas2r_request *rq)
+{
+   struct esas2r_mem_desc *memdesc = kzalloc(
+   sizeof(struct esas2r_mem_desc), GFP_ATOMIC);
+
+   if (memdesc == NULL) {
+   esas2r_hdebug(could not alloc mem for vda request memdesc\n);
+   return false;
+   }
+
+   memdesc-size = sizeof(union atto_vda_req) +
+   ESAS2R_DATA_BUF_LEN;
+
+   if (!esas2r_initmem_alloc(a, memdesc, 256)) {
+   esas2r_hdebug(could not alloc mem for vda request\n);
+   kfree(memdesc);
+   return false;
+   }
+
+   a-num_vrqs++;
+   memdesc-next_desc = a-vrq_mds;
+   rq-vrq_md = a-vrq_mds = memdesc;
+   rq-vrq = (union atto_vda_req *)memdesc-virt_addr;
+   rq-vrq-scsi.handle = a-num_vrqs;
+
+   return true;
+}
+
+static void esas2r_unmap_regions(struct esas2r_adapter

[PATCH 04/10] [RFC] SCSI: esas2r: Add device discovery and logging functions

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_disc.c | 1192 +
 drivers/scsi/esas2r/esas2r_log.c  |  255 
 drivers/scsi/esas2r/esas2r_log.h  |  118 
 3 files changed, 1565 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h

diff --git a/drivers/scsi/esas2r/esas2r_disc.c 
b/drivers/scsi/esas2r/esas2r_disc.c
new file mode 100644
index 000..6eae3c1
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_disc.c
@@ -0,0 +1,1191 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_disc.c
+ *  esas2r device discovery routines
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Miscellaneous internal discovery routines */
+static void esas2r_disc_abort(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_continue(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static void esas2r_disc_fix_curr_requests(struct esas2r_adapter *a);
+static u32 esas2r_disc_get_phys_addr(struct esas2r_sg_context *sgc, u64 *addr);
+static bool esas2r_disc_start_request(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+
+/* Internal discovery routines that process the states */
+static bool esas2r_disc_block_dev_scan(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static void esas2r_disc_block_dev_scan_cb(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static bool esas2r_disc_dev_add(struct esas2r_adapter *a,
+   struct esas2r_request *rq);
+static bool esas2r_disc_dev_remove(struct esas2r_adapter *a,
+  struct esas2r_request *rq);
+static bool esas2r_disc_part_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_part_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_info(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_info_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_passthru_dev_addr(struct esas2r_adapter *a,
+ struct esas2r_request *rq);
+static void esas2r_disc_passthru_dev_addr_cb(struct esas2r_adapter *a,
+struct esas2r_request *rq);
+static bool esas2r_disc_raid_grp_info(struct esas2r_adapter

[PATCH 05/10] [RFC] SCSI: esas2r: Add interrupt and IO functions

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_int.c | 935 +++
 drivers/scsi/esas2r/esas2r_io.c  | 886 +
 2 files changed, 1821 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c

diff --git a/drivers/scsi/esas2r/esas2r_int.c b/drivers/scsi/esas2r/esas2r_int.c
new file mode 100644
index 000..85624b5
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_int.c
@@ -0,0 +1,935 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_int.c
+ *  esas2r interrupt handling
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+#include esas2r.h
+
+/* Local function prototypes */
+static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell);
+static void esas2r_get_outbound_responses(struct esas2r_adapter *a);
+static void esas2r_process_bus_reset(struct esas2r_adapter *a);
+
+/*
+ * Poll the adapter for interrupts and service them.
+ * This function handles both legacy interrupts and MSI.
+ */
+void esas2r_polled_interrupt(struct esas2r_adapter *a)
+{
+   u32 intstat;
+   u32 doorbell;
+
+   esas2r_disable_chip_interrupts(a);
+
+   intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
+
+   if (intstat  MU_INTSTAT_POST_OUT) {
+   /* clear the interrupt */
+
+   esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT,
+   MU_OLIS_INT);
+   esas2r_flush_register_dword(a, MU_OUT_LIST_INT_STAT);
+
+   esas2r_get_outbound_responses(a);
+   }
+
+   if (intstat  MU_INTSTAT_DRBL) {
+   doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
+   if (doorbell != 0)
+   esas2r_doorbell_interrupt(a, doorbell);
+   }
+
+   esas2r_enable_chip_interrupts(a);
+
+   if (atomic_read(a-disable_cnt) == 0)
+   esas2r_do_deferred_processes(a);
+}
+
+/*
+ * Legacy and MSI interrupt handlers.  Note that the legacy interrupt handler
+ * schedules a DPC to process events, whereas the MSI handler just processes
+ * interrupt events directly.
+ */
+irqreturn_t esas2r_interrupt(int irq, void *dev_id)
+{
+   struct esas2r_adapter *a = (struct esas2r_adapter *)dev_id;
+
+   if (!esas2r_adapter_interrupt_pending(a))
+   return IRQ_NONE;
+
+   esas2r_lock_set_flags(a-flags2, AF2_INT_PENDING);
+   esas2r_schedule_dpc(a);
+
+   return IRQ_HANDLED;
+}
+
+void esas2r_adapter_interrupt(struct esas2r_adapter *a)
+{
+   u32 doorbell;
+
+   if (likely(a-int_stat  MU_INTSTAT_POST_OUT)) {
+   /* clear the interrupt */
+   esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT

[PATCH 01/10] [RFC] SCSI: esas2r: Add main header file

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r.h | 1755 ++
 1 file changed, 1755 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r.h

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
new file mode 100644
index 000..33b1f1c
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -0,0 +1,1755 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r.h
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include linux/kernel.h
+#include linux/delay.h
+#include linux/pci.h
+#include linux/proc_fs.h
+#include linux/workqueue.h
+#include linux/interrupt.h
+#include linux/module.h
+#include scsi/scsi.h
+#include scsi/scsi_host.h
+#include scsi/scsi_cmnd.h
+#include scsi/scsi_device.h
+#include scsi/scsi_eh.h
+#include scsi/scsi_tcq.h
+#include net/sock.h
+
+#include esas2r_log.h
+#include atioctl.h
+#include atvda.h
+
+#ifndef ESAS2R_H
+#define ESAS2R_H
+
+/* Global Variables */
+extern struct esas2r_adapter *esas2r_adapters[];
+extern u8 *esas2r_buffered_ioctl;
+extern dma_addr_t esas2r_buffered_ioctl_addr;
+extern u32 esas2r_buffered_ioctl_size;
+extern struct pci_dev *esas2r_buffered_ioctl_pcid;
+#define SGL_PG_SZ_MIN   64
+#define SGL_PG_SZ_MAX   1024
+extern int sgl_page_size;
+#define NUM_SGL_MIN 8
+#define NUM_SGL_MAX 2048
+extern int num_sg_lists;
+#define NUM_REQ_MIN 4
+#define NUM_REQ_MAX 256
+extern int num_requests;
+#define NUM_AE_MIN  2
+#define NUM_AE_MAX  8
+extern int num_ae_requests;
+extern int cmd_per_lun;
+extern int can_queue;
+extern int esas2r_max_sectors;
+extern int sg_tablesize;
+extern int interrupt_mode;
+extern int num_io_requests;
+
+/* Macro defintions */
+#define ESAS2R_MAX_ID255
+#define MAX_ADAPTERS 32
+#define ESAS2R_DRVR_NAME esas2r
+#define ESAS2R_LONGNAME  ATTO ExpressSAS 6GB RAID Adapter
+#define ESAS2R_MAX_DEVICES 32
+#define ATTONODE_NAME ATTONode
+#define ESAS2R_MAJOR_REV   1
+#define ESAS2R_MINOR_REV   00
+#define ESAS2R_VERSION_STR DEFINED_NUM_TO_STR(ESAS2R_MAJOR_REV) . \
+   DEFINED_NUM_TO_STR(ESAS2R_MINOR_REV)
+#define ESAS2R_COPYRIGHT_YEARS 2001-2013
+#define ESAS2R_DEFAULT_SGL_PAGE_SIZE 384
+#define ESAS2R_DEFAULT_CMD_PER_LUN   64
+#define ESAS2R_DEFAULT_NUM_SG_LISTS 1024
+#define DEFINED_NUM_TO_STR(num) NUM_TO_STR(num)
+#define NUM_TO_STR(num) #num
+#define PCIE_CAPABILITIES   0x70
+
+#define ESAS2R_DATA_BUF_LEN 256
+#define ESAS2R_DEFAULT_TMO  5000
+#define ESAS2R_DISC_BUF_LEN 512
+#define ESAS2R_FWCOREDUMP_SZ0x8
+#define ESAS2R_NUM_PHYS 8
+#define ESAS2R_PCI_CFG_SPACE_SZ 256
+#define ESAS2R_TARG_ID_INV  0x
+#define ESAS2R_INT_STS_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_ENB_MASK MU_INTSTAT_MASK
+#define ESAS2R_INT_DIS_MASK 0
+#define ESAS2R_MAX_TARGETS

[PATCH 00/10] [RFC] SCSI: esas2r: ATTO Technology ExpressSAS 6G SAS/SATA RAID Adapter Driver

2013-06-13 Thread Bradley Grove

This is a new driver for ATTO Technology's ExpressSAS series of hardware RAID 
adapters.  It supports the following adapters:

- ExpressSAS R60F
- ExpressSAS R680
- ExpressSAS R608
- ExpressSAS R644

This patch is split into ten parts to make reviewing easier.   You'll need to
apply all of them to get the complete patch.

We have done some testing under x86 and x64 architectures, but the code is 
still under development and we expect to find additional issues.  We appreciate
any review comments.

Bradley Grove (10):
  [RFC] SCSI: esas2r: Add main header file
  [RFC] SCSI: esas2r: Add main file
  [RFC] SCSI: esas2r: Add initialization functions
  [RFC] SCSI: esas2r: Add device discovery and logging functions
  [RFC] SCSI: esas2r: Add interrupt and IO functions
  [RFC] SCSI: esas2r: Add flash and target database functions
  [RFC] SCSI: esas2r: Add IOCTL header file
  [RFC] SCSI: esas2r: Add IOCTL functions
  [RFC] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. 
This API is used to control and manage the RAID adapter.
  [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

 MAINTAINERS |9 +-
 drivers/scsi/Kconfig|1 +
 drivers/scsi/Makefile   |1 +
 drivers/scsi/esas2r/Kconfig |6 +
 drivers/scsi/esas2r/Makefile|6 +
 drivers/scsi/esas2r/atioctl.h   | 1254 
 drivers/scsi/esas2r/atvda.h | 1327 +
 drivers/scsi/esas2r/esas2r.h| 1755 
 drivers/scsi/esas2r/esas2r_disc.c   | 1192 +++
 drivers/scsi/esas2r/esas2r_flash.c  | 1518 
 drivers/scsi/esas2r/esas2r_init.c   | 2019 
 drivers/scsi/esas2r/esas2r_int.c|  935 +++
 drivers/scsi/esas2r/esas2r_io.c |  886 ++
 drivers/scsi/esas2r/esas2r_ioctl.c  | 2110 +
 drivers/scsi/esas2r/esas2r_log.c|  255 
 drivers/scsi/esas2r/esas2r_log.h|  118 ++
 drivers/scsi/esas2r/esas2r_main.c   | 2177 +++
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +
 drivers/scsi/esas2r/esas2r_vda.c|  526 +
 19 files changed, 16400 insertions(+), 1 deletion(-)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile
 create mode 100644 drivers/scsi/esas2r/atioctl.h
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r.h
 create mode 100644 drivers/scsi/esas2r/esas2r_disc.c
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_init.c
 create mode 100644 drivers/scsi/esas2r/esas2r_int.c
 create mode 100644 drivers/scsi/esas2r/esas2r_io.c
 create mode 100644 drivers/scsi/esas2r/esas2r_ioctl.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.c
 create mode 100644 drivers/scsi/esas2r/esas2r_log.h
 create mode 100644 drivers/scsi/esas2r/esas2r_main.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

-- 
1.8.1.4

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


[PATCH 06/10] [RFC] SCSI: esas2r: Add flash and target database functions

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/esas2r_flash.c  | 1518 +++
 drivers/scsi/esas2r/esas2r_targdb.c |  306 +++
 2 files changed, 1824 insertions(+)
 create mode 100644 drivers/scsi/esas2r/esas2r_flash.c
 create mode 100644 drivers/scsi/esas2r/esas2r_targdb.c

diff --git a/drivers/scsi/esas2r/esas2r_flash.c 
b/drivers/scsi/esas2r/esas2r_flash.c
new file mode 100644
index 000..70a45d4
--- /dev/null
+++ b/drivers/scsi/esas2r/esas2r_flash.c
@@ -0,0 +1,1516 @@
+/*
+ *  linux/drivers/scsi/esas2r/esas2r_flash.c
+ *  For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * NO WARRANTY
+ * THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ * solely responsible for determining the appropriateness of using and
+ * distributing the Program and assumes all risks associated with its
+ * exercise of rights under this Agreement, including but not limited to
+ * the risks and costs of program errors, damage to or loss of data,
+ * programs or equipment, and unavailability or interruption of operations.
+ *
+ * DISCLAIMER OF LIABILITY
+ * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include esas2r.h
+
+/* local macro defs */
+#define esas2r_nvramcalc_cksum(n) \
+   (esas2r_calc_byte_cksum((u8 *)(n), sizeof(struct esas2r_sas_nvram), \
+   SASNVR_CKSUM_SEED))
+#define esas2r_nvramcalc_xor_cksum(n)  \
+   (esas2r_calc_byte_xor_cksum((u8 *)(n), \
+   sizeof(struct esas2r_sas_nvram), 0))
+
+#define ESAS2R_FS_DRVR_VER 2
+
+static struct esas2r_sas_nvram default_sas_nvram = {
+   { 'E',  'S',  'A',  'S' },  /* signature  */
+   SASNVR_VERSION, /* version*/
+   0,  /* checksum   */
+   31, /* max_lun_for_target */
+   SASNVR_PCILAT_MAX,  /* pci_latency*/
+   SASNVR1_BOOT_DRVR,  /* options1   */
+   SASNVR2_HEARTBEAT   | SASNVR2_SINGLE_BUS/* options2   */
+   | SASNVR2_SW_MUX_CTRL,
+   SASNVR_COAL_DIS,/* int_coalescing */
+   SASNVR_CMDTHR_NONE, /* cmd_throttle   */
+   3,  /* dev_wait_time  */
+   1,  /* dev_wait_count */
+   0,  /* spin_up_delay  */
+   0,  /* ssp_align_rate */
+   { 0x50, 0x01, 0x08, 0x60,   /* sas_addr   */
+ 0x00, 0x00, 0x00, 0x00 },
+   { SASNVR_SPEED_AUTO },  /* phy_speed  */
+   { SASNVR_MUX_DISABLED },/* SAS multiplexing   */
+   { 0 },  /* phy_flags  */
+   SASNVR_SORT_SAS_ADDR,   /* sort_type  */
+   3,  /* dpm_reqcmd_lmt */
+   3,  /* dpm_stndby_time*/
+   0,  /* dpm_active_time*/
+   { 0

[PATCH 09/10] [RFC] SCSI: esas2r: Add ATTO VDA Firmware API headers and functions. This API is used to control and manage the RAID adapter.

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 drivers/scsi/esas2r/atvda.h  | 1327 ++
 drivers/scsi/esas2r/esas2r_vda.c |  526 +++
 2 files changed, 1853 insertions(+)
 create mode 100644 drivers/scsi/esas2r/atvda.h
 create mode 100644 drivers/scsi/esas2r/esas2r_vda.c

diff --git a/drivers/scsi/esas2r/atvda.h b/drivers/scsi/esas2r/atvda.h
new file mode 100644
index 000..ab2ad29
--- /dev/null
+++ b/drivers/scsi/esas2r/atvda.h
@@ -0,0 +1,1326 @@
+/*  linux/drivers/scsi/esas2r/atvda.h
+ *   ATTO VDA interface definitions
+ *
+ *  Copyright (c) 2001-2013 ATTO Technology, Inc.
+ *  (mailto:linuxdriv...@attotech.com)
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  NO WARRANTY
+ *  THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR
+ *  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
+ *  LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
+ *  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
+ *  solely responsible for determining the appropriateness of using and
+ *  distributing the Program and assumes all risks associated with its
+ *  exercise of rights under this Agreement, including but not limited to
+ *  the risks and costs of program errors, damage to or loss of data,
+ *  programs or equipment, and unavailability or interruption of operations.
+ *
+ *  DISCLAIMER OF LIABILITY
+ *  NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
+ *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ *  DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
+ *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ *  USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+ *  HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+
+
+#ifndef ATVDA_H
+#define ATVDA_H
+
+struct __packed atto_dev_addr {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+  #define VDA_DEVADDRF_SATA   0x01
+  #define VDA_DEVADDRF_SSD0x02
+   u8 link_speed; /* VDALINKSPEED_xxx */
+   u8 pad[1];
+};
+
+/* dev_addr2 was added for 64-bit alignment */
+
+struct __packed atto_dev_addr2 {
+   u64 dev_port;
+   u64 hba_port;
+   u8 lun;
+   u8 flags;
+   u8 link_speed;
+   u8 pad[5];
+};
+
+struct __packed atto_vda_sge {
+   u32 length;
+   dma_addr_t address;
+};
+
+
+/* VDA request function codes */
+
+#define VDA_FUNC_SCSI 0x00
+#define VDA_FUNC_FLASH0x01
+#define VDA_FUNC_DIAG 0x02
+#define VDA_FUNC_AE   0x03
+#define VDA_FUNC_CLI  0x04
+#define VDA_FUNC_IOCTL0x05
+#define VDA_FUNC_CFG  0x06
+#define VDA_FUNC_MGT  0x07
+#define VDA_FUNC_GSV  0x08
+
+
+/* VDA request status values.  for host driver considerations, values for
+ * SCSI requests start at zero.  other requests may use these values as well. 
*/
+
+#define RS_SUCCESS  0x00/*! successful completion*/
+#define RS_INV_FUNC 0x01/*! invalid command function */
+#define RS_BUSY 0x02/*! insufficient resources   */
+#define RS_SEL  0x03/*! no target at target_id   */
+#define RS_NO_LUN   0x04/*! invalid LUN  */
+#define RS_TIMEOUT  0x05/*! request timeout  */
+#define RS_OVERRUN  0x06/*! data overrun */
+#define RS_UNDERRUN 0x07/*! data underrun*/
+#define RS_SCSI_ERROR   0x08/*! SCSI error occurred  */
+#define RS_ABORTED  0x0A/*! command aborted  */
+#define RS_RESID_MISM   0x0B/*! residual length incorrect*/
+#define RS_TM_FAILED0x0C/*! task management failed   */
+#define RS_RESET0x0D/*! aborted due to bus reset */
+#define RS_ERR_DMA_SG   0x0E/*! error reading SG

[PATCH 10/10] [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

2013-06-13 Thread Bradley Grove

Signed-off-by: Bradley Grove bgr...@attotech.com
---
 MAINTAINERS  | 9 -
 drivers/scsi/Kconfig | 1 +
 drivers/scsi/Makefile| 1 +
 drivers/scsi/esas2r/Kconfig  | 6 ++
 drivers/scsi/esas2r/Makefile | 6 ++
 5 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 drivers/scsi/esas2r/Kconfig
 create mode 100644 drivers/scsi/esas2r/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index 0c9dc71..e789b3f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1401,6 +1401,13 @@ W:   
http://wireless.kernel.org/en/users/Drivers/ath9k
 S: Supported
 F: drivers/net/wireless/ath/ath9k/
 
+ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
+M:Bradley Grove linuxdriv...@attotech.com
+L:linux-scsi@vger.kernel.org
+W:http://www.attotech.com
+S:Supported
+F:drivers/scsi/esas2r
+
 WILOCITY WIL6210 WIRELESS DRIVER
 M: Vladimir Kondratiev qca_vkond...@qca.qualcomm.com
 L: linux-wirel...@vger.kernel.org
@@ -5766,7 +5773,7 @@ M:Matthew Wilcox wi...@linux.intel.com
 L: linux-n...@lists.infradead.org
 T: git git://git.infradead.org/users/willy/linux-nvme.git
 S: Supported
-F: drivers/block/nvme*
+F: drivers/block/nvme.c
 F: include/linux/nvme.h
 
 OMAP SUPPORT
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 86af29f..846feea 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -601,6 +601,7 @@ config SCSI_ARCMSR
  To compile this driver as a module, choose M here: the
  module will be called arcmsr (modprobe arcmsr).
 
+source drivers/scsi/esas2r/Kconfig
 source drivers/scsi/megaraid/Kconfig.megaraid
 source drivers/scsi/mpt2sas/Kconfig
 source drivers/scsi/mpt3sas/Kconfig
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index b607ba4..149bb6b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -141,6 +141,7 @@ obj-$(CONFIG_SCSI_CXGB3_ISCSI)  += libiscsi.o 
libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_CXGB4_ISCSI) += libiscsi.o libiscsi_tcp.o cxgbi/
 obj-$(CONFIG_SCSI_BNX2_ISCSI)  += libiscsi.o bnx2i/
 obj-$(CONFIG_BE2ISCSI) += libiscsi.o be2iscsi/
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r/
 obj-$(CONFIG_SCSI_PMCRAID) += pmcraid.o
 obj-$(CONFIG_SCSI_VIRTIO)  += virtio_scsi.o
 obj-$(CONFIG_VMWARE_PVSCSI)+= vmw_pvscsi.o
diff --git a/drivers/scsi/esas2r/Kconfig b/drivers/scsi/esas2r/Kconfig
new file mode 100644
index 000..80824f0
--- /dev/null
+++ b/drivers/scsi/esas2r/Kconfig
@@ -0,0 +1,5 @@
+config SCSI_ESAS2R
+   tristate ATTO Technology's ExpressSAS RAID adapter driver
+   depends on PCI  SCSI
+   ---help---
+ This driver supports the ATTO ExpressSAS R6xx SAS/SATA RAID 
controllers.
diff --git a/drivers/scsi/esas2r/Makefile b/drivers/scsi/esas2r/Makefile
new file mode 100644
index 000..526d199
--- /dev/null
+++ b/drivers/scsi/esas2r/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_SCSI_ESAS2R)  += esas2r.o
+
+esas2r-objs := esas2r_log.o esas2r_disc.o esas2r_flash.o esas2r_init.o \
+esas2r_int.o esas2r_io.o esas2r_ioctl.o esas2r_targdb.o   \
+esas2r_vda.o esas2r_main.o
-- 
1.8.1.4

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


Re: [PATCH 10/10] [RFC] SCSI: esas2r: Add Makefile, Kconfig, and MAINTAINERS files

2013-06-13 Thread Bradley Grove

On 06/13/2013 11:50 AM, Jack Wang wrote:

  S: Supported
-F: drivers/block/nvme*
+F: drivers/block/nvme.c
  F: include/linux/nvme.h


I don't think you want to change this, it seems you are not generate
your patch set against scsi misc branch?

Regards,
Jack



I generated the patch from the kernel tree instead of the misc branch of 
the scsi tree.  I'll fix that when I spin the next patch.


Brad
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html