Skip to contentSkip to conversation

pm80xx : Updates for the driver version 0.1.39.

PATCH In review Deepak Ukey 2 participants 11 messages Apr 13, 2020 – May 12, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover pm80xx : Updates for the driver version 0.1.39.

From: Deepak Ukey <[email protected]>

This patch set includes some bug fixes and features for pm80xx driver.

Viswas G (2):
pm80xx : Support for get phy profile functionality. pm80xx : Staggered spin up support.

peter chang (1):
pm80xx : Wait for PHY startup before draining libsas queue.

 drivers/scsi/pm8001/pm8001_ctl.c  |  36 ++++++
 drivers/scsi/pm8001/pm8001_ctl.h  |  27 ++++
 drivers/scsi/pm8001/pm8001_defs.h |   9 +-
 drivers/scsi/pm8001/pm8001_hwi.c  |  14 ++-
 drivers/scsi/pm8001/pm8001_init.c |  79 +++++++++++-
 drivers/scsi/pm8001/pm8001_sas.c  |  99 ++++++++++++++-
 drivers/scsi/pm8001/pm8001_sas.h  |  22 ++++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 252 +++++++++++++++++++++++++++++++++++---
 drivers/scsi/pm8001/pm80xx_hwi.h  |   2 +
 9 files changed, 509 insertions(+), 31 deletions(-)
Signature · 1 line
2.16.3
#1 lore raw

PATCH 1/3 pm80xx : Support for get phy profile functionality.

From: Viswas G <[email protected]>

Added the support to get the phy profile which gives information about the phy states, port and errors on phy.

---
 drivers/scsi/pm8001/pm8001_ctl.h  | 27 +++++++++++++
 drivers/scsi/pm8001/pm8001_init.c |  1 +
 drivers/scsi/pm8001/pm8001_sas.c  |  1 +
 drivers/scsi/pm8001/pm8001_sas.h  |  5 +++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 82 ++++++++++++++++++++++++++++++++++++++-
 drivers/scsi/pm8001/pm80xx_hwi.h  |  2 +
 6 files changed, 116 insertions(+), 2 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.h +27 -0
index d0d43a250b9e..5a1cbd54164c 100644
@@ -41,6 +41,33 @@
 #ifndef PM8001_CTL_H_INCLUDED
 #define PM8001_CTL_H_INCLUDED
 
+struct phy_profile {
+	char		phy_id;
+	unsigned int	phy_state:4;
+	unsigned int	nlr:4;
+	unsigned int	plr:4;
+	unsigned int	reserved1:12;
+	unsigned char	port_id;
+	unsigned int	prts:4;
+	unsigned int	reserved2:20;
+} __packed;
+
+struct phy_errcnt {
+	unsigned int	InvalidDword;
+	unsigned int	runningDisparityError;
+	unsigned int	codeViolation;
+	unsigned int	LossOfSyncDW;
+	unsigned int	phyResetProblem;
+	unsigned int	inboundCRCError;
+};
+
+struct phy_prof_resp {
+	union {
+		struct phy_profile status;
+		struct phy_errcnt errcnt;
+	} phy;
+};
+
 #define IOCTL_BUF_SIZE		4096
 #define HEADER_LEN			28
 #define SIZE_OFFSET			16
drivers/scsi/pm8001/pm8001_init.c +1 -0
index a8f5344fdfda..68005d0cb33d 100644
@@ -502,6 +502,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
 	else
 		pm8001_ha->iomb_size = IOMB_SIZE_SPC;
 
+	pm8001_ha->phyprofile_completion = NULL;
 #ifdef PM8001_USE_TASKLET
 	/* Tasklet for non msi-x interrupt handler */
 	if ((!pdev->msix_cap || !pci_msi_enabled())
drivers/scsi/pm8001/pm8001_sas.c +1 -0
index b7cbc312843e..3a69d8d1d52e 100644
@@ -283,6 +283,7 @@ int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
 	* is empirically about all it takes) */
 	if (time < HZ)
 		return 0;
+
 	/* Wait for discovery to finish */
 	sas_drain_work(ha);
 	return 1;
drivers/scsi/pm8001/pm8001_sas.h +5 -0
index ae7ba9b3c4bc..cba4e9b95c58 100644
@@ -56,6 +56,7 @@
 #include <scsi/sas_ata.h>
 #include <linux/atomic.h>
 #include "pm8001_defs.h"
+#include "pm8001_ctl.h"
 
 #define DRV_NAME		"pm80xx"
 #define DRV_VERSION		"0.1.39"
@@ -244,6 +245,8 @@ struct pm8001_dispatch {
 	int (*sas_diag_execute_req)(struct pm8001_hba_info *pm8001_ha,
 		u32 state);
 	int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha);
+	int (*get_phy_profile_req)(struct pm8001_hba_info *pm8001_ha,
+		int phy, int page);
 };
 
 struct pm8001_chip_info {
@@ -561,6 +564,8 @@ struct pm8001_hba_info {
 	u32			reset_in_progress;
 	u32			non_fatal_count;
 	u32			non_fatal_read_length;
+	struct completion	*phyprofile_completion;
+	struct phy_prof_resp	phy_profile_resp;
 };
 
 struct pm8001_work {
drivers/scsi/pm8001/pm80xx_hwi.c +80 -2

106 lines not on this page · raw message

drivers/scsi/pm8001/pm80xx_hwi.h +2 -0
index 701951a0f715..b5119c5479da 100644
@@ -175,7 +175,9 @@
 #define PHY_STOP_ERR_DEVICE_ATTACHED	0x1046
 
 /* phy_profile */
+#define SAS_PHY_ERR_COUNTERS_PAGE	0x01
 #define SAS_PHY_ANALOG_SETTINGS_PAGE	0x04
+#define SAS_PHY_GENERAL_STATUS_PAGE	0x05
 #define PHY_DWORD_LENGTH		0xC
 
 /* Thermal related */
Signature · 1 line
2.16.3
maintainer
#2 lore raw

Re: [PATCH 1/3] pm80xx : Support for get phy profile functionality.

Quoted 9 lines · Deepak Ukey

From: Viswas G <[email protected]>

Added the support to get the phy profile which gives information about the phy states, port and errors on phy.

Hi,

I failed to find where do you initialize the phyprofile_completion, did I miss something?

Thanks!
Jinpu

Quoted 232 lines
---
 drivers/scsi/pm8001/pm8001_ctl.h  | 27 +++++++++++++
 drivers/scsi/pm8001/pm8001_init.c |  1 +
 drivers/scsi/pm8001/pm8001_sas.c  |  1 +
 drivers/scsi/pm8001/pm8001_sas.h  |  5 +++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 82 ++++++++++++++++++++++++++++++++++++++-
 drivers/scsi/pm8001/pm80xx_hwi.h  |  2 +
 6 files changed, 116 insertions(+), 2 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.h +27 -0
index d0d43a250b9e..5a1cbd54164c 100644
@@ -41,6 +41,33 @@
 #ifndef PM8001_CTL_H_INCLUDED
 #define PM8001_CTL_H_INCLUDED
 
+struct phy_profile {
+       char            phy_id;
+       unsigned int    phy_state:4;
+       unsigned int    nlr:4;
+       unsigned int    plr:4;
+       unsigned int    reserved1:12;
+       unsigned char   port_id;
+       unsigned int    prts:4;
+       unsigned int    reserved2:20;
+} __packed;
+
+struct phy_errcnt {
+       unsigned int    InvalidDword;
+       unsigned int    runningDisparityError;
+       unsigned int    codeViolation;
+       unsigned int    LossOfSyncDW;
+       unsigned int    phyResetProblem;
+       unsigned int    inboundCRCError;
+};
+
+struct phy_prof_resp {
+       union {
+               struct phy_profile status;
+               struct phy_errcnt errcnt;
+       } phy;
+};
+
 #define IOCTL_BUF_SIZE         4096
 #define HEADER_LEN                     28
 #define SIZE_OFFSET                    16
drivers/scsi/pm8001/pm8001_init.c +1 -0
index a8f5344fdfda..68005d0cb33d 100644
@@ -502,6 +502,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
        else
                pm8001_ha->iomb_size = IOMB_SIZE_SPC;
 
+       pm8001_ha->phyprofile_completion = NULL;
 #ifdef PM8001_USE_TASKLET
        /* Tasklet for non msi-x interrupt handler */
        if ((!pdev->msix_cap || !pci_msi_enabled())
drivers/scsi/pm8001/pm8001_sas.c +1 -0
index b7cbc312843e..3a69d8d1d52e 100644
@@ -283,6 +283,7 @@ int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
        * is empirically about all it takes) */
        if (time < HZ)
                return 0;
+
        /* Wait for discovery to finish */
        sas_drain_work(ha);
        return 1;
drivers/scsi/pm8001/pm8001_sas.h +5 -0
index ae7ba9b3c4bc..cba4e9b95c58 100644
@@ -56,6 +56,7 @@
 #include <scsi/sas_ata.h>
 #include <linux/atomic.h>
 #include "pm8001_defs.h"
+#include "pm8001_ctl.h"
 
 #define DRV_NAME               "pm80xx"
 #define DRV_VERSION            "0.1.39"
@@ -244,6 +245,8 @@ struct pm8001_dispatch {
        int (*sas_diag_execute_req)(struct pm8001_hba_info *pm8001_ha,
                u32 state);
        int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha);
+       int (*get_phy_profile_req)(struct pm8001_hba_info *pm8001_ha,
+               int phy, int page);
 };
 
 struct pm8001_chip_info {
@@ -561,6 +564,8 @@ struct pm8001_hba_info {
        u32                     reset_in_progress;
        u32                     non_fatal_count;
        u32                     non_fatal_read_length;
+       struct completion       *phyprofile_completion;
+       struct phy_prof_resp    phy_profile_resp;
 };
 
 struct pm8001_work {
drivers/scsi/pm8001/pm80xx_hwi.c +80 -2
index 4d205ebaee87..0f4f18b0e480 100644
@@ -3792,7 +3792,6 @@ static int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
        PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
                        "SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
                        status, err_qlfr_pgcd));
-
        return 0;
 }
 
@@ -3818,9 +3817,59 @@ static int mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
 static int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
                        void *piomb)
 {
+       u32 tag, page_code;
+       struct phy_profile *phy_profile, *phy_prof;
+       struct phy_errcnt *phy_err, *phy_err_cnt;
+       struct get_phy_profile_resp *pPayload =
+               (struct get_phy_profile_resp *)(piomb + 4);
+       u32 status = le32_to_cpu(pPayload->status);
+
+       page_code = (u8)((pPayload->ppc_phyid & 0xFF00) >> 8);
+
        PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk(" pm80xx_addition_functionality\n"));
+               pm8001_printk(" pm80xx_addition_functionality\n"));
+       if (status) {
+               /* status is FAILED */
+               PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
+                       "mpiGetPhyProfileReq failed  with status 0x%08x\n",
+                       status));
+       }
 
+       tag = le32_to_cpu(pPayload->tag);
+       if (pm8001_ha->phyprofile_completion != NULL) {
+               if (status) {
+                       /* signal fail status */
+                       memset(&pm8001_ha->phy_profile_resp, 0xff,
+                                       sizeof(pm8001_ha->phy_profile_resp));
+               } else if (page_code == SAS_PHY_GENERAL_STATUS_PAGE) {
+                       phy_profile =
+                       (struct phy_profile *)&pm8001_ha->phy_profile_resp;
+                       phy_prof =
+                       (struct phy_profile *)pPayload->ppc_specific_rsp;
+                       phy_profile->phy_id = le32_to_cpu(phy_prof->phy_id);
+                       phy_profile->phy_state =
+                                       le32_to_cpu(phy_prof->phy_state);
+                       phy_profile->plr = le32_to_cpu(phy_prof->plr);
+                       phy_profile->nlr = le32_to_cpu(phy_prof->nlr);
+                       phy_profile->port_id = le32_to_cpu(phy_prof->port_id);
+                       phy_profile->prts = le32_to_cpu(phy_prof->prts);
+               } else if (page_code == SAS_PHY_ERR_COUNTERS_PAGE) {
+                       phy_err =
+                       (struct phy_errcnt *)&pm8001_ha->phy_profile_resp;
+                       phy_err_cnt =
+                       (struct phy_errcnt *)pPayload->ppc_specific_rsp;
+                       phy_err->InvalidDword =
+                       le32_to_cpu(phy_err_cnt->InvalidDword);
+                       phy_err->runningDisparityError =
+                       le32_to_cpu(phy_err_cnt->runningDisparityError);
+                       phy_err->LossOfSyncDW =
+                       le32_to_cpu(phy_err_cnt->LossOfSyncDW);
+                       phy_err->phyResetProblem =
+                       le32_to_cpu(phy_err_cnt->phyResetProblem);
+               }
+               complete(pm8001_ha->phyprofile_completion);
+       }
+       pm8001_tag_free(pm8001_ha, tag);
        return 0;
 }
 
