Thomas Gleixner | 97fb5e8 | 2019-05-29 07:17:58 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _UFS_QUIRKS_H_ |
| 7 | #define _UFS_QUIRKS_H_ |
| 8 | |
| 9 | /* return true if s1 is a prefix of s2 */ |
| 10 | #define STR_PRFX_EQUAL(s1, s2) !strncmp(s1, s2, strlen(s1)) |
| 11 | |
Yaniv Gardi | b799fdf | 2016-03-10 17:37:18 +0200 | [diff] [blame] | 12 | #define UFS_ANY_VENDOR 0xFFFF |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 13 | #define UFS_ANY_MODEL "ANY_MODEL" |
| 14 | |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 15 | #define UFS_VENDOR_TOSHIBA 0x198 |
| 16 | #define UFS_VENDOR_SAMSUNG 0x1CE |
Kyuho Choi | 46c1cf7 | 2016-09-26 23:58:25 +0900 | [diff] [blame] | 17 | #define UFS_VENDOR_SKHYNIX 0x1AD |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 18 | |
| 19 | /** |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 20 | * ufs_dev_fix - ufs device quirk info |
| 21 | * @card: ufs card details |
| 22 | * @quirk: device quirk |
| 23 | */ |
| 24 | struct ufs_dev_fix { |
Tomas Winkler | 93fdd5a | 2017-01-05 10:45:12 +0200 | [diff] [blame] | 25 | struct ufs_dev_desc card; |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 26 | unsigned int quirk; |
| 27 | }; |
| 28 | |
| 29 | #define END_FIX { { 0 }, 0 } |
| 30 | |
| 31 | /* add specific device quirk */ |
Tomas Winkler | 93fdd5a | 2017-01-05 10:45:12 +0200 | [diff] [blame] | 32 | #define UFS_FIX(_vendor, _model, _quirk) { \ |
| 33 | .card.wmanufacturerid = (_vendor),\ |
| 34 | .card.model = (_model), \ |
| 35 | .quirk = (_quirk), \ |
| 36 | } |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 37 | |
| 38 | /* |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 39 | * Some vendor's UFS device sends back to back NACs for the DL data frames |
| 40 | * causing the host controller to raise the DFES error status. Sometimes |
| 41 | * such UFS devices send back to back NAC without waiting for new |
| 42 | * retransmitted DL frame from the host and in such cases it might be possible |
| 43 | * the Host UniPro goes into bad state without raising the DFES error |
| 44 | * interrupt. If this happens then all the pending commands would timeout |
| 45 | * only after respective SW command (which is generally too large). |
| 46 | * |
| 47 | * We can workaround such device behaviour like this: |
| 48 | * - As soon as SW sees the DL NAC error, it should schedule the error handler |
| 49 | * - Error handler would sleep for 50ms to see if there are any fatal errors |
| 50 | * raised by UFS controller. |
| 51 | * - If there are fatal errors then SW does normal error recovery. |
| 52 | * - If there are no fatal errors then SW sends the NOP command to device |
| 53 | * to check if link is alive. |
| 54 | * - If NOP command times out, SW does normal error recovery |
| 55 | * - If NOP command succeed, skip the error handling. |
| 56 | * |
| 57 | * If DL NAC error is seen multiple times with some vendor's UFS devices then |
| 58 | * enable this quirk to initiate quick error recovery and also silence related |
| 59 | * error logs to reduce spamming of kernel logs. |
| 60 | */ |
| 61 | #define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2) |
| 62 | |
| 63 | /* |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 64 | * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as |
| 65 | * 600us which may not be enough for reliable hibern8 exit hardware sequence |
| 66 | * from UFS device. |
| 67 | * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even |
| 68 | * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms. |
| 69 | */ |
| 70 | #define UFS_DEVICE_QUIRK_PA_TACTIVATE (1 << 4) |
| 71 | |
| 72 | /* |
Yaniv Gardi | b799fdf | 2016-03-10 17:37:18 +0200 | [diff] [blame] | 73 | * It seems some UFS devices may keep drawing more than sleep current |
| 74 | * (atleast for 500us) from UFS rails (especially from VCCQ rail). |
| 75 | * To avoid this situation, add 2ms delay before putting these UFS |
| 76 | * rails in LPM mode. |
| 77 | */ |
| 78 | #define UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM (1 << 6) |
| 79 | |
subhashj@codeaurora.org | c6a6db4 | 2016-11-23 16:32:08 -0800 | [diff] [blame] | 80 | /* |
| 81 | * Some UFS devices require host PA_TACTIVATE to be lower than device |
| 82 | * PA_TACTIVATE, enabling this quirk ensure this. |
| 83 | */ |
| 84 | #define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE (1 << 7) |
| 85 | |
Subhash Jadavani | 56d4a18 | 2016-12-05 19:25:32 -0800 | [diff] [blame] | 86 | /* |
| 87 | * The max. value PA_SaveConfigTime is 250 (10us) but this is not enough for |
| 88 | * some vendors. |
| 89 | * Gear switch from PWM to HS may fail even with this max. PA_SaveConfigTime. |
| 90 | * Gear switch can be issued by host controller as an error recovery and any |
| 91 | * software delay will not help on this case so we need to increase |
| 92 | * PA_SaveConfigTime to >32us as per vendor recommendation. |
| 93 | */ |
| 94 | #define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME (1 << 8) |
subhashj@codeaurora.org | c6a6db4 | 2016-11-23 16:32:08 -0800 | [diff] [blame] | 95 | |
Wei Li | 8e4829c | 2018-11-08 09:08:29 -0800 | [diff] [blame] | 96 | /* |
| 97 | * Some UFS devices require VS_DebugSaveConfigTime is 0x10, |
| 98 | * enabling this quirk ensure this. |
| 99 | */ |
| 100 | #define UFS_DEVICE_QUIRK_HOST_VS_DEBUGSAVECONFIGTIME (1 << 9) |
| 101 | |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 102 | #endif /* UFS_QUIRKS_H_ */ |