ufs_quirks.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifndef _UFS_QUIRKS_H_
  15. #define _UFS_QUIRKS_H_
  16. /* return true if s1 is a prefix of s2 */
  17. #define STR_PRFX_EQUAL(s1, s2) !strncmp(s1, s2, strlen(s1))
  18. #define UFS_ANY_VENDOR 0xFFFF
  19. #define UFS_ANY_MODEL "ANY_MODEL"
  20. #define MAX_MODEL_LEN 16
  21. #define UFS_VENDOR_TOSHIBA 0x198
  22. #define UFS_VENDOR_SAMSUNG 0x1CE
  23. #define UFS_VENDOR_SKHYNIX 0x1AD
  24. /**
  25. * ufs_device_info - ufs device details
  26. * @wmanufacturerid: card details
  27. * @model: card model
  28. */
  29. struct ufs_device_info {
  30. u16 wmanufacturerid;
  31. char model[MAX_MODEL_LEN + 1];
  32. };
  33. /**
  34. * ufs_dev_fix - ufs device quirk info
  35. * @card: ufs card details
  36. * @quirk: device quirk
  37. */
  38. struct ufs_dev_fix {
  39. struct ufs_device_info card;
  40. unsigned int quirk;
  41. };
  42. #define END_FIX { { 0 }, 0 }
  43. /* add specific device quirk */
  44. #define UFS_FIX(_vendor, _model, _quirk) \
  45. { \
  46. .card.wmanufacturerid = (_vendor),\
  47. .card.model = (_model), \
  48. .quirk = (_quirk), \
  49. }
  50. /*
  51. * If UFS device is having issue in processing LCC (Line Control
  52. * Command) coming from UFS host controller then enable this quirk.
  53. * When this quirk is enabled, host controller driver should disable
  54. * the LCC transmission on UFS host controller (by clearing
  55. * TX_LCC_ENABLE attribute of host to 0).
  56. */
  57. #define UFS_DEVICE_QUIRK_BROKEN_LCC (1 << 0)
  58. /*
  59. * Some UFS devices don't need VCCQ rail for device operations. Enabling this
  60. * quirk for such devices will make sure that VCCQ rail is not voted.
  61. */
  62. #define UFS_DEVICE_NO_VCCQ (1 << 1)
  63. /*
  64. * Some vendor's UFS device sends back to back NACs for the DL data frames
  65. * causing the host controller to raise the DFES error status. Sometimes
  66. * such UFS devices send back to back NAC without waiting for new
  67. * retransmitted DL frame from the host and in such cases it might be possible
  68. * the Host UniPro goes into bad state without raising the DFES error
  69. * interrupt. If this happens then all the pending commands would timeout
  70. * only after respective SW command (which is generally too large).
  71. *
  72. * We can workaround such device behaviour like this:
  73. * - As soon as SW sees the DL NAC error, it should schedule the error handler
  74. * - Error handler would sleep for 50ms to see if there are any fatal errors
  75. * raised by UFS controller.
  76. * - If there are fatal errors then SW does normal error recovery.
  77. * - If there are no fatal errors then SW sends the NOP command to device
  78. * to check if link is alive.
  79. * - If NOP command times out, SW does normal error recovery
  80. * - If NOP command succeed, skip the error handling.
  81. *
  82. * If DL NAC error is seen multiple times with some vendor's UFS devices then
  83. * enable this quirk to initiate quick error recovery and also silence related
  84. * error logs to reduce spamming of kernel logs.
  85. */
  86. #define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2)
  87. /*
  88. * Some UFS devices may not work properly after resume if the link was kept
  89. * in off state during suspend. Enabling this quirk will not allow the
  90. * link to be kept in off state during suspend.
  91. */
  92. #define UFS_DEVICE_QUIRK_NO_LINK_OFF (1 << 3)
  93. /*
  94. * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as
  95. * 600us which may not be enough for reliable hibern8 exit hardware sequence
  96. * from UFS device.
  97. * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even
  98. * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms.
  99. */
  100. #define UFS_DEVICE_QUIRK_PA_TACTIVATE (1 << 4)
  101. /*
  102. * Some UFS memory devices may have really low read/write throughput in
  103. * FAST AUTO mode, enable this quirk to make sure that FAST AUTO mode is
  104. * never enabled for such devices.
  105. */
  106. #define UFS_DEVICE_NO_FASTAUTO (1 << 5)
  107. /*
  108. * It seems some UFS devices may keep drawing more than sleep current
  109. * (atleast for 500us) from UFS rails (especially from VCCQ rail).
  110. * To avoid this situation, add 2ms delay before putting these UFS
  111. * rails in LPM mode.
  112. */
  113. #define UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM (1 << 6)
  114. /*
  115. * Some UFS devices require host PA_TACTIVATE to be lower than device
  116. * PA_TACTIVATE, enabling this quirk ensure this.
  117. */
  118. #define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE (1 << 7)
  119. /*
  120. * The max. value PA_SaveConfigTime is 250 (10us) but this is not enough for
  121. * some vendors.
  122. * Gear switch from PWM to HS may fail even with this max. PA_SaveConfigTime.
  123. * Gear switch can be issued by host controller as an error recovery and any
  124. * software delay will not help on this case so we need to increase
  125. * PA_SaveConfigTime to >32us as per vendor recommendation.
  126. */
  127. #define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME (1 << 8)
  128. struct ufs_hba;
  129. void ufs_advertise_fixup_device(struct ufs_hba *hba);
  130. #endif /* UFS_QUIRKS_H_ */