@@ -5013,6 +5062,34 @@ pm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
        return IRQ_HANDLED;
 }
 
+int pm8001_chip_get_phy_profile(struct pm8001_hba_info *pm8001_ha,
+               int phy_id, int page_code)
+{
+
+       u32 tag;
+       struct get_phy_profile_req payload;
+       struct inbound_queue_table *circularQ;
+       int rc, ppc_phyid;
+       u32 opc = OPC_INB_GET_PHY_PROFILE;
+
+       memset(&payload, 0, sizeof(payload));
+
+       rc = pm8001_tag_alloc(pm8001_ha, &tag);
+       if (rc)
+               PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Invalid tag\n"));
+
+       circularQ = &pm8001_ha->inbnd_q_tbl[0];
+
+       payload.tag = cpu_to_le32(tag);
+       ppc_phyid = (page_code & 0xFF)  << 8 | (phy_id & 0xFF);
+       payload.ppc_phyid = cpu_to_le32(ppc_phyid);
+
+       pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
+                       sizeof(payload), 0);
+
+       return rc;
+}
+
 void mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
        u32 operation, u32 phyid, u32 length, u32 *buf)
 {
@@ -5113,4 +5190,5 @@ const struct pm8001_dispatch pm8001_80xx_dispatch = {
        .set_nvmd_req           = pm8001_chip_set_nvmd_req,
        .fw_flash_update_req    = pm8001_chip_fw_flash_update_req,
        .set_dev_state_req      = pm8001_chip_set_dev_state_req,
+       .get_phy_profile_req    = pm8001_chip_get_phy_profile,
 };
drivers/scsi/pm8001/pm80xx_hwi.h +2 -1
index 701951a0f715..b5119c5479da 100644
@@ -175,7 +175,9 @@
 #define PHY_STOP_ERR_DEVICE_ATTACHED   0x1046
 
 /* phy_profile */
+#define SAS_PHY_ERR_COUNTERS_PAGE      0x01
 #define SAS_PHY_ANALOG_SETTINGS_PAGE   0x04
+#define SAS_PHY_GENERAL_STATUS_PAGE    0x05
 #define PHY_DWORD_LENGTH               0xC
 
 /* Thermal related */
--

2.16.3

#3 lore raw

RE: [PATCH 1/3] pm80xx : Support for get phy profile functionality.

Hi,

I failed to find where do you initialize the phyprofile_completion, did I miss something? [DU] We will initalize phyprofile_completion in this patch itself.

Thanks,
Deepak

Quoted 8 lines

From: Viswas G <[email protected]>

Added the support to get the phy profile which gives information about the phy states, port and errors on phy.

Hi,

I failed to find where do you initialize the phyprofile_completion, did I miss something?

Thanks!
Jinpu

Quoted 237 lines
---
 drivers/scsi/pm8001/pm8001_ctl.h  | 27 +++++++++++++  
drivers/scsi/pm8001/pm8001_init.c |  1 +  
drivers/scsi/pm8001/pm8001_sas.c  |  1 +  
drivers/scsi/pm8001/pm8001_sas.h  |  5 +++  
drivers/scsi/pm8001/pm80xx_hwi.c  | 82 
++++++++++++++++++++++++++++++++++++++-
 drivers/scsi/pm8001/pm80xx_hwi.h  |  2 +
 6 files changed, 116 insertions(+), 2 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.h +27 -0
index d0d43a250b9e..5a1cbd54164c 100644
@@ -41,6 +41,33 @@
 #ifndef PM8001_CTL_H_INCLUDED
 #define PM8001_CTL_H_INCLUDED
 
+struct phy_profile {
+       char            phy_id;
+       unsigned int    phy_state:4;
+       unsigned int    nlr:4;
+       unsigned int    plr:4;
+       unsigned int    reserved1:12;
+       unsigned char   port_id;
+       unsigned int    prts:4;
+       unsigned int    reserved2:20;
+} __packed;
+
+struct phy_errcnt {
+       unsigned int    InvalidDword;
+       unsigned int    runningDisparityError;
+       unsigned int    codeViolation;
+       unsigned int    LossOfSyncDW;
+       unsigned int    phyResetProblem;
+       unsigned int    inboundCRCError;
+};
+
+struct phy_prof_resp {
+       union {
+               struct phy_profile status;
+               struct phy_errcnt errcnt;
+       } phy;
+};
+
 #define IOCTL_BUF_SIZE         4096
 #define HEADER_LEN                     28
 #define SIZE_OFFSET                    16
drivers/scsi/pm8001/pm8001_init.c +1 -0
index a8f5344fdfda..68005d0cb33d 100644
@@ -502,6 +502,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
        else
                pm8001_ha->iomb_size = IOMB_SIZE_SPC;
 
+       pm8001_ha->phyprofile_completion = NULL;
 #ifdef PM8001_USE_TASKLET
        /* Tasklet for non msi-x interrupt handler */
        if ((!pdev->msix_cap || !pci_msi_enabled()) diff --git 

a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c index b7cbc312843e..3a69d8d1d52e 100644

drivers/scsi/pm8001/pm8001_sas.c +1 -0
@@ -283,6 +283,7 @@ int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
        * is empirically about all it takes) */
        if (time < HZ)
                return 0;
+
        /* Wait for discovery to finish */
        sas_drain_work(ha);
        return 1;
drivers/scsi/pm8001/pm8001_sas.h +5 -0
index ae7ba9b3c4bc..cba4e9b95c58 100644
@@ -56,6 +56,7 @@
 #include <scsi/sas_ata.h>
 #include <linux/atomic.h>
 #include "pm8001_defs.h"
+#include "pm8001_ctl.h"
 
 #define DRV_NAME               "pm80xx"
 #define DRV_VERSION            "0.1.39"
@@ -244,6 +245,8 @@ struct pm8001_dispatch {
        int (*sas_diag_execute_req)(struct pm8001_hba_info *pm8001_ha,
                u32 state);
        int (*sas_re_init_req)(struct pm8001_hba_info *pm8001_ha);
+       int (*get_phy_profile_req)(struct pm8001_hba_info *pm8001_ha,
+               int phy, int page);
 };
 
 struct pm8001_chip_info {
@@ -561,6 +564,8 @@ struct pm8001_hba_info {
        u32                     reset_in_progress;
        u32                     non_fatal_count;
        u32                     non_fatal_read_length;
+       struct completion       *phyprofile_completion;
+       struct phy_prof_resp    phy_profile_resp;
 };
 
 struct pm8001_work {
drivers/scsi/pm8001/pm80xx_hwi.c +81 -2
index 4d205ebaee87..0f4f18b0e480 100644
@@ -3792,7 +3792,6 @@ static int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
        PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
                        "SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
                        status, err_qlfr_pgcd));
-
        return 0;
 }
 
@@ -3818,9 +3817,59 @@ static int 
 mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,  static int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
                        void *piomb)
 {
+       u32 tag, page_code;
+       struct phy_profile *phy_profile, *phy_prof;
+       struct phy_errcnt *phy_err, *phy_err_cnt;
+       struct get_phy_profile_resp *pPayload =
+               (struct get_phy_profile_resp *)(piomb + 4);
+       u32 status = le32_to_cpu(pPayload->status);
+
+       page_code = (u8)((pPayload->ppc_phyid & 0xFF00) >> 8);
+
        PM8001_MSG_DBG(pm8001_ha,
-                       pm8001_printk(" pm80xx_addition_functionality\n"));
+               pm8001_printk(" pm80xx_addition_functionality\n"));
+       if (status) {
+               /* status is FAILED */
+               PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
+                       "mpiGetPhyProfileReq failed  with status 0x%08x\n",
+                       status));
+       }
 
+       tag = le32_to_cpu(pPayload->tag);
+       if (pm8001_ha->phyprofile_completion != NULL) {
+               if (status) {
+                       /* signal fail status */
+                       memset(&pm8001_ha->phy_profile_resp, 0xff,
+                                       sizeof(pm8001_ha->phy_profile_resp));
+               } else if (page_code == SAS_PHY_GENERAL_STATUS_PAGE) {
+                       phy_profile =
+                       (struct phy_profile *)&pm8001_ha->phy_profile_resp;
+                       phy_prof =
+                       (struct phy_profile *)pPayload->ppc_specific_rsp;
+                       phy_profile->phy_id = le32_to_cpu(phy_prof->phy_id);
+                       phy_profile->phy_state =
+                                       le32_to_cpu(phy_prof->phy_state);
+                       phy_profile->plr = le32_to_cpu(phy_prof->plr);
+                       phy_profile->nlr = le32_to_cpu(phy_prof->nlr);
+                       phy_profile->port_id = le32_to_cpu(phy_prof->port_id);
+                       phy_profile->prts = le32_to_cpu(phy_prof->prts);
+               } else if (page_code == SAS_PHY_ERR_COUNTERS_PAGE) {
+                       phy_err =
+                       (struct phy_errcnt *)&pm8001_ha->phy_profile_resp;
+                       phy_err_cnt =
+                       (struct phy_errcnt *)pPayload->ppc_specific_rsp;
+                       phy_err->InvalidDword =
+                       le32_to_cpu(phy_err_cnt->InvalidDword);
+                       phy_err->runningDisparityError =
+                       le32_to_cpu(phy_err_cnt->runningDisparityError);
+                       phy_err->LossOfSyncDW =
+                       le32_to_cpu(phy_err_cnt->LossOfSyncDW);
+                       phy_err->phyResetProblem =
+                       le32_to_cpu(phy_err_cnt->phyResetProblem);
+               }
+               complete(pm8001_ha->phyprofile_completion);
+       }
+       pm8001_tag_free(pm8001_ha, tag);
        return 0;
 }
 
@@ -5013,6 +5062,34 @@ pm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
        return IRQ_HANDLED;
 }
 
