Re: [PATCH 15/17 v2] lpfc: Synchronize link speed with boot driver

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:18PM -0700, James Smart wrote:
> 
> Synchronize link speed with boot driver
> 
> Link speed settings set by the boot driver are reported by the hw.
> Driver will attempt to read them, and if set, will respect their
> values.
> The driver can override the settings with its own if instructed by
> user space (via bsg), with the new values being picked up by the
> boot driver.
> 
> Signed-off-by: Dick Kennedy 
> Signed-off-by: James Smart 
> ---
>  drivers/scsi/lpfc/lpfc.h  |  4 
>  drivers/scsi/lpfc/lpfc_attr.c |  7 +-
>  drivers/scsi/lpfc/lpfc_bsg.c  | 44 +++
>  drivers/scsi/lpfc/lpfc_bsg.h  | 10 
>  drivers/scsi/lpfc/lpfc_hw4.h  |  3 +++
>  drivers/scsi/lpfc/lpfc_init.c | 54 
> +++
>  6 files changed, 121 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
> index debba5e..8a20b4e 100644
> --- a/drivers/scsi/lpfc/lpfc.h
> +++ b/drivers/scsi/lpfc/lpfc.h
> @@ -648,6 +648,10 @@ struct lpfc_hba {
>  #define HBA_FCP_IOQ_FLUSH0x8000 /* FCP I/O queues being flushed */
>  #define HBA_FW_DUMP_OP   0x1 /* Skips fn reset before FW 
> dump */
>  #define HBA_RECOVERABLE_UE   0x2 /* Firmware supports recoverable UE */
> +#define HBA_FORCED_LINK_SPEED0x4 /*
> +  * Firmware supports Forced Link Speed
> +  * capability
> +  */
>   uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
>   struct lpfc_dmabuf slim2p;
>  
> diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
> index 3740e5d..39ba01a 100644
> --- a/drivers/scsi/lpfc/lpfc_attr.c
> +++ b/drivers/scsi/lpfc/lpfc_attr.c
> @@ -3668,7 +3668,12 @@ lpfc_link_speed_store(struct device *dev, struct 
> device_attribute *attr,
>   int nolip = 0;
>   const char *val_buf = buf;
>   int err;
> - uint32_t prev_val;
> + uint32_t prev_val, if_type;
> +
> + if_type = bf_get(lpfc_sli_intf_if_type, >sli4_hba.sli_intf);
> + if ((if_type == LPFC_SLI_INTF_IF_TYPE_2) &&
> + (phba->hba_flag & HBA_FORCED_LINK_SPEED))

The parentheses aren't needed here.

> + return -EPERM;
>  
>   if (!strncmp(buf, "nolip ", strlen("nolip "))) {
>   nolip = 1;
> diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
> index 05dcc2a..f9f5972 100644
> --- a/drivers/scsi/lpfc/lpfc_bsg.c
> +++ b/drivers/scsi/lpfc/lpfc_bsg.c
> @@ -5185,6 +5185,47 @@ no_dd_data:
>   return rc;
>  }
>  
> +static int
> +lpfc_forced_link_speed(struct fc_bsg_job *job)

This has an unfortunate collision with my bsg rewrite series. Please remind me
of that fact when your patches are merged and mine aren't yet. But it's a
nice test case :-).

> +{
> + struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;

Please use shost_priv() here, or if you want to make my live easy 
struct Scsi_Host *shost = job->shost;
struct lpfc_vport *vport = shost_priv(shost);

Other than that,
Reviewed-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
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 15/17 v2] lpfc: Synchronize link speed with boot driver

2016-10-12 Thread James Smart

Synchronize link speed with boot driver

Link speed settings set by the boot driver are reported by the hw.
Driver will attempt to read them, and if set, will respect their
values.
The driver can override the settings with its own if instructed by
user space (via bsg), with the new values being picked up by the
boot driver.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
---
 drivers/scsi/lpfc/lpfc.h  |  4 
 drivers/scsi/lpfc/lpfc_attr.c |  7 +-
 drivers/scsi/lpfc/lpfc_bsg.c  | 44 +++
 drivers/scsi/lpfc/lpfc_bsg.h  | 10 
 drivers/scsi/lpfc/lpfc_hw4.h  |  3 +++
 drivers/scsi/lpfc/lpfc_init.c | 54 +++
 6 files changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index debba5e..8a20b4e 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -648,6 +648,10 @@ struct lpfc_hba {
 #define HBA_FCP_IOQ_FLUSH  0x8000 /* FCP I/O queues being flushed */
 #define HBA_FW_DUMP_OP 0x1 /* Skips fn reset before FW dump */
 #define HBA_RECOVERABLE_UE 0x2 /* Firmware supports recoverable UE */
+#define HBA_FORCED_LINK_SPEED  0x4 /*
+* Firmware supports Forced Link Speed
+* capability
+*/
uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
struct lpfc_dmabuf slim2p;
 
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 3740e5d..39ba01a 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -3668,7 +3668,12 @@ lpfc_link_speed_store(struct device *dev, struct 
device_attribute *attr,
int nolip = 0;
const char *val_buf = buf;
int err;
-   uint32_t prev_val;
+   uint32_t prev_val, if_type;
+
+   if_type = bf_get(lpfc_sli_intf_if_type, >sli4_hba.sli_intf);
+   if ((if_type == LPFC_SLI_INTF_IF_TYPE_2) &&
+   (phba->hba_flag & HBA_FORCED_LINK_SPEED))
+   return -EPERM;
 
if (!strncmp(buf, "nolip ", strlen("nolip "))) {
nolip = 1;
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 05dcc2a..f9f5972 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -5185,6 +5185,47 @@ no_dd_data:
return rc;
 }
 
+static int
+lpfc_forced_link_speed(struct fc_bsg_job *job)
+{
+   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_hba *phba = vport->phba;
+   struct forced_link_speed_support_reply *forced_reply;
+   int rc = 0;
+
+   if (job->request_len <
+   sizeof(struct fc_bsg_request) +
+   sizeof(struct get_forced_link_speed_support)) {
+   lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
+   "0048 Received FORCED_LINK_SPEED request "
+   "below minimum size\n");
+   rc = -EINVAL;
+   goto job_error;
+   }
+
+   forced_reply = (struct forced_link_speed_support_reply *)
+   job->reply->reply_data.vendor_reply.vendor_rsp;
+
+   if (job->reply_len <
+   sizeof(struct fc_bsg_request) +
+   sizeof(struct forced_link_speed_support_reply)) {
+   lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
+   "0049 Received FORCED_LINK_SPEED reply below "
+   "minimum size\n");
+   rc = -EINVAL;
+   goto job_error;
+   }
+
+   forced_reply->supported = (phba->hba_flag & HBA_FORCED_LINK_SPEED)
+  ? LPFC_FORCED_LINK_SPEED_SUPPORTED
+  : LPFC_FORCED_LINK_SPEED_NOT_SUPPORTED;
+job_error:
+   job->reply->result = rc;
+   if (rc == 0)
+   job->job_done(job);
+   return rc;
+}
+
 /**
  * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
  * @job: fc_bsg_job to handle
@@ -5227,6 +5268,9 @@ lpfc_bsg_hst_vendor(struct fc_bsg_job *job)
case LPFC_BSG_VENDOR_MENLO_DATA:
rc = lpfc_menlo_cmd(job);
break;
+   case LPFC_BSG_VENDOR_FORCED_LINK_SPEED:
+   rc = lpfc_forced_link_speed(job);
+   break;
default:
rc = -EINVAL;
job->reply->reply_payload_rcv_len = 0;
diff --git a/drivers/scsi/lpfc/lpfc_bsg.h b/drivers/scsi/lpfc/lpfc_bsg.h
index e557bcd..f2247aa 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.h
+++ b/drivers/scsi/lpfc/lpfc_bsg.h
@@ -35,6 +35,7 @@
 #define LPFC_BSG_VENDOR_MENLO_DATA 9
 #define LPFC_BSG_VENDOR_DIAG_MODE_END  10
 #define LPFC_BSG_VENDOR_LINK_DIAG_TEST 11
+#define LPFC_BSG_VENDOR_FORCED_LINK_SPEED  14
 
 struct set_ct_event {
uint32_t