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