+int pm8001_chip_get_phy_profile(struct pm8001_hba_info *pm8001_ha,
+               int phy_id, int page_code) {
+
+       u32 tag;
+       struct get_phy_profile_req payload;
+       struct inbound_queue_table *circularQ;
+       int rc, ppc_phyid;
+       u32 opc = OPC_INB_GET_PHY_PROFILE;
+
+       memset(&payload, 0, sizeof(payload));
+
+       rc = pm8001_tag_alloc(pm8001_ha, &tag);
+       if (rc)
+               PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Invalid 
+ tag\n"));
+
+       circularQ = &pm8001_ha->inbnd_q_tbl[0];
+
+       payload.tag = cpu_to_le32(tag);
+       ppc_phyid = (page_code & 0xFF)  << 8 | (phy_id & 0xFF);
+       payload.ppc_phyid = cpu_to_le32(ppc_phyid);
+
+       pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
+                       sizeof(payload), 0);
+
+       return rc;
+}
+
 void mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
        u32 operation, u32 phyid, u32 length, u32 *buf)  { @@ -5113,4 
+5190,5 @@ const struct pm8001_dispatch pm8001_80xx_dispatch = {
        .set_nvmd_req           = pm8001_chip_set_nvmd_req,
        .fw_flash_update_req    = pm8001_chip_fw_flash_update_req,
        .set_dev_state_req      = pm8001_chip_set_dev_state_req,
+       .get_phy_profile_req    = pm8001_chip_get_phy_profile,
 };
drivers/scsi/pm8001/pm80xx_hwi.h +2 -1
index 701951a0f715..b5119c5479da 100644
@@ -175,7 +175,9 @@
 #define PHY_STOP_ERR_DEVICE_ATTACHED   0x1046
 
 /* phy_profile */
+#define SAS_PHY_ERR_COUNTERS_PAGE      0x01
 #define SAS_PHY_ANALOG_SETTINGS_PAGE   0x04
+#define SAS_PHY_GENERAL_STATUS_PAGE    0x05
 #define PHY_DWORD_LENGTH               0xC
 
 /* Thermal related */
--

2.16.3

#4 lore raw

PATCH 2/3 pm80xx : Staggered spin up support.

In reply to Deepak Ukey

From: Viswas G <[email protected]>

As a part of drive discovery, driver will initaite the drive spin up. If all drives do spin up together, it will result in large power consumption. To reduce the power consumption, driver provide an option to make a small group of drives (say 3 or 4 drives together) to do the spin up. The delay between two spin up group and no of drives to spin up (group) can be programmed by the customer in seeprom and driver will use it to control the spinup.

---
 drivers/scsi/pm8001/pm8001_defs.h |   3 +
 drivers/scsi/pm8001/pm8001_hwi.c  |  14 ++++-
 drivers/scsi/pm8001/pm8001_init.c |  53 +++++++++++++++-
 drivers/scsi/pm8001/pm8001_sas.c  |  37 ++++++++++-
 drivers/scsi/pm8001/pm8001_sas.h  |  14 +++++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 125 +++++++++++++++++++++++++++++++++-----
 6 files changed, 223 insertions(+), 23 deletions(-)
drivers/scsi/pm8001/pm8001_defs.h +3 -0
index 1c7f15fd69ce..fd700ce5e80c 100644
@@ -101,6 +101,9 @@ enum port_type {
 #define USI_MAX_MEMCNT		(PI + PM8001_MAX_SPCV_OUTB_NUM)
 #define	CONFIG_SCSI_PM8001_MAX_DMA_SG	528
 #define PM8001_MAX_DMA_SG	CONFIG_SCSI_PM8001_MAX_DMA_SG
+#define SPINUP_DELAY_OFFSET		0x890 /* 0x890 - delay */
+#define SPINUP_GROUP_OFFSET		0x892 /* 0x892 - group */
+#define PM80XX_MAX_SPINUP_DELAY	10000 /* 10000 ms */
 enum memory_region_num {
 	AAP1 = 0x0, /* application acceleration processor */
 	IOP,	    /* IO processor */
drivers/scsi/pm8001/pm8001_hwi.c +12 -2
index fb9848e1d481..6378c8e8d6b2 100644
@@ -3237,7 +3237,7 @@ int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
 		(struct local_phy_ctl_resp *)(piomb + 4);
 	u32 status = le32_to_cpu(pPayload->status);
 	u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
-	u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
+	u32 phy_op = (le32_to_cpu(pPayload->phyop_phyid) & OP_BITS) >> 8;
 	tag = le32_to_cpu(pPayload->tag);
 	if (status != 0) {
 		PM8001_MSG_DBG(pm8001_ha,
@@ -3248,6 +3248,13 @@ int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
 			pm8001_printk("%x phy execute %x phy op success!\n",
 			phy_id, phy_op));
 		pm8001_ha->phy[phy_id].reset_success = true;
+		if (phy_op == PHY_NOTIFY_ENABLE_SPINUP &&
+			!pm8001_ha->reset_in_progress){
+			/* Notify the sas layer to discover
+			 * the the whole sas domain
+			 */
+			pm8001_bytes_dmaed(pm8001_ha, phy_id);
+		}
 	}
 	if (pm8001_ha->phy[phy_id].enable_completion) {
 		complete(pm8001_ha->phy[phy_id].enable_completion);
@@ -3643,7 +3650,10 @@ int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
 			pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n"));
 		break;
 	}
-	complete(pm8001_dev->dcompletion);
+	if (pm8001_dev->dcompletion) {
+		complete(pm8001_dev->dcompletion);
+		pm8001_dev->dcompletion = NULL;
+	}
 	ccb->task = NULL;
 	ccb->ccb_tag = 0xFFFFFFFF;
 	pm8001_tag_free(pm8001_ha, htag);
drivers/scsi/pm8001/pm8001_init.c +50 -3

89 lines not on this page · raw message

drivers/scsi/pm8001/pm8001_sas.c +35 -2
index 3a69d8d1d52e..806845203602 100644
@@ -267,12 +267,38 @@ void pm8001_scan_start(struct Scsi_Host *shost)
 	int i;
 	struct pm8001_hba_info *pm8001_ha;
 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+	DECLARE_COMPLETION(comp);
 	pm8001_ha = sha->lldd_ha;
 	/* SAS_RE_INITIALIZATION not available in SPCv/ve */
 	if (pm8001_ha->chip_id == chip_8001)
 		PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha);
-	for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
-		PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+
+	if (pm8001_ha->pdev->device == 0x8001 ||
+		pm8001_ha->pdev->device == 0x8081 ||
+		(pm8001_ha->spinup_interval != 0)) {
+		for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
+			PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+	} else {
+		for (i = 0; i < pm8001_ha->chip->n_phy; ++i) {
+			spin_lock_irqsave(&pm8001_ha->lock,
+				pm8001_ha->lock_flags);
+			pm8001_ha->phy_started = i;
+			pm8001_ha->scan_completion = &comp;
+			pm8001_ha->phystart_timedout = 1;
+			spin_unlock_irqrestore(&pm8001_ha->lock,
+				pm8001_ha->lock_flags);
+			PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+			wait_for_completion_timeout(&comp,
+				msecs_to_jiffies(500));
+			if (pm8001_ha->phystart_timedout)
+				PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+				"Timeout happened for phyid = %d\n", i));
+		}
+		spin_lock_irqsave(&pm8001_ha->lock, pm8001_ha->lock_flags);
+		pm8001_ha->phy_started = -1;
+		pm8001_ha->scan_completion = NULL;
+		spin_unlock_irqrestore(&pm8001_ha->lock, pm8001_ha->lock_flags);
+	}
 }
 
 int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
@@ -663,6 +689,13 @@ static int pm8001_dev_found_notify(struct domain_device *dev)
 			flag = 1; /* directly sata */
 		}
 	} /*register this device to HBA*/
+
+	if (pm8001_ha->phy_started == pm8001_device->attached_phy) {
+		if (pm8001_ha->scan_completion != NULL) {
+			pm8001_ha->phystart_timedout = 0;
+			complete(pm8001_ha->scan_completion);
+		}
+	}
 	PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device\n"));
 	PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
 	spin_unlock_irqrestore(&pm8001_ha->lock, flags);
drivers/scsi/pm8001/pm8001_sas.h +14 -0
index cba4e9b95c58..df02c6cd116a 100644
@@ -261,6 +261,7 @@ struct pm8001_port {
 	u8			port_attached;
 	u16			wide_port_phymap;
 	u8			port_state;
+	u8			port_id;
 	struct list_head	list;
 };
 
@@ -503,6 +504,7 @@ struct pm8001_hba_info {
 	unsigned long		flags;
 	spinlock_t		lock;/* host-wide lock */
 	spinlock_t		bitmap_lock;
+	unsigned long		lock_flags;
 	struct pci_dev		*pdev;/* our device */
 	struct device		*dev;
 	struct pm8001_hba_memspace io_mem[6];
@@ -566,6 +568,17 @@ struct pm8001_hba_info {
 	u32			non_fatal_read_length;
 	struct completion	*phyprofile_completion;
 	struct phy_prof_resp	phy_profile_resp;
+	bool			staggered_spinup;
+	struct completion	*scan_completion;
+	u32			phy_started;
+	u16			phystart_timedout;
+	int			spinup_group;
+	int			spinup_interval;
+	int			phy_up[PM8001_MAX_PHYS];
+	struct timer_list	spinup_timer;
+	int			phy_head;
+	int			phy_tail;
+	spinlock_t		phy_q_lock;
 };
 
 struct pm8001_work {
@@ -684,6 +697,7 @@ void pm8001_open_reject_retry(
 int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
 	dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo,
 	u32 mem_size, u32 align);
+void pm8001_spinup_timedout(struct timer_list *t);
 
 void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha);
 int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
drivers/scsi/pm8001/pm80xx_hwi.c +109 -16

201 lines not on this page · raw message

Signature · 1 line
2.16.3
maintainer
#5 lore raw

Re: [PATCH 2/3] pm80xx : Staggered spin up support.

Quoted 247 lines · Deepak Ukey

From: Viswas G <[email protected]>

As a part of drive discovery, driver will initaite the drive spin up. If all drives do spin up together, it will result in large power consumption. To reduce the power consumption, driver provide an option to make a small group of drives (say 3 or 4 drives together) to do the spin up. The delay between two spin up group and no of drives to spin up (group) can be programmed by the customer in seeprom and driver will use it to control the spinup.

---
 drivers/scsi/pm8001/pm8001_defs.h |   3 +
 drivers/scsi/pm8001/pm8001_hwi.c  |  14 ++++-
 drivers/scsi/pm8001/pm8001_init.c |  53 +++++++++++++++-
 drivers/scsi/pm8001/pm8001_sas.c  |  37 ++++++++++-
 drivers/scsi/pm8001/pm8001_sas.h  |  14 +++++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 125 +++++++++++++++++++++++++++++++++-----
 6 files changed, 223 insertions(+), 23 deletions(-)
drivers/scsi/pm8001/pm8001_defs.h +3 -0
index 1c7f15fd69ce..fd700ce5e80c 100644
@@ -101,6 +101,9 @@ enum port_type {
 #define USI_MAX_MEMCNT         (PI + PM8001_MAX_SPCV_OUTB_NUM)
 #define        CONFIG_SCSI_PM8001_MAX_DMA_SG   528
 #define PM8001_MAX_DMA_SG      CONFIG_SCSI_PM8001_MAX_DMA_SG
+#define SPINUP_DELAY_OFFSET            0x890 /* 0x890 - delay */
+#define SPINUP_GROUP_OFFSET            0x892 /* 0x892 - group */
+#define PM80XX_MAX_SPINUP_DELAY        10000 /* 10000 ms */
 enum memory_region_num {
        AAP1 = 0x0, /* application acceleration processor */
        IOP,        /* IO processor */
drivers/scsi/pm8001/pm8001_hwi.c +12 -2
index fb9848e1d481..6378c8e8d6b2 100644
@@ -3237,7 +3237,7 @@ int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
                (struct local_phy_ctl_resp *)(piomb + 4);
        u32 status = le32_to_cpu(pPayload->status);
        u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
-       u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
+       u32 phy_op = (le32_to_cpu(pPayload->phyop_phyid) & OP_BITS) >> 8;
        tag = le32_to_cpu(pPayload->tag);
        if (status != 0) {
                PM8001_MSG_DBG(pm8001_ha,
@@ -3248,6 +3248,13 @@ int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
                        pm8001_printk("%x phy execute %x phy op success!\n",
                        phy_id, phy_op));
                pm8001_ha->phy[phy_id].reset_success = true;
+               if (phy_op == PHY_NOTIFY_ENABLE_SPINUP &&
+                       !pm8001_ha->reset_in_progress){
+                       /* Notify the sas layer to discover
+                        * the the whole sas domain
+                        */
+                       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+               }
        }
        if (pm8001_ha->phy[phy_id].enable_completion) {
                complete(pm8001_ha->phy[phy_id].enable_completion);
@@ -3643,7 +3650,10 @@ int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
                        pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n"));
                break;
        }
-       complete(pm8001_dev->dcompletion);
+       if (pm8001_dev->dcompletion) {
+               complete(pm8001_dev->dcompletion);
+               pm8001_dev->dcompletion = NULL;
+       }
        ccb->task = NULL;
        ccb->ccb_tag = 0xFFFFFFFF;
        pm8001_tag_free(pm8001_ha, htag);
drivers/scsi/pm8001/pm8001_init.c +50 -3
index 68005d0cb33d..6cbb8fa74456 100644
@@ -55,6 +55,12 @@ MODULE_PARM_DESC(link_rate, "Enable link rate.\n"
                " 4: Link rate 6.0G\n"
                " 8: Link rate 12.0G\n");
 
+bool staggered_spinup;
+module_param(staggered_spinup, bool, 0644);
+MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n"
+               " 0/N: false\n"
+               " 1/Y: true\n");
+
 static struct scsi_transport_template *pm8001_stt;
 
 /**
@@ -164,7 +170,7 @@ static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
 
        if (!pm8001_ha)
                return;
-
+       del_timer(&pm8001_ha->spinup_timer);
        for (i = 0; i < USI_MAX_MEMCNT; i++) {
                if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
                        dma_free_coherent(&pm8001_ha->pdev->dev,
@@ -486,6 +492,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
        pm8001_ha->shost = shost;
        pm8001_ha->id = pm8001_id++;
        pm8001_ha->logging_level = logging_level;
+       pm8001_ha->staggered_spinup = staggered_spinup;
        pm8001_ha->non_fatal_count = 0;
        if (link_rate >= 1 && link_rate <= 15)
                pm8001_ha->link_rate = (link_rate << 8);
@@ -620,7 +627,8 @@ static void  pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  * Currently we just set the fixed SAS address to our HBA,for manufacture,
  * it should read from the EEPROM
  */
-static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
+static void pm8001_init_sas_add_and_spinup_config
+               (struct pm8001_hba_info *pm8001_ha)
 {
        u8 i, j;
        u8 sas_add[8];
@@ -706,6 +714,45 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
        memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
                SAS_ADDR_SIZE);
 #endif
+
+       /* For spinning up drives in group */
+       pm8001_ha->phy_head = -1;
+       pm8001_ha->phy_tail = -1;
+
+       for (i = 0; i < PM8001_MAX_PHYS; i++)
+               pm8001_ha->phy_up[i] = 0xff;
+
+       timer_setup(&pm8001_ha->spinup_timer,
+               (void *)pm8001_spinup_timedout, 0);
+
+       if (pm8001_ha->staggered_spinup == true) {
+               /* spinup interval in unit of 100 ms */
+               pm8001_ha->spinup_interval =
+                       payload.func_specific[SPINUP_DELAY_OFFSET] * 100;
+               pm8001_ha->spinup_group =
+                       payload.func_specific[SPINUP_GROUP_OFFSET];
+       } else {
+               pm8001_ha->spinup_interval = 0;
+               pm8001_ha->spinup_group = pm8001_ha->chip->n_phy;
+       }
+
+       if (pm8001_ha->spinup_interval > PM80XX_MAX_SPINUP_DELAY) {
+               PM8001_DISC_DBG(pm8001_ha, pm8001_printk(
+               "Spinup delay from Seeprom is %d ms, reset to %d ms\n",
+               pm8001_ha->spinup_interval * 100, PM80XX_MAX_SPINUP_DELAY));
+               pm8001_ha->spinup_interval = PM80XX_MAX_SPINUP_DELAY;
+       }
+
+       if (pm8001_ha->spinup_group > pm8001_ha->chip->n_phy) {
+               PM8001_DISC_DBG(pm8001_ha, pm8001_printk(
+               "Spinup group from Seeprom is %d, reset to %d\n",
+               pm8001_ha->spinup_group, pm8001_ha->chip->n_phy));
+               pm8001_ha->spinup_group = pm8001_ha->chip->n_phy;
+       }
+
+       PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+               "Spinup interval : %d Spinup group %d\n",
+               pm8001_ha->spinup_interval, pm8001_ha->spinup_group));
 }
 
 /*
@@ -1104,7 +1151,7 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
                pm80xx_set_thermal_config(pm8001_ha);
        }
 
-       pm8001_init_sas_add(pm8001_ha);
+       pm8001_init_sas_add_and_spinup_config(pm8001_ha);
        /* phy setting support for motherboard controller */
        if (pm8001_configure_phy_settings(pm8001_ha))
                goto err_out_shost;
