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