18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _UFS_QUIRKS_H_
78c2ecf20Sopenharmony_ci#define _UFS_QUIRKS_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/* return true if s1 is a prefix of s2 */
108c2ecf20Sopenharmony_ci#define STR_PRFX_EQUAL(s1, s2) !strncmp(s1, s2, strlen(s1))
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define UFS_ANY_VENDOR 0xFFFF
138c2ecf20Sopenharmony_ci#define UFS_ANY_MODEL  "ANY_MODEL"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define UFS_VENDOR_MICRON      0x12C
168c2ecf20Sopenharmony_ci#define UFS_VENDOR_SAMSUNG     0x1CE
178c2ecf20Sopenharmony_ci#define UFS_VENDOR_SKHYNIX     0x1AD
188c2ecf20Sopenharmony_ci#define UFS_VENDOR_TOSHIBA     0x198
198c2ecf20Sopenharmony_ci#define UFS_VENDOR_WDC         0x145
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/**
228c2ecf20Sopenharmony_ci * ufs_dev_fix - ufs device quirk info
238c2ecf20Sopenharmony_ci * @card: ufs card details
248c2ecf20Sopenharmony_ci * @quirk: device quirk
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_cistruct ufs_dev_fix {
278c2ecf20Sopenharmony_ci	u16 wmanufacturerid;
288c2ecf20Sopenharmony_ci	u8 *model;
298c2ecf20Sopenharmony_ci	unsigned int quirk;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define END_FIX { }
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* add specific device quirk */
358c2ecf20Sopenharmony_ci#define UFS_FIX(_vendor, _model, _quirk) { \
368c2ecf20Sopenharmony_ci	.wmanufacturerid = (_vendor),\
378c2ecf20Sopenharmony_ci	.model = (_model),		   \
388c2ecf20Sopenharmony_ci	.quirk = (_quirk),		   \
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * Some vendor's UFS device sends back to back NACs for the DL data frames
438c2ecf20Sopenharmony_ci * causing the host controller to raise the DFES error status. Sometimes
448c2ecf20Sopenharmony_ci * such UFS devices send back to back NAC without waiting for new
458c2ecf20Sopenharmony_ci * retransmitted DL frame from the host and in such cases it might be possible
468c2ecf20Sopenharmony_ci * the Host UniPro goes into bad state without raising the DFES error
478c2ecf20Sopenharmony_ci * interrupt. If this happens then all the pending commands would timeout
488c2ecf20Sopenharmony_ci * only after respective SW command (which is generally too large).
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * We can workaround such device behaviour like this:
518c2ecf20Sopenharmony_ci * - As soon as SW sees the DL NAC error, it should schedule the error handler
528c2ecf20Sopenharmony_ci * - Error handler would sleep for 50ms to see if there are any fatal errors
538c2ecf20Sopenharmony_ci *   raised by UFS controller.
548c2ecf20Sopenharmony_ci *    - If there are fatal errors then SW does normal error recovery.
558c2ecf20Sopenharmony_ci *    - If there are no fatal errors then SW sends the NOP command to device
568c2ecf20Sopenharmony_ci *      to check if link is alive.
578c2ecf20Sopenharmony_ci *        - If NOP command times out, SW does normal error recovery
588c2ecf20Sopenharmony_ci *        - If NOP command succeed, skip the error handling.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * If DL NAC error is seen multiple times with some vendor's UFS devices then
618c2ecf20Sopenharmony_ci * enable this quirk to initiate quick error recovery and also silence related
628c2ecf20Sopenharmony_ci * error logs to reduce spamming of kernel logs.
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as
688c2ecf20Sopenharmony_ci * 600us which may not be enough for reliable hibern8 exit hardware sequence
698c2ecf20Sopenharmony_ci * from UFS device.
708c2ecf20Sopenharmony_ci * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even
718c2ecf20Sopenharmony_ci * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms.
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_PA_TACTIVATE	(1 << 4)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/*
768c2ecf20Sopenharmony_ci * It seems some UFS devices may keep drawing more than sleep current
778c2ecf20Sopenharmony_ci * (atleast for 500us) from UFS rails (especially from VCCQ rail).
788c2ecf20Sopenharmony_ci * To avoid this situation, add 2ms delay before putting these UFS
798c2ecf20Sopenharmony_ci * rails in LPM mode.
808c2ecf20Sopenharmony_ci */
818c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM	(1 << 6)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/*
848c2ecf20Sopenharmony_ci * Some UFS devices require host PA_TACTIVATE to be lower than device
858c2ecf20Sopenharmony_ci * PA_TACTIVATE, enabling this quirk ensure this.
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE	(1 << 7)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/*
908c2ecf20Sopenharmony_ci * The max. value PA_SaveConfigTime is 250 (10us) but this is not enough for
918c2ecf20Sopenharmony_ci * some vendors.
928c2ecf20Sopenharmony_ci * Gear switch from PWM to HS may fail even with this max. PA_SaveConfigTime.
938c2ecf20Sopenharmony_ci * Gear switch can be issued by host controller as an error recovery and any
948c2ecf20Sopenharmony_ci * software delay will not help on this case so we need to increase
958c2ecf20Sopenharmony_ci * PA_SaveConfigTime to >32us as per vendor recommendation.
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME	(1 << 8)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/*
1008c2ecf20Sopenharmony_ci * Some UFS devices require VS_DebugSaveConfigTime is 0x10,
1018c2ecf20Sopenharmony_ci * enabling this quirk ensure this.
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_HOST_VS_DEBUGSAVECONFIGTIME	(1 << 9)
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/*
1068c2ecf20Sopenharmony_ci * Some pre-3.1 UFS devices can support extended features by upgrading
1078c2ecf20Sopenharmony_ci * the firmware. Enable this quirk to make UFS core driver probe and enable
1088c2ecf20Sopenharmony_ci * supported features on such devices.
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES (1 << 10)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci * Some UFS devices require delay after VCC power rail is turned-off.
1148c2ecf20Sopenharmony_ci * Enable this quirk to introduce 5ms delays after VCC power-off during
1158c2ecf20Sopenharmony_ci * suspend flow.
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_ci#define UFS_DEVICE_QUIRK_DELAY_AFTER_LPM        (1 << 11)
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#endif /* UFS_QUIRKS_H_ */
120