drivers/scsi/pm8001/pm8001_sas.c +35 -2
index 3a69d8d1d52e..806845203602 100644
@@ -267,12 +267,38 @@ void pm8001_scan_start(struct Scsi_Host *shost)
        int i;
        struct pm8001_hba_info *pm8001_ha;
        struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       DECLARE_COMPLETION(comp);
        pm8001_ha = sha->lldd_ha;
        /* SAS_RE_INITIALIZATION not available in SPCv/ve */
        if (pm8001_ha->chip_id == chip_8001)
                PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha);
-       for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
-               PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+
+       if (pm8001_ha->pdev->device == 0x8001 ||
+               pm8001_ha->pdev->device == 0x8081 ||
+               (pm8001_ha->spinup_interval != 0)) {
+               for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
+                       PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+       } else {
+               for (i = 0; i < pm8001_ha->chip->n_phy; ++i) {
+                       spin_lock_irqsave(&pm8001_ha->lock,
+                               pm8001_ha->lock_flags);
+                       pm8001_ha->phy_started = i;
+                       pm8001_ha->scan_completion = &comp;
+                       pm8001_ha->phystart_timedout = 1;
+                       spin_unlock_irqrestore(&pm8001_ha->lock,
+                               pm8001_ha->lock_flags);
+                       PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+                       wait_for_completion_timeout(&comp,
+                               msecs_to_jiffies(500));
+                       if (pm8001_ha->phystart_timedout)
+                               PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+                               "Timeout happened for phyid = %d\n", i));
+               }
+               spin_lock_irqsave(&pm8001_ha->lock, pm8001_ha->lock_flags);
+               pm8001_ha->phy_started = -1;
+               pm8001_ha->scan_completion = NULL;
+               spin_unlock_irqrestore(&pm8001_ha->lock, pm8001_ha->lock_flags);
+       }
 }
 
 int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)
@@ -663,6 +689,13 @@ static int pm8001_dev_found_notify(struct domain_device *dev)
                        flag = 1; /* directly sata */
                }
        } /*register this device to HBA*/
+
+       if (pm8001_ha->phy_started == pm8001_device->attached_phy) {
+               if (pm8001_ha->scan_completion != NULL) {
+                       pm8001_ha->phystart_timedout = 0;
+                       complete(pm8001_ha->scan_completion);
+               }
+       }
        PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device\n"));
        PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
        spin_unlock_irqrestore(&pm8001_ha->lock, flags);
drivers/scsi/pm8001/pm8001_sas.h +1 -0
index cba4e9b95c58..df02c6cd116a 100644
@@ -261,6 +261,7 @@ struct pm8001_port {
        u8                      port_attached;
        u16                     wide_port_phymap;
        u8                      port_state;
+       u8                      port_id;
        struct list_head        list;
 };
 

drivers/scsi/pm8001/pm8001_sas.h struct pm8001_hba_info { · line 507

Quoted 4 lines
drivers/scsi/pm8001/pm8001_sas.h +1 -0
@@ -503,6 +504,7 @@ struct pm8001_hba_info {
        unsigned long           flags;
        spinlock_t              lock;/* host-wide lock */
        spinlock_t              bitmap_lock;
+       unsigned long           lock_flags;

This seems fine, only one question: why do you need this lock_flags in hba?

Quoted 248 lines
drivers/scsi/pm8001/pm8001_sas.h +12 -0
        struct pci_dev          *pdev;/* our device */
        struct device           *dev;
        struct pm8001_hba_memspace io_mem[6];
@@ -566,6 +568,17 @@ struct pm8001_hba_info {
        u32                     non_fatal_read_length;
        struct completion       *phyprofile_completion;
        struct phy_prof_resp    phy_profile_resp;
+       bool                    staggered_spinup;
+       struct completion       *scan_completion;
+       u32                     phy_started;
+       u16                     phystart_timedout;
+       int                     spinup_group;
+       int                     spinup_interval;
+       int                     phy_up[PM8001_MAX_PHYS];
+       struct timer_list       spinup_timer;
+       int                     phy_head;
+       int                     phy_tail;
+       spinlock_t              phy_q_lock;
 };
 
 struct pm8001_work {
@@ -684,6 +697,7 @@ void pm8001_open_reject_retry(
 int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
        dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo,
        u32 mem_size, u32 align);
+void pm8001_spinup_timedout(struct timer_list *t);
 
 void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha);
 int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
drivers/scsi/pm8001/pm80xx_hwi.c +109 -17
index 0f4f18b0e480..0040bb4e1b71 100644
@@ -46,6 +46,72 @@
 #define SMP_DIRECT 1
 #define SMP_INDIRECT 2
 
+static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
+       u32 phyId, u32 phy_op);
+
+void  pm8001_queue_phyup(struct pm8001_hba_info *pm8001_ha, int phy_id)
+{
+       int i;
+
+       if (pm8001_ha->phy_head == -1) {
+               pm8001_ha->phy_head = pm8001_ha->phy_tail = 0;
+       } else {
+               /* If the phy id is already queued , discard the phy up */
+               for (i = 0; i < pm8001_ha->chip->n_phy; i++)
+                       if (pm8001_ha->phy_up[i] == phy_id)
+                               return;
+               pm8001_ha->phy_tail =
+                       (pm8001_ha->phy_tail + 1) % PM8001_MAX_PHYS;
+       }
+       pm8001_ha->phy_up[pm8001_ha->phy_tail] = phy_id;
+}
+
+void pm8001_spinup_timedout(struct timer_list *t)
+{
+       struct pm8001_hba_info *pm8001_ha =
+                       from_timer(pm8001_ha, t, spinup_timer);
+       struct pm8001_phy *phy;
+       unsigned long flags;
+       int i = 0, phy_id = 0xff;
+
+       spin_lock_irqsave(&pm8001_ha->phy_q_lock, flags);
+
+       do {
+               if (i++ >= pm8001_ha->spinup_group && pm8001_ha->spinup_group)
+                       break;
+
+               if (pm8001_ha->phy_head == -1 || pm8001_ha->reset_in_progress)
+                       break; /* No phys to spinup */
+
+               phy_id = pm8001_ha->phy_up[pm8001_ha->phy_head];
+               /* Processed phy id, make it invalid 0xff for
+                * checking repeated phy ups
+                */
+               pm8001_ha->phy_up[pm8001_ha->phy_head] = 0xff;
+               if (pm8001_ha->phy_head == pm8001_ha->phy_tail) {
+                       pm8001_ha->phy_head = pm8001_ha->phy_tail = -1;
+               } else {
+                       pm8001_ha->phy_head =
+                               (pm8001_ha->phy_head+1) % PM8001_MAX_PHYS;
+               }
+
+               if (phy_id == 0xff)
+                       break;
+               phy = &pm8001_ha->phy[phy_id];
+               if (phy->phy_type & PORT_TYPE_SAS) {
+                       PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
+                                       PHY_NOTIFY_ENABLE_SPINUP);
+               } else {
+                       PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
+                                       PHY_LINK_RESET);
+               }
+       } while (1);
+
+       if (pm8001_ha->phy_head != -1 && pm8001_ha->spinup_group)
+               mod_timer(&pm8001_ha->spinup_timer,
+                       jiffies + msecs_to_jiffies(pm8001_ha->spinup_interval));
+       spin_unlock_irqrestore(&pm8001_ha->phy_q_lock, flags);
+}
 
 int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shift_value)
 {
@@ -3302,11 +3368,12 @@ hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
        port->port_state = portstate;
        port->wide_port_phymap |= (1U << phy_id);
        phy->phy_state = PHY_STATE_LINK_UP_SPCV;
+       phy->port = port;
        PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
                "portid:%d; phyid:%d; linkrate:%d; "
                "portstate:%x; devicetype:%x\n",
                port_id, phy_id, link_rate, portstate, deviceType));
