OSDN Git Service

Merge tag 'v4.4.214' into 10
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / scsi / ufs / ufs_quirks.h
1 /* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
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
20 #define UFS_ANY_VENDOR -1
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
27 #define UFS_VENDOR_HYNIX       0x1AD
28
29 /* UFS TOSHIBA MODELS */
30 #define UFS_MODEL_TOSHIBA_32GB "THGLF2G8D4KBADR"
31 #define UFS_MODEL_TOSHIBA_64GB "THGLF2G9D8KBADG"
32
33 /**
34  * ufs_card_info - ufs device details
35  * @wmanufacturerid: card details
36  * @model: card model
37  */
38 struct ufs_card_info {
39         u16 wmanufacturerid;
40         char *model;
41 };
42
43 /**
44  * ufs_card_fix - ufs device quirk info
45  * @card: ufs card details
46  * @quirk: device quirk
47  */
48 struct ufs_card_fix {
49         struct ufs_card_info card;
50         unsigned int quirk;
51 };
52
53 #define END_FIX { { 0 } , 0 }
54
55 /* add specific device quirk */
56 #define UFS_FIX(_vendor, _model, _quirk) \
57                 {                                                 \
58                                 .card.wmanufacturerid = (_vendor),\
59                                 .card.model = (_model),           \
60                                 .quirk = (_quirk),                \
61                 }
62
63 /*
64  * If UFS device is having issue in processing LCC (Line Control
65  * Command) coming from UFS host controller then enable this quirk.
66  * When this quirk is enabled, host controller driver should disable
67  * the LCC transmission on UFS host controller (by clearing
68  * TX_LCC_ENABLE attribute of host to 0).
69  */
70 #define UFS_DEVICE_QUIRK_BROKEN_LCC (1 << 0)
71
72 /*
73  * Some UFS devices don't need VCCQ rail for device operations. Enabling this
74  * quirk for such devices will make sure that VCCQ rail is not voted.
75  */
76 #define UFS_DEVICE_NO_VCCQ (1 << 1)
77
78 /*
79  * Some vendor's UFS device sends back to back NACs for the DL data frames
80  * causing the host controller to raise the DFES error status. Sometimes
81  * such UFS devices send back to back NAC without waiting for new
82  * retransmitted DL frame from the host and in such cases it might be possible
83  * the Host UniPro goes into bad state without raising the DFES error
84  * interrupt. If this happens then all the pending commands would timeout
85  * only after respective SW command (which is generally too large).
86  *
87  * We can workaround such device behaviour like this:
88  * - As soon as SW sees the DL NAC error, it should schedule the error handler
89  * - Error handler would sleep for 50ms to see if there are any fatal errors
90  *   raised by UFS controller.
91  *    - If there are fatal errors then SW does normal error recovery.
92  *    - If there are no fatal errors then SW sends the NOP command to device
93  *      to check if link is alive.
94  *        - If NOP command times out, SW does normal error recovery
95  *        - If NOP command succeed, skip the error handling.
96  *
97  * If DL NAC error is seen multiple times with some vendor's UFS devices then
98  * enable this quirk to initiate quick error recovery and also silence related
99  * error logs to reduce spamming of kernel logs.
100  */
101 #define UFS_DEVICE_QUIRK_RECOVERY_FROM_DL_NAC_ERRORS (1 << 2)
102
103 /*
104  * Some UFS devices may not work properly after resume if the link was kept
105  * in off state during suspend. Enabling this quirk will not allow the
106  * link to be kept in off state during suspend.
107  */
108 #define UFS_DEVICE_QUIRK_NO_LINK_OFF    (1 << 3)
109
110 /*
111  * Few Toshiba UFS device models advertise RX_MIN_ACTIVATETIME_CAPABILITY as
112  * 600us which may not be enough for reliable hibern8 exit hardware sequence
113  * from UFS device.
114  * To workaround this issue, host should set its PA_TACTIVATE time to 1ms even
115  * if device advertises RX_MIN_ACTIVATETIME_CAPABILITY less than 1ms.
116  */
117 #define UFS_DEVICE_QUIRK_PA_TACTIVATE   (1 << 4)
118
119 /*
120  * Some UFS memory devices may have really low read/write throughput in
121  * FAST AUTO mode, enable this quirk to make sure that FAST AUTO mode is
122  * never enabled for such devices.
123  */
124 #define UFS_DEVICE_NO_FASTAUTO          (1 << 5)
125
126 /*
127  * Some UFS devices require host PA_TACTIVATE to be lower than device
128  * PA_TACTIVATE, enabling this quirk ensure this.
129  */
130 #define UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE      (1 << 6)
131
132 /*
133  * The max. value PA_SaveConfigTime is 250 (10us) but this is not enough for
134  * some vendors.
135  * Gear switch from PWM to HS may fail even with this max. PA_SaveConfigTime.
136  * Gear switch can be issued by host controller as an error recovery and any
137  * software delay will not help on this case so we need to increase
138  * PA_SaveConfigTime to >32us as per vendor recommendation.
139  */
140 #define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME (1 << 7)
141
142 /*
143  * Some UFS devices may stop responding after switching from HS-G1 to HS-G3.
144  * Also, it is found that these devices work fine if we do 2 steps switch:
145  * HS-G1 to HS-G2 followed by HS-G2 to HS-G3. Enabling this quirk for such
146  * device would apply this 2 steps gear switch workaround.
147  */
148 #define UFS_DEVICE_QUIRK_HS_G1_TO_HS_G3_SWITCH (1 << 8)
149
150 struct ufs_hba;
151 void ufs_advertise_fixup_device(struct ufs_hba *hba);
152 #endif /* UFS_QUIRKS_H_ */