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