-
+       port->port_id = port_id;
        switch (deviceType) {
        case SAS_PHY_UNUSED:
                PM8001_MSG_DBG(pm8001_ha,
@@ -3314,8 +3381,12 @@ hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
                break;
        case SAS_END_DEVICE:
                PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
-               pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
-                       PHY_NOTIFY_ENABLE_SPINUP);
+               spin_lock_irqsave(&pm8001_ha->phy_q_lock, flags);
+               pm8001_queue_phyup(pm8001_ha, phy_id);
+               spin_unlock_irqrestore(&pm8001_ha->phy_q_lock, flags);
+               if (!timer_pending(&pm8001_ha->spinup_timer))
+                       mod_timer(&pm8001_ha->spinup_timer,
+                       jiffies + msecs_to_jiffies(pm8001_ha->spinup_interval));
                port->port_attached = 1;
                pm8001_get_lrate_mode(phy, link_rate);
                break;
@@ -3351,9 +3422,10 @@ hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
        phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
        pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
        spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
-       if (pm8001_ha->flags == PM8001F_RUN_TIME)
-               msleep(200);/*delay a moment to wait disk to spinup*/
-       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+       if (!pm8001_ha->reset_in_progress) {
+               if (deviceType != SAS_END_DEVICE)
+                       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+       }
 }
 
 /**
@@ -3388,11 +3460,17 @@ hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
        port->port_state = portstate;
        phy->phy_state = PHY_STATE_LINK_UP_SPCV;
        port->port_attached = 1;
+       phy->port = port;
+       port->port_id = port_id;
        pm8001_get_lrate_mode(phy, link_rate);
        phy->phy_type |= PORT_TYPE_SATA;
        phy->phy_attached = 1;
        phy->sas_phy.oob_mode = SATA_OOB_MODE;
-       sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
+       if (!pm8001_ha->reset_in_progress) {
+               sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
+       } else
+               PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+                       "HW_EVENT_PHY_UP: not notified to host\n"));
        spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
        memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
                sizeof(struct dev_to_host_fis));
@@ -3401,7 +3479,8 @@ hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
        phy->identify.device_type = SAS_SATA_DEV;
        pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
        spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
-       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+       if (!pm8001_ha->reset_in_progress)
+               pm8001_bytes_dmaed(pm8001_ha, phy_id);
 }
 
 /**
@@ -3497,12 +3576,14 @@ static int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
                                status, phy_id));
        if (status == 0) {
                phy->phy_state = PHY_LINK_DOWN;
-               if (pm8001_ha->flags == PM8001F_RUN_TIME &&
-                               phy->enable_completion != NULL) {
-                       complete(phy->enable_completion);
-                       phy->enable_completion = NULL;
-               }
        }
+
+       if (pm8001_ha->flags == PM8001F_RUN_TIME &&
+               phy->enable_completion != NULL) {
+               complete(phy->enable_completion);
+               phy->enable_completion = NULL;
+       }
+
        return 0;
 
 }
@@ -3580,7 +3661,14 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
        case HW_EVENT_SATA_SPINUP_HOLD:
                PM8001_MSG_DBG(pm8001_ha,
                        pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
-               sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
+               spin_lock_irqsave(&pm8001_ha->phy_q_lock, flags);
+               pm8001_queue_phyup(pm8001_ha, phy_id);
+               spin_unlock_irqrestore(&pm8001_ha->phy_q_lock, flags);
+
+               /* Start the timer if not started */
+               if (!timer_pending(&pm8001_ha->spinup_timer))
+                       mod_timer(&pm8001_ha->spinup_timer,
+                       jiffies + msecs_to_jiffies(pm8001_ha->spinup_interval));
                break;
        case HW_EVENT_PHY_DOWN:
                PM8001_MSG_DBG(pm8001_ha,
@@ -4889,7 +4977,7 @@ pm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
        PM8001_INIT_DBG(pm8001_ha,
                pm8001_printk("PHY START REQ for phy_id %d\n", phy_id));
 
-       payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
+       payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_ENABLE |
                        LINKMODE_AUTO | pm8001_ha->link_rate | phy_id);
        /* SSC Disable and SAS Analog ST configuration */
        /**
@@ -4951,6 +5039,8 @@ static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
        u16 ITNT = 2000;
        struct domain_device *dev = pm8001_dev->sas_device;
        struct domain_device *parent_dev = dev->parent;
+       struct pm8001_phy *phy;
+       struct pm8001_port *port;
        circularQ = &pm8001_ha->inbnd_q_tbl[0];
 
        memset(&payload, 0, sizeof(payload));
@@ -4982,8 +5072,11 @@ static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
        linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
                        pm8001_dev->sas_device->linkrate : dev->port->linkrate;
 
+       phy = &pm8001_ha->phy[phy_id];
+       port = phy->port;
+
        payload.phyid_portid =
-               cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0xFF) |
+               cpu_to_le32(((port->port_id) & 0xFF) |
                ((phy_id & 0xFF) << 8));
 
        payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 0x01) |
--

2.16.3

#6 lore raw

RE: [PATCH 2/3] pm80xx : Staggered spin up support.

Quoted 253 lines

From: Viswas G <[email protected]>

As a part of drive discovery, driver will initaite the drive spin up. If all drives do spin up together, it will result in large power consumption. To reduce the power consumption, driver provide an option to make a small group of drives (say 3 or 4 drives together) to do the spin up. The delay between two spin up group and no of drives to spin up (group) can be programmed by the customer in seeprom and driver will use it to control the spinup.

---
 drivers/scsi/pm8001/pm8001_defs.h |   3 +
 drivers/scsi/pm8001/pm8001_hwi.c  |  14 ++++-  
drivers/scsi/pm8001/pm8001_init.c |  53 +++++++++++++++-  
drivers/scsi/pm8001/pm8001_sas.c  |  37 ++++++++++-  
drivers/scsi/pm8001/pm8001_sas.h  |  14 +++++  
drivers/scsi/pm8001/pm80xx_hwi.c  | 125 
+++++++++++++++++++++++++++++++++-----
 6 files changed, 223 insertions(+), 23 deletions(-)
drivers/scsi/pm8001/pm8001_defs.h +3 -0
index 1c7f15fd69ce..fd700ce5e80c 100644
@@ -101,6 +101,9 @@ enum port_type {
 #define USI_MAX_MEMCNT         (PI + PM8001_MAX_SPCV_OUTB_NUM)
 #define        CONFIG_SCSI_PM8001_MAX_DMA_SG   528
 #define PM8001_MAX_DMA_SG      CONFIG_SCSI_PM8001_MAX_DMA_SG
+#define SPINUP_DELAY_OFFSET            0x890 /* 0x890 - delay */
+#define SPINUP_GROUP_OFFSET            0x892 /* 0x892 - group */
+#define PM80XX_MAX_SPINUP_DELAY        10000 /* 10000 ms */
 enum memory_region_num {
        AAP1 = 0x0, /* application acceleration processor */
        IOP,        /* IO processor */
drivers/scsi/pm8001/pm8001_hwi.c +2 -1
index fb9848e1d481..6378c8e8d6b2 100644
@@ -3237,7 +3237,7 @@ int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
                (struct local_phy_ctl_resp *)(piomb + 4);
        u32 status = le32_to_cpu(pPayload->status);
        u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
-       u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
+       u32 phy_op = (le32_to_cpu(pPayload->phyop_phyid) & OP_BITS) >> 
+ 8;
        tag = le32_to_cpu(pPayload->tag);
        if (status != 0) {
                PM8001_MSG_DBG(pm8001_ha, @@ -3248,6 +3248,13 @@ int 

pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)

                        pm8001_printk("%x phy execute %x phy op success!\n",
                        phy_id, phy_op));
                pm8001_ha->phy[phy_id].reset_success = true;
drivers/scsi/pm8001/pm8001_hwi.c +11 -1
+               if (phy_op == PHY_NOTIFY_ENABLE_SPINUP &&
+                       !pm8001_ha->reset_in_progress){
+                       /* Notify the sas layer to discover
+                        * the the whole sas domain
+                        */
+                       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+               }
        }
        if (pm8001_ha->phy[phy_id].enable_completion) {
                complete(pm8001_ha->phy[phy_id].enable_completion);
@@ -3643,7 +3650,10 @@ int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
                        pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n"));
                break;
        }
-       complete(pm8001_dev->dcompletion);
+       if (pm8001_dev->dcompletion) {
+               complete(pm8001_dev->dcompletion);
+               pm8001_dev->dcompletion = NULL;
+       }
        ccb->task = NULL;
        ccb->ccb_tag = 0xFFFFFFFF;
        pm8001_tag_free(pm8001_ha, htag); diff --git 

a/drivers/scsi/pm8001/pm8001_init.c
b/drivers/scsi/pm8001/pm8001_init.c
index 68005d0cb33d..6cbb8fa74456 100644

drivers/scsi/pm8001/pm8001_init.c +7 -1
@@ -55,6 +55,12 @@ MODULE_PARM_DESC(link_rate, "Enable link rate.\n"
                " 4: Link rate 6.0G\n"
                " 8: Link rate 12.0G\n");
 
+bool staggered_spinup;
+module_param(staggered_spinup, bool, 0644); 
+MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n"
+               " 0/N: false\n"
+               " 1/Y: true\n");
+
 static struct scsi_transport_template *pm8001_stt;
 
 /**
@@ -164,7 +170,7 @@ static void pm8001_free(struct pm8001_hba_info 
 *pm8001_ha)
 
        if (!pm8001_ha)
                return;
-
+       del_timer(&pm8001_ha->spinup_timer);
        for (i = 0; i < USI_MAX_MEMCNT; i++) {
                if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
                        dma_free_coherent(&pm8001_ha->pdev->dev,
drivers/scsi/pm8001/pm8001_init.c +44 -2
@@ -486,6 +492,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
        pm8001_ha->shost = shost;
        pm8001_ha->id = pm8001_id++;
        pm8001_ha->logging_level = logging_level;
+       pm8001_ha->staggered_spinup = staggered_spinup;
        pm8001_ha->non_fatal_count = 0;
        if (link_rate >= 1 && link_rate <= 15)
                pm8001_ha->link_rate = (link_rate << 8); @@ -620,7 
+627,8 @@ static void  pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  * Currently we just set the fixed SAS address to our HBA,for manufacture,
  * it should read from the EEPROM
  */
-static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
+static void pm8001_init_sas_add_and_spinup_config
+               (struct pm8001_hba_info *pm8001_ha)
 {
        u8 i, j;
        u8 sas_add[8];
@@ -706,6 +714,45 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
        memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
                SAS_ADDR_SIZE);
 #endif
+
+       /* For spinning up drives in group */
+       pm8001_ha->phy_head = -1;
+       pm8001_ha->phy_tail = -1;
+
+       for (i = 0; i < PM8001_MAX_PHYS; i++)
+               pm8001_ha->phy_up[i] = 0xff;
+
+       timer_setup(&pm8001_ha->spinup_timer,
+               (void *)pm8001_spinup_timedout, 0);
+
+       if (pm8001_ha->staggered_spinup == true) {
+               /* spinup interval in unit of 100 ms */
+               pm8001_ha->spinup_interval =
+                       payload.func_specific[SPINUP_DELAY_OFFSET] * 100;
+               pm8001_ha->spinup_group =
+                       payload.func_specific[SPINUP_GROUP_OFFSET];
+       } else {
+               pm8001_ha->spinup_interval = 0;
+               pm8001_ha->spinup_group = pm8001_ha->chip->n_phy;
+       }
+
+       if (pm8001_ha->spinup_interval > PM80XX_MAX_SPINUP_DELAY) {
+               PM8001_DISC_DBG(pm8001_ha, pm8001_printk(
+               "Spinup delay from Seeprom is %d ms, reset to %d ms\n",
+               pm8001_ha->spinup_interval * 100, PM80XX_MAX_SPINUP_DELAY));
+               pm8001_ha->spinup_interval = PM80XX_MAX_SPINUP_DELAY;
+       }
+
+       if (pm8001_ha->spinup_group > pm8001_ha->chip->n_phy) {
+               PM8001_DISC_DBG(pm8001_ha, pm8001_printk(
+               "Spinup group from Seeprom is %d, reset to %d\n",
+               pm8001_ha->spinup_group, pm8001_ha->chip->n_phy));
+               pm8001_ha->spinup_group = pm8001_ha->chip->n_phy;
+       }
+
+       PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+               "Spinup interval : %d Spinup group %d\n",
+               pm8001_ha->spinup_interval, pm8001_ha->spinup_group));
 }
 
 /*
@@ -1104,7 +1151,7 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
                pm80xx_set_thermal_config(pm8001_ha);
        }
 
-       pm8001_init_sas_add(pm8001_ha);
+       pm8001_init_sas_add_and_spinup_config(pm8001_ha);
        /* phy setting support for motherboard controller */
        if (pm8001_configure_phy_settings(pm8001_ha))
                goto err_out_shost;
drivers/scsi/pm8001/pm8001_sas.c +35 -2
index 3a69d8d1d52e..806845203602 100644
@@ -267,12 +267,38 @@ void pm8001_scan_start(struct Scsi_Host *shost)
        int i;
        struct pm8001_hba_info *pm8001_ha;
        struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       DECLARE_COMPLETION(comp);
        pm8001_ha = sha->lldd_ha;
        /* SAS_RE_INITIALIZATION not available in SPCv/ve */
        if (pm8001_ha->chip_id == chip_8001)
                PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha);
-       for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
-               PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+
+       if (pm8001_ha->pdev->device == 0x8001 ||
+               pm8001_ha->pdev->device == 0x8081 ||
+               (pm8001_ha->spinup_interval != 0)) {
+               for (i = 0; i < pm8001_ha->chip->n_phy; ++i)
+                       PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+       } else {
+               for (i = 0; i < pm8001_ha->chip->n_phy; ++i) {
+                       spin_lock_irqsave(&pm8001_ha->lock,
+                               pm8001_ha->lock_flags);
+                       pm8001_ha->phy_started = i;
+                       pm8001_ha->scan_completion = &comp;
+                       pm8001_ha->phystart_timedout = 1;
+                       spin_unlock_irqrestore(&pm8001_ha->lock,
+                               pm8001_ha->lock_flags);
+                       PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
+                       wait_for_completion_timeout(&comp,
+                               msecs_to_jiffies(500));
+                       if (pm8001_ha->phystart_timedout)
+                               PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+                               "Timeout happened for phyid = %d\n", i));
+               }
+               spin_lock_irqsave(&pm8001_ha->lock, pm8001_ha->lock_flags);
+               pm8001_ha->phy_started = -1;
+               pm8001_ha->scan_completion = NULL;
+               spin_unlock_irqrestore(&pm8001_ha->lock, pm8001_ha->lock_flags);
+       }
 }
 
 int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time) 
@@ -663,6 +689,13 @@ static int pm8001_dev_found_notify(struct domain_device *dev)
                        flag = 1; /* directly sata */
                }
        } /*register this device to HBA*/
+
+       if (pm8001_ha->phy_started == pm8001_device->attached_phy) {
+               if (pm8001_ha->scan_completion != NULL) {
+                       pm8001_ha->phystart_timedout = 0;
+                       complete(pm8001_ha->scan_completion);
+               }
+       }
        PM8001_DISC_DBG(pm8001_ha, pm8001_printk("Found device\n"));
        PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag);
        spin_unlock_irqrestore(&pm8001_ha->lock, flags); diff --git 

a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h index cba4e9b95c58..df02c6cd116a 100644

