blob: f7182edad3a7cdca0b8de17db8c9763be098013d [file] [log] [blame]
Subhash Jadavani344c16c2016-12-15 17:09:35 -08001/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
Yaniv Gardic58ab7a2016-03-10 17:37:10 +02002 *
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 Jadavanicce6fbc2016-08-11 11:35:26 -070020#define UFS_ANY_VENDOR -1
Yaniv Gardic58ab7a2016-03-10 17:37:10 +020021#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 Choi46c1cf72016-09-26 23:58:25 +090027#define UFS_VENDOR_SKHYNIX 0x1AD
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -070028
29/* UFS TOSHIBA MODELS */
30#define UFS_MODEL_TOSHIBA_32GB "THGLF2G8D4KBADR"
31#define UFS_MODEL_TOSHIBA_64GB "THGLF2G9D8KBADG"
Yaniv Gardic58ab7a2016-03-10 17:37:10 +020032
33/**
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -070034 * ufs_card_fix - ufs device quirk info
Yaniv Gardic58ab7a2016-03-10 17:37:10 +020035 * @card: ufs card details
36 * @quirk: device quirk
37 */
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -070038struct ufs_card_fix {
Subhash Jadavani344c16c2016-12-15 17:09:35 -080039 u16 w_manufacturer_id;
40 char *model;
Yaniv Gardic58ab7a2016-03-10 17:37:10 +020041 unsigned int quirk;
42};
43
Subhash Jadavani344c16c2016-12-15 17:09:35 -080044#define END_FIX { 0 }
Yaniv Gardic58ab7a2016-03-10 17:37:10 +020045
46/* add specific device quirk */
47#define UFS_FIX(_vendor, _model, _quirk) \
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -070048 { \
Subhash Jadavani344c16c2016-12-15 17:09:35 -080049 .w_manufacturer_id = (_vendor),\
50 .model = (_model), \
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -070051 .quirk = (_quirk), \
Yaniv Gardic58ab7a2016-03-10 17:37:10 +020052 }
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 Gardib799fdf2016-03-10 17:37:18 +0200117/*
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -0700118 * Some UFS devices require host PA_TACTIVATE to be lower than device
119 * PA_TACTIVATE, enabling this quirk ensure this.
Yaniv Gardib799fdf2016-03-10 17:37:18 +0200120 */
Subhash Jadavanicce6fbc2016-08-11 11:35:26 -0700121#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 Gardib799fdf2016-03-10 17:37:18 +0200132
Yaniv Gardic58ab7a2016-03-10 17:37:10 +0200133struct ufs_hba;
134void ufs_advertise_fixup_device(struct ufs_hba *hba);
135
Yaniv Gardic58ab7a2016-03-10 17:37:10 +0200136#endif /* UFS_QUIRKS_H_ */