Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef _UFS_QUIRKS_H_ |
| 16 | #define _UFS_QUIRKS_H_ |
| 17 | |
| 18 | /* return true if s1 is a prefix of s2 */ |
| 19 | #define STR_PRFX_EQUAL(s1, s2) !strncmp(s1, s2, strlen(s1)) |
| 20 | |
Yaniv Gardi | b799fdf | 2016-03-10 17:37:18 +0200 | [diff] [blame] | 21 | #define UFS_ANY_VENDOR 0xFFFF |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 22 | #define UFS_ANY_MODEL "ANY_MODEL" |
| 23 | |
| 24 | #define MAX_MODEL_LEN 16 |
| 25 | |
| 26 | #define UFS_VENDOR_TOSHIBA 0x198 |
| 27 | #define UFS_VENDOR_SAMSUNG 0x1CE |
Kyuho Choi | 46c1cf7 | 2016-09-26 23:58:25 +0900 | [diff] [blame] | 28 | #define UFS_VENDOR_SKHYNIX 0x1AD |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * ufs_device_info - ufs device details |
| 32 | * @wmanufacturerid: card details |
| 33 | * @model: card model |
| 34 | */ |
| 35 | struct ufs_device_info { |
| 36 | u16 wmanufacturerid; |
| 37 | char model[MAX_MODEL_LEN + 1]; |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * ufs_dev_fix - ufs device quirk info |
| 42 | * @card: ufs card details |
| 43 | * @quirk: device quirk |
| 44 | */ |
| 45 | struct ufs_dev_fix { |
| 46 | struct ufs_device_info card; |
| 47 | unsigned int quirk; |
| 48 | }; |
| 49 | |
| 50 | #define END_FIX { { 0 }, 0 } |
| 51 | |
| 52 | /* add specific device quirk */ |
| 53 | #define UFS_FIX(_vendor, _model, _quirk) \ |
| 54 | { \ |
| 55 | .card.wmanufacturerid = (_vendor),\ |
| 56 | .card.model = (_model), \ |
| 57 | .quirk = (_quirk), \ |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * If UFS device is having issue in processing LCC (Line Control |
| 62 | * Command) coming from UFS host controller then enable this quirk. |
| 63 | * When this quirk is enabled, host controller driver should disable |
| 64 | * the LCC transmission on UFS host controller (by clearing |
| 65 | * TX_LCC_ENABLE attribute of host to 0). |
| 66 | */ |
| 67 | #define UFS_DEVICE_QUIRK_BROKEN_LCC (1 << 0) |
| 68 | |
| 69 | /* |
| 70 | * Some UFS devices don't need VCCQ rail for device operations. Enabling this |
| 71 | * quirk for such devices will make sure that VCCQ rail is not voted. |
| 72 | */ |
| 73 | #define UFS_DEVICE_NO_VCCQ (1 << 1) |
| 74 | |
| 75 | /* |
| 76 | * Some vendor's UFS device sends back to back NACs for the DL data frames |
| 77 | * causing the host controller to raise the DFES error status. Sometimes |
| 78 | * such UFS devices send back to back NAC without waiting for new |
| 79 | * retransmitted DL frame from the host and in such cases it might be possible |
| 80 | * the Host UniPro goes into bad state without raising the DFES error |
| 81 | * interrupt. If this happens then all the pending commands would timeout |
| 82 | * only after respective SW command (which is generally too large). |
| 83 | * |
| 84 | * We can workaround such device behaviour like this: |
| 85 | * - As soon as SW sees the DL NAC error, it should schedule the error handler |
| 86 | * - Error handler would sleep for 50ms to see if there are any fatal errors |
| 87 | * raised by UFS controller. |
| 88 | * - If there are fatal errors then SW does normal error recovery. |
| 89 | * - If there are no fatal errors then SW sends the NOP command to device |
| 90 | * to check if link is alive. |
| 91 | * - If NOP command times out, SW does normal error recovery |
| 92 | * - If NOP command succeed, skip the error handling. |
| 93 | * |
| 94 | * If DL NAC error is seen multiple times with some vendor's UFS devices then |
| 95 | * enable this quirk to initiate quick error recovery and also silence related |
| 96 | * error logs to reduce spamming of kernel logs. |
| 97 | */ |
| 98 | #define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2) |
| 99 | |
| 100 | /* |
| 101 | * Some UFS devices may not work properly after resume if the link was kept |
| 102 | * in off state during suspend. Enabling this quirk will not allow the |
| 103 | * link to be kept in off state during suspend. |
| 104 | */ |
| 105 | #define UFS_DEVICE_QUIRK_NO_LINK_OFF (1 << 3) |
| 106 | |
| 107 | /* |
| 108 | * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as |
| 109 | * 600us which may not be enough for reliable hibern8 exit hardware sequence |
| 110 | * from UFS device. |
| 111 | * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even |
| 112 | * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms. |
| 113 | */ |
| 114 | #define UFS_DEVICE_QUIRK_PA_TACTIVATE (1 << 4) |
| 115 | |
| 116 | /* |
| 117 | * Some UFS memory devices may have really low read/write throughput in |
| 118 | * FAST AUTO mode, enable this quirk to make sure that FAST AUTO mode is |
| 119 | * never enabled for such devices. |
| 120 | */ |
| 121 | #define UFS_DEVICE_NO_FASTAUTO (1 << 5) |
| 122 | |
Yaniv Gardi | b799fdf | 2016-03-10 17:37:18 +0200 | [diff] [blame] | 123 | /* |
| 124 | * It seems some UFS devices may keep drawing more than sleep current |
| 125 | * (atleast for 500us) from UFS rails (especially from VCCQ rail). |
| 126 | * To avoid this situation, add 2ms delay before putting these UFS |
| 127 | * rails in LPM mode. |
| 128 | */ |
| 129 | #define UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM (1 << 6) |
| 130 | |
subhashj@codeaurora.org | c6a6db4 | 2016-11-23 16:32:08 -0800 | [diff] [blame^] | 131 | /* |
| 132 | * Some UFS devices require host PA_TACTIVATE to be lower than device |
| 133 | * PA_TACTIVATE, enabling this quirk ensure this. |
| 134 | */ |
| 135 | #define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE (1 << 7) |
| 136 | |
| 137 | |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 138 | struct ufs_hba; |
| 139 | void ufs_advertise_fixup_device(struct ufs_hba *hba); |
| 140 | |
| 141 | static struct ufs_dev_fix ufs_fixups[] = { |
| 142 | /* UFS cards deviations table */ |
Yaniv Gardi | b799fdf | 2016-03-10 17:37:18 +0200 | [diff] [blame] | 143 | UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, |
| 144 | UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM), |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 145 | UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, UFS_DEVICE_NO_VCCQ), |
| 146 | UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, |
| 147 | UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS), |
| 148 | UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, |
| 149 | UFS_DEVICE_NO_FASTAUTO), |
subhashj@codeaurora.org | c6a6db4 | 2016-11-23 16:32:08 -0800 | [diff] [blame^] | 150 | UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL, |
| 151 | UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE), |
Yaniv Gardi | b799fdf | 2016-03-10 17:37:18 +0200 | [diff] [blame] | 152 | UFS_FIX(UFS_VENDOR_TOSHIBA, UFS_ANY_MODEL, |
| 153 | UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM), |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 154 | UFS_FIX(UFS_VENDOR_TOSHIBA, "THGLF2G9C8KBADG", |
| 155 | UFS_DEVICE_QUIRK_PA_TACTIVATE), |
| 156 | UFS_FIX(UFS_VENDOR_TOSHIBA, "THGLF2G9D8KBADG", |
| 157 | UFS_DEVICE_QUIRK_PA_TACTIVATE), |
Kyuho Choi | 46c1cf7 | 2016-09-26 23:58:25 +0900 | [diff] [blame] | 158 | UFS_FIX(UFS_VENDOR_SKHYNIX, UFS_ANY_MODEL, UFS_DEVICE_NO_VCCQ), |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 159 | |
| 160 | END_FIX |
| 161 | }; |
| 162 | #endif /* UFS_QUIRKS_H_ */ |