drivers/scsi/pm8001/pm8001_sas.h +1 -0
@@ -261,6 +261,7 @@ struct pm8001_port {
        u8                      port_attached;
        u16                     wide_port_phymap;
        u8                      port_state;
+       u8                      port_id;
        struct list_head        list;
 };
 

drivers/scsi/pm8001/pm8001_sas.h struct pm8001_hba_info { · line 507

Quoted 4 lines
drivers/scsi/pm8001/pm8001_sas.h +1 -0
@@ -503,6 +504,7 @@ struct pm8001_hba_info {
        unsigned long           flags;
        spinlock_t              lock;/* host-wide lock */
        spinlock_t              bitmap_lock;
+       unsigned long           lock_flags;

This seems fine, only one question: why do you need this lock_flags in hba? [DU] Thanks for comment. I will remove the lok_flags from hba structure and add it locally.

Quoted 250 lines
drivers/scsi/pm8001/pm8001_sas.h +0 -0
        struct pci_dev          *pdev;/* our device */
        struct device           *dev;
        struct pm8001_hba_memspace io_mem[6]; @@ -566,6 +568,17 @@ 
struct pm8001_hba_info {
        u32                     non_fatal_read_length;
        struct completion       *phyprofile_completion;
        struct phy_prof_resp    phy_profile_resp;
drivers/scsi/pm8001/pm8001_sas.h +12 -0
+       bool                    staggered_spinup;
+       struct completion       *scan_completion;
+       u32                     phy_started;
+       u16                     phystart_timedout;
+       int                     spinup_group;
+       int                     spinup_interval;
+       int                     phy_up[PM8001_MAX_PHYS];
+       struct timer_list       spinup_timer;
+       int                     phy_head;
+       int                     phy_tail;
+       spinlock_t              phy_q_lock;
 };
 
 struct pm8001_work {
@@ -684,6 +697,7 @@ void pm8001_open_reject_retry(  int 
 pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
        dma_addr_t *pphys_addr, u32 *pphys_addr_hi, u32 *pphys_addr_lo,
        u32 mem_size, u32 align);
+void pm8001_spinup_timedout(struct timer_list *t);
 
 void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha);  int 

pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha, diff --git a/drivers/scsi/pm8001/pm80xx_hwi.c b/drivers/scsi/pm8001/pm80xx_hwi.c index 0f4f18b0e480..0040bb4e1b71 100644

drivers/scsi/pm8001/pm80xx_hwi.c +63 -0
@@ -46,6 +46,72 @@
 #define SMP_DIRECT 1
 #define SMP_INDIRECT 2
 
+static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
+       u32 phyId, u32 phy_op);
+
+void  pm8001_queue_phyup(struct pm8001_hba_info *pm8001_ha, int 
+phy_id) {
+       int i;
+
+       if (pm8001_ha->phy_head == -1) {
+               pm8001_ha->phy_head = pm8001_ha->phy_tail = 0;
+       } else {
+               /* If the phy id is already queued , discard the phy up */
+               for (i = 0; i < pm8001_ha->chip->n_phy; i++)
+                       if (pm8001_ha->phy_up[i] == phy_id)
+                               return;
+               pm8001_ha->phy_tail =
+                       (pm8001_ha->phy_tail + 1) % PM8001_MAX_PHYS;
+       }
+       pm8001_ha->phy_up[pm8001_ha->phy_tail] = phy_id; }
+
+void pm8001_spinup_timedout(struct timer_list *t) {
+       struct pm8001_hba_info *pm8001_ha =
+                       from_timer(pm8001_ha, t, spinup_timer);
+       struct pm8001_phy *phy;
+       unsigned long flags;
+       int i = 0, phy_id = 0xff;
+
+       spin_lock_irqsave(&pm8001_ha->phy_q_lock, flags);
+
+       do {
+               if (i++ >= pm8001_ha->spinup_group && pm8001_ha->spinup_group)
+                       break;
+
+               if (pm8001_ha->phy_head == -1 || pm8001_ha->reset_in_progress)
+                       break; /* No phys to spinup */
+
+               phy_id = pm8001_ha->phy_up[pm8001_ha->phy_head];
+               /* Processed phy id, make it invalid 0xff for
+                * checking repeated phy ups
+                */
+               pm8001_ha->phy_up[pm8001_ha->phy_head] = 0xff;
+               if (pm8001_ha->phy_head == pm8001_ha->phy_tail) {
+                       pm8001_ha->phy_head = pm8001_ha->phy_tail = -1;
+               } else {
+                       pm8001_ha->phy_head =
+                               (pm8001_ha->phy_head+1) % PM8001_MAX_PHYS;
+               }
+
+               if (phy_id == 0xff)
+                       break;
+               phy = &pm8001_ha->phy[phy_id];
+               if (phy->phy_type & PORT_TYPE_SAS) {
+                       PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
+                                       PHY_NOTIFY_ENABLE_SPINUP);
+               } else {
+                       PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id,
+                                       PHY_LINK_RESET);
+               }
+       } while (1);
+
+       if (pm8001_ha->phy_head != -1 && pm8001_ha->spinup_group)
+               mod_timer(&pm8001_ha->spinup_timer,
+                       jiffies + msecs_to_jiffies(pm8001_ha->spinup_interval));
+       spin_unlock_irqrestore(&pm8001_ha->phy_q_lock, flags); }
 
 int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 

shift_value) { @@ -3302,11 +3368,12 @@ hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)

        port->port_state = portstate;
        port->wide_port_phymap |= (1U << phy_id);
        phy->phy_state = PHY_STATE_LINK_UP_SPCV;
drivers/scsi/pm8001/pm80xx_hwi.c +2 -1
+       phy->port = port;
        PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
                "portid:%d; phyid:%d; linkrate:%d; "
                "portstate:%x; devicetype:%x\n",
                port_id, phy_id, link_rate, portstate, deviceType));
-
+       port->port_id = port_id;
        switch (deviceType) {
        case SAS_PHY_UNUSED:
                PM8001_MSG_DBG(pm8001_ha, @@ -3314,8 +3381,12 @@ 

hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)

                break;
        case SAS_END_DEVICE:
                PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
drivers/scsi/pm8001/pm80xx_hwi.c +18 -6
-               pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
-                       PHY_NOTIFY_ENABLE_SPINUP);
+               spin_lock_irqsave(&pm8001_ha->phy_q_lock, flags);
+               pm8001_queue_phyup(pm8001_ha, phy_id);
+               spin_unlock_irqrestore(&pm8001_ha->phy_q_lock, flags);
+               if (!timer_pending(&pm8001_ha->spinup_timer))
+                       mod_timer(&pm8001_ha->spinup_timer,
+                       jiffies + 
+ msecs_to_jiffies(pm8001_ha->spinup_interval));
                port->port_attached = 1;
                pm8001_get_lrate_mode(phy, link_rate);
                break;
@@ -3351,9 +3422,10 @@ hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
        phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
        pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
        spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
-       if (pm8001_ha->flags == PM8001F_RUN_TIME)
-               msleep(200);/*delay a moment to wait disk to spinup*/
-       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+       if (!pm8001_ha->reset_in_progress) {
+               if (deviceType != SAS_END_DEVICE)
+                       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+       }
 }
 
 /**
@@ -3388,11 +3460,17 @@ hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
        port->port_state = portstate;
        phy->phy_state = PHY_STATE_LINK_UP_SPCV;
        port->port_attached = 1;
+       phy->port = port;
+       port->port_id = port_id;
        pm8001_get_lrate_mode(phy, link_rate);
        phy->phy_type |= PORT_TYPE_SATA;
        phy->phy_attached = 1;
        phy->sas_phy.oob_mode = SATA_OOB_MODE;
-       sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
+       if (!pm8001_ha->reset_in_progress) {
+               sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
+       } else
+               PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
+                       "HW_EVENT_PHY_UP: not notified to host\n"));
        spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
        memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
                sizeof(struct dev_to_host_fis)); @@ -3401,7 +3479,8 @@ 

hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)

        phy->identify.device_type = SAS_SATA_DEV;
        pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
        spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
drivers/scsi/pm8001/pm80xx_hwi.c +18 -7
-       pm8001_bytes_dmaed(pm8001_ha, phy_id);
+       if (!pm8001_ha->reset_in_progress)
+               pm8001_bytes_dmaed(pm8001_ha, phy_id);
 }
 
 /**
@@ -3497,12 +3576,14 @@ static int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
                                status, phy_id));
        if (status == 0) {
                phy->phy_state = PHY_LINK_DOWN;
-               if (pm8001_ha->flags == PM8001F_RUN_TIME &&
-                               phy->enable_completion != NULL) {
-                       complete(phy->enable_completion);
-                       phy->enable_completion = NULL;
-               }
        }
+
+       if (pm8001_ha->flags == PM8001F_RUN_TIME &&
+               phy->enable_completion != NULL) {
+               complete(phy->enable_completion);
+               phy->enable_completion = NULL;
+       }
+
        return 0;
 
 }
@@ -3580,7 +3661,14 @@ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
        case HW_EVENT_SATA_SPINUP_HOLD:
                PM8001_MSG_DBG(pm8001_ha,
                        pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
-               sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
+               spin_lock_irqsave(&pm8001_ha->phy_q_lock, flags);
+               pm8001_queue_phyup(pm8001_ha, phy_id);
+               spin_unlock_irqrestore(&pm8001_ha->phy_q_lock, flags);
+
+               /* Start the timer if not started */
+               if (!timer_pending(&pm8001_ha->spinup_timer))
+                       mod_timer(&pm8001_ha->spinup_timer,
+                       jiffies + 
+ msecs_to_jiffies(pm8001_ha->spinup_interval));
                break;
        case HW_EVENT_PHY_DOWN:
                PM8001_MSG_DBG(pm8001_ha, @@ -4889,7 +4977,7 @@ 

pm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)

        PM8001_INIT_DBG(pm8001_ha,
                pm8001_printk("PHY START REQ for phy_id %d\n", 

phy_id));

drivers/scsi/pm8001/pm80xx_hwi.c +3 -1
-       payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
+       payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_ENABLE |
                        LINKMODE_AUTO | pm8001_ha->link_rate | phy_id);
        /* SSC Disable and SAS Analog ST configuration */
        /**
@@ -4951,6 +5039,8 @@ static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
        u16 ITNT = 2000;
        struct domain_device *dev = pm8001_dev->sas_device;
        struct domain_device *parent_dev = dev->parent;
+       struct pm8001_phy *phy;
+       struct pm8001_port *port;
        circularQ = &pm8001_ha->inbnd_q_tbl[0];
 
        memset(&payload, 0, sizeof(payload)); @@ -4982,8 +5072,11 @@ 

static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,

        linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
                        pm8001_dev->sas_device->linkrate : 

dev->port->linkrate;

drivers/scsi/pm8001/pm80xx_hwi.c +4 -1
+       phy = &pm8001_ha->phy[phy_id];
+       port = phy->port;
+
        payload.phyid_portid =
-               cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0xFF) |
+               cpu_to_le32(((port->port_id) & 0xFF) |
                ((phy_id & 0xFF) << 8));
 
        payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 

0x01) |
--
2.16.3

#7 lore raw

PATCH 3/3 pm80xx : Wait for PHY startup before draining libsas queue.

In reply to Deepak Ukey

From: peter chang <[email protected]>

Until udev rolls out we can't proceed past module loading w/ device discovery in progress because things like the init scripts only work over the currently discovered block devices. The drivers for disk controllers have various forms of 'barriers' to prevent this from happening depending on their underlying support libraries. The host's scan finish waits for the libsas queue to drain. However, if the PHYs are still in the process of starting then the queue will be empty. This means that we declare the scan finished before it has even started. Here we wait for various events from the firmware-side, and even though we disable staggered spinup we still pretend like it's there.

---
 drivers/scsi/pm8001/pm8001_ctl.c  | 36 +++++++++++++++++++++
 drivers/scsi/pm8001/pm8001_defs.h |  6 ++--
 drivers/scsi/pm8001/pm8001_init.c | 25 +++++++++++++++
 drivers/scsi/pm8001/pm8001_sas.c  | 61 +++++++++++++++++++++++++++++++++--
 drivers/scsi/pm8001/pm8001_sas.h  |  3 ++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 67 ++++++++++++++++++++++++++++++++-------
 6 files changed, 181 insertions(+), 17 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.c +36 -0
index 3c9f42779dd0..eae629610a5f 100644
@@ -88,6 +88,41 @@ static ssize_t controller_fatal_error_show(struct device *cdev,
 }
 static DEVICE_ATTR_RO(controller_fatal_error);
 
+/**
+ * phy_startup_timeout_show - per-phy discovery timeout
+ * @cdev: pointer to embedded class device
+ * @buf: the buffer returned
+ *
+ * A sysfs 'read/write' shost attribute.
+ */
+static ssize_t phy_startup_timeout_show(struct device *cdev,
+	struct device_attribute *attr, char *buf)
+{
+	struct Scsi_Host *shost = class_to_shost(cdev);
+	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+
+	return snprintf(buf, PAGE_SIZE, "%08xh\n",
+		pm8001_ha->phy_startup_timeout / HZ);
+}
+
+static ssize_t phy_startup_timeout_store(struct device *cdev,
+	struct device_attribute *attr, const char *buf, size_t count)
+{
+	struct Scsi_Host *shost = class_to_shost(cdev);
+	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+	int val = 0;
+
+	if (kstrtoint(buf, 0, &val) < 0)
+		return -EINVAL;
+
+	pm8001_ha->phy_startup_timeout = val * HZ;
+	return strlen(buf);
+}
+
+static DEVICE_ATTR_RW(phy_startup_timeout);
+
 /**
  * pm8001_ctl_fw_version_show - firmware version
  * @cdev: pointer to embedded class device
@@ -867,6 +902,7 @@ static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
 struct device_attribute *pm8001_host_attrs[] = {
 	&dev_attr_interface_rev,
 	&dev_attr_controller_fatal_error,
+	&dev_attr_phy_startup_timeout,
 	&dev_attr_fw_version,
 	&dev_attr_update_fw,
 	&dev_attr_aap_log,
drivers/scsi/pm8001/pm8001_defs.h +4 -2
index fd700ce5e80c..aaeabb2f2808 100644
@@ -141,7 +141,9 @@ enum pm8001_hba_info_flags {
  */
 #define PHY_LINK_DISABLE	0x00
 #define PHY_LINK_DOWN		0x01
