hisi_sas: Some misc patches
Subsystems (2)
cover hisi_sas: Some misc patches
This patchset includes support for some more minor features, a bit of tidying, and a few patches to make the driver a bit more robust.
Notables:
- BIST phy loopback support
- Fix for NCQ tags
- Correctly config registers after controller reset
Luo Jiaxing (7):
scsi: hisi_sas: add debugfs auto-trigger for internal abort time out
scsi: hisi_sas: Use true/false as input parameter of sas_phy_reset()
scsi: hisi_sas: Directly return when running I_T_nexus reset if phy
disabled
scsi: hisi_sas: Remove sleep after issue phy reset if
sas_smp_phy_control() fails
scsi: hisi_sas: Remove hisi_sas_hw.slot_complete
scsi: hisi_sas: Remove some unused function arguments
scsi: hisi_sas: Add hisi_sas_debugfs_alloc() to centralise allocation
Xiang Chen (6):
scsi: hisi_sas: Retry 3 times TMF IO for SAS disks when init device
scsi: hisi_sas: Update all the registers after suspend and resume
scsi: hisi_sas: Assign NCQ tag for all NCQ commands
scsi: hisi_sas: Remove redundant work declaration
scsi: hisi_sas: Add BIST support for phy loopback
scsi: hisi_sas: Fix the conflict between device gone and host reset
drivers/scsi/hisi_sas/hisi_sas.h | 18 +- drivers/scsi/hisi_sas/hisi_sas_main.c | 569 +++++++++++++++++++++---- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 1 - drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 17 +- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 159 ++++++- 5 files changed, 661 insertions(+), 103 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/13 scsi: hisi_sas: add debugfs auto-trigger for internal abort time out
From: Luo Jiaxing <[email protected]>
This trigger is add at _hisi_sas_internal_task_abort()
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/hisi_sas/hisi_sas_main.c +3 -0
@@ -2060,6 +2060,9 @@ _hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,/* Internal abort timed out */ if ((task->task_state_flags &SAS_TASK_STATE_ABORTED )) { +if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct) +queue_work (hisi_hba->wq, &hisi_hba->debugfs_work); +if (!(task->task_state_flags &SAS_TASK_STATE_DONE )) {struct hisi_sas_slot *slot = task->lldd_task;
Signature · 1 line
2.17.1
PATCH 2/13 scsi: hisi_sas: Use true/false as input parameter of sas_phy_reset()
In reply to John GarryFrom: Luo Jiaxing <[email protected]>
When calling sas_phy_reset(), we need to specify whether the reset type is hard reset or link reset - use true/false for clarity.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +2 -2
@@ -1762,7 +1762,7 @@ static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) } reset_type = (sas_dev->dev_status ==HISI_SAS_DEV_INIT || - !dev_is_sata (device)) ?1 :0 ; + !dev_is_sata (device)) ? true : false; rc =sas_phy_reset (local_phy, reset_type);sas_put_local_phy (local_phy);
@@ -1843,7 +1843,7 @@ static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) phy =sas_get_local_phy (device); - rc =sas_phy_reset (phy,1 ); + rc =sas_phy_reset (phy, true);if (rc ==0 )hisi_sas_release_task (hisi_hba, device);
Signature · 1 line
2.17.1
PATCH 3/13 scsi: hisi_sas: Directly return when running I_T_nexus reset if phy disabled
In reply to John GarryFrom: Luo Jiaxing <[email protected]>
At hisi_sas_debug_I_T_nexus_reset(), we call sas_phy_reset() to reset a phy. But if the phy is disabled, sas_phy_reset() will directly return -ENODEV without issue a phy reset request.
If so, We can directly return -ENODEV to libsas before issue a phy reset.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/scsi/hisi_sas/hisi_sas_main.c +5 -0
@@ -1752,6 +1752,11 @@ static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)DECLARE_COMPLETION_ONSTACK (phyreset);int rc, reset_type; +if (!local_phy->enabled) { +sas_put_local_phy (local_phy); +return -ENODEV ; + } +if (scsi_is_sas_phy_local (local_phy)) {struct asd_sas_phy *sas_phy = sas_ha->sas_phy[local_phy->number];
Signature · 1 line
2.17.1
PATCH 4/13 scsi: hisi_sas: Remove sleep after issue phy reset if sas_smp_phy_control() fails
In reply to John GarryFrom: Luo Jiaxing <[email protected]>
At expander environment, we delay after issue phy reset to wait for hardware to handle phy reset. But if sas_smp_phy_control() fails, the delay is unnecessary so remove it.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +3 -2
@@ -1791,9 +1791,10 @@ static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) }else if (sas_dev->dev_status !=HISI_SAS_DEV_INIT ) {/* * If in init state, we rely on caller to wait for link to be -* ready; otherwise, delay. +* ready; otherwise, except phy reset is fail, delay. */ -msleep (2000 ); +if (!rc) +msleep (2000 ); }return rc;
Signature · 1 line
2.17.1
PATCH 5/13 scsi: hisi_sas: Retry 3 times TMF IO for SAS disks when init device
In reply to John GarryFrom: Xiang Chen <[email protected]>
When init device for SAS disks, it will send TMF IO to clear disks. At that times TMF IO is broken by some operations such as injecting controller reset from HW RAs event, the TMF IO will be timeout, and at last device will be gone. Print is as followed:
hisi_sas_v3_hw 0000:74:02.0: dev[240:1] found
...hisi_sas_v3_hw 0000:74:02.0: controller resetting... hisi_sas_v3_hw 0000:74:02.0: phyup: phy7 link_rate=10(sata) hisi_sas_v3_hw 0000:74:02.0: phyup: phy0 link_rate=9(sata) hisi_sas_v3_hw 0000:74:02.0: phyup: phy1 link_rate=9(sata) hisi_sas_v3_hw 0000:74:02.0: phyup: phy2 link_rate=9(sata) hisi_sas_v3_hw 0000:74:02.0: phyup: phy3 link_rate=9(sata) hisi_sas_v3_hw 0000:74:02.0: phyup: phy6 link_rate=10(sata) hisi_sas_v3_hw 0000:74:02.0: phyup: phy5 link_rate=11 hisi_sas_v3_hw 0000:74:02.0: phyup: phy4 link_rate=11 hisi_sas_v3_hw 0000:74:02.0: controller reset complete hisi_sas_v3_hw 0000:74:02.0: abort tmf: TMF task timeout and not done hisi_sas_v3_hw 0000:74:02.0: dev[240:1] is gone
sas: driver on host 0000:74:02.0 cannot handle device 5000c500a75a860d, error:5
To improve the reliability, retry TMF IO max of 3 times for SAS disks which is the same as softreset does.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +10 -6
@@ -698,13 +698,13 @@ static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device)return sas_dev; } -#define HISI_SAS_SRST_ATA_DISK_CNT 3 +#define HISI_SAS_DISK_RECOVER_CNT 3static int hisi_sas_init_device (struct domain_device *device) {int rc =TMF_RESP_FUNC_COMPLETE ;struct scsi_lun lun;struct hisi_sas_tmf_task tmf_task; -int retry =HISI_SAS_SRST_ATA_DISK_CNT ; +int retry =HISI_SAS_DISK_RECOVER_CNT ;struct hisi_hba *hisi_hba =dev_to_hisi_hba (device);struct device *dev = hisi_hba->dev;struct sas_phy *local_phy;
@@ -714,10 +714,14 @@ static int hisi_sas_init_device(struct domain_device *device)int_to_scsilun (0 , &lun); tmf_task.tmf =TMF_CLEAR_TASK_SET ; - rc =hisi_sas_debug_issue_ssp_tmf (device, lun.scsi_lun, - &tmf_task); -if (rc ==TMF_RESP_FUNC_COMPLETE ) -hisi_sas_release_task (hisi_hba, device); +while (retry-- >0 ) { + rc =hisi_sas_debug_issue_ssp_tmf (device, lun.scsi_lun, + &tmf_task); +if (rc ==TMF_RESP_FUNC_COMPLETE ) { +hisi_sas_release_task (hisi_hba, device); +break ; + } + }break ;case SAS_SATA_DEV :case SAS_SATA_PM :
Signature · 1 line
2.17.1
PATCH 6/13 scsi: hisi_sas: Update all the registers after suspend and resume
In reply to John GarryFrom: Xiang Chen <[email protected]>
After suspend and resume, the HW registers will be set back to their initial value. We use init_reg_v3_hw() to set some registers, but some registers are set via firmware in ACPI "_RST" method, so add reset handler before init_reg_v3_hw().
--- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +8 -2
@@ -3283,15 +3283,21 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)pci_enable_wake (pdev,PCI_D0 ,0 );pci_restore_state (pdev); rc =pci_enable_device (pdev); -if (rc) +if (rc) {dev_err (dev,"enable device failed during resume (%d)\n" , rc); +return rc; + }pci_set_master (pdev);scsi_unblock_requests (shost);clear_bit (HISI_SAS_REJECT_CMD_BIT , &hisi_hba->flags);sas_prep_resume_ha (sha); -init_reg_v3_hw (hisi_hba); + rc =hw_init_v3_hw (hisi_hba); +if (rc) { +scsi_remove_host (shost); +pci_disable_device (pdev); + } hisi_hba->hw->phys_init (hisi_hba);sas_resume_ha (sha);clear_bit (HISI_SAS_RESET_BIT , &hisi_hba->flags);
Signature · 1 line
2.17.1
PATCH 7/13 scsi: hisi_sas: Assign NCQ tag for all NCQ commands
In reply to John GarryFrom: Xiang Chen <[email protected]>
Currently the NCQ tag is only assigned for FPDMA READ and FPDMA WRITE commands, and for other NCQ commands (such as FPDMA SEND), their NCQ tags are set in the delivery command to 0.
So for all the NCQ commands, we also need to assign normal NCQ tag for them, so drop the command type check in hisi_sas_get_ncq_tag() [drop hisi_sas_get_ncq_tag() altogether actually], and always use the ATA command NCQ tag when appropriate.
--- drivers/scsi/hisi_sas/hisi_sas.h | 1 - drivers/scsi/hisi_sas/hisi_sas_main.c | 15 --------------- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 5 ++++- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 5 ++++- 4 files changed, 8 insertions(+), 18 deletions(-)
drivers/scsi/hisi_sas/hisi_sas.h +0 -1
@@ -559,7 +559,6 @@ extern u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis,extern struct hisi_sas_port *to_hisi_sas_port (struct asd_sas_port *sas_port);extern void hisi_sas_sata_done (struct sas_task *task,struct hisi_sas_slot *slot); -extern int hisi_sas_get_ncq_tag (struct sas_task *task,u32 *tag);extern int hisi_sas_get_fw_info (struct hisi_hba *hisi_hba);extern int hisi_sas_probe (struct platform_device *pdev,const struct hisi_sas_hw *ops);
drivers/scsi/hisi_sas/hisi_sas_main.c +0 -15
@@ -118,21 +118,6 @@ void hisi_sas_sata_done(struct sas_task *task, }EXPORT_SYMBOL_GPL (hisi_sas_sata_done); -int hisi_sas_get_ncq_tag (struct sas_task *task,u32 *tag) -{ -struct ata_queued_cmd *qc = task->uldd_task; - -if (qc) { -if (qc->tf.command ==ATA_CMD_FPDMA_WRITE || - qc->tf.command ==ATA_CMD_FPDMA_READ ) { - *tag = qc->tag; -return 1 ; - } - } -return 0 ; -} -EXPORT_SYMBOL_GPL (hisi_sas_get_ncq_tag); -/* * This function assumes linkrate mask fits in 8 bits, which it * does for all HW versions supported.
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +4 -1
@@ -2534,7 +2534,10 @@ static void prep_ata_v2_hw(struct hisi_hba *hisi_hba, hdr->dw1 =cpu_to_le32 (dw1);/* dw2 */ -if (task->ata_task.use_ncq &&hisi_sas_get_ncq_tag (task, &hdr_tag)) { +if (task->ata_task.use_ncq) { +struct ata_queued_cmd *qc = task->uldd_task; + + hdr_tag = qc->tag; task->ata_task.fis.sector_count |= (u8) (hdr_tag <<3 ); dw2 |= hdr_tag <<CMD_HDR_NCQ_TAG_OFF ; }
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +4 -1
@@ -1356,7 +1356,10 @@ static void prep_ata_v3_hw(struct hisi_hba *hisi_hba, hdr->dw1 =cpu_to_le32 (dw1);/* dw2 */ -if (task->ata_task.use_ncq &&hisi_sas_get_ncq_tag (task, &hdr_tag)) { +if (task->ata_task.use_ncq) { +struct ata_queued_cmd *qc = task->uldd_task; + + hdr_tag = qc->tag; task->ata_task.fis.sector_count |= (u8) (hdr_tag <<3 ); dw2 |= hdr_tag <<CMD_HDR_NCQ_TAG_OFF ; }
Signature · 1 line
2.17.1
PATCH 8/13 scsi: hisi_sas: Remove hisi_sas_hw.slot_complete
In reply to John GarryFrom: Luo Jiaxing <[email protected]>
We never call hisi_sas_hw.slot_complete, so remove it.
--- drivers/scsi/hisi_sas/hisi_sas.h | 2 -- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 1 - drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 1 - drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 1 - 4 files changed, 5 deletions(-)
drivers/scsi/hisi_sas/hisi_sas.h +0 -2
@@ -289,8 +289,6 @@ struct hisi_sas_hw {void (*prep_abort)(struct hisi_hba *hisi_hba,struct hisi_sas_slot *slot,int device_id,int abort_flag,int tag_to_abort); -int (*slot_complete)(struct hisi_hba *hisi_hba, -struct hisi_sas_slot *slot);void (*phys_init)(struct hisi_hba *hisi_hba);void (*phy_start)(struct hisi_hba *hisi_hba,int phy_no);void (*phy_disable)(struct hisi_hba *hisi_hba,int phy_no);
drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +0 -1
@@ -1782,7 +1782,6 @@ static const struct hisi_sas_hw hisi_sas_v1_hw = { .prep_smp = prep_smp_v1_hw, .prep_ssp = prep_ssp_v1_hw, .start_delivery = start_delivery_v1_hw, - .slot_complete = slot_complete_v1_hw, .phys_init = phys_init_v1_hw, .phy_start = start_phy_v1_hw, .phy_disable = disable_phy_v1_hw,
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +0 -1
@@ -3561,7 +3561,6 @@ static const struct hisi_sas_hw hisi_sas_v2_hw = { .prep_stp = prep_ata_v2_hw, .prep_abort = prep_abort_v2_hw, .start_delivery = start_delivery_v2_hw, - .slot_complete = slot_complete_v2_hw, .phys_init = phys_init_v2_hw, .phy_start = start_phy_v2_hw, .phy_disable = disable_phy_v2_hw,
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +0 -1
@@ -2961,7 +2961,6 @@ static const struct hisi_sas_hw hisi_sas_v3_hw = { .prep_stp = prep_ata_v3_hw, .prep_abort = prep_abort_v3_hw, .start_delivery = start_delivery_v3_hw, - .slot_complete = slot_complete_v3_hw, .phys_init = phys_init_v3_hw, .phy_start = start_phy_v3_hw, .phy_disable = disable_phy_v3_hw,
Signature · 1 line
2.17.1
PATCH 9/13 scsi: hisi_sas: Remove redundant work declaration
In reply to John GarryFrom: Xiang Chen <[email protected]>
Remove redundant work declaration in HISI_SAS_DECLARE_RST_WORK_ON_STACK
--- drivers/scsi/hisi_sas/hisi_sas.h | 1 - 1 file changed, 1 deletion(-)
drivers/scsi/hisi_sas/hisi_sas.h +0 -1
@@ -134,7 +134,6 @@ struct hisi_sas_rst {#define HISI_SAS_DECLARE_RST_WORK_ON_STACK (r) \ DECLARE_COMPLETION_ONSTACK(c); \ - DECLARE_WORK(w, hisi_sas_sync_rst_work_handler); \ struct hisi_sas_rst r = HISI_SAS_RST_WORK_INIT(r, c)enum hisi_sas_bit_err_type {
Signature · 1 line
2.17.1
PATCH 10/13 scsi: hisi_sas: Remove some unused function arguments
In reply to John GarryFrom: Luo Jiaxing <[email protected]>
Some function arguments are unused, so remove them.
Also move the timeout print in for wait_cmds_complete_timeout_vX_hw() callsites into that same function.
--- drivers/scsi/hisi_sas/hisi_sas.h | 4 ++-- drivers/scsi/hisi_sas/hisi_sas_main.c | 5 ++--- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 11 ++++++----- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 17 +++++++---------- 4 files changed, 17 insertions(+), 20 deletions(-)
drivers/scsi/hisi_sas/hisi_sas.h +2 -2
@@ -306,8 +306,8 @@ struct hisi_sas_hw {u32 (*get_phys_state)(struct hisi_hba *hisi_hba);int (*write_gpio)(struct hisi_hba *hisi_hba,u8 reg_type,u8 reg_index,u8 reg_count,u8 *write_data); -int (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba, -int delay_ms,int timeout_ms); +void (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba, +int delay_ms,int timeout_ms);void (*snapshot_prepare)(struct hisi_hba *hisi_hba);void (*snapshot_restore)(struct hisi_hba *hisi_hba); void (*read_iost_itct_cache)(struct hisi_hba *hisi_hba,
drivers/scsi/hisi_sas/hisi_sas_main.c +2 -3
@@ -1391,8 +1391,7 @@ static void hisi_sas_refresh_port_id(struct hisi_hba *hisi_hba) } } -static void hisi_sas_rescan_topology (struct hisi_hba *hisi_hba,u32 old_state, -u32 state) +static void hisi_sas_rescan_topology (struct hisi_hba *hisi_hba,u32 state) {struct sas_ha_struct *sas_ha = &hisi_hba->sha;struct asd_sas_port *_sas_port =NULL ;
@@ -1553,7 +1552,7 @@ void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba)clear_bit (HISI_SAS_RESET_BIT , &hisi_hba->flags); state = hisi_hba->hw->get_phys_state (hisi_hba); -hisi_sas_rescan_topology (hisi_hba, hisi_hba->phy_state, state); +hisi_sas_rescan_topology (hisi_hba, state); }EXPORT_SYMBOL_GPL (hisi_sas_controller_reset_done);
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +6 -5
@@ -3498,8 +3498,8 @@ static int write_gpio_v2_hw(struct hisi_hba *hisi_hba, u8 reg_type,return 0 ; } -static int wait_cmds_complete_timeout_v2_hw (struct hisi_hba *hisi_hba, -int delay_ms,int timeout_ms) +static void wait_cmds_complete_timeout_v2_hw (struct hisi_hba *hisi_hba, +int delay_ms,int timeout_ms) {struct device *dev = hisi_hba->dev;int entries, entries_old =0 , time;
@@ -3513,12 +3513,13 @@ static int wait_cmds_complete_timeout_v2_hw(struct hisi_hba *hisi_hba,msleep (delay_ms); } -if (time >= timeout_ms) -return -ETIMEDOUT ; +if (time >= timeout_ms) { +dev_dbg (dev,"Wait commands complete timeout!\n" ); +return ; + }dev_dbg (dev,"wait commands complete %dms\n" , time); -return 0 ; }static struct device_attribute *host_attrs_v2_hw[] = {
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +7 -10
@@ -2576,8 +2576,8 @@ static int write_gpio_v3_hw(struct hisi_hba *hisi_hba, u8 reg_type,return 0 ; } -static int wait_cmds_complete_timeout_v3_hw (struct hisi_hba *hisi_hba, -int delay_ms,int timeout_ms) +static void wait_cmds_complete_timeout_v3_hw (struct hisi_hba *hisi_hba, +int delay_ms,int timeout_ms) {struct device *dev = hisi_hba->dev;int entries, entries_old =0 , time;
@@ -2591,12 +2591,12 @@ static int wait_cmds_complete_timeout_v3_hw(struct hisi_hba *hisi_hba,msleep (delay_ms); } -if (time >= timeout_ms) -return -ETIMEDOUT ; +if (time >= timeout_ms) { +dev_dbg (dev,"Wait commands complete timeout!\n" ); +return ; + }dev_dbg (dev,"wait commands complete %dms\n" , time); - -return 0 ; } static ssize_t intr_conv_v3_hw_show(struct device *dev,
@@ -2877,14 +2877,11 @@ static const struct hisi_sas_debugfs_reg debugfs_ras_reg = {static void debugfs_snapshot_prepare_v3_hw (struct hisi_hba *hisi_hba) { -struct device *dev = hisi_hba->dev; -set_bit (HISI_SAS_REJECT_CMD_BIT , &hisi_hba->flags);hisi_sas_write32 (hisi_hba,DLVRY_QUEUE_ENABLE ,0 ); -if (wait_cmds_complete_timeout_v3_hw (hisi_hba,100 ,5000 ) == -ETIMEDOUT ) -dev_dbg (dev,"Wait commands complete timeout!\n" ); +wait_cmds_complete_timeout_v3_hw (hisi_hba,100 ,5000 );hisi_sas_kill_tasklets (hisi_hba); }
Signature · 1 line
2.17.1
PATCH 11/13 scsi: hisi_sas: Add hisi_sas_debugfs_alloc() to centralise allocation
In reply to John GarryFrom: Luo Jiaxing <[email protected]>
We extract the code of memory allocate and construct an new function for it. We think it's convenient for subsequent optimization.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 102 +++++++++++++++----------- 1 file changed, 58 insertions(+), 44 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +58 -44
@@ -3307,27 +3307,44 @@ void hisi_sas_debugfs_work_handler(struct work_struct *work) }EXPORT_SYMBOL_GPL (hisi_sas_debugfs_work_handler); -void hisi_sas_debugfs_init (struct hisi_hba *hisi_hba) +void hisi_sas_debugfs_release (struct hisi_hba *hisi_hba) +{ +struct device *dev = hisi_hba->dev; +int i; + +devm_kfree (dev, hisi_hba->debugfs_iost_cache); +devm_kfree (dev, hisi_hba->debugfs_itct_cache); +devm_kfree (dev, hisi_hba->debugfs_iost); + +for (i =0 ; i < hisi_hba->queue_count; i++) +devm_kfree (dev, hisi_hba->debugfs_cmd_hdr[i]); + +for (i =0 ; i < hisi_hba->queue_count; i++) +devm_kfree (dev, hisi_hba->debugfs_complete_hdr[i]); + +for (i =0 ; i <DEBUGFS_REGS_NUM ; i++) +devm_kfree (dev, hisi_hba->debugfs_regs[i]); + +for (i =0 ; i < hisi_hba->n_phy; i++) +devm_kfree (dev, hisi_hba->debugfs_port_reg[i]); +} + +int hisi_sas_debugfs_alloc (struct hisi_hba *hisi_hba) { -int max_command_entries =HISI_SAS_MAX_COMMANDS ;const struct hisi_sas_hw *hw = hisi_hba->hw;struct device *dev = hisi_hba->dev; -int p, i, c, d; +int p, c, d;size_t sz; - hisi_hba->debugfs_dir =debugfs_create_dir (dev_name (dev), - hisi_sas_debugfs_dir); -debugfs_create_file ("trigger_dump" ,0600 , - hisi_hba->debugfs_dir, - hisi_hba, - &hisi_sas_debugfs_trigger_dump_fops); + hisi_hba->debugfs_dump_dentry = +debugfs_create_dir ("dump" , hisi_hba->debugfs_dir); sz = hw->debugfs_reg_array[DEBUGFS_GLOBAL ]->count *4 ; hisi_hba->debugfs_regs[DEBUGFS_GLOBAL ] =devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_regs[DEBUGFS_GLOBAL ]) - goto fail_global; + goto fail; sz = hw->debugfs_reg_port->count *4 ;for (p =0 ; p < hisi_hba->n_phy; p++) {
@@ -3335,7 +3352,7 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_port_reg[p]) - goto fail_port; + goto fail; } sz = hw->debugfs_reg_array[DEBUGFS_AXI ]->count *4 ;
@@ -3343,14 +3360,14 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_regs[DEBUGFS_AXI ]) - goto fail_axi; + goto fail; sz = hw->debugfs_reg_array[DEBUGFS_RAS ]->count *4 ; hisi_hba->debugfs_regs[DEBUGFS_RAS ] =devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_regs[DEBUGFS_RAS ]) - goto fail_ras; + goto fail; sz = hw->complete_hdr_size *HISI_SAS_QUEUE_SLOTS ;for (c =0 ; c < hisi_hba->queue_count; c++) {
@@ -3358,7 +3375,7 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_complete_hdr[c]) - goto fail_cq; + goto fail; } sz =sizeof (struct hisi_sas_cmd_hdr ) *HISI_SAS_QUEUE_SLOTS ;
@@ -3367,60 +3384,57 @@ void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba)devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_cmd_hdr[d]) - goto fail_iost_dq; + goto fail; } - sz = max_command_entries *sizeof (struct hisi_sas_iost ); + sz =HISI_SAS_MAX_COMMANDS *sizeof (struct hisi_sas_iost ); hisi_hba->debugfs_iost =devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_iost) - goto fail_iost_dq; + goto fail; sz =HISI_SAS_IOST_ITCT_CACHE_NUM *sizeof (struct hisi_sas_iost_itct_cache ); hisi_hba->debugfs_iost_cache =devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_iost_cache) - goto fail_iost_cache; + goto fail; sz =HISI_SAS_IOST_ITCT_CACHE_NUM *sizeof (struct hisi_sas_iost_itct_cache ); hisi_hba->debugfs_itct_cache =devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_itct_cache) - goto fail_itct_cache; + goto fail;/* New memory allocation must be locate before itct */ sz =HISI_SAS_MAX_ITCT_ENTRIES *sizeof (struct hisi_sas_itct ); hisi_hba->debugfs_itct =devm_kmalloc (dev, sz,GFP_KERNEL );if (!hisi_hba->debugfs_itct) - goto fail_itct; + goto fail; -return ; -fail_itct: -devm_kfree (dev, hisi_hba->debugfs_iost_cache); -fail_itct_cache: -devm_kfree (dev, hisi_hba->debugfs_iost_cache); -fail_iost_cache: -devm_kfree (dev, hisi_hba->debugfs_iost); -fail_iost_dq: -for (i =0 ; i < d; i++) -devm_kfree (dev, hisi_hba->debugfs_cmd_hdr[i]); -fail_cq: -for (i =0 ; i < c; i++) -devm_kfree (dev, hisi_hba->debugfs_complete_hdr[i]); -devm_kfree (dev, hisi_hba->debugfs_regs[DEBUGFS_RAS ]); -fail_ras: -devm_kfree (dev, hisi_hba->debugfs_regs[DEBUGFS_AXI ]); -fail_axi: -fail_port: -for (i =0 ; i < p; i++) -devm_kfree (dev, hisi_hba->debugfs_port_reg[i]); -devm_kfree (dev, hisi_hba->debugfs_regs[DEBUGFS_GLOBAL ]); -fail_global: -debugfs_remove_recursive (hisi_hba->debugfs_dir); -dev_dbg (dev,"failed to init debugfs!\n" ); +return 0 ; +fail: +hisi_sas_debugfs_release (hisi_hba); +return -ENOMEM ; +} + +void hisi_sas_debugfs_init (struct hisi_hba *hisi_hba) +{ +struct device *dev = hisi_hba->dev; + + hisi_hba->debugfs_dir =debugfs_create_dir (dev_name (dev), + hisi_sas_debugfs_dir); +debugfs_create_file ("trigger_dump" ,0600 , + hisi_hba->debugfs_dir, + hisi_hba, + &hisi_sas_debugfs_trigger_dump_fops); + +if (hisi_sas_debugfs_alloc (hisi_hba)) { +debugfs_remove_recursive (hisi_hba->debugfs_dir); +dev_dbg (dev,"failed to init debugfs!\n" ); + } }EXPORT_SYMBOL_GPL (hisi_sas_debugfs_init);
Signature · 1 line
2.17.1
PATCH 12/13 scsi: hisi_sas: Add BIST support for phy loopback
In reply to John GarryFrom: Xiang Chen <[email protected]>
Add BIST (built in self test) support for phy loopback.
Through the new debugfs interface, the user can configure loopback mode/linkrate/phy id/code mode before enabling it. And also user can enable/disable BIST function.
--- drivers/scsi/hisi_sas/hisi_sas.h | 10 + drivers/scsi/hisi_sas/hisi_sas_main.c | 407 +++++++++++++++++++++++++ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 126 ++++++++ 3 files changed, 543 insertions(+)
drivers/scsi/hisi_sas/hisi_sas.h +10 -0
@@ -310,6 +310,7 @@ struct hisi_sas_hw { int delay_ms, int timeout_ms);void (*snapshot_prepare)(struct hisi_hba *hisi_hba);void (*snapshot_restore)(struct hisi_hba *hisi_hba); +int (*set_bist)(struct hisi_hba *hisi_hba,bool enable);void (*read_iost_itct_cache)(struct hisi_hba *hisi_hba,enum hisi_sas_debugfs_cache_type type,u32 *cache);
@@ -391,6 +392,14 @@ struct hisi_hba {int cq_nvecs;unsigned int *reply_map; +/* bist */ +enum sas_linkrate debugfs_bist_linkrate; +int debugfs_bist_code_mode; +int debugfs_bist_phy_no; +int debugfs_bist_mode; +u32 debugfs_bist_cnt; +int debugfs_bist_enable; +/* debugfs memories */ /* Put Global AXI and RAS Register into register array */ u32 *debugfs_regs[DEBUGFS_REGS_NUM ];
@@ -404,6 +413,7 @@ struct hisi_hba {struct dentry *debugfs_dir;struct dentry *debugfs_dump_dentry; +struct dentry *debugfs_bist_dentry;bool debugfs_snapshot; };
drivers/scsi/hisi_sas/hisi_sas_main.c +407 -0
425 lines not on this page · raw message
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +126 -0
150 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 13/13 scsi: hisi_sas: Fix the conflict between device gone and host reset
In reply to John GarryFrom: Xiang Chen <[email protected]>
When device gone, it will check whether it is during reset, if not, it will send internal task abort. Before internal task abort returned, reset begins, and it will check whether SAS_PHY_UNUSED is set, if not, it will call hisi_sas_init_device(), but at that time domain_device may already be freed or part of it is freed, so it may referenece null pointer in hisi_sas_init_device(). It may occur as follows:
thread0 thread1
hisi_sas_dev_gone()
check whether in RESET(no)
internal task abort
reset prep
soft_reset
... (part of reset_done)
internal task abort failed
release resource anyway
clear_itct
device->lldd_dev=NULL
hisi_sas_reset_init_all_device
check sas_dev->dev_type is SAS_PHY_UNUSED and !device
set dev_type SAS_PHY_UNUSED
sas_free_device
hisi_sas_init_device
...
Semaphore hisi_hba.sema is used to sync the processes of device gone and host reset.
To solve the issue, expand the scope that semaphore protects and let them never occur together.
And also some places will check whether domain_device is NULL to judge whether the device is gone. So when device gone, need to clear sas_dev->sas_device.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +4 -3
@@ -1049,21 +1049,22 @@ static void hisi_sas_dev_gone(struct domain_device *device)dev_info (dev,"dev[%d:%x] is gone\n" , sas_dev->device_id, sas_dev->dev_type); +down (&hisi_hba->sem);if (!test_bit (HISI_SAS_RESET_BIT , &hisi_hba->flags)) {hisi_sas_internal_task_abort (hisi_hba, device,HISI_SAS_INT_ABT_DEV ,0 );hisi_sas_dereg_device (hisi_hba, device); -down (&hisi_hba->sem); hisi_hba->hw->clear_itct (hisi_hba, sas_dev); -up (&hisi_hba->sem); device->lldd_dev =NULL ; }if (hisi_hba->hw->free_device) hisi_hba->hw->free_device (sas_dev); sas_dev->dev_type =SAS_PHY_UNUSED ; + sas_dev->sas_device =NULL ; +up (&hisi_hba->sem); }static int hisi_sas_queue_command (struct sas_task *task,gfp_t gfp_flags)
@@ -1543,11 +1544,11 @@ void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba)msleep (1000 );hisi_sas_refresh_port_id (hisi_hba);clear_bit (HISI_SAS_REJECT_CMD_BIT , &hisi_hba->flags); -up (&hisi_hba->sem);if (hisi_hba->reject_stp_links_msk)hisi_sas_terminate_stp_reject (hisi_hba);hisi_sas_reset_init_all_devices (hisi_hba); +up (&hisi_hba->sem);scsi_unblock_requests (shost);clear_bit (HISI_SAS_RESET_BIT , &hisi_hba->flags);
Signature · 1 line
2.17.1
Martin K. Petersen
AppliedJohn,
Quoted 2 lines
This patchset includes support for some more minor features, a bit of tidying, and a few patches to make the driver a bit more robust.
Applied to 5.4/scsi-queue, thanks.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering