]>
Commit | Line | Data |
---|---|---|
3417ba8a JG |
1 | /* |
2 | * Copyright (c) 2016 Linaro Ltd. | |
3 | * Copyright (c) 2016 Hisilicon Limited. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | */ | |
11 | ||
12 | #include "hisi_sas.h" | |
13 | #define DRV_NAME "hisi_sas_v2_hw" | |
14 | ||
45c901b8 JG |
15 | /* global registers need init*/ |
16 | #define DLVRY_QUEUE_ENABLE 0x0 | |
17 | #define IOST_BASE_ADDR_LO 0x8 | |
18 | #define IOST_BASE_ADDR_HI 0xc | |
19 | #define ITCT_BASE_ADDR_LO 0x10 | |
20 | #define ITCT_BASE_ADDR_HI 0x14 | |
21 | #define IO_BROKEN_MSG_ADDR_LO 0x18 | |
22 | #define IO_BROKEN_MSG_ADDR_HI 0x1c | |
23 | #define PHY_CONTEXT 0x20 | |
24 | #define PHY_STATE 0x24 | |
25 | #define PHY_PORT_NUM_MA 0x28 | |
26 | #define PORT_STATE 0x2c | |
27 | #define PORT_STATE_PHY8_PORT_NUM_OFF 16 | |
28 | #define PORT_STATE_PHY8_PORT_NUM_MSK (0xf << PORT_STATE_PHY8_PORT_NUM_OFF) | |
29 | #define PORT_STATE_PHY8_CONN_RATE_OFF 20 | |
30 | #define PORT_STATE_PHY8_CONN_RATE_MSK (0xf << PORT_STATE_PHY8_CONN_RATE_OFF) | |
31 | #define PHY_CONN_RATE 0x30 | |
32 | #define HGC_TRANS_TASK_CNT_LIMIT 0x38 | |
33 | #define AXI_AHB_CLK_CFG 0x3c | |
34 | #define ITCT_CLR 0x44 | |
35 | #define ITCT_CLR_EN_OFF 16 | |
36 | #define ITCT_CLR_EN_MSK (0x1 << ITCT_CLR_EN_OFF) | |
37 | #define ITCT_DEV_OFF 0 | |
38 | #define ITCT_DEV_MSK (0x7ff << ITCT_DEV_OFF) | |
39 | #define AXI_USER1 0x48 | |
40 | #define AXI_USER2 0x4c | |
41 | #define IO_SATA_BROKEN_MSG_ADDR_LO 0x58 | |
42 | #define IO_SATA_BROKEN_MSG_ADDR_HI 0x5c | |
43 | #define SATA_INITI_D2H_STORE_ADDR_LO 0x60 | |
44 | #define SATA_INITI_D2H_STORE_ADDR_HI 0x64 | |
45 | #define HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL 0x84 | |
46 | #define HGC_SAS_TXFAIL_RETRY_CTRL 0x88 | |
47 | #define HGC_GET_ITV_TIME 0x90 | |
48 | #define DEVICE_MSG_WORK_MODE 0x94 | |
49 | #define OPENA_WT_CONTI_TIME 0x9c | |
50 | #define I_T_NEXUS_LOSS_TIME 0xa0 | |
51 | #define MAX_CON_TIME_LIMIT_TIME 0xa4 | |
52 | #define BUS_INACTIVE_LIMIT_TIME 0xa8 | |
53 | #define REJECT_TO_OPEN_LIMIT_TIME 0xac | |
54 | #define CFG_AGING_TIME 0xbc | |
55 | #define HGC_DFX_CFG2 0xc0 | |
56 | #define HGC_IOMB_PROC1_STATUS 0x104 | |
57 | #define CFG_1US_TIMER_TRSH 0xcc | |
d3b688d3 XC |
58 | #define HGC_LM_DFX_STATUS2 0x128 |
59 | #define HGC_LM_DFX_STATUS2_IOSTLIST_OFF 0 | |
60 | #define HGC_LM_DFX_STATUS2_IOSTLIST_MSK (0xfff << \ | |
61 | HGC_LM_DFX_STATUS2_IOSTLIST_OFF) | |
62 | #define HGC_LM_DFX_STATUS2_ITCTLIST_OFF 12 | |
63 | #define HGC_LM_DFX_STATUS2_ITCTLIST_MSK (0x7ff << \ | |
64 | HGC_LM_DFX_STATUS2_ITCTLIST_OFF) | |
65 | #define HGC_CQE_ECC_ADDR 0x13c | |
66 | #define HGC_CQE_ECC_1B_ADDR_OFF 0 | |
ce41b41e | 67 | #define HGC_CQE_ECC_1B_ADDR_MSK (0x3f << HGC_CQE_ECC_1B_ADDR_OFF) |
d3b688d3 | 68 | #define HGC_CQE_ECC_MB_ADDR_OFF 8 |
ce41b41e | 69 | #define HGC_CQE_ECC_MB_ADDR_MSK (0x3f << HGC_CQE_ECC_MB_ADDR_OFF) |
d3b688d3 XC |
70 | #define HGC_IOST_ECC_ADDR 0x140 |
71 | #define HGC_IOST_ECC_1B_ADDR_OFF 0 | |
ce41b41e | 72 | #define HGC_IOST_ECC_1B_ADDR_MSK (0x3ff << HGC_IOST_ECC_1B_ADDR_OFF) |
d3b688d3 | 73 | #define HGC_IOST_ECC_MB_ADDR_OFF 16 |
ce41b41e | 74 | #define HGC_IOST_ECC_MB_ADDR_MSK (0x3ff << HGC_IOST_ECC_MB_ADDR_OFF) |
d3b688d3 XC |
75 | #define HGC_DQE_ECC_ADDR 0x144 |
76 | #define HGC_DQE_ECC_1B_ADDR_OFF 0 | |
ce41b41e | 77 | #define HGC_DQE_ECC_1B_ADDR_MSK (0xfff << HGC_DQE_ECC_1B_ADDR_OFF) |
d3b688d3 | 78 | #define HGC_DQE_ECC_MB_ADDR_OFF 16 |
ce41b41e | 79 | #define HGC_DQE_ECC_MB_ADDR_MSK (0xfff << HGC_DQE_ECC_MB_ADDR_OFF) |
45c901b8 JG |
80 | #define HGC_INVLD_DQE_INFO 0x148 |
81 | #define HGC_INVLD_DQE_INFO_FB_CH0_OFF 9 | |
82 | #define HGC_INVLD_DQE_INFO_FB_CH0_MSK (0x1 << HGC_INVLD_DQE_INFO_FB_CH0_OFF) | |
83 | #define HGC_INVLD_DQE_INFO_FB_CH3_OFF 18 | |
d3b688d3 XC |
84 | #define HGC_ITCT_ECC_ADDR 0x150 |
85 | #define HGC_ITCT_ECC_1B_ADDR_OFF 0 | |
86 | #define HGC_ITCT_ECC_1B_ADDR_MSK (0x3ff << \ | |
87 | HGC_ITCT_ECC_1B_ADDR_OFF) | |
88 | #define HGC_ITCT_ECC_MB_ADDR_OFF 16 | |
89 | #define HGC_ITCT_ECC_MB_ADDR_MSK (0x3ff << \ | |
90 | HGC_ITCT_ECC_MB_ADDR_OFF) | |
91 | #define HGC_AXI_FIFO_ERR_INFO 0x154 | |
92 | #define AXI_ERR_INFO_OFF 0 | |
93 | #define AXI_ERR_INFO_MSK (0xff << AXI_ERR_INFO_OFF) | |
94 | #define FIFO_ERR_INFO_OFF 8 | |
95 | #define FIFO_ERR_INFO_MSK (0xff << FIFO_ERR_INFO_OFF) | |
45c901b8 JG |
96 | #define INT_COAL_EN 0x19c |
97 | #define OQ_INT_COAL_TIME 0x1a0 | |
98 | #define OQ_INT_COAL_CNT 0x1a4 | |
99 | #define ENT_INT_COAL_TIME 0x1a8 | |
100 | #define ENT_INT_COAL_CNT 0x1ac | |
101 | #define OQ_INT_SRC 0x1b0 | |
102 | #define OQ_INT_SRC_MSK 0x1b4 | |
103 | #define ENT_INT_SRC1 0x1b8 | |
104 | #define ENT_INT_SRC1_D2H_FIS_CH0_OFF 0 | |
105 | #define ENT_INT_SRC1_D2H_FIS_CH0_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH0_OFF) | |
106 | #define ENT_INT_SRC1_D2H_FIS_CH1_OFF 8 | |
107 | #define ENT_INT_SRC1_D2H_FIS_CH1_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH1_OFF) | |
108 | #define ENT_INT_SRC2 0x1bc | |
109 | #define ENT_INT_SRC3 0x1c0 | |
d3b688d3 XC |
110 | #define ENT_INT_SRC3_WP_DEPTH_OFF 8 |
111 | #define ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF 9 | |
112 | #define ENT_INT_SRC3_RP_DEPTH_OFF 10 | |
113 | #define ENT_INT_SRC3_AXI_OFF 11 | |
114 | #define ENT_INT_SRC3_FIFO_OFF 12 | |
115 | #define ENT_INT_SRC3_LM_OFF 14 | |
45c901b8 JG |
116 | #define ENT_INT_SRC3_ITC_INT_OFF 15 |
117 | #define ENT_INT_SRC3_ITC_INT_MSK (0x1 << ENT_INT_SRC3_ITC_INT_OFF) | |
d3b688d3 | 118 | #define ENT_INT_SRC3_ABT_OFF 16 |
45c901b8 JG |
119 | #define ENT_INT_SRC_MSK1 0x1c4 |
120 | #define ENT_INT_SRC_MSK2 0x1c8 | |
121 | #define ENT_INT_SRC_MSK3 0x1cc | |
122 | #define ENT_INT_SRC_MSK3_ENT95_MSK_OFF 31 | |
123 | #define ENT_INT_SRC_MSK3_ENT95_MSK_MSK (0x1 << ENT_INT_SRC_MSK3_ENT95_MSK_OFF) | |
d3b688d3 XC |
124 | #define SAS_ECC_INTR 0x1e8 |
125 | #define SAS_ECC_INTR_DQE_ECC_1B_OFF 0 | |
126 | #define SAS_ECC_INTR_DQE_ECC_MB_OFF 1 | |
127 | #define SAS_ECC_INTR_IOST_ECC_1B_OFF 2 | |
128 | #define SAS_ECC_INTR_IOST_ECC_MB_OFF 3 | |
129 | #define SAS_ECC_INTR_ITCT_ECC_MB_OFF 4 | |
130 | #define SAS_ECC_INTR_ITCT_ECC_1B_OFF 5 | |
131 | #define SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF 6 | |
132 | #define SAS_ECC_INTR_IOSTLIST_ECC_1B_OFF 7 | |
133 | #define SAS_ECC_INTR_ITCTLIST_ECC_1B_OFF 8 | |
134 | #define SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF 9 | |
135 | #define SAS_ECC_INTR_CQE_ECC_1B_OFF 10 | |
136 | #define SAS_ECC_INTR_CQE_ECC_MB_OFF 11 | |
137 | #define SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF 12 | |
138 | #define SAS_ECC_INTR_NCQ_MEM0_ECC_1B_OFF 13 | |
139 | #define SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF 14 | |
140 | #define SAS_ECC_INTR_NCQ_MEM1_ECC_1B_OFF 15 | |
141 | #define SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF 16 | |
142 | #define SAS_ECC_INTR_NCQ_MEM2_ECC_1B_OFF 17 | |
143 | #define SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF 18 | |
144 | #define SAS_ECC_INTR_NCQ_MEM3_ECC_1B_OFF 19 | |
45c901b8 JG |
145 | #define SAS_ECC_INTR_MSK 0x1ec |
146 | #define HGC_ERR_STAT_EN 0x238 | |
147 | #define DLVRY_Q_0_BASE_ADDR_LO 0x260 | |
148 | #define DLVRY_Q_0_BASE_ADDR_HI 0x264 | |
149 | #define DLVRY_Q_0_DEPTH 0x268 | |
150 | #define DLVRY_Q_0_WR_PTR 0x26c | |
151 | #define DLVRY_Q_0_RD_PTR 0x270 | |
152 | #define HYPER_STREAM_ID_EN_CFG 0xc80 | |
153 | #define OQ0_INT_SRC_MSK 0xc90 | |
154 | #define COMPL_Q_0_BASE_ADDR_LO 0x4e0 | |
155 | #define COMPL_Q_0_BASE_ADDR_HI 0x4e4 | |
156 | #define COMPL_Q_0_DEPTH 0x4e8 | |
157 | #define COMPL_Q_0_WR_PTR 0x4ec | |
158 | #define COMPL_Q_0_RD_PTR 0x4f0 | |
d3b688d3 XC |
159 | #define HGC_RXM_DFX_STATUS14 0xae8 |
160 | #define HGC_RXM_DFX_STATUS14_MEM0_OFF 0 | |
161 | #define HGC_RXM_DFX_STATUS14_MEM0_MSK (0x1ff << \ | |
162 | HGC_RXM_DFX_STATUS14_MEM0_OFF) | |
163 | #define HGC_RXM_DFX_STATUS14_MEM1_OFF 9 | |
164 | #define HGC_RXM_DFX_STATUS14_MEM1_MSK (0x1ff << \ | |
165 | HGC_RXM_DFX_STATUS14_MEM1_OFF) | |
166 | #define HGC_RXM_DFX_STATUS14_MEM2_OFF 18 | |
167 | #define HGC_RXM_DFX_STATUS14_MEM2_MSK (0x1ff << \ | |
168 | HGC_RXM_DFX_STATUS14_MEM2_OFF) | |
169 | #define HGC_RXM_DFX_STATUS15 0xaec | |
170 | #define HGC_RXM_DFX_STATUS15_MEM3_OFF 0 | |
171 | #define HGC_RXM_DFX_STATUS15_MEM3_MSK (0x1ff << \ | |
172 | HGC_RXM_DFX_STATUS15_MEM3_OFF) | |
45c901b8 JG |
173 | /* phy registers need init */ |
174 | #define PORT_BASE (0x2000) | |
175 | ||
176 | #define PHY_CFG (PORT_BASE + 0x0) | |
177 | #define HARD_PHY_LINKRATE (PORT_BASE + 0x4) | |
178 | #define PHY_CFG_ENA_OFF 0 | |
179 | #define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF) | |
180 | #define PHY_CFG_DC_OPT_OFF 2 | |
181 | #define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF) | |
182 | #define PROG_PHY_LINK_RATE (PORT_BASE + 0x8) | |
183 | #define PROG_PHY_LINK_RATE_MAX_OFF 0 | |
184 | #define PROG_PHY_LINK_RATE_MAX_MSK (0xff << PROG_PHY_LINK_RATE_MAX_OFF) | |
185 | #define PHY_CTRL (PORT_BASE + 0x14) | |
186 | #define PHY_CTRL_RESET_OFF 0 | |
187 | #define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF) | |
188 | #define SAS_PHY_CTRL (PORT_BASE + 0x20) | |
189 | #define SL_CFG (PORT_BASE + 0x84) | |
190 | #define PHY_PCN (PORT_BASE + 0x44) | |
191 | #define SL_TOUT_CFG (PORT_BASE + 0x8c) | |
192 | #define SL_CONTROL (PORT_BASE + 0x94) | |
193 | #define SL_CONTROL_NOTIFY_EN_OFF 0 | |
194 | #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF) | |
9c81e2cf JG |
195 | #define SL_CONTROL_CTA_OFF 17 |
196 | #define SL_CONTROL_CTA_MSK (0x1 << SL_CONTROL_CTA_OFF) | |
0844a3ff JG |
197 | #define RX_PRIMS_STATUS (PORT_BASE + 0x98) |
198 | #define RX_BCAST_CHG_OFF 1 | |
199 | #define RX_BCAST_CHG_MSK (0x1 << RX_BCAST_CHG_OFF) | |
45c901b8 JG |
200 | #define TX_ID_DWORD0 (PORT_BASE + 0x9c) |
201 | #define TX_ID_DWORD1 (PORT_BASE + 0xa0) | |
202 | #define TX_ID_DWORD2 (PORT_BASE + 0xa4) | |
203 | #define TX_ID_DWORD3 (PORT_BASE + 0xa8) | |
204 | #define TX_ID_DWORD4 (PORT_BASE + 0xaC) | |
205 | #define TX_ID_DWORD5 (PORT_BASE + 0xb0) | |
206 | #define TX_ID_DWORD6 (PORT_BASE + 0xb4) | |
9c81e2cf JG |
207 | #define TXID_AUTO (PORT_BASE + 0xb8) |
208 | #define TXID_AUTO_CT3_OFF 1 | |
209 | #define TXID_AUTO_CT3_MSK (0x1 << TXID_AUTO_CT3_OFF) | |
819cbf18 XT |
210 | #define TXID_AUTO_CTB_OFF 11 |
211 | #define TXID_AUTO_CTB_MSK (0x1 << TXID_AUTO_CTB_OFF) | |
0844a3ff JG |
212 | #define TX_HARDRST_OFF 2 |
213 | #define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF) | |
45c901b8 JG |
214 | #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4) |
215 | #define RX_IDAF_DWORD1 (PORT_BASE + 0xc8) | |
216 | #define RX_IDAF_DWORD2 (PORT_BASE + 0xcc) | |
217 | #define RX_IDAF_DWORD3 (PORT_BASE + 0xd0) | |
218 | #define RX_IDAF_DWORD4 (PORT_BASE + 0xd4) | |
219 | #define RX_IDAF_DWORD5 (PORT_BASE + 0xd8) | |
220 | #define RX_IDAF_DWORD6 (PORT_BASE + 0xdc) | |
221 | #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc) | |
f2f89c32 | 222 | #define CON_CONTROL (PORT_BASE + 0x118) |
c7b9d369 XT |
223 | #define CON_CONTROL_CFG_OPEN_ACC_STP_OFF 0 |
224 | #define CON_CONTROL_CFG_OPEN_ACC_STP_MSK \ | |
225 | (0x01 << CON_CONTROL_CFG_OPEN_ACC_STP_OFF) | |
45c901b8 JG |
226 | #define DONE_RECEIVED_TIME (PORT_BASE + 0x11c) |
227 | #define CHL_INT0 (PORT_BASE + 0x1b4) | |
228 | #define CHL_INT0_HOTPLUG_TOUT_OFF 0 | |
229 | #define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF) | |
230 | #define CHL_INT0_SL_RX_BCST_ACK_OFF 1 | |
231 | #define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF) | |
232 | #define CHL_INT0_SL_PHY_ENABLE_OFF 2 | |
233 | #define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF) | |
234 | #define CHL_INT0_NOT_RDY_OFF 4 | |
235 | #define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF) | |
236 | #define CHL_INT0_PHY_RDY_OFF 5 | |
237 | #define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF) | |
238 | #define CHL_INT1 (PORT_BASE + 0x1b8) | |
239 | #define CHL_INT1_DMAC_TX_ECC_ERR_OFF 15 | |
240 | #define CHL_INT1_DMAC_TX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_TX_ECC_ERR_OFF) | |
241 | #define CHL_INT1_DMAC_RX_ECC_ERR_OFF 17 | |
242 | #define CHL_INT1_DMAC_RX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_RX_ECC_ERR_OFF) | |
243 | #define CHL_INT2 (PORT_BASE + 0x1bc) | |
244 | #define CHL_INT0_MSK (PORT_BASE + 0x1c0) | |
245 | #define CHL_INT1_MSK (PORT_BASE + 0x1c4) | |
246 | #define CHL_INT2_MSK (PORT_BASE + 0x1c8) | |
247 | #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0) | |
0844a3ff JG |
248 | #define DMA_TX_DFX0 (PORT_BASE + 0x200) |
249 | #define DMA_TX_DFX1 (PORT_BASE + 0x204) | |
c7b9d369 XT |
250 | #define DMA_TX_DFX1_IPTT_OFF 0 |
251 | #define DMA_TX_DFX1_IPTT_MSK (0xffff << DMA_TX_DFX1_IPTT_OFF) | |
819cbf18 | 252 | #define DMA_TX_FIFO_DFX0 (PORT_BASE + 0x240) |
0844a3ff JG |
253 | #define PORT_DFX0 (PORT_BASE + 0x258) |
254 | #define LINK_DFX2 (PORT_BASE + 0X264) | |
819cbf18 XT |
255 | #define LINK_DFX2_RCVR_HOLD_STS_OFF 9 |
256 | #define LINK_DFX2_RCVR_HOLD_STS_MSK (0x1 << LINK_DFX2_RCVR_HOLD_STS_OFF) | |
257 | #define LINK_DFX2_SEND_HOLD_STS_OFF 10 | |
258 | #define LINK_DFX2_SEND_HOLD_STS_MSK (0x1 << LINK_DFX2_SEND_HOLD_STS_OFF) | |
c52108c6 XT |
259 | #define SAS_ERR_CNT4_REG (PORT_BASE + 0x290) |
260 | #define SAS_ERR_CNT6_REG (PORT_BASE + 0x298) | |
45c901b8 JG |
261 | #define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0) |
262 | #define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4) | |
263 | #define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8) | |
264 | #define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc) | |
265 | #define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0) | |
266 | #define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4) | |
267 | #define DMA_TX_STATUS (PORT_BASE + 0x2d0) | |
268 | #define DMA_TX_STATUS_BUSY_OFF 0 | |
269 | #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF) | |
270 | #define DMA_RX_STATUS (PORT_BASE + 0x2e8) | |
271 | #define DMA_RX_STATUS_BUSY_OFF 0 | |
272 | #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF) | |
273 | ||
274 | #define AXI_CFG (0x5100) | |
275 | #define AM_CFG_MAX_TRANS (0x5010) | |
276 | #define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014) | |
277 | ||
06ec0fb9 XC |
278 | #define AXI_MASTER_CFG_BASE (0x5000) |
279 | #define AM_CTRL_GLOBAL (0x0) | |
280 | #define AM_CURR_TRANS_RETURN (0x150) | |
281 | ||
45c901b8 JG |
282 | /* HW dma structures */ |
283 | /* Delivery queue header */ | |
284 | /* dw0 */ | |
a3e665d9 JG |
285 | #define CMD_HDR_ABORT_FLAG_OFF 0 |
286 | #define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF) | |
287 | #define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2 | |
288 | #define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF) | |
45c901b8 JG |
289 | #define CMD_HDR_RESP_REPORT_OFF 5 |
290 | #define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF) | |
291 | #define CMD_HDR_TLR_CTRL_OFF 6 | |
292 | #define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF) | |
293 | #define CMD_HDR_PORT_OFF 18 | |
294 | #define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF) | |
295 | #define CMD_HDR_PRIORITY_OFF 27 | |
296 | #define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF) | |
297 | #define CMD_HDR_CMD_OFF 29 | |
298 | #define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF) | |
299 | /* dw1 */ | |
300 | #define CMD_HDR_DIR_OFF 5 | |
301 | #define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF) | |
302 | #define CMD_HDR_RESET_OFF 7 | |
303 | #define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF) | |
304 | #define CMD_HDR_VDTL_OFF 10 | |
305 | #define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF) | |
306 | #define CMD_HDR_FRAME_TYPE_OFF 11 | |
307 | #define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF) | |
308 | #define CMD_HDR_DEV_ID_OFF 16 | |
309 | #define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF) | |
310 | /* dw2 */ | |
311 | #define CMD_HDR_CFL_OFF 0 | |
312 | #define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF) | |
313 | #define CMD_HDR_NCQ_TAG_OFF 10 | |
314 | #define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF) | |
315 | #define CMD_HDR_MRFL_OFF 15 | |
316 | #define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF) | |
317 | #define CMD_HDR_SG_MOD_OFF 24 | |
318 | #define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF) | |
319 | #define CMD_HDR_FIRST_BURST_OFF 26 | |
320 | #define CMD_HDR_FIRST_BURST_MSK (0x1 << CMD_HDR_SG_MOD_OFF) | |
321 | /* dw3 */ | |
322 | #define CMD_HDR_IPTT_OFF 0 | |
323 | #define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF) | |
324 | /* dw6 */ | |
325 | #define CMD_HDR_DIF_SGL_LEN_OFF 0 | |
326 | #define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF) | |
327 | #define CMD_HDR_DATA_SGL_LEN_OFF 16 | |
328 | #define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF) | |
a3e665d9 JG |
329 | #define CMD_HDR_ABORT_IPTT_OFF 16 |
330 | #define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF) | |
45c901b8 JG |
331 | |
332 | /* Completion header */ | |
333 | /* dw0 */ | |
634a9585 XC |
334 | #define CMPLT_HDR_ERR_PHASE_OFF 2 |
335 | #define CMPLT_HDR_ERR_PHASE_MSK (0xff << CMPLT_HDR_ERR_PHASE_OFF) | |
45c901b8 JG |
336 | #define CMPLT_HDR_RSPNS_XFRD_OFF 10 |
337 | #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF) | |
338 | #define CMPLT_HDR_ERX_OFF 12 | |
339 | #define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF) | |
df032d0e JG |
340 | #define CMPLT_HDR_ABORT_STAT_OFF 13 |
341 | #define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF) | |
342 | /* abort_stat */ | |
343 | #define STAT_IO_NOT_VALID 0x1 | |
344 | #define STAT_IO_NO_DEVICE 0x2 | |
345 | #define STAT_IO_COMPLETE 0x3 | |
346 | #define STAT_IO_ABORTED 0x4 | |
45c901b8 JG |
347 | /* dw1 */ |
348 | #define CMPLT_HDR_IPTT_OFF 0 | |
349 | #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF) | |
350 | #define CMPLT_HDR_DEV_ID_OFF 16 | |
351 | #define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF) | |
352 | ||
353 | /* ITCT header */ | |
354 | /* qw0 */ | |
355 | #define ITCT_HDR_DEV_TYPE_OFF 0 | |
356 | #define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF) | |
357 | #define ITCT_HDR_VALID_OFF 2 | |
358 | #define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF) | |
359 | #define ITCT_HDR_MCR_OFF 5 | |
360 | #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF) | |
361 | #define ITCT_HDR_VLN_OFF 9 | |
362 | #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF) | |
c399acfb XC |
363 | #define ITCT_HDR_SMP_TIMEOUT_OFF 16 |
364 | #define ITCT_HDR_SMP_TIMEOUT_8US 1 | |
365 | #define ITCT_HDR_SMP_TIMEOUT (ITCT_HDR_SMP_TIMEOUT_8US * \ | |
366 | 250) /* 2ms */ | |
367 | #define ITCT_HDR_AWT_CONTINUE_OFF 25 | |
45c901b8 JG |
368 | #define ITCT_HDR_PORT_ID_OFF 28 |
369 | #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF) | |
370 | /* qw2 */ | |
371 | #define ITCT_HDR_INLT_OFF 0 | |
372 | #define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF) | |
373 | #define ITCT_HDR_BITLT_OFF 16 | |
374 | #define ITCT_HDR_BITLT_MSK (0xffffULL << ITCT_HDR_BITLT_OFF) | |
375 | #define ITCT_HDR_MCTLT_OFF 32 | |
376 | #define ITCT_HDR_MCTLT_MSK (0xffffULL << ITCT_HDR_MCTLT_OFF) | |
377 | #define ITCT_HDR_RTOLT_OFF 48 | |
378 | #define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF) | |
379 | ||
d3b688d3 XC |
380 | #define HISI_SAS_FATAL_INT_NR 2 |
381 | ||
94eac9e1 JG |
382 | struct hisi_sas_complete_v2_hdr { |
383 | __le32 dw0; | |
384 | __le32 dw1; | |
385 | __le32 act; | |
386 | __le32 dw3; | |
387 | }; | |
388 | ||
e8fed0e9 JG |
389 | struct hisi_sas_err_record_v2 { |
390 | /* dw0 */ | |
391 | __le32 trans_tx_fail_type; | |
392 | ||
393 | /* dw1 */ | |
394 | __le32 trans_rx_fail_type; | |
395 | ||
396 | /* dw2 */ | |
397 | __le16 dma_tx_err_type; | |
398 | __le16 sipc_rx_err_type; | |
399 | ||
400 | /* dw3 */ | |
401 | __le32 dma_rx_err_type; | |
402 | }; | |
403 | ||
2b383351 JG |
404 | static const struct hisi_sas_hw_error one_bit_ecc_errors[] = { |
405 | { | |
406 | .irq_msk = BIT(SAS_ECC_INTR_DQE_ECC_1B_OFF), | |
407 | .msk = HGC_DQE_ECC_1B_ADDR_MSK, | |
408 | .shift = HGC_DQE_ECC_1B_ADDR_OFF, | |
409 | .msg = "hgc_dqe_acc1b_intr found: \ | |
410 | Ram address is 0x%08X\n", | |
411 | .reg = HGC_DQE_ECC_ADDR, | |
412 | }, | |
413 | { | |
414 | .irq_msk = BIT(SAS_ECC_INTR_IOST_ECC_1B_OFF), | |
415 | .msk = HGC_IOST_ECC_1B_ADDR_MSK, | |
416 | .shift = HGC_IOST_ECC_1B_ADDR_OFF, | |
417 | .msg = "hgc_iost_acc1b_intr found: \ | |
418 | Ram address is 0x%08X\n", | |
419 | .reg = HGC_IOST_ECC_ADDR, | |
420 | }, | |
421 | { | |
422 | .irq_msk = BIT(SAS_ECC_INTR_ITCT_ECC_1B_OFF), | |
423 | .msk = HGC_ITCT_ECC_1B_ADDR_MSK, | |
424 | .shift = HGC_ITCT_ECC_1B_ADDR_OFF, | |
425 | .msg = "hgc_itct_acc1b_intr found: \ | |
426 | Ram address is 0x%08X\n", | |
427 | .reg = HGC_ITCT_ECC_ADDR, | |
428 | }, | |
429 | { | |
430 | .irq_msk = BIT(SAS_ECC_INTR_IOSTLIST_ECC_1B_OFF), | |
431 | .msk = HGC_LM_DFX_STATUS2_IOSTLIST_MSK, | |
432 | .shift = HGC_LM_DFX_STATUS2_IOSTLIST_OFF, | |
433 | .msg = "hgc_iostl_acc1b_intr found: \ | |
434 | memory address is 0x%08X\n", | |
435 | .reg = HGC_LM_DFX_STATUS2, | |
436 | }, | |
437 | { | |
438 | .irq_msk = BIT(SAS_ECC_INTR_ITCTLIST_ECC_1B_OFF), | |
439 | .msk = HGC_LM_DFX_STATUS2_ITCTLIST_MSK, | |
440 | .shift = HGC_LM_DFX_STATUS2_ITCTLIST_OFF, | |
441 | .msg = "hgc_itctl_acc1b_intr found: \ | |
442 | memory address is 0x%08X\n", | |
443 | .reg = HGC_LM_DFX_STATUS2, | |
444 | }, | |
445 | { | |
446 | .irq_msk = BIT(SAS_ECC_INTR_CQE_ECC_1B_OFF), | |
447 | .msk = HGC_CQE_ECC_1B_ADDR_MSK, | |
448 | .shift = HGC_CQE_ECC_1B_ADDR_OFF, | |
449 | .msg = "hgc_cqe_acc1b_intr found: \ | |
450 | Ram address is 0x%08X\n", | |
451 | .reg = HGC_CQE_ECC_ADDR, | |
452 | }, | |
453 | { | |
454 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_1B_OFF), | |
455 | .msk = HGC_RXM_DFX_STATUS14_MEM0_MSK, | |
456 | .shift = HGC_RXM_DFX_STATUS14_MEM0_OFF, | |
457 | .msg = "rxm_mem0_acc1b_intr found: \ | |
458 | memory address is 0x%08X\n", | |
459 | .reg = HGC_RXM_DFX_STATUS14, | |
460 | }, | |
461 | { | |
462 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_1B_OFF), | |
463 | .msk = HGC_RXM_DFX_STATUS14_MEM1_MSK, | |
464 | .shift = HGC_RXM_DFX_STATUS14_MEM1_OFF, | |
465 | .msg = "rxm_mem1_acc1b_intr found: \ | |
466 | memory address is 0x%08X\n", | |
467 | .reg = HGC_RXM_DFX_STATUS14, | |
468 | }, | |
469 | { | |
470 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_1B_OFF), | |
471 | .msk = HGC_RXM_DFX_STATUS14_MEM2_MSK, | |
472 | .shift = HGC_RXM_DFX_STATUS14_MEM2_OFF, | |
473 | .msg = "rxm_mem2_acc1b_intr found: \ | |
474 | memory address is 0x%08X\n", | |
475 | .reg = HGC_RXM_DFX_STATUS14, | |
476 | }, | |
477 | { | |
478 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_1B_OFF), | |
479 | .msk = HGC_RXM_DFX_STATUS15_MEM3_MSK, | |
480 | .shift = HGC_RXM_DFX_STATUS15_MEM3_OFF, | |
481 | .msg = "rxm_mem3_acc1b_intr found: \ | |
482 | memory address is 0x%08X\n", | |
483 | .reg = HGC_RXM_DFX_STATUS15, | |
484 | }, | |
485 | }; | |
486 | ||
487 | static const struct hisi_sas_hw_error multi_bit_ecc_errors[] = { | |
488 | { | |
489 | .irq_msk = BIT(SAS_ECC_INTR_DQE_ECC_MB_OFF), | |
490 | .msk = HGC_DQE_ECC_MB_ADDR_MSK, | |
491 | .shift = HGC_DQE_ECC_MB_ADDR_OFF, | |
492 | .msg = "hgc_dqe_accbad_intr (0x%x) found: \ | |
493 | Ram address is 0x%08X\n", | |
494 | .reg = HGC_DQE_ECC_ADDR, | |
495 | }, | |
496 | { | |
497 | .irq_msk = BIT(SAS_ECC_INTR_IOST_ECC_MB_OFF), | |
498 | .msk = HGC_IOST_ECC_MB_ADDR_MSK, | |
499 | .shift = HGC_IOST_ECC_MB_ADDR_OFF, | |
500 | .msg = "hgc_iost_accbad_intr (0x%x) found: \ | |
501 | Ram address is 0x%08X\n", | |
502 | .reg = HGC_IOST_ECC_ADDR, | |
503 | }, | |
504 | { | |
505 | .irq_msk = BIT(SAS_ECC_INTR_ITCT_ECC_MB_OFF), | |
506 | .msk = HGC_ITCT_ECC_MB_ADDR_MSK, | |
507 | .shift = HGC_ITCT_ECC_MB_ADDR_OFF, | |
508 | .msg = "hgc_itct_accbad_intr (0x%x) found: \ | |
509 | Ram address is 0x%08X\n", | |
510 | .reg = HGC_ITCT_ECC_ADDR, | |
511 | }, | |
512 | { | |
513 | .irq_msk = BIT(SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF), | |
514 | .msk = HGC_LM_DFX_STATUS2_IOSTLIST_MSK, | |
515 | .shift = HGC_LM_DFX_STATUS2_IOSTLIST_OFF, | |
516 | .msg = "hgc_iostl_accbad_intr (0x%x) found: \ | |
517 | memory address is 0x%08X\n", | |
518 | .reg = HGC_LM_DFX_STATUS2, | |
519 | }, | |
520 | { | |
521 | .irq_msk = BIT(SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF), | |
522 | .msk = HGC_LM_DFX_STATUS2_ITCTLIST_MSK, | |
523 | .shift = HGC_LM_DFX_STATUS2_ITCTLIST_OFF, | |
524 | .msg = "hgc_itctl_accbad_intr (0x%x) found: \ | |
525 | memory address is 0x%08X\n", | |
526 | .reg = HGC_LM_DFX_STATUS2, | |
527 | }, | |
528 | { | |
529 | .irq_msk = BIT(SAS_ECC_INTR_CQE_ECC_MB_OFF), | |
530 | .msk = HGC_CQE_ECC_MB_ADDR_MSK, | |
531 | .shift = HGC_CQE_ECC_MB_ADDR_OFF, | |
532 | .msg = "hgc_cqe_accbad_intr (0x%x) found: \ | |
533 | Ram address is 0x%08X\n", | |
534 | .reg = HGC_CQE_ECC_ADDR, | |
535 | }, | |
536 | { | |
537 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF), | |
538 | .msk = HGC_RXM_DFX_STATUS14_MEM0_MSK, | |
539 | .shift = HGC_RXM_DFX_STATUS14_MEM0_OFF, | |
540 | .msg = "rxm_mem0_accbad_intr (0x%x) found: \ | |
541 | memory address is 0x%08X\n", | |
542 | .reg = HGC_RXM_DFX_STATUS14, | |
543 | }, | |
544 | { | |
545 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF), | |
546 | .msk = HGC_RXM_DFX_STATUS14_MEM1_MSK, | |
547 | .shift = HGC_RXM_DFX_STATUS14_MEM1_OFF, | |
548 | .msg = "rxm_mem1_accbad_intr (0x%x) found: \ | |
549 | memory address is 0x%08X\n", | |
550 | .reg = HGC_RXM_DFX_STATUS14, | |
551 | }, | |
552 | { | |
553 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF), | |
554 | .msk = HGC_RXM_DFX_STATUS14_MEM2_MSK, | |
555 | .shift = HGC_RXM_DFX_STATUS14_MEM2_OFF, | |
556 | .msg = "rxm_mem2_accbad_intr (0x%x) found: \ | |
557 | memory address is 0x%08X\n", | |
558 | .reg = HGC_RXM_DFX_STATUS14, | |
559 | }, | |
560 | { | |
561 | .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF), | |
562 | .msk = HGC_RXM_DFX_STATUS15_MEM3_MSK, | |
563 | .shift = HGC_RXM_DFX_STATUS15_MEM3_OFF, | |
564 | .msg = "rxm_mem3_accbad_intr (0x%x) found: \ | |
565 | memory address is 0x%08X\n", | |
566 | .reg = HGC_RXM_DFX_STATUS15, | |
567 | }, | |
568 | }; | |
569 | ||
7911e66f JG |
570 | enum { |
571 | HISI_SAS_PHY_PHY_UPDOWN, | |
d3bf3d84 | 572 | HISI_SAS_PHY_CHNL_INT, |
7911e66f JG |
573 | HISI_SAS_PHY_INT_NR |
574 | }; | |
575 | ||
e8fed0e9 JG |
576 | enum { |
577 | TRANS_TX_FAIL_BASE = 0x0, /* dw0 */ | |
634a9585 XC |
578 | TRANS_RX_FAIL_BASE = 0x20, /* dw1 */ |
579 | DMA_TX_ERR_BASE = 0x40, /* dw2 bit 15-0 */ | |
580 | SIPC_RX_ERR_BASE = 0x50, /* dw2 bit 31-16*/ | |
581 | DMA_RX_ERR_BASE = 0x60, /* dw3 */ | |
e8fed0e9 JG |
582 | |
583 | /* trans tx*/ | |
584 | TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS = TRANS_TX_FAIL_BASE, /* 0x0 */ | |
585 | TRANS_TX_ERR_PHY_NOT_ENABLE, /* 0x1 */ | |
586 | TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION, /* 0x2 */ | |
587 | TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION, /* 0x3 */ | |
588 | TRANS_TX_OPEN_CNX_ERR_BY_OTHER, /* 0x4 */ | |
589 | RESERVED0, /* 0x5 */ | |
590 | TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT, /* 0x6 */ | |
591 | TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY, /* 0x7 */ | |
592 | TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED, /* 0x8 */ | |
593 | TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED, /* 0x9 */ | |
594 | TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION, /* 0xa */ | |
595 | TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD, /* 0xb */ | |
596 | TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER, /* 0xc */ | |
597 | TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED, /* 0xd */ | |
598 | TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT, /* 0xe */ | |
599 | TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION, /* 0xf */ | |
600 | TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED, /* 0x10 */ | |
601 | TRANS_TX_ERR_FRAME_TXED, /* 0x11 */ | |
602 | TRANS_TX_ERR_WITH_BREAK_TIMEOUT, /* 0x12 */ | |
603 | TRANS_TX_ERR_WITH_BREAK_REQUEST, /* 0x13 */ | |
604 | TRANS_TX_ERR_WITH_BREAK_RECEVIED, /* 0x14 */ | |
605 | TRANS_TX_ERR_WITH_CLOSE_TIMEOUT, /* 0x15 */ | |
606 | TRANS_TX_ERR_WITH_CLOSE_NORMAL, /* 0x16 for ssp*/ | |
607 | TRANS_TX_ERR_WITH_CLOSE_PHYDISALE, /* 0x17 */ | |
608 | TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT, /* 0x18 */ | |
609 | TRANS_TX_ERR_WITH_CLOSE_COMINIT, /* 0x19 */ | |
610 | TRANS_TX_ERR_WITH_NAK_RECEVIED, /* 0x1a for ssp*/ | |
611 | TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT, /* 0x1b for ssp*/ | |
612 | /*IO_TX_ERR_WITH_R_ERR_RECEVIED, [> 0x1b for sata/stp<] */ | |
613 | TRANS_TX_ERR_WITH_CREDIT_TIMEOUT, /* 0x1c for ssp */ | |
614 | /*IO_RX_ERR_WITH_SATA_DEVICE_LOST 0x1c for sata/stp */ | |
615 | TRANS_TX_ERR_WITH_IPTT_CONFLICT, /* 0x1d for ssp/smp */ | |
616 | TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS, /* 0x1e */ | |
617 | /*IO_TX_ERR_WITH_SYNC_RXD, [> 0x1e <] for sata/stp */ | |
618 | TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT, /* 0x1f for sata/stp */ | |
619 | ||
620 | /* trans rx */ | |
634a9585 XC |
621 | TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR = TRANS_RX_FAIL_BASE, /* 0x20 */ |
622 | TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR, /* 0x21 for sata/stp */ | |
623 | TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM, /* 0x22 for ssp/smp */ | |
624 | /*IO_ERR_WITH_RXFIS_8B10B_CODE_ERR, [> 0x22 <] for sata/stp */ | |
625 | TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR, /* 0x23 for sata/stp */ | |
626 | TRANS_RX_ERR_WITH_RXFIS_CRC_ERR, /* 0x24 for sata/stp */ | |
627 | TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN, /* 0x25 for smp */ | |
628 | /*IO_ERR_WITH_RXFIS_TX SYNCP, [> 0x25 <] for sata/stp */ | |
629 | TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP, /* 0x26 for sata/stp*/ | |
630 | TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN, /* 0x27 */ | |
631 | TRANS_RX_ERR_WITH_BREAK_TIMEOUT, /* 0x28 */ | |
632 | TRANS_RX_ERR_WITH_BREAK_REQUEST, /* 0x29 */ | |
633 | TRANS_RX_ERR_WITH_BREAK_RECEVIED, /* 0x2a */ | |
634 | RESERVED1, /* 0x2b */ | |
635 | TRANS_RX_ERR_WITH_CLOSE_NORMAL, /* 0x2c */ | |
636 | TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE, /* 0x2d */ | |
637 | TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT, /* 0x2e */ | |
638 | TRANS_RX_ERR_WITH_CLOSE_COMINIT, /* 0x2f */ | |
639 | TRANS_RX_ERR_WITH_DATA_LEN0, /* 0x30 for ssp/smp */ | |
640 | TRANS_RX_ERR_WITH_BAD_HASH, /* 0x31 for ssp */ | |
641 | /*IO_RX_ERR_WITH_FIS_TOO_SHORT, [> 0x31 <] for sata/stp */ | |
642 | TRANS_RX_XRDY_WLEN_ZERO_ERR, /* 0x32 for ssp*/ | |
643 | /*IO_RX_ERR_WITH_FIS_TOO_LONG, [> 0x32 <] for sata/stp */ | |
644 | TRANS_RX_SSP_FRM_LEN_ERR, /* 0x33 for ssp */ | |
645 | /*IO_RX_ERR_WITH_SATA_DEVICE_LOST, [> 0x33 <] for sata */ | |
646 | RESERVED2, /* 0x34 */ | |
647 | RESERVED3, /* 0x35 */ | |
648 | RESERVED4, /* 0x36 */ | |
649 | RESERVED5, /* 0x37 */ | |
650 | TRANS_RX_ERR_WITH_BAD_FRM_TYPE, /* 0x38 */ | |
651 | TRANS_RX_SMP_FRM_LEN_ERR, /* 0x39 */ | |
652 | TRANS_RX_SMP_RESP_TIMEOUT_ERR, /* 0x3a */ | |
653 | RESERVED6, /* 0x3b */ | |
654 | RESERVED7, /* 0x3c */ | |
655 | RESERVED8, /* 0x3d */ | |
656 | RESERVED9, /* 0x3e */ | |
657 | TRANS_RX_R_ERR, /* 0x3f */ | |
e8fed0e9 JG |
658 | |
659 | /* dma tx */ | |
634a9585 XC |
660 | DMA_TX_DIF_CRC_ERR = DMA_TX_ERR_BASE, /* 0x40 */ |
661 | DMA_TX_DIF_APP_ERR, /* 0x41 */ | |
662 | DMA_TX_DIF_RPP_ERR, /* 0x42 */ | |
663 | DMA_TX_DATA_SGL_OVERFLOW, /* 0x43 */ | |
664 | DMA_TX_DIF_SGL_OVERFLOW, /* 0x44 */ | |
665 | DMA_TX_UNEXP_XFER_ERR, /* 0x45 */ | |
666 | DMA_TX_UNEXP_RETRANS_ERR, /* 0x46 */ | |
667 | DMA_TX_XFER_LEN_OVERFLOW, /* 0x47 */ | |
668 | DMA_TX_XFER_OFFSET_ERR, /* 0x48 */ | |
669 | DMA_TX_RAM_ECC_ERR, /* 0x49 */ | |
670 | DMA_TX_DIF_LEN_ALIGN_ERR, /* 0x4a */ | |
671 | DMA_TX_MAX_ERR_CODE, | |
e8fed0e9 JG |
672 | |
673 | /* sipc rx */ | |
634a9585 XC |
674 | SIPC_RX_FIS_STATUS_ERR_BIT_VLD = SIPC_RX_ERR_BASE, /* 0x50 */ |
675 | SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR, /* 0x51 */ | |
676 | SIPC_RX_FIS_STATUS_BSY_BIT_ERR, /* 0x52 */ | |
677 | SIPC_RX_WRSETUP_LEN_ODD_ERR, /* 0x53 */ | |
678 | SIPC_RX_WRSETUP_LEN_ZERO_ERR, /* 0x54 */ | |
679 | SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR, /* 0x55 */ | |
680 | SIPC_RX_NCQ_WRSETUP_OFFSET_ERR, /* 0x56 */ | |
681 | SIPC_RX_NCQ_WRSETUP_AUTO_ACTIVE_ERR, /* 0x57 */ | |
682 | SIPC_RX_SATA_UNEXP_FIS_ERR, /* 0x58 */ | |
683 | SIPC_RX_WRSETUP_ESTATUS_ERR, /* 0x59 */ | |
684 | SIPC_RX_DATA_UNDERFLOW_ERR, /* 0x5a */ | |
685 | SIPC_RX_MAX_ERR_CODE, | |
e8fed0e9 JG |
686 | |
687 | /* dma rx */ | |
634a9585 XC |
688 | DMA_RX_DIF_CRC_ERR = DMA_RX_ERR_BASE, /* 0x60 */ |
689 | DMA_RX_DIF_APP_ERR, /* 0x61 */ | |
690 | DMA_RX_DIF_RPP_ERR, /* 0x62 */ | |
691 | DMA_RX_DATA_SGL_OVERFLOW, /* 0x63 */ | |
692 | DMA_RX_DIF_SGL_OVERFLOW, /* 0x64 */ | |
693 | DMA_RX_DATA_LEN_OVERFLOW, /* 0x65 */ | |
694 | DMA_RX_DATA_LEN_UNDERFLOW, /* 0x66 */ | |
695 | DMA_RX_DATA_OFFSET_ERR, /* 0x67 */ | |
696 | RESERVED10, /* 0x68 */ | |
697 | DMA_RX_SATA_FRAME_TYPE_ERR, /* 0x69 */ | |
698 | DMA_RX_RESP_BUF_OVERFLOW, /* 0x6a */ | |
699 | DMA_RX_UNEXP_RETRANS_RESP_ERR, /* 0x6b */ | |
700 | DMA_RX_UNEXP_NORM_RESP_ERR, /* 0x6c */ | |
701 | DMA_RX_UNEXP_RDFRAME_ERR, /* 0x6d */ | |
702 | DMA_RX_PIO_DATA_LEN_ERR, /* 0x6e */ | |
703 | DMA_RX_RDSETUP_STATUS_ERR, /* 0x6f */ | |
704 | DMA_RX_RDSETUP_STATUS_DRQ_ERR, /* 0x70 */ | |
705 | DMA_RX_RDSETUP_STATUS_BSY_ERR, /* 0x71 */ | |
706 | DMA_RX_RDSETUP_LEN_ODD_ERR, /* 0x72 */ | |
707 | DMA_RX_RDSETUP_LEN_ZERO_ERR, /* 0x73 */ | |
708 | DMA_RX_RDSETUP_LEN_OVER_ERR, /* 0x74 */ | |
709 | DMA_RX_RDSETUP_OFFSET_ERR, /* 0x75 */ | |
710 | DMA_RX_RDSETUP_ACTIVE_ERR, /* 0x76 */ | |
711 | DMA_RX_RDSETUP_ESTATUS_ERR, /* 0x77 */ | |
712 | DMA_RX_RAM_ECC_ERR, /* 0x78 */ | |
713 | DMA_RX_UNKNOWN_FRM_ERR, /* 0x79 */ | |
714 | DMA_RX_MAX_ERR_CODE, | |
e8fed0e9 JG |
715 | }; |
716 | ||
94eac9e1 | 717 | #define HISI_SAS_COMMAND_ENTRIES_V2_HW 4096 |
32ccba52 | 718 | #define HISI_MAX_SATA_SUPPORT_V2_HW (HISI_SAS_COMMAND_ENTRIES_V2_HW/64 - 1) |
94eac9e1 | 719 | |
8c36e31d JG |
720 | #define DIR_NO_DATA 0 |
721 | #define DIR_TO_INI 1 | |
722 | #define DIR_TO_DEVICE 2 | |
723 | #define DIR_RESERVED 3 | |
724 | ||
634a9585 XC |
725 | #define ERR_ON_TX_PHASE(err_phase) (err_phase == 0x2 || \ |
726 | err_phase == 0x4 || err_phase == 0x8 ||\ | |
727 | err_phase == 0x6 || err_phase == 0xa) | |
728 | #define ERR_ON_RX_PHASE(err_phase) (err_phase == 0x10 || \ | |
729 | err_phase == 0x20 || err_phase == 0x40) | |
730 | ||
4df642db | 731 | static void link_timeout_disable_link(unsigned long data); |
f2f89c32 | 732 | |
94eac9e1 JG |
733 | static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off) |
734 | { | |
735 | void __iomem *regs = hisi_hba->regs + off; | |
736 | ||
737 | return readl(regs); | |
738 | } | |
739 | ||
8c36e31d JG |
740 | static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off) |
741 | { | |
742 | void __iomem *regs = hisi_hba->regs + off; | |
743 | ||
744 | return readl_relaxed(regs); | |
745 | } | |
746 | ||
94eac9e1 JG |
747 | static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val) |
748 | { | |
749 | void __iomem *regs = hisi_hba->regs + off; | |
750 | ||
751 | writel(val, regs); | |
752 | } | |
753 | ||
754 | static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no, | |
755 | u32 off, u32 val) | |
756 | { | |
757 | void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off; | |
758 | ||
759 | writel(val, regs); | |
760 | } | |
761 | ||
762 | static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba, | |
763 | int phy_no, u32 off) | |
764 | { | |
765 | void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off; | |
766 | ||
767 | return readl(regs); | |
768 | } | |
769 | ||
330fa7f3 JG |
770 | /* This function needs to be protected from pre-emption. */ |
771 | static int | |
772 | slot_index_alloc_quirk_v2_hw(struct hisi_hba *hisi_hba, int *slot_idx, | |
32ccba52 | 773 | struct domain_device *device) |
330fa7f3 | 774 | { |
330fa7f3 | 775 | int sata_dev = dev_is_sata(device); |
32ccba52 XT |
776 | void *bitmap = hisi_hba->slot_index_tags; |
777 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
778 | int sata_idx = sas_dev->sata_idx; | |
779 | int start, end; | |
780 | ||
781 | if (!sata_dev) { | |
782 | /* | |
783 | * STP link SoC bug workaround: index starts from 1. | |
784 | * additionally, we can only allocate odd IPTT(1~4095) | |
785 | * for SAS/SMP device. | |
786 | */ | |
787 | start = 1; | |
788 | end = hisi_hba->slot_index_count; | |
789 | } else { | |
790 | if (sata_idx >= HISI_MAX_SATA_SUPPORT_V2_HW) | |
791 | return -EINVAL; | |
792 | ||
793 | /* | |
794 | * For SATA device: allocate even IPTT in this interval | |
795 | * [64*(sata_idx+1), 64*(sata_idx+2)], then each SATA device | |
796 | * own 32 IPTTs. IPTT 0 shall not be used duing to STP link | |
797 | * SoC bug workaround. So we ignore the first 32 even IPTTs. | |
798 | */ | |
799 | start = 64 * (sata_idx + 1); | |
800 | end = 64 * (sata_idx + 2); | |
801 | } | |
330fa7f3 JG |
802 | |
803 | while (1) { | |
32ccba52 XT |
804 | start = find_next_zero_bit(bitmap, |
805 | hisi_hba->slot_index_count, start); | |
806 | if (start >= end) | |
330fa7f3 JG |
807 | return -SAS_QUEUE_FULL; |
808 | /* | |
32ccba52 XT |
809 | * SAS IPTT bit0 should be 1, and SATA IPTT bit0 should be 0. |
810 | */ | |
811 | if (sata_dev ^ (start & 1)) | |
330fa7f3 | 812 | break; |
32ccba52 | 813 | start++; |
330fa7f3 JG |
814 | } |
815 | ||
32ccba52 XT |
816 | set_bit(start, bitmap); |
817 | *slot_idx = start; | |
330fa7f3 JG |
818 | return 0; |
819 | } | |
820 | ||
32ccba52 XT |
821 | static bool sata_index_alloc_v2_hw(struct hisi_hba *hisi_hba, int *idx) |
822 | { | |
823 | unsigned int index; | |
11b75249 | 824 | struct device *dev = hisi_hba->dev; |
32ccba52 XT |
825 | void *bitmap = hisi_hba->sata_dev_bitmap; |
826 | ||
827 | index = find_first_zero_bit(bitmap, HISI_MAX_SATA_SUPPORT_V2_HW); | |
828 | if (index >= HISI_MAX_SATA_SUPPORT_V2_HW) { | |
829 | dev_warn(dev, "alloc sata index failed, index=%d\n", index); | |
830 | return false; | |
831 | } | |
832 | ||
833 | set_bit(index, bitmap); | |
834 | *idx = index; | |
835 | return true; | |
836 | } | |
837 | ||
838 | ||
b2bdaf2b JG |
839 | static struct |
840 | hisi_sas_device *alloc_dev_quirk_v2_hw(struct domain_device *device) | |
841 | { | |
842 | struct hisi_hba *hisi_hba = device->port->ha->lldd_ha; | |
843 | struct hisi_sas_device *sas_dev = NULL; | |
844 | int i, sata_dev = dev_is_sata(device); | |
32ccba52 | 845 | int sata_idx = -1; |
b2bdaf2b JG |
846 | |
847 | spin_lock(&hisi_hba->lock); | |
32ccba52 XT |
848 | |
849 | if (sata_dev) | |
850 | if (!sata_index_alloc_v2_hw(hisi_hba, &sata_idx)) | |
851 | goto out; | |
852 | ||
b2bdaf2b JG |
853 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
854 | /* | |
855 | * SATA device id bit0 should be 0 | |
856 | */ | |
857 | if (sata_dev && (i & 1)) | |
858 | continue; | |
859 | if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { | |
b1a49412 XC |
860 | int queue = i % hisi_hba->queue_count; |
861 | struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; | |
862 | ||
b2bdaf2b JG |
863 | hisi_hba->devices[i].device_id = i; |
864 | sas_dev = &hisi_hba->devices[i]; | |
865 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; | |
866 | sas_dev->dev_type = device->dev_type; | |
867 | sas_dev->hisi_hba = hisi_hba; | |
868 | sas_dev->sas_device = device; | |
32ccba52 | 869 | sas_dev->sata_idx = sata_idx; |
b1a49412 | 870 | sas_dev->dq = dq; |
405314df | 871 | INIT_LIST_HEAD(&hisi_hba->devices[i].list); |
b2bdaf2b JG |
872 | break; |
873 | } | |
874 | } | |
32ccba52 XT |
875 | |
876 | out: | |
b2bdaf2b JG |
877 | spin_unlock(&hisi_hba->lock); |
878 | ||
879 | return sas_dev; | |
880 | } | |
881 | ||
29a20428 JG |
882 | static void config_phy_opt_mode_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
883 | { | |
884 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
885 | ||
886 | cfg &= ~PHY_CFG_DC_OPT_MSK; | |
887 | cfg |= 1 << PHY_CFG_DC_OPT_OFF; | |
888 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
889 | } | |
890 | ||
806bb768 JG |
891 | static void config_id_frame_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
892 | { | |
893 | struct sas_identify_frame identify_frame; | |
894 | u32 *identify_buffer; | |
895 | ||
896 | memset(&identify_frame, 0, sizeof(identify_frame)); | |
897 | identify_frame.dev_type = SAS_END_DEVICE; | |
898 | identify_frame.frame_type = 0; | |
899 | identify_frame._un1 = 1; | |
900 | identify_frame.initiator_bits = SAS_PROTOCOL_ALL; | |
901 | identify_frame.target_bits = SAS_PROTOCOL_NONE; | |
902 | memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE); | |
903 | memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE); | |
904 | identify_frame.phy_id = phy_no; | |
905 | identify_buffer = (u32 *)(&identify_frame); | |
906 | ||
907 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0, | |
908 | __swab32(identify_buffer[0])); | |
909 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1, | |
d82debec | 910 | __swab32(identify_buffer[1])); |
806bb768 | 911 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2, |
d82debec | 912 | __swab32(identify_buffer[2])); |
806bb768 | 913 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3, |
d82debec | 914 | __swab32(identify_buffer[3])); |
806bb768 | 915 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4, |
d82debec | 916 | __swab32(identify_buffer[4])); |
806bb768 JG |
917 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5, |
918 | __swab32(identify_buffer[5])); | |
919 | } | |
920 | ||
85b2c3c0 JG |
921 | static void setup_itct_v2_hw(struct hisi_hba *hisi_hba, |
922 | struct hisi_sas_device *sas_dev) | |
923 | { | |
924 | struct domain_device *device = sas_dev->sas_device; | |
11b75249 | 925 | struct device *dev = hisi_hba->dev; |
85b2c3c0 JG |
926 | u64 qw0, device_id = sas_dev->device_id; |
927 | struct hisi_sas_itct *itct = &hisi_hba->itct[device_id]; | |
928 | struct domain_device *parent_dev = device->parent; | |
2e244f0f JG |
929 | struct asd_sas_port *sas_port = device->port; |
930 | struct hisi_sas_port *port = to_hisi_sas_port(sas_port); | |
85b2c3c0 JG |
931 | |
932 | memset(itct, 0, sizeof(*itct)); | |
933 | ||
934 | /* qw0 */ | |
935 | qw0 = 0; | |
936 | switch (sas_dev->dev_type) { | |
937 | case SAS_END_DEVICE: | |
938 | case SAS_EDGE_EXPANDER_DEVICE: | |
939 | case SAS_FANOUT_EXPANDER_DEVICE: | |
940 | qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF; | |
941 | break; | |
942 | case SAS_SATA_DEV: | |
56cc74b9 | 943 | case SAS_SATA_PENDING: |
85b2c3c0 JG |
944 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) |
945 | qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF; | |
946 | else | |
947 | qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF; | |
948 | break; | |
949 | default: | |
950 | dev_warn(dev, "setup itct: unsupported dev type (%d)\n", | |
951 | sas_dev->dev_type); | |
952 | } | |
953 | ||
954 | qw0 |= ((1 << ITCT_HDR_VALID_OFF) | | |
75249268 | 955 | (device->linkrate << ITCT_HDR_MCR_OFF) | |
85b2c3c0 | 956 | (1 << ITCT_HDR_VLN_OFF) | |
c399acfb XC |
957 | (ITCT_HDR_SMP_TIMEOUT << ITCT_HDR_SMP_TIMEOUT_OFF) | |
958 | (1 << ITCT_HDR_AWT_CONTINUE_OFF) | | |
85b2c3c0 JG |
959 | (port->id << ITCT_HDR_PORT_ID_OFF)); |
960 | itct->qw0 = cpu_to_le64(qw0); | |
961 | ||
962 | /* qw1 */ | |
963 | memcpy(&itct->sas_addr, device->sas_addr, SAS_ADDR_SIZE); | |
964 | itct->sas_addr = __swab64(itct->sas_addr); | |
965 | ||
966 | /* qw2 */ | |
f76a0b49 | 967 | if (!dev_is_sata(device)) |
c399acfb | 968 | itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) | |
f76a0b49 JG |
969 | (0x1ULL << ITCT_HDR_BITLT_OFF) | |
970 | (0x32ULL << ITCT_HDR_MCTLT_OFF) | | |
971 | (0x1ULL << ITCT_HDR_RTOLT_OFF)); | |
85b2c3c0 JG |
972 | } |
973 | ||
974 | static void free_device_v2_hw(struct hisi_hba *hisi_hba, | |
975 | struct hisi_sas_device *sas_dev) | |
976 | { | |
640acc9a | 977 | DECLARE_COMPLETION_ONSTACK(completion); |
c399acfb | 978 | u64 dev_id = sas_dev->device_id; |
85b2c3c0 JG |
979 | struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id]; |
980 | u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
981 | int i; | |
982 | ||
640acc9a XC |
983 | sas_dev->completion = &completion; |
984 | ||
32ccba52 XT |
985 | /* SoC bug workaround */ |
986 | if (dev_is_sata(sas_dev->sas_device)) | |
987 | clear_bit(sas_dev->sata_idx, hisi_hba->sata_dev_bitmap); | |
988 | ||
85b2c3c0 JG |
989 | /* clear the itct interrupt state */ |
990 | if (ENT_INT_SRC3_ITC_INT_MSK & reg_val) | |
991 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
992 | ENT_INT_SRC3_ITC_INT_MSK); | |
993 | ||
85b2c3c0 | 994 | for (i = 0; i < 2; i++) { |
640acc9a | 995 | reg_val = ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK); |
85b2c3c0 | 996 | hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val); |
640acc9a | 997 | wait_for_completion(sas_dev->completion); |
85b2c3c0 | 998 | |
640acc9a | 999 | memset(itct, 0, sizeof(struct hisi_sas_itct)); |
85b2c3c0 JG |
1000 | } |
1001 | } | |
1002 | ||
94eac9e1 JG |
1003 | static int reset_hw_v2_hw(struct hisi_hba *hisi_hba) |
1004 | { | |
1005 | int i, reset_val; | |
1006 | u32 val; | |
1007 | unsigned long end_time; | |
11b75249 | 1008 | struct device *dev = hisi_hba->dev; |
94eac9e1 JG |
1009 | |
1010 | /* The mask needs to be set depending on the number of phys */ | |
1011 | if (hisi_hba->n_phy == 9) | |
1012 | reset_val = 0x1fffff; | |
1013 | else | |
1014 | reset_val = 0x7ffff; | |
1015 | ||
d0df8f9a | 1016 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0); |
94eac9e1 JG |
1017 | |
1018 | /* Disable all of the PHYs */ | |
1019 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
1020 | u32 phy_cfg = hisi_sas_phy_read32(hisi_hba, i, PHY_CFG); | |
1021 | ||
1022 | phy_cfg &= ~PHY_CTRL_RESET_MSK; | |
1023 | hisi_sas_phy_write32(hisi_hba, i, PHY_CFG, phy_cfg); | |
1024 | } | |
1025 | udelay(50); | |
1026 | ||
1027 | /* Ensure DMA tx & rx idle */ | |
1028 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
1029 | u32 dma_tx_status, dma_rx_status; | |
1030 | ||
1031 | end_time = jiffies + msecs_to_jiffies(1000); | |
1032 | ||
1033 | while (1) { | |
1034 | dma_tx_status = hisi_sas_phy_read32(hisi_hba, i, | |
1035 | DMA_TX_STATUS); | |
1036 | dma_rx_status = hisi_sas_phy_read32(hisi_hba, i, | |
1037 | DMA_RX_STATUS); | |
1038 | ||
1039 | if (!(dma_tx_status & DMA_TX_STATUS_BUSY_MSK) && | |
1040 | !(dma_rx_status & DMA_RX_STATUS_BUSY_MSK)) | |
1041 | break; | |
1042 | ||
1043 | msleep(20); | |
1044 | if (time_after(jiffies, end_time)) | |
1045 | return -EIO; | |
1046 | } | |
1047 | } | |
1048 | ||
1049 | /* Ensure axi bus idle */ | |
1050 | end_time = jiffies + msecs_to_jiffies(1000); | |
1051 | while (1) { | |
1052 | u32 axi_status = | |
1053 | hisi_sas_read32(hisi_hba, AXI_CFG); | |
1054 | ||
1055 | if (axi_status == 0) | |
1056 | break; | |
1057 | ||
1058 | msleep(20); | |
1059 | if (time_after(jiffies, end_time)) | |
1060 | return -EIO; | |
1061 | } | |
1062 | ||
50408712 JG |
1063 | if (ACPI_HANDLE(dev)) { |
1064 | acpi_status s; | |
94eac9e1 | 1065 | |
50408712 JG |
1066 | s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL); |
1067 | if (ACPI_FAILURE(s)) { | |
1068 | dev_err(dev, "Reset failed\n"); | |
1069 | return -EIO; | |
1070 | } | |
1071 | } else if (hisi_hba->ctrl) { | |
1072 | /* reset and disable clock*/ | |
1073 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg, | |
1074 | reset_val); | |
1075 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg + 4, | |
1076 | reset_val); | |
1077 | msleep(1); | |
1078 | regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val); | |
1079 | if (reset_val != (val & reset_val)) { | |
1080 | dev_err(dev, "SAS reset fail.\n"); | |
1081 | return -EIO; | |
1082 | } | |
1083 | ||
1084 | /* De-reset and enable clock*/ | |
1085 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg + 4, | |
1086 | reset_val); | |
1087 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg, | |
1088 | reset_val); | |
1089 | msleep(1); | |
1090 | regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, | |
1091 | &val); | |
1092 | if (val & reset_val) { | |
1093 | dev_err(dev, "SAS de-reset fail.\n"); | |
1094 | return -EIO; | |
1095 | } | |
1096 | } else | |
1097 | dev_warn(dev, "no reset method\n"); | |
94eac9e1 JG |
1098 | |
1099 | return 0; | |
1100 | } | |
1101 | ||
c7b9d369 XT |
1102 | /* This function needs to be called after resetting SAS controller. */ |
1103 | static void phys_reject_stp_links_v2_hw(struct hisi_hba *hisi_hba) | |
1104 | { | |
1105 | u32 cfg; | |
1106 | int phy_no; | |
1107 | ||
1108 | hisi_hba->reject_stp_links_msk = (1 << hisi_hba->n_phy) - 1; | |
1109 | for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { | |
1110 | cfg = hisi_sas_phy_read32(hisi_hba, phy_no, CON_CONTROL); | |
1111 | if (!(cfg & CON_CONTROL_CFG_OPEN_ACC_STP_MSK)) | |
1112 | continue; | |
1113 | ||
1114 | cfg &= ~CON_CONTROL_CFG_OPEN_ACC_STP_MSK; | |
1115 | hisi_sas_phy_write32(hisi_hba, phy_no, CON_CONTROL, cfg); | |
1116 | } | |
1117 | } | |
1118 | ||
1119 | static void phys_try_accept_stp_links_v2_hw(struct hisi_hba *hisi_hba) | |
1120 | { | |
1121 | int phy_no; | |
1122 | u32 dma_tx_dfx1; | |
1123 | ||
1124 | for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { | |
1125 | if (!(hisi_hba->reject_stp_links_msk & BIT(phy_no))) | |
1126 | continue; | |
1127 | ||
1128 | dma_tx_dfx1 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1129 | DMA_TX_DFX1); | |
1130 | if (dma_tx_dfx1 & DMA_TX_DFX1_IPTT_MSK) { | |
1131 | u32 cfg = hisi_sas_phy_read32(hisi_hba, | |
1132 | phy_no, CON_CONTROL); | |
1133 | ||
1134 | cfg |= CON_CONTROL_CFG_OPEN_ACC_STP_MSK; | |
1135 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
1136 | CON_CONTROL, cfg); | |
1137 | clear_bit(phy_no, &hisi_hba->reject_stp_links_msk); | |
1138 | } | |
1139 | } | |
1140 | } | |
1141 | ||
94eac9e1 JG |
1142 | static void init_reg_v2_hw(struct hisi_hba *hisi_hba) |
1143 | { | |
11b75249 | 1144 | struct device *dev = hisi_hba->dev; |
94eac9e1 JG |
1145 | int i; |
1146 | ||
1147 | /* Global registers init */ | |
1148 | ||
1149 | /* Deal with am-max-transmissions quirk */ | |
50408712 | 1150 | if (device_property_present(dev, "hip06-sas-v2-quirk-amt")) { |
94eac9e1 JG |
1151 | hisi_sas_write32(hisi_hba, AM_CFG_MAX_TRANS, 0x2020); |
1152 | hisi_sas_write32(hisi_hba, AM_CFG_SINGLE_PORT_MAX_TRANS, | |
1153 | 0x2020); | |
1154 | } /* Else, use defaults -> do nothing */ | |
1155 | ||
1156 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, | |
1157 | (u32)((1ULL << hisi_hba->queue_count) - 1)); | |
1158 | hisi_sas_write32(hisi_hba, AXI_USER1, 0xc0000000); | |
1159 | hisi_sas_write32(hisi_hba, AXI_USER2, 0x10000); | |
f1dc7518 | 1160 | hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x0); |
94eac9e1 JG |
1161 | hisi_sas_write32(hisi_hba, HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL, 0x7FF); |
1162 | hisi_sas_write32(hisi_hba, OPENA_WT_CONTI_TIME, 0x1); | |
1163 | hisi_sas_write32(hisi_hba, I_T_NEXUS_LOSS_TIME, 0x1F4); | |
f76a0b49 | 1164 | hisi_sas_write32(hisi_hba, MAX_CON_TIME_LIMIT_TIME, 0x32); |
94eac9e1 JG |
1165 | hisi_sas_write32(hisi_hba, BUS_INACTIVE_LIMIT_TIME, 0x1); |
1166 | hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1); | |
1167 | hisi_sas_write32(hisi_hba, HGC_ERR_STAT_EN, 0x1); | |
1168 | hisi_sas_write32(hisi_hba, HGC_GET_ITV_TIME, 0x1); | |
f1dc7518 JG |
1169 | hisi_sas_write32(hisi_hba, INT_COAL_EN, 0xc); |
1170 | hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x60); | |
1171 | hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x3); | |
94eac9e1 JG |
1172 | hisi_sas_write32(hisi_hba, ENT_INT_COAL_TIME, 0x1); |
1173 | hisi_sas_write32(hisi_hba, ENT_INT_COAL_CNT, 0x1); | |
1174 | hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0x0); | |
1175 | hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff); | |
1176 | hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff); | |
1177 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff); | |
1178 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0x7efefefe); | |
1179 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0x7efefefe); | |
640acc9a | 1180 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0x7ffe20fe); |
d3b688d3 | 1181 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xfff00c30); |
94eac9e1 JG |
1182 | for (i = 0; i < hisi_hba->queue_count; i++) |
1183 | hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0); | |
1184 | ||
1185 | hisi_sas_write32(hisi_hba, AXI_AHB_CLK_CFG, 1); | |
1186 | hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1); | |
1187 | ||
1188 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
1189 | hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x855); | |
1190 | hisi_sas_phy_write32(hisi_hba, i, SAS_PHY_CTRL, 0x30b9908); | |
1191 | hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d); | |
9c81e2cf JG |
1192 | hisi_sas_phy_write32(hisi_hba, i, SL_CONTROL, 0x0); |
1193 | hisi_sas_phy_write32(hisi_hba, i, TXID_AUTO, 0x2); | |
f1dc7518 | 1194 | hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0x8); |
94eac9e1 JG |
1195 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff); |
1196 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff); | |
d3b688d3 | 1197 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xfff87fff); |
94eac9e1 JG |
1198 | hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000); |
1199 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff); | |
1200 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8ffffbff); | |
f1dc7518 | 1201 | hisi_sas_phy_write32(hisi_hba, i, SL_CFG, 0x13f801fc); |
94eac9e1 JG |
1202 | hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0); |
1203 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0); | |
1204 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0); | |
1205 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0); | |
1206 | hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0); | |
1207 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT_COAL_EN, 0x0); | |
1208 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x0); | |
3bc45af8 JG |
1209 | if (hisi_hba->refclk_frequency_mhz == 66) |
1210 | hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, 0x199B694); | |
1211 | /* else, do nothing -> leave it how you found it */ | |
94eac9e1 JG |
1212 | } |
1213 | ||
1214 | for (i = 0; i < hisi_hba->queue_count; i++) { | |
1215 | /* Delivery queue */ | |
1216 | hisi_sas_write32(hisi_hba, | |
1217 | DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14), | |
1218 | upper_32_bits(hisi_hba->cmd_hdr_dma[i])); | |
1219 | ||
1220 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14), | |
1221 | lower_32_bits(hisi_hba->cmd_hdr_dma[i])); | |
1222 | ||
1223 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14), | |
1224 | HISI_SAS_QUEUE_SLOTS); | |
1225 | ||
1226 | /* Completion queue */ | |
1227 | hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14), | |
1228 | upper_32_bits(hisi_hba->complete_hdr_dma[i])); | |
1229 | ||
1230 | hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14), | |
1231 | lower_32_bits(hisi_hba->complete_hdr_dma[i])); | |
1232 | ||
1233 | hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14), | |
1234 | HISI_SAS_QUEUE_SLOTS); | |
1235 | } | |
1236 | ||
1237 | /* itct */ | |
1238 | hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO, | |
1239 | lower_32_bits(hisi_hba->itct_dma)); | |
1240 | ||
1241 | hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI, | |
1242 | upper_32_bits(hisi_hba->itct_dma)); | |
1243 | ||
1244 | /* iost */ | |
1245 | hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO, | |
1246 | lower_32_bits(hisi_hba->iost_dma)); | |
1247 | ||
1248 | hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI, | |
1249 | upper_32_bits(hisi_hba->iost_dma)); | |
1250 | ||
1251 | /* breakpoint */ | |
1252 | hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO, | |
1253 | lower_32_bits(hisi_hba->breakpoint_dma)); | |
1254 | ||
1255 | hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI, | |
1256 | upper_32_bits(hisi_hba->breakpoint_dma)); | |
1257 | ||
1258 | /* SATA broken msg */ | |
1259 | hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO, | |
1260 | lower_32_bits(hisi_hba->sata_breakpoint_dma)); | |
1261 | ||
1262 | hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI, | |
1263 | upper_32_bits(hisi_hba->sata_breakpoint_dma)); | |
1264 | ||
1265 | /* SATA initial fis */ | |
1266 | hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO, | |
1267 | lower_32_bits(hisi_hba->initial_fis_dma)); | |
1268 | ||
1269 | hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI, | |
1270 | upper_32_bits(hisi_hba->initial_fis_dma)); | |
1271 | } | |
1272 | ||
4df642db | 1273 | static void link_timeout_enable_link(unsigned long data) |
f2f89c32 XC |
1274 | { |
1275 | struct hisi_hba *hisi_hba = (struct hisi_hba *)data; | |
1276 | int i, reg_val; | |
1277 | ||
1278 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
c7b9d369 XT |
1279 | if (hisi_hba->reject_stp_links_msk & BIT(i)) |
1280 | continue; | |
1281 | ||
f2f89c32 XC |
1282 | reg_val = hisi_sas_phy_read32(hisi_hba, i, CON_CONTROL); |
1283 | if (!(reg_val & BIT(0))) { | |
1284 | hisi_sas_phy_write32(hisi_hba, i, | |
1285 | CON_CONTROL, 0x7); | |
1286 | break; | |
1287 | } | |
1288 | } | |
1289 | ||
4df642db | 1290 | hisi_hba->timer.function = link_timeout_disable_link; |
f2f89c32 XC |
1291 | mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(900)); |
1292 | } | |
1293 | ||
4df642db | 1294 | static void link_timeout_disable_link(unsigned long data) |
f2f89c32 XC |
1295 | { |
1296 | struct hisi_hba *hisi_hba = (struct hisi_hba *)data; | |
1297 | int i, reg_val; | |
1298 | ||
1299 | reg_val = hisi_sas_read32(hisi_hba, PHY_STATE); | |
1300 | for (i = 0; i < hisi_hba->n_phy && reg_val; i++) { | |
c7b9d369 XT |
1301 | if (hisi_hba->reject_stp_links_msk & BIT(i)) |
1302 | continue; | |
1303 | ||
f2f89c32 XC |
1304 | if (reg_val & BIT(i)) { |
1305 | hisi_sas_phy_write32(hisi_hba, i, | |
1306 | CON_CONTROL, 0x6); | |
1307 | break; | |
1308 | } | |
1309 | } | |
1310 | ||
4df642db | 1311 | hisi_hba->timer.function = link_timeout_enable_link; |
f2f89c32 XC |
1312 | mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(100)); |
1313 | } | |
1314 | ||
1315 | static void set_link_timer_quirk(struct hisi_hba *hisi_hba) | |
1316 | { | |
1317 | hisi_hba->timer.data = (unsigned long)hisi_hba; | |
4df642db | 1318 | hisi_hba->timer.function = link_timeout_disable_link; |
f2f89c32 XC |
1319 | hisi_hba->timer.expires = jiffies + msecs_to_jiffies(1000); |
1320 | add_timer(&hisi_hba->timer); | |
1321 | } | |
1322 | ||
94eac9e1 JG |
1323 | static int hw_init_v2_hw(struct hisi_hba *hisi_hba) |
1324 | { | |
11b75249 | 1325 | struct device *dev = hisi_hba->dev; |
94eac9e1 JG |
1326 | int rc; |
1327 | ||
1328 | rc = reset_hw_v2_hw(hisi_hba); | |
1329 | if (rc) { | |
1330 | dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc); | |
1331 | return rc; | |
1332 | } | |
1333 | ||
1334 | msleep(100); | |
1335 | init_reg_v2_hw(hisi_hba); | |
806bb768 | 1336 | |
94eac9e1 JG |
1337 | return 0; |
1338 | } | |
1339 | ||
29a20428 JG |
1340 | static void enable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1341 | { | |
1342 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
1343 | ||
1344 | cfg |= PHY_CFG_ENA_MSK; | |
1345 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
1346 | } | |
1347 | ||
4935933e XT |
1348 | static bool is_sata_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1349 | { | |
1350 | u32 context; | |
1351 | ||
1352 | context = hisi_sas_read32(hisi_hba, PHY_CONTEXT); | |
1353 | if (context & (1 << phy_no)) | |
1354 | return true; | |
1355 | ||
1356 | return false; | |
1357 | } | |
1358 | ||
819cbf18 XT |
1359 | static bool tx_fifo_is_empty_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1360 | { | |
1361 | u32 dfx_val; | |
1362 | ||
1363 | dfx_val = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX1); | |
1364 | ||
1365 | if (dfx_val & BIT(16)) | |
1366 | return false; | |
1367 | ||
1368 | return true; | |
1369 | } | |
1370 | ||
1371 | static bool axi_bus_is_idle_v2_hw(struct hisi_hba *hisi_hba, int phy_no) | |
1372 | { | |
1373 | int i, max_loop = 1000; | |
11b75249 | 1374 | struct device *dev = hisi_hba->dev; |
819cbf18 XT |
1375 | u32 status, axi_status, dfx_val, dfx_tx_val; |
1376 | ||
1377 | for (i = 0; i < max_loop; i++) { | |
1378 | status = hisi_sas_read32_relaxed(hisi_hba, | |
1379 | AXI_MASTER_CFG_BASE + AM_CURR_TRANS_RETURN); | |
1380 | ||
1381 | axi_status = hisi_sas_read32(hisi_hba, AXI_CFG); | |
1382 | dfx_val = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX1); | |
1383 | dfx_tx_val = hisi_sas_phy_read32(hisi_hba, | |
1384 | phy_no, DMA_TX_FIFO_DFX0); | |
1385 | ||
1386 | if ((status == 0x3) && (axi_status == 0x0) && | |
1387 | (dfx_val & BIT(20)) && (dfx_tx_val & BIT(10))) | |
1388 | return true; | |
1389 | udelay(10); | |
1390 | } | |
1391 | dev_err(dev, "bus is not idle phy%d, axi150:0x%x axi100:0x%x port204:0x%x port240:0x%x\n", | |
1392 | phy_no, status, axi_status, | |
1393 | dfx_val, dfx_tx_val); | |
1394 | return false; | |
1395 | } | |
1396 | ||
1397 | static bool wait_io_done_v2_hw(struct hisi_hba *hisi_hba, int phy_no) | |
1398 | { | |
1399 | int i, max_loop = 1000; | |
11b75249 | 1400 | struct device *dev = hisi_hba->dev; |
819cbf18 XT |
1401 | u32 status, tx_dfx0; |
1402 | ||
1403 | for (i = 0; i < max_loop; i++) { | |
1404 | status = hisi_sas_phy_read32(hisi_hba, phy_no, LINK_DFX2); | |
1405 | status = (status & 0x3fc0) >> 6; | |
1406 | ||
1407 | if (status != 0x1) | |
1408 | return true; | |
1409 | ||
1410 | tx_dfx0 = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX0); | |
1411 | if ((tx_dfx0 & 0x1ff) == 0x2) | |
1412 | return true; | |
1413 | udelay(10); | |
1414 | } | |
1415 | dev_err(dev, "IO not done phy%d, port264:0x%x port200:0x%x\n", | |
1416 | phy_no, status, tx_dfx0); | |
1417 | return false; | |
1418 | } | |
1419 | ||
1420 | static bool allowed_disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) | |
1421 | { | |
1422 | if (tx_fifo_is_empty_v2_hw(hisi_hba, phy_no)) | |
1423 | return true; | |
1424 | ||
1425 | if (!axi_bus_is_idle_v2_hw(hisi_hba, phy_no)) | |
1426 | return false; | |
1427 | ||
1428 | if (!wait_io_done_v2_hw(hisi_hba, phy_no)) | |
1429 | return false; | |
1430 | ||
1431 | return true; | |
1432 | } | |
1433 | ||
1434 | ||
63fb11b8 JG |
1435 | static void disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1436 | { | |
819cbf18 | 1437 | u32 cfg, axi_val, dfx0_val, txid_auto; |
11b75249 | 1438 | struct device *dev = hisi_hba->dev; |
819cbf18 XT |
1439 | |
1440 | /* Close axi bus. */ | |
1441 | axi_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE + | |
1442 | AM_CTRL_GLOBAL); | |
1443 | axi_val |= 0x1; | |
1444 | hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + | |
1445 | AM_CTRL_GLOBAL, axi_val); | |
1446 | ||
1447 | if (is_sata_phy_v2_hw(hisi_hba, phy_no)) { | |
1448 | if (allowed_disable_phy_v2_hw(hisi_hba, phy_no)) | |
1449 | goto do_disable; | |
63fb11b8 | 1450 | |
819cbf18 XT |
1451 | /* Reset host controller. */ |
1452 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
1453 | return; | |
1454 | } | |
1455 | ||
1456 | dfx0_val = hisi_sas_phy_read32(hisi_hba, phy_no, PORT_DFX0); | |
1457 | dfx0_val = (dfx0_val & 0x1fc0) >> 6; | |
1458 | if (dfx0_val != 0x4) | |
1459 | goto do_disable; | |
1460 | ||
1461 | if (!tx_fifo_is_empty_v2_hw(hisi_hba, phy_no)) { | |
1462 | dev_warn(dev, "phy%d, wait tx fifo need send break\n", | |
1463 | phy_no); | |
1464 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1465 | TXID_AUTO); | |
1466 | txid_auto |= TXID_AUTO_CTB_MSK; | |
1467 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
1468 | txid_auto); | |
1469 | } | |
1470 | ||
1471 | do_disable: | |
1472 | cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
63fb11b8 JG |
1473 | cfg &= ~PHY_CFG_ENA_MSK; |
1474 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
819cbf18 XT |
1475 | |
1476 | /* Open axi bus. */ | |
1477 | axi_val &= ~0x1; | |
1478 | hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + | |
1479 | AM_CTRL_GLOBAL, axi_val); | |
63fb11b8 JG |
1480 | } |
1481 | ||
29a20428 JG |
1482 | static void start_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1483 | { | |
1484 | config_id_frame_v2_hw(hisi_hba, phy_no); | |
1485 | config_phy_opt_mode_v2_hw(hisi_hba, phy_no); | |
1486 | enable_phy_v2_hw(hisi_hba, phy_no); | |
1487 | } | |
1488 | ||
63fb11b8 JG |
1489 | static void stop_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1490 | { | |
1491 | disable_phy_v2_hw(hisi_hba, phy_no); | |
1492 | } | |
1493 | ||
06ec0fb9 XC |
1494 | static void stop_phys_v2_hw(struct hisi_hba *hisi_hba) |
1495 | { | |
1496 | int i; | |
1497 | ||
1498 | for (i = 0; i < hisi_hba->n_phy; i++) | |
1499 | stop_phy_v2_hw(hisi_hba, i); | |
1500 | } | |
1501 | ||
63fb11b8 JG |
1502 | static void phy_hard_reset_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1503 | { | |
0edef7e4 XC |
1504 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
1505 | u32 txid_auto; | |
1506 | ||
63fb11b8 | 1507 | stop_phy_v2_hw(hisi_hba, phy_no); |
0edef7e4 XC |
1508 | if (phy->identify.device_type == SAS_END_DEVICE) { |
1509 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO); | |
1510 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
1511 | txid_auto | TX_HARDRST_MSK); | |
1512 | } | |
63fb11b8 JG |
1513 | msleep(100); |
1514 | start_phy_v2_hw(hisi_hba, phy_no); | |
1515 | } | |
1516 | ||
c52108c6 XT |
1517 | static void phy_get_events_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1518 | { | |
1519 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
1520 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1521 | struct sas_phy *sphy = sas_phy->phy; | |
1522 | u32 err4_reg_val, err6_reg_val; | |
1523 | ||
1524 | /* loss dword syn, phy reset problem */ | |
1525 | err4_reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_ERR_CNT4_REG); | |
1526 | ||
1527 | /* disparity err, invalid dword */ | |
1528 | err6_reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_ERR_CNT6_REG); | |
1529 | ||
1530 | sphy->loss_of_dword_sync_count += (err4_reg_val >> 16) & 0xFFFF; | |
1531 | sphy->phy_reset_problem_count += err4_reg_val & 0xFFFF; | |
1532 | sphy->invalid_dword_count += (err6_reg_val & 0xFF0000) >> 16; | |
1533 | sphy->running_disparity_error_count += err6_reg_val & 0xFF; | |
1534 | } | |
1535 | ||
0757f041 | 1536 | static void start_phys_v2_hw(struct hisi_hba *hisi_hba) |
29a20428 | 1537 | { |
29a20428 JG |
1538 | int i; |
1539 | ||
917d3bda XT |
1540 | for (i = 0; i < hisi_hba->n_phy; i++) { |
1541 | struct hisi_sas_phy *phy = &hisi_hba->phy[i]; | |
1542 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1543 | ||
1544 | if (!sas_phy->phy->enabled) | |
1545 | continue; | |
1546 | ||
29a20428 | 1547 | start_phy_v2_hw(hisi_hba, i); |
917d3bda | 1548 | } |
29a20428 JG |
1549 | } |
1550 | ||
1551 | static void phys_init_v2_hw(struct hisi_hba *hisi_hba) | |
1552 | { | |
0757f041 | 1553 | start_phys_v2_hw(hisi_hba); |
29a20428 JG |
1554 | } |
1555 | ||
7911e66f JG |
1556 | static void sl_notify_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1557 | { | |
1558 | u32 sl_control; | |
1559 | ||
1560 | sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
1561 | sl_control |= SL_CONTROL_NOTIFY_EN_MSK; | |
1562 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control); | |
1563 | msleep(1); | |
1564 | sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
1565 | sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK; | |
1566 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control); | |
1567 | } | |
1568 | ||
2ae75787 XC |
1569 | static enum sas_linkrate phy_get_max_linkrate_v2_hw(void) |
1570 | { | |
1571 | return SAS_LINK_RATE_12_0_GBPS; | |
1572 | } | |
1573 | ||
1574 | static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no, | |
1575 | struct sas_phy_linkrates *r) | |
1576 | { | |
1577 | u32 prog_phy_link_rate = | |
1578 | hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); | |
1579 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
1580 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1581 | int i; | |
1582 | enum sas_linkrate min, max; | |
1583 | u32 rate_mask = 0; | |
1584 | ||
1585 | if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { | |
1586 | max = sas_phy->phy->maximum_linkrate; | |
1587 | min = r->minimum_linkrate; | |
1588 | } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { | |
1589 | max = r->maximum_linkrate; | |
1590 | min = sas_phy->phy->minimum_linkrate; | |
1591 | } else | |
1592 | return; | |
1593 | ||
1594 | sas_phy->phy->maximum_linkrate = max; | |
1595 | sas_phy->phy->minimum_linkrate = min; | |
1596 | ||
1597 | min -= SAS_LINK_RATE_1_5_GBPS; | |
1598 | max -= SAS_LINK_RATE_1_5_GBPS; | |
1599 | ||
1600 | for (i = 0; i <= max; i++) | |
1601 | rate_mask |= 1 << (i * 2); | |
1602 | ||
1603 | prog_phy_link_rate &= ~0xff; | |
1604 | prog_phy_link_rate |= rate_mask; | |
1605 | ||
1606 | hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, | |
1607 | prog_phy_link_rate); | |
1608 | ||
1609 | phy_hard_reset_v2_hw(hisi_hba, phy_no); | |
1610 | } | |
1611 | ||
5473c060 JG |
1612 | static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id) |
1613 | { | |
1614 | int i, bitmap = 0; | |
1615 | u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
1616 | u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE); | |
1617 | ||
1618 | for (i = 0; i < (hisi_hba->n_phy < 9 ? hisi_hba->n_phy : 8); i++) | |
1619 | if (phy_state & 1 << i) | |
1620 | if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id) | |
1621 | bitmap |= 1 << i; | |
1622 | ||
1623 | if (hisi_hba->n_phy == 9) { | |
1624 | u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
1625 | ||
1626 | if (phy_state & 1 << 8) | |
1627 | if (((port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >> | |
1628 | PORT_STATE_PHY8_PORT_NUM_OFF) == port_id) | |
1629 | bitmap |= 1 << 9; | |
1630 | } | |
1631 | ||
1632 | return bitmap; | |
1633 | } | |
1634 | ||
b1a49412 | 1635 | /* |
8c36e31d JG |
1636 | * The callpath to this function and upto writing the write |
1637 | * queue pointer should be safe from interruption. | |
1638 | */ | |
b1a49412 XC |
1639 | static int |
1640 | get_free_slot_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq) | |
8c36e31d | 1641 | { |
11b75249 | 1642 | struct device *dev = hisi_hba->dev; |
b1a49412 | 1643 | int queue = dq->id; |
8c36e31d | 1644 | u32 r, w; |
c70f1fb7 | 1645 | |
c70f1fb7 XC |
1646 | w = dq->wr_point; |
1647 | r = hisi_sas_read32_relaxed(hisi_hba, | |
1648 | DLVRY_Q_0_RD_PTR + (queue * 0x14)); | |
1649 | if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) { | |
1650 | dev_warn(dev, "full queue=%d r=%d w=%d\n\n", | |
1651 | queue, r, w); | |
1652 | return -EAGAIN; | |
8c36e31d | 1653 | } |
c70f1fb7 | 1654 | |
8c36e31d JG |
1655 | return 0; |
1656 | } | |
1657 | ||
b1a49412 | 1658 | static void start_delivery_v2_hw(struct hisi_sas_dq *dq) |
8c36e31d | 1659 | { |
b1a49412 XC |
1660 | struct hisi_hba *hisi_hba = dq->hisi_hba; |
1661 | int dlvry_queue = dq->slot_prep->dlvry_queue; | |
1662 | int dlvry_queue_slot = dq->slot_prep->dlvry_queue_slot; | |
8c36e31d | 1663 | |
4fde02ad | 1664 | dq->wr_point = ++dlvry_queue_slot % HISI_SAS_QUEUE_SLOTS; |
8c36e31d | 1665 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), |
4fde02ad | 1666 | dq->wr_point); |
8c36e31d JG |
1667 | } |
1668 | ||
1669 | static int prep_prd_sge_v2_hw(struct hisi_hba *hisi_hba, | |
1670 | struct hisi_sas_slot *slot, | |
1671 | struct hisi_sas_cmd_hdr *hdr, | |
1672 | struct scatterlist *scatter, | |
1673 | int n_elem) | |
1674 | { | |
f557e32c | 1675 | struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot); |
11b75249 | 1676 | struct device *dev = hisi_hba->dev; |
8c36e31d JG |
1677 | struct scatterlist *sg; |
1678 | int i; | |
1679 | ||
1680 | if (n_elem > HISI_SAS_SGE_PAGE_CNT) { | |
1681 | dev_err(dev, "prd err: n_elem(%d) > HISI_SAS_SGE_PAGE_CNT", | |
1682 | n_elem); | |
1683 | return -EINVAL; | |
1684 | } | |
1685 | ||
8c36e31d | 1686 | for_each_sg(scatter, sg, n_elem, i) { |
f557e32c | 1687 | struct hisi_sas_sge *entry = &sge_page->sge[i]; |
8c36e31d JG |
1688 | |
1689 | entry->addr = cpu_to_le64(sg_dma_address(sg)); | |
1690 | entry->page_ctrl_0 = entry->page_ctrl_1 = 0; | |
1691 | entry->data_len = cpu_to_le32(sg_dma_len(sg)); | |
1692 | entry->data_off = 0; | |
1693 | } | |
1694 | ||
f557e32c | 1695 | hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot)); |
8c36e31d JG |
1696 | |
1697 | hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF); | |
1698 | ||
1699 | return 0; | |
1700 | } | |
1701 | ||
c2d89392 JG |
1702 | static int prep_smp_v2_hw(struct hisi_hba *hisi_hba, |
1703 | struct hisi_sas_slot *slot) | |
1704 | { | |
1705 | struct sas_task *task = slot->task; | |
1706 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1707 | struct domain_device *device = task->dev; | |
11b75249 | 1708 | struct device *dev = hisi_hba->dev; |
c2d89392 JG |
1709 | struct hisi_sas_port *port = slot->port; |
1710 | struct scatterlist *sg_req, *sg_resp; | |
1711 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
1712 | dma_addr_t req_dma_addr; | |
1713 | unsigned int req_len, resp_len; | |
1714 | int elem, rc; | |
1715 | ||
1716 | /* | |
1717 | * DMA-map SMP request, response buffers | |
1718 | */ | |
1719 | /* req */ | |
1720 | sg_req = &task->smp_task.smp_req; | |
1721 | elem = dma_map_sg(dev, sg_req, 1, DMA_TO_DEVICE); | |
1722 | if (!elem) | |
1723 | return -ENOMEM; | |
1724 | req_len = sg_dma_len(sg_req); | |
1725 | req_dma_addr = sg_dma_address(sg_req); | |
1726 | ||
1727 | /* resp */ | |
1728 | sg_resp = &task->smp_task.smp_resp; | |
1729 | elem = dma_map_sg(dev, sg_resp, 1, DMA_FROM_DEVICE); | |
1730 | if (!elem) { | |
1731 | rc = -ENOMEM; | |
1732 | goto err_out_req; | |
1733 | } | |
1734 | resp_len = sg_dma_len(sg_resp); | |
1735 | if ((req_len & 0x3) || (resp_len & 0x3)) { | |
1736 | rc = -EINVAL; | |
1737 | goto err_out_resp; | |
1738 | } | |
1739 | ||
1740 | /* create header */ | |
1741 | /* dw0 */ | |
1742 | hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) | | |
1743 | (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */ | |
1744 | (2 << CMD_HDR_CMD_OFF)); /* smp */ | |
1745 | ||
1746 | /* map itct entry */ | |
1747 | hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) | | |
1748 | (1 << CMD_HDR_FRAME_TYPE_OFF) | | |
1749 | (DIR_NO_DATA << CMD_HDR_DIR_OFF)); | |
1750 | ||
1751 | /* dw2 */ | |
1752 | hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) | | |
1753 | (HISI_SAS_MAX_SMP_RESP_SZ / 4 << | |
1754 | CMD_HDR_MRFL_OFF)); | |
1755 | ||
1756 | hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF); | |
1757 | ||
1758 | hdr->cmd_table_addr = cpu_to_le64(req_dma_addr); | |
f557e32c | 1759 | hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot)); |
c2d89392 JG |
1760 | |
1761 | return 0; | |
1762 | ||
1763 | err_out_resp: | |
1764 | dma_unmap_sg(dev, &slot->task->smp_task.smp_resp, 1, | |
1765 | DMA_FROM_DEVICE); | |
1766 | err_out_req: | |
1767 | dma_unmap_sg(dev, &slot->task->smp_task.smp_req, 1, | |
1768 | DMA_TO_DEVICE); | |
1769 | return rc; | |
1770 | } | |
1771 | ||
8c36e31d JG |
1772 | static int prep_ssp_v2_hw(struct hisi_hba *hisi_hba, |
1773 | struct hisi_sas_slot *slot, int is_tmf, | |
1774 | struct hisi_sas_tmf_task *tmf) | |
1775 | { | |
1776 | struct sas_task *task = slot->task; | |
1777 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1778 | struct domain_device *device = task->dev; | |
1779 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
1780 | struct hisi_sas_port *port = slot->port; | |
1781 | struct sas_ssp_task *ssp_task = &task->ssp_task; | |
1782 | struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; | |
1783 | int has_data = 0, rc, priority = is_tmf; | |
1784 | u8 *buf_cmd; | |
1785 | u32 dw1 = 0, dw2 = 0; | |
1786 | ||
1787 | hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) | | |
1788 | (2 << CMD_HDR_TLR_CTRL_OFF) | | |
1789 | (port->id << CMD_HDR_PORT_OFF) | | |
1790 | (priority << CMD_HDR_PRIORITY_OFF) | | |
1791 | (1 << CMD_HDR_CMD_OFF)); /* ssp */ | |
1792 | ||
1793 | dw1 = 1 << CMD_HDR_VDTL_OFF; | |
1794 | if (is_tmf) { | |
1795 | dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF; | |
1796 | dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF; | |
1797 | } else { | |
1798 | dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF; | |
1799 | switch (scsi_cmnd->sc_data_direction) { | |
1800 | case DMA_TO_DEVICE: | |
1801 | has_data = 1; | |
1802 | dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF; | |
1803 | break; | |
1804 | case DMA_FROM_DEVICE: | |
1805 | has_data = 1; | |
1806 | dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF; | |
1807 | break; | |
1808 | default: | |
1809 | dw1 &= ~CMD_HDR_DIR_MSK; | |
1810 | } | |
1811 | } | |
1812 | ||
1813 | /* map itct entry */ | |
1814 | dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; | |
1815 | hdr->dw1 = cpu_to_le32(dw1); | |
1816 | ||
1817 | dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr) | |
1818 | + 3) / 4) << CMD_HDR_CFL_OFF) | | |
1819 | ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) | | |
1820 | (2 << CMD_HDR_SG_MOD_OFF); | |
1821 | hdr->dw2 = cpu_to_le32(dw2); | |
1822 | ||
1823 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
1824 | ||
1825 | if (has_data) { | |
1826 | rc = prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter, | |
1827 | slot->n_elem); | |
1828 | if (rc) | |
1829 | return rc; | |
1830 | } | |
1831 | ||
1832 | hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len); | |
f557e32c XT |
1833 | hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot)); |
1834 | hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot)); | |
8c36e31d | 1835 | |
f557e32c XT |
1836 | buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) + |
1837 | sizeof(struct ssp_frame_hdr); | |
8c36e31d JG |
1838 | |
1839 | memcpy(buf_cmd, &task->ssp_task.LUN, 8); | |
1840 | if (!is_tmf) { | |
1841 | buf_cmd[9] = task->ssp_task.task_attr | | |
1842 | (task->ssp_task.task_prio << 3); | |
1843 | memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd, | |
1844 | task->ssp_task.cmd->cmd_len); | |
1845 | } else { | |
1846 | buf_cmd[10] = tmf->tmf; | |
1847 | switch (tmf->tmf) { | |
1848 | case TMF_ABORT_TASK: | |
1849 | case TMF_QUERY_TASK: | |
1850 | buf_cmd[12] = | |
1851 | (tmf->tag_of_task_to_be_managed >> 8) & 0xff; | |
1852 | buf_cmd[13] = | |
1853 | tmf->tag_of_task_to_be_managed & 0xff; | |
1854 | break; | |
1855 | default: | |
1856 | break; | |
1857 | } | |
1858 | } | |
1859 | ||
1860 | return 0; | |
1861 | } | |
1862 | ||
634a9585 XC |
1863 | #define TRANS_TX_ERR 0 |
1864 | #define TRANS_RX_ERR 1 | |
1865 | #define DMA_TX_ERR 2 | |
1866 | #define SIPC_RX_ERR 3 | |
1867 | #define DMA_RX_ERR 4 | |
1868 | ||
1869 | #define DMA_TX_ERR_OFF 0 | |
1870 | #define DMA_TX_ERR_MSK (0xffff << DMA_TX_ERR_OFF) | |
1871 | #define SIPC_RX_ERR_OFF 16 | |
1872 | #define SIPC_RX_ERR_MSK (0xffff << SIPC_RX_ERR_OFF) | |
1873 | ||
1874 | static int parse_trans_tx_err_code_v2_hw(u32 err_msk) | |
1875 | { | |
89b203e9 | 1876 | static const u8 trans_tx_err_code_prio[] = { |
634a9585 XC |
1877 | TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS, |
1878 | TRANS_TX_ERR_PHY_NOT_ENABLE, | |
1879 | TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION, | |
1880 | TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION, | |
1881 | TRANS_TX_OPEN_CNX_ERR_BY_OTHER, | |
1882 | RESERVED0, | |
1883 | TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT, | |
1884 | TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY, | |
1885 | TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED, | |
1886 | TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED, | |
1887 | TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION, | |
1888 | TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD, | |
1889 | TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER, | |
1890 | TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED, | |
1891 | TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT, | |
1892 | TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION, | |
1893 | TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED, | |
1894 | TRANS_TX_ERR_WITH_CLOSE_PHYDISALE, | |
1895 | TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT, | |
1896 | TRANS_TX_ERR_WITH_CLOSE_COMINIT, | |
1897 | TRANS_TX_ERR_WITH_BREAK_TIMEOUT, | |
1898 | TRANS_TX_ERR_WITH_BREAK_REQUEST, | |
1899 | TRANS_TX_ERR_WITH_BREAK_RECEVIED, | |
1900 | TRANS_TX_ERR_WITH_CLOSE_TIMEOUT, | |
1901 | TRANS_TX_ERR_WITH_CLOSE_NORMAL, | |
1902 | TRANS_TX_ERR_WITH_NAK_RECEVIED, | |
1903 | TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT, | |
1904 | TRANS_TX_ERR_WITH_CREDIT_TIMEOUT, | |
1905 | TRANS_TX_ERR_WITH_IPTT_CONFLICT, | |
1906 | TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS, | |
1907 | TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT, | |
1908 | }; | |
1909 | int index, i; | |
1910 | ||
1911 | for (i = 0; i < ARRAY_SIZE(trans_tx_err_code_prio); i++) { | |
1912 | index = trans_tx_err_code_prio[i] - TRANS_TX_FAIL_BASE; | |
1913 | if (err_msk & (1 << index)) | |
1914 | return trans_tx_err_code_prio[i]; | |
1915 | } | |
1916 | return -1; | |
1917 | } | |
1918 | ||
1919 | static int parse_trans_rx_err_code_v2_hw(u32 err_msk) | |
1920 | { | |
89b203e9 | 1921 | static const u8 trans_rx_err_code_prio[] = { |
634a9585 XC |
1922 | TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR, |
1923 | TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR, | |
1924 | TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM, | |
1925 | TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR, | |
1926 | TRANS_RX_ERR_WITH_RXFIS_CRC_ERR, | |
1927 | TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN, | |
1928 | TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP, | |
1929 | TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN, | |
1930 | TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE, | |
1931 | TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT, | |
1932 | TRANS_RX_ERR_WITH_CLOSE_COMINIT, | |
1933 | TRANS_RX_ERR_WITH_BREAK_TIMEOUT, | |
1934 | TRANS_RX_ERR_WITH_BREAK_REQUEST, | |
1935 | TRANS_RX_ERR_WITH_BREAK_RECEVIED, | |
1936 | RESERVED1, | |
1937 | TRANS_RX_ERR_WITH_CLOSE_NORMAL, | |
1938 | TRANS_RX_ERR_WITH_DATA_LEN0, | |
1939 | TRANS_RX_ERR_WITH_BAD_HASH, | |
1940 | TRANS_RX_XRDY_WLEN_ZERO_ERR, | |
1941 | TRANS_RX_SSP_FRM_LEN_ERR, | |
1942 | RESERVED2, | |
1943 | RESERVED3, | |
1944 | RESERVED4, | |
1945 | RESERVED5, | |
1946 | TRANS_RX_ERR_WITH_BAD_FRM_TYPE, | |
1947 | TRANS_RX_SMP_FRM_LEN_ERR, | |
1948 | TRANS_RX_SMP_RESP_TIMEOUT_ERR, | |
1949 | RESERVED6, | |
1950 | RESERVED7, | |
1951 | RESERVED8, | |
1952 | RESERVED9, | |
1953 | TRANS_RX_R_ERR, | |
1954 | }; | |
1955 | int index, i; | |
1956 | ||
1957 | for (i = 0; i < ARRAY_SIZE(trans_rx_err_code_prio); i++) { | |
1958 | index = trans_rx_err_code_prio[i] - TRANS_RX_FAIL_BASE; | |
1959 | if (err_msk & (1 << index)) | |
1960 | return trans_rx_err_code_prio[i]; | |
1961 | } | |
1962 | return -1; | |
1963 | } | |
1964 | ||
1965 | static int parse_dma_tx_err_code_v2_hw(u32 err_msk) | |
1966 | { | |
89b203e9 | 1967 | static const u8 dma_tx_err_code_prio[] = { |
634a9585 XC |
1968 | DMA_TX_UNEXP_XFER_ERR, |
1969 | DMA_TX_UNEXP_RETRANS_ERR, | |
1970 | DMA_TX_XFER_LEN_OVERFLOW, | |
1971 | DMA_TX_XFER_OFFSET_ERR, | |
1972 | DMA_TX_RAM_ECC_ERR, | |
1973 | DMA_TX_DIF_LEN_ALIGN_ERR, | |
1974 | DMA_TX_DIF_CRC_ERR, | |
1975 | DMA_TX_DIF_APP_ERR, | |
1976 | DMA_TX_DIF_RPP_ERR, | |
1977 | DMA_TX_DATA_SGL_OVERFLOW, | |
1978 | DMA_TX_DIF_SGL_OVERFLOW, | |
1979 | }; | |
1980 | int index, i; | |
1981 | ||
1982 | for (i = 0; i < ARRAY_SIZE(dma_tx_err_code_prio); i++) { | |
1983 | index = dma_tx_err_code_prio[i] - DMA_TX_ERR_BASE; | |
1984 | err_msk = err_msk & DMA_TX_ERR_MSK; | |
1985 | if (err_msk & (1 << index)) | |
1986 | return dma_tx_err_code_prio[i]; | |
1987 | } | |
1988 | return -1; | |
1989 | } | |
1990 | ||
1991 | static int parse_sipc_rx_err_code_v2_hw(u32 err_msk) | |
1992 | { | |
89b203e9 | 1993 | static const u8 sipc_rx_err_code_prio[] = { |
634a9585 XC |
1994 | SIPC_RX_FIS_STATUS_ERR_BIT_VLD, |
1995 | SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR, | |
1996 | SIPC_RX_FIS_STATUS_BSY_BIT_ERR, | |
1997 | SIPC_RX_WRSETUP_LEN_ODD_ERR, | |
1998 | SIPC_RX_WRSETUP_LEN_ZERO_ERR, | |
1999 | SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR, | |
2000 | SIPC_RX_NCQ_WRSETUP_OFFSET_ERR, | |
2001 | SIPC_RX_NCQ_WRSETUP_AUTO_ACTIVE_ERR, | |
2002 | SIPC_RX_SATA_UNEXP_FIS_ERR, | |
2003 | SIPC_RX_WRSETUP_ESTATUS_ERR, | |
2004 | SIPC_RX_DATA_UNDERFLOW_ERR, | |
2005 | }; | |
2006 | int index, i; | |
2007 | ||
2008 | for (i = 0; i < ARRAY_SIZE(sipc_rx_err_code_prio); i++) { | |
2009 | index = sipc_rx_err_code_prio[i] - SIPC_RX_ERR_BASE; | |
2010 | err_msk = err_msk & SIPC_RX_ERR_MSK; | |
2011 | if (err_msk & (1 << (index + 0x10))) | |
2012 | return sipc_rx_err_code_prio[i]; | |
2013 | } | |
2014 | return -1; | |
2015 | } | |
2016 | ||
2017 | static int parse_dma_rx_err_code_v2_hw(u32 err_msk) | |
2018 | { | |
89b203e9 | 2019 | static const u8 dma_rx_err_code_prio[] = { |
634a9585 XC |
2020 | DMA_RX_UNKNOWN_FRM_ERR, |
2021 | DMA_RX_DATA_LEN_OVERFLOW, | |
2022 | DMA_RX_DATA_LEN_UNDERFLOW, | |
2023 | DMA_RX_DATA_OFFSET_ERR, | |
2024 | RESERVED10, | |
2025 | DMA_RX_SATA_FRAME_TYPE_ERR, | |
2026 | DMA_RX_RESP_BUF_OVERFLOW, | |
2027 | DMA_RX_UNEXP_RETRANS_RESP_ERR, | |
2028 | DMA_RX_UNEXP_NORM_RESP_ERR, | |
2029 | DMA_RX_UNEXP_RDFRAME_ERR, | |
2030 | DMA_RX_PIO_DATA_LEN_ERR, | |
2031 | DMA_RX_RDSETUP_STATUS_ERR, | |
2032 | DMA_RX_RDSETUP_STATUS_DRQ_ERR, | |
2033 | DMA_RX_RDSETUP_STATUS_BSY_ERR, | |
2034 | DMA_RX_RDSETUP_LEN_ODD_ERR, | |
2035 | DMA_RX_RDSETUP_LEN_ZERO_ERR, | |
2036 | DMA_RX_RDSETUP_LEN_OVER_ERR, | |
2037 | DMA_RX_RDSETUP_OFFSET_ERR, | |
2038 | DMA_RX_RDSETUP_ACTIVE_ERR, | |
2039 | DMA_RX_RDSETUP_ESTATUS_ERR, | |
2040 | DMA_RX_RAM_ECC_ERR, | |
2041 | DMA_RX_DIF_CRC_ERR, | |
2042 | DMA_RX_DIF_APP_ERR, | |
2043 | DMA_RX_DIF_RPP_ERR, | |
2044 | DMA_RX_DATA_SGL_OVERFLOW, | |
2045 | DMA_RX_DIF_SGL_OVERFLOW, | |
2046 | }; | |
2047 | int index, i; | |
2048 | ||
2049 | for (i = 0; i < ARRAY_SIZE(dma_rx_err_code_prio); i++) { | |
2050 | index = dma_rx_err_code_prio[i] - DMA_RX_ERR_BASE; | |
2051 | if (err_msk & (1 << index)) | |
2052 | return dma_rx_err_code_prio[i]; | |
2053 | } | |
2054 | return -1; | |
2055 | } | |
2056 | ||
e8fed0e9 JG |
2057 | /* by default, task resp is complete */ |
2058 | static void slot_err_v2_hw(struct hisi_hba *hisi_hba, | |
2059 | struct sas_task *task, | |
634a9585 XC |
2060 | struct hisi_sas_slot *slot, |
2061 | int err_phase) | |
e8fed0e9 JG |
2062 | { |
2063 | struct task_status_struct *ts = &task->task_status; | |
f557e32c XT |
2064 | struct hisi_sas_err_record_v2 *err_record = |
2065 | hisi_sas_status_buf_addr_mem(slot); | |
e8fed0e9 JG |
2066 | u32 trans_tx_fail_type = cpu_to_le32(err_record->trans_tx_fail_type); |
2067 | u32 trans_rx_fail_type = cpu_to_le32(err_record->trans_rx_fail_type); | |
2068 | u16 dma_tx_err_type = cpu_to_le16(err_record->dma_tx_err_type); | |
2069 | u16 sipc_rx_err_type = cpu_to_le16(err_record->sipc_rx_err_type); | |
2070 | u32 dma_rx_err_type = cpu_to_le32(err_record->dma_rx_err_type); | |
2071 | int error = -1; | |
2072 | ||
634a9585 XC |
2073 | if (err_phase == 1) { |
2074 | /* error in TX phase, the priority of error is: DW2 > DW0 */ | |
2075 | error = parse_dma_tx_err_code_v2_hw(dma_tx_err_type); | |
2076 | if (error == -1) | |
2077 | error = parse_trans_tx_err_code_v2_hw( | |
2078 | trans_tx_fail_type); | |
2079 | } else if (err_phase == 2) { | |
2080 | /* error in RX phase, the priority is: DW1 > DW3 > DW2 */ | |
2081 | error = parse_trans_rx_err_code_v2_hw( | |
2082 | trans_rx_fail_type); | |
2083 | if (error == -1) { | |
2084 | error = parse_dma_rx_err_code_v2_hw( | |
2085 | dma_rx_err_type); | |
2086 | if (error == -1) | |
2087 | error = parse_sipc_rx_err_code_v2_hw( | |
2088 | sipc_rx_err_type); | |
2089 | } | |
e8fed0e9 JG |
2090 | } |
2091 | ||
2092 | switch (task->task_proto) { | |
2093 | case SAS_PROTOCOL_SSP: | |
2094 | { | |
2095 | switch (error) { | |
2096 | case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION: | |
2097 | { | |
2098 | ts->stat = SAS_OPEN_REJECT; | |
2099 | ts->open_rej_reason = SAS_OREJ_NO_DEST; | |
a28b259b | 2100 | break; |
e8fed0e9 JG |
2101 | } |
2102 | case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED: | |
2103 | { | |
2104 | ts->stat = SAS_OPEN_REJECT; | |
2105 | ts->open_rej_reason = SAS_OREJ_EPROTO; | |
2106 | break; | |
2107 | } | |
2108 | case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED: | |
2109 | { | |
2110 | ts->stat = SAS_OPEN_REJECT; | |
2111 | ts->open_rej_reason = SAS_OREJ_CONN_RATE; | |
2112 | break; | |
2113 | } | |
2114 | case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION: | |
2115 | { | |
2116 | ts->stat = SAS_OPEN_REJECT; | |
2117 | ts->open_rej_reason = SAS_OREJ_BAD_DEST; | |
2118 | break; | |
2119 | } | |
e8fed0e9 JG |
2120 | case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION: |
2121 | { | |
2122 | ts->stat = SAS_OPEN_REJECT; | |
2123 | ts->open_rej_reason = SAS_OREJ_WRONG_DEST; | |
2124 | break; | |
2125 | } | |
634a9585 | 2126 | case DMA_RX_UNEXP_NORM_RESP_ERR: |
e8fed0e9 | 2127 | case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION: |
634a9585 | 2128 | case DMA_RX_RESP_BUF_OVERFLOW: |
e8fed0e9 JG |
2129 | { |
2130 | ts->stat = SAS_OPEN_REJECT; | |
2131 | ts->open_rej_reason = SAS_OREJ_UNKNOWN; | |
2132 | break; | |
2133 | } | |
2134 | case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER: | |
2135 | { | |
2136 | /* not sure */ | |
2137 | ts->stat = SAS_DEV_NO_RESPONSE; | |
2138 | break; | |
2139 | } | |
e8fed0e9 JG |
2140 | case DMA_RX_DATA_LEN_OVERFLOW: |
2141 | { | |
2142 | ts->stat = SAS_DATA_OVERRUN; | |
2143 | ts->residual = 0; | |
2144 | break; | |
2145 | } | |
2146 | case DMA_RX_DATA_LEN_UNDERFLOW: | |
e8fed0e9 | 2147 | { |
01b361fc | 2148 | ts->residual = trans_tx_fail_type; |
e8fed0e9 JG |
2149 | ts->stat = SAS_DATA_UNDERRUN; |
2150 | break; | |
2151 | } | |
2152 | case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS: | |
2153 | case TRANS_TX_ERR_PHY_NOT_ENABLE: | |
2154 | case TRANS_TX_OPEN_CNX_ERR_BY_OTHER: | |
2155 | case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT: | |
634a9585 XC |
2156 | case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD: |
2157 | case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED: | |
2158 | case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT: | |
e8fed0e9 JG |
2159 | case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED: |
2160 | case TRANS_TX_ERR_WITH_BREAK_TIMEOUT: | |
2161 | case TRANS_TX_ERR_WITH_BREAK_REQUEST: | |
2162 | case TRANS_TX_ERR_WITH_BREAK_RECEVIED: | |
2163 | case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT: | |
2164 | case TRANS_TX_ERR_WITH_CLOSE_NORMAL: | |
634a9585 | 2165 | case TRANS_TX_ERR_WITH_CLOSE_PHYDISALE: |
e8fed0e9 JG |
2166 | case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT: |
2167 | case TRANS_TX_ERR_WITH_CLOSE_COMINIT: | |
2168 | case TRANS_TX_ERR_WITH_NAK_RECEVIED: | |
2169 | case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT: | |
e8fed0e9 | 2170 | case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT: |
634a9585 | 2171 | case TRANS_TX_ERR_WITH_IPTT_CONFLICT: |
e8fed0e9 JG |
2172 | case TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR: |
2173 | case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR: | |
2174 | case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM: | |
634a9585 | 2175 | case TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN: |
e8fed0e9 JG |
2176 | case TRANS_RX_ERR_WITH_BREAK_TIMEOUT: |
2177 | case TRANS_RX_ERR_WITH_BREAK_REQUEST: | |
2178 | case TRANS_RX_ERR_WITH_BREAK_RECEVIED: | |
2179 | case TRANS_RX_ERR_WITH_CLOSE_NORMAL: | |
2180 | case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT: | |
2181 | case TRANS_RX_ERR_WITH_CLOSE_COMINIT: | |
634a9585 XC |
2182 | case TRANS_TX_ERR_FRAME_TXED: |
2183 | case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE: | |
e8fed0e9 JG |
2184 | case TRANS_RX_ERR_WITH_DATA_LEN0: |
2185 | case TRANS_RX_ERR_WITH_BAD_HASH: | |
2186 | case TRANS_RX_XRDY_WLEN_ZERO_ERR: | |
2187 | case TRANS_RX_SSP_FRM_LEN_ERR: | |
2188 | case TRANS_RX_ERR_WITH_BAD_FRM_TYPE: | |
634a9585 | 2189 | case DMA_TX_DATA_SGL_OVERFLOW: |
e8fed0e9 JG |
2190 | case DMA_TX_UNEXP_XFER_ERR: |
2191 | case DMA_TX_UNEXP_RETRANS_ERR: | |
2192 | case DMA_TX_XFER_LEN_OVERFLOW: | |
2193 | case DMA_TX_XFER_OFFSET_ERR: | |
634a9585 XC |
2194 | case SIPC_RX_DATA_UNDERFLOW_ERR: |
2195 | case DMA_RX_DATA_SGL_OVERFLOW: | |
e8fed0e9 | 2196 | case DMA_RX_DATA_OFFSET_ERR: |
634a9585 XC |
2197 | case DMA_RX_RDSETUP_LEN_ODD_ERR: |
2198 | case DMA_RX_RDSETUP_LEN_ZERO_ERR: | |
2199 | case DMA_RX_RDSETUP_LEN_OVER_ERR: | |
2200 | case DMA_RX_SATA_FRAME_TYPE_ERR: | |
e8fed0e9 JG |
2201 | case DMA_RX_UNKNOWN_FRM_ERR: |
2202 | { | |
634a9585 XC |
2203 | /* This will request a retry */ |
2204 | ts->stat = SAS_QUEUE_FULL; | |
2205 | slot->abort = 1; | |
e8fed0e9 JG |
2206 | break; |
2207 | } | |
2208 | default: | |
2209 | break; | |
2210 | } | |
2211 | } | |
2212 | break; | |
2213 | case SAS_PROTOCOL_SMP: | |
2214 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
2215 | break; | |
2216 | ||
2217 | case SAS_PROTOCOL_SATA: | |
2218 | case SAS_PROTOCOL_STP: | |
2219 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
2220 | { | |
2221 | switch (error) { | |
e8fed0e9 | 2222 | case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION: |
634a9585 XC |
2223 | { |
2224 | ts->stat = SAS_OPEN_REJECT; | |
2225 | ts->open_rej_reason = SAS_OREJ_NO_DEST; | |
2226 | break; | |
2227 | } | |
2228 | case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER: | |
e8fed0e9 JG |
2229 | { |
2230 | ts->resp = SAS_TASK_UNDELIVERED; | |
2231 | ts->stat = SAS_DEV_NO_RESPONSE; | |
2232 | break; | |
2233 | } | |
2234 | case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED: | |
634a9585 XC |
2235 | { |
2236 | ts->stat = SAS_OPEN_REJECT; | |
2237 | ts->open_rej_reason = SAS_OREJ_EPROTO; | |
2238 | break; | |
2239 | } | |
e8fed0e9 | 2240 | case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED: |
634a9585 XC |
2241 | { |
2242 | ts->stat = SAS_OPEN_REJECT; | |
2243 | ts->open_rej_reason = SAS_OREJ_CONN_RATE; | |
2244 | break; | |
2245 | } | |
e8fed0e9 | 2246 | case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION: |
634a9585 XC |
2247 | { |
2248 | ts->stat = SAS_OPEN_REJECT; | |
2249 | ts->open_rej_reason = SAS_OREJ_CONN_RATE; | |
2250 | break; | |
2251 | } | |
e8fed0e9 | 2252 | case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION: |
e8fed0e9 JG |
2253 | { |
2254 | ts->stat = SAS_OPEN_REJECT; | |
634a9585 | 2255 | ts->open_rej_reason = SAS_OREJ_WRONG_DEST; |
e8fed0e9 JG |
2256 | break; |
2257 | } | |
634a9585 XC |
2258 | case DMA_RX_RESP_BUF_OVERFLOW: |
2259 | case DMA_RX_UNEXP_NORM_RESP_ERR: | |
2260 | case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION: | |
e8fed0e9 | 2261 | { |
634a9585 XC |
2262 | ts->stat = SAS_OPEN_REJECT; |
2263 | ts->open_rej_reason = SAS_OREJ_UNKNOWN; | |
e8fed0e9 JG |
2264 | break; |
2265 | } | |
2266 | case DMA_RX_DATA_LEN_OVERFLOW: | |
2267 | { | |
2268 | ts->stat = SAS_DATA_OVERRUN; | |
634a9585 XC |
2269 | ts->residual = 0; |
2270 | break; | |
2271 | } | |
2272 | case DMA_RX_DATA_LEN_UNDERFLOW: | |
2273 | { | |
01b361fc | 2274 | ts->residual = trans_tx_fail_type; |
634a9585 | 2275 | ts->stat = SAS_DATA_UNDERRUN; |
e8fed0e9 JG |
2276 | break; |
2277 | } | |
2278 | case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS: | |
2279 | case TRANS_TX_ERR_PHY_NOT_ENABLE: | |
2280 | case TRANS_TX_OPEN_CNX_ERR_BY_OTHER: | |
2281 | case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT: | |
634a9585 XC |
2282 | case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD: |
2283 | case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED: | |
2284 | case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT: | |
e8fed0e9 JG |
2285 | case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED: |
2286 | case TRANS_TX_ERR_WITH_BREAK_TIMEOUT: | |
2287 | case TRANS_TX_ERR_WITH_BREAK_REQUEST: | |
2288 | case TRANS_TX_ERR_WITH_BREAK_RECEVIED: | |
2289 | case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT: | |
2290 | case TRANS_TX_ERR_WITH_CLOSE_NORMAL: | |
634a9585 | 2291 | case TRANS_TX_ERR_WITH_CLOSE_PHYDISALE: |
e8fed0e9 JG |
2292 | case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT: |
2293 | case TRANS_TX_ERR_WITH_CLOSE_COMINIT: | |
e8fed0e9 JG |
2294 | case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT: |
2295 | case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT: | |
634a9585 | 2296 | case TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS: |
e8fed0e9 | 2297 | case TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT: |
e8fed0e9 | 2298 | case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM: |
634a9585 | 2299 | case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR: |
e8fed0e9 JG |
2300 | case TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR: |
2301 | case TRANS_RX_ERR_WITH_RXFIS_CRC_ERR: | |
2302 | case TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN: | |
2303 | case TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP: | |
634a9585 XC |
2304 | case TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN: |
2305 | case TRANS_RX_ERR_WITH_BREAK_TIMEOUT: | |
2306 | case TRANS_RX_ERR_WITH_BREAK_REQUEST: | |
2307 | case TRANS_RX_ERR_WITH_BREAK_RECEVIED: | |
e8fed0e9 JG |
2308 | case TRANS_RX_ERR_WITH_CLOSE_NORMAL: |
2309 | case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE: | |
2310 | case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT: | |
2311 | case TRANS_RX_ERR_WITH_CLOSE_COMINIT: | |
2312 | case TRANS_RX_ERR_WITH_DATA_LEN0: | |
2313 | case TRANS_RX_ERR_WITH_BAD_HASH: | |
2314 | case TRANS_RX_XRDY_WLEN_ZERO_ERR: | |
634a9585 XC |
2315 | case TRANS_RX_ERR_WITH_BAD_FRM_TYPE: |
2316 | case DMA_TX_DATA_SGL_OVERFLOW: | |
2317 | case DMA_TX_UNEXP_XFER_ERR: | |
2318 | case DMA_TX_UNEXP_RETRANS_ERR: | |
2319 | case DMA_TX_XFER_LEN_OVERFLOW: | |
2320 | case DMA_TX_XFER_OFFSET_ERR: | |
e8fed0e9 JG |
2321 | case SIPC_RX_FIS_STATUS_ERR_BIT_VLD: |
2322 | case SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR: | |
2323 | case SIPC_RX_FIS_STATUS_BSY_BIT_ERR: | |
2324 | case SIPC_RX_WRSETUP_LEN_ODD_ERR: | |
2325 | case SIPC_RX_WRSETUP_LEN_ZERO_ERR: | |
2326 | case SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR: | |
2327 | case SIPC_RX_SATA_UNEXP_FIS_ERR: | |
634a9585 XC |
2328 | case DMA_RX_DATA_SGL_OVERFLOW: |
2329 | case DMA_RX_DATA_OFFSET_ERR: | |
e8fed0e9 JG |
2330 | case DMA_RX_SATA_FRAME_TYPE_ERR: |
2331 | case DMA_RX_UNEXP_RDFRAME_ERR: | |
2332 | case DMA_RX_PIO_DATA_LEN_ERR: | |
2333 | case DMA_RX_RDSETUP_STATUS_ERR: | |
2334 | case DMA_RX_RDSETUP_STATUS_DRQ_ERR: | |
2335 | case DMA_RX_RDSETUP_STATUS_BSY_ERR: | |
2336 | case DMA_RX_RDSETUP_LEN_ODD_ERR: | |
2337 | case DMA_RX_RDSETUP_LEN_ZERO_ERR: | |
2338 | case DMA_RX_RDSETUP_LEN_OVER_ERR: | |
2339 | case DMA_RX_RDSETUP_OFFSET_ERR: | |
2340 | case DMA_RX_RDSETUP_ACTIVE_ERR: | |
2341 | case DMA_RX_RDSETUP_ESTATUS_ERR: | |
2342 | case DMA_RX_UNKNOWN_FRM_ERR: | |
634a9585 XC |
2343 | case TRANS_RX_SSP_FRM_LEN_ERR: |
2344 | case TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY: | |
e8fed0e9 | 2345 | { |
634a9585 XC |
2346 | slot->abort = 1; |
2347 | ts->stat = SAS_PHY_DOWN; | |
e8fed0e9 JG |
2348 | break; |
2349 | } | |
2350 | default: | |
2351 | { | |
2352 | ts->stat = SAS_PROTO_RESPONSE; | |
2353 | break; | |
2354 | } | |
2355 | } | |
75904077 | 2356 | hisi_sas_sata_done(task, slot); |
e8fed0e9 JG |
2357 | } |
2358 | break; | |
2359 | default: | |
2360 | break; | |
2361 | } | |
2362 | } | |
2363 | ||
31a9cfa6 | 2364 | static int |
405314df | 2365 | slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot) |
31a9cfa6 JG |
2366 | { |
2367 | struct sas_task *task = slot->task; | |
2368 | struct hisi_sas_device *sas_dev; | |
11b75249 | 2369 | struct device *dev = hisi_hba->dev; |
31a9cfa6 JG |
2370 | struct task_status_struct *ts; |
2371 | struct domain_device *device; | |
2372 | enum exec_status sts; | |
2373 | struct hisi_sas_complete_v2_hdr *complete_queue = | |
2374 | hisi_hba->complete_hdr[slot->cmplt_queue]; | |
2375 | struct hisi_sas_complete_v2_hdr *complete_hdr = | |
2376 | &complete_queue[slot->cmplt_queue_slot]; | |
54c9dd2d | 2377 | unsigned long flags; |
a305f337 | 2378 | int aborted; |
31a9cfa6 JG |
2379 | |
2380 | if (unlikely(!task || !task->lldd_task || !task->dev)) | |
2381 | return -EINVAL; | |
2382 | ||
2383 | ts = &task->task_status; | |
2384 | device = task->dev; | |
2385 | sas_dev = device->lldd_dev; | |
2386 | ||
54c9dd2d | 2387 | spin_lock_irqsave(&task->task_state_lock, flags); |
a305f337 | 2388 | aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED; |
31a9cfa6 JG |
2389 | task->task_state_flags &= |
2390 | ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); | |
54c9dd2d | 2391 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
31a9cfa6 JG |
2392 | |
2393 | memset(ts, 0, sizeof(*ts)); | |
2394 | ts->resp = SAS_TASK_COMPLETE; | |
2395 | ||
a305f337 JG |
2396 | if (unlikely(aborted)) { |
2397 | ts->stat = SAS_ABORTED_TASK; | |
2398 | hisi_sas_slot_task_free(hisi_hba, task, slot); | |
2399 | return -1; | |
2400 | } | |
2401 | ||
405314df JG |
2402 | if (unlikely(!sas_dev)) { |
2403 | dev_dbg(dev, "slot complete: port has no device\n"); | |
31a9cfa6 JG |
2404 | ts->stat = SAS_PHY_DOWN; |
2405 | goto out; | |
2406 | } | |
2407 | ||
df032d0e JG |
2408 | /* Use SAS+TMF status codes */ |
2409 | switch ((complete_hdr->dw0 & CMPLT_HDR_ABORT_STAT_MSK) | |
2410 | >> CMPLT_HDR_ABORT_STAT_OFF) { | |
2411 | case STAT_IO_ABORTED: | |
2412 | /* this io has been aborted by abort command */ | |
2413 | ts->stat = SAS_ABORTED_TASK; | |
2414 | goto out; | |
2415 | case STAT_IO_COMPLETE: | |
2416 | /* internal abort command complete */ | |
c35279f2 | 2417 | ts->stat = TMF_RESP_FUNC_SUCC; |
0844a3ff | 2418 | del_timer(&slot->internal_abort_timer); |
df032d0e JG |
2419 | goto out; |
2420 | case STAT_IO_NO_DEVICE: | |
2421 | ts->stat = TMF_RESP_FUNC_COMPLETE; | |
0844a3ff | 2422 | del_timer(&slot->internal_abort_timer); |
df032d0e JG |
2423 | goto out; |
2424 | case STAT_IO_NOT_VALID: | |
2425 | /* abort single io, controller don't find | |
2426 | * the io need to abort | |
2427 | */ | |
2428 | ts->stat = TMF_RESP_FUNC_FAILED; | |
0844a3ff | 2429 | del_timer(&slot->internal_abort_timer); |
df032d0e JG |
2430 | goto out; |
2431 | default: | |
2432 | break; | |
2433 | } | |
2434 | ||
31a9cfa6 JG |
2435 | if ((complete_hdr->dw0 & CMPLT_HDR_ERX_MSK) && |
2436 | (!(complete_hdr->dw0 & CMPLT_HDR_RSPNS_XFRD_MSK))) { | |
634a9585 XC |
2437 | u32 err_phase = (complete_hdr->dw0 & CMPLT_HDR_ERR_PHASE_MSK) |
2438 | >> CMPLT_HDR_ERR_PHASE_OFF; | |
2439 | ||
2440 | /* Analyse error happens on which phase TX or RX */ | |
2441 | if (ERR_ON_TX_PHASE(err_phase)) | |
2442 | slot_err_v2_hw(hisi_hba, task, slot, 1); | |
2443 | else if (ERR_ON_RX_PHASE(err_phase)) | |
2444 | slot_err_v2_hw(hisi_hba, task, slot, 2); | |
fc866951 XC |
2445 | |
2446 | if (unlikely(slot->abort)) | |
9c8ee657 | 2447 | return ts->stat; |
31a9cfa6 JG |
2448 | goto out; |
2449 | } | |
2450 | ||
2451 | switch (task->task_proto) { | |
2452 | case SAS_PROTOCOL_SSP: | |
2453 | { | |
f557e32c XT |
2454 | struct hisi_sas_status_buffer *status_buffer = |
2455 | hisi_sas_status_buf_addr_mem(slot); | |
2456 | struct ssp_response_iu *iu = (struct ssp_response_iu *) | |
2457 | &status_buffer->iu[0]; | |
31a9cfa6 JG |
2458 | |
2459 | sas_ssp_task_response(dev, task, iu); | |
2460 | break; | |
2461 | } | |
2462 | case SAS_PROTOCOL_SMP: | |
2463 | { | |
2464 | struct scatterlist *sg_resp = &task->smp_task.smp_resp; | |
2465 | void *to; | |
2466 | ||
2467 | ts->stat = SAM_STAT_GOOD; | |
2468 | to = kmap_atomic(sg_page(sg_resp)); | |
2469 | ||
2470 | dma_unmap_sg(dev, &task->smp_task.smp_resp, 1, | |
2471 | DMA_FROM_DEVICE); | |
2472 | dma_unmap_sg(dev, &task->smp_task.smp_req, 1, | |
2473 | DMA_TO_DEVICE); | |
2474 | memcpy(to + sg_resp->offset, | |
f557e32c | 2475 | hisi_sas_status_buf_addr_mem(slot) + |
31a9cfa6 JG |
2476 | sizeof(struct hisi_sas_err_record), |
2477 | sg_dma_len(sg_resp)); | |
2478 | kunmap_atomic(to); | |
2479 | break; | |
2480 | } | |
2481 | case SAS_PROTOCOL_SATA: | |
2482 | case SAS_PROTOCOL_STP: | |
2483 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
6f2ff1a1 JG |
2484 | { |
2485 | ts->stat = SAM_STAT_GOOD; | |
75904077 | 2486 | hisi_sas_sata_done(task, slot); |
6f2ff1a1 JG |
2487 | break; |
2488 | } | |
31a9cfa6 JG |
2489 | default: |
2490 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
2491 | break; | |
2492 | } | |
2493 | ||
2494 | if (!slot->port->port_attached) { | |
2495 | dev_err(dev, "slot complete: port %d has removed\n", | |
2496 | slot->port->sas_port.id); | |
2497 | ts->stat = SAS_PHY_DOWN; | |
2498 | } | |
2499 | ||
2500 | out: | |
54c9dd2d | 2501 | spin_lock_irqsave(&task->task_state_lock, flags); |
fc866951 | 2502 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
54c9dd2d | 2503 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
b1a49412 | 2504 | spin_lock_irqsave(&hisi_hba->lock, flags); |
31a9cfa6 | 2505 | hisi_sas_slot_task_free(hisi_hba, task, slot); |
b1a49412 | 2506 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
31a9cfa6 JG |
2507 | sts = ts->stat; |
2508 | ||
2509 | if (task->task_done) | |
2510 | task->task_done(task); | |
2511 | ||
2512 | return sts; | |
2513 | } | |
2514 | ||
6f2ff1a1 JG |
2515 | static int prep_ata_v2_hw(struct hisi_hba *hisi_hba, |
2516 | struct hisi_sas_slot *slot) | |
2517 | { | |
2518 | struct sas_task *task = slot->task; | |
2519 | struct domain_device *device = task->dev; | |
2520 | struct domain_device *parent_dev = device->parent; | |
2521 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
2522 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
2e244f0f JG |
2523 | struct asd_sas_port *sas_port = device->port; |
2524 | struct hisi_sas_port *port = to_hisi_sas_port(sas_port); | |
6f2ff1a1 JG |
2525 | u8 *buf_cmd; |
2526 | int has_data = 0, rc = 0, hdr_tag = 0; | |
2527 | u32 dw1 = 0, dw2 = 0; | |
2528 | ||
2529 | /* create header */ | |
2530 | /* dw0 */ | |
2531 | hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF); | |
2532 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) | |
2533 | hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF); | |
2534 | else | |
2535 | hdr->dw0 |= cpu_to_le32(4 << CMD_HDR_CMD_OFF); | |
2536 | ||
2537 | /* dw1 */ | |
2538 | switch (task->data_dir) { | |
2539 | case DMA_TO_DEVICE: | |
2540 | has_data = 1; | |
2541 | dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF; | |
2542 | break; | |
2543 | case DMA_FROM_DEVICE: | |
2544 | has_data = 1; | |
2545 | dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF; | |
2546 | break; | |
2547 | default: | |
2548 | dw1 &= ~CMD_HDR_DIR_MSK; | |
2549 | } | |
2550 | ||
7c594f04 XC |
2551 | if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) && |
2552 | (task->ata_task.fis.control & ATA_SRST)) | |
6f2ff1a1 JG |
2553 | dw1 |= 1 << CMD_HDR_RESET_OFF; |
2554 | ||
6c7bb8a1 XC |
2555 | dw1 |= (hisi_sas_get_ata_protocol( |
2556 | task->ata_task.fis.command, task->data_dir)) | |
6f2ff1a1 JG |
2557 | << CMD_HDR_FRAME_TYPE_OFF; |
2558 | dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; | |
2559 | hdr->dw1 = cpu_to_le32(dw1); | |
2560 | ||
2561 | /* dw2 */ | |
318913c6 | 2562 | if (task->ata_task.use_ncq && hisi_sas_get_ncq_tag(task, &hdr_tag)) { |
6f2ff1a1 JG |
2563 | task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); |
2564 | dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF; | |
2565 | } | |
2566 | ||
2567 | dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF | | |
2568 | 2 << CMD_HDR_SG_MOD_OFF; | |
2569 | hdr->dw2 = cpu_to_le32(dw2); | |
2570 | ||
2571 | /* dw3 */ | |
2572 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
2573 | ||
2574 | if (has_data) { | |
2575 | rc = prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter, | |
2576 | slot->n_elem); | |
2577 | if (rc) | |
2578 | return rc; | |
2579 | } | |
2580 | ||
6f2ff1a1 | 2581 | hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len); |
f557e32c XT |
2582 | hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot)); |
2583 | hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot)); | |
6f2ff1a1 | 2584 | |
f557e32c | 2585 | buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot); |
6f2ff1a1 JG |
2586 | |
2587 | if (likely(!task->ata_task.device_control_reg_update)) | |
2588 | task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */ | |
2589 | /* fill in command FIS */ | |
2590 | memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); | |
2591 | ||
2592 | return 0; | |
2593 | } | |
2594 | ||
0844a3ff JG |
2595 | static void hisi_sas_internal_abort_quirk_timeout(unsigned long data) |
2596 | { | |
2597 | struct hisi_sas_slot *slot = (struct hisi_sas_slot *)data; | |
2598 | struct hisi_sas_port *port = slot->port; | |
2599 | struct asd_sas_port *asd_sas_port; | |
2600 | struct asd_sas_phy *sas_phy; | |
2601 | ||
2602 | if (!port) | |
2603 | return; | |
2604 | ||
2605 | asd_sas_port = &port->sas_port; | |
2606 | ||
2607 | /* Kick the hardware - send break command */ | |
2608 | list_for_each_entry(sas_phy, &asd_sas_port->phy_list, port_phy_el) { | |
2609 | struct hisi_sas_phy *phy = sas_phy->lldd_phy; | |
2610 | struct hisi_hba *hisi_hba = phy->hisi_hba; | |
2611 | int phy_no = sas_phy->id; | |
2612 | u32 link_dfx2; | |
2613 | ||
2614 | link_dfx2 = hisi_sas_phy_read32(hisi_hba, phy_no, LINK_DFX2); | |
2615 | if ((link_dfx2 == LINK_DFX2_RCVR_HOLD_STS_MSK) || | |
2616 | (link_dfx2 & LINK_DFX2_SEND_HOLD_STS_MSK)) { | |
2617 | u32 txid_auto; | |
2618 | ||
2619 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2620 | TXID_AUTO); | |
2621 | txid_auto |= TXID_AUTO_CTB_MSK; | |
2622 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
2623 | txid_auto); | |
2624 | return; | |
2625 | } | |
2626 | } | |
2627 | } | |
2628 | ||
a3e665d9 JG |
2629 | static int prep_abort_v2_hw(struct hisi_hba *hisi_hba, |
2630 | struct hisi_sas_slot *slot, | |
2631 | int device_id, int abort_flag, int tag_to_abort) | |
2632 | { | |
2633 | struct sas_task *task = slot->task; | |
2634 | struct domain_device *dev = task->dev; | |
2635 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
2636 | struct hisi_sas_port *port = slot->port; | |
0844a3ff JG |
2637 | struct timer_list *timer = &slot->internal_abort_timer; |
2638 | ||
2639 | /* setup the quirk timer */ | |
2640 | setup_timer(timer, hisi_sas_internal_abort_quirk_timeout, | |
2641 | (unsigned long)slot); | |
2642 | /* Set the timeout to 10ms less than internal abort timeout */ | |
2643 | mod_timer(timer, jiffies + msecs_to_jiffies(100)); | |
a3e665d9 JG |
2644 | |
2645 | /* dw0 */ | |
2646 | hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/ | |
2647 | (port->id << CMD_HDR_PORT_OFF) | | |
2648 | ((dev_is_sata(dev) ? 1:0) << | |
2649 | CMD_HDR_ABORT_DEVICE_TYPE_OFF) | | |
2650 | (abort_flag << CMD_HDR_ABORT_FLAG_OFF)); | |
2651 | ||
2652 | /* dw1 */ | |
2653 | hdr->dw1 = cpu_to_le32(device_id << CMD_HDR_DEV_ID_OFF); | |
2654 | ||
2655 | /* dw7 */ | |
2656 | hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF); | |
2657 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
2658 | ||
2659 | return 0; | |
2660 | } | |
2661 | ||
7911e66f JG |
2662 | static int phy_up_v2_hw(int phy_no, struct hisi_hba *hisi_hba) |
2663 | { | |
981843c6 | 2664 | int i, res = IRQ_HANDLED; |
4935933e | 2665 | u32 port_id, link_rate, hard_phy_linkrate; |
7911e66f JG |
2666 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
2667 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
11b75249 | 2668 | struct device *dev = hisi_hba->dev; |
7911e66f JG |
2669 | u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd; |
2670 | struct sas_identify_frame *id = (struct sas_identify_frame *)frame_rcvd; | |
2671 | ||
2672 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1); | |
2673 | ||
4935933e | 2674 | if (is_sata_phy_v2_hw(hisi_hba, phy_no)) |
7911e66f JG |
2675 | goto end; |
2676 | ||
2677 | if (phy_no == 8) { | |
2678 | u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
2679 | ||
2680 | port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >> | |
2681 | PORT_STATE_PHY8_PORT_NUM_OFF; | |
2682 | link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >> | |
2683 | PORT_STATE_PHY8_CONN_RATE_OFF; | |
2684 | } else { | |
2685 | port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
2686 | port_id = (port_id >> (4 * phy_no)) & 0xf; | |
2687 | link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE); | |
2688 | link_rate = (link_rate >> (phy_no * 4)) & 0xf; | |
2689 | } | |
2690 | ||
2691 | if (port_id == 0xf) { | |
2692 | dev_err(dev, "phyup: phy%d invalid portid\n", phy_no); | |
2693 | res = IRQ_NONE; | |
2694 | goto end; | |
2695 | } | |
2696 | ||
2697 | for (i = 0; i < 6; i++) { | |
2698 | u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2699 | RX_IDAF_DWORD0 + (i * 4)); | |
2700 | frame_rcvd[i] = __swab32(idaf); | |
2701 | } | |
2702 | ||
7911e66f JG |
2703 | sas_phy->linkrate = link_rate; |
2704 | hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2705 | HARD_PHY_LINKRATE); | |
2706 | phy->maximum_linkrate = hard_phy_linkrate & 0xf; | |
2707 | phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf; | |
2708 | ||
2709 | sas_phy->oob_mode = SAS_OOB_MODE; | |
2710 | memcpy(sas_phy->attached_sas_addr, &id->sas_addr, SAS_ADDR_SIZE); | |
2711 | dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate); | |
2712 | phy->port_id = port_id; | |
2713 | phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); | |
2714 | phy->phy_type |= PORT_TYPE_SAS; | |
2715 | phy->phy_attached = 1; | |
2716 | phy->identify.device_type = id->dev_type; | |
2717 | phy->frame_rcvd_size = sizeof(struct sas_identify_frame); | |
2718 | if (phy->identify.device_type == SAS_END_DEVICE) | |
2719 | phy->identify.target_port_protocols = | |
2720 | SAS_PROTOCOL_SSP; | |
f2f89c32 | 2721 | else if (phy->identify.device_type != SAS_PHY_UNUSED) { |
7911e66f JG |
2722 | phy->identify.target_port_protocols = |
2723 | SAS_PROTOCOL_SMP; | |
f2f89c32 XC |
2724 | if (!timer_pending(&hisi_hba->timer)) |
2725 | set_link_timer_quirk(hisi_hba); | |
2726 | } | |
7911e66f JG |
2727 | queue_work(hisi_hba->wq, &phy->phyup_ws); |
2728 | ||
2729 | end: | |
2730 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, | |
2731 | CHL_INT0_SL_PHY_ENABLE_MSK); | |
2732 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0); | |
2733 | ||
2734 | return res; | |
2735 | } | |
2736 | ||
f2f89c32 XC |
2737 | static bool check_any_wideports_v2_hw(struct hisi_hba *hisi_hba) |
2738 | { | |
2739 | u32 port_state; | |
2740 | ||
2741 | port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
2742 | if (port_state & 0x1ff) | |
2743 | return true; | |
2744 | ||
2745 | return false; | |
2746 | } | |
2747 | ||
5473c060 JG |
2748 | static int phy_down_v2_hw(int phy_no, struct hisi_hba *hisi_hba) |
2749 | { | |
9c81e2cf | 2750 | u32 phy_state, sl_ctrl, txid_auto; |
f2f89c32 XC |
2751 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
2752 | struct hisi_sas_port *port = phy->port; | |
5473c060 JG |
2753 | |
2754 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1); | |
2755 | ||
5473c060 | 2756 | phy_state = hisi_sas_read32(hisi_hba, PHY_STATE); |
5473c060 JG |
2757 | hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0); |
2758 | ||
9c81e2cf JG |
2759 | sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); |
2760 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, | |
2761 | sl_ctrl & ~SL_CONTROL_CTA_MSK); | |
f2f89c32 XC |
2762 | if (port && !get_wideport_bitmap_v2_hw(hisi_hba, port->id)) |
2763 | if (!check_any_wideports_v2_hw(hisi_hba) && | |
2764 | timer_pending(&hisi_hba->timer)) | |
2765 | del_timer(&hisi_hba->timer); | |
9c81e2cf JG |
2766 | |
2767 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO); | |
2768 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
2769 | txid_auto | TXID_AUTO_CT3_MSK); | |
2770 | ||
5473c060 JG |
2771 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK); |
2772 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0); | |
2773 | ||
981843c6 | 2774 | return IRQ_HANDLED; |
5473c060 JG |
2775 | } |
2776 | ||
7911e66f JG |
2777 | static irqreturn_t int_phy_updown_v2_hw(int irq_no, void *p) |
2778 | { | |
2779 | struct hisi_hba *hisi_hba = p; | |
2780 | u32 irq_msk; | |
2781 | int phy_no = 0; | |
c16db736 | 2782 | irqreturn_t res = IRQ_NONE; |
7911e66f JG |
2783 | |
2784 | irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO) | |
2785 | >> HGC_INVLD_DQE_INFO_FB_CH0_OFF) & 0x1ff; | |
2786 | while (irq_msk) { | |
2787 | if (irq_msk & 1) { | |
981843c6 XT |
2788 | u32 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, |
2789 | CHL_INT0); | |
2790 | ||
2791 | switch (reg_value & (CHL_INT0_NOT_RDY_MSK | | |
2792 | CHL_INT0_SL_PHY_ENABLE_MSK)) { | |
7911e66f | 2793 | |
981843c6 | 2794 | case CHL_INT0_SL_PHY_ENABLE_MSK: |
7911e66f | 2795 | /* phy up */ |
981843c6 | 2796 | if (phy_up_v2_hw(phy_no, hisi_hba) == |
c16db736 XC |
2797 | IRQ_HANDLED) |
2798 | res = IRQ_HANDLED; | |
981843c6 | 2799 | break; |
7911e66f | 2800 | |
981843c6 | 2801 | case CHL_INT0_NOT_RDY_MSK: |
5473c060 | 2802 | /* phy down */ |
981843c6 | 2803 | if (phy_down_v2_hw(phy_no, hisi_hba) == |
c16db736 XC |
2804 | IRQ_HANDLED) |
2805 | res = IRQ_HANDLED; | |
981843c6 XT |
2806 | break; |
2807 | ||
2808 | case (CHL_INT0_NOT_RDY_MSK | | |
2809 | CHL_INT0_SL_PHY_ENABLE_MSK): | |
2810 | reg_value = hisi_sas_read32(hisi_hba, | |
2811 | PHY_STATE); | |
2812 | if (reg_value & BIT(phy_no)) { | |
2813 | /* phy up */ | |
2814 | if (phy_up_v2_hw(phy_no, hisi_hba) == | |
c16db736 XC |
2815 | IRQ_HANDLED) |
2816 | res = IRQ_HANDLED; | |
981843c6 XT |
2817 | } else { |
2818 | /* phy down */ | |
2819 | if (phy_down_v2_hw(phy_no, hisi_hba) == | |
c16db736 XC |
2820 | IRQ_HANDLED) |
2821 | res = IRQ_HANDLED; | |
5473c060 | 2822 | } |
981843c6 XT |
2823 | break; |
2824 | ||
2825 | default: | |
2826 | break; | |
2827 | } | |
2828 | ||
7911e66f JG |
2829 | } |
2830 | irq_msk >>= 1; | |
2831 | phy_no++; | |
2832 | } | |
2833 | ||
c16db736 | 2834 | return res; |
7911e66f JG |
2835 | } |
2836 | ||
d3bf3d84 JG |
2837 | static void phy_bcast_v2_hw(int phy_no, struct hisi_hba *hisi_hba) |
2838 | { | |
2839 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
2840 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
2841 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; | |
85080a25 | 2842 | u32 bcast_status; |
d3bf3d84 JG |
2843 | |
2844 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1); | |
85080a25 XC |
2845 | bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS); |
2846 | if (bcast_status & RX_BCAST_CHG_MSK) | |
2847 | sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); | |
d3bf3d84 JG |
2848 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, |
2849 | CHL_INT0_SL_RX_BCST_ACK_MSK); | |
2850 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0); | |
2851 | } | |
2852 | ||
2853 | static irqreturn_t int_chnl_int_v2_hw(int irq_no, void *p) | |
2854 | { | |
2855 | struct hisi_hba *hisi_hba = p; | |
11b75249 | 2856 | struct device *dev = hisi_hba->dev; |
d3bf3d84 JG |
2857 | u32 ent_msk, ent_tmp, irq_msk; |
2858 | int phy_no = 0; | |
2859 | ||
2860 | ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3); | |
2861 | ent_tmp = ent_msk; | |
2862 | ent_msk |= ENT_INT_SRC_MSK3_ENT95_MSK_MSK; | |
2863 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_msk); | |
2864 | ||
2865 | irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO) >> | |
2866 | HGC_INVLD_DQE_INFO_FB_CH3_OFF) & 0x1ff; | |
2867 | ||
2868 | while (irq_msk) { | |
2869 | if (irq_msk & (1 << phy_no)) { | |
2870 | u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2871 | CHL_INT0); | |
2872 | u32 irq_value1 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2873 | CHL_INT1); | |
2874 | u32 irq_value2 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2875 | CHL_INT2); | |
2876 | ||
2877 | if (irq_value1) { | |
2878 | if (irq_value1 & (CHL_INT1_DMAC_RX_ECC_ERR_MSK | | |
2879 | CHL_INT1_DMAC_TX_ECC_ERR_MSK)) | |
d3b688d3 XC |
2880 | panic("%s: DMAC RX/TX ecc bad error!\ |
2881 | (0x%x)", | |
2882 | dev_name(dev), irq_value1); | |
d3bf3d84 JG |
2883 | |
2884 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
2885 | CHL_INT1, irq_value1); | |
2886 | } | |
2887 | ||
2888 | if (irq_value2) | |
2889 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
2890 | CHL_INT2, irq_value2); | |
2891 | ||
2892 | ||
2893 | if (irq_value0) { | |
2894 | if (irq_value0 & CHL_INT0_SL_RX_BCST_ACK_MSK) | |
2895 | phy_bcast_v2_hw(phy_no, hisi_hba); | |
2896 | ||
2897 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
2898 | CHL_INT0, irq_value0 | |
2899 | & (~CHL_INT0_HOTPLUG_TOUT_MSK) | |
2900 | & (~CHL_INT0_SL_PHY_ENABLE_MSK) | |
2901 | & (~CHL_INT0_NOT_RDY_MSK)); | |
2902 | } | |
2903 | } | |
2904 | irq_msk &= ~(1 << phy_no); | |
2905 | phy_no++; | |
2906 | } | |
2907 | ||
2908 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_tmp); | |
2909 | ||
2910 | return IRQ_HANDLED; | |
2911 | } | |
2912 | ||
d3b688d3 XC |
2913 | static void |
2914 | one_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba, u32 irq_value) | |
2915 | { | |
11b75249 | 2916 | struct device *dev = hisi_hba->dev; |
2b383351 JG |
2917 | const struct hisi_sas_hw_error *ecc_error; |
2918 | u32 val; | |
2919 | int i; | |
d3b688d3 | 2920 | |
2b383351 JG |
2921 | for (i = 0; i < ARRAY_SIZE(one_bit_ecc_errors); i++) { |
2922 | ecc_error = &one_bit_ecc_errors[i]; | |
2923 | if (irq_value & ecc_error->irq_msk) { | |
2924 | val = hisi_sas_read32(hisi_hba, ecc_error->reg); | |
2925 | val &= ecc_error->msk; | |
2926 | val >>= ecc_error->shift; | |
2927 | dev_warn(dev, ecc_error->msg, val); | |
2928 | } | |
d3b688d3 | 2929 | } |
d3b688d3 XC |
2930 | } |
2931 | ||
2932 | static void multi_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba, | |
2933 | u32 irq_value) | |
2934 | { | |
11b75249 | 2935 | struct device *dev = hisi_hba->dev; |
2b383351 JG |
2936 | const struct hisi_sas_hw_error *ecc_error; |
2937 | u32 val; | |
2938 | int i; | |
d3b688d3 | 2939 | |
2b383351 JG |
2940 | for (i = 0; i < ARRAY_SIZE(multi_bit_ecc_errors); i++) { |
2941 | ecc_error = &multi_bit_ecc_errors[i]; | |
2942 | if (irq_value & ecc_error->irq_msk) { | |
2943 | val = hisi_sas_read32(hisi_hba, ecc_error->reg); | |
2944 | val &= ecc_error->msk; | |
2945 | val >>= ecc_error->shift; | |
2946 | dev_warn(dev, ecc_error->msg, irq_value, val); | |
2947 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
2948 | } | |
d3b688d3 XC |
2949 | } |
2950 | ||
e281f42f | 2951 | return; |
d3b688d3 XC |
2952 | } |
2953 | ||
2954 | static irqreturn_t fatal_ecc_int_v2_hw(int irq_no, void *p) | |
2955 | { | |
2956 | struct hisi_hba *hisi_hba = p; | |
2957 | u32 irq_value, irq_msk; | |
2958 | ||
2959 | irq_msk = hisi_sas_read32(hisi_hba, SAS_ECC_INTR_MSK); | |
2960 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk | 0xffffffff); | |
2961 | ||
2962 | irq_value = hisi_sas_read32(hisi_hba, SAS_ECC_INTR); | |
2963 | if (irq_value) { | |
2964 | one_bit_ecc_error_process_v2_hw(hisi_hba, irq_value); | |
2965 | multi_bit_ecc_error_process_v2_hw(hisi_hba, irq_value); | |
2966 | } | |
2967 | ||
2968 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR, irq_value); | |
2969 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk); | |
2970 | ||
2971 | return IRQ_HANDLED; | |
2972 | } | |
2973 | ||
2974 | #define AXI_ERR_NR 8 | |
2975 | static const char axi_err_info[AXI_ERR_NR][32] = { | |
2976 | "IOST_AXI_W_ERR", | |
2977 | "IOST_AXI_R_ERR", | |
2978 | "ITCT_AXI_W_ERR", | |
2979 | "ITCT_AXI_R_ERR", | |
2980 | "SATA_AXI_W_ERR", | |
2981 | "SATA_AXI_R_ERR", | |
2982 | "DQE_AXI_R_ERR", | |
2983 | "CQE_AXI_W_ERR" | |
2984 | }; | |
2985 | ||
2986 | #define FIFO_ERR_NR 5 | |
2987 | static const char fifo_err_info[FIFO_ERR_NR][32] = { | |
2988 | "CQE_WINFO_FIFO", | |
2989 | "CQE_MSG_FIFIO", | |
2990 | "GETDQE_FIFO", | |
2991 | "CMDP_FIFO", | |
2992 | "AWTCTRL_FIFO" | |
2993 | }; | |
2994 | ||
2995 | static irqreturn_t fatal_axi_int_v2_hw(int irq_no, void *p) | |
2996 | { | |
2997 | struct hisi_hba *hisi_hba = p; | |
2998 | u32 irq_value, irq_msk, err_value; | |
11b75249 | 2999 | struct device *dev = hisi_hba->dev; |
d3b688d3 XC |
3000 | |
3001 | irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3); | |
3002 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0xfffffffe); | |
3003 | ||
3004 | irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
3005 | if (irq_value) { | |
3006 | if (irq_value & BIT(ENT_INT_SRC3_WP_DEPTH_OFF)) { | |
3007 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
3008 | 1 << ENT_INT_SRC3_WP_DEPTH_OFF); | |
e281f42f | 3009 | dev_warn(dev, "write pointer and depth error (0x%x) \ |
d3b688d3 | 3010 | found!\n", |
e281f42f XC |
3011 | irq_value); |
3012 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
d3b688d3 XC |
3013 | } |
3014 | ||
3015 | if (irq_value & BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF)) { | |
3016 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
3017 | 1 << | |
3018 | ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF); | |
e281f42f XC |
3019 | dev_warn(dev, "iptt no match slot error (0x%x) found!\n", |
3020 | irq_value); | |
3021 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
d3b688d3 XC |
3022 | } |
3023 | ||
e281f42f XC |
3024 | if (irq_value & BIT(ENT_INT_SRC3_RP_DEPTH_OFF)) { |
3025 | dev_warn(dev, "read pointer and depth error (0x%x) \ | |
d3b688d3 | 3026 | found!\n", |
e281f42f XC |
3027 | irq_value); |
3028 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
3029 | } | |
d3b688d3 XC |
3030 | |
3031 | if (irq_value & BIT(ENT_INT_SRC3_AXI_OFF)) { | |
3032 | int i; | |
3033 | ||
3034 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
3035 | 1 << ENT_INT_SRC3_AXI_OFF); | |
3036 | err_value = hisi_sas_read32(hisi_hba, | |
3037 | HGC_AXI_FIFO_ERR_INFO); | |
3038 | ||
3039 | for (i = 0; i < AXI_ERR_NR; i++) { | |
e281f42f XC |
3040 | if (err_value & BIT(i)) { |
3041 | dev_warn(dev, "%s (0x%x) found!\n", | |
d3b688d3 | 3042 | axi_err_info[i], irq_value); |
e281f42f XC |
3043 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); |
3044 | } | |
d3b688d3 XC |
3045 | } |
3046 | } | |
3047 | ||
3048 | if (irq_value & BIT(ENT_INT_SRC3_FIFO_OFF)) { | |
3049 | int i; | |
3050 | ||
3051 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
3052 | 1 << ENT_INT_SRC3_FIFO_OFF); | |
3053 | err_value = hisi_sas_read32(hisi_hba, | |
3054 | HGC_AXI_FIFO_ERR_INFO); | |
3055 | ||
3056 | for (i = 0; i < FIFO_ERR_NR; i++) { | |
e281f42f XC |
3057 | if (err_value & BIT(AXI_ERR_NR + i)) { |
3058 | dev_warn(dev, "%s (0x%x) found!\n", | |
d3b688d3 | 3059 | fifo_err_info[i], irq_value); |
e281f42f XC |
3060 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); |
3061 | } | |
d3b688d3 XC |
3062 | } |
3063 | ||
3064 | } | |
3065 | ||
3066 | if (irq_value & BIT(ENT_INT_SRC3_LM_OFF)) { | |
3067 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
3068 | 1 << ENT_INT_SRC3_LM_OFF); | |
e281f42f XC |
3069 | dev_warn(dev, "LM add/fetch list error (0x%x) found!\n", |
3070 | irq_value); | |
3071 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
d3b688d3 XC |
3072 | } |
3073 | ||
3074 | if (irq_value & BIT(ENT_INT_SRC3_ABT_OFF)) { | |
3075 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
3076 | 1 << ENT_INT_SRC3_ABT_OFF); | |
e281f42f XC |
3077 | dev_warn(dev, "SAS_HGC_ABT fetch LM list error (0x%x) found!\n", |
3078 | irq_value); | |
3079 | queue_work(hisi_hba->wq, &hisi_hba->rst_work); | |
d3b688d3 | 3080 | } |
640acc9a XC |
3081 | |
3082 | if (irq_value & BIT(ENT_INT_SRC3_ITC_INT_OFF)) { | |
3083 | u32 reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR); | |
3084 | u32 dev_id = reg_val & ITCT_DEV_MSK; | |
3085 | struct hisi_sas_device *sas_dev = | |
3086 | &hisi_hba->devices[dev_id]; | |
3087 | ||
3088 | hisi_sas_write32(hisi_hba, ITCT_CLR, 0); | |
3089 | dev_dbg(dev, "clear ITCT ok\n"); | |
3090 | complete(sas_dev->completion); | |
3091 | } | |
d3b688d3 XC |
3092 | } |
3093 | ||
640acc9a | 3094 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, irq_value); |
d3b688d3 XC |
3095 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk); |
3096 | ||
3097 | return IRQ_HANDLED; | |
3098 | } | |
3099 | ||
d177c408 | 3100 | static void cq_tasklet_v2_hw(unsigned long val) |
31a9cfa6 | 3101 | { |
d177c408 | 3102 | struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val; |
31a9cfa6 JG |
3103 | struct hisi_hba *hisi_hba = cq->hisi_hba; |
3104 | struct hisi_sas_slot *slot; | |
3105 | struct hisi_sas_itct *itct; | |
3106 | struct hisi_sas_complete_v2_hdr *complete_queue; | |
d177c408 | 3107 | u32 rd_point = cq->rd_point, wr_point, dev_id; |
31a9cfa6 | 3108 | int queue = cq->id; |
b1a49412 | 3109 | struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; |
31a9cfa6 | 3110 | |
c7b9d369 XT |
3111 | if (unlikely(hisi_hba->reject_stp_links_msk)) |
3112 | phys_try_accept_stp_links_v2_hw(hisi_hba); | |
3113 | ||
31a9cfa6 | 3114 | complete_queue = hisi_hba->complete_hdr[queue]; |
31a9cfa6 | 3115 | |
b1a49412 | 3116 | spin_lock(&dq->lock); |
31a9cfa6 JG |
3117 | wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR + |
3118 | (0x14 * queue)); | |
3119 | ||
3120 | while (rd_point != wr_point) { | |
3121 | struct hisi_sas_complete_v2_hdr *complete_hdr; | |
3122 | int iptt; | |
3123 | ||
3124 | complete_hdr = &complete_queue[rd_point]; | |
3125 | ||
3126 | /* Check for NCQ completion */ | |
3127 | if (complete_hdr->act) { | |
3128 | u32 act_tmp = complete_hdr->act; | |
3129 | int ncq_tag_count = ffs(act_tmp); | |
3130 | ||
3131 | dev_id = (complete_hdr->dw1 & CMPLT_HDR_DEV_ID_MSK) >> | |
3132 | CMPLT_HDR_DEV_ID_OFF; | |
3133 | itct = &hisi_hba->itct[dev_id]; | |
3134 | ||
3135 | /* The NCQ tags are held in the itct header */ | |
3136 | while (ncq_tag_count) { | |
3137 | __le64 *ncq_tag = &itct->qw4_15[0]; | |
3138 | ||
3139 | ncq_tag_count -= 1; | |
3140 | iptt = (ncq_tag[ncq_tag_count / 5] | |
3141 | >> (ncq_tag_count % 5) * 12) & 0xfff; | |
3142 | ||
3143 | slot = &hisi_hba->slot_info[iptt]; | |
3144 | slot->cmplt_queue_slot = rd_point; | |
3145 | slot->cmplt_queue = queue; | |
405314df | 3146 | slot_complete_v2_hw(hisi_hba, slot); |
31a9cfa6 JG |
3147 | |
3148 | act_tmp &= ~(1 << ncq_tag_count); | |
3149 | ncq_tag_count = ffs(act_tmp); | |
3150 | } | |
3151 | } else { | |
3152 | iptt = (complete_hdr->dw1) & CMPLT_HDR_IPTT_MSK; | |
3153 | slot = &hisi_hba->slot_info[iptt]; | |
3154 | slot->cmplt_queue_slot = rd_point; | |
3155 | slot->cmplt_queue = queue; | |
405314df | 3156 | slot_complete_v2_hw(hisi_hba, slot); |
31a9cfa6 JG |
3157 | } |
3158 | ||
3159 | if (++rd_point >= HISI_SAS_QUEUE_SLOTS) | |
3160 | rd_point = 0; | |
3161 | } | |
3162 | ||
3163 | /* update rd_point */ | |
e6c346f3 | 3164 | cq->rd_point = rd_point; |
31a9cfa6 | 3165 | hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point); |
b1a49412 | 3166 | spin_unlock(&dq->lock); |
d177c408 JG |
3167 | } |
3168 | ||
3169 | static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p) | |
3170 | { | |
3171 | struct hisi_sas_cq *cq = p; | |
3172 | struct hisi_hba *hisi_hba = cq->hisi_hba; | |
3173 | int queue = cq->id; | |
3174 | ||
3175 | hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue); | |
3176 | ||
3177 | tasklet_schedule(&cq->tasklet); | |
3178 | ||
31a9cfa6 JG |
3179 | return IRQ_HANDLED; |
3180 | } | |
3181 | ||
d43f9cdb JG |
3182 | static irqreturn_t sata_int_v2_hw(int irq_no, void *p) |
3183 | { | |
3184 | struct hisi_sas_phy *phy = p; | |
3185 | struct hisi_hba *hisi_hba = phy->hisi_hba; | |
3186 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
11b75249 | 3187 | struct device *dev = hisi_hba->dev; |
d43f9cdb JG |
3188 | struct hisi_sas_initial_fis *initial_fis; |
3189 | struct dev_to_host_fis *fis; | |
3190 | u32 ent_tmp, ent_msk, ent_int, port_id, link_rate, hard_phy_linkrate; | |
3191 | irqreturn_t res = IRQ_HANDLED; | |
3192 | u8 attached_sas_addr[SAS_ADDR_SIZE] = {0}; | |
11826e5d | 3193 | int phy_no, offset; |
d43f9cdb JG |
3194 | |
3195 | phy_no = sas_phy->id; | |
3196 | initial_fis = &hisi_hba->initial_fis[phy_no]; | |
3197 | fis = &initial_fis->fis; | |
3198 | ||
11826e5d JG |
3199 | offset = 4 * (phy_no / 4); |
3200 | ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK1 + offset); | |
3201 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset, | |
3202 | ent_msk | 1 << ((phy_no % 4) * 8)); | |
d43f9cdb | 3203 | |
11826e5d JG |
3204 | ent_int = hisi_sas_read32(hisi_hba, ENT_INT_SRC1 + offset); |
3205 | ent_tmp = ent_int & (1 << (ENT_INT_SRC1_D2H_FIS_CH1_OFF * | |
3206 | (phy_no % 4))); | |
d43f9cdb JG |
3207 | ent_int >>= ENT_INT_SRC1_D2H_FIS_CH1_OFF * (phy_no % 4); |
3208 | if ((ent_int & ENT_INT_SRC1_D2H_FIS_CH0_MSK) == 0) { | |
3209 | dev_warn(dev, "sata int: phy%d did not receive FIS\n", phy_no); | |
d43f9cdb JG |
3210 | res = IRQ_NONE; |
3211 | goto end; | |
04708ff4 XC |
3212 | } |
3213 | ||
3214 | /* check ERR bit of Status Register */ | |
3215 | if (fis->status & ATA_ERR) { | |
3216 | dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n", phy_no, | |
3217 | fis->status); | |
3218 | disable_phy_v2_hw(hisi_hba, phy_no); | |
3219 | enable_phy_v2_hw(hisi_hba, phy_no); | |
3220 | res = IRQ_NONE; | |
3221 | goto end; | |
d43f9cdb JG |
3222 | } |
3223 | ||
3224 | if (unlikely(phy_no == 8)) { | |
3225 | u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
3226 | ||
3227 | port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >> | |
3228 | PORT_STATE_PHY8_PORT_NUM_OFF; | |
3229 | link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >> | |
3230 | PORT_STATE_PHY8_CONN_RATE_OFF; | |
3231 | } else { | |
3232 | port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
3233 | port_id = (port_id >> (4 * phy_no)) & 0xf; | |
3234 | link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE); | |
3235 | link_rate = (link_rate >> (phy_no * 4)) & 0xf; | |
3236 | } | |
3237 | ||
3238 | if (port_id == 0xf) { | |
3239 | dev_err(dev, "sata int: phy%d invalid portid\n", phy_no); | |
3240 | res = IRQ_NONE; | |
3241 | goto end; | |
3242 | } | |
3243 | ||
3244 | sas_phy->linkrate = link_rate; | |
3245 | hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no, | |
3246 | HARD_PHY_LINKRATE); | |
3247 | phy->maximum_linkrate = hard_phy_linkrate & 0xf; | |
3248 | phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf; | |
3249 | ||
3250 | sas_phy->oob_mode = SATA_OOB_MODE; | |
3251 | /* Make up some unique SAS address */ | |
3252 | attached_sas_addr[0] = 0x50; | |
3253 | attached_sas_addr[7] = phy_no; | |
3254 | memcpy(sas_phy->attached_sas_addr, attached_sas_addr, SAS_ADDR_SIZE); | |
3255 | memcpy(sas_phy->frame_rcvd, fis, sizeof(struct dev_to_host_fis)); | |
3256 | dev_info(dev, "sata int phyup: phy%d link_rate=%d\n", phy_no, link_rate); | |
3257 | phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); | |
3258 | phy->port_id = port_id; | |
3259 | phy->phy_type |= PORT_TYPE_SATA; | |
3260 | phy->phy_attached = 1; | |
3261 | phy->identify.device_type = SAS_SATA_DEV; | |
3262 | phy->frame_rcvd_size = sizeof(struct dev_to_host_fis); | |
3263 | phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; | |
3264 | queue_work(hisi_hba->wq, &phy->phyup_ws); | |
3265 | ||
3266 | end: | |
11826e5d JG |
3267 | hisi_sas_write32(hisi_hba, ENT_INT_SRC1 + offset, ent_tmp); |
3268 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset, ent_msk); | |
d43f9cdb JG |
3269 | |
3270 | return res; | |
3271 | } | |
3272 | ||
7911e66f JG |
3273 | static irq_handler_t phy_interrupts[HISI_SAS_PHY_INT_NR] = { |
3274 | int_phy_updown_v2_hw, | |
d3bf3d84 | 3275 | int_chnl_int_v2_hw, |
7911e66f JG |
3276 | }; |
3277 | ||
d3b688d3 XC |
3278 | static irq_handler_t fatal_interrupts[HISI_SAS_FATAL_INT_NR] = { |
3279 | fatal_ecc_int_v2_hw, | |
3280 | fatal_axi_int_v2_hw | |
3281 | }; | |
3282 | ||
7911e66f JG |
3283 | /** |
3284 | * There is a limitation in the hip06 chipset that we need | |
3285 | * to map in all mbigen interrupts, even if they are not used. | |
3286 | */ | |
3287 | static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) | |
3288 | { | |
11b75249 | 3289 | struct platform_device *pdev = hisi_hba->platform_dev; |
7911e66f | 3290 | struct device *dev = &pdev->dev; |
8a253888 XC |
3291 | int irq, rc, irq_map[128]; |
3292 | int i, phy_no, fatal_no, queue_no, k; | |
7911e66f JG |
3293 | |
3294 | for (i = 0; i < 128; i++) | |
3295 | irq_map[i] = platform_get_irq(pdev, i); | |
3296 | ||
3297 | for (i = 0; i < HISI_SAS_PHY_INT_NR; i++) { | |
8a253888 | 3298 | irq = irq_map[i + 1]; /* Phy up/down is irq1 */ |
7911e66f JG |
3299 | rc = devm_request_irq(dev, irq, phy_interrupts[i], 0, |
3300 | DRV_NAME " phy", hisi_hba); | |
3301 | if (rc) { | |
3302 | dev_err(dev, "irq init: could not request " | |
3303 | "phy interrupt %d, rc=%d\n", | |
3304 | irq, rc); | |
8a253888 XC |
3305 | rc = -ENOENT; |
3306 | goto free_phy_int_irqs; | |
7911e66f JG |
3307 | } |
3308 | } | |
3309 | ||
8a253888 XC |
3310 | for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { |
3311 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
d43f9cdb | 3312 | |
8a253888 | 3313 | irq = irq_map[phy_no + 72]; |
d43f9cdb JG |
3314 | rc = devm_request_irq(dev, irq, sata_int_v2_hw, 0, |
3315 | DRV_NAME " sata", phy); | |
3316 | if (rc) { | |
3317 | dev_err(dev, "irq init: could not request " | |
3318 | "sata interrupt %d, rc=%d\n", | |
3319 | irq, rc); | |
8a253888 XC |
3320 | rc = -ENOENT; |
3321 | goto free_sata_int_irqs; | |
d43f9cdb JG |
3322 | } |
3323 | } | |
31a9cfa6 | 3324 | |
8a253888 XC |
3325 | for (fatal_no = 0; fatal_no < HISI_SAS_FATAL_INT_NR; fatal_no++) { |
3326 | irq = irq_map[fatal_no + 81]; | |
3327 | rc = devm_request_irq(dev, irq, fatal_interrupts[fatal_no], 0, | |
d3b688d3 XC |
3328 | DRV_NAME " fatal", hisi_hba); |
3329 | if (rc) { | |
3330 | dev_err(dev, | |
3331 | "irq init: could not request fatal interrupt %d, rc=%d\n", | |
3332 | irq, rc); | |
8a253888 XC |
3333 | rc = -ENOENT; |
3334 | goto free_fatal_int_irqs; | |
d3b688d3 XC |
3335 | } |
3336 | } | |
3337 | ||
8a253888 XC |
3338 | for (queue_no = 0; queue_no < hisi_hba->queue_count; queue_no++) { |
3339 | struct hisi_sas_cq *cq = &hisi_hba->cq[queue_no]; | |
d177c408 | 3340 | struct tasklet_struct *t = &cq->tasklet; |
31a9cfa6 | 3341 | |
8a253888 | 3342 | irq = irq_map[queue_no + 96]; |
31a9cfa6 | 3343 | rc = devm_request_irq(dev, irq, cq_interrupt_v2_hw, 0, |
8a253888 | 3344 | DRV_NAME " cq", cq); |
31a9cfa6 JG |
3345 | if (rc) { |
3346 | dev_err(dev, | |
3347 | "irq init: could not request cq interrupt %d, rc=%d\n", | |
3348 | irq, rc); | |
8a253888 XC |
3349 | rc = -ENOENT; |
3350 | goto free_cq_int_irqs; | |
31a9cfa6 | 3351 | } |
d177c408 | 3352 | tasklet_init(t, cq_tasklet_v2_hw, (unsigned long)cq); |
31a9cfa6 JG |
3353 | } |
3354 | ||
7911e66f | 3355 | return 0; |
8a253888 XC |
3356 | |
3357 | free_cq_int_irqs: | |
3358 | for (k = 0; k < queue_no; k++) { | |
3359 | struct hisi_sas_cq *cq = &hisi_hba->cq[k]; | |
3360 | ||
3361 | free_irq(irq_map[k + 96], cq); | |
3362 | tasklet_kill(&cq->tasklet); | |
3363 | } | |
3364 | free_fatal_int_irqs: | |
3365 | for (k = 0; k < fatal_no; k++) | |
3366 | free_irq(irq_map[k + 81], hisi_hba); | |
3367 | free_sata_int_irqs: | |
3368 | for (k = 0; k < phy_no; k++) { | |
3369 | struct hisi_sas_phy *phy = &hisi_hba->phy[k]; | |
3370 | ||
3371 | free_irq(irq_map[k + 72], phy); | |
3372 | } | |
3373 | free_phy_int_irqs: | |
3374 | for (k = 0; k < i; k++) | |
3375 | free_irq(irq_map[k + 1], hisi_hba); | |
3376 | return rc; | |
7911e66f JG |
3377 | } |
3378 | ||
94eac9e1 JG |
3379 | static int hisi_sas_v2_init(struct hisi_hba *hisi_hba) |
3380 | { | |
3381 | int rc; | |
3382 | ||
32ccba52 XT |
3383 | memset(hisi_hba->sata_dev_bitmap, 0, sizeof(hisi_hba->sata_dev_bitmap)); |
3384 | ||
94eac9e1 JG |
3385 | rc = hw_init_v2_hw(hisi_hba); |
3386 | if (rc) | |
3387 | return rc; | |
3388 | ||
7911e66f JG |
3389 | rc = interrupt_init_v2_hw(hisi_hba); |
3390 | if (rc) | |
3391 | return rc; | |
3392 | ||
94eac9e1 JG |
3393 | return 0; |
3394 | } | |
3395 | ||
06ec0fb9 XC |
3396 | static void interrupt_disable_v2_hw(struct hisi_hba *hisi_hba) |
3397 | { | |
11b75249 | 3398 | struct platform_device *pdev = hisi_hba->platform_dev; |
06ec0fb9 XC |
3399 | int i; |
3400 | ||
3401 | for (i = 0; i < hisi_hba->queue_count; i++) | |
3402 | hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1); | |
3403 | ||
3404 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff); | |
3405 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff); | |
3406 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff); | |
3407 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff); | |
3408 | ||
3409 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
3410 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff); | |
3411 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff); | |
3412 | } | |
3413 | ||
3414 | for (i = 0; i < 128; i++) | |
3415 | synchronize_irq(platform_get_irq(pdev, i)); | |
3416 | } | |
3417 | ||
917d3bda XT |
3418 | |
3419 | static u32 get_phys_state_v2_hw(struct hisi_hba *hisi_hba) | |
3420 | { | |
3421 | return hisi_sas_read32(hisi_hba, PHY_STATE); | |
3422 | } | |
3423 | ||
06ec0fb9 XC |
3424 | static int soft_reset_v2_hw(struct hisi_hba *hisi_hba) |
3425 | { | |
11b75249 | 3426 | struct device *dev = hisi_hba->dev; |
06ec0fb9 | 3427 | int rc, cnt; |
06ec0fb9 XC |
3428 | |
3429 | interrupt_disable_v2_hw(hisi_hba); | |
3430 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0); | |
3431 | ||
3432 | stop_phys_v2_hw(hisi_hba); | |
3433 | ||
3434 | mdelay(10); | |
3435 | ||
3436 | hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + AM_CTRL_GLOBAL, 0x1); | |
3437 | ||
3438 | /* wait until bus idle */ | |
3439 | cnt = 0; | |
3440 | while (1) { | |
3441 | u32 status = hisi_sas_read32_relaxed(hisi_hba, | |
3442 | AXI_MASTER_CFG_BASE + AM_CURR_TRANS_RETURN); | |
3443 | ||
3444 | if (status == 0x3) | |
3445 | break; | |
3446 | ||
3447 | udelay(10); | |
3448 | if (cnt++ > 10) { | |
3449 | dev_info(dev, "wait axi bus state to idle timeout!\n"); | |
3450 | return -1; | |
3451 | } | |
3452 | } | |
3453 | ||
3454 | hisi_sas_init_mem(hisi_hba); | |
3455 | ||
3456 | rc = hw_init_v2_hw(hisi_hba); | |
3457 | if (rc) | |
3458 | return rc; | |
3459 | ||
c7b9d369 XT |
3460 | phys_reject_stp_links_v2_hw(hisi_hba); |
3461 | ||
06ec0fb9 XC |
3462 | return 0; |
3463 | } | |
3464 | ||
3417ba8a | 3465 | static const struct hisi_sas_hw hisi_sas_v2_hw = { |
94eac9e1 | 3466 | .hw_init = hisi_sas_v2_init, |
85b2c3c0 | 3467 | .setup_itct = setup_itct_v2_hw, |
330fa7f3 | 3468 | .slot_index_alloc = slot_index_alloc_quirk_v2_hw, |
b2bdaf2b | 3469 | .alloc_dev = alloc_dev_quirk_v2_hw, |
7911e66f | 3470 | .sl_notify = sl_notify_v2_hw, |
5473c060 | 3471 | .get_wideport_bitmap = get_wideport_bitmap_v2_hw, |
85b2c3c0 | 3472 | .free_device = free_device_v2_hw, |
c2d89392 | 3473 | .prep_smp = prep_smp_v2_hw, |
8c36e31d | 3474 | .prep_ssp = prep_ssp_v2_hw, |
6f2ff1a1 | 3475 | .prep_stp = prep_ata_v2_hw, |
a3e665d9 | 3476 | .prep_abort = prep_abort_v2_hw, |
8c36e31d JG |
3477 | .get_free_slot = get_free_slot_v2_hw, |
3478 | .start_delivery = start_delivery_v2_hw, | |
31a9cfa6 | 3479 | .slot_complete = slot_complete_v2_hw, |
396b8044 | 3480 | .phys_init = phys_init_v2_hw, |
63fb11b8 JG |
3481 | .phy_enable = enable_phy_v2_hw, |
3482 | .phy_disable = disable_phy_v2_hw, | |
3483 | .phy_hard_reset = phy_hard_reset_v2_hw, | |
c52108c6 | 3484 | .get_events = phy_get_events_v2_hw, |
2ae75787 XC |
3485 | .phy_set_linkrate = phy_set_linkrate_v2_hw, |
3486 | .phy_get_max_linkrate = phy_get_max_linkrate_v2_hw, | |
94eac9e1 JG |
3487 | .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V2_HW, |
3488 | .complete_hdr_size = sizeof(struct hisi_sas_complete_v2_hdr), | |
06ec0fb9 | 3489 | .soft_reset = soft_reset_v2_hw, |
917d3bda | 3490 | .get_phys_state = get_phys_state_v2_hw, |
3417ba8a JG |
3491 | }; |
3492 | ||
3493 | static int hisi_sas_v2_probe(struct platform_device *pdev) | |
3494 | { | |
26f3ba96 JG |
3495 | /* |
3496 | * Check if we should defer the probe before we probe the | |
3497 | * upper layer, as it's hard to defer later on. | |
3498 | */ | |
3499 | int ret = platform_get_irq(pdev, 0); | |
3500 | ||
3501 | if (ret < 0) { | |
3502 | if (ret != -EPROBE_DEFER) | |
3503 | dev_err(&pdev->dev, "cannot obtain irq\n"); | |
3504 | return ret; | |
3505 | } | |
3506 | ||
3417ba8a JG |
3507 | return hisi_sas_probe(pdev, &hisi_sas_v2_hw); |
3508 | } | |
3509 | ||
3510 | static int hisi_sas_v2_remove(struct platform_device *pdev) | |
3511 | { | |
f2f89c32 XC |
3512 | struct sas_ha_struct *sha = platform_get_drvdata(pdev); |
3513 | struct hisi_hba *hisi_hba = sha->lldd_ha; | |
8a253888 | 3514 | int i; |
f2f89c32 XC |
3515 | |
3516 | if (timer_pending(&hisi_hba->timer)) | |
3517 | del_timer(&hisi_hba->timer); | |
3518 | ||
8a253888 XC |
3519 | for (i = 0; i < hisi_hba->queue_count; i++) { |
3520 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; | |
3521 | ||
3522 | tasklet_kill(&cq->tasklet); | |
3523 | } | |
3524 | ||
3417ba8a JG |
3525 | return hisi_sas_remove(pdev); |
3526 | } | |
3527 | ||
3528 | static const struct of_device_id sas_v2_of_match[] = { | |
3529 | { .compatible = "hisilicon,hip06-sas-v2",}, | |
039ae102 | 3530 | { .compatible = "hisilicon,hip07-sas-v2",}, |
3417ba8a JG |
3531 | {}, |
3532 | }; | |
3533 | MODULE_DEVICE_TABLE(of, sas_v2_of_match); | |
3534 | ||
50408712 JG |
3535 | static const struct acpi_device_id sas_v2_acpi_match[] = { |
3536 | { "HISI0162", 0 }, | |
3537 | { } | |
3538 | }; | |
3539 | ||
3540 | MODULE_DEVICE_TABLE(acpi, sas_v2_acpi_match); | |
3541 | ||
3417ba8a JG |
3542 | static struct platform_driver hisi_sas_v2_driver = { |
3543 | .probe = hisi_sas_v2_probe, | |
3544 | .remove = hisi_sas_v2_remove, | |
3545 | .driver = { | |
3546 | .name = DRV_NAME, | |
3547 | .of_match_table = sas_v2_of_match, | |
50408712 | 3548 | .acpi_match_table = ACPI_PTR(sas_v2_acpi_match), |
3417ba8a JG |
3549 | }, |
3550 | }; | |
3551 | ||
3552 | module_platform_driver(hisi_sas_v2_driver); | |
3553 | ||
3554 | MODULE_LICENSE("GPL"); | |
3555 | MODULE_AUTHOR("John Garry <john.garry@huawei.com>"); | |
3556 | MODULE_DESCRIPTION("HISILICON SAS controller v2 hw driver"); | |
3557 | MODULE_ALIAS("platform:" DRV_NAME); |