-#define PHY_STATE_LINK_UP_SPCV	0x2
-#define PHY_STATE_LINK_UP_SPC	0x1
+#define PHY_STATE_LINK_UP_SPCV	0x02
+#define PHY_STATE_LINK_UP_SPC	0x01
+#define PHY_STATE_LINK_RESET	0x03
+#define PHY_STATE_HARD_RESET	0x04
 
 #endif
drivers/scsi/pm8001/pm8001_init.c +25 -0
index 6cbb8fa74456..560dd9c3f745 100644
@@ -61,6 +61,30 @@ MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n"
 		" 0/N: false\n"
 		" 1/Y: true\n");
 
+/* if nothing is detected, the PHYs will reset continuously once they
+ * are started. we don't have a good way of differentiating a trained
+ * but waiting-on-signature from one that's never going to train
+ * (nothing attached or dead drive), so we wait an possibly
+ * unreasonable amount of time. this is stuck in start_timeout, and
+ * checked in the host's scan_finished callback for PHYs that haven't
+ * yet come up.
+ *
+ * the timeout here was experimentally determined by looking at our
+ * current worst-case spin-up drive (seagate 8T) which has
+ * the most drive-to-drive variance, some issues coming up from the
+ * sleep state (randomly applied ~10s delay to non-data operations),
+ * and errors from IDENTIFY.
+ *
+ * NB: this a workaround to handle current lack of udev. once
+ * that's everywhere and dynamically dealing w/ device add/remove
+ * (step one doesn't deal w/ this later condition) then the patches
+ * can be removed.
+ */
+static ulong phy_startup_timeout = 60;
+module_param(phy_startup_timeout, ulong, 0644);
+MODULE_PARM_DESC(phy_startup_timeout_s,
+		" seconds to wait for discovery, per-PHY.");
+
 static struct scsi_transport_template *pm8001_stt;
 
 /**
@@ -493,6 +517,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
 	pm8001_ha->id = pm8001_id++;
 	pm8001_ha->logging_level = logging_level;
 	pm8001_ha->staggered_spinup = staggered_spinup;
+	pm8001_ha->phy_startup_timeout = phy_startup_timeout * HZ;
 	pm8001_ha->non_fatal_count = 0;
 	if (link_rate >= 1 && link_rate <= 15)
 		pm8001_ha->link_rate = (link_rate << 8);
drivers/scsi/pm8001/pm8001_sas.c +58 -3

87 lines not on this page · raw message

drivers/scsi/pm8001/pm8001_sas.h +3 -0
index df02c6cd116a..bb4f099a1723 100644
@@ -283,6 +283,7 @@ struct pm8001_phy {
 	struct completion	*reset_completion;
 	bool			port_reset_status;
 	bool			reset_success;
+	unsigned long		start_timeout;
 };
 
 /* port reset status */
@@ -579,6 +580,8 @@ struct pm8001_hba_info {
 	int			phy_head;
 	int			phy_tail;
 	spinlock_t		phy_q_lock;
+	unsigned long		phy_mask;
+	u32			phy_startup_timeout;
 };
 
 struct pm8001_work {
drivers/scsi/pm8001/pm80xx_hwi.c +55 -12

93 lines not on this page · raw message

Signature · 1 line
2.16.3
maintainer
#8 lore raw

Re: [PATCH 3/3] pm80xx : Wait for PHY startup before draining libsas queue.

Quoted 6 lines · Deepak Ukey

From: peter chang <[email protected]>

Until udev rolls out we can't proceed past module loading w/ device discovery in progress because things like the init scripts only work over the currently discovered block devices.

Just curious, what's this udev rollout?

The drivers for disk

Quoted 108 lines

controllers have various forms of 'barriers' to prevent this from happening depending on their underlying support libraries. The host's scan finish waits for the libsas queue to drain. However, if the PHYs are still in the process of starting then the queue will be empty. This means that we declare the scan finished before it has even started. Here we wait for various events from the firmware-side, and even though we disable staggered spinup we still pretend like it's there.

---
 drivers/scsi/pm8001/pm8001_ctl.c  | 36 +++++++++++++++++++++
 drivers/scsi/pm8001/pm8001_defs.h |  6 ++--
 drivers/scsi/pm8001/pm8001_init.c | 25 +++++++++++++++
 drivers/scsi/pm8001/pm8001_sas.c  | 61 +++++++++++++++++++++++++++++++++--
 drivers/scsi/pm8001/pm8001_sas.h  |  3 ++
 drivers/scsi/pm8001/pm80xx_hwi.c  | 67 ++++++++++++++++++++++++++++++++-------
 6 files changed, 181 insertions(+), 17 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.c +36 -0
index 3c9f42779dd0..eae629610a5f 100644
@@ -88,6 +88,41 @@ static ssize_t controller_fatal_error_show(struct device *cdev,
 }
 static DEVICE_ATTR_RO(controller_fatal_error);
 
+/**
+ * phy_startup_timeout_show - per-phy discovery timeout
+ * @cdev: pointer to embedded class device
+ * @buf: the buffer returned
+ *
+ * A sysfs 'read/write' shost attribute.
+ */
+static ssize_t phy_startup_timeout_show(struct device *cdev,
+       struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+
+       return snprintf(buf, PAGE_SIZE, "%08xh\n",
+               pm8001_ha->phy_startup_timeout / HZ);
+}
+
+static ssize_t phy_startup_timeout_store(struct device *cdev,
+       struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+       int val = 0;
+
+       if (kstrtoint(buf, 0, &val) < 0)
+               return -EINVAL;
+
+       pm8001_ha->phy_startup_timeout = val * HZ;
+       return strlen(buf);
+}
+
+static DEVICE_ATTR_RW(phy_startup_timeout);
+
 /**
  * pm8001_ctl_fw_version_show - firmware version
  * @cdev: pointer to embedded class device
@@ -867,6 +902,7 @@ static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
 struct device_attribute *pm8001_host_attrs[] = {
        &dev_attr_interface_rev,
        &dev_attr_controller_fatal_error,
+       &dev_attr_phy_startup_timeout,
        &dev_attr_fw_version,
        &dev_attr_update_fw,
        &dev_attr_aap_log,
drivers/scsi/pm8001/pm8001_defs.h +4 -2
index fd700ce5e80c..aaeabb2f2808 100644
@@ -141,7 +141,9 @@ enum pm8001_hba_info_flags {
  */
 #define PHY_LINK_DISABLE       0x00
 #define PHY_LINK_DOWN          0x01
-#define PHY_STATE_LINK_UP_SPCV 0x2
-#define PHY_STATE_LINK_UP_SPC  0x1
+#define PHY_STATE_LINK_UP_SPCV 0x02
+#define PHY_STATE_LINK_UP_SPC  0x01
+#define PHY_STATE_LINK_RESET   0x03
+#define PHY_STATE_HARD_RESET   0x04
 
 #endif
drivers/scsi/pm8001/pm8001_init.c +8 -0
index 6cbb8fa74456..560dd9c3f745 100644
@@ -61,6 +61,30 @@ MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n"
                " 0/N: false\n"
                " 1/Y: true\n");
 
+/* if nothing is detected, the PHYs will reset continuously once they
+ * are started. we don't have a good way of differentiating a trained
+ * but waiting-on-signature from one that's never going to train
+ * (nothing attached or dead drive), so we wait an possibly
+ * unreasonable amount of time. this is stuck in start_timeout, and
+ * checked in the host's scan_finished callback for PHYs that haven't
+ * yet come up.
+ *

drivers/scsi/pm8001/pm8001_init.c MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n" · line 81

Quoted 10 lines
drivers/scsi/pm8001/pm8001_init.c +10 -0
+ * the timeout here was experimentally determined by looking at our
+ * current worst-case spin-up drive (seagate 8T) which has
+ * the most drive-to-drive variance, some issues coming up from the
+ * sleep state (randomly applied ~10s delay to non-data operations),
+ * and errors from IDENTIFY.
+ *
+ * NB: this a workaround to handle current lack of udev. once
+ * that's everywhere and dynamically dealing w/ device add/remove
+ * (step one doesn't deal w/ this later condition) then the patches
+ * can be removed.

If it's just a workaround for missing proper udev rule, I think we shouldnt' include it in upstream.

Quoted 36 lines
drivers/scsi/pm8001/pm8001_init.c +7 -0
+ */
+static ulong phy_startup_timeout = 60;
+module_param(phy_startup_timeout, ulong, 0644);
+MODULE_PARM_DESC(phy_startup_timeout_s,
+               " seconds to wait for discovery, per-PHY.");
+
 static struct scsi_transport_template *pm8001_stt;
 
 /**
@@ -493,6 +517,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
        pm8001_ha->id = pm8001_id++;
        pm8001_ha->logging_level = logging_level;
        pm8001_ha->staggered_spinup = staggered_spinup;
+       pm8001_ha->phy_startup_timeout = phy_startup_timeout * HZ;
        pm8001_ha->non_fatal_count = 0;
        if (link_rate >= 1 && link_rate <= 15)
                pm8001_ha->link_rate = (link_rate << 8);
drivers/scsi/pm8001/pm8001_sas.c +4 -0
index 806845203602..470fe4dd3b52 100644
@@ -39,6 +39,7 @@
  */
 
 #include <linux/slab.h>
+#include "pm80xx_hwi.h"
 #include "pm8001_sas.h"
 
 /**
@@ -257,6 +258,54 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
        return rc;
 }
 
+static int pm8001_update_phy_mask(struct pm8001_hba_info *pm8001_ha)
+{
+       struct phy_profile *profile = &pm8001_ha->phy_profile_resp.phy.status;

drivers/scsi/pm8001/pm8001_sas.c int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func, · line 273

Quoted 10 lines
drivers/scsi/pm8001/pm8001_sas.c +10 -0
+       DECLARE_COMPLETION_ONSTACK(comp);
+       unsigned long timeout = msecs_to_jiffies(2000);
+       int ret = 0;
+       int i;
+
+       for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
+               struct pm8001_phy *phy = pm8001_ha->phy + i;
+
+               if (pm8001_ha->phy_mask & (1 << i) && phy->phy_state) {
+                       pm8001_ha->phyprofile_completion = &comp;

Ok, you have phyprofile_completion init here, I think it should be moved to first patch.

Thanks!

#9 lore raw

RE: [PATCH 3/3] pm80xx : Wait for PHY startup before draining libsas queue.

Quoted 6 lines · Deepak Ukey

From: peter chang <[email protected]>

Until udev rolls out we can't proceed past module loading w/ device discovery in progress because things like the init scripts only work over the currently discovered block devices.

Just curious, what's this udev rollout?

The drivers for disk

Quoted 110 lines

controllers have various forms of 'barriers' to prevent this from happening depending on their underlying support libraries. The host's scan finish waits for the libsas queue to drain. However, if the PHYs are still in the process of starting then the queue will be empty. This means that we declare the scan finished before it has even started. Here we wait for various events from the firmware-side, and even though we disable staggered spinup we still pretend like it's there.

---
 drivers/scsi/pm8001/pm8001_ctl.c  | 36 +++++++++++++++++++++  
drivers/scsi/pm8001/pm8001_defs.h |  6 ++--  
drivers/scsi/pm8001/pm8001_init.c | 25 +++++++++++++++  
drivers/scsi/pm8001/pm8001_sas.c  | 61 
+++++++++++++++++++++++++++++++++--
 drivers/scsi/pm8001/pm8001_sas.h  |  3 ++  
drivers/scsi/pm8001/pm80xx_hwi.c  | 67 
++++++++++++++++++++++++++++++++-------
 6 files changed, 181 insertions(+), 17 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.c +33 -0
index 3c9f42779dd0..eae629610a5f 100644
@@ -88,6 +88,41 @@ static ssize_t controller_fatal_error_show(struct 
 device *cdev,  }  static DEVICE_ATTR_RO(controller_fatal_error);
 
+/**
+ * phy_startup_timeout_show - per-phy discovery timeout
+ * @cdev: pointer to embedded class device
+ * @buf: the buffer returned
+ *
+ * A sysfs 'read/write' shost attribute.
+ */
+static ssize_t phy_startup_timeout_show(struct device *cdev,
+       struct device_attribute *attr, char *buf) {
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+
+       return snprintf(buf, PAGE_SIZE, "%08xh\n",
+               pm8001_ha->phy_startup_timeout / HZ); }
+
+static ssize_t phy_startup_timeout_store(struct device *cdev,
+       struct device_attribute *attr, const char *buf, size_t count) 
+{
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+       int val = 0;
+
+       if (kstrtoint(buf, 0, &val) < 0)
+               return -EINVAL;
+
+       pm8001_ha->phy_startup_timeout = val * HZ;
+       return strlen(buf);
+}
+
+static DEVICE_ATTR_RW(phy_startup_timeout);
+
 /**
  * pm8001_ctl_fw_version_show - firmware version
  * @cdev: pointer to embedded class device @@ -867,6 +902,7 @@ static 

DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP, struct device_attribute *pm8001_host_attrs[] = {
&dev_attr_interface_rev, &dev_attr_controller_fatal_error,

drivers/scsi/pm8001/pm8001_ctl.c +1 -0
+       &dev_attr_phy_startup_timeout,
        &dev_attr_fw_version,
        &dev_attr_update_fw,
        &dev_attr_aap_log,
drivers/scsi/pm8001/pm8001_defs.h +4 -2
index fd700ce5e80c..aaeabb2f2808 100644
@@ -141,7 +141,9 @@ enum pm8001_hba_info_flags {
  */
 #define PHY_LINK_DISABLE       0x00
 #define PHY_LINK_DOWN          0x01
-#define PHY_STATE_LINK_UP_SPCV 0x2
-#define PHY_STATE_LINK_UP_SPC  0x1
+#define PHY_STATE_LINK_UP_SPCV 0x02
+#define PHY_STATE_LINK_UP_SPC  0x01
+#define PHY_STATE_LINK_RESET   0x03
+#define PHY_STATE_HARD_RESET   0x04
 
 #endif
drivers/scsi/pm8001/pm8001_init.c +8 -0
index 6cbb8fa74456..560dd9c3f745 100644
@@ -61,6 +61,30 @@ MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n"
                " 0/N: false\n"
                " 1/Y: true\n");
 
+/* if nothing is detected, the PHYs will reset continuously once they
+ * are started. we don't have a good way of differentiating a trained
+ * but waiting-on-signature from one that's never going to train
+ * (nothing attached or dead drive), so we wait an possibly
+ * unreasonable amount of time. this is stuck in start_timeout, and
+ * checked in the host's scan_finished callback for PHYs that haven't
+ * yet come up.
+ *

drivers/scsi/pm8001/pm8001_init.c MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n" · line 81

Quoted 10 lines
drivers/scsi/pm8001/pm8001_init.c +10 -0
+ * the timeout here was experimentally determined by looking at our
+ * current worst-case spin-up drive (seagate 8T) which has
+ * the most drive-to-drive variance, some issues coming up from the
+ * sleep state (randomly applied ~10s delay to non-data operations),
+ * and errors from IDENTIFY.
+ *
+ * NB: this a workaround to handle current lack of udev. once
+ * that's everywhere and dynamically dealing w/ device add/remove
+ * (step one doesn't deal w/ this later condition) then the patches
+ * can be removed.

If it's just a workaround for missing proper udev rule, I think we shouldnt' include it in upstream.

Thank you for your suggestion, we are looking into the possibility of handling this behavior with udev.
Since some drives take longer to respond back to that phy start request, the following wait does nothing, since the sas workqueue is empty.

    /* Wait for discovery to finish */
        sas_drain_work(ha);

The "wait" behavior could be exposed as a module parameter, if the parameter is enabled, the driver will wait for the phy up event from the firmware, before proceeding with load. Would this be acceptable as an alternative solution?

Quoted 36 lines
drivers/scsi/pm8001/pm8001_init.c +7 -0
+ */
+static ulong phy_startup_timeout = 60; 
+module_param(phy_startup_timeout, ulong, 0644); 
+MODULE_PARM_DESC(phy_startup_timeout_s,
+               " seconds to wait for discovery, per-PHY.");
+
 static struct scsi_transport_template *pm8001_stt;
 
 /**
@@ -493,6 +517,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
        pm8001_ha->id = pm8001_id++;
        pm8001_ha->logging_level = logging_level;
        pm8001_ha->staggered_spinup = staggered_spinup;
+       pm8001_ha->phy_startup_timeout = phy_startup_timeout * HZ;
        pm8001_ha->non_fatal_count = 0;
        if (link_rate >= 1 && link_rate <= 15)
                pm8001_ha->link_rate = (link_rate << 8); diff --git 

a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c index 806845203602..470fe4dd3b52 100644

drivers/scsi/pm8001/pm8001_sas.c +4 -0
@@ -39,6 +39,7 @@
  */
 
 #include <linux/slab.h>
+#include "pm80xx_hwi.h"
 #include "pm8001_sas.h"
 
 /**
@@ -257,6 +258,54 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
        return rc;
 }
 
+static int pm8001_update_phy_mask(struct pm8001_hba_info *pm8001_ha) 
+{
+       struct phy_profile *profile = &pm8001_ha->phy_profile_resp.phy.status;

drivers/scsi/pm8001/pm8001_sas.c int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func, · line 273

Quoted 10 lines
drivers/scsi/pm8001/pm8001_sas.c +10 -0
+       DECLARE_COMPLETION_ONSTACK(comp);
+       unsigned long timeout = msecs_to_jiffies(2000);
+       int ret = 0;
+       int i;
+
+       for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
+               struct pm8001_phy *phy = pm8001_ha->phy + i;
+
+               if (pm8001_ha->phy_mask & (1 << i) && phy->phy_state) {
+                       pm8001_ha->phyprofile_completion = &comp;

Ok, you have phyprofile_completion init here, I think it should be moved to first patch.

Thanks!

maintainer
#10 lore raw

Re: [PATCH 3/3] pm80xx : Wait for PHY startup before draining libsas queue.

Quoted 134 lines · On Tue, May 12, 2020 at 7:32 AM <[email protected]> wrote:
Quoted 6 lines · Deepak Ukey

From: peter chang <[email protected]>

Until udev rolls out we can't proceed past module loading w/ device discovery in progress because things like the init scripts only work over the currently discovered block devices.

Just curious, what's this udev rollout?

The drivers for disk

Quoted 110 lines

controllers have various forms of 'barriers' to prevent this from happening depending on their underlying support libraries. The host's scan finish waits for the libsas queue to drain. However, if the PHYs are still in the process of starting then the queue will be empty. This means that we declare the scan finished before it has even started. Here we wait for various events from the firmware-side, and even though we disable staggered spinup we still pretend like it's there.

---
 drivers/scsi/pm8001/pm8001_ctl.c  | 36 +++++++++++++++++++++
drivers/scsi/pm8001/pm8001_defs.h |  6 ++--
drivers/scsi/pm8001/pm8001_init.c | 25 +++++++++++++++
drivers/scsi/pm8001/pm8001_sas.c  | 61
+++++++++++++++++++++++++++++++++--
 drivers/scsi/pm8001/pm8001_sas.h  |  3 ++
drivers/scsi/pm8001/pm80xx_hwi.c  | 67
++++++++++++++++++++++++++++++++-------
 6 files changed, 181 insertions(+), 17 deletions(-)
drivers/scsi/pm8001/pm8001_ctl.c +33 -0
index 3c9f42779dd0..eae629610a5f 100644
@@ -88,6 +88,41 @@ static ssize_t controller_fatal_error_show(struct
 device *cdev,  }  static DEVICE_ATTR_RO(controller_fatal_error);
 
+/**
+ * phy_startup_timeout_show - per-phy discovery timeout
+ * @cdev: pointer to embedded class device
+ * @buf: the buffer returned
+ *
+ * A sysfs 'read/write' shost attribute.
+ */
+static ssize_t phy_startup_timeout_show(struct device *cdev,
+       struct device_attribute *attr, char *buf) {
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+
+       return snprintf(buf, PAGE_SIZE, "%08xh\n",
+               pm8001_ha->phy_startup_timeout / HZ); }
+
+static ssize_t phy_startup_timeout_store(struct device *cdev,
+       struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+       int val = 0;
+
+       if (kstrtoint(buf, 0, &val) < 0)
+               return -EINVAL;
+
+       pm8001_ha->phy_startup_timeout = val * HZ;
+       return strlen(buf);
+}
+
+static DEVICE_ATTR_RW(phy_startup_timeout);
+
 /**
  * pm8001_ctl_fw_version_show - firmware version
  * @cdev: pointer to embedded class device @@ -867,6 +902,7 @@ static

DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP, struct device_attribute *pm8001_host_attrs[] = {
&dev_attr_interface_rev, &dev_attr_controller_fatal_error,

drivers/scsi/pm8001/pm8001_ctl.c +1 -0
+       &dev_attr_phy_startup_timeout,
        &dev_attr_fw_version,
        &dev_attr_update_fw,
        &dev_attr_aap_log,
drivers/scsi/pm8001/pm8001_defs.h +4 -2
index fd700ce5e80c..aaeabb2f2808 100644
@@ -141,7 +141,9 @@ enum pm8001_hba_info_flags {
  */
 #define PHY_LINK_DISABLE       0x00
 #define PHY_LINK_DOWN          0x01
-#define PHY_STATE_LINK_UP_SPCV 0x2
-#define PHY_STATE_LINK_UP_SPC  0x1
+#define PHY_STATE_LINK_UP_SPCV 0x02
+#define PHY_STATE_LINK_UP_SPC  0x01
+#define PHY_STATE_LINK_RESET   0x03
+#define PHY_STATE_HARD_RESET   0x04
 
 #endif
drivers/scsi/pm8001/pm8001_init.c +8 -0
index 6cbb8fa74456..560dd9c3f745 100644
@@ -61,6 +61,30 @@ MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n"
                " 0/N: false\n"
                " 1/Y: true\n");
 
+/* if nothing is detected, the PHYs will reset continuously once they
+ * are started. we don't have a good way of differentiating a trained
+ * but waiting-on-signature from one that's never going to train
+ * (nothing attached or dead drive), so we wait an possibly
+ * unreasonable amount of time. this is stuck in start_timeout, and
+ * checked in the host's scan_finished callback for PHYs that haven't
+ * yet come up.
+ *

drivers/scsi/pm8001/pm8001_init.c MODULE_PARM_DESC(staggered_spinup, "enable the staggered spinup feature.\n" · line 81

Quoted 10 lines
drivers/scsi/pm8001/pm8001_init.c +10 -0
+ * the timeout here was experimentally determined by looking at our
+ * current worst-case spin-up drive (seagate 8T) which has
+ * the most drive-to-drive variance, some issues coming up from the
+ * sleep state (randomly applied ~10s delay to non-data operations),
+ * and errors from IDENTIFY.
+ *
+ * NB: this a workaround to handle current lack of udev. once
+ * that's everywhere and dynamically dealing w/ device add/remove
+ * (step one doesn't deal w/ this later condition) then the patches
+ * can be removed.

If it's just a workaround for missing proper udev rule, I think we shouldnt' include it in upstream.

Quoted 5 lines

Thank you for your suggestion, we are looking into the possibility of handling this behavior with udev.
Since some drives take longer to respond back to that phy start request, the following wait does nothing, since the sas workqueue is empty.

    /* Wait for discovery to finish */
        sas_drain_work(ha);

The "wait" behavior could be exposed as a module parameter, if the parameter is enabled, the driver will wait for the phy up event from the firmware, before proceeding with load. Would this be acceptable as an alternative solution?

Sounds fine to me!

Thanks