1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. 4*4882a593Smuzhiyun */ 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun #ifndef _UFS_QUIRKS_H_ 7*4882a593Smuzhiyun #define _UFS_QUIRKS_H_ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun /* return true if s1 is a prefix of s2 */ 10*4882a593Smuzhiyun #define STR_PRFX_EQUAL(s1, s2) !strncmp(s1, s2, strlen(s1)) 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun #define UFS_ANY_VENDOR 0xFFFF 13*4882a593Smuzhiyun #define UFS_ANY_MODEL "ANY_MODEL" 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun #define UFS_VENDOR_MICRON 0x12C 16*4882a593Smuzhiyun #define UFS_VENDOR_SAMSUNG 0x1CE 17*4882a593Smuzhiyun #define UFS_VENDOR_SKHYNIX 0x1AD 18*4882a593Smuzhiyun #define UFS_VENDOR_TOSHIBA 0x198 19*4882a593Smuzhiyun #define UFS_VENDOR_WDC 0x145 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun /** 22*4882a593Smuzhiyun * ufs_dev_fix - ufs device quirk info 23*4882a593Smuzhiyun * @card: ufs card details 24*4882a593Smuzhiyun * @quirk: device quirk 25*4882a593Smuzhiyun */ 26*4882a593Smuzhiyun struct ufs_dev_fix { 27*4882a593Smuzhiyun u16 wmanufacturerid; 28*4882a593Smuzhiyun u8 *model; 29*4882a593Smuzhiyun unsigned int quirk; 30*4882a593Smuzhiyun }; 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun #define END_FIX { } 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /* add specific device quirk */ 35*4882a593Smuzhiyun #define UFS_FIX(_vendor, _model, _quirk) { \ 36*4882a593Smuzhiyun .wmanufacturerid = (_vendor),\ 37*4882a593Smuzhiyun .model = (_model), \ 38*4882a593Smuzhiyun .quirk = (_quirk), \ 39*4882a593Smuzhiyun } 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun /* 42*4882a593Smuzhiyun * Some vendor's UFS device sends back to back NACs for the DL data frames 43*4882a593Smuzhiyun * causing the host controller to raise the DFES error status. Sometimes 44*4882a593Smuzhiyun * such UFS devices send back to back NAC without waiting for new 45*4882a593Smuzhiyun * retransmitted DL frame from the host and in such cases it might be possible 46*4882a593Smuzhiyun * the Host UniPro goes into bad state without raising the DFES error 47*4882a593Smuzhiyun * interrupt. If this happens then all the pending commands would timeout 48*4882a593Smuzhiyun * only after respective SW command (which is generally too large). 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * We can workaround such device behaviour like this: 51*4882a593Smuzhiyun * - As soon as SW sees the DL NAC error, it should schedule the error handler 52*4882a593Smuzhiyun * - Error handler would sleep for 50ms to see if there are any fatal errors 53*4882a593Smuzhiyun * raised by UFS controller. 54*4882a593Smuzhiyun * - If there are fatal errors then SW does normal error recovery. 55*4882a593Smuzhiyun * - If there are no fatal errors then SW sends the NOP command to device 56*4882a593Smuzhiyun * to check if link is alive. 57*4882a593Smuzhiyun * - If NOP command times out, SW does normal error recovery 58*4882a593Smuzhiyun * - If NOP command succeed, skip the error handling. 59*4882a593Smuzhiyun * 60*4882a593Smuzhiyun * If DL NAC error is seen multiple times with some vendor's UFS devices then 61*4882a593Smuzhiyun * enable this quirk to initiate quick error recovery and also silence related 62*4882a593Smuzhiyun * error logs to reduce spamming of kernel logs. 63*4882a593Smuzhiyun */ 64*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2) 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun /* 67*4882a593Smuzhiyun * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as 68*4882a593Smuzhiyun * 600us which may not be enough for reliable hibern8 exit hardware sequence 69*4882a593Smuzhiyun * from UFS device. 70*4882a593Smuzhiyun * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even 71*4882a593Smuzhiyun * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms. 72*4882a593Smuzhiyun */ 73*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_PA_TACTIVATE (1 << 4) 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun /* 76*4882a593Smuzhiyun * It seems some UFS devices may keep drawing more than sleep current 77*4882a593Smuzhiyun * (atleast for 500us) from UFS rails (especially from VCCQ rail). 78*4882a593Smuzhiyun * To avoid this situation, add 2ms delay before putting these UFS 79*4882a593Smuzhiyun * rails in LPM mode. 80*4882a593Smuzhiyun */ 81*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM (1 << 6) 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun /* 84*4882a593Smuzhiyun * Some UFS devices require host PA_TACTIVATE to be lower than device 85*4882a593Smuzhiyun * PA_TACTIVATE, enabling this quirk ensure this. 86*4882a593Smuzhiyun */ 87*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE (1 << 7) 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun /* 90*4882a593Smuzhiyun * The max. value PA_SaveConfigTime is 250 (10us) but this is not enough for 91*4882a593Smuzhiyun * some vendors. 92*4882a593Smuzhiyun * Gear switch from PWM to HS may fail even with this max. PA_SaveConfigTime. 93*4882a593Smuzhiyun * Gear switch can be issued by host controller as an error recovery and any 94*4882a593Smuzhiyun * software delay will not help on this case so we need to increase 95*4882a593Smuzhiyun * PA_SaveConfigTime to >32us as per vendor recommendation. 96*4882a593Smuzhiyun */ 97*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME (1 << 8) 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun /* 100*4882a593Smuzhiyun * Some UFS devices require VS_DebugSaveConfigTime is 0x10, 101*4882a593Smuzhiyun * enabling this quirk ensure this. 102*4882a593Smuzhiyun */ 103*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_HOST_VS_DEBUGSAVECONFIGTIME (1 << 9) 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun /* 106*4882a593Smuzhiyun * Some pre-3.1 UFS devices can support extended features by upgrading 107*4882a593Smuzhiyun * the firmware. Enable this quirk to make UFS core driver probe and enable 108*4882a593Smuzhiyun * supported features on such devices. 109*4882a593Smuzhiyun */ 110*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES (1 << 10) 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun /* 113*4882a593Smuzhiyun * Some UFS devices require delay after VCC power rail is turned-off. 114*4882a593Smuzhiyun * Enable this quirk to introduce 5ms delays after VCC power-off during 115*4882a593Smuzhiyun * suspend flow. 116*4882a593Smuzhiyun */ 117*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_DELAY_AFTER_LPM (1 << 11) 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun /* 120*4882a593Smuzhiyun * Some UFS devices require L2P entry should be swapped before being sent to the 121*4882a593Smuzhiyun * UFS device for HPB READ command. 122*4882a593Smuzhiyun */ 123*4882a593Smuzhiyun #define UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ (1 << 12) 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun #endif /* UFS_QUIRKS_H_ */ 126