add fixes, device quirks, error recovery,
Subsystems (4)
cover add fixes, device quirks, error recovery,
V1:
This series should be pushed on top of 15 patches series:
"Big fixes, retries, handle a race condition"
Yaniv Gardi (17):
scsi: ufs-qcom: add number of lanes per direction
scsi: ufs: add option to change default UFS power management level
scsi: ufs: optimize system suspend handling
scsi: ufs: avoid spurious UFS host controller interrupts
scsi: ufs: implement scsi host timeout handler
scsi :ufs: verify hba controller hce reg value
scsi: ufs: separate device and host quirks
scsi: ufs: split broken LCC quirk
scsi: ufs: disable vccq if it's not needed by UFS device
scsi: ufs: make error handling bit faster
scsi: ufs: add error recovery after DL NAC error
scsi: ufs: add retry for query descriptors
scsi: ufs: handle non spec compliant bkops behaviour by device
scsi: ufs: tune UniPro parameters to optimize hibern8 exit time
scsi: ufs: fix leakage during link off state
scsi: ufs: add delay before putting UFS rails in low power modes
scsi: ufs-qcom: set PA_Local_TX_LCC_Enable before link startup
.../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 11 + drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs-qcom.c | 163 +++- drivers/scsi/ufs/ufs-qcom.h | 9 + drivers/scsi/ufs/ufs.h | 32 + drivers/scsi/ufs/ufs_quirks.c | 101 +++ drivers/scsi/ufs/ufs_quirks.h | 123 +++ drivers/scsi/ufs/ufshcd-pltfrm.c | 17 +- drivers/scsi/ufs/ufshcd.c | 829 ++++++++++++++++++--- drivers/scsi/ufs/ufshcd.h | 44 +- drivers/scsi/ufs/ufshci.h | 4 + drivers/scsi/ufs/unipro.h | 22 + 12 files changed, 1215 insertions(+), 142 deletions(-) create mode 100644 drivers/scsi/ufs/ufs_quirks.c create mode 100644 drivers/scsi/ufs/ufs_quirks.h
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 1/17 scsi: ufs-qcom: add number of lanes per direction
Different platform may have different number of lanes for the UFS link.
Add parameter to device tree specifying how many lanes should be configured for the UFS link.
--- .../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 3 ++ drivers/scsi/ufs/ufs-qcom.c | 38 ++++++++++++---------- drivers/scsi/ufs/ufshcd.c | 20 ++++++++++++ drivers/scsi/ufs/ufshcd.h | 2 ++ 4 files changed, 46 insertions(+), 17 deletions(-)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +3 -0
@@ -31,6 +31,9 @@ Optional properties: defined or a value in the array is "0" then it is assumed that the frequency is set by the parent clock or a fixed rate clock source. +- lanes-per-direction: number of lanes available per direction - either 1 or 2. + Note that it is assume same number of lanes is used both directions at once. + If not specified, default is 2 lanes per direction. Note: If above properties are not defined it can be assumed that the supply regulators or clocks are always on.
drivers/scsi/ufs/ufs-qcom.c +21 -17
@@ -132,21 +132,23 @@ static int ufs_qcom_enable_lane_clks(struct ufs_qcom_host *host)if (err) goto disable_rx_l0; - err =ufs_qcom_host_clk_enable (dev,"rx_lane1_sync_clk" , - host->rx_l1_sync_clk); -if (err) - goto disable_tx_l0; - - err =ufs_qcom_host_clk_enable (dev,"tx_lane1_sync_clk" , - host->tx_l1_sync_clk); -if (err) - goto disable_rx_l1; +if (host->hba->lanes_per_direction >1 ) { + err =ufs_qcom_host_clk_enable (dev,"rx_lane1_sync_clk" , + host->rx_l1_sync_clk); +if (err) + goto disable_tx_l0; + err =ufs_qcom_host_clk_enable (dev,"tx_lane1_sync_clk" , + host->tx_l1_sync_clk); +if (err) + goto disable_rx_l1; + } host->is_lane_clks_enabled = true; goto out; disable_rx_l1: -clk_disable_unprepare (host->rx_l1_sync_clk); +if (host->hba->lanes_per_direction >1 ) +clk_disable_unprepare (host->rx_l1_sync_clk); disable_tx_l0:clk_disable_unprepare (host->tx_l0_sync_clk); disable_rx_l0:
@@ -170,14 +172,16 @@ static int ufs_qcom_init_lane_clks(struct ufs_qcom_host *host)if (err) goto out; - err =ufs_qcom_host_clk_get (dev,"rx_lane1_sync_clk" , - &host->rx_l1_sync_clk); -if (err) - goto out; - - err =ufs_qcom_host_clk_get (dev,"tx_lane1_sync_clk" , - &host->tx_l1_sync_clk); +/* In case of single lane per direction, don't read lane1 clocks */ +if (host->hba->lanes_per_direction >1 ) { + err =ufs_qcom_host_clk_get (dev,"rx_lane1_sync_clk" , + &host->rx_l1_sync_clk); +if (err) + goto out; + err =ufs_qcom_host_clk_get (dev,"tx_lane1_sync_clk" , + &host->tx_l1_sync_clk); + } out:return err; }
drivers/scsi/ufs/ufshcd.c +20 -0
@@ -40,6 +40,7 @@#include <linux/async.h> #include <linux/devfreq.h> +#include <linux/of.h> #include "ufshcd.h" #include "unipro.h" #define UFSHCD_REQ_SENSE_SIZE 18
@@ -87,6 +88,8 @@/* Interrupt aggregation default timeout, unit: 40us */ #define INT_AGGR_DEF_TO 0x02 +#define UFSHCD_DEFAULT_LANES_PER_DIRECTION 2 +#define ufshcd_toggle_vreg (_dev, _vreg, _on) \ ({ \ int _ret; \
@@ -5765,6 +5768,21 @@ static struct devfreq_dev_profile ufs_devfreq_profile = { .get_dev_status = ufshcd_devfreq_get_dev_status, }; +static void ufshcd_init_lanes_per_dir (struct ufs_hba *hba) +{ +struct device *dev = hba->dev; +int ret; + + ret =of_property_read_u32 (dev->of_node,"lanes-per-direction" , + &hba->lanes_per_direction); +if (ret) { +dev_dbg (hba->dev, +"%s: failed to read lanes-per-direction, ret=%d\n" , + __func__, ret); + hba->lanes_per_direction =UFSHCD_DEFAULT_LANES_PER_DIRECTION ; + } +} +/** * ufshcd_init - Driver initialization routine * @hba: per-adapter instance
@@ -5788,6 +5806,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->mmio_base = mmio_base; hba->irq = irq; +ufshcd_init_lanes_per_dir (hba); + err =ufshcd_hba_init (hba);if (err) goto out_error;
drivers/scsi/ufs/ufshcd.h +2 -0
@@ -509,6 +509,8 @@ struct ufs_hba {bool wlun_dev_clr_ua; +/* Number of lanes available (1 or 2) for Rx/Tx */ +u32 lanes_per_direction;struct ufs_pa_layer_attr pwr_info;struct ufs_pwr_mode_info max_pwr_info;
Signature · 8 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/17 scsi: ufs: add option to change default UFS power management level
In reply to Yaniv GardiUFS device and link can be put in multiple different low power modes hence UFS driver supports multiple different low power modes. By default UFS driver selects the default (optimal) low power mode (which gives moderate power savings and have relatively less enter and exit latencies) but we might have to tune this default power mode for different chipset platforms to meet the low power requirements/goals. Hence this patch adds option to change default UFS low power mode (level).
--- .../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 8 +++++ drivers/scsi/ufs/ufs-qcom.c | 9 ++--- drivers/scsi/ufs/ufshcd-pltfrm.c | 17 +++++++++- drivers/scsi/ufs/ufshcd.c | 39 ++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 4 +-- 5 files changed, 70 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +8 -0
@@ -31,6 +31,14 @@ Optional properties: defined or a value in the array is "0" then it is assumed that the frequency is set by the parent clock or a fixed rate clock source. +- rpm-level : UFS Runtime power management level. Following PM levels are supported: + 0 - Both UFS device and Link in active state (Highest power consumption) + 1 - UFS device in active state but Link in Hibern8 state + 2 - UFS device in Sleep state but Link in active state + 3 - UFS device in Sleep state and Link in hibern8 state (default PM level) + 4 - UFS device in Power-down state and Link in Hibern8 state + 5 - UFS device in Power-down state and Link in OFF state (Lowest power consumption) +- spm-level : UFS System power management level. Allowed PM levels are same as rpm-level. - lanes-per-direction: number of lanes available per direction - either 1 or 2. Note that it is assume same number of lanes is used both directions at once. If not specified, default is 2 lanes per direction.
drivers/scsi/ufs/ufs-qcom.c +5 -4
@@ -1195,11 +1195,12 @@ static int ufs_qcom_init(struct ufs_hba *hba)if (res) { host->dev_ref_clk_ctrl_mmio =devm_ioremap_resource (dev, res); -if (IS_ERR (host->dev_ref_clk_ctrl_mmio)) { -dev_warn (dev, -"%s: could not map dev_ref_clk_ctrl_mmio, err %ld\n" , +if (IS_ERR ((__force void const *) + host->dev_ref_clk_ctrl_mmio)) { +dev_warn (dev,"%s: could not map dev_ref_clk_ctrl_mmio, err %ld\n" , __func__, -PTR_ERR (host->dev_ref_clk_ctrl_mmio)); +PTR_ERR ((__force void const *) + host->dev_ref_clk_ctrl_mmio)); host->dev_ref_clk_ctrl_mmio =NULL ; } host->dev_ref_clk_en_mask =BIT (5 );
drivers/scsi/ufs/ufshcd-pltfrm.c +16 -1
@@ -224,7 +224,20 @@ out:return err; } -#ifdef CONFIG_PM +static void ufshcd_parse_pm_levels (struct ufs_hba *hba) +{ +struct device *dev = hba->dev; +struct device_node *np = dev->of_node; + +if (np) { +if (of_property_read_u32 (np,"rpm-level" , &hba->rpm_lvl)) + hba->rpm_lvl =-1 ; +if (of_property_read_u32 (np,"spm-level" , &hba->spm_lvl)) + hba->spm_lvl =-1 ; + } +} + +#ifdef CONFIG_SMP /** * ufshcd_pltfrm_suspend - suspend power management function * @dev: pointer to device handle
@@ -328,6 +341,8 @@ int ufshcd_pltfrm_init(struct platform_device *pdev, goto out; } +ufshcd_parse_pm_levels (hba); +pm_runtime_set_active (&pdev->dev);pm_runtime_enable (&pdev->dev);
drivers/scsi/ufs/ufshcd.c +39 -0
@@ -188,6 +188,30 @@ ufs_get_pm_lvl_to_link_pwr_state(enum ufs_pm_level lvl)return ufs_pm_lvl_states[lvl].link_state; } +static inline enum ufs_pm_level +ufs_get_desired_pm_lvl_for_dev_link_state (enum ufs_dev_pwr_mode dev_state, +enum uic_link_state link_state) +{ +enum ufs_pm_level lvl; + +for (lvl =UFS_PM_LVL_0 ; lvl <UFS_PM_LVL_MAX ; lvl++) { +if ((ufs_pm_lvl_states[lvl].dev_state == dev_state) && + (ufs_pm_lvl_states[lvl].link_state == link_state)) +return lvl; + } + +/* if no match found, return the level 0 */ +return UFS_PM_LVL_0 ; +} + +static inline bool ufshcd_is_valid_pm_lvl (int lvl) +{ +if (lvl >=0 && lvl <ARRAY_SIZE (ufs_pm_lvl_states)) +return true; +else +return false; +} +static void ufshcd_tmc_handler (struct ufs_hba *hba);static void ufshcd_async_scan (void *data,async_cookie_t cookie);static int ufshcd_reset_and_restore (struct ufs_hba *hba);
@@ -5907,6 +5931,21 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->clk_scaling.window_start_t =0 ; } +/* +* If rpm_lvl and and spm_lvl are not already set to valid levels, +* set the default power management level for UFS runtime and system +* suspend. Default power saving mode selected is keeping UFS link in +* Hibern8 state and UFS device in sleep. +*/ +if (!ufshcd_is_valid_pm_lvl (hba->rpm_lvl)) + hba->rpm_lvl =ufs_get_desired_pm_lvl_for_dev_link_state ( +UFS_SLEEP_PWR_MODE , +UIC_LINK_HIBERN8_STATE ); +if (!ufshcd_is_valid_pm_lvl (hba->spm_lvl)) + hba->spm_lvl =ufs_get_desired_pm_lvl_for_dev_link_state ( +UFS_SLEEP_PWR_MODE , +UIC_LINK_HIBERN8_STATE ); +/* Hold auto suspend until async scan completes */ pm_runtime_get_sync (dev);
drivers/scsi/ufs/ufshcd.h +2 -2
@@ -408,9 +408,9 @@ struct ufs_hba {enum ufs_dev_pwr_mode curr_dev_pwr_mode;enum uic_link_state uic_link_state;/* Desired UFS power management level during runtime PM */ -enum ufs_pm_level rpm_lvl; +int rpm_lvl;/* Desired UFS power management level during system PM */ -enum ufs_pm_level spm_lvl; +int spm_lvl;int pm_op_in_progress;struct ufshcd_lrb *lrb;
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 3/17 scsi: ufs: optimize system suspend handling
In reply to Yaniv GardiConsider following sequence of events:
1. UFS is runtime suspended, link_state = Hibern8, device_state = sleep
2. System goes into system suspend, ufshcd_system_suspend() brings both link and device to active state and then puts the device in Power_Down state and link in OFF state.
3. System resumes at some later point in time, ufshcd_system_resume() doesn't do anything as UFS state is runtime suspended. Note that link is still on OFF state and device is in Power_Down state.
4. Now system again goes into suspend without any UFS accesses before it.
ufshcd_system_suspend() again brings both link and device to active state and then puts the device in Power_Down state and link if OFF state. But it's unnecessary to bring the link & device in active state as both link and device are already in desired low power states. This change fixes this issue by adding proper state checks in ufshcd_system_suspend().
--- drivers/scsi/ufs/ufshcd.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/scsi/ufs/ufshcd.c +6 -9
@@ -5464,16 +5464,13 @@ int ufshcd_system_suspend(struct ufs_hba *hba)if (!hba || !hba->is_powered)return 0 ; -if (pm_runtime_suspended (hba->dev)) { -if (hba->rpm_lvl == hba->spm_lvl) -/* -* There is possibility that device may still be in -* active state during the runtime suspend. -*/ -if ((ufs_get_pm_lvl_to_dev_pwr_mode (hba->spm_lvl) == - hba->curr_dev_pwr_mode) && !hba->auto_bkops_enabled) - goto out; +if ((ufs_get_pm_lvl_to_dev_pwr_mode (hba->spm_lvl) == + hba->curr_dev_pwr_mode) && + (ufs_get_pm_lvl_to_link_pwr_state (hba->spm_lvl) == + hba->uic_link_state)) + goto out; +if (pm_runtime_suspended (hba->dev)) {/* * UFS device and/or UFS link low power states during runtime * suspend seems to be different than what is expected during
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 4/17 scsi: ufs: avoid spurious UFS host controller interrupts
In reply to Yaniv GardiWhen control reaches to Linux UFS driver during UFS boot mode, UFS host controller interrupt status/enable registers may have left over settings.
In order to avoid any spurious interrupts due to these left overs, it's important to clear these interrupt status/enable registers before enabling UFS interrupt handling.
--- drivers/scsi/ufs/ufshcd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/scsi/ufs/ufshcd.c +15 -0
@@ -5886,6 +5886,21 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)init_waitqueue_head (&hba->dev_cmd.tag_wq);ufshcd_init_clk_gating (hba); + +/* +* In order to avoid any spurious interrupt immediately after +* registering UFS controller interrupt handler, clear any pending UFS +* interrupt status and disable all the UFS interrupts. +*/ +ufshcd_writel (hba,ufshcd_readl (hba,REG_INTERRUPT_STATUS ), +REG_INTERRUPT_STATUS ); +ufshcd_writel (hba,0 ,REG_INTERRUPT_ENABLE ); +/* +* Make sure that UFS interrupts are disabled and any pending interrupt +* status is cleared before registering UFS interrupt handler. +*/ +mb (); +/* IRQ registration */ err =devm_request_irq (dev, irq, ufshcd_intr,IRQF_SHARED ,UFSHCD , hba);if (err) {
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 5/17 scsi: ufs: implement scsi host timeout handler
In reply to Yaniv GardiA race condition exists between request requeueing and scsi layer error handling:
When UFS driver queuecommand returns a busy status for a request, it will be requeued and its tag will be freed and set to -1. At the same time it is possible that the request will timeout and scsi layer will start error handling for it. The scsi layer reuses the request and its tag to send error related commands to the device, however its tag is no longer valid.
As this request was never really sent to the device, there is no point to start error handling with the device.
Implement the scsi error handling timeout callback and bypass SCSI error handling for request that were not actually sent to the device. For such requests simply reset the block layer timer. Otherwise, let SCSI layer perform the usual error handling.
--- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/scsi/ufs/ufshcd.c +36 -0
@@ -4602,6 +4602,41 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)ufshcd_probe_hba (hba); } +static enum blk_eh_timer_return ufshcd_eh_timed_out (struct scsi_cmnd *scmd) +{ +unsigned long flags; +struct Scsi_Host *host; +struct ufs_hba *hba; +int index; +bool found = false; + +if (!scmd || !scmd->device || !scmd->device->host) +return BLK_EH_NOT_HANDLED ; + + host = scmd->device->host; + hba =shost_priv (host); +if (!hba) +return BLK_EH_NOT_HANDLED ; + +spin_lock_irqsave (host->host_lock, flags); + +for_each_set_bit (index, &hba->outstanding_reqs, hba->nutrs) { +if (hba->lrb[index].cmd == scmd) { + found = true; +break ; + } + } + +spin_unlock_irqrestore (host->host_lock, flags); + +/* +* Bypass SCSI error handling and reset the block layer timer if this +* SCSI command was not actually dispatched to UFS driver, otherwise +* let SCSI layer handle the error as usual. +*/ +return found ?BLK_EH_NOT_HANDLED :BLK_EH_RESET_TIMER ; +} +static struct scsi_host_template ufshcd_driver_template = { .module =THIS_MODULE , .name =UFSHCD ,
@@ -4614,6 +4649,7 @@ static struct scsi_host_template ufshcd_driver_template = { .eh_abort_handler = ufshcd_abort, .eh_device_reset_handler = ufshcd_eh_device_reset_handler, .eh_host_reset_handler = ufshcd_eh_host_reset_handler, + .eh_timed_out = ufshcd_eh_timed_out, .this_id = -1, .sg_tablesize = SG_ALL, .cmd_per_lun = UFSHCD_CMD_PER_LUN,
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 6/17 scsi :ufs: verify hba controller hce reg value
In reply to Yaniv GardiSometimes due to hw issues it takes some time to the host controller register to update. In order to verify the register has updated, a polling is done until its value is set.
In addition the functions ufshcd_hba_stop() and ufshcd_wait_for_register() was updated with an additional input parameter, indicating the timeout between reads will be done by sleeping or spinning the cpu.
--- drivers/scsi/ufs/ufshcd.c | 54 ++++++++++++++++++++++++++++------------------- drivers/scsi/ufs/ufshcd.h | 12 +++-------- 2 files changed, 35 insertions(+), 31 deletions(-)
drivers/scsi/ufs/ufshcd.c +32 -22
@@ -267,11 +267,12 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba)* @val - wait condition * @interval_us - polling interval in microsecs * @timeout_ms - timeout in millisecs -* +* @can_sleep - perform sleep or just spin * Returns -ETIMEDOUT on error, zero on success */ -static int ufshcd_wait_for_register (struct ufs_hba *hba,u32 reg,u32 mask, -u32 val,unsigned long interval_us,unsigned long timeout_ms) +int ufshcd_wait_for_register (struct ufs_hba *hba,u32 reg,u32 mask, +u32 val,unsigned long interval_us, +unsigned long timeout_ms,bool can_sleep) {int err =0 ;unsigned long timeout = jiffies +msecs_to_jiffies (timeout_ms);
@@ -280,9 +281,10 @@ static int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask, val = val & mask;while ((ufshcd_readl (hba, reg) & mask) != val) { -/* wakeup within 50us of expiry */ -usleep_range (interval_us, interval_us +50 ); - +if (can_sleep) +usleep_range (interval_us, interval_us +50 ); +else +udelay (interval_us);if (time_after (jiffies, timeout)) {if ((ufshcd_readl (hba, reg) & mask) != val) err = -ETIMEDOUT ;
@@ -1491,7 +1493,7 @@ ufshcd_clear_cmd(struct ufs_hba *hba, int tag)*/ err =ufshcd_wait_for_register (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL , - mask, ~mask,1000 ,1000 ); + mask, ~mask,1000 ,1000 , true);return err; }
@@ -2847,6 +2849,23 @@ out: }/** +* ufshcd_hba_stop - Send controller to reset state +* @hba: per adapter instance +* @can_sleep: perform sleep or just spin +*/ +static inline void ufshcd_hba_stop (struct ufs_hba *hba,bool can_sleep) +{ +int err; + +ufshcd_writel (hba,CONTROLLER_DISABLE ,REG_CONTROLLER_ENABLE ); + err =ufshcd_wait_for_register (hba,REG_CONTROLLER_ENABLE , +CONTROLLER_ENABLE ,CONTROLLER_DISABLE , +10 ,1 , can_sleep); +if (err) +dev_err (hba->dev,"%s: Controller disable failed\n" , __func__); +} + +/** * ufshcd_hba_enable - initialize the controller * @hba: per adapter instance *
@@ -2866,18 +2885,9 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)* development and testing of this driver. msleep can be changed to * mdelay and retry count can be reduced based on the controller. */ -if (!ufshcd_is_hba_active (hba)) { - +if (!ufshcd_is_hba_active (hba))/* change controller state to "reset state" */ -ufshcd_hba_stop (hba); - -/* -* This delay is based on the testing done with UFS host -* controller FPGA. The delay can be changed based on the -* host controller used. -*/ -msleep (5 ); - } +ufshcd_hba_stop (hba, true);/* UniPro link is disabled at this point */ ufshcd_set_link_off (hba);
@@ -3930,7 +3940,7 @@ static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag)/* poll for max. 1 sec to clear door bell register by h/w */ err =ufshcd_wait_for_register (hba,REG_UTP_TASK_REQ_DOOR_BELL , - mask,0 ,1000 ,1000 ); + mask,0 ,1000 ,1000 , true); out:return err; }
@@ -4214,7 +4224,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)/* Reset the host controller */ spin_lock_irqsave (hba->host->host_lock, flags); -ufshcd_hba_stop (hba); +ufshcd_hba_stop (hba, false);spin_unlock_irqrestore (hba->host->host_lock, flags); err =ufshcd_hba_enable (hba);
@@ -5168,7 +5178,7 @@ static int ufshcd_link_state_transition(struct ufs_hba *hba,* Change controller state to "reset state" which * should also put the link in off/reset state */ -ufshcd_hba_stop (hba); +ufshcd_hba_stop (hba, true);/* * TODO: Check if we need any delay to make sure that * controller is reset
@@ -5641,7 +5651,7 @@ void ufshcd_remove(struct ufs_hba *hba)scsi_remove_host (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask); -ufshcd_hba_stop (hba); +ufshcd_hba_stop (hba, true);scsi_host_put (hba->host);
drivers/scsi/ufs/ufshcd.h +3 -9
@@ -590,15 +590,9 @@ int ufshcd_alloc_host(struct device *, struct ufs_hba **);void ufshcd_dealloc_host (struct ufs_hba *);int ufshcd_init (struct ufs_hba * ,void __iomem * ,unsigned int );void ufshcd_remove (struct ufs_hba *); - -/** -* ufshcd_hba_stop - Send controller to reset state -* @hba: per adapter instance -*/ -static inline void ufshcd_hba_stop (struct ufs_hba *hba) -{ -ufshcd_writel (hba,CONTROLLER_DISABLE ,REG_CONTROLLER_ENABLE ); -} +int ufshcd_wait_for_register (struct ufs_hba *hba,u32 reg,u32 mask, +u32 val,unsigned long interval_us, +unsigned long timeout_ms,bool can_sleep);static inline void check_upiu_size (void ) {
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 7/17 scsi: ufs: separate device and host quirks
In reply to Yaniv GardiCurrently we use the host quirks mechanism in order to handle both device and host controller quirks.
In order to support various of UFS devices we should separate handling the device quirks from the host controller's.
--- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs.h | 31 +++++++++++ drivers/scsi/ufs/ufs_quirks.c | 101 ++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufs_quirks.h | 123 ++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 90 ++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 10 ++++ 6 files changed, 355 insertions(+), 2 deletions(-) create mode 100644 drivers/scsi/ufs/ufs_quirks.c create mode 100644 drivers/scsi/ufs/ufs_quirks.h
drivers/scsi/ufs/Makefile +1 -1
@@ -1,5 +1,5 @@ # UFSHCD makefile obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o -obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o +obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o ufs_quirks.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
drivers/scsi/ufs/ufs.h +31 -0
@@ -43,6 +43,7 @@#define GENERAL_UPIU_REQUEST_SIZE 32#define QUERY_DESC_MAX_SIZE 255#define QUERY_DESC_MIN_SIZE 2 +#define QUERY_DESC_HDR_SIZE 2#define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \ (sizeof(struct utp_upiu_header)))
@@ -195,6 +196,36 @@ enum unit_desc_param { UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22, }; +/* Device descriptor parameters offsets in bytes*/ +enum device_desc_param { +DEVICE_DESC_PARAM_LEN =0x0 , +DEVICE_DESC_PARAM_TYPE =0x1 , +DEVICE_DESC_PARAM_DEVICE_TYPE =0x2 , +DEVICE_DESC_PARAM_DEVICE_CLASS =0x3 , +DEVICE_DESC_PARAM_DEVICE_SUB_CLASS =0x4 , +DEVICE_DESC_PARAM_PRTCL =0x5 , +DEVICE_DESC_PARAM_NUM_LU =0x6 , +DEVICE_DESC_PARAM_NUM_WLU =0x7 , +DEVICE_DESC_PARAM_BOOT_ENBL =0x8 , +DEVICE_DESC_PARAM_DESC_ACCSS_ENBL =0x9 , +DEVICE_DESC_PARAM_INIT_PWR_MODE =0xA , +DEVICE_DESC_PARAM_HIGH_PR_LUN =0xB , +DEVICE_DESC_PARAM_SEC_RMV_TYPE =0xC , +DEVICE_DESC_PARAM_SEC_LU =0xD , +DEVICE_DESC_PARAM_BKOP_TERM_LT =0xE , +DEVICE_DESC_PARAM_ACTVE_ICC_LVL =0xF , +DEVICE_DESC_PARAM_SPEC_VER =0x10 , +DEVICE_DESC_PARAM_MANF_DATE =0x12 , +DEVICE_DESC_PARAM_MANF_NAME =0x14 , +DEVICE_DESC_PARAM_PRDCT_NAME =0x15 , +DEVICE_DESC_PARAM_SN =0x16 , +DEVICE_DESC_PARAM_OEM_ID =0x17 , +DEVICE_DESC_PARAM_MANF_ID =0x18 , +DEVICE_DESC_PARAM_UD_OFFSET =0x1A , +DEVICE_DESC_PARAM_UD_LEN =0x1B , +DEVICE_DESC_PARAM_RTT_CAP =0x1C , +DEVICE_DESC_PARAM_FRQ_RTC =0x1D , +};/* * Logical Unit Write Protect * 00h: LU not write protected
drivers/scsi/ufs/ufs_quirks.c new file +101 -0
101 lines not on this page · raw message
drivers/scsi/ufs/ufs_quirks.h new file +123 -0
123 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.c +89 -1
116 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +10 -0
@@ -470,6 +470,9 @@ struct ufs_hba {unsigned int quirks;/* Deviations from standard UFSHCI spec. */ +/* Device deviations from standard UFS device spec. */ +unsigned int dev_quirks; +wait_queue_head_t tm_wq;wait_queue_head_t tm_tag_wq;unsigned long tm_condition;
@@ -678,6 +681,13 @@ static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,return ufshcd_dme_get_attr (hba, attr_sel, mib_val,DME_PEER ); } +int ufshcd_read_device_desc (struct ufs_hba *hba,u8 *buf,u32 size); + +#define ASCII_STD true + +int ufshcd_read_string_desc (struct ufs_hba *hba,int desc_index,u8 *buf, +u32 size,bool ascii); +/* Expose Query-Request API */ int ufshcd_query_flag (struct ufs_hba *hba,enum query_opcode opcode,enum flag_idn idn,bool *flag_res);
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 8/17 scsi: ufs: split broken LCC quirk
In reply to Yaniv GardiCurrently when UFSHCD_BROKEN_LCC quirk is defined, LCC is getting disabled on both host and device side but there could be a need where we don't want to disable the LCC on both side hence this change splits the quirk in 2 parts one for host and one for device.
--- drivers/scsi/ufs/ufshcd.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/scsi/ufs/ufshcd.c +11 -0
@@ -3048,6 +3048,11 @@ static int ufshcd_disable_tx_lcc(struct ufs_hba *hba, bool peer)return err; } +static inline int ufshcd_disable_host_tx_lcc (struct ufs_hba *hba) +{ +return ufshcd_disable_tx_lcc (hba, false); +} +static inline int ufshcd_disable_device_tx_lcc (struct ufs_hba *hba) {return ufshcd_disable_tx_lcc (hba, true);
@@ -3095,6 +3100,12 @@ static int ufshcd_link_startup(struct ufs_hba *hba) goto out; } +if (hba->dev_quirks &UFS_DEVICE_QUIRK_BROKEN_LCC ) { + ret =ufshcd_disable_host_tx_lcc (hba); +if (ret) + goto out; + } +/* Include any host controller configuration via UIC commands */ ret =ufshcd_vops_link_startup_notify (hba,POST_CHANGE );if (ret)
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 9/17 scsi: ufs: disable vccq if it's not needed by UFS device
In reply to Yaniv GardiSome UFS devices don't require VCCQ rail for device operations hence this change adds support to recognize such devices and remove vote for the unused VCCQ rail.
--- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufshcd.c | 60 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-)
drivers/scsi/ufs/ufs.h +1 -0
@@ -500,6 +500,7 @@ struct ufs_vreg {struct regulator *reg;const char *name;bool enabled; +bool unused;int min_uV;int max_uV;int min_uA;
drivers/scsi/ufs/ufshcd.c +56 -4
101 lines not on this page · raw message
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 10/17 scsi: ufs: make error handling bit faster
In reply to Yaniv GardiUFS driver's error handler forcefully tries to clear all the pending requests. For each pending request in the queue, it waits 1 sec for it to get cleared. If we have multiple requests in the queue then it's possible that we might end up waiting for those many seconds before resetting the host. But note that resetting host would any way clear all the pending requests from the hardware. Hence this change skips the forceful clear of the pending requests if we are anyway going to reset the host (for fatal errors).
--- drivers/scsi/ufs/ufshcd.c | 155 +++++++++++++++++++++++++++++++++------------- 1 file changed, 112 insertions(+), 43 deletions(-)
drivers/scsi/ufs/ufshcd.c +112 -43
@@ -136,9 +136,11 @@ enum {/* UFSHCD UIC layer error flags */ enum {UFSHCD_UIC_DL_PA_INIT_ERROR = (1 <<0 ),/* Data link layer error */ -UFSHCD_UIC_NL_ERROR = (1 <<1 ),/* Network layer error */ -UFSHCD_UIC_TL_ERROR = (1 <<2 ),/* Transport Layer error */ -UFSHCD_UIC_DME_ERROR = (1 <<3 ),/* DME error */ +UFSHCD_UIC_DL_NAC_RECEIVED_ERROR = (1 <<1 ),/* Data link layer error */ + UFSHCD_UIC_DL_TCx_REPLAY_ERROR = (1 <<2 ),/* Data link layer error */ +UFSHCD_UIC_NL_ERROR = (1 <<3 ),/* Network layer error */ +UFSHCD_UIC_TL_ERROR = (1 <<4 ),/* Transport Layer error */ +UFSHCD_UIC_DME_ERROR = (1 <<5 ),/* DME error */ };/* Interrupt configuration options */
@@ -3507,31 +3509,18 @@ static void ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status) }/** -* ufshcd_transfer_req_compl - handle SCSI and query command completion +* __ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance +* @completed_reqs: requests to complete */ -static void ufshcd_transfer_req_compl (struct ufs_hba *hba) +static void __ufshcd_transfer_req_compl (struct ufs_hba *hba, +unsigned long completed_reqs) {struct ufshcd_lrb *lrbp;struct scsi_cmnd *cmd; -unsigned long completed_reqs; -u32 tr_doorbell;int result;int index; -/* Resetting interrupt aggregation counters first and reading the -* DOOR_BELL afterward allows us to handle all the completed requests. -* In order to prevent other interrupts starvation the DB is read once -* after reset. The down side of this solution is the possibility of -* false interrupt if device completes another request after resetting -* aggregation and before reading the DB. -*/ -if (ufshcd_is_intr_aggr_allowed (hba)) -ufshcd_reset_intr_aggr (hba); - - tr_doorbell =ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); - completed_reqs = tr_doorbell ^ hba->outstanding_reqs; -for_each_set_bit (index, &completed_reqs, hba->nutrs) { lrbp = &hba->lrb[index]; cmd = lrbp->cmd;
@@ -3561,6 +3550,31 @@ static void ufshcd_transfer_req_compl(struct ufs_hba *hba) }/** +* ufshcd_transfer_req_compl - handle SCSI and query command completion +* @hba: per adapter instance +*/ +static void ufshcd_transfer_req_compl (struct ufs_hba *hba) +{ +unsigned long completed_reqs; +u32 tr_doorbell; + +/* Resetting interrupt aggregation counters first and reading the +* DOOR_BELL afterward allows us to handle all the completed requests. +* In order to prevent other interrupts starvation the DB is read once +* after reset. The down side of this solution is the possibility of +* false interrupt if device completes another request after resetting +* aggregation and before reading the DB. +*/ +if (ufshcd_is_intr_aggr_allowed (hba)) +ufshcd_reset_intr_aggr (hba); + + tr_doorbell =ufshcd_readl (hba,REG_UTP_TRANSFER_REQ_DOOR_BELL ); + completed_reqs = tr_doorbell ^ hba->outstanding_reqs; + +__ufshcd_transfer_req_compl (hba, completed_reqs); +} + +/** * ufshcd_disable_ee - disable exception event * @hba: per-adapter instance * @mask: exception event to disable
@@ -3815,6 +3829,13 @@ out:return ; } +/* Complete requests that have door-bell cleared */ +static void ufshcd_complete_requests (struct ufs_hba *hba) +{ +ufshcd_transfer_req_compl (hba); +ufshcd_tmc_handler (hba); +} +/** * ufshcd_err_handler - handle UFS errors that require s/w attention * @work: pointer to work structure
@@ -3827,6 +3848,7 @@ static void ufshcd_err_handler(struct work_struct *work)u32 err_tm =0 ;int err =0 ;int tag; +bool needs_reset = false; hba = container_of(work, struct ufs_hba, eh_work);
@@ -3834,40 +3856,75 @@ static void ufshcd_err_handler(struct work_struct *work)ufshcd_hold (hba, false);spin_lock_irqsave (hba->host->host_lock, flags); -if (hba->ufshcd_state ==UFSHCD_STATE_RESET ) { -spin_unlock_irqrestore (hba->host->host_lock, flags); +if (hba->ufshcd_state ==UFSHCD_STATE_RESET ) goto out; - } hba->ufshcd_state =UFSHCD_STATE_RESET ;ufshcd_set_eh_in_progress (hba);/* Complete requests that have door-bell cleared by h/w */ -ufshcd_transfer_req_compl (hba); -ufshcd_tmc_handler (hba); -spin_unlock_irqrestore (hba->host->host_lock, flags); +ufshcd_complete_requests (hba); +if ((hba->saved_err &INT_FATAL_ERRORS ) || + ((hba->saved_err &UIC_ERROR ) && + (hba->saved_uic_err & (UFSHCD_UIC_DL_PA_INIT_ERROR | +UFSHCD_UIC_DL_NAC_RECEIVED_ERROR | + UFSHCD_UIC_DL_TCx_REPLAY_ERROR)))) + needs_reset = true; +/* +* if host reset is required then skip clearing the pending +* transfers forcefully because they will automatically get +* cleared after link startup. +*/ +if (needs_reset) + goto skip_pending_xfer_clear; + +/* release lock as clear command might sleep */ +spin_unlock_irqrestore (hba->host->host_lock, flags);/* Clear pending transfer requests */ -for_each_set_bit (tag, &hba->outstanding_reqs, hba->nutrs) -if (ufshcd_clear_cmd (hba, tag)) - err_xfer |=1 << tag; +for_each_set_bit (tag, &hba->outstanding_reqs, hba->nutrs) { +if (ufshcd_clear_cmd (hba, tag)) { + err_xfer = true; + goto lock_skip_pending_xfer_clear; + } + }/* Clear pending task management requests */ -for_each_set_bit (tag, &hba->outstanding_tasks, hba->nutmrs) -if (ufshcd_clear_tm_cmd (hba, tag)) - err_tm |=1 << tag; +for_each_set_bit (tag, &hba->outstanding_tasks, hba->nutmrs) { +if (ufshcd_clear_tm_cmd (hba, tag)) { + err_tm = true; + goto lock_skip_pending_xfer_clear; + } + } -/* Complete the requests that are cleared by s/w */ +lock_skip_pending_xfer_clear:spin_lock_irqsave (hba->host->host_lock, flags); -ufshcd_transfer_req_compl (hba); -ufshcd_tmc_handler (hba); -spin_unlock_irqrestore (hba->host->host_lock, flags); +/* Complete the requests that are cleared by s/w */ +ufshcd_complete_requests (hba); + +if (err_xfer || err_tm) + needs_reset = true; + +skip_pending_xfer_clear:/* Fatal errors need reset */ -if (err_xfer || err_tm || (hba->saved_err &INT_FATAL_ERRORS ) || - ((hba->saved_err &UIC_ERROR ) && - (hba->saved_uic_err &UFSHCD_UIC_DL_PA_INIT_ERROR ))) { +if (needs_reset) { +unsigned long max_doorbells = (1UL << hba->nutrs) -1 ; + +/* +* ufshcd_reset_and_restore() does the link reinitialization +* which will need atleast one empty doorbell slot to send the +* device management commands (NOP and query commands). +* If there is no slot empty at this moment then free up last +* slot forcefully. +*/ +if (hba->outstanding_reqs == max_doorbells) +__ufshcd_transfer_req_compl (hba, + (1UL << (hba->nutrs -1 ))); + +spin_unlock_irqrestore (hba->host->host_lock, flags); err =ufshcd_reset_and_restore (hba); +spin_lock_irqsave (hba->host->host_lock, flags);if (err) {dev_err (hba->dev,"%s: reset and restore failed\n" , __func__);
@@ -3881,9 +3938,18 @@ static void ufshcd_err_handler(struct work_struct *work) hba->saved_err =0 ; hba->saved_uic_err =0 ; } + +if (!needs_reset) { + hba->ufshcd_state =UFSHCD_STATE_OPERATIONAL ; +if (hba->saved_err || hba->saved_uic_err) +dev_err_ratelimited (hba->dev,"%s: exit: saved_err 0x%x saved_uic_err 0x%x" , + __func__, hba->saved_err, hba->saved_uic_err); + } +ufshcd_clear_eh_in_progress (hba); out: +spin_unlock_irqrestore (hba->host->host_lock, flags);scsi_unblock_requests (hba->host);ufshcd_release (hba);pm_runtime_put_sync (hba->dev);
@@ -3938,15 +4004,18 @@ static void ufshcd_check_errors(struct ufs_hba *hba) }if (queue_eh_work) { +/* +* update the transfer error masks to sticky bits, let's do this +* irrespective of current ufshcd_state. +*/ + hba->saved_err |= hba->errors; + hba->saved_uic_err |= hba->uic_error; +/* handle fatal errors only when link is functional */ if (hba->ufshcd_state ==UFSHCD_STATE_OPERATIONAL ) {/* block commands from scsi mid-layer */ scsi_block_requests (hba->host); -/* transfer error masks to sticky bits */ - hba->saved_err |= hba->errors; - hba->saved_uic_err |= hba->uic_error; - hba->ufshcd_state =UFSHCD_STATE_ERROR ;schedule_work (&hba->eh_work); }
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 11/17 scsi: ufs: add error recovery after DL NAC error
In reply to Yaniv GardiSome vendor's UFS device sends back to back NACs for the DL data frames causing the host controller to raise the DFES error status. Sometimes such UFS devices send back to back NAC without waiting for new retransmitted DL frame from the host and in such cases it might be possible the Host UniPro goes into bad state without raising the DFES error interrupt. If this happens then all the pending commands would timeout only after respective SW command (which is generally too large).
This change workarounds such device behaviour like this:
- As soon as SW sees the DL NAC error, it would schedule the error handler
- Error handler would sleep for 50ms to see if there any fatal errors raised by UFS controller.
- If there are fatal errors then SW does normal error recovery.
- If there are no fatal errors then SW sends the NOP command to device to check if link is alive.
- If NOP command times out, SW does normal error recovery
- If NOP command succeed, skip the error handling.
If DL NAC error is seen multiple times with some vendor's UFS devices then enable this quirk to initiate quick error recovery and also silence related error logs to reduce spamming of kernel logs.
--- drivers/scsi/ufs/ufshcd.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshci.h | 2 + 2 files changed, 95 insertions(+)
drivers/scsi/ufs/ufshcd.c +93 -0
@@ -3837,6 +3837,79 @@ static void ufshcd_complete_requests(struct ufs_hba *hba) }/** +* ufshcd_quirk_dl_nac_errors - This function checks if error handling is +* to recover from the DL NAC errors or not. +* @hba: per-adapter instance +* +* Returns true if error handling is required, false otherwise +*/ +static bool ufshcd_quirk_dl_nac_errors (struct ufs_hba *hba) +{ +unsigned long flags; +bool err_handling = true; + +spin_lock_irqsave (hba->host->host_lock, flags); +/* +* UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS only workaround the +* device fatal error and/or DL NAC & REPLAY timeout errors. +*/ +if (hba->saved_err & (CONTROLLER_FATAL_ERROR |SYSTEM_BUS_FATAL_ERROR )) + goto out; + +if ((hba->saved_err &DEVICE_FATAL_ERROR ) || + ((hba->saved_err &UIC_ERROR ) && + (hba->saved_uic_err & UFSHCD_UIC_DL_TCx_REPLAY_ERROR))) + goto out; + +if ((hba->saved_err &UIC_ERROR ) && + (hba->saved_uic_err &UFSHCD_UIC_DL_NAC_RECEIVED_ERROR )) { +int err; +/* +* wait for 50ms to see if we can get any other errors or not. +*/ +spin_unlock_irqrestore (hba->host->host_lock, flags); +msleep (50 ); +spin_lock_irqsave (hba->host->host_lock, flags); + +/* +* now check if we have got any other severe errors other than +* DL NAC error? +*/ +if ((hba->saved_err &INT_FATAL_ERRORS ) || + ((hba->saved_err &UIC_ERROR ) && + (hba->saved_uic_err & ~UFSHCD_UIC_DL_NAC_RECEIVED_ERROR ))) + goto out; + +/* +* As DL NAC is the only error received so far, send out NOP +* command to confirm if link is still active or not. +* - If we don't get any response then do error recovery. +* - If we get response then clear the DL NAC error bit. +*/ + +spin_unlock_irqrestore (hba->host->host_lock, flags); + err =ufshcd_verify_dev_init (hba); +spin_lock_irqsave (hba->host->host_lock, flags); + +if (err) + goto out; + +/* Link seems to be alive hence ignore the DL NAC errors */ +if (hba->saved_uic_err ==UFSHCD_UIC_DL_NAC_RECEIVED_ERROR ) + hba->saved_err &= ~UIC_ERROR ; +/* clear NAC error */ + hba->saved_uic_err &= ~UFSHCD_UIC_DL_NAC_RECEIVED_ERROR ; +if (!hba->saved_uic_err) { + err_handling = false; + goto out; + } + } +out: +spin_unlock_irqrestore (hba->host->host_lock, flags); +return err_handling; +} + +/** * ufshcd_err_handler - handle UFS errors that require s/w attention * @work: pointer to work structure */
@@ -3864,6 +3937,17 @@ static void ufshcd_err_handler(struct work_struct *work)/* Complete requests that have door-bell cleared by h/w */ ufshcd_complete_requests (hba); + +if (hba->dev_quirks &UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS ) { +bool ret; + +spin_unlock_irqrestore (hba->host->host_lock, flags); +/* release the lock as ufshcd_quirk_dl_nac_errors() may sleep */ + ret =ufshcd_quirk_dl_nac_errors (hba); +spin_lock_irqsave (hba->host->host_lock, flags); +if (!ret) + goto skip_err_handling; + } if ((hba->saved_err & INT_FATAL_ERRORS) || ((hba->saved_err & UIC_ERROR) && (hba->saved_uic_err & (UFSHCD_UIC_DL_PA_INIT_ERROR |
@@ -3939,6 +4023,7 @@ skip_pending_xfer_clear: hba->saved_uic_err =0 ; } +skip_err_handling:if (!needs_reset) { hba->ufshcd_state =UFSHCD_STATE_OPERATIONAL ;if (hba->saved_err || hba->saved_uic_err)
@@ -3967,6 +4052,14 @@ static void ufshcd_update_uic_error(struct ufs_hba *hba) reg =ufshcd_readl (hba,REG_UIC_ERROR_CODE_DATA_LINK_LAYER );if (reg &UIC_DATA_LINK_LAYER_ERROR_PA_INIT ) hba->uic_error |=UFSHCD_UIC_DL_PA_INIT_ERROR ; +else if (hba->dev_quirks & +UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS ) { +if (reg &UIC_DATA_LINK_LAYER_ERROR_NAC_RECEIVED ) + hba->uic_error |= +UFSHCD_UIC_DL_NAC_RECEIVED_ERROR ; +else if (reg & UIC_DATA_LINK_LAYER_ERROR_TCx_REPLAY_TIMEOUT) + hba->uic_error |= UFSHCD_UIC_DL_TCx_REPLAY_ERROR; + }/* UIC NL/TL/DME errors needs software retry */ reg =ufshcd_readl (hba,REG_UIC_ERROR_CODE_NETWORK_LAYER );
drivers/scsi/ufs/ufshci.h +2 -0
@@ -170,6 +170,8 @@ enum {#define UIC_DATA_LINK_LAYER_ERROR UFS_BIT(31)#define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0x7FFF#define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000 +#define UIC_DATA_LINK_LAYER_ERROR_NAC_RECEIVED 0x0001 +#define UIC_DATA_LINK_LAYER_ERROR_TCx_REPLAY_TIMEOUT 0x0002/* UECN - Host UIC Error Code Network Layer 40h */ #define UIC_NETWORK_LAYER_ERROR UFS_BIT(31)
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 12/17 scsi: ufs: add retry for query descriptors
In reply to Yaniv GardiQuery commands have 100ms timeout and it may timeout if they are issued in parallel to ongoing read/write SCSI commands, this change adds the retry (max: 10) in case command timeouts.
--- drivers/scsi/ufs/ufshcd.c | 48 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)
drivers/scsi/ufs/ufshcd.c +33 -15
@@ -1906,21 +1906,7 @@ static int ufshcd_query_attr_retry(struct ufs_hba *hba,return ret; } -/** -* ufshcd_query_descriptor - API function for sending descriptor requests -* hba: per-adapter instance -* opcode: attribute opcode -* idn: attribute idn to access -* index: index field -* selector: selector field -* desc_buf: the buffer that contains the descriptor -* buf_len: length parameter passed to the device -* -* Returns 0 for success, non-zero in case of failure. -* The buf_len parameter will contain, on return, the length parameter -* received on the response. -*/ -static int ufshcd_query_descriptor (struct ufs_hba *hba, +static int __ufshcd_query_descriptor (struct ufs_hba *hba,enum query_opcode opcode,enum desc_idn idn,u8 index,u8 selector,u8 *desc_buf,int *buf_len) {
@@ -1985,6 +1971,38 @@ out: }/** +* ufshcd_query_descriptor - API function for sending descriptor requests +* hba: per-adapter instance +* opcode: attribute opcode +* idn: attribute idn to access +* index: index field +* selector: selector field +* desc_buf: the buffer that contains the descriptor +* buf_len: length parameter passed to the device +* +* Returns 0 for success, non-zero in case of failure. +* The buf_len parameter will contain, on return, the length parameter +* received on the response. +*/ +int ufshcd_query_descriptor (struct ufs_hba *hba, +enum query_opcode opcode,enum desc_idn idn,u8 index, +u8 selector,u8 *desc_buf,int *buf_len) +{ +int err; +int retries; + +for (retries =QUERY_REQ_RETRIES ; retries >0 ; retries--) { + err =__ufshcd_query_descriptor (hba, opcode, idn, index, + selector, desc_buf, buf_len); +if (!err || err == -EINVAL ) +break ; + } + +return err; +} +EXPORT_SYMBOL (ufshcd_query_descriptor); + +/** * ufshcd_read_desc_param - read the specified descriptor parameter * @hba: Pointer to adapter instance * @desc_id: descriptor idn value
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 13/17 scsi: ufs: handle non spec compliant bkops behaviour by device
In reply to Yaniv GardiWe are seeing that some devices are raising the urgent bkops exception events even when BKOPS status doesn't indicate performace impacted or critical. Handle these device by determining their urgent bkops status at runtime.
--- drivers/scsi/ufs/ufshcd.c | 53 ++++++++++++++++++++++++++++++++++++++++------- drivers/scsi/ufs/ufshcd.h | 6 ++++++ 2 files changed, 52 insertions(+), 7 deletions(-)
drivers/scsi/ufs/ufshcd.c +46 -7
@@ -3804,7 +3804,7 @@ out:*/ static int ufshcd_urgent_bkops (struct ufs_hba *hba) { -return ufshcd_bkops_ctrl (hba,BKOPS_STATUS_PERF_IMPACT ); +return ufshcd_bkops_ctrl (hba, hba->urgent_bkops_lvl); }static inline int ufshcd_get_ee_status (struct ufs_hba *hba,u32 *status)
@@ -3813,6 +3813,43 @@ static inline int ufshcd_get_ee_status(struct ufs_hba *hba, u32 *status) QUERY_ATTR_IDN_EE_STATUS, 0, 0, status); } +static void ufshcd_bkops_exception_event_handler (struct ufs_hba *hba) +{ +int err; +u32 curr_status =0 ; + +if (hba->is_urgent_bkops_lvl_checked) + goto enable_auto_bkops; + + err =ufshcd_get_bkops_status (hba, &curr_status); +if (err) { +dev_err (hba->dev,"%s: failed to get BKOPS status %d\n" , + __func__, err); + goto out; + } + +/* +* We are seeing that some devices are raising the urgent bkops +* exception events even when BKOPS status doesn't indicate performace +* impacted or critical. Handle these device by determining their urgent +* bkops status at runtime. +*/ +if (curr_status <BKOPS_STATUS_PERF_IMPACT ) { +dev_err (hba->dev,"%s: device raised urgent BKOPS exception for bkops status %d\n" , + __func__, curr_status); +/* update the current status as the urgent bkops level */ + hba->urgent_bkops_lvl = curr_status; + hba->is_urgent_bkops_lvl_checked = true; + } + +enable_auto_bkops: + err =ufshcd_enable_auto_bkops (hba); +out: +if (err <0 ) +dev_err (hba->dev,"%s: failed to handle urgent bkops %d\n" , + __func__, err); +} +/** * ufshcd_exception_event_handler - handle exceptions raised by device * @work: pointer to work data
@@ -3836,12 +3873,10 @@ static void ufshcd_exception_event_handler(struct work_struct *work) } status &= hba->ee_ctrl_mask; -if (status &MASK_EE_URGENT_BKOPS ) { - err =ufshcd_urgent_bkops (hba); -if (err <0 ) -dev_err (hba->dev,"%s: failed to handle urgent bkops %d\n" , - __func__, err); - } + +if (status &MASK_EE_URGENT_BKOPS ) +ufshcd_bkops_exception_event_handler (hba); + out:pm_runtime_put_sync (hba->dev);return ;
@@ -4806,6 +4841,10 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)ufshcd_init_pwr_info (hba); +/* set the default level for urgent bkops */ + hba->urgent_bkops_lvl =BKOPS_STATUS_PERF_IMPACT ; + hba->is_urgent_bkops_lvl_checked = false; +/* UniPro link is active now */ ufshcd_set_link_active (hba);
drivers/scsi/ufs/ufshcd.h +6 -0
@@ -383,6 +383,9 @@ struct ufs_init_prefetch {* @clk_list_head: UFS host controller clocks list node head * @pwr_info: holds current power mode * @max_pwr_info: keeps the device max valid pwm +* @urgent_bkops_lvl: keeps track of urgent bkops level for device +* @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for +* device is known or not. */ struct ufs_hba {void __iomem *mmio_base;
@@ -538,6 +541,9 @@ struct ufs_hba {struct devfreq *devfreq;struct ufs_clk_scaling clk_scaling;bool is_sys_suspended; + +enum bkops_status urgent_bkops_lvl; +bool is_urgent_bkops_lvl_checked; };/* Returns true if clocks can be gated. Otherwise false */
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 14/17 scsi: ufs: tune UniPro parameters to optimize hibern8 exit time
In reply to Yaniv GardiOptimal values of local UniPro parameters like PA_Hibern8Time & PA_TActivate can help reduce the hibern8 exit latency. If both host and device supports UniPro ver1.6 or later, these parameters will be automatically tuned during link startup itself. But if either host or device doesn't support UniPro ver 1.6 or later, we have to manually tune them. But to keep manual tuning logic simple, we will only do manual tuning if local unipro version doesn't support ver1.6 or later.
--- drivers/scsi/ufs/ufshcd.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 1 + drivers/scsi/ufs/ufshci.h | 2 + drivers/scsi/ufs/unipro.h | 21 ++++++++ 4 files changed, 145 insertions(+)
drivers/scsi/ufs/ufshcd.c +121 -0
@@ -596,6 +596,34 @@ static inline int ufshcd_is_hba_active(struct ufs_hba *hba)return (ufshcd_readl (hba,REG_CONTROLLER_ENABLE ) &0x1 ) ?0 :1 ; } +u32 ufshcd_get_local_unipro_ver (struct ufs_hba *hba) +{ +/* HCI version 1.0 and 1.1 supports UniPro 1.41 */ +if ((hba->ufs_version ==UFSHCI_VERSION_10 ) || + (hba->ufs_version ==UFSHCI_VERSION_11 )) +return UFS_UNIPRO_VER_1_41 ; +else +return UFS_UNIPRO_VER_1_6 ; +} +EXPORT_SYMBOL (ufshcd_get_local_unipro_ver); + +static bool ufshcd_is_unipro_pa_params_tuning_req (struct ufs_hba *hba) +{ +/* +* If both host and device support UniPro ver1.6 or later, PA layer +* parameters tuning happens during link startup itself. +* +* We can manually tune PA layer parameters if either host or device +* doesn't support UniPro ver 1.6 or later. But to keep manual tuning +* logic simple, we will only do manual tuning if local unipro version +* doesn't support ver1.6 or later. +*/ +if (ufshcd_get_local_unipro_ver (hba) <UFS_UNIPRO_VER_1_6 ) +return true; +else +return false; +} +static void ufshcd_ungate_work (struct work_struct *work) {int ret;
@@ -4826,6 +4854,98 @@ out: }/** +* ufshcd_tune_pa_tactivate - Tunes PA_TActivate of local UniPro +* @hba: per-adapter instance +* +* PA_TActivate parameter can be tuned manually if UniPro version is less than +* 1.61. PA_TActivate needs to be greater than or equal to peerM-PHY's +* RX_MIN_ACTIVATETIME_CAPABILITY attribute. This optimal value can help reduce +* the hibern8 exit latency. +* +* Returns zero on success, non-zero error value on failure. +*/ +static int ufshcd_tune_pa_tactivate (struct ufs_hba *hba) +{ +int ret =0 ; +u32 peer_rx_min_activatetime =0 , tuned_pa_tactivate; + +if (!ufshcd_is_unipro_pa_params_tuning_req (hba)) +return 0 ; + + ret =ufshcd_dme_peer_get (hba, +UIC_ARG_MIB_SEL ( +RX_MIN_ACTIVATETIME_CAPABILITY , +UIC_ARG_MPHY_RX_GEN_SEL_INDEX (0 )), + &peer_rx_min_activatetime); +if (ret) + goto out; + +/* make sure proper unit conversion is applied */ + tuned_pa_tactivate = + ((peer_rx_min_activatetime *RX_MIN_ACTIVATETIME_UNIT_US ) + /PA_TACTIVATE_TIME_UNIT_US ); + ret =ufshcd_dme_set (hba,UIC_ARG_MIB (PA_TACTIVATE ), + tuned_pa_tactivate); + +out: +return ret; +} + +/** +* ufshcd_tune_pa_hibern8time - Tunes PA_Hibern8Time of local UniPro +* @hba: per-adapter instance +* +* PA_Hibern8Time parameter can be tuned manually if UniPro version is less than +* 1.61. PA_Hibern8Time needs to be maximum of local M-PHY's +* TX_HIBERN8TIME_CAPABILITY & peer M-PHY's RX_HIBERN8TIME_CAPABILITY. +* This optimal value can help reduce the hibern8 exit latency. +* +* Returns zero on success, non-zero error value on failure. +*/ +static int ufshcd_tune_pa_hibern8time (struct ufs_hba *hba) +{ +int ret =0 ; +u32 local_tx_hibern8_time_cap =0 , peer_rx_hibern8_time_cap =0 ; +u32 max_hibern8_time, tuned_pa_hibern8time; + + ret =ufshcd_dme_get (hba, +UIC_ARG_MIB_SEL (TX_HIBERN8TIME_CAPABILITY , +UIC_ARG_MPHY_TX_GEN_SEL_INDEX (0 )), + &local_tx_hibern8_time_cap); +if (ret) + goto out; + + ret =ufshcd_dme_peer_get (hba, +UIC_ARG_MIB_SEL (RX_HIBERN8TIME_CAPABILITY , +UIC_ARG_MPHY_RX_GEN_SEL_INDEX (0 )), + &peer_rx_hibern8_time_cap); +if (ret) + goto out; + + max_hibern8_time =max (local_tx_hibern8_time_cap, + peer_rx_hibern8_time_cap); +/* make sure proper unit conversion is applied */ + tuned_pa_hibern8time = ((max_hibern8_time *HIBERN8TIME_UNIT_US ) + /PA_HIBERN8_TIME_UNIT_US ); + ret =ufshcd_dme_set (hba,UIC_ARG_MIB (PA_HIBERN8TIME ), + tuned_pa_hibern8time); +out: +return ret; +} + +static void ufshcd_tune_unipro_params (struct ufs_hba *hba) +{ +if (ufshcd_is_unipro_pa_params_tuning_req (hba)) { +ufshcd_tune_pa_tactivate (hba); +ufshcd_tune_pa_hibern8time (hba); + } + +if (hba->dev_quirks &UFS_DEVICE_QUIRK_PA_TACTIVATE ) +/* set 1ms timeout for PA_TACTIVATE */ +ufshcd_dme_set (hba,UIC_ARG_MIB (PA_TACTIVATE ),10 ); +} + +/** * ufshcd_probe_hba - probe hba to detect device and initialize * @hba: per-adapter instance *
@@ -4857,6 +4977,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) goto out;ufs_advertise_fixup_device (hba); +ufshcd_tune_unipro_params (hba); ret =ufshcd_set_vccq_rail_unused (hba, (hba->dev_quirks &UFS_DEVICE_NO_VCCQ ) ? true : false);
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -699,6 +699,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, enum flag_idn idn, bool *flag_res);int ufshcd_hold (struct ufs_hba *hba,bool async);void ufshcd_release (struct ufs_hba *hba); +u32 ufshcd_get_local_unipro_ver (struct ufs_hba *hba);/* Wrapper functions for safely calling variant operations */ static inline const char *ufshcd_get_var_name (struct ufs_hba *hba)
drivers/scsi/ufs/ufshci.h +2 -0
@@ -92,6 +92,7 @@ enum {UFSHCI_VERSION_10 =0x00010000 ,/* 1.0 */ UFSHCI_VERSION_11 =0x00010100 ,/* 1.1 */ UFSHCI_VERSION_20 =0x00000200 ,/* 2.0 */ + UFSHCI_VERSION_21 = 0x00000210, /* 2.1 */ };/*
@@ -211,6 +212,7 @@ enum {/* GenSelectorIndex calculation macros for M-PHY attributes */ #define UIC_ARG_MPHY_TX_GEN_SEL_INDEX (lane) (lane) +#define UIC_ARG_MPHY_RX_GEN_SEL_INDEX (lane) (PA_MAXDATALANES + (lane))#define UIC_ARG_MIB_SEL (attr, sel) ((((attr) & 0xFFFF) << 16) |\ ((sel) & 0xFFFF))
drivers/scsi/ufs/unipro.h +21 -0
@@ -15,6 +15,7 @@/* * M-TX Configuration Attributes */ +#define TX_HIBERN8TIME_CAPABILITY 0x000F#define TX_MODE 0x0021#define TX_HSRATE_SERIES 0x0022#define TX_HSGEAR 0x0023
@@ -48,8 +49,12 @@#define RX_ENTER_HIBERN8 0x00A7#define RX_BYPASS_8B10B_ENABLE 0x00A8#define RX_TERMINATION_FORCE_ENABLE 0x0089 +#define RX_MIN_ACTIVATETIME_CAPABILITY 0x008F +#define RX_HIBERN8TIME_CAPABILITY 0x0092#define is_mphy_tx_attr (attr) (attr < RX_MODE) +#define RX_MIN_ACTIVATETIME_UNIT_US 100 +#define HIBERN8TIME_UNIT_US 100/* * PHY Adpater attributes */
@@ -110,6 +115,12 @@#define PA_STALLNOCONFIGTIME 0x15A3#define PA_SAVECONFIGTIME 0x15A4 +#define PA_TACTIVATE_TIME_UNIT_US 10 +#define PA_HIBERN8_TIME_UNIT_US 100 + +/* PHY Adapter Protocol Constants */ +#define PA_MAXDATALANES 4 +/* PA power modes */ enum {FAST_MODE =1 ,
@@ -143,6 +154,16 @@ enum ufs_hs_gear_tag { UFS_HS_G3, /* HS Gear 3 */ }; +enum ufs_unipro_ver { +UFS_UNIPRO_VER_RESERVED =0 , +UFS_UNIPRO_VER_1_40 =1 ,/* UniPro version 1.40 */ +UFS_UNIPRO_VER_1_41 =2 ,/* UniPro version 1.41 */ +UFS_UNIPRO_VER_1_6 =3 ,/* UniPro version 1.6 */ +UFS_UNIPRO_VER_MAX =4 ,/* UniPro unsupported version */ +/* UniPro version field mask in PA_LOCALVERINFO */ +UFS_UNIPRO_VER_MASK =0xF , +}; +/* * Data Link Layer Attributes */
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 15/17 scsi: ufs: fix leakage during link off state
In reply to Yaniv GardiCurrently when we try to put the link in off/disabled state during suspend, it seems link is not being kept in low power mode. This patch fixes the issue by putting the link in hibern8 first (so device also puts the link in low power mode) and then stop the host controller.
--- drivers/scsi/ufs/ufshcd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/scsi/ufs/ufshcd.c +10 -0
@@ -5666,6 +5666,16 @@ static int ufshcd_link_state_transition(struct ufs_hba *hba, (!check_for_bkops || (check_for_bkops && !hba->auto_bkops_enabled))) {/* +* Let's make sure that link is in low power mode, we are doing +* this currently by putting the link in Hibern8. Otherway to +* put the link in low power mode is to send the DME end point +* to device and then send the DME reset command to local +* unipro. But putting the link in hibern8 is much faster. +*/ + ret =ufshcd_uic_hibern8_enter (hba); +if (ret) + goto out; +/* * Change controller state to "reset state" which * should also put the link in off/reset state */
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 16/17 scsi: ufs: add delay before putting UFS rails in low power modes
In reply to Yaniv GardiWe put the UFS device in sleep state & UFS link in hibern8 state during runtime suspaned. After this we put all the UFS rails in low power modes immediately but it seems some devices may still draw more than sleep current from UFS rails (especially from VCCQ rail) atleast for 500us.
To avoid this situation, this change adds 2ms delay before putting these UFS rails in LPM mode.
--- drivers/scsi/ufs/ufshcd.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/scsi/ufs/ufshcd.c +9 -0
@@ -5694,6 +5694,15 @@ out:static void ufshcd_vreg_set_lpm (struct ufs_hba *hba) {/* +* It seems some UFS devices may keep drawing more than sleep current +* (atleast for 500us) from UFS rails (especially from VCCQ rail). +* To avoid this situation, add 2ms delay before putting these UFS +* rails in LPM mode. +*/ +if (!ufshcd_is_link_active (hba)) +usleep_range (2000 ,2100 ); + +/* * If UFS device is either in UFS_Sleep turn off VCC rail to save some * power. *
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 17/17 scsi: ufs-qcom: set PA_Local_TX_LCC_Enable before link startup
In reply to Yaniv GardiSome UFS devices (and may be host) have issues if LCC is enabled. So we are setting PA_Local_TX_LCC_Enable to 0 before link startup which will make sure that both host and device TX LCC are disabled once link startup is completed.
This change also:
- enables the device ref clock before changing to HS mode and disables it if entered to PWM mode
- adds printouts of testbus debug registers
--- drivers/scsi/ufs/ufs-qcom.c | 116 +++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs-qcom.h | 9 ++++ drivers/scsi/ufs/ufshcd.h | 9 ++++ drivers/scsi/ufs/unipro.h | 1 + 4 files changed, 128 insertions(+), 7 deletions(-)
drivers/scsi/ufs/ufs-qcom.c +109 -7
@@ -16,8 +16,8 @@#include <linux/of.h> #include <linux/platform_device.h> #include <linux/phy/phy.h> -#include <linux/phy/phy-qcom-ufs.h> +#include "ufshcd.h" #include "ufshcd-pltfrm.h" #include "unipro.h"
@@ -58,6 +58,12 @@ static void ufs_qcom_dump_regs(struct ufs_hba *hba, int offset, int len, len * 4, false); } +static void ufs_qcom_dump_regs_wrapper (struct ufs_hba *hba,int offset,int len, +char *prefix,void *priv) +{ +ufs_qcom_dump_regs (hba, offset, len, prefix); +} +static int ufs_qcom_get_connected_tx_lanes (struct ufs_hba *hba,u32 *tx_lanes) {int err =0 ;
@@ -106,9 +112,11 @@ static void ufs_qcom_disable_lane_clks(struct ufs_qcom_host *host)if (!host->is_lane_clks_enabled)return ; -clk_disable_unprepare (host->tx_l1_sync_clk); +if (host->hba->lanes_per_direction >1 ) +clk_disable_unprepare (host->tx_l1_sync_clk);clk_disable_unprepare (host->tx_l0_sync_clk); -clk_disable_unprepare (host->rx_l1_sync_clk); +if (host->hba->lanes_per_direction >1 ) +clk_disable_unprepare (host->rx_l1_sync_clk);clk_disable_unprepare (host->rx_l0_sync_clk); host->is_lane_clks_enabled = false;
@@ -271,9 +279,8 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) ret =ufs_qcom_phy_calibrate_phy (phy, is_rate_B);if (ret) { -dev_err (hba->dev, -"%s: ufs_qcom_phy_calibrate_phy()failed, ret = %d\n" , - __func__, ret); +dev_err (hba->dev,"%s: ufs_qcom_phy_calibrate_phy() failed, ret = %d\n" , + __func__, ret); goto out; }
@@ -523,6 +530,18 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba, err =ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div (hba,150 ); +/* +* Some UFS devices (and may be host) have issues if LCC is +* enabled. So we are setting PA_Local_TX_LCC_Enable to 0 +* before link startup which will make sure that both host +* and device TX LCC are disabled once link startup is +* completed. +*/ +if (ufshcd_get_local_unipro_ver (hba) !=UFS_UNIPRO_VER_1_41 ) + err =ufshcd_dme_set (hba, +UIC_ARG_MIB (PA_LOCAL_TX_LCC_ENABLE ), +0 ); +break ;case POST_CHANGE :ufs_qcom_link_startup_post_change (hba);
@@ -966,6 +985,10 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba, goto out; } +/* enable the device ref clock before changing to HS mode */ +if (!ufshcd_is_hs_mode (&hba->pwr_info) && +ufshcd_is_hs_mode (dev_req_params)) +ufs_qcom_dev_ref_clk_ctrl (host, true);break ;case POST_CHANGE : if (ufs_qcom_cfg_timers(hba, dev_req_params->gear_rx,
@@ -993,6 +1016,11 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba,memcpy (&host->dev_req_params, dev_req_params,sizeof (*dev_req_params));ufs_qcom_update_bus_bw_vote (host); + +/* disable the device ref clock if entered PWM mode */ +if (ufshcd_is_hs_mode (&hba->pwr_info) && + !ufshcd_is_hs_mode (dev_req_params)) +ufs_qcom_dev_ref_clk_ctrl (host, false);break ;default : ret = -EINVAL ;
@@ -1094,6 +1122,9 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on)ufs_qcom_phy_disable_iface_clk (host->generic_phy); goto out; } +/* enable the device ref clock for HS mode*/ +if (ufshcd_is_hs_mode (&hba->pwr_info)) +ufs_qcom_dev_ref_clk_ctrl (host, true); vote = host->bus_vote.saved_vote;if (vote == host->bus_vote.min_bw_vote)ufs_qcom_update_bus_bw_vote (host);
@@ -1372,6 +1403,74 @@ out:return err; } +static void ufs_qcom_print_hw_debug_reg_all (struct ufs_hba *hba, +void *priv,void (*print_fn)(struct ufs_hba *hba, +int offset,int num_regs,char *str,void *priv)) +{ +u32 reg; +struct ufs_qcom_host *host; + +if (unlikely (!hba)) { +pr_err ("%s: hba is NULL\n" , __func__); +return ; + } +if (unlikely (!print_fn)) { +dev_err (hba->dev,"%s: print_fn is NULL\n" , __func__); +return ; + } + + host =ufshcd_get_variant (hba); +if (!(host->dbg_print_en &UFS_QCOM_DBG_PRINT_REGS_EN )) +return ; + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_UFS_DBG_RD_REG_OCSC ); +print_fn (hba, reg,44 ,"UFS_UFS_DBG_RD_REG_OCSC " , priv); + + reg =ufshcd_readl (hba,REG_UFS_CFG1 ); + reg |=UFS_BIT (17 ); +ufshcd_writel (hba, reg,REG_UFS_CFG1 ); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_UFS_DBG_RD_EDTL_RAM ); +print_fn (hba, reg,32 ,"UFS_UFS_DBG_RD_EDTL_RAM " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_UFS_DBG_RD_DESC_RAM ); +print_fn (hba, reg,128 ,"UFS_UFS_DBG_RD_DESC_RAM " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_UFS_DBG_RD_PRDT_RAM ); +print_fn (hba, reg,64 ,"UFS_UFS_DBG_RD_PRDT_RAM " , priv); + +ufshcd_writel (hba, (reg & ~UFS_BIT (17 )),REG_UFS_CFG1 ); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_UAWM ); +print_fn (hba, reg,4 ,"UFS_DBG_RD_REG_UAWM " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_UARM ); +print_fn (hba, reg,4 ,"UFS_DBG_RD_REG_UARM " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_TXUC ); +print_fn (hba, reg,48 ,"UFS_DBG_RD_REG_TXUC " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_RXUC ); +print_fn (hba, reg,27 ,"UFS_DBG_RD_REG_RXUC " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_DFC ); +print_fn (hba, reg,19 ,"UFS_DBG_RD_REG_DFC " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_TRLUT ); +print_fn (hba, reg,34 ,"UFS_DBG_RD_REG_TRLUT " , priv); + + reg =ufs_qcom_get_debug_reg_offset (host,UFS_DBG_RD_REG_TMRLUT ); +print_fn (hba, reg,9 ,"UFS_DBG_RD_REG_TMRLUT " , priv); +} + +static void ufs_qcom_enable_test_bus (struct ufs_qcom_host *host) +{ +if (host->dbg_print_en &UFS_QCOM_DBG_PRINT_TEST_BUS_EN ) +ufshcd_rmwl (host->hba,TEST_BUS_EN ,TEST_BUS_EN ,REG_UFS_CFG1 ); +else +ufshcd_rmwl (host->hba,TEST_BUS_EN ,0 ,REG_UFS_CFG1 ); +} +static void ufs_qcom_get_default_testbus_cfg (struct ufs_qcom_host *host) {/* provide a legal default configuration */
@@ -1480,6 +1579,7 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host *host)ufshcd_rmwl (host->hba, mask, (u32 )host->testbus.select_minor << offset, reg); +ufs_qcom_enable_test_bus (host);ufshcd_release (host->hba);pm_runtime_put_sync (host->hba->dev);
@@ -1496,8 +1596,10 @@ static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba)ufs_qcom_dump_regs (hba,REG_UFS_SYS1CLK_1US ,16 ,"HCI Vendor Specific Registers " ); +ufs_qcom_print_hw_debug_reg_all (hba,NULL , ufs_qcom_dump_regs_wrapper);ufs_qcom_testbus_read (hba); } +/** * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations *
@@ -1558,7 +1660,7 @@ out:* ufs_qcom_remove - set driver_data of the device to NULL * @pdev: pointer to platform device handle * -* Always return 0 +* Always returns 0 */ static int ufs_qcom_remove (struct platform_device *pdev) {
drivers/scsi/ufs/ufs-qcom.h +9 -0
@@ -241,6 +241,15 @@ struct ufs_qcom_host {struct ufs_qcom_testbus testbus; }; +static inline u32 +ufs_qcom_get_debug_reg_offset (struct ufs_qcom_host *host,u32 reg) +{ +if (host->hw_ver.major <=0x02 ) +return UFS_CNTLR_2_x_x_VEN_REGS_OFFSET (reg); + +return UFS_CNTLR_3_x_x_VEN_REGS_OFFSET (reg); +}; +#define ufs_qcom_is_link_off (hba) ufshcd_is_link_off(hba)#define ufs_qcom_is_link_active (hba) ufshcd_is_link_active(hba)#define ufs_qcom_is_link_hibern8 (hba) ufshcd_is_link_hibern8(hba)
drivers/scsi/ufs/ufshcd.h +9 -0
@@ -54,6 +54,7 @@#include <linux/clk.h> #include <linux/completion.h> #include <linux/regulator/consumer.h> +#include "unipro.h" #include <asm/irq.h> #include <asm/byteorder.h>
@@ -689,6 +690,14 @@ static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,int ufshcd_read_device_desc (struct ufs_hba *hba,u8 *buf,u32 size); +static inline bool ufshcd_is_hs_mode (struct ufs_pa_layer_attr *pwr_info) +{ +return (pwr_info->pwr_rx ==FAST_MODE || + pwr_info->pwr_rx ==FASTAUTO_MODE ) && + (pwr_info->pwr_tx ==FAST_MODE || + pwr_info->pwr_tx ==FASTAUTO_MODE ); +} +#define ASCII_STD true int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, u8 *buf,
drivers/scsi/ufs/unipro.h +1 -0
@@ -75,6 +75,7 @@#define PA_MAXRXSPEEDFAST 0x1541#define PA_MAXRXSPEEDSLOW 0x1542#define PA_TXLINKSTARTUPHS 0x1544 +#define PA_LOCAL_TX_LCC_ENABLE 0x155E#define PA_TXSPEEDFAST 0x1565#define PA_TXSPEEDSLOW 0x1566#define PA_REMOTEVERINFO 0x15A0
Signature · 4 lines
1.8.5.2 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH v1 01/17] scsi: ufs-qcom: add number of lanes per direction
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 44 lines
drivers/scsi/ufs/ufshcd.c +18
-0@@ -40,6 +40,7 @@#include <linux/async.h> #include <linux/devfreq.h> +#include <linux/of.h> #include "ufshcd.h" #include "unipro.h" #define UFSHCD_REQ_SENSE_SIZE 18@@ -87,6 +88,8 @@/* Interrupt aggregation default timeout, unit: 40us */ #define INT_AGGR_DEF_TO 0x02 +#define UFSHCD_DEFAULT_LANES_PER_DIRECTION 2 +#define ufshcd_toggle_vreg (_dev, _vreg, _on) \ ({ \ int _ret; \@@ -5765,6 +5768,21 @@ static struct devfreq_dev_profile ufs_devfreq_profile = { .get_dev_status = ufshcd_devfreq_get_dev_status, }; +static void ufshcd_init_lanes_per_dir (struct ufs_hba *hba) +{ +struct device *dev = hba->dev; +int ret; + + ret =of_property_read_u32 (dev->of_node,"lanes-per-direction" , + &hba->lanes_per_direction); +if (ret) { +dev_dbg (hba->dev, +"%s: failed to read lanes-per-direction, ret=%d\n" , + __func__, ret); + hba->lanes_per_direction =UFSHCD_DEFAULT_LANES_PER_DIRECTION ; + } +} +/** * ufshcd_init - Driver initialization routine * @hba: per-adapter instance
drivers/scsi/ufs/ufshcd.c int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) · line 5813
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +2
-0@@ -5788,6 +5806,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->mmio_base = mmio_base; hba->irq = irq; +ufshcd_init_lanes_per_dir (hba); + err =ufshcd_hba_init (hba);if (err) goto out_error;
Should this be called in ufshcd_pltfrm_init() and move ufshcd_init_lanes_per_dir() toufshcd-pltfrm.c? Because all 'of_' stuffs are in ufshcd-pltfrm.c.
Re: [PATCH v1 02/17] scsi: ufs: add option to change default UFS power management level
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 11 lines
UFS device and link can be put in multiple different low power modes hence UFS driver supports multiple different low power modes. By default UFS driver selects the default (optimal) low power mode (which gives moderate power savings and have relatively less enter and exit latencies) but we might have to tune this default power mode for different chipset platforms to meet the low power requirements/goals. Hence this patch adds option to change default UFS low power mode (level).
Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>
...
Quoted 11 lines
drivers/scsi/ufs/ufs-qcom.c +0
-3@@ -1195,11 +1195,12 @@ static int ufs_qcom_init(struct ufs_hba *hba)if (res) { host->dev_ref_clk_ctrl_mmio =devm_ioremap_resource (dev, res); -if (IS_ERR (host->dev_ref_clk_ctrl_mmio)) { - dev_warn(dev, - "%s: could not map dev_ref_clk_ctrl_mmio, err %ld\n",
drivers/scsi/ufs/ufs-qcom.c static int ufs_qcom_init(struct ufs_hba *hba) · line 1206
Quoted 10 lines
drivers/scsi/ufs/ufs-qcom.c +5
-1+if (IS_ERR ((__force void const *) + host->dev_ref_clk_ctrl_mmio)) { +dev_warn (dev,"%s: could not map dev_ref_clk_ctrl_mmio, err %ld\n" , __func__, - PTR_ERR(host->dev_ref_clk_ctrl_mmio)); +PTR_ERR ((__force void const *) + host->dev_ref_clk_ctrl_mmio)); host->dev_ref_clk_ctrl_mmio =NULL ; } host->dev_ref_clk_en_mask =BIT (5 );
This change looks unrelated. Should this be belong to other patch?
Re: [PATCH v1 06/17] scsi :ufs: verify hba controller hce reg value
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 22 lines
Sometimes due to hw issues it takes some time to the host controller register to update. In order to verify the register has updated, a polling is done until its value is set.
In addition the functions
ufshcd_hba_stop()andufshcd_wait_for_register()was updated with an additional input parameter, indicating the timeout between reads will be done by sleeping or spinning the cpu.Signed-off-by Raviv Shvili <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 54 ++++++++++++++++++++++++++++------------------- drivers/scsi/ufs/ufshcd.h | 12 +++-------- 2 files changed, 35 insertions(+), 31 deletions(-)drivers/scsi/ufs/ufshcd.c +0
-0
drivers/scsi/ufs/ufshcd.c static inline void ufshcd_disable_irq(struct ufs_hba *hba) · line 272
Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +1
-1@@ -267,11 +267,12 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba)* @val - wait condition * @interval_us - polling interval in microsecs * @timeout_ms - timeout in millisecs -* +* @can_sleep - perform sleep or just spin * Returns -ETIMEDOUT on error, zero on success */
We usually put a blank line between @argument description and return value description.
Re: [PATCH v1 07/17] scsi: ufs: separate device and host quirks
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 13 lines
drivers/scsi/ufs/ufs_quirks.c new file +7
-0@@ -0,0 +1,101 @@ +/* +* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +*
drivers/scsi/ufs/ufs_quirks.c line 17
Quoted 10 lines
drivers/scsi/ufs/ufs_quirks.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include "ufshcd.h" +#include "ufs_quirks.h" + +
Single blank line is enough.
Quoted 56 lines
drivers/scsi/ufs/ufshcd.c +31
-1@@ -39,9 +39,10 @@#include <linux/async.h> #include <linux/devfreq.h> - +#include <linux/nls.h> #include <linux/of.h> #include "ufshcd.h" +#include "ufs_quirks.h" #include "unipro.h" #define UFSHCD_REQ_SENSE_SIZE 18@@ -259,6 +260,16 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba) } } +/* replace non-printable or non-ASCII characters with spaces */ +static inline void ufshcd_remove_non_printable (char *val) +{ +if (!val) +return ; + +if (*val <0x20 || *val >0x7e ) + *val =' ' ; +} +/* * ufshcd_wait_for_register - wait for register value to change * @hba - per-adapter interface @@ -2052,6 +2063,82 @@ static inline int ufshcd_read_power_desc(struct ufs_hba *hba,return ufshcd_read_desc (hba,QUERY_DESC_IDN_POWER ,0 , buf, size); } +int ufshcd_read_device_desc (struct ufs_hba *hba,u8 *buf,u32 size) +{ +return ufshcd_read_desc (hba,QUERY_DESC_IDN_DEVICE ,0 , buf, size); +} +EXPORT_SYMBOL (ufshcd_read_device_desc); + +/** +* ufshcd_read_string_desc - read string descriptor +* @hba: pointer to adapter instance +* @desc_index: descriptor index +* @buf: pointer to buffer where descriptor would be read +* @size: size of buf +* @ascii: if true convert from unicode to ascii characters +* +* Return 0 in case of success, non-zero otherwise +*/ +int ufshcd_read_string_desc (struct ufs_hba *hba,int desc_index,u8 *buf, +u32 size,bool ascii) +{
drivers/scsi/ufs/ufshcd.c static inline int ufshcd_read_power_desc(struct ufs_hba *hba, · line 2094
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10
-0+int err =0 ; + + err =ufshcd_read_desc (hba, +QUERY_DESC_IDN_STRING , desc_index, buf, size); + +if (err) { +dev_err (hba->dev,"%s: reading String Desc failed after %d retries. err = %d\n" , + __func__,QUERY_REQ_RETRIES , err); + goto out; + }
I actually tried this patch and ufshcd_read_desc() always returns -EINVAL due to the following check in the end of ufshcd_read_desc().
if (ret || (buff_len < ufs_query_desc_max_size[desc_id]) ||
(desc_buf[QUERY_DESC_LENGTH_OFFSET] !=
ufs_query_desc_max_size[desc_id])
|| (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id)) {
...
if (!ret)
ret = -EINVAL;Could you also include a fix fir ufshcd_read_desc()?
Re: [PATCH v1 08/17] scsi: ufs: split broken LCC quirk
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 29 lines
Currently when
UFSHCD_BROKEN_LCCquirk is defined, LCC is getting disabled on both host and device side but there could be a need where we don't want to disable the LCC on both side hence this change splits the quirk in 2 parts one for host and one for device.Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/scsi/ufs/ufshcd.c +5
-0@@ -3048,6 +3048,11 @@ static int ufshcd_disable_tx_lcc(struct ufs_hba *hba, bool peer)return err; } +static inline int ufshcd_disable_host_tx_lcc (struct ufs_hba *hba) +{ +return ufshcd_disable_tx_lcc (hba, false); +} +static inline int ufshcd_disable_device_tx_lcc (struct ufs_hba *hba) {return ufshcd_disable_tx_lcc (hba, true);
drivers/scsi/ufs/ufshcd.c static int ufshcd_link_startup(struct ufs_hba *hba) · line 3108
Quoted 9 lines
drivers/scsi/ufs/ufshcd.c +6
-0@@ -3095,6 +3100,12 @@ static int ufshcd_link_startup(struct ufs_hba *hba) goto out; } +if (hba->dev_quirks &UFS_DEVICE_QUIRK_BROKEN_LCC ) { + ret =ufshcd_disable_host_tx_lcc (hba); +if (ret) + goto out; + } +
This dev_quirks is checked just after link startup. But dev_quirk is determined after ufshcd_complete_dev_init(). Is this quirk correctly be applied?
Quoted 12 lines
drivers/scsi/ufs/ufshcd.c +0
-1/* Include any host controller configuration via UIC commands */ ret =ufshcd_vops_link_startup_notify (hba,POST_CHANGE );if (ret) --1.8.5.2
--
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation --
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 12/17] scsi: ufs: add retry for query descriptors
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 62 lines
Query commands have 100ms timeout and it may timeout if they are issued in parallel to ongoing read/write SCSI commands, this change adds the retry (max: 10) in case command timeouts.
Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 48 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)drivers/scsi/ufs/ufshcd.c +21
-15@@ -1906,21 +1906,7 @@ static int ufshcd_query_attr_retry(struct ufs_hba *hba,return ret; } -/** -* ufshcd_query_descriptor - API function for sending descriptor requests -* hba: per-adapter instance -* opcode: attribute opcode -* idn: attribute idn to access -* index: index field -* selector: selector field -* desc_buf: the buffer that contains the descriptor -* buf_len: length parameter passed to the device -* -* Returns 0 for success, non-zero in case of failure. -* The buf_len parameter will contain, on return, the length parameter -* received on the response. -*/ -static int ufshcd_query_descriptor (struct ufs_hba *hba, +static int __ufshcd_query_descriptor (struct ufs_hba *hba,enum query_opcode opcode,enum desc_idn idn,u8 index,u8 selector,u8 *desc_buf,int *buf_len) {@@ -1985,6 +1971,38 @@ out: }/** +* ufshcd_query_descriptor - API function for sending descriptor requests +* hba: per-adapter instance +* opcode: attribute opcode +* idn: attribute idn to access +* index: index field +* selector: selector field +* desc_buf: the buffer that contains the descriptor +* buf_len: length parameter passed to the device +* +* Returns 0 for success, non-zero in case of failure. +* The buf_len parameter will contain, on return, the length parameter +* received on the response. +*/ +int ufshcd_query_descriptor (struct ufs_hba *hba, +enum query_opcode opcode,enum desc_idn idn,u8 index, +u8 selector,u8 *desc_buf,int *buf_len) +{ +int err; +int retries; +
drivers/scsi/ufs/ufshcd.c out: · line 2003
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10
-0+for (retries =QUERY_REQ_RETRIES ; retries >0 ; retries--) { + err =__ufshcd_query_descriptor (hba, opcode, idn, index, + selector, desc_buf, buf_len); +if (!err || err == -EINVAL ) +break ; + } + +return err; +} +EXPORT_SYMBOL (ufshcd_query_descriptor);
You introduced query flag and attribute APIs for retry version with '_retry' suffix.
This function retries but doesn't have '_retry' suffix. Should we have consistent function names for these query APIs?
Re: [PATCH v1 14/17] scsi: ufs: tune UniPro parameters to optimize hibern8 exit time
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 68 lines
Optimal values of local UniPro parameters like
PA_Hibern8Time&PA_TActivatecan help reduce the hibern8 exit latency. If both host and device supports UniPro ver1.6 or later, these parameters will be automatically tuned during link startup itself. But if either host or device doesn't support UniPro ver 1.6 or later, we have to manually tune them. But to keep manual tuning logic simple, we will only do manual tuning if local unipro version doesn't support ver1.6 or later.Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 1 + drivers/scsi/ufs/ufshci.h | 2 + drivers/scsi/ufs/unipro.h | 21 ++++++++ 4 files changed, 145 insertions(+)drivers/scsi/ufs/ufshcd.c +35
-0@@ -596,6 +596,34 @@ static inline int ufshcd_is_hba_active(struct ufs_hba *hba)return (ufshcd_readl (hba,REG_CONTROLLER_ENABLE ) &0x1 ) ?0 :1 ; } +u32 ufshcd_get_local_unipro_ver (struct ufs_hba *hba) +{ +/* HCI version 1.0 and 1.1 supports UniPro 1.41 */ +if ((hba->ufs_version ==UFSHCI_VERSION_10 ) || + (hba->ufs_version ==UFSHCI_VERSION_11 )) +return UFS_UNIPRO_VER_1_41 ; +else +return UFS_UNIPRO_VER_1_6 ; +} +EXPORT_SYMBOL (ufshcd_get_local_unipro_ver); + +static bool ufshcd_is_unipro_pa_params_tuning_req (struct ufs_hba *hba) +{ +/* +* If both host and device support UniPro ver1.6 or later, PA layer +* parameters tuning happens during link startup itself. +* +* We can manually tune PA layer parameters if either host or device +* doesn't support UniPro ver 1.6 or later. But to keep manual tuning +* logic simple, we will only do manual tuning if local unipro version +* doesn't support ver1.6 or later. +*/ +if (ufshcd_get_local_unipro_ver (hba) <UFS_UNIPRO_VER_1_6 ) +return true; +else +return false; +} +static void ufshcd_ungate_work (struct work_struct *work) {int ret;@@ -4826,6 +4854,98 @@ out: }/** +* ufshcd_tune_pa_tactivate - Tunes PA_TActivate of local UniPro +* @hba: per-adapter instance +* +* PA_TActivate parameter can be tuned manually if UniPro version is less than +* 1.61. PA_TActivate needs to be greater than or equal to peerM-PHY's +* RX_MIN_ACTIVATETIME_CAPABILITY attribute. This optimal value can help reduce +* the hibern8 exit latency.
drivers/scsi/ufs/ufshcd.c out: · line 4873
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10
-0+* +* Returns zero on success, non-zero error value on failure. +*/ +static int ufshcd_tune_pa_tactivate (struct ufs_hba *hba) +{ +int ret =0 ; +u32 peer_rx_min_activatetime =0 , tuned_pa_tactivate; + +if (!ufshcd_is_unipro_pa_params_tuning_req (hba)) +return 0 ;
This ufshcd_tune_pa_tactivate() is called only when ufshcd_is_unipro_pa_params_tuning_req() returns true. Is this second check needed?
Re: [PATCH v1 16/17] scsi: ufs: add delay before putting UFS rails in low power modes
In reply to Yaniv Gardi2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 21 lines
We put the UFS device in sleep state & UFS link in hibern8 state during runtime suspaned. After this we put all the UFS rails in low power modes immediately but it seems some devices may still draw more than sleep current from UFS rails (especially from VCCQ rail) atleast for 500us.
To avoid this situation, this change adds 2ms delay before putting these UFS rails in LPM mode.Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/scsi/ufs/ufshcd.c +0
-0@@ -5694,6 +5694,15 @@ out:static void ufshcd_vreg_set_lpm (struct ufs_hba *hba)
drivers/scsi/ufs/ufshcd.c out: · line 5704
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +8
-0{/* +* It seems some UFS devices may keep drawing more than sleep current +* (atleast for 500us) from UFS rails (especially from VCCQ rail). +* To avoid this situation, add 2ms delay before putting these UFS +* rails in LPM mode. +*/ +if (!ufshcd_is_link_active (hba)) +usleep_range (2000 ,2100 ); +
Shouldn't we define dev_quirks for this?
Quoted 13 lines
drivers/scsi/ufs/ufshcd.c +1
-1+/* * If UFS device is either in UFS_Sleep turn off VCC rail to save some * power. * -- 1.8.5.2
--
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation --
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 02/17] scsi: ufs: add option to change default UFS power management level
In reply to Akinobu MitaQuoted 34 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 11 lines
UFS device and link can be put in multiple different low power modes hence UFS driver supports multiple different low power modes. By default UFS driver selects the default (optimal) low power mode (which gives moderate power savings and have relatively less enter and exit latencies) but we might have to tune this default power mode for different chipset platforms to meet the low power requirements/goals. Hence this patch adds option to change default UFS low power mode (level).
Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>...
Quoted 19 lines
drivers/scsi/ufs/ufs-qcom.c +3
-4@@ -1195,11 +1195,12 @@ static int ufs_qcom_init(struct ufs_hba *hba)if (res) { host->dev_ref_clk_ctrl_mmio =devm_ioremap_resource (dev, res); -if (IS_ERR (host->dev_ref_clk_ctrl_mmio)) { -dev_warn (dev, - "%s: could not map dev_ref_clk_ctrl_mmio, err %ld\n", + if (IS_ERR((__force void const *) + host->dev_ref_clk_ctrl_mmio)) { + dev_warn(dev, "%s: could not map dev_ref_clk_ctrl_mmio, err %ld\n", __func__, -PTR_ERR (host->dev_ref_clk_ctrl_mmio));
Quoted 9 lines
Quoted 6 lines
drivers/scsi/ufs/ufs-qcom.c +2
-0+ PTR_ERR((__force void const *) +host->dev_ref_clk_ctrl_mmio)); host->dev_ref_clk_ctrl_mmio = NULL; } host->dev_ref_clk_en_mask = BIT(5);This change looks unrelated. Should this be belong to other patch?
correct, it's minor change,
but i will separate it to a different patch.
Re: [PATCH v1 06/17] scsi :ufs: verify hba controller hce reg value
In reply to Akinobu MitaQuoted 19 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 18 lines
Sometimes due to hw issues it takes some time to the host controller register to update. In order to verify the register has updated, a polling is done until its value is set.
In addition the functions
ufshcd_hba_stop()andufshcd_wait_for_register()was updated with an additional input parameter, indicating the timeout between reads will be done by sleeping or spinning the cpu.Signed-off-by Raviv Shvili <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 54 ++++++++++++++++++++++++++++------------------- drivers/scsi/ufs/ufshcd.h | 12 +++-------- 2 files changed, 35 insertions(+), 31 deletions(-)
Quoted 17 lines
drivers/scsi/ufs/ufshcd.c static inline void ufshcd_disable_irq(struct · line 273
Quoted 13 lines
drivers/scsi/ufs/ufshcd.c +1
-1@@ -267,11 +267,12 @@ static inline void ufshcd_disable_irq(structufs_hba *hba) * @val - wait condition * @interval_us - polling interval in microsecs * @timeout_ms - timeout in millisecs -* +* @can_sleep - perform sleep or just spin * Returns -ETIMEDOUT on error, zero on success */ We usually put a blank line between @argument description and return value description.
will be fixed in v2.
thanks
Re: [PATCH v1 07/17] scsi: ufs: separate device and host quirks
In reply to Akinobu MitaQuoted 20 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 18 lines
drivers/scsi/ufs/ufs_quirks.c new file +11
-0@@ -0,0 +1,101 @@ +/* +* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details.
Quoted 8 lines
drivers/scsi/ufs/ufs_quirks.c line 17
Quoted 6 lines
drivers/scsi/ufs/ufs_quirks.c new file +6
-0+*/ + +#include "ufshcd.h" +#include "ufs_quirks.h" + +Single blank line is enough.
done
Quoted 86 lines
Quoted 71 lines
drivers/scsi/ufs/ufshcd.c +12
-1@@ -39,9 +39,10 @@#include <linux/async.h> #include <linux/devfreq.h> - +#include <linux/nls.h> #include <linux/of.h> #include "ufshcd.h" +#include "ufs_quirks.h" #include "unipro.h" #define UFSHCD_REQ_SENSE_SIZE 18@@ -259,6 +260,16 @@ static inline void ufshcd_disable_irq(struct ufs_hba *hba) } } +/* replace non-printable or non-ASCII characters with spaces */ +static inline void ufshcd_remove_non_printable (char *val) +{ +if (!val) +return ; + +if (*val <0x20 || *val >0x7e ) + *val =' ' ; +} +/* * ufshcd_wait_for_register - wait for register value to change * @hba - per-adapter interface
drivers/scsi/ufs/ufshcd.c +17
-0@@ -2052,6 +2063,82 @@ static inline int ufshcd_read_power_desc(structufs_hba *hba, return ufshcd_read_desc(hba, QUERY_DESC_IDN_POWER, 0, buf,size ); } +int ufshcd_read_device_desc (struct ufs_hba *hba,u8 *buf,u32 size) +{ +return ufshcd_read_desc (hba,QUERY_DESC_IDN_DEVICE ,0 , buf, size); +} +EXPORT_SYMBOL (ufshcd_read_device_desc); + +/** +* ufshcd_read_string_desc - read string descriptor +* @hba: pointer to adapter instance +* @desc_index: descriptor index +* @buf: pointer to buffer where descriptor would be read +* @size: size of buf +* @ascii: if true convert from unicode to ascii characters +* +* Return 0 in case of success, non-zero otherwise +*/ +int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, u8*buf,
drivers/scsi/ufs/ufshcd.c +6
-0+ u32 size, bool ascii) +{ + int err = 0; + + err = ufshcd_read_desc(hba, + QUERY_DESC_IDN_STRING, desc_index, buf,size);
drivers/scsi/ufs/ufshcd.c +3
-0+ +if (err) { + dev_err(hba->dev, "%s: reading String Desc failed after%d retries. err = %d\n",
drivers/scsi/ufs/ufshcd.c static inline int ufshcd_read_power_desc(struct ufs_hba *hba, · line 2094
Quoted 3 lines
drivers/scsi/ufs/ufshcd.c +3
-0+ __func__, QUERY_REQ_RETRIES, err); + goto out; + }I actually tried this patch and
ufshcd_read_desc()always returns-EINVALdue to the following check in the end ofufshcd_read_desc().if (ret || (buff_len < ufs_query_desc_max_size[desc_id]) || (desc_buf[QUERY_DESC_LENGTH_OFFSET] != ufs_query_desc_max_size[desc_id]) || (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id)) { ... if (!ret) ret = -EINVAL;
Quoted 1 line
Could you also include a fix fir
ufshcd_read_desc()?
i'm not sure i understand what should be fixed.
if the check you mentioned implies that something is wrong, we shouldn't ignore the error. otherwise we might exceed the buf boundaries for example.
can you elaborate what is that you think we should fix ?
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 08/17] scsi: ufs: split broken LCC quirk
In reply to Akinobu MitaQuoted 35 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 34 lines
Currently when
UFSHCD_BROKEN_LCCquirk is defined, LCC is getting disabled on both host and device side but there could be a need where we don't want to disable the LCC on both side hence this change splits the quirk in 2 parts one for host and one for device.Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/scsi/ufs/ufshcd.c +5
-0@@ -3048,6 +3048,11 @@ static int ufshcd_disable_tx_lcc(struct ufs_hba *hba, bool peer)return err; } +static inline int ufshcd_disable_host_tx_lcc (struct ufs_hba *hba) +{ +return ufshcd_disable_tx_lcc (hba, false); +} +static inline int ufshcd_disable_device_tx_lcc (struct ufs_hba *hba) {return ufshcd_disable_tx_lcc(hba, true);drivers/scsi/ufs/ufshcd.c +0
-0@@ -3095,6 +3100,12 @@ static int ufshcd_link_startup(struct ufs_hba *hba) goto out; }
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c static int ufshcd_link_startup(struct ufs_hba *hba) · line 3108
Quoted 6 lines
drivers/scsi/ufs/ufshcd.c +6
-0+if (hba->dev_quirks &UFS_DEVICE_QUIRK_BROKEN_LCC ) { + ret =ufshcd_disable_host_tx_lcc (hba); +if (ret) + goto out; + } +This
dev_quirksis checked just after link startup. Butdev_quirkis determined afterufshcd_complete_dev_init(). Is this quirk correctly be applied?
good comment :)
since there is no need in this quirk anymore (it is never set), luckily we can totally remove the quirk.
i will remove this patch totally in v2
Quoted 15 lines
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c +0
-0/* Include any host controller configuration via UIC commands */ ret =ufshcd_vops_link_startup_notify (hba,POST_CHANGE );if (ret)
--
1.8.5.2--
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation --
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 12/17] scsi: ufs: add retry for query descriptors
In reply to Akinobu MitaQuoted 77 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 76 lines
Query commands have 100ms timeout and it may timeout if they are issued in parallel to ongoing read/write SCSI commands, this change adds the retry (max: 10) in case command timeouts.
Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 48 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)drivers/scsi/ufs/ufshcd.c +0
-2@@ -1906,21 +1906,7 @@ static int ufshcd_query_attr_retry(struct ufs_hba *hba, return ret; } -/** -* ufshcd_query_descriptor - API function for sending descriptor requests
- * hba: per-adapter instance
- * opcode: attribute opcode
- * idn: attribute idn to access
- * index: index field
- * selector: selector field
- *desc_buf: the buffer that contains the descriptor
- *buf_len: length parameter passed to the device
- *
- * Returns 0 for success, non-zero in case of failure.
- * Thebuf_lenparameter will contain, on return, the length parameter
- * received on the response.
- */drivers/scsi/ufs/ufshcd.c +1
-1-static int ufshcd_query_descriptor (struct ufs_hba *hba, +static int __ufshcd_query_descriptor (struct ufs_hba *hba, enum query_opcode opcode, enum desc_idn idn, u8index,
u8 selector, u8*desc_buf, int*buf_len)
{drivers/scsi/ufs/ufshcd.c +1
-0@@ -1985,6 +1971,38 @@ out: }/** +* ufshcd_query_descriptor - API function for sending descriptor requests
+ * hba: per-adapter instance
+ * opcode: attribute opcode
+ * idn: attribute idn to access
+ * index: index field
+ * selector: selector field
+ *desc_buf: the buffer that contains the descriptor
+ *buf_len: length parameter passed to the device
+ *
+ * Returns 0 for success, non-zero in case of failure.
+ * Thebuf_lenparameter will contain, on return, the length parameter
+ * received on the response.
+ */drivers/scsi/ufs/ufshcd.c +2
-0+int ufshcd_query_descriptor (struct ufs_hba *hba, + enum query_opcode opcode, enum desc_idn idn, u8index,
drivers/scsi/ufs/ufshcd.c +8
-0+ u8 selector, u8 *desc_buf, int *buf_len) +{ + int err; +int retries; + + for (retries = QUERY_REQ_RETRIES; retries > 0; retries--) { + err = __ufshcd_query_descriptor(hba, opcode, idn, index, + selector, desc_buf,
buf_len);drivers/scsi/ufs/ufshcd.c +4
-0+if (!err || err == -EINVAL ) +break ; + } +
Quoted 9 lines
drivers/scsi/ufs/ufshcd.c out: · line 2003
Quoted 3 lines
drivers/scsi/ufs/ufshcd.c +3
-0+return err; +} +EXPORT_SYMBOL (ufshcd_query_descriptor);You introduced query flag and attribute APIs for retry version with '
_retry' suffix.
This function retries but doesn't have '_retry' suffix. Should we have consistent function names for these query APIs?
sure. will fix this in v2
Re: [PATCH v1 14/17] scsi: ufs: tune UniPro parameters to optimize hibern8 exit time
In reply to Akinobu MitaQuoted 83 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 82 lines
Optimal values of local UniPro parameters like
PA_Hibern8Time&PA_TActivatecan help reduce the hibern8 exit latency. If both host and device supports UniPro ver1.6 or later, these parameters will be automatically tuned during link startup itself. But if either host or device doesn't support UniPro ver 1.6 or later, we have to manually tune them. But to keep manual tuning logic simple, we will only do manual tuning if local unipro version doesn't support ver1.6 or later.Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 1 + drivers/scsi/ufs/ufshci.h | 2 + drivers/scsi/ufs/unipro.h | 21 ++++++++ 4 files changed, 145 insertions(+)drivers/scsi/ufs/ufshcd.c +15
-0@@ -596,6 +596,34 @@ static inline int ufshcd_is_hba_active(struct ufs_hba *hba)return (ufshcd_readl (hba,REG_CONTROLLER_ENABLE ) &0x1 ) ?0 :1 ; } +u32 ufshcd_get_local_unipro_ver (struct ufs_hba *hba) +{ +/* HCI version 1.0 and 1.1 supports UniPro 1.41 */ +if ((hba->ufs_version ==UFSHCI_VERSION_10 ) || + (hba->ufs_version ==UFSHCI_VERSION_11 )) +return UFS_UNIPRO_VER_1_41 ; +else +return UFS_UNIPRO_VER_1_6 ; +} +EXPORT_SYMBOL (ufshcd_get_local_unipro_ver); + +static bool ufshcd_is_unipro_pa_params_tuning_req (struct ufs_hba *hba) +{ +/* +* If both host and device support UniPro ver1.6 or later, PA layer
drivers/scsi/ufs/ufshcd.c +3
-0+* parameters tuning happens during link startup itself. +* +* We can manually tune PA layer parameters if either host or device
+ * doesn't support UniPro ver 1.6 or later. But to keep manual
tuning
+ * logic simple, we will only do manual tuning if local unipro
versiondrivers/scsi/ufs/ufshcd.c +12
-0+* doesn't support ver1.6 or later. +*/ +if (ufshcd_get_local_unipro_ver (hba) <UFS_UNIPRO_VER_1_6 ) +return true; +else +return false; +} +static void ufshcd_ungate_work (struct work_struct *work) {int ret;@@ -4826,6 +4854,98 @@ out: }/** +* ufshcd_tune_pa_tactivate - Tunes PA_TActivate of local UniPro +* @hba: per-adapter instance +* +* PA_TActivate parameter can be tuned manually if UniPro version is less than
+ * 1.61.PA_TActivateneeds to be greater than or equal to peerM-PHY's
+ *RX_MIN_ACTIVATETIME_CAPABILITYattribute. This optimal value can help reduce
+ * the hibern8 exit latency.
+ *
+ * Returns zero on success, non-zero error value on failure.
+ */drivers/scsi/ufs/ufshcd.c +3
-0+static int ufshcd_tune_pa_tactivate (struct ufs_hba *hba) +{ +int ret =0 ;
Quoted 9 lines
drivers/scsi/ufs/ufshcd.c out: · line 4873
Quoted 4 lines
drivers/scsi/ufs/ufshcd.c +4
-0+u32 peer_rx_min_activatetime =0 , tuned_pa_tactivate; + +if (!ufshcd_is_unipro_pa_params_tuning_req (hba)) +return 0 ;This
ufshcd_tune_pa_tactivate()is called only whenufshcd_is_unipro_pa_params_tuning_req()returns true. Is this second check needed?
i could think of having this second check for any future call to ufshcd_tune_pa_tactivate() which is not protected with a wrapping check like in this case.
but i guess every call to ufshcd_tune_pa_tactivate()
will use ufshcd_tune_unipro_params() so we are good.
i will remove the 2nd check
Re: [PATCH v1 16/17] scsi: ufs: add delay before putting UFS rails in low power modes
In reply to Akinobu MitaQuoted 29 lines
2015-09-13 23:52 GMT+09:00 Yaniv Gardi <[email protected]>:
Quoted 28 lines
We put the UFS device in sleep state & UFS link in hibern8 state during runtime suspaned. After this we put all the UFS rails in low power modes immediately but it seems some devices may still draw more than sleep current from UFS rails (especially from VCCQ rail) atleast for 500us.
To avoid this situation, this change adds 2ms delay before putting these UFS rails in LPM mode.Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Yaniv Gardi <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/scsi/ufs/ufshcd.c +1
-0@@ -5694,6 +5694,15 @@ out:static void ufshcd_vreg_set_lpm (struct ufs_hba *hba) {/* +* It seems some UFS devices may keep drawing more than sleep current
+ * (atleast for 500us) from UFS rails (especially from VCCQ
rail).
+ * To avoid this situation, add 2ms delay before putting these
Quoted 8 lines
drivers/scsi/ufs/ufshcd.c out: · line 5704
Quoted 6 lines
UFS
drivers/scsi/ufs/ufshcd.c +5
-0+* rails in LPM mode. +*/ +if (!ufshcd_is_link_active (hba)) +usleep_range (2000 ,2100 ); +Shouldn't we define
dev_quirksfor this?
as you suggested, in v2 i added a device quirk for that.
Quoted 17 lines
Quoted 16 lines
+ /*
* If UFS device is either inUFS_Sleepturn off VCC rail to
save some
* power.
*
--
1.8.5.2--
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation --
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html