162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _UFS_QUIRKS_H_ 762306a36Sopenharmony_ci#define _UFS_QUIRKS_H_ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* return true if s1 is a prefix of s2 */ 1062306a36Sopenharmony_ci#define STR_PRFX_EQUAL(s1, s2) !strncmp(s1, s2, strlen(s1)) 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#define UFS_ANY_VENDOR 0xFFFF 1362306a36Sopenharmony_ci#define UFS_ANY_MODEL "ANY_MODEL" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define UFS_VENDOR_MICRON 0x12C 1662306a36Sopenharmony_ci#define UFS_VENDOR_SAMSUNG 0x1CE 1762306a36Sopenharmony_ci#define UFS_VENDOR_SKHYNIX 0x1AD 1862306a36Sopenharmony_ci#define UFS_VENDOR_TOSHIBA 0x198 1962306a36Sopenharmony_ci#define UFS_VENDOR_WDC 0x145 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/** 2262306a36Sopenharmony_ci * ufs_dev_quirk - ufs device quirk info 2362306a36Sopenharmony_ci * @card: ufs card details 2462306a36Sopenharmony_ci * @quirk: device quirk 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_cistruct ufs_dev_quirk { 2762306a36Sopenharmony_ci u16 wmanufacturerid; 2862306a36Sopenharmony_ci const u8 *model; 2962306a36Sopenharmony_ci unsigned int quirk; 3062306a36Sopenharmony_ci}; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* 3362306a36Sopenharmony_ci * Some vendor's UFS device sends back to back NACs for the DL data frames 3462306a36Sopenharmony_ci * causing the host controller to raise the DFES error status. Sometimes 3562306a36Sopenharmony_ci * such UFS devices send back to back NAC without waiting for new 3662306a36Sopenharmony_ci * retransmitted DL frame from the host and in such cases it might be possible 3762306a36Sopenharmony_ci * the Host UniPro goes into bad state without raising the DFES error 3862306a36Sopenharmony_ci * interrupt. If this happens then all the pending commands would timeout 3962306a36Sopenharmony_ci * only after respective SW command (which is generally too large). 4062306a36Sopenharmony_ci * 4162306a36Sopenharmony_ci * We can workaround such device behaviour like this: 4262306a36Sopenharmony_ci * - As soon as SW sees the DL NAC error, it should schedule the error handler 4362306a36Sopenharmony_ci * - Error handler would sleep for 50ms to see if there are any fatal errors 4462306a36Sopenharmony_ci * raised by UFS controller. 4562306a36Sopenharmony_ci * - If there are fatal errors then SW does normal error recovery. 4662306a36Sopenharmony_ci * - If there are no fatal errors then SW sends the NOP command to device 4762306a36Sopenharmony_ci * to check if link is alive. 4862306a36Sopenharmony_ci * - If NOP command times out, SW does normal error recovery 4962306a36Sopenharmony_ci * - If NOP command succeed, skip the error handling. 5062306a36Sopenharmony_ci * 5162306a36Sopenharmony_ci * If DL NAC error is seen multiple times with some vendor's UFS devices then 5262306a36Sopenharmony_ci * enable this quirk to initiate quick error recovery and also silence related 5362306a36Sopenharmony_ci * error logs to reduce spamming of kernel logs. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* 5862306a36Sopenharmony_ci * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as 5962306a36Sopenharmony_ci * 600us which may not be enough for reliable hibern8 exit hardware sequence 6062306a36Sopenharmony_ci * from UFS device. 6162306a36Sopenharmony_ci * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even 6262306a36Sopenharmony_ci * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms. 6362306a36Sopenharmony_ci */ 6462306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_PA_TACTIVATE (1 << 4) 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* 6762306a36Sopenharmony_ci * It seems some UFS devices may keep drawing more than sleep current 6862306a36Sopenharmony_ci * (atleast for 500us) from UFS rails (especially from VCCQ rail). 6962306a36Sopenharmony_ci * To avoid this situation, add 2ms delay before putting these UFS 7062306a36Sopenharmony_ci * rails in LPM mode. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM (1 << 6) 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* 7562306a36Sopenharmony_ci * Some UFS devices require host PA_TACTIVATE to be lower than device 7662306a36Sopenharmony_ci * PA_TACTIVATE, enabling this quirk ensure this. 7762306a36Sopenharmony_ci */ 7862306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE (1 << 7) 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* 8162306a36Sopenharmony_ci * The max. value PA_SaveConfigTime is 250 (10us) but this is not enough for 8262306a36Sopenharmony_ci * some vendors. 8362306a36Sopenharmony_ci * Gear switch from PWM to HS may fail even with this max. PA_SaveConfigTime. 8462306a36Sopenharmony_ci * Gear switch can be issued by host controller as an error recovery and any 8562306a36Sopenharmony_ci * software delay will not help on this case so we need to increase 8662306a36Sopenharmony_ci * PA_SaveConfigTime to >32us as per vendor recommendation. 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME (1 << 8) 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* 9162306a36Sopenharmony_ci * Some UFS devices require VS_DebugSaveConfigTime is 0x10, 9262306a36Sopenharmony_ci * enabling this quirk ensure this. 9362306a36Sopenharmony_ci */ 9462306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_HOST_VS_DEBUGSAVECONFIGTIME (1 << 9) 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/* 9762306a36Sopenharmony_ci * Some pre-3.1 UFS devices can support extended features by upgrading 9862306a36Sopenharmony_ci * the firmware. Enable this quirk to make UFS core driver probe and enable 9962306a36Sopenharmony_ci * supported features on such devices. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES (1 << 10) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* 10462306a36Sopenharmony_ci * Some UFS devices require delay after VCC power rail is turned-off. 10562306a36Sopenharmony_ci * Enable this quirk to introduce 5ms delays after VCC power-off during 10662306a36Sopenharmony_ci * suspend flow. 10762306a36Sopenharmony_ci */ 10862306a36Sopenharmony_ci#define UFS_DEVICE_QUIRK_DELAY_AFTER_LPM (1 << 11) 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci#endif /* UFS_QUIRKS_H_ */ 111