RE: [PATCH 09/39] megaraid_sas: NVME Interface detection and prop settings

2017-02-06 Thread Shivasharan Srikanteshwara
> -Original Message-
> From: Hannes Reinecke [mailto:h...@suse.com]
> Sent: Monday, February 06, 2017 4:17 PM
> To: Shivasharan S; linux-scsi@vger.kernel.org
> Cc: martin.peter...@oracle.com; the...@redhat.com;
> j...@linux.vnet.ibm.com; kashyap.de...@broadcom.com;
> sumit.sax...@broadcom.com
> Subject: Re: [PATCH 09/39] megaraid_sas: NVME Interface detection and
prop
> settings
>
> On 02/06/2017 10:59 AM, Shivasharan S wrote:
> > New functionality
> > Adding detection logic for NVME device attached behind Ventura
controller.
> > Driver set HostPageSize in IOC_INIT frame to inform about page size
for NVME
> devices.
> > Firmware reports NVME page size to the driver.
> > PD INFO DCMD provide new interface type NVME_PD. Driver set property
of
> NVME device.
> >
> > Signed-off-by: Shivasharan S <shivasharan.srikanteshw...@broadcom.com>
> > Signed-off-by: Kashyap Desai <kashyap.de...@broadcom.com>
> > ---
> >  drivers/scsi/megaraid/megaraid_sas.h|  23 ++--
> >  drivers/scsi/megaraid/megaraid_sas_base.c   | 170
--
> --
> >  drivers/scsi/megaraid/megaraid_sas_fusion.c |   6 +-
> >  drivers/scsi/megaraid/megaraid_sas_fusion.h |   2 +-
> >  4 files changed, 142 insertions(+), 59 deletions(-)
> >
> [ .. ]
> > @@ -3983,18 +4037,22 @@ dcmd_timeout_ocr_possible(struct
> megasas_instance *instance) {
> > return INITIATE_OCR;
> >  }
> >
> > -static int
> > -megasas_get_pd_info(struct megasas_instance *instance, u16 device_id)
> > +static void
> > +megasas_get_pd_info(struct megasas_instance *instance, struct
> > +scsi_device *sdev)
> >  {
> > int ret;
> > struct megasas_cmd *cmd;
> > struct megasas_dcmd_frame *dcmd;
> >
> > +   struct MR_PRIV_DEVICE *mr_device_priv_data;
> > +   u16 device_id = 0;
> > +
> > +   device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
> > +sdev->id;
> > cmd = megasas_get_cmd(instance);
> >
> > if (!cmd) {
> > dev_err(>pdev->dev, "Failed to get cmd %s\n",
> __func__);
> > -   return -ENOMEM;
> > +   return;
> > }
> >
> > dcmd = >frame->dcmd;
> > @@ -4021,7 +4079,9 @@ megasas_get_pd_info(struct megasas_instance
> > *instance, u16 device_id)
> >
> > switch (ret) {
> > case DCMD_SUCCESS:
> > -   instance->pd_list[device_id].interface =
> > +   mr_device_priv_data = sdev->hostdata;
> > +   le16_to_cpus((u16 *)>pd_info->state.ddf.pdType);
> > +   mr_device_priv_data->interface_type =
> > instance->pd_info->state.ddf.pdType.intf;
> > break;
> >
> > @@ -4048,7 +4108,7 @@ megasas_get_pd_info(struct megasas_instance
> *instance, u16 device_id)
> > if (ret != DCMD_TIMEOUT)
> > megasas_return_cmd(instance, cmd);
> >
> > -   return ret;
> > +   return;
> >  }
> >  /*
> >   * megasas_get_pd_list_info -  Returns FW's pd_list structure
> Please don't do this.
> There's a valid reason why there is return value in the first place (hot
removal of
> devices IIRC), and it's always good manners to provide for an error path
instead
> of assuming that everything will be fine.

megasas_get_pd_info is called to get "interface type" (SAS, SATA or NVME)
of non-RAID disks. The interface type is used in IO path (applicable only
for
NVME based non-RAID disks) and also used for setting the device queue
depth.
Even if this function returns some error, driver is not going to do
anything but
continue in low performance mode (for NVME based non-RAID disks driver
will
not form native PRPs and device QD will be set to default value).
>
> And, incidentally, this has nothing to do with the NVMe backend changes,
right?

The "interface type" tells the driver whether a drive is NVME based or
not. And
if NVME, then we form PRPs.

Thanks,
Shivasharan
>
> Cheers,
>
> Hannes
> --
> Dr. Hannes Reinecke  zSeries & Storage
> h...@suse.com+49 911 74053 688
> SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
> GF: F. Imendörffer, J. Smithard, D. Upmanyu, G. Norton HRB 21284 (AG
> Nürnberg)


Re: [PATCH 09/39] megaraid_sas: NVME Interface detection and prop settings

2017-02-06 Thread Hannes Reinecke
On 02/06/2017 10:59 AM, Shivasharan S wrote:
> New functionality
> Adding detection logic for NVME device attached behind Ventura controller.
> Driver set HostPageSize in IOC_INIT frame to inform about page size for NVME 
> devices.
> Firmware reports NVME page size to the driver.
> PD INFO DCMD provide new interface type NVME_PD. Driver set property of NVME 
> device.
> 
> Signed-off-by: Shivasharan S 
> Signed-off-by: Kashyap Desai 
> ---
>  drivers/scsi/megaraid/megaraid_sas.h|  23 ++--
>  drivers/scsi/megaraid/megaraid_sas_base.c   | 170 
> 
>  drivers/scsi/megaraid/megaraid_sas_fusion.c |   6 +-
>  drivers/scsi/megaraid/megaraid_sas_fusion.h |   2 +-
>  4 files changed, 142 insertions(+), 59 deletions(-)
> 
[ .. ]
> @@ -3983,18 +4037,22 @@ dcmd_timeout_ocr_possible(struct megasas_instance 
> *instance) {
>   return INITIATE_OCR;
>  }
>  
> -static int
> -megasas_get_pd_info(struct megasas_instance *instance, u16 device_id)
> +static void
> +megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device 
> *sdev)
>  {
>   int ret;
>   struct megasas_cmd *cmd;
>   struct megasas_dcmd_frame *dcmd;
>  
> + struct MR_PRIV_DEVICE *mr_device_priv_data;
> + u16 device_id = 0;
> +
> + device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
>   cmd = megasas_get_cmd(instance);
>  
>   if (!cmd) {
>   dev_err(>pdev->dev, "Failed to get cmd %s\n", 
> __func__);
> - return -ENOMEM;
> + return;
>   }
>  
>   dcmd = >frame->dcmd;
> @@ -4021,7 +4079,9 @@ megasas_get_pd_info(struct megasas_instance *instance, 
> u16 device_id)
>  
>   switch (ret) {
>   case DCMD_SUCCESS:
> - instance->pd_list[device_id].interface =
> + mr_device_priv_data = sdev->hostdata;
> + le16_to_cpus((u16 *)>pd_info->state.ddf.pdType);
> + mr_device_priv_data->interface_type =
>   instance->pd_info->state.ddf.pdType.intf;
>   break;
>  
> @@ -4048,7 +4108,7 @@ megasas_get_pd_info(struct megasas_instance *instance, 
> u16 device_id)
>   if (ret != DCMD_TIMEOUT)
>   megasas_return_cmd(instance, cmd);
>  
> - return ret;
> + return;
>  }
>  /*
>   * megasas_get_pd_list_info -Returns FW's pd_list structure
Please don't do this.
There's a valid reason why there is return value in the first place (hot
removal of devices IIRC), and it's always good manners to provide for an
error path instead of assuming that everything will be fine.

And, incidentally, this has nothing to do with the NVMe backend changes,
right?

Cheers,

Hannes
-- 
Dr. Hannes ReineckezSeries & Storage
h...@suse.com  +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


[PATCH 09/39] megaraid_sas: NVME Interface detection and prop settings

2017-02-06 Thread Shivasharan S
New functionality
Adding detection logic for NVME device attached behind Ventura controller.
Driver set HostPageSize in IOC_INIT frame to inform about page size for NVME 
devices.
Firmware reports NVME page size to the driver.
PD INFO DCMD provide new interface type NVME_PD. Driver set property of NVME 
device.

Signed-off-by: Shivasharan S 
Signed-off-by: Kashyap Desai 
---
 drivers/scsi/megaraid/megaraid_sas.h|  23 ++--
 drivers/scsi/megaraid/megaraid_sas_base.c   | 170 
 drivers/scsi/megaraid/megaraid_sas_fusion.c |   6 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.h |   2 +-
 4 files changed, 142 insertions(+), 59 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
b/drivers/scsi/megaraid/megaraid_sas.h
index dff877f..c5c55fe 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -733,7 +733,6 @@ struct megasas_pd_list {
u16 tid;
u8 driveType;
u8 driveState;
-   u8 interface;
 } __packed;
 
  /*
@@ -1530,8 +1529,8 @@ struct megasas_register_set {
u32 outbound_scratch_pad ;  /*00B0h*/
u32 outbound_scratch_pad_2; /*00B4h*/
u32 outbound_scratch_pad_3; /*00B8h*/
+   u32 outbound_scratch_pad_4; /*00BCh*/
 
-   u32 reserved_4; /*00BCh*/
 
u32 inbound_low_queue_port ;/*00C0h*/
 
@@ -1864,6 +1863,7 @@ union megasas_frame {
 struct MR_PRIV_DEVICE {
bool is_tm_capable;
bool tm_busy;
+   u8   interface_type;
 };
 struct megasas_cmd;
 
@@ -2055,17 +2055,24 @@ struct MR_DRV_SYSTEM_INFO {
 };
 
 enum MR_PD_TYPE {
-UNKNOWN_DRIVE = 0,
-PARALLEL_SCSI = 1,
-SAS_PD = 2,
-SATA_PD = 3,
-FC_PD = 4,
+   UNKNOWN_DRIVE = 0,
+   PARALLEL_SCSI = 1,
+   SAS_PD = 2,
+   SATA_PD = 3,
+   FC_PD = 4,
+   NVME_PD = 5,
 };
 
 /* JBOD Queue depth definitions */
 #define MEGASAS_SATA_QD32
 #define MEGASAS_SAS_QD 64
 #define MEGASAS_DEFAULT_PD_QD  64
+#define MEGASAS_NVME_QD32
+
+#define MR_DEFAULT_NVME_PAGE_SIZE  4096
+#define MR_DEFAULT_NVME_PAGE_SHIFT 12
+#define MR_DEFAULT_NVME_MDTS_KB128
+#define MR_NVME_PAGE_SIZE_MASK 0x00FF
 
 struct megasas_instance {
 
@@ -2209,6 +2216,7 @@ struct megasas_instance {
bool is_ventura;
bool msix_combined;
u16 max_raid_mapsize;
+   u32 nvme_page_size;
 };
 struct MR_LD_VF_MAP {
u32 size;
@@ -2428,6 +2436,7 @@ int megasas_get_ctrl_info(struct megasas_instance 
*instance);
 /* PD sequence */
 int
 megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend);
+void megasas_set_dynamic_target_properties(struct scsi_device *sdev);
 int megasas_set_crash_dump_params(struct megasas_instance *instance,
u8 crash_buf_state);
 void megasas_free_host_crash_buffer(struct megasas_instance *instance);
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 138d028..7b47109 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -116,8 +116,8 @@ static int megasas_ld_list_query(struct megasas_instance 
*instance,
 static int megasas_issue_init_mfi(struct megasas_instance *instance);
 static int megasas_register_aen(struct megasas_instance *instance,
u32 seq_num, u32 class_locale_word);
-static int
-megasas_get_pd_info(struct megasas_instance *instance, u16 device_id);
+static void megasas_get_pd_info(struct megasas_instance *instance,
+   struct scsi_device *sdev);
 /*
  * PCI ID table for all supported controllers
  */
@@ -1735,16 +1735,21 @@ static struct megasas_instance 
*megasas_lookup_instance(u16 host_no)
 }
 
 /*
-* megasas_update_sdev_properties - Update sdev structure based on controller's 
FW capabilities
+* megasas_set_dynamic_target_properties -
+* Device property set by driver may not be static and it is required to be
+* updated after OCR
+*
+* set tm_capable.
+* set dma alignment (only for eedp protection enable vd).
 *
 * @sdev: OS provided scsi device
 *
 * Returns void
 */
-void megasas_update_sdev_properties(struct scsi_device *sdev)
+void megasas_set_dynamic_target_properties(struct scsi_device *sdev)
 {
-   u16 pd_index = 0;
-   u32 device_id, ld;
+   u16 pd_index = 0, ld;
+   u32 device_id;
struct megasas_instance *instance;
struct fusion_context *fusion;
struct MR_PRIV_DEVICE *mr_device_priv_data;
@@ -1769,57 +1774,102 @@ void megasas_update_sdev_properties(struct scsi_device 
*sdev)
raid = MR_LdRaidGet(ld, local_map_ptr);
 
if (raid->capability.ldPiMode ==