]>
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) | |
85080a25 XC |
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) | |
45c901b8 JG |
210 | #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4) |
211 | #define RX_IDAF_DWORD1 (PORT_BASE + 0xc8) | |
212 | #define RX_IDAF_DWORD2 (PORT_BASE + 0xcc) | |
213 | #define RX_IDAF_DWORD3 (PORT_BASE + 0xd0) | |
214 | #define RX_IDAF_DWORD4 (PORT_BASE + 0xd4) | |
215 | #define RX_IDAF_DWORD5 (PORT_BASE + 0xd8) | |
216 | #define RX_IDAF_DWORD6 (PORT_BASE + 0xdc) | |
217 | #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc) | |
f2f89c32 | 218 | #define CON_CONTROL (PORT_BASE + 0x118) |
45c901b8 JG |
219 | #define DONE_RECEIVED_TIME (PORT_BASE + 0x11c) |
220 | #define CHL_INT0 (PORT_BASE + 0x1b4) | |
221 | #define CHL_INT0_HOTPLUG_TOUT_OFF 0 | |
222 | #define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF) | |
223 | #define CHL_INT0_SL_RX_BCST_ACK_OFF 1 | |
224 | #define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF) | |
225 | #define CHL_INT0_SL_PHY_ENABLE_OFF 2 | |
226 | #define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF) | |
227 | #define CHL_INT0_NOT_RDY_OFF 4 | |
228 | #define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF) | |
229 | #define CHL_INT0_PHY_RDY_OFF 5 | |
230 | #define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF) | |
231 | #define CHL_INT1 (PORT_BASE + 0x1b8) | |
232 | #define CHL_INT1_DMAC_TX_ECC_ERR_OFF 15 | |
233 | #define CHL_INT1_DMAC_TX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_TX_ECC_ERR_OFF) | |
234 | #define CHL_INT1_DMAC_RX_ECC_ERR_OFF 17 | |
235 | #define CHL_INT1_DMAC_RX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_RX_ECC_ERR_OFF) | |
236 | #define CHL_INT2 (PORT_BASE + 0x1bc) | |
237 | #define CHL_INT0_MSK (PORT_BASE + 0x1c0) | |
238 | #define CHL_INT1_MSK (PORT_BASE + 0x1c4) | |
239 | #define CHL_INT2_MSK (PORT_BASE + 0x1c8) | |
240 | #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0) | |
241 | #define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0) | |
242 | #define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4) | |
243 | #define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8) | |
244 | #define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc) | |
245 | #define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0) | |
246 | #define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4) | |
247 | #define DMA_TX_STATUS (PORT_BASE + 0x2d0) | |
248 | #define DMA_TX_STATUS_BUSY_OFF 0 | |
249 | #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF) | |
250 | #define DMA_RX_STATUS (PORT_BASE + 0x2e8) | |
251 | #define DMA_RX_STATUS_BUSY_OFF 0 | |
252 | #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF) | |
253 | ||
254 | #define AXI_CFG (0x5100) | |
255 | #define AM_CFG_MAX_TRANS (0x5010) | |
256 | #define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014) | |
257 | ||
258 | /* HW dma structures */ | |
259 | /* Delivery queue header */ | |
260 | /* dw0 */ | |
a3e665d9 JG |
261 | #define CMD_HDR_ABORT_FLAG_OFF 0 |
262 | #define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF) | |
263 | #define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2 | |
264 | #define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF) | |
45c901b8 JG |
265 | #define CMD_HDR_RESP_REPORT_OFF 5 |
266 | #define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF) | |
267 | #define CMD_HDR_TLR_CTRL_OFF 6 | |
268 | #define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF) | |
269 | #define CMD_HDR_PORT_OFF 18 | |
270 | #define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF) | |
271 | #define CMD_HDR_PRIORITY_OFF 27 | |
272 | #define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF) | |
273 | #define CMD_HDR_CMD_OFF 29 | |
274 | #define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF) | |
275 | /* dw1 */ | |
276 | #define CMD_HDR_DIR_OFF 5 | |
277 | #define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF) | |
278 | #define CMD_HDR_RESET_OFF 7 | |
279 | #define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF) | |
280 | #define CMD_HDR_VDTL_OFF 10 | |
281 | #define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF) | |
282 | #define CMD_HDR_FRAME_TYPE_OFF 11 | |
283 | #define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF) | |
284 | #define CMD_HDR_DEV_ID_OFF 16 | |
285 | #define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF) | |
286 | /* dw2 */ | |
287 | #define CMD_HDR_CFL_OFF 0 | |
288 | #define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF) | |
289 | #define CMD_HDR_NCQ_TAG_OFF 10 | |
290 | #define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF) | |
291 | #define CMD_HDR_MRFL_OFF 15 | |
292 | #define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF) | |
293 | #define CMD_HDR_SG_MOD_OFF 24 | |
294 | #define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF) | |
295 | #define CMD_HDR_FIRST_BURST_OFF 26 | |
296 | #define CMD_HDR_FIRST_BURST_MSK (0x1 << CMD_HDR_SG_MOD_OFF) | |
297 | /* dw3 */ | |
298 | #define CMD_HDR_IPTT_OFF 0 | |
299 | #define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF) | |
300 | /* dw6 */ | |
301 | #define CMD_HDR_DIF_SGL_LEN_OFF 0 | |
302 | #define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF) | |
303 | #define CMD_HDR_DATA_SGL_LEN_OFF 16 | |
304 | #define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF) | |
a3e665d9 JG |
305 | #define CMD_HDR_ABORT_IPTT_OFF 16 |
306 | #define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF) | |
45c901b8 JG |
307 | |
308 | /* Completion header */ | |
309 | /* dw0 */ | |
310 | #define CMPLT_HDR_RSPNS_XFRD_OFF 10 | |
311 | #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF) | |
312 | #define CMPLT_HDR_ERX_OFF 12 | |
313 | #define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF) | |
df032d0e JG |
314 | #define CMPLT_HDR_ABORT_STAT_OFF 13 |
315 | #define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF) | |
316 | /* abort_stat */ | |
317 | #define STAT_IO_NOT_VALID 0x1 | |
318 | #define STAT_IO_NO_DEVICE 0x2 | |
319 | #define STAT_IO_COMPLETE 0x3 | |
320 | #define STAT_IO_ABORTED 0x4 | |
45c901b8 JG |
321 | /* dw1 */ |
322 | #define CMPLT_HDR_IPTT_OFF 0 | |
323 | #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF) | |
324 | #define CMPLT_HDR_DEV_ID_OFF 16 | |
325 | #define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF) | |
326 | ||
327 | /* ITCT header */ | |
328 | /* qw0 */ | |
329 | #define ITCT_HDR_DEV_TYPE_OFF 0 | |
330 | #define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF) | |
331 | #define ITCT_HDR_VALID_OFF 2 | |
332 | #define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF) | |
333 | #define ITCT_HDR_MCR_OFF 5 | |
334 | #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF) | |
335 | #define ITCT_HDR_VLN_OFF 9 | |
336 | #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF) | |
337 | #define ITCT_HDR_PORT_ID_OFF 28 | |
338 | #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF) | |
339 | /* qw2 */ | |
340 | #define ITCT_HDR_INLT_OFF 0 | |
341 | #define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF) | |
342 | #define ITCT_HDR_BITLT_OFF 16 | |
343 | #define ITCT_HDR_BITLT_MSK (0xffffULL << ITCT_HDR_BITLT_OFF) | |
344 | #define ITCT_HDR_MCTLT_OFF 32 | |
345 | #define ITCT_HDR_MCTLT_MSK (0xffffULL << ITCT_HDR_MCTLT_OFF) | |
346 | #define ITCT_HDR_RTOLT_OFF 48 | |
347 | #define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF) | |
348 | ||
d3b688d3 XC |
349 | #define HISI_SAS_FATAL_INT_NR 2 |
350 | ||
94eac9e1 JG |
351 | struct hisi_sas_complete_v2_hdr { |
352 | __le32 dw0; | |
353 | __le32 dw1; | |
354 | __le32 act; | |
355 | __le32 dw3; | |
356 | }; | |
357 | ||
e8fed0e9 JG |
358 | struct hisi_sas_err_record_v2 { |
359 | /* dw0 */ | |
360 | __le32 trans_tx_fail_type; | |
361 | ||
362 | /* dw1 */ | |
363 | __le32 trans_rx_fail_type; | |
364 | ||
365 | /* dw2 */ | |
366 | __le16 dma_tx_err_type; | |
367 | __le16 sipc_rx_err_type; | |
368 | ||
369 | /* dw3 */ | |
370 | __le32 dma_rx_err_type; | |
371 | }; | |
372 | ||
7911e66f JG |
373 | enum { |
374 | HISI_SAS_PHY_PHY_UPDOWN, | |
d3bf3d84 | 375 | HISI_SAS_PHY_CHNL_INT, |
7911e66f JG |
376 | HISI_SAS_PHY_INT_NR |
377 | }; | |
378 | ||
e8fed0e9 JG |
379 | enum { |
380 | TRANS_TX_FAIL_BASE = 0x0, /* dw0 */ | |
381 | TRANS_RX_FAIL_BASE = 0x100, /* dw1 */ | |
382 | DMA_TX_ERR_BASE = 0x200, /* dw2 bit 15-0 */ | |
383 | SIPC_RX_ERR_BASE = 0x300, /* dw2 bit 31-16*/ | |
384 | DMA_RX_ERR_BASE = 0x400, /* dw3 */ | |
385 | ||
386 | /* trans tx*/ | |
387 | TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS = TRANS_TX_FAIL_BASE, /* 0x0 */ | |
388 | TRANS_TX_ERR_PHY_NOT_ENABLE, /* 0x1 */ | |
389 | TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION, /* 0x2 */ | |
390 | TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION, /* 0x3 */ | |
391 | TRANS_TX_OPEN_CNX_ERR_BY_OTHER, /* 0x4 */ | |
392 | RESERVED0, /* 0x5 */ | |
393 | TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT, /* 0x6 */ | |
394 | TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY, /* 0x7 */ | |
395 | TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED, /* 0x8 */ | |
396 | TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED, /* 0x9 */ | |
397 | TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION, /* 0xa */ | |
398 | TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD, /* 0xb */ | |
399 | TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER, /* 0xc */ | |
400 | TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED, /* 0xd */ | |
401 | TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT, /* 0xe */ | |
402 | TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION, /* 0xf */ | |
403 | TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED, /* 0x10 */ | |
404 | TRANS_TX_ERR_FRAME_TXED, /* 0x11 */ | |
405 | TRANS_TX_ERR_WITH_BREAK_TIMEOUT, /* 0x12 */ | |
406 | TRANS_TX_ERR_WITH_BREAK_REQUEST, /* 0x13 */ | |
407 | TRANS_TX_ERR_WITH_BREAK_RECEVIED, /* 0x14 */ | |
408 | TRANS_TX_ERR_WITH_CLOSE_TIMEOUT, /* 0x15 */ | |
409 | TRANS_TX_ERR_WITH_CLOSE_NORMAL, /* 0x16 for ssp*/ | |
410 | TRANS_TX_ERR_WITH_CLOSE_PHYDISALE, /* 0x17 */ | |
411 | TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT, /* 0x18 */ | |
412 | TRANS_TX_ERR_WITH_CLOSE_COMINIT, /* 0x19 */ | |
413 | TRANS_TX_ERR_WITH_NAK_RECEVIED, /* 0x1a for ssp*/ | |
414 | TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT, /* 0x1b for ssp*/ | |
415 | /*IO_TX_ERR_WITH_R_ERR_RECEVIED, [> 0x1b for sata/stp<] */ | |
416 | TRANS_TX_ERR_WITH_CREDIT_TIMEOUT, /* 0x1c for ssp */ | |
417 | /*IO_RX_ERR_WITH_SATA_DEVICE_LOST 0x1c for sata/stp */ | |
418 | TRANS_TX_ERR_WITH_IPTT_CONFLICT, /* 0x1d for ssp/smp */ | |
419 | TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS, /* 0x1e */ | |
420 | /*IO_TX_ERR_WITH_SYNC_RXD, [> 0x1e <] for sata/stp */ | |
421 | TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT, /* 0x1f for sata/stp */ | |
422 | ||
423 | /* trans rx */ | |
424 | TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR = TRANS_RX_FAIL_BASE, /* 0x100 */ | |
425 | TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR, /* 0x101 for sata/stp */ | |
426 | TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM, /* 0x102 for ssp/smp */ | |
427 | /*IO_ERR_WITH_RXFIS_8B10B_CODE_ERR, [> 0x102 <] for sata/stp */ | |
428 | TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR, /* 0x103 for sata/stp */ | |
429 | TRANS_RX_ERR_WITH_RXFIS_CRC_ERR, /* 0x104 for sata/stp */ | |
430 | TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN, /* 0x105 for smp */ | |
431 | /*IO_ERR_WITH_RXFIS_TX SYNCP, [> 0x105 <] for sata/stp */ | |
432 | TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP, /* 0x106 for sata/stp*/ | |
433 | TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN, /* 0x107 */ | |
434 | TRANS_RX_ERR_WITH_BREAK_TIMEOUT, /* 0x108 */ | |
435 | TRANS_RX_ERR_WITH_BREAK_REQUEST, /* 0x109 */ | |
436 | TRANS_RX_ERR_WITH_BREAK_RECEVIED, /* 0x10a */ | |
437 | RESERVED1, /* 0x10b */ | |
438 | TRANS_RX_ERR_WITH_CLOSE_NORMAL, /* 0x10c */ | |
439 | TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE, /* 0x10d */ | |
440 | TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT, /* 0x10e */ | |
441 | TRANS_RX_ERR_WITH_CLOSE_COMINIT, /* 0x10f */ | |
442 | TRANS_RX_ERR_WITH_DATA_LEN0, /* 0x110 for ssp/smp */ | |
443 | TRANS_RX_ERR_WITH_BAD_HASH, /* 0x111 for ssp */ | |
444 | /*IO_RX_ERR_WITH_FIS_TOO_SHORT, [> 0x111 <] for sata/stp */ | |
445 | TRANS_RX_XRDY_WLEN_ZERO_ERR, /* 0x112 for ssp*/ | |
446 | /*IO_RX_ERR_WITH_FIS_TOO_LONG, [> 0x112 <] for sata/stp */ | |
447 | TRANS_RX_SSP_FRM_LEN_ERR, /* 0x113 for ssp */ | |
448 | /*IO_RX_ERR_WITH_SATA_DEVICE_LOST, [> 0x113 <] for sata */ | |
449 | RESERVED2, /* 0x114 */ | |
450 | RESERVED3, /* 0x115 */ | |
451 | RESERVED4, /* 0x116 */ | |
452 | RESERVED5, /* 0x117 */ | |
453 | TRANS_RX_ERR_WITH_BAD_FRM_TYPE, /* 0x118 */ | |
454 | TRANS_RX_SMP_FRM_LEN_ERR, /* 0x119 */ | |
455 | TRANS_RX_SMP_RESP_TIMEOUT_ERR, /* 0x11a */ | |
456 | RESERVED6, /* 0x11b */ | |
457 | RESERVED7, /* 0x11c */ | |
458 | RESERVED8, /* 0x11d */ | |
459 | RESERVED9, /* 0x11e */ | |
460 | TRANS_RX_R_ERR, /* 0x11f */ | |
461 | ||
462 | /* dma tx */ | |
463 | DMA_TX_DIF_CRC_ERR = DMA_TX_ERR_BASE, /* 0x200 */ | |
464 | DMA_TX_DIF_APP_ERR, /* 0x201 */ | |
465 | DMA_TX_DIF_RPP_ERR, /* 0x202 */ | |
466 | DMA_TX_DATA_SGL_OVERFLOW, /* 0x203 */ | |
467 | DMA_TX_DIF_SGL_OVERFLOW, /* 0x204 */ | |
468 | DMA_TX_UNEXP_XFER_ERR, /* 0x205 */ | |
469 | DMA_TX_UNEXP_RETRANS_ERR, /* 0x206 */ | |
470 | DMA_TX_XFER_LEN_OVERFLOW, /* 0x207 */ | |
471 | DMA_TX_XFER_OFFSET_ERR, /* 0x208 */ | |
472 | DMA_TX_RAM_ECC_ERR, /* 0x209 */ | |
473 | DMA_TX_DIF_LEN_ALIGN_ERR, /* 0x20a */ | |
474 | ||
475 | /* sipc rx */ | |
476 | SIPC_RX_FIS_STATUS_ERR_BIT_VLD = SIPC_RX_ERR_BASE, /* 0x300 */ | |
477 | SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR, /* 0x301 */ | |
478 | SIPC_RX_FIS_STATUS_BSY_BIT_ERR, /* 0x302 */ | |
479 | SIPC_RX_WRSETUP_LEN_ODD_ERR, /* 0x303 */ | |
480 | SIPC_RX_WRSETUP_LEN_ZERO_ERR, /* 0x304 */ | |
481 | SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR, /* 0x305 */ | |
482 | SIPC_RX_NCQ_WRSETUP_OFFSET_ERR, /* 0x306 */ | |
483 | SIPC_RX_NCQ_WRSETUP_AUTO_ACTIVE_ERR, /* 0x307 */ | |
484 | SIPC_RX_SATA_UNEXP_FIS_ERR, /* 0x308 */ | |
485 | SIPC_RX_WRSETUP_ESTATUS_ERR, /* 0x309 */ | |
486 | SIPC_RX_DATA_UNDERFLOW_ERR, /* 0x30a */ | |
487 | ||
488 | /* dma rx */ | |
489 | DMA_RX_DIF_CRC_ERR = DMA_RX_ERR_BASE, /* 0x400 */ | |
490 | DMA_RX_DIF_APP_ERR, /* 0x401 */ | |
491 | DMA_RX_DIF_RPP_ERR, /* 0x402 */ | |
492 | DMA_RX_DATA_SGL_OVERFLOW, /* 0x403 */ | |
493 | DMA_RX_DIF_SGL_OVERFLOW, /* 0x404 */ | |
494 | DMA_RX_DATA_LEN_OVERFLOW, /* 0x405 */ | |
495 | DMA_RX_DATA_LEN_UNDERFLOW, /* 0x406 */ | |
496 | DMA_RX_DATA_OFFSET_ERR, /* 0x407 */ | |
497 | RESERVED10, /* 0x408 */ | |
498 | DMA_RX_SATA_FRAME_TYPE_ERR, /* 0x409 */ | |
499 | DMA_RX_RESP_BUF_OVERFLOW, /* 0x40a */ | |
500 | DMA_RX_UNEXP_RETRANS_RESP_ERR, /* 0x40b */ | |
501 | DMA_RX_UNEXP_NORM_RESP_ERR, /* 0x40c */ | |
502 | DMA_RX_UNEXP_RDFRAME_ERR, /* 0x40d */ | |
503 | DMA_RX_PIO_DATA_LEN_ERR, /* 0x40e */ | |
504 | DMA_RX_RDSETUP_STATUS_ERR, /* 0x40f */ | |
505 | DMA_RX_RDSETUP_STATUS_DRQ_ERR, /* 0x410 */ | |
506 | DMA_RX_RDSETUP_STATUS_BSY_ERR, /* 0x411 */ | |
507 | DMA_RX_RDSETUP_LEN_ODD_ERR, /* 0x412 */ | |
508 | DMA_RX_RDSETUP_LEN_ZERO_ERR, /* 0x413 */ | |
509 | DMA_RX_RDSETUP_LEN_OVER_ERR, /* 0x414 */ | |
510 | DMA_RX_RDSETUP_OFFSET_ERR, /* 0x415 */ | |
511 | DMA_RX_RDSETUP_ACTIVE_ERR, /* 0x416 */ | |
512 | DMA_RX_RDSETUP_ESTATUS_ERR, /* 0x417 */ | |
513 | DMA_RX_RAM_ECC_ERR, /* 0x418 */ | |
514 | DMA_RX_UNKNOWN_FRM_ERR, /* 0x419 */ | |
515 | }; | |
516 | ||
94eac9e1 JG |
517 | #define HISI_SAS_COMMAND_ENTRIES_V2_HW 4096 |
518 | ||
8c36e31d JG |
519 | #define DIR_NO_DATA 0 |
520 | #define DIR_TO_INI 1 | |
521 | #define DIR_TO_DEVICE 2 | |
522 | #define DIR_RESERVED 3 | |
523 | ||
6f2ff1a1 JG |
524 | #define SATA_PROTOCOL_NONDATA 0x1 |
525 | #define SATA_PROTOCOL_PIO 0x2 | |
526 | #define SATA_PROTOCOL_DMA 0x4 | |
527 | #define SATA_PROTOCOL_FPDMA 0x8 | |
528 | #define SATA_PROTOCOL_ATAPI 0x10 | |
529 | ||
f2f89c32 XC |
530 | static void hisi_sas_link_timeout_disable_link(unsigned long data); |
531 | ||
94eac9e1 JG |
532 | static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off) |
533 | { | |
534 | void __iomem *regs = hisi_hba->regs + off; | |
535 | ||
536 | return readl(regs); | |
537 | } | |
538 | ||
8c36e31d JG |
539 | static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off) |
540 | { | |
541 | void __iomem *regs = hisi_hba->regs + off; | |
542 | ||
543 | return readl_relaxed(regs); | |
544 | } | |
545 | ||
94eac9e1 JG |
546 | static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val) |
547 | { | |
548 | void __iomem *regs = hisi_hba->regs + off; | |
549 | ||
550 | writel(val, regs); | |
551 | } | |
552 | ||
553 | static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no, | |
554 | u32 off, u32 val) | |
555 | { | |
556 | void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off; | |
557 | ||
558 | writel(val, regs); | |
559 | } | |
560 | ||
561 | static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba, | |
562 | int phy_no, u32 off) | |
563 | { | |
564 | void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off; | |
565 | ||
566 | return readl(regs); | |
567 | } | |
568 | ||
330fa7f3 JG |
569 | /* This function needs to be protected from pre-emption. */ |
570 | static int | |
571 | slot_index_alloc_quirk_v2_hw(struct hisi_hba *hisi_hba, int *slot_idx, | |
572 | struct domain_device *device) | |
573 | { | |
574 | unsigned int index = 0; | |
575 | void *bitmap = hisi_hba->slot_index_tags; | |
576 | int sata_dev = dev_is_sata(device); | |
577 | ||
578 | while (1) { | |
579 | index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count, | |
580 | index); | |
581 | if (index >= hisi_hba->slot_index_count) | |
582 | return -SAS_QUEUE_FULL; | |
583 | /* | |
584 | * SAS IPTT bit0 should be 1 | |
585 | */ | |
586 | if (sata_dev || (index & 1)) | |
587 | break; | |
588 | index++; | |
589 | } | |
590 | ||
591 | set_bit(index, bitmap); | |
592 | *slot_idx = index; | |
593 | return 0; | |
594 | } | |
595 | ||
b2bdaf2b JG |
596 | static struct |
597 | hisi_sas_device *alloc_dev_quirk_v2_hw(struct domain_device *device) | |
598 | { | |
599 | struct hisi_hba *hisi_hba = device->port->ha->lldd_ha; | |
600 | struct hisi_sas_device *sas_dev = NULL; | |
601 | int i, sata_dev = dev_is_sata(device); | |
602 | ||
603 | spin_lock(&hisi_hba->lock); | |
604 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { | |
605 | /* | |
606 | * SATA device id bit0 should be 0 | |
607 | */ | |
608 | if (sata_dev && (i & 1)) | |
609 | continue; | |
610 | if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { | |
611 | hisi_hba->devices[i].device_id = i; | |
612 | sas_dev = &hisi_hba->devices[i]; | |
613 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; | |
614 | sas_dev->dev_type = device->dev_type; | |
615 | sas_dev->hisi_hba = hisi_hba; | |
616 | sas_dev->sas_device = device; | |
617 | break; | |
618 | } | |
619 | } | |
620 | spin_unlock(&hisi_hba->lock); | |
621 | ||
622 | return sas_dev; | |
623 | } | |
624 | ||
29a20428 JG |
625 | static void config_phy_opt_mode_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
626 | { | |
627 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
628 | ||
629 | cfg &= ~PHY_CFG_DC_OPT_MSK; | |
630 | cfg |= 1 << PHY_CFG_DC_OPT_OFF; | |
631 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
632 | } | |
633 | ||
806bb768 JG |
634 | static void config_id_frame_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
635 | { | |
636 | struct sas_identify_frame identify_frame; | |
637 | u32 *identify_buffer; | |
638 | ||
639 | memset(&identify_frame, 0, sizeof(identify_frame)); | |
640 | identify_frame.dev_type = SAS_END_DEVICE; | |
641 | identify_frame.frame_type = 0; | |
642 | identify_frame._un1 = 1; | |
643 | identify_frame.initiator_bits = SAS_PROTOCOL_ALL; | |
644 | identify_frame.target_bits = SAS_PROTOCOL_NONE; | |
645 | memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE); | |
646 | memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE); | |
647 | identify_frame.phy_id = phy_no; | |
648 | identify_buffer = (u32 *)(&identify_frame); | |
649 | ||
650 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0, | |
651 | __swab32(identify_buffer[0])); | |
652 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1, | |
d82debec | 653 | __swab32(identify_buffer[1])); |
806bb768 | 654 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2, |
d82debec | 655 | __swab32(identify_buffer[2])); |
806bb768 | 656 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3, |
d82debec | 657 | __swab32(identify_buffer[3])); |
806bb768 | 658 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4, |
d82debec | 659 | __swab32(identify_buffer[4])); |
806bb768 JG |
660 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5, |
661 | __swab32(identify_buffer[5])); | |
662 | } | |
663 | ||
85b2c3c0 JG |
664 | static void setup_itct_v2_hw(struct hisi_hba *hisi_hba, |
665 | struct hisi_sas_device *sas_dev) | |
666 | { | |
667 | struct domain_device *device = sas_dev->sas_device; | |
668 | struct device *dev = &hisi_hba->pdev->dev; | |
669 | u64 qw0, device_id = sas_dev->device_id; | |
670 | struct hisi_sas_itct *itct = &hisi_hba->itct[device_id]; | |
671 | struct domain_device *parent_dev = device->parent; | |
672 | struct hisi_sas_port *port = device->port->lldd_port; | |
673 | ||
674 | memset(itct, 0, sizeof(*itct)); | |
675 | ||
676 | /* qw0 */ | |
677 | qw0 = 0; | |
678 | switch (sas_dev->dev_type) { | |
679 | case SAS_END_DEVICE: | |
680 | case SAS_EDGE_EXPANDER_DEVICE: | |
681 | case SAS_FANOUT_EXPANDER_DEVICE: | |
682 | qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF; | |
683 | break; | |
684 | case SAS_SATA_DEV: | |
56cc74b9 | 685 | case SAS_SATA_PENDING: |
85b2c3c0 JG |
686 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) |
687 | qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF; | |
688 | else | |
689 | qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF; | |
690 | break; | |
691 | default: | |
692 | dev_warn(dev, "setup itct: unsupported dev type (%d)\n", | |
693 | sas_dev->dev_type); | |
694 | } | |
695 | ||
696 | qw0 |= ((1 << ITCT_HDR_VALID_OFF) | | |
75249268 | 697 | (device->linkrate << ITCT_HDR_MCR_OFF) | |
85b2c3c0 JG |
698 | (1 << ITCT_HDR_VLN_OFF) | |
699 | (port->id << ITCT_HDR_PORT_ID_OFF)); | |
700 | itct->qw0 = cpu_to_le64(qw0); | |
701 | ||
702 | /* qw1 */ | |
703 | memcpy(&itct->sas_addr, device->sas_addr, SAS_ADDR_SIZE); | |
704 | itct->sas_addr = __swab64(itct->sas_addr); | |
705 | ||
706 | /* qw2 */ | |
f76a0b49 JG |
707 | if (!dev_is_sata(device)) |
708 | itct->qw2 = cpu_to_le64((500ULL << ITCT_HDR_INLT_OFF) | | |
709 | (0x1ULL << ITCT_HDR_BITLT_OFF) | | |
710 | (0x32ULL << ITCT_HDR_MCTLT_OFF) | | |
711 | (0x1ULL << ITCT_HDR_RTOLT_OFF)); | |
85b2c3c0 JG |
712 | } |
713 | ||
714 | static void free_device_v2_hw(struct hisi_hba *hisi_hba, | |
715 | struct hisi_sas_device *sas_dev) | |
716 | { | |
717 | u64 qw0, dev_id = sas_dev->device_id; | |
718 | struct device *dev = &hisi_hba->pdev->dev; | |
719 | struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id]; | |
720 | u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
721 | int i; | |
722 | ||
723 | /* clear the itct interrupt state */ | |
724 | if (ENT_INT_SRC3_ITC_INT_MSK & reg_val) | |
725 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
726 | ENT_INT_SRC3_ITC_INT_MSK); | |
727 | ||
728 | /* clear the itct int*/ | |
729 | for (i = 0; i < 2; i++) { | |
730 | /* clear the itct table*/ | |
731 | reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR); | |
732 | reg_val |= ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK); | |
733 | hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val); | |
734 | ||
735 | udelay(10); | |
736 | reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
737 | if (ENT_INT_SRC3_ITC_INT_MSK & reg_val) { | |
738 | dev_dbg(dev, "got clear ITCT done interrupt\n"); | |
739 | ||
740 | /* invalid the itct state*/ | |
741 | qw0 = cpu_to_le64(itct->qw0); | |
742 | qw0 &= ~(1 << ITCT_HDR_VALID_OFF); | |
743 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
744 | ENT_INT_SRC3_ITC_INT_MSK); | |
85b2c3c0 JG |
745 | |
746 | /* clear the itct */ | |
747 | hisi_sas_write32(hisi_hba, ITCT_CLR, 0); | |
748 | dev_dbg(dev, "clear ITCT ok\n"); | |
749 | break; | |
750 | } | |
751 | } | |
752 | } | |
753 | ||
94eac9e1 JG |
754 | static int reset_hw_v2_hw(struct hisi_hba *hisi_hba) |
755 | { | |
756 | int i, reset_val; | |
757 | u32 val; | |
758 | unsigned long end_time; | |
759 | struct device *dev = &hisi_hba->pdev->dev; | |
760 | ||
761 | /* The mask needs to be set depending on the number of phys */ | |
762 | if (hisi_hba->n_phy == 9) | |
763 | reset_val = 0x1fffff; | |
764 | else | |
765 | reset_val = 0x7ffff; | |
766 | ||
d0df8f9a | 767 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0); |
94eac9e1 JG |
768 | |
769 | /* Disable all of the PHYs */ | |
770 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
771 | u32 phy_cfg = hisi_sas_phy_read32(hisi_hba, i, PHY_CFG); | |
772 | ||
773 | phy_cfg &= ~PHY_CTRL_RESET_MSK; | |
774 | hisi_sas_phy_write32(hisi_hba, i, PHY_CFG, phy_cfg); | |
775 | } | |
776 | udelay(50); | |
777 | ||
778 | /* Ensure DMA tx & rx idle */ | |
779 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
780 | u32 dma_tx_status, dma_rx_status; | |
781 | ||
782 | end_time = jiffies + msecs_to_jiffies(1000); | |
783 | ||
784 | while (1) { | |
785 | dma_tx_status = hisi_sas_phy_read32(hisi_hba, i, | |
786 | DMA_TX_STATUS); | |
787 | dma_rx_status = hisi_sas_phy_read32(hisi_hba, i, | |
788 | DMA_RX_STATUS); | |
789 | ||
790 | if (!(dma_tx_status & DMA_TX_STATUS_BUSY_MSK) && | |
791 | !(dma_rx_status & DMA_RX_STATUS_BUSY_MSK)) | |
792 | break; | |
793 | ||
794 | msleep(20); | |
795 | if (time_after(jiffies, end_time)) | |
796 | return -EIO; | |
797 | } | |
798 | } | |
799 | ||
800 | /* Ensure axi bus idle */ | |
801 | end_time = jiffies + msecs_to_jiffies(1000); | |
802 | while (1) { | |
803 | u32 axi_status = | |
804 | hisi_sas_read32(hisi_hba, AXI_CFG); | |
805 | ||
806 | if (axi_status == 0) | |
807 | break; | |
808 | ||
809 | msleep(20); | |
810 | if (time_after(jiffies, end_time)) | |
811 | return -EIO; | |
812 | } | |
813 | ||
50408712 JG |
814 | if (ACPI_HANDLE(dev)) { |
815 | acpi_status s; | |
94eac9e1 | 816 | |
50408712 JG |
817 | s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL); |
818 | if (ACPI_FAILURE(s)) { | |
819 | dev_err(dev, "Reset failed\n"); | |
820 | return -EIO; | |
821 | } | |
822 | } else if (hisi_hba->ctrl) { | |
823 | /* reset and disable clock*/ | |
824 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg, | |
825 | reset_val); | |
826 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg + 4, | |
827 | reset_val); | |
828 | msleep(1); | |
829 | regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val); | |
830 | if (reset_val != (val & reset_val)) { | |
831 | dev_err(dev, "SAS reset fail.\n"); | |
832 | return -EIO; | |
833 | } | |
834 | ||
835 | /* De-reset and enable clock*/ | |
836 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg + 4, | |
837 | reset_val); | |
838 | regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg, | |
839 | reset_val); | |
840 | msleep(1); | |
841 | regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, | |
842 | &val); | |
843 | if (val & reset_val) { | |
844 | dev_err(dev, "SAS de-reset fail.\n"); | |
845 | return -EIO; | |
846 | } | |
847 | } else | |
848 | dev_warn(dev, "no reset method\n"); | |
94eac9e1 JG |
849 | |
850 | return 0; | |
851 | } | |
852 | ||
853 | static void init_reg_v2_hw(struct hisi_hba *hisi_hba) | |
854 | { | |
855 | struct device *dev = &hisi_hba->pdev->dev; | |
94eac9e1 JG |
856 | int i; |
857 | ||
858 | /* Global registers init */ | |
859 | ||
860 | /* Deal with am-max-transmissions quirk */ | |
50408712 | 861 | if (device_property_present(dev, "hip06-sas-v2-quirk-amt")) { |
94eac9e1 JG |
862 | hisi_sas_write32(hisi_hba, AM_CFG_MAX_TRANS, 0x2020); |
863 | hisi_sas_write32(hisi_hba, AM_CFG_SINGLE_PORT_MAX_TRANS, | |
864 | 0x2020); | |
865 | } /* Else, use defaults -> do nothing */ | |
866 | ||
867 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, | |
868 | (u32)((1ULL << hisi_hba->queue_count) - 1)); | |
869 | hisi_sas_write32(hisi_hba, AXI_USER1, 0xc0000000); | |
870 | hisi_sas_write32(hisi_hba, AXI_USER2, 0x10000); | |
871 | hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x108); | |
872 | hisi_sas_write32(hisi_hba, HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL, 0x7FF); | |
873 | hisi_sas_write32(hisi_hba, OPENA_WT_CONTI_TIME, 0x1); | |
874 | hisi_sas_write32(hisi_hba, I_T_NEXUS_LOSS_TIME, 0x1F4); | |
f76a0b49 | 875 | hisi_sas_write32(hisi_hba, MAX_CON_TIME_LIMIT_TIME, 0x32); |
94eac9e1 JG |
876 | hisi_sas_write32(hisi_hba, BUS_INACTIVE_LIMIT_TIME, 0x1); |
877 | hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1); | |
878 | hisi_sas_write32(hisi_hba, HGC_ERR_STAT_EN, 0x1); | |
879 | hisi_sas_write32(hisi_hba, HGC_GET_ITV_TIME, 0x1); | |
880 | hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1); | |
881 | hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1); | |
882 | hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1); | |
883 | hisi_sas_write32(hisi_hba, ENT_INT_COAL_TIME, 0x1); | |
884 | hisi_sas_write32(hisi_hba, ENT_INT_COAL_CNT, 0x1); | |
885 | hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0x0); | |
886 | hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff); | |
887 | hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff); | |
888 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff); | |
889 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0x7efefefe); | |
890 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0x7efefefe); | |
891 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0x7ffffffe); | |
d3b688d3 | 892 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xfff00c30); |
94eac9e1 JG |
893 | for (i = 0; i < hisi_hba->queue_count; i++) |
894 | hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0); | |
895 | ||
896 | hisi_sas_write32(hisi_hba, AXI_AHB_CLK_CFG, 1); | |
897 | hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1); | |
898 | ||
899 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
900 | hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x855); | |
901 | hisi_sas_phy_write32(hisi_hba, i, SAS_PHY_CTRL, 0x30b9908); | |
902 | hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d); | |
9c81e2cf JG |
903 | hisi_sas_phy_write32(hisi_hba, i, SL_CONTROL, 0x0); |
904 | hisi_sas_phy_write32(hisi_hba, i, TXID_AUTO, 0x2); | |
94eac9e1 JG |
905 | hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0x10); |
906 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff); | |
907 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff); | |
d3b688d3 | 908 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xfff87fff); |
94eac9e1 JG |
909 | hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000); |
910 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff); | |
911 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8ffffbff); | |
912 | hisi_sas_phy_write32(hisi_hba, i, SL_CFG, 0x23f801fc); | |
913 | hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0); | |
914 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0); | |
915 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0); | |
916 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0); | |
917 | hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0); | |
918 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT_COAL_EN, 0x0); | |
919 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x0); | |
3bc45af8 JG |
920 | if (hisi_hba->refclk_frequency_mhz == 66) |
921 | hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, 0x199B694); | |
922 | /* else, do nothing -> leave it how you found it */ | |
94eac9e1 JG |
923 | } |
924 | ||
925 | for (i = 0; i < hisi_hba->queue_count; i++) { | |
926 | /* Delivery queue */ | |
927 | hisi_sas_write32(hisi_hba, | |
928 | DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14), | |
929 | upper_32_bits(hisi_hba->cmd_hdr_dma[i])); | |
930 | ||
931 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14), | |
932 | lower_32_bits(hisi_hba->cmd_hdr_dma[i])); | |
933 | ||
934 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14), | |
935 | HISI_SAS_QUEUE_SLOTS); | |
936 | ||
937 | /* Completion queue */ | |
938 | hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14), | |
939 | upper_32_bits(hisi_hba->complete_hdr_dma[i])); | |
940 | ||
941 | hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14), | |
942 | lower_32_bits(hisi_hba->complete_hdr_dma[i])); | |
943 | ||
944 | hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14), | |
945 | HISI_SAS_QUEUE_SLOTS); | |
946 | } | |
947 | ||
948 | /* itct */ | |
949 | hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO, | |
950 | lower_32_bits(hisi_hba->itct_dma)); | |
951 | ||
952 | hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI, | |
953 | upper_32_bits(hisi_hba->itct_dma)); | |
954 | ||
955 | /* iost */ | |
956 | hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO, | |
957 | lower_32_bits(hisi_hba->iost_dma)); | |
958 | ||
959 | hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI, | |
960 | upper_32_bits(hisi_hba->iost_dma)); | |
961 | ||
962 | /* breakpoint */ | |
963 | hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO, | |
964 | lower_32_bits(hisi_hba->breakpoint_dma)); | |
965 | ||
966 | hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI, | |
967 | upper_32_bits(hisi_hba->breakpoint_dma)); | |
968 | ||
969 | /* SATA broken msg */ | |
970 | hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO, | |
971 | lower_32_bits(hisi_hba->sata_breakpoint_dma)); | |
972 | ||
973 | hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI, | |
974 | upper_32_bits(hisi_hba->sata_breakpoint_dma)); | |
975 | ||
976 | /* SATA initial fis */ | |
977 | hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO, | |
978 | lower_32_bits(hisi_hba->initial_fis_dma)); | |
979 | ||
980 | hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI, | |
981 | upper_32_bits(hisi_hba->initial_fis_dma)); | |
982 | } | |
983 | ||
f2f89c32 XC |
984 | static void hisi_sas_link_timeout_enable_link(unsigned long data) |
985 | { | |
986 | struct hisi_hba *hisi_hba = (struct hisi_hba *)data; | |
987 | int i, reg_val; | |
988 | ||
989 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
990 | reg_val = hisi_sas_phy_read32(hisi_hba, i, CON_CONTROL); | |
991 | if (!(reg_val & BIT(0))) { | |
992 | hisi_sas_phy_write32(hisi_hba, i, | |
993 | CON_CONTROL, 0x7); | |
994 | break; | |
995 | } | |
996 | } | |
997 | ||
998 | hisi_hba->timer.function = hisi_sas_link_timeout_disable_link; | |
999 | mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(900)); | |
1000 | } | |
1001 | ||
1002 | static void hisi_sas_link_timeout_disable_link(unsigned long data) | |
1003 | { | |
1004 | struct hisi_hba *hisi_hba = (struct hisi_hba *)data; | |
1005 | int i, reg_val; | |
1006 | ||
1007 | reg_val = hisi_sas_read32(hisi_hba, PHY_STATE); | |
1008 | for (i = 0; i < hisi_hba->n_phy && reg_val; i++) { | |
1009 | if (reg_val & BIT(i)) { | |
1010 | hisi_sas_phy_write32(hisi_hba, i, | |
1011 | CON_CONTROL, 0x6); | |
1012 | break; | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | hisi_hba->timer.function = hisi_sas_link_timeout_enable_link; | |
1017 | mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(100)); | |
1018 | } | |
1019 | ||
1020 | static void set_link_timer_quirk(struct hisi_hba *hisi_hba) | |
1021 | { | |
1022 | hisi_hba->timer.data = (unsigned long)hisi_hba; | |
1023 | hisi_hba->timer.function = hisi_sas_link_timeout_disable_link; | |
1024 | hisi_hba->timer.expires = jiffies + msecs_to_jiffies(1000); | |
1025 | add_timer(&hisi_hba->timer); | |
1026 | } | |
1027 | ||
94eac9e1 JG |
1028 | static int hw_init_v2_hw(struct hisi_hba *hisi_hba) |
1029 | { | |
1030 | struct device *dev = &hisi_hba->pdev->dev; | |
1031 | int rc; | |
1032 | ||
1033 | rc = reset_hw_v2_hw(hisi_hba); | |
1034 | if (rc) { | |
1035 | dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc); | |
1036 | return rc; | |
1037 | } | |
1038 | ||
1039 | msleep(100); | |
1040 | init_reg_v2_hw(hisi_hba); | |
806bb768 | 1041 | |
94eac9e1 JG |
1042 | return 0; |
1043 | } | |
1044 | ||
29a20428 JG |
1045 | static void enable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1046 | { | |
1047 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
1048 | ||
1049 | cfg |= PHY_CFG_ENA_MSK; | |
1050 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
1051 | } | |
1052 | ||
63fb11b8 JG |
1053 | static void disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1054 | { | |
1055 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
1056 | ||
1057 | cfg &= ~PHY_CFG_ENA_MSK; | |
1058 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
1059 | } | |
1060 | ||
29a20428 JG |
1061 | static void start_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1062 | { | |
1063 | config_id_frame_v2_hw(hisi_hba, phy_no); | |
1064 | config_phy_opt_mode_v2_hw(hisi_hba, phy_no); | |
1065 | enable_phy_v2_hw(hisi_hba, phy_no); | |
1066 | } | |
1067 | ||
63fb11b8 JG |
1068 | static void stop_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1069 | { | |
1070 | disable_phy_v2_hw(hisi_hba, phy_no); | |
1071 | } | |
1072 | ||
1073 | static void phy_hard_reset_v2_hw(struct hisi_hba *hisi_hba, int phy_no) | |
1074 | { | |
1075 | stop_phy_v2_hw(hisi_hba, phy_no); | |
1076 | msleep(100); | |
1077 | start_phy_v2_hw(hisi_hba, phy_no); | |
1078 | } | |
1079 | ||
29a20428 JG |
1080 | static void start_phys_v2_hw(unsigned long data) |
1081 | { | |
1082 | struct hisi_hba *hisi_hba = (struct hisi_hba *)data; | |
1083 | int i; | |
1084 | ||
1085 | for (i = 0; i < hisi_hba->n_phy; i++) | |
1086 | start_phy_v2_hw(hisi_hba, i); | |
1087 | } | |
1088 | ||
1089 | static void phys_init_v2_hw(struct hisi_hba *hisi_hba) | |
1090 | { | |
29a20428 JG |
1091 | struct timer_list *timer = &hisi_hba->timer; |
1092 | ||
29a20428 JG |
1093 | setup_timer(timer, start_phys_v2_hw, (unsigned long)hisi_hba); |
1094 | mod_timer(timer, jiffies + HZ); | |
1095 | } | |
1096 | ||
7911e66f JG |
1097 | static void sl_notify_v2_hw(struct hisi_hba *hisi_hba, int phy_no) |
1098 | { | |
1099 | u32 sl_control; | |
1100 | ||
1101 | sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
1102 | sl_control |= SL_CONTROL_NOTIFY_EN_MSK; | |
1103 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control); | |
1104 | msleep(1); | |
1105 | sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
1106 | sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK; | |
1107 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control); | |
1108 | } | |
1109 | ||
2ae75787 XC |
1110 | static enum sas_linkrate phy_get_max_linkrate_v2_hw(void) |
1111 | { | |
1112 | return SAS_LINK_RATE_12_0_GBPS; | |
1113 | } | |
1114 | ||
1115 | static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no, | |
1116 | struct sas_phy_linkrates *r) | |
1117 | { | |
1118 | u32 prog_phy_link_rate = | |
1119 | hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); | |
1120 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
1121 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1122 | int i; | |
1123 | enum sas_linkrate min, max; | |
1124 | u32 rate_mask = 0; | |
1125 | ||
1126 | if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { | |
1127 | max = sas_phy->phy->maximum_linkrate; | |
1128 | min = r->minimum_linkrate; | |
1129 | } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { | |
1130 | max = r->maximum_linkrate; | |
1131 | min = sas_phy->phy->minimum_linkrate; | |
1132 | } else | |
1133 | return; | |
1134 | ||
1135 | sas_phy->phy->maximum_linkrate = max; | |
1136 | sas_phy->phy->minimum_linkrate = min; | |
1137 | ||
1138 | min -= SAS_LINK_RATE_1_5_GBPS; | |
1139 | max -= SAS_LINK_RATE_1_5_GBPS; | |
1140 | ||
1141 | for (i = 0; i <= max; i++) | |
1142 | rate_mask |= 1 << (i * 2); | |
1143 | ||
1144 | prog_phy_link_rate &= ~0xff; | |
1145 | prog_phy_link_rate |= rate_mask; | |
1146 | ||
1147 | hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, | |
1148 | prog_phy_link_rate); | |
1149 | ||
1150 | phy_hard_reset_v2_hw(hisi_hba, phy_no); | |
1151 | } | |
1152 | ||
5473c060 JG |
1153 | static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id) |
1154 | { | |
1155 | int i, bitmap = 0; | |
1156 | u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
1157 | u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE); | |
1158 | ||
1159 | for (i = 0; i < (hisi_hba->n_phy < 9 ? hisi_hba->n_phy : 8); i++) | |
1160 | if (phy_state & 1 << i) | |
1161 | if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id) | |
1162 | bitmap |= 1 << i; | |
1163 | ||
1164 | if (hisi_hba->n_phy == 9) { | |
1165 | u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
1166 | ||
1167 | if (phy_state & 1 << 8) | |
1168 | if (((port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >> | |
1169 | PORT_STATE_PHY8_PORT_NUM_OFF) == port_id) | |
1170 | bitmap |= 1 << 9; | |
1171 | } | |
1172 | ||
1173 | return bitmap; | |
1174 | } | |
1175 | ||
8c36e31d JG |
1176 | /** |
1177 | * This function allocates across all queues to load balance. | |
1178 | * Slots are allocated from queues in a round-robin fashion. | |
1179 | * | |
1180 | * The callpath to this function and upto writing the write | |
1181 | * queue pointer should be safe from interruption. | |
1182 | */ | |
c70f1fb7 XC |
1183 | static int get_free_slot_v2_hw(struct hisi_hba *hisi_hba, u32 dev_id, |
1184 | int *q, int *s) | |
8c36e31d JG |
1185 | { |
1186 | struct device *dev = &hisi_hba->pdev->dev; | |
4fde02ad | 1187 | struct hisi_sas_dq *dq; |
8c36e31d | 1188 | u32 r, w; |
c70f1fb7 XC |
1189 | int queue = dev_id % hisi_hba->queue_count; |
1190 | ||
1191 | dq = &hisi_hba->dq[queue]; | |
1192 | w = dq->wr_point; | |
1193 | r = hisi_sas_read32_relaxed(hisi_hba, | |
1194 | DLVRY_Q_0_RD_PTR + (queue * 0x14)); | |
1195 | if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) { | |
1196 | dev_warn(dev, "full queue=%d r=%d w=%d\n\n", | |
1197 | queue, r, w); | |
1198 | return -EAGAIN; | |
8c36e31d | 1199 | } |
c70f1fb7 | 1200 | |
8c36e31d JG |
1201 | *q = queue; |
1202 | *s = w; | |
1203 | return 0; | |
1204 | } | |
1205 | ||
1206 | static void start_delivery_v2_hw(struct hisi_hba *hisi_hba) | |
1207 | { | |
1208 | int dlvry_queue = hisi_hba->slot_prep->dlvry_queue; | |
1209 | int dlvry_queue_slot = hisi_hba->slot_prep->dlvry_queue_slot; | |
4fde02ad | 1210 | struct hisi_sas_dq *dq = &hisi_hba->dq[dlvry_queue]; |
8c36e31d | 1211 | |
4fde02ad | 1212 | dq->wr_point = ++dlvry_queue_slot % HISI_SAS_QUEUE_SLOTS; |
8c36e31d | 1213 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), |
4fde02ad | 1214 | dq->wr_point); |
8c36e31d JG |
1215 | } |
1216 | ||
1217 | static int prep_prd_sge_v2_hw(struct hisi_hba *hisi_hba, | |
1218 | struct hisi_sas_slot *slot, | |
1219 | struct hisi_sas_cmd_hdr *hdr, | |
1220 | struct scatterlist *scatter, | |
1221 | int n_elem) | |
1222 | { | |
1223 | struct device *dev = &hisi_hba->pdev->dev; | |
1224 | struct scatterlist *sg; | |
1225 | int i; | |
1226 | ||
1227 | if (n_elem > HISI_SAS_SGE_PAGE_CNT) { | |
1228 | dev_err(dev, "prd err: n_elem(%d) > HISI_SAS_SGE_PAGE_CNT", | |
1229 | n_elem); | |
1230 | return -EINVAL; | |
1231 | } | |
1232 | ||
1233 | slot->sge_page = dma_pool_alloc(hisi_hba->sge_page_pool, GFP_ATOMIC, | |
1234 | &slot->sge_page_dma); | |
1235 | if (!slot->sge_page) | |
1236 | return -ENOMEM; | |
1237 | ||
1238 | for_each_sg(scatter, sg, n_elem, i) { | |
1239 | struct hisi_sas_sge *entry = &slot->sge_page->sge[i]; | |
1240 | ||
1241 | entry->addr = cpu_to_le64(sg_dma_address(sg)); | |
1242 | entry->page_ctrl_0 = entry->page_ctrl_1 = 0; | |
1243 | entry->data_len = cpu_to_le32(sg_dma_len(sg)); | |
1244 | entry->data_off = 0; | |
1245 | } | |
1246 | ||
1247 | hdr->prd_table_addr = cpu_to_le64(slot->sge_page_dma); | |
1248 | ||
1249 | hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF); | |
1250 | ||
1251 | return 0; | |
1252 | } | |
1253 | ||
c2d89392 JG |
1254 | static int prep_smp_v2_hw(struct hisi_hba *hisi_hba, |
1255 | struct hisi_sas_slot *slot) | |
1256 | { | |
1257 | struct sas_task *task = slot->task; | |
1258 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1259 | struct domain_device *device = task->dev; | |
1260 | struct device *dev = &hisi_hba->pdev->dev; | |
1261 | struct hisi_sas_port *port = slot->port; | |
1262 | struct scatterlist *sg_req, *sg_resp; | |
1263 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
1264 | dma_addr_t req_dma_addr; | |
1265 | unsigned int req_len, resp_len; | |
1266 | int elem, rc; | |
1267 | ||
1268 | /* | |
1269 | * DMA-map SMP request, response buffers | |
1270 | */ | |
1271 | /* req */ | |
1272 | sg_req = &task->smp_task.smp_req; | |
1273 | elem = dma_map_sg(dev, sg_req, 1, DMA_TO_DEVICE); | |
1274 | if (!elem) | |
1275 | return -ENOMEM; | |
1276 | req_len = sg_dma_len(sg_req); | |
1277 | req_dma_addr = sg_dma_address(sg_req); | |
1278 | ||
1279 | /* resp */ | |
1280 | sg_resp = &task->smp_task.smp_resp; | |
1281 | elem = dma_map_sg(dev, sg_resp, 1, DMA_FROM_DEVICE); | |
1282 | if (!elem) { | |
1283 | rc = -ENOMEM; | |
1284 | goto err_out_req; | |
1285 | } | |
1286 | resp_len = sg_dma_len(sg_resp); | |
1287 | if ((req_len & 0x3) || (resp_len & 0x3)) { | |
1288 | rc = -EINVAL; | |
1289 | goto err_out_resp; | |
1290 | } | |
1291 | ||
1292 | /* create header */ | |
1293 | /* dw0 */ | |
1294 | hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) | | |
1295 | (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */ | |
1296 | (2 << CMD_HDR_CMD_OFF)); /* smp */ | |
1297 | ||
1298 | /* map itct entry */ | |
1299 | hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) | | |
1300 | (1 << CMD_HDR_FRAME_TYPE_OFF) | | |
1301 | (DIR_NO_DATA << CMD_HDR_DIR_OFF)); | |
1302 | ||
1303 | /* dw2 */ | |
1304 | hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) | | |
1305 | (HISI_SAS_MAX_SMP_RESP_SZ / 4 << | |
1306 | CMD_HDR_MRFL_OFF)); | |
1307 | ||
1308 | hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF); | |
1309 | ||
1310 | hdr->cmd_table_addr = cpu_to_le64(req_dma_addr); | |
1311 | hdr->sts_buffer_addr = cpu_to_le64(slot->status_buffer_dma); | |
1312 | ||
1313 | return 0; | |
1314 | ||
1315 | err_out_resp: | |
1316 | dma_unmap_sg(dev, &slot->task->smp_task.smp_resp, 1, | |
1317 | DMA_FROM_DEVICE); | |
1318 | err_out_req: | |
1319 | dma_unmap_sg(dev, &slot->task->smp_task.smp_req, 1, | |
1320 | DMA_TO_DEVICE); | |
1321 | return rc; | |
1322 | } | |
1323 | ||
8c36e31d JG |
1324 | static int prep_ssp_v2_hw(struct hisi_hba *hisi_hba, |
1325 | struct hisi_sas_slot *slot, int is_tmf, | |
1326 | struct hisi_sas_tmf_task *tmf) | |
1327 | { | |
1328 | struct sas_task *task = slot->task; | |
1329 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1330 | struct domain_device *device = task->dev; | |
1331 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
1332 | struct hisi_sas_port *port = slot->port; | |
1333 | struct sas_ssp_task *ssp_task = &task->ssp_task; | |
1334 | struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; | |
1335 | int has_data = 0, rc, priority = is_tmf; | |
1336 | u8 *buf_cmd; | |
1337 | u32 dw1 = 0, dw2 = 0; | |
1338 | ||
1339 | hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) | | |
1340 | (2 << CMD_HDR_TLR_CTRL_OFF) | | |
1341 | (port->id << CMD_HDR_PORT_OFF) | | |
1342 | (priority << CMD_HDR_PRIORITY_OFF) | | |
1343 | (1 << CMD_HDR_CMD_OFF)); /* ssp */ | |
1344 | ||
1345 | dw1 = 1 << CMD_HDR_VDTL_OFF; | |
1346 | if (is_tmf) { | |
1347 | dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF; | |
1348 | dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF; | |
1349 | } else { | |
1350 | dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF; | |
1351 | switch (scsi_cmnd->sc_data_direction) { | |
1352 | case DMA_TO_DEVICE: | |
1353 | has_data = 1; | |
1354 | dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF; | |
1355 | break; | |
1356 | case DMA_FROM_DEVICE: | |
1357 | has_data = 1; | |
1358 | dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF; | |
1359 | break; | |
1360 | default: | |
1361 | dw1 &= ~CMD_HDR_DIR_MSK; | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | /* map itct entry */ | |
1366 | dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; | |
1367 | hdr->dw1 = cpu_to_le32(dw1); | |
1368 | ||
1369 | dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr) | |
1370 | + 3) / 4) << CMD_HDR_CFL_OFF) | | |
1371 | ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) | | |
1372 | (2 << CMD_HDR_SG_MOD_OFF); | |
1373 | hdr->dw2 = cpu_to_le32(dw2); | |
1374 | ||
1375 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
1376 | ||
1377 | if (has_data) { | |
1378 | rc = prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter, | |
1379 | slot->n_elem); | |
1380 | if (rc) | |
1381 | return rc; | |
1382 | } | |
1383 | ||
1384 | hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len); | |
1385 | hdr->cmd_table_addr = cpu_to_le64(slot->command_table_dma); | |
1386 | hdr->sts_buffer_addr = cpu_to_le64(slot->status_buffer_dma); | |
1387 | ||
1388 | buf_cmd = slot->command_table + sizeof(struct ssp_frame_hdr); | |
1389 | ||
1390 | memcpy(buf_cmd, &task->ssp_task.LUN, 8); | |
1391 | if (!is_tmf) { | |
1392 | buf_cmd[9] = task->ssp_task.task_attr | | |
1393 | (task->ssp_task.task_prio << 3); | |
1394 | memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd, | |
1395 | task->ssp_task.cmd->cmd_len); | |
1396 | } else { | |
1397 | buf_cmd[10] = tmf->tmf; | |
1398 | switch (tmf->tmf) { | |
1399 | case TMF_ABORT_TASK: | |
1400 | case TMF_QUERY_TASK: | |
1401 | buf_cmd[12] = | |
1402 | (tmf->tag_of_task_to_be_managed >> 8) & 0xff; | |
1403 | buf_cmd[13] = | |
1404 | tmf->tag_of_task_to_be_managed & 0xff; | |
1405 | break; | |
1406 | default: | |
1407 | break; | |
1408 | } | |
1409 | } | |
1410 | ||
1411 | return 0; | |
1412 | } | |
1413 | ||
6f2ff1a1 JG |
1414 | static void sata_done_v2_hw(struct hisi_hba *hisi_hba, struct sas_task *task, |
1415 | struct hisi_sas_slot *slot) | |
1416 | { | |
1417 | struct task_status_struct *ts = &task->task_status; | |
1418 | struct ata_task_resp *resp = (struct ata_task_resp *)ts->buf; | |
1419 | struct dev_to_host_fis *d2h = slot->status_buffer + | |
1420 | sizeof(struct hisi_sas_err_record); | |
1421 | ||
1422 | resp->frame_len = sizeof(struct dev_to_host_fis); | |
1423 | memcpy(&resp->ending_fis[0], d2h, sizeof(struct dev_to_host_fis)); | |
1424 | ||
1425 | ts->buf_valid_size = sizeof(*resp); | |
1426 | } | |
e8fed0e9 JG |
1427 | |
1428 | /* by default, task resp is complete */ | |
1429 | static void slot_err_v2_hw(struct hisi_hba *hisi_hba, | |
1430 | struct sas_task *task, | |
1431 | struct hisi_sas_slot *slot) | |
1432 | { | |
1433 | struct task_status_struct *ts = &task->task_status; | |
1434 | struct hisi_sas_err_record_v2 *err_record = slot->status_buffer; | |
1435 | u32 trans_tx_fail_type = cpu_to_le32(err_record->trans_tx_fail_type); | |
1436 | u32 trans_rx_fail_type = cpu_to_le32(err_record->trans_rx_fail_type); | |
1437 | u16 dma_tx_err_type = cpu_to_le16(err_record->dma_tx_err_type); | |
1438 | u16 sipc_rx_err_type = cpu_to_le16(err_record->sipc_rx_err_type); | |
1439 | u32 dma_rx_err_type = cpu_to_le32(err_record->dma_rx_err_type); | |
1440 | int error = -1; | |
1441 | ||
1442 | if (dma_rx_err_type) { | |
1443 | error = ffs(dma_rx_err_type) | |
1444 | - 1 + DMA_RX_ERR_BASE; | |
1445 | } else if (sipc_rx_err_type) { | |
1446 | error = ffs(sipc_rx_err_type) | |
1447 | - 1 + SIPC_RX_ERR_BASE; | |
1448 | } else if (dma_tx_err_type) { | |
1449 | error = ffs(dma_tx_err_type) | |
1450 | - 1 + DMA_TX_ERR_BASE; | |
1451 | } else if (trans_rx_fail_type) { | |
1452 | error = ffs(trans_rx_fail_type) | |
1453 | - 1 + TRANS_RX_FAIL_BASE; | |
1454 | } else if (trans_tx_fail_type) { | |
1455 | error = ffs(trans_tx_fail_type) | |
1456 | - 1 + TRANS_TX_FAIL_BASE; | |
1457 | } | |
1458 | ||
1459 | switch (task->task_proto) { | |
1460 | case SAS_PROTOCOL_SSP: | |
1461 | { | |
1462 | switch (error) { | |
1463 | case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION: | |
1464 | { | |
1465 | ts->stat = SAS_OPEN_REJECT; | |
1466 | ts->open_rej_reason = SAS_OREJ_NO_DEST; | |
1467 | break; | |
1468 | } | |
1469 | case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED: | |
1470 | { | |
1471 | ts->stat = SAS_OPEN_REJECT; | |
1472 | ts->open_rej_reason = SAS_OREJ_PATH_BLOCKED; | |
1473 | break; | |
1474 | } | |
1475 | case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED: | |
1476 | { | |
1477 | ts->stat = SAS_OPEN_REJECT; | |
1478 | ts->open_rej_reason = SAS_OREJ_EPROTO; | |
1479 | break; | |
1480 | } | |
1481 | case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED: | |
1482 | { | |
1483 | ts->stat = SAS_OPEN_REJECT; | |
1484 | ts->open_rej_reason = SAS_OREJ_CONN_RATE; | |
1485 | break; | |
1486 | } | |
1487 | case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION: | |
1488 | { | |
1489 | ts->stat = SAS_OPEN_REJECT; | |
1490 | ts->open_rej_reason = SAS_OREJ_BAD_DEST; | |
1491 | break; | |
1492 | } | |
1493 | case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD: | |
1494 | { | |
1495 | ts->stat = SAS_OPEN_REJECT; | |
1496 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; | |
1497 | break; | |
1498 | } | |
1499 | case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION: | |
1500 | { | |
1501 | ts->stat = SAS_OPEN_REJECT; | |
1502 | ts->open_rej_reason = SAS_OREJ_WRONG_DEST; | |
1503 | break; | |
1504 | } | |
1505 | case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION: | |
1506 | { | |
1507 | ts->stat = SAS_OPEN_REJECT; | |
1508 | ts->open_rej_reason = SAS_OREJ_UNKNOWN; | |
1509 | break; | |
1510 | } | |
1511 | case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER: | |
1512 | { | |
1513 | /* not sure */ | |
1514 | ts->stat = SAS_DEV_NO_RESPONSE; | |
1515 | break; | |
1516 | } | |
1517 | case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE: | |
1518 | { | |
1519 | ts->stat = SAS_PHY_DOWN; | |
1520 | break; | |
1521 | } | |
1522 | case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT: | |
1523 | { | |
1524 | ts->stat = SAS_OPEN_TO; | |
1525 | break; | |
1526 | } | |
1527 | case DMA_RX_DATA_LEN_OVERFLOW: | |
1528 | { | |
1529 | ts->stat = SAS_DATA_OVERRUN; | |
1530 | ts->residual = 0; | |
1531 | break; | |
1532 | } | |
1533 | case DMA_RX_DATA_LEN_UNDERFLOW: | |
1534 | case SIPC_RX_DATA_UNDERFLOW_ERR: | |
1535 | { | |
1536 | ts->residual = trans_tx_fail_type; | |
1537 | ts->stat = SAS_DATA_UNDERRUN; | |
1538 | break; | |
1539 | } | |
9c8ee657 JG |
1540 | case TRANS_TX_ERR_FRAME_TXED: |
1541 | { | |
1542 | /* This will request a retry */ | |
1543 | ts->stat = SAS_QUEUE_FULL; | |
1544 | slot->abort = 1; | |
1545 | break; | |
1546 | } | |
e8fed0e9 JG |
1547 | case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS: |
1548 | case TRANS_TX_ERR_PHY_NOT_ENABLE: | |
1549 | case TRANS_TX_OPEN_CNX_ERR_BY_OTHER: | |
1550 | case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT: | |
1551 | case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED: | |
1552 | case TRANS_TX_ERR_WITH_BREAK_TIMEOUT: | |
1553 | case TRANS_TX_ERR_WITH_BREAK_REQUEST: | |
1554 | case TRANS_TX_ERR_WITH_BREAK_RECEVIED: | |
1555 | case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT: | |
1556 | case TRANS_TX_ERR_WITH_CLOSE_NORMAL: | |
1557 | case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT: | |
1558 | case TRANS_TX_ERR_WITH_CLOSE_COMINIT: | |
1559 | case TRANS_TX_ERR_WITH_NAK_RECEVIED: | |
1560 | case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT: | |
1561 | case TRANS_TX_ERR_WITH_IPTT_CONFLICT: | |
1562 | case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT: | |
1563 | case TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR: | |
1564 | case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR: | |
1565 | case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM: | |
1566 | case TRANS_RX_ERR_WITH_BREAK_TIMEOUT: | |
1567 | case TRANS_RX_ERR_WITH_BREAK_REQUEST: | |
1568 | case TRANS_RX_ERR_WITH_BREAK_RECEVIED: | |
1569 | case TRANS_RX_ERR_WITH_CLOSE_NORMAL: | |
1570 | case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT: | |
1571 | case TRANS_RX_ERR_WITH_CLOSE_COMINIT: | |
1572 | case TRANS_RX_ERR_WITH_DATA_LEN0: | |
1573 | case TRANS_RX_ERR_WITH_BAD_HASH: | |
1574 | case TRANS_RX_XRDY_WLEN_ZERO_ERR: | |
1575 | case TRANS_RX_SSP_FRM_LEN_ERR: | |
1576 | case TRANS_RX_ERR_WITH_BAD_FRM_TYPE: | |
1577 | case DMA_TX_UNEXP_XFER_ERR: | |
1578 | case DMA_TX_UNEXP_RETRANS_ERR: | |
1579 | case DMA_TX_XFER_LEN_OVERFLOW: | |
1580 | case DMA_TX_XFER_OFFSET_ERR: | |
1581 | case DMA_RX_DATA_OFFSET_ERR: | |
1582 | case DMA_RX_UNEXP_NORM_RESP_ERR: | |
1583 | case DMA_RX_UNEXP_RDFRAME_ERR: | |
1584 | case DMA_RX_UNKNOWN_FRM_ERR: | |
1585 | { | |
1586 | ts->stat = SAS_OPEN_REJECT; | |
1587 | ts->open_rej_reason = SAS_OREJ_UNKNOWN; | |
1588 | break; | |
1589 | } | |
1590 | default: | |
1591 | break; | |
1592 | } | |
1593 | } | |
1594 | break; | |
1595 | case SAS_PROTOCOL_SMP: | |
1596 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
1597 | break; | |
1598 | ||
1599 | case SAS_PROTOCOL_SATA: | |
1600 | case SAS_PROTOCOL_STP: | |
1601 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
1602 | { | |
1603 | switch (error) { | |
1604 | case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER: | |
1605 | case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED: | |
1606 | case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION: | |
1607 | { | |
1608 | ts->resp = SAS_TASK_UNDELIVERED; | |
1609 | ts->stat = SAS_DEV_NO_RESPONSE; | |
1610 | break; | |
1611 | } | |
1612 | case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED: | |
1613 | case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED: | |
1614 | case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION: | |
1615 | case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD: | |
1616 | case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION: | |
1617 | case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION: | |
1618 | case TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY: | |
1619 | { | |
1620 | ts->stat = SAS_OPEN_REJECT; | |
1621 | break; | |
1622 | } | |
1623 | case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT: | |
1624 | { | |
1625 | ts->stat = SAS_OPEN_TO; | |
1626 | break; | |
1627 | } | |
1628 | case DMA_RX_DATA_LEN_OVERFLOW: | |
1629 | { | |
1630 | ts->stat = SAS_DATA_OVERRUN; | |
1631 | break; | |
1632 | } | |
1633 | case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS: | |
1634 | case TRANS_TX_ERR_PHY_NOT_ENABLE: | |
1635 | case TRANS_TX_OPEN_CNX_ERR_BY_OTHER: | |
1636 | case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT: | |
1637 | case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED: | |
1638 | case TRANS_TX_ERR_WITH_BREAK_TIMEOUT: | |
1639 | case TRANS_TX_ERR_WITH_BREAK_REQUEST: | |
1640 | case TRANS_TX_ERR_WITH_BREAK_RECEVIED: | |
1641 | case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT: | |
1642 | case TRANS_TX_ERR_WITH_CLOSE_NORMAL: | |
1643 | case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT: | |
1644 | case TRANS_TX_ERR_WITH_CLOSE_COMINIT: | |
1645 | case TRANS_TX_ERR_WITH_NAK_RECEVIED: | |
1646 | case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT: | |
1647 | case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT: | |
1648 | case TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT: | |
1649 | case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR: | |
1650 | case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM: | |
1651 | case TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR: | |
1652 | case TRANS_RX_ERR_WITH_RXFIS_CRC_ERR: | |
1653 | case TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN: | |
1654 | case TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP: | |
1655 | case TRANS_RX_ERR_WITH_CLOSE_NORMAL: | |
1656 | case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE: | |
1657 | case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT: | |
1658 | case TRANS_RX_ERR_WITH_CLOSE_COMINIT: | |
1659 | case TRANS_RX_ERR_WITH_DATA_LEN0: | |
1660 | case TRANS_RX_ERR_WITH_BAD_HASH: | |
1661 | case TRANS_RX_XRDY_WLEN_ZERO_ERR: | |
1662 | case TRANS_RX_SSP_FRM_LEN_ERR: | |
1663 | case SIPC_RX_FIS_STATUS_ERR_BIT_VLD: | |
1664 | case SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR: | |
1665 | case SIPC_RX_FIS_STATUS_BSY_BIT_ERR: | |
1666 | case SIPC_RX_WRSETUP_LEN_ODD_ERR: | |
1667 | case SIPC_RX_WRSETUP_LEN_ZERO_ERR: | |
1668 | case SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR: | |
1669 | case SIPC_RX_SATA_UNEXP_FIS_ERR: | |
1670 | case DMA_RX_SATA_FRAME_TYPE_ERR: | |
1671 | case DMA_RX_UNEXP_RDFRAME_ERR: | |
1672 | case DMA_RX_PIO_DATA_LEN_ERR: | |
1673 | case DMA_RX_RDSETUP_STATUS_ERR: | |
1674 | case DMA_RX_RDSETUP_STATUS_DRQ_ERR: | |
1675 | case DMA_RX_RDSETUP_STATUS_BSY_ERR: | |
1676 | case DMA_RX_RDSETUP_LEN_ODD_ERR: | |
1677 | case DMA_RX_RDSETUP_LEN_ZERO_ERR: | |
1678 | case DMA_RX_RDSETUP_LEN_OVER_ERR: | |
1679 | case DMA_RX_RDSETUP_OFFSET_ERR: | |
1680 | case DMA_RX_RDSETUP_ACTIVE_ERR: | |
1681 | case DMA_RX_RDSETUP_ESTATUS_ERR: | |
1682 | case DMA_RX_UNKNOWN_FRM_ERR: | |
1683 | { | |
1684 | ts->stat = SAS_OPEN_REJECT; | |
1685 | break; | |
1686 | } | |
1687 | default: | |
1688 | { | |
1689 | ts->stat = SAS_PROTO_RESPONSE; | |
1690 | break; | |
1691 | } | |
1692 | } | |
1693 | sata_done_v2_hw(hisi_hba, task, slot); | |
1694 | } | |
1695 | break; | |
1696 | default: | |
1697 | break; | |
1698 | } | |
1699 | } | |
1700 | ||
31a9cfa6 JG |
1701 | static int |
1702 | slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot, | |
1703 | int abort) | |
1704 | { | |
1705 | struct sas_task *task = slot->task; | |
1706 | struct hisi_sas_device *sas_dev; | |
1707 | struct device *dev = &hisi_hba->pdev->dev; | |
1708 | struct task_status_struct *ts; | |
1709 | struct domain_device *device; | |
1710 | enum exec_status sts; | |
1711 | struct hisi_sas_complete_v2_hdr *complete_queue = | |
1712 | hisi_hba->complete_hdr[slot->cmplt_queue]; | |
1713 | struct hisi_sas_complete_v2_hdr *complete_hdr = | |
1714 | &complete_queue[slot->cmplt_queue_slot]; | |
1715 | ||
1716 | if (unlikely(!task || !task->lldd_task || !task->dev)) | |
1717 | return -EINVAL; | |
1718 | ||
1719 | ts = &task->task_status; | |
1720 | device = task->dev; | |
1721 | sas_dev = device->lldd_dev; | |
1722 | ||
1723 | task->task_state_flags &= | |
1724 | ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); | |
1725 | task->task_state_flags |= SAS_TASK_STATE_DONE; | |
1726 | ||
1727 | memset(ts, 0, sizeof(*ts)); | |
1728 | ts->resp = SAS_TASK_COMPLETE; | |
1729 | ||
1730 | if (unlikely(!sas_dev || abort)) { | |
1731 | if (!sas_dev) | |
1732 | dev_dbg(dev, "slot complete: port has not device\n"); | |
1733 | ts->stat = SAS_PHY_DOWN; | |
1734 | goto out; | |
1735 | } | |
1736 | ||
df032d0e JG |
1737 | /* Use SAS+TMF status codes */ |
1738 | switch ((complete_hdr->dw0 & CMPLT_HDR_ABORT_STAT_MSK) | |
1739 | >> CMPLT_HDR_ABORT_STAT_OFF) { | |
1740 | case STAT_IO_ABORTED: | |
1741 | /* this io has been aborted by abort command */ | |
1742 | ts->stat = SAS_ABORTED_TASK; | |
1743 | goto out; | |
1744 | case STAT_IO_COMPLETE: | |
1745 | /* internal abort command complete */ | |
1746 | ts->stat = TMF_RESP_FUNC_COMPLETE; | |
1747 | goto out; | |
1748 | case STAT_IO_NO_DEVICE: | |
1749 | ts->stat = TMF_RESP_FUNC_COMPLETE; | |
1750 | goto out; | |
1751 | case STAT_IO_NOT_VALID: | |
1752 | /* abort single io, controller don't find | |
1753 | * the io need to abort | |
1754 | */ | |
1755 | ts->stat = TMF_RESP_FUNC_FAILED; | |
1756 | goto out; | |
1757 | default: | |
1758 | break; | |
1759 | } | |
1760 | ||
31a9cfa6 JG |
1761 | if ((complete_hdr->dw0 & CMPLT_HDR_ERX_MSK) && |
1762 | (!(complete_hdr->dw0 & CMPLT_HDR_RSPNS_XFRD_MSK))) { | |
31a9cfa6 | 1763 | |
e8fed0e9 | 1764 | slot_err_v2_hw(hisi_hba, task, slot); |
9c8ee657 JG |
1765 | if (unlikely(slot->abort)) { |
1766 | queue_work(hisi_hba->wq, &slot->abort_slot); | |
1767 | /* immediately return and do not complete */ | |
1768 | return ts->stat; | |
1769 | } | |
31a9cfa6 JG |
1770 | goto out; |
1771 | } | |
1772 | ||
1773 | switch (task->task_proto) { | |
1774 | case SAS_PROTOCOL_SSP: | |
1775 | { | |
1776 | struct ssp_response_iu *iu = slot->status_buffer + | |
1777 | sizeof(struct hisi_sas_err_record); | |
1778 | ||
1779 | sas_ssp_task_response(dev, task, iu); | |
1780 | break; | |
1781 | } | |
1782 | case SAS_PROTOCOL_SMP: | |
1783 | { | |
1784 | struct scatterlist *sg_resp = &task->smp_task.smp_resp; | |
1785 | void *to; | |
1786 | ||
1787 | ts->stat = SAM_STAT_GOOD; | |
1788 | to = kmap_atomic(sg_page(sg_resp)); | |
1789 | ||
1790 | dma_unmap_sg(dev, &task->smp_task.smp_resp, 1, | |
1791 | DMA_FROM_DEVICE); | |
1792 | dma_unmap_sg(dev, &task->smp_task.smp_req, 1, | |
1793 | DMA_TO_DEVICE); | |
1794 | memcpy(to + sg_resp->offset, | |
1795 | slot->status_buffer + | |
1796 | sizeof(struct hisi_sas_err_record), | |
1797 | sg_dma_len(sg_resp)); | |
1798 | kunmap_atomic(to); | |
1799 | break; | |
1800 | } | |
1801 | case SAS_PROTOCOL_SATA: | |
1802 | case SAS_PROTOCOL_STP: | |
1803 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
6f2ff1a1 JG |
1804 | { |
1805 | ts->stat = SAM_STAT_GOOD; | |
1806 | sata_done_v2_hw(hisi_hba, task, slot); | |
1807 | break; | |
1808 | } | |
31a9cfa6 JG |
1809 | default: |
1810 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
1811 | break; | |
1812 | } | |
1813 | ||
1814 | if (!slot->port->port_attached) { | |
1815 | dev_err(dev, "slot complete: port %d has removed\n", | |
1816 | slot->port->sas_port.id); | |
1817 | ts->stat = SAS_PHY_DOWN; | |
1818 | } | |
1819 | ||
1820 | out: | |
f696cc32 JG |
1821 | if (sas_dev) |
1822 | atomic64_dec(&sas_dev->running_req); | |
31a9cfa6 JG |
1823 | |
1824 | hisi_sas_slot_task_free(hisi_hba, task, slot); | |
1825 | sts = ts->stat; | |
1826 | ||
1827 | if (task->task_done) | |
1828 | task->task_done(task); | |
1829 | ||
1830 | return sts; | |
1831 | } | |
1832 | ||
6f2ff1a1 JG |
1833 | static u8 get_ata_protocol(u8 cmd, int direction) |
1834 | { | |
1835 | switch (cmd) { | |
1836 | case ATA_CMD_FPDMA_WRITE: | |
1837 | case ATA_CMD_FPDMA_READ: | |
ef026b18 HR |
1838 | case ATA_CMD_FPDMA_RECV: |
1839 | case ATA_CMD_FPDMA_SEND: | |
661ce1f0 | 1840 | case ATA_CMD_NCQ_NON_DATA: |
6f2ff1a1 JG |
1841 | return SATA_PROTOCOL_FPDMA; |
1842 | ||
ee44bfe4 | 1843 | case ATA_CMD_DOWNLOAD_MICRO: |
6f2ff1a1 JG |
1844 | case ATA_CMD_ID_ATA: |
1845 | case ATA_CMD_PMP_READ: | |
1846 | case ATA_CMD_READ_LOG_EXT: | |
1847 | case ATA_CMD_PIO_READ: | |
1848 | case ATA_CMD_PIO_READ_EXT: | |
1849 | case ATA_CMD_PMP_WRITE: | |
1850 | case ATA_CMD_WRITE_LOG_EXT: | |
1851 | case ATA_CMD_PIO_WRITE: | |
1852 | case ATA_CMD_PIO_WRITE_EXT: | |
1853 | return SATA_PROTOCOL_PIO; | |
1854 | ||
ee44bfe4 XC |
1855 | case ATA_CMD_DSM: |
1856 | case ATA_CMD_DOWNLOAD_MICRO_DMA: | |
1857 | case ATA_CMD_PMP_READ_DMA: | |
1858 | case ATA_CMD_PMP_WRITE_DMA: | |
6f2ff1a1 JG |
1859 | case ATA_CMD_READ: |
1860 | case ATA_CMD_READ_EXT: | |
1861 | case ATA_CMD_READ_LOG_DMA_EXT: | |
ee44bfe4 XC |
1862 | case ATA_CMD_READ_STREAM_DMA_EXT: |
1863 | case ATA_CMD_TRUSTED_RCV_DMA: | |
1864 | case ATA_CMD_TRUSTED_SND_DMA: | |
6f2ff1a1 JG |
1865 | case ATA_CMD_WRITE: |
1866 | case ATA_CMD_WRITE_EXT: | |
ee44bfe4 | 1867 | case ATA_CMD_WRITE_FUA_EXT: |
6f2ff1a1 JG |
1868 | case ATA_CMD_WRITE_QUEUED: |
1869 | case ATA_CMD_WRITE_LOG_DMA_EXT: | |
ee44bfe4 | 1870 | case ATA_CMD_WRITE_STREAM_DMA_EXT: |
6f2ff1a1 JG |
1871 | return SATA_PROTOCOL_DMA; |
1872 | ||
6f2ff1a1 | 1873 | case ATA_CMD_CHK_POWER: |
ee44bfe4 XC |
1874 | case ATA_CMD_DEV_RESET: |
1875 | case ATA_CMD_EDD: | |
6f2ff1a1 JG |
1876 | case ATA_CMD_FLUSH: |
1877 | case ATA_CMD_FLUSH_EXT: | |
1878 | case ATA_CMD_VERIFY: | |
1879 | case ATA_CMD_VERIFY_EXT: | |
1880 | case ATA_CMD_SET_FEATURES: | |
1881 | case ATA_CMD_STANDBY: | |
1882 | case ATA_CMD_STANDBYNOW1: | |
1883 | return SATA_PROTOCOL_NONDATA; | |
1884 | default: | |
1885 | if (direction == DMA_NONE) | |
1886 | return SATA_PROTOCOL_NONDATA; | |
1887 | return SATA_PROTOCOL_PIO; | |
1888 | } | |
1889 | } | |
1890 | ||
1891 | static int get_ncq_tag_v2_hw(struct sas_task *task, u32 *tag) | |
1892 | { | |
1893 | struct ata_queued_cmd *qc = task->uldd_task; | |
1894 | ||
1895 | if (qc) { | |
1896 | if (qc->tf.command == ATA_CMD_FPDMA_WRITE || | |
1897 | qc->tf.command == ATA_CMD_FPDMA_READ) { | |
1898 | *tag = qc->tag; | |
1899 | return 1; | |
1900 | } | |
1901 | } | |
1902 | return 0; | |
1903 | } | |
1904 | ||
1905 | static int prep_ata_v2_hw(struct hisi_hba *hisi_hba, | |
1906 | struct hisi_sas_slot *slot) | |
1907 | { | |
1908 | struct sas_task *task = slot->task; | |
1909 | struct domain_device *device = task->dev; | |
1910 | struct domain_device *parent_dev = device->parent; | |
1911 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
1912 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1913 | struct hisi_sas_port *port = device->port->lldd_port; | |
1914 | u8 *buf_cmd; | |
1915 | int has_data = 0, rc = 0, hdr_tag = 0; | |
1916 | u32 dw1 = 0, dw2 = 0; | |
1917 | ||
1918 | /* create header */ | |
1919 | /* dw0 */ | |
1920 | hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF); | |
1921 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) | |
1922 | hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF); | |
1923 | else | |
1924 | hdr->dw0 |= cpu_to_le32(4 << CMD_HDR_CMD_OFF); | |
1925 | ||
1926 | /* dw1 */ | |
1927 | switch (task->data_dir) { | |
1928 | case DMA_TO_DEVICE: | |
1929 | has_data = 1; | |
1930 | dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF; | |
1931 | break; | |
1932 | case DMA_FROM_DEVICE: | |
1933 | has_data = 1; | |
1934 | dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF; | |
1935 | break; | |
1936 | default: | |
1937 | dw1 &= ~CMD_HDR_DIR_MSK; | |
1938 | } | |
1939 | ||
1940 | if (0 == task->ata_task.fis.command) | |
1941 | dw1 |= 1 << CMD_HDR_RESET_OFF; | |
1942 | ||
1943 | dw1 |= (get_ata_protocol(task->ata_task.fis.command, task->data_dir)) | |
1944 | << CMD_HDR_FRAME_TYPE_OFF; | |
1945 | dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; | |
1946 | hdr->dw1 = cpu_to_le32(dw1); | |
1947 | ||
1948 | /* dw2 */ | |
1949 | if (task->ata_task.use_ncq && get_ncq_tag_v2_hw(task, &hdr_tag)) { | |
1950 | task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); | |
1951 | dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF; | |
1952 | } | |
1953 | ||
1954 | dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF | | |
1955 | 2 << CMD_HDR_SG_MOD_OFF; | |
1956 | hdr->dw2 = cpu_to_le32(dw2); | |
1957 | ||
1958 | /* dw3 */ | |
1959 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
1960 | ||
1961 | if (has_data) { | |
1962 | rc = prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter, | |
1963 | slot->n_elem); | |
1964 | if (rc) | |
1965 | return rc; | |
1966 | } | |
1967 | ||
1968 | ||
1969 | hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len); | |
1970 | hdr->cmd_table_addr = cpu_to_le64(slot->command_table_dma); | |
1971 | hdr->sts_buffer_addr = cpu_to_le64(slot->status_buffer_dma); | |
1972 | ||
1973 | buf_cmd = slot->command_table; | |
1974 | ||
1975 | if (likely(!task->ata_task.device_control_reg_update)) | |
1976 | task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */ | |
1977 | /* fill in command FIS */ | |
1978 | memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); | |
1979 | ||
1980 | return 0; | |
1981 | } | |
1982 | ||
a3e665d9 JG |
1983 | static int prep_abort_v2_hw(struct hisi_hba *hisi_hba, |
1984 | struct hisi_sas_slot *slot, | |
1985 | int device_id, int abort_flag, int tag_to_abort) | |
1986 | { | |
1987 | struct sas_task *task = slot->task; | |
1988 | struct domain_device *dev = task->dev; | |
1989 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1990 | struct hisi_sas_port *port = slot->port; | |
1991 | ||
1992 | /* dw0 */ | |
1993 | hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/ | |
1994 | (port->id << CMD_HDR_PORT_OFF) | | |
1995 | ((dev_is_sata(dev) ? 1:0) << | |
1996 | CMD_HDR_ABORT_DEVICE_TYPE_OFF) | | |
1997 | (abort_flag << CMD_HDR_ABORT_FLAG_OFF)); | |
1998 | ||
1999 | /* dw1 */ | |
2000 | hdr->dw1 = cpu_to_le32(device_id << CMD_HDR_DEV_ID_OFF); | |
2001 | ||
2002 | /* dw7 */ | |
2003 | hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF); | |
2004 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
2005 | ||
2006 | return 0; | |
2007 | } | |
2008 | ||
7911e66f JG |
2009 | static int phy_up_v2_hw(int phy_no, struct hisi_hba *hisi_hba) |
2010 | { | |
2011 | int i, res = 0; | |
2012 | u32 context, port_id, link_rate, hard_phy_linkrate; | |
2013 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
2014 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
2015 | struct device *dev = &hisi_hba->pdev->dev; | |
2016 | u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd; | |
2017 | struct sas_identify_frame *id = (struct sas_identify_frame *)frame_rcvd; | |
2018 | ||
2019 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1); | |
2020 | ||
2021 | /* Check for SATA dev */ | |
2022 | context = hisi_sas_read32(hisi_hba, PHY_CONTEXT); | |
2023 | if (context & (1 << phy_no)) | |
2024 | goto end; | |
2025 | ||
2026 | if (phy_no == 8) { | |
2027 | u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
2028 | ||
2029 | port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >> | |
2030 | PORT_STATE_PHY8_PORT_NUM_OFF; | |
2031 | link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >> | |
2032 | PORT_STATE_PHY8_CONN_RATE_OFF; | |
2033 | } else { | |
2034 | port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
2035 | port_id = (port_id >> (4 * phy_no)) & 0xf; | |
2036 | link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE); | |
2037 | link_rate = (link_rate >> (phy_no * 4)) & 0xf; | |
2038 | } | |
2039 | ||
2040 | if (port_id == 0xf) { | |
2041 | dev_err(dev, "phyup: phy%d invalid portid\n", phy_no); | |
2042 | res = IRQ_NONE; | |
2043 | goto end; | |
2044 | } | |
2045 | ||
2046 | for (i = 0; i < 6; i++) { | |
2047 | u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2048 | RX_IDAF_DWORD0 + (i * 4)); | |
2049 | frame_rcvd[i] = __swab32(idaf); | |
2050 | } | |
2051 | ||
7911e66f JG |
2052 | sas_phy->linkrate = link_rate; |
2053 | hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2054 | HARD_PHY_LINKRATE); | |
2055 | phy->maximum_linkrate = hard_phy_linkrate & 0xf; | |
2056 | phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf; | |
2057 | ||
2058 | sas_phy->oob_mode = SAS_OOB_MODE; | |
2059 | memcpy(sas_phy->attached_sas_addr, &id->sas_addr, SAS_ADDR_SIZE); | |
2060 | dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate); | |
2061 | phy->port_id = port_id; | |
2062 | phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); | |
2063 | phy->phy_type |= PORT_TYPE_SAS; | |
2064 | phy->phy_attached = 1; | |
2065 | phy->identify.device_type = id->dev_type; | |
2066 | phy->frame_rcvd_size = sizeof(struct sas_identify_frame); | |
2067 | if (phy->identify.device_type == SAS_END_DEVICE) | |
2068 | phy->identify.target_port_protocols = | |
2069 | SAS_PROTOCOL_SSP; | |
f2f89c32 | 2070 | else if (phy->identify.device_type != SAS_PHY_UNUSED) { |
7911e66f JG |
2071 | phy->identify.target_port_protocols = |
2072 | SAS_PROTOCOL_SMP; | |
f2f89c32 XC |
2073 | if (!timer_pending(&hisi_hba->timer)) |
2074 | set_link_timer_quirk(hisi_hba); | |
2075 | } | |
7911e66f JG |
2076 | queue_work(hisi_hba->wq, &phy->phyup_ws); |
2077 | ||
2078 | end: | |
2079 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, | |
2080 | CHL_INT0_SL_PHY_ENABLE_MSK); | |
2081 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0); | |
2082 | ||
2083 | return res; | |
2084 | } | |
2085 | ||
f2f89c32 XC |
2086 | static bool check_any_wideports_v2_hw(struct hisi_hba *hisi_hba) |
2087 | { | |
2088 | u32 port_state; | |
2089 | ||
2090 | port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
2091 | if (port_state & 0x1ff) | |
2092 | return true; | |
2093 | ||
2094 | return false; | |
2095 | } | |
2096 | ||
5473c060 JG |
2097 | static int phy_down_v2_hw(int phy_no, struct hisi_hba *hisi_hba) |
2098 | { | |
2099 | int res = 0; | |
9c81e2cf | 2100 | u32 phy_state, sl_ctrl, txid_auto; |
f2f89c32 XC |
2101 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
2102 | struct hisi_sas_port *port = phy->port; | |
5473c060 JG |
2103 | |
2104 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1); | |
2105 | ||
5473c060 | 2106 | phy_state = hisi_sas_read32(hisi_hba, PHY_STATE); |
5473c060 JG |
2107 | hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0); |
2108 | ||
9c81e2cf JG |
2109 | sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); |
2110 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, | |
2111 | sl_ctrl & ~SL_CONTROL_CTA_MSK); | |
f2f89c32 XC |
2112 | if (port && !get_wideport_bitmap_v2_hw(hisi_hba, port->id)) |
2113 | if (!check_any_wideports_v2_hw(hisi_hba) && | |
2114 | timer_pending(&hisi_hba->timer)) | |
2115 | del_timer(&hisi_hba->timer); | |
9c81e2cf JG |
2116 | |
2117 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO); | |
2118 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
2119 | txid_auto | TXID_AUTO_CT3_MSK); | |
2120 | ||
5473c060 JG |
2121 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK); |
2122 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0); | |
2123 | ||
2124 | return res; | |
2125 | } | |
2126 | ||
7911e66f JG |
2127 | static irqreturn_t int_phy_updown_v2_hw(int irq_no, void *p) |
2128 | { | |
2129 | struct hisi_hba *hisi_hba = p; | |
2130 | u32 irq_msk; | |
2131 | int phy_no = 0; | |
2132 | irqreturn_t res = IRQ_HANDLED; | |
2133 | ||
2134 | irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO) | |
2135 | >> HGC_INVLD_DQE_INFO_FB_CH0_OFF) & 0x1ff; | |
2136 | while (irq_msk) { | |
2137 | if (irq_msk & 1) { | |
2138 | u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2139 | CHL_INT0); | |
2140 | ||
2141 | if (irq_value & CHL_INT0_SL_PHY_ENABLE_MSK) | |
2142 | /* phy up */ | |
2143 | if (phy_up_v2_hw(phy_no, hisi_hba)) { | |
2144 | res = IRQ_NONE; | |
2145 | goto end; | |
2146 | } | |
2147 | ||
5473c060 JG |
2148 | if (irq_value & CHL_INT0_NOT_RDY_MSK) |
2149 | /* phy down */ | |
2150 | if (phy_down_v2_hw(phy_no, hisi_hba)) { | |
2151 | res = IRQ_NONE; | |
2152 | goto end; | |
2153 | } | |
7911e66f JG |
2154 | } |
2155 | irq_msk >>= 1; | |
2156 | phy_no++; | |
2157 | } | |
2158 | ||
2159 | end: | |
2160 | return res; | |
2161 | } | |
2162 | ||
d3bf3d84 JG |
2163 | static void phy_bcast_v2_hw(int phy_no, struct hisi_hba *hisi_hba) |
2164 | { | |
2165 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
2166 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
2167 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; | |
85080a25 | 2168 | u32 bcast_status; |
d3bf3d84 JG |
2169 | |
2170 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1); | |
85080a25 XC |
2171 | bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS); |
2172 | if (bcast_status & RX_BCAST_CHG_MSK) | |
2173 | sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); | |
d3bf3d84 JG |
2174 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, |
2175 | CHL_INT0_SL_RX_BCST_ACK_MSK); | |
2176 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0); | |
2177 | } | |
2178 | ||
2179 | static irqreturn_t int_chnl_int_v2_hw(int irq_no, void *p) | |
2180 | { | |
2181 | struct hisi_hba *hisi_hba = p; | |
2182 | struct device *dev = &hisi_hba->pdev->dev; | |
2183 | u32 ent_msk, ent_tmp, irq_msk; | |
2184 | int phy_no = 0; | |
2185 | ||
2186 | ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3); | |
2187 | ent_tmp = ent_msk; | |
2188 | ent_msk |= ENT_INT_SRC_MSK3_ENT95_MSK_MSK; | |
2189 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_msk); | |
2190 | ||
2191 | irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO) >> | |
2192 | HGC_INVLD_DQE_INFO_FB_CH3_OFF) & 0x1ff; | |
2193 | ||
2194 | while (irq_msk) { | |
2195 | if (irq_msk & (1 << phy_no)) { | |
2196 | u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2197 | CHL_INT0); | |
2198 | u32 irq_value1 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2199 | CHL_INT1); | |
2200 | u32 irq_value2 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2201 | CHL_INT2); | |
2202 | ||
2203 | if (irq_value1) { | |
2204 | if (irq_value1 & (CHL_INT1_DMAC_RX_ECC_ERR_MSK | | |
2205 | CHL_INT1_DMAC_TX_ECC_ERR_MSK)) | |
d3b688d3 XC |
2206 | panic("%s: DMAC RX/TX ecc bad error!\ |
2207 | (0x%x)", | |
2208 | dev_name(dev), irq_value1); | |
d3bf3d84 JG |
2209 | |
2210 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
2211 | CHL_INT1, irq_value1); | |
2212 | } | |
2213 | ||
2214 | if (irq_value2) | |
2215 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
2216 | CHL_INT2, irq_value2); | |
2217 | ||
2218 | ||
2219 | if (irq_value0) { | |
2220 | if (irq_value0 & CHL_INT0_SL_RX_BCST_ACK_MSK) | |
2221 | phy_bcast_v2_hw(phy_no, hisi_hba); | |
2222 | ||
2223 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
2224 | CHL_INT0, irq_value0 | |
2225 | & (~CHL_INT0_HOTPLUG_TOUT_MSK) | |
2226 | & (~CHL_INT0_SL_PHY_ENABLE_MSK) | |
2227 | & (~CHL_INT0_NOT_RDY_MSK)); | |
2228 | } | |
2229 | } | |
2230 | irq_msk &= ~(1 << phy_no); | |
2231 | phy_no++; | |
2232 | } | |
2233 | ||
2234 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_tmp); | |
2235 | ||
2236 | return IRQ_HANDLED; | |
2237 | } | |
2238 | ||
d3b688d3 XC |
2239 | static void |
2240 | one_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba, u32 irq_value) | |
2241 | { | |
2242 | struct device *dev = &hisi_hba->pdev->dev; | |
2243 | u32 reg_val; | |
2244 | ||
2245 | if (irq_value & BIT(SAS_ECC_INTR_DQE_ECC_1B_OFF)) { | |
2246 | reg_val = hisi_sas_read32(hisi_hba, HGC_DQE_ECC_ADDR); | |
2247 | dev_warn(dev, "hgc_dqe_acc1b_intr found: \ | |
2248 | Ram address is 0x%08X\n", | |
2249 | (reg_val & HGC_DQE_ECC_1B_ADDR_MSK) >> | |
2250 | HGC_DQE_ECC_1B_ADDR_OFF); | |
2251 | } | |
2252 | ||
2253 | if (irq_value & BIT(SAS_ECC_INTR_IOST_ECC_1B_OFF)) { | |
2254 | reg_val = hisi_sas_read32(hisi_hba, HGC_IOST_ECC_ADDR); | |
2255 | dev_warn(dev, "hgc_iost_acc1b_intr found: \ | |
2256 | Ram address is 0x%08X\n", | |
2257 | (reg_val & HGC_IOST_ECC_1B_ADDR_MSK) >> | |
2258 | HGC_IOST_ECC_1B_ADDR_OFF); | |
2259 | } | |
2260 | ||
2261 | if (irq_value & BIT(SAS_ECC_INTR_ITCT_ECC_1B_OFF)) { | |
2262 | reg_val = hisi_sas_read32(hisi_hba, HGC_ITCT_ECC_ADDR); | |
2263 | dev_warn(dev, "hgc_itct_acc1b_intr found: \ | |
2264 | Ram address is 0x%08X\n", | |
2265 | (reg_val & HGC_ITCT_ECC_1B_ADDR_MSK) >> | |
2266 | HGC_ITCT_ECC_1B_ADDR_OFF); | |
2267 | } | |
2268 | ||
2269 | if (irq_value & BIT(SAS_ECC_INTR_IOSTLIST_ECC_1B_OFF)) { | |
2270 | reg_val = hisi_sas_read32(hisi_hba, HGC_LM_DFX_STATUS2); | |
2271 | dev_warn(dev, "hgc_iostl_acc1b_intr found: \ | |
2272 | memory address is 0x%08X\n", | |
2273 | (reg_val & HGC_LM_DFX_STATUS2_IOSTLIST_MSK) >> | |
2274 | HGC_LM_DFX_STATUS2_IOSTLIST_OFF); | |
2275 | } | |
2276 | ||
2277 | if (irq_value & BIT(SAS_ECC_INTR_ITCTLIST_ECC_1B_OFF)) { | |
2278 | reg_val = hisi_sas_read32(hisi_hba, HGC_LM_DFX_STATUS2); | |
2279 | dev_warn(dev, "hgc_itctl_acc1b_intr found: \ | |
2280 | memory address is 0x%08X\n", | |
2281 | (reg_val & HGC_LM_DFX_STATUS2_ITCTLIST_MSK) >> | |
2282 | HGC_LM_DFX_STATUS2_ITCTLIST_OFF); | |
2283 | } | |
2284 | ||
2285 | if (irq_value & BIT(SAS_ECC_INTR_CQE_ECC_1B_OFF)) { | |
2286 | reg_val = hisi_sas_read32(hisi_hba, HGC_CQE_ECC_ADDR); | |
2287 | dev_warn(dev, "hgc_cqe_acc1b_intr found: \ | |
2288 | Ram address is 0x%08X\n", | |
2289 | (reg_val & HGC_CQE_ECC_1B_ADDR_MSK) >> | |
2290 | HGC_CQE_ECC_1B_ADDR_OFF); | |
2291 | } | |
2292 | ||
2293 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_1B_OFF)) { | |
2294 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS14); | |
2295 | dev_warn(dev, "rxm_mem0_acc1b_intr found: \ | |
2296 | memory address is 0x%08X\n", | |
2297 | (reg_val & HGC_RXM_DFX_STATUS14_MEM0_MSK) >> | |
2298 | HGC_RXM_DFX_STATUS14_MEM0_OFF); | |
2299 | } | |
2300 | ||
2301 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_1B_OFF)) { | |
2302 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS14); | |
2303 | dev_warn(dev, "rxm_mem1_acc1b_intr found: \ | |
2304 | memory address is 0x%08X\n", | |
2305 | (reg_val & HGC_RXM_DFX_STATUS14_MEM1_MSK) >> | |
2306 | HGC_RXM_DFX_STATUS14_MEM1_OFF); | |
2307 | } | |
2308 | ||
2309 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_1B_OFF)) { | |
2310 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS14); | |
2311 | dev_warn(dev, "rxm_mem2_acc1b_intr found: \ | |
2312 | memory address is 0x%08X\n", | |
2313 | (reg_val & HGC_RXM_DFX_STATUS14_MEM2_MSK) >> | |
2314 | HGC_RXM_DFX_STATUS14_MEM2_OFF); | |
2315 | } | |
2316 | ||
2317 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_1B_OFF)) { | |
2318 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS15); | |
2319 | dev_warn(dev, "rxm_mem3_acc1b_intr found: \ | |
2320 | memory address is 0x%08X\n", | |
2321 | (reg_val & HGC_RXM_DFX_STATUS15_MEM3_MSK) >> | |
2322 | HGC_RXM_DFX_STATUS15_MEM3_OFF); | |
2323 | } | |
2324 | ||
2325 | } | |
2326 | ||
2327 | static void multi_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba, | |
2328 | u32 irq_value) | |
2329 | { | |
2330 | u32 reg_val; | |
2331 | struct device *dev = &hisi_hba->pdev->dev; | |
2332 | ||
2333 | if (irq_value & BIT(SAS_ECC_INTR_DQE_ECC_MB_OFF)) { | |
2334 | reg_val = hisi_sas_read32(hisi_hba, HGC_DQE_ECC_ADDR); | |
2335 | panic("%s: hgc_dqe_accbad_intr (0x%x) found: \ | |
2336 | Ram address is 0x%08X\n", | |
2337 | dev_name(dev), irq_value, | |
2338 | (reg_val & HGC_DQE_ECC_MB_ADDR_MSK) >> | |
2339 | HGC_DQE_ECC_MB_ADDR_OFF); | |
2340 | } | |
2341 | ||
2342 | if (irq_value & BIT(SAS_ECC_INTR_IOST_ECC_MB_OFF)) { | |
2343 | reg_val = hisi_sas_read32(hisi_hba, HGC_IOST_ECC_ADDR); | |
2344 | panic("%s: hgc_iost_accbad_intr (0x%x) found: \ | |
2345 | Ram address is 0x%08X\n", | |
2346 | dev_name(dev), irq_value, | |
2347 | (reg_val & HGC_IOST_ECC_MB_ADDR_MSK) >> | |
2348 | HGC_IOST_ECC_MB_ADDR_OFF); | |
2349 | } | |
2350 | ||
2351 | if (irq_value & BIT(SAS_ECC_INTR_ITCT_ECC_MB_OFF)) { | |
2352 | reg_val = hisi_sas_read32(hisi_hba, HGC_ITCT_ECC_ADDR); | |
2353 | panic("%s: hgc_itct_accbad_intr (0x%x) found: \ | |
2354 | Ram address is 0x%08X\n", | |
2355 | dev_name(dev), irq_value, | |
2356 | (reg_val & HGC_ITCT_ECC_MB_ADDR_MSK) >> | |
2357 | HGC_ITCT_ECC_MB_ADDR_OFF); | |
2358 | } | |
2359 | ||
2360 | if (irq_value & BIT(SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF)) { | |
2361 | reg_val = hisi_sas_read32(hisi_hba, HGC_LM_DFX_STATUS2); | |
2362 | panic("%s: hgc_iostl_accbad_intr (0x%x) found: \ | |
2363 | memory address is 0x%08X\n", | |
2364 | dev_name(dev), irq_value, | |
2365 | (reg_val & HGC_LM_DFX_STATUS2_IOSTLIST_MSK) >> | |
2366 | HGC_LM_DFX_STATUS2_IOSTLIST_OFF); | |
2367 | } | |
2368 | ||
2369 | if (irq_value & BIT(SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF)) { | |
2370 | reg_val = hisi_sas_read32(hisi_hba, HGC_LM_DFX_STATUS2); | |
2371 | panic("%s: hgc_itctl_accbad_intr (0x%x) found: \ | |
2372 | memory address is 0x%08X\n", | |
2373 | dev_name(dev), irq_value, | |
2374 | (reg_val & HGC_LM_DFX_STATUS2_ITCTLIST_MSK) >> | |
2375 | HGC_LM_DFX_STATUS2_ITCTLIST_OFF); | |
2376 | } | |
2377 | ||
2378 | if (irq_value & BIT(SAS_ECC_INTR_CQE_ECC_MB_OFF)) { | |
2379 | reg_val = hisi_sas_read32(hisi_hba, HGC_CQE_ECC_ADDR); | |
2380 | panic("%s: hgc_cqe_accbad_intr (0x%x) found: \ | |
2381 | Ram address is 0x%08X\n", | |
2382 | dev_name(dev), irq_value, | |
2383 | (reg_val & HGC_CQE_ECC_MB_ADDR_MSK) >> | |
2384 | HGC_CQE_ECC_MB_ADDR_OFF); | |
2385 | } | |
2386 | ||
2387 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF)) { | |
2388 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS14); | |
2389 | panic("%s: rxm_mem0_accbad_intr (0x%x) found: \ | |
2390 | memory address is 0x%08X\n", | |
2391 | dev_name(dev), irq_value, | |
2392 | (reg_val & HGC_RXM_DFX_STATUS14_MEM0_MSK) >> | |
2393 | HGC_RXM_DFX_STATUS14_MEM0_OFF); | |
2394 | } | |
2395 | ||
2396 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF)) { | |
2397 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS14); | |
2398 | panic("%s: rxm_mem1_accbad_intr (0x%x) found: \ | |
2399 | memory address is 0x%08X\n", | |
2400 | dev_name(dev), irq_value, | |
2401 | (reg_val & HGC_RXM_DFX_STATUS14_MEM1_MSK) >> | |
2402 | HGC_RXM_DFX_STATUS14_MEM1_OFF); | |
2403 | } | |
2404 | ||
2405 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF)) { | |
2406 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS14); | |
2407 | panic("%s: rxm_mem2_accbad_intr (0x%x) found: \ | |
2408 | memory address is 0x%08X\n", | |
2409 | dev_name(dev), irq_value, | |
2410 | (reg_val & HGC_RXM_DFX_STATUS14_MEM2_MSK) >> | |
2411 | HGC_RXM_DFX_STATUS14_MEM2_OFF); | |
2412 | } | |
2413 | ||
2414 | if (irq_value & BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF)) { | |
2415 | reg_val = hisi_sas_read32(hisi_hba, HGC_RXM_DFX_STATUS15); | |
2416 | panic("%s: rxm_mem3_accbad_intr (0x%x) found: \ | |
2417 | memory address is 0x%08X\n", | |
2418 | dev_name(dev), irq_value, | |
2419 | (reg_val & HGC_RXM_DFX_STATUS15_MEM3_MSK) >> | |
2420 | HGC_RXM_DFX_STATUS15_MEM3_OFF); | |
2421 | } | |
2422 | ||
2423 | } | |
2424 | ||
2425 | static irqreturn_t fatal_ecc_int_v2_hw(int irq_no, void *p) | |
2426 | { | |
2427 | struct hisi_hba *hisi_hba = p; | |
2428 | u32 irq_value, irq_msk; | |
2429 | ||
2430 | irq_msk = hisi_sas_read32(hisi_hba, SAS_ECC_INTR_MSK); | |
2431 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk | 0xffffffff); | |
2432 | ||
2433 | irq_value = hisi_sas_read32(hisi_hba, SAS_ECC_INTR); | |
2434 | if (irq_value) { | |
2435 | one_bit_ecc_error_process_v2_hw(hisi_hba, irq_value); | |
2436 | multi_bit_ecc_error_process_v2_hw(hisi_hba, irq_value); | |
2437 | } | |
2438 | ||
2439 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR, irq_value); | |
2440 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk); | |
2441 | ||
2442 | return IRQ_HANDLED; | |
2443 | } | |
2444 | ||
2445 | #define AXI_ERR_NR 8 | |
2446 | static const char axi_err_info[AXI_ERR_NR][32] = { | |
2447 | "IOST_AXI_W_ERR", | |
2448 | "IOST_AXI_R_ERR", | |
2449 | "ITCT_AXI_W_ERR", | |
2450 | "ITCT_AXI_R_ERR", | |
2451 | "SATA_AXI_W_ERR", | |
2452 | "SATA_AXI_R_ERR", | |
2453 | "DQE_AXI_R_ERR", | |
2454 | "CQE_AXI_W_ERR" | |
2455 | }; | |
2456 | ||
2457 | #define FIFO_ERR_NR 5 | |
2458 | static const char fifo_err_info[FIFO_ERR_NR][32] = { | |
2459 | "CQE_WINFO_FIFO", | |
2460 | "CQE_MSG_FIFIO", | |
2461 | "GETDQE_FIFO", | |
2462 | "CMDP_FIFO", | |
2463 | "AWTCTRL_FIFO" | |
2464 | }; | |
2465 | ||
2466 | static irqreturn_t fatal_axi_int_v2_hw(int irq_no, void *p) | |
2467 | { | |
2468 | struct hisi_hba *hisi_hba = p; | |
2469 | u32 irq_value, irq_msk, err_value; | |
2470 | struct device *dev = &hisi_hba->pdev->dev; | |
2471 | ||
2472 | irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3); | |
2473 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0xfffffffe); | |
2474 | ||
2475 | irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
2476 | if (irq_value) { | |
2477 | if (irq_value & BIT(ENT_INT_SRC3_WP_DEPTH_OFF)) { | |
2478 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
2479 | 1 << ENT_INT_SRC3_WP_DEPTH_OFF); | |
2480 | panic("%s: write pointer and depth error (0x%x) \ | |
2481 | found!\n", | |
2482 | dev_name(dev), irq_value); | |
2483 | } | |
2484 | ||
2485 | if (irq_value & BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF)) { | |
2486 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
2487 | 1 << | |
2488 | ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF); | |
2489 | panic("%s: iptt no match slot error (0x%x) found!\n", | |
2490 | dev_name(dev), irq_value); | |
2491 | } | |
2492 | ||
2493 | if (irq_value & BIT(ENT_INT_SRC3_RP_DEPTH_OFF)) | |
2494 | panic("%s: read pointer and depth error (0x%x) \ | |
2495 | found!\n", | |
2496 | dev_name(dev), irq_value); | |
2497 | ||
2498 | if (irq_value & BIT(ENT_INT_SRC3_AXI_OFF)) { | |
2499 | int i; | |
2500 | ||
2501 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
2502 | 1 << ENT_INT_SRC3_AXI_OFF); | |
2503 | err_value = hisi_sas_read32(hisi_hba, | |
2504 | HGC_AXI_FIFO_ERR_INFO); | |
2505 | ||
2506 | for (i = 0; i < AXI_ERR_NR; i++) { | |
2507 | if (err_value & BIT(i)) | |
2508 | panic("%s: %s (0x%x) found!\n", | |
2509 | dev_name(dev), | |
2510 | axi_err_info[i], irq_value); | |
2511 | } | |
2512 | } | |
2513 | ||
2514 | if (irq_value & BIT(ENT_INT_SRC3_FIFO_OFF)) { | |
2515 | int i; | |
2516 | ||
2517 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
2518 | 1 << ENT_INT_SRC3_FIFO_OFF); | |
2519 | err_value = hisi_sas_read32(hisi_hba, | |
2520 | HGC_AXI_FIFO_ERR_INFO); | |
2521 | ||
2522 | for (i = 0; i < FIFO_ERR_NR; i++) { | |
2523 | if (err_value & BIT(AXI_ERR_NR + i)) | |
2524 | panic("%s: %s (0x%x) found!\n", | |
2525 | dev_name(dev), | |
2526 | fifo_err_info[i], irq_value); | |
2527 | } | |
2528 | ||
2529 | } | |
2530 | ||
2531 | if (irq_value & BIT(ENT_INT_SRC3_LM_OFF)) { | |
2532 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
2533 | 1 << ENT_INT_SRC3_LM_OFF); | |
2534 | panic("%s: LM add/fetch list error (0x%x) found!\n", | |
2535 | dev_name(dev), irq_value); | |
2536 | } | |
2537 | ||
2538 | if (irq_value & BIT(ENT_INT_SRC3_ABT_OFF)) { | |
2539 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
2540 | 1 << ENT_INT_SRC3_ABT_OFF); | |
2541 | panic("%s: SAS_HGC_ABT fetch LM list error (0x%x) found!\n", | |
2542 | dev_name(dev), irq_value); | |
2543 | } | |
2544 | } | |
2545 | ||
2546 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk); | |
2547 | ||
2548 | return IRQ_HANDLED; | |
2549 | } | |
2550 | ||
d177c408 | 2551 | static void cq_tasklet_v2_hw(unsigned long val) |
31a9cfa6 | 2552 | { |
d177c408 | 2553 | struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val; |
31a9cfa6 JG |
2554 | struct hisi_hba *hisi_hba = cq->hisi_hba; |
2555 | struct hisi_sas_slot *slot; | |
2556 | struct hisi_sas_itct *itct; | |
2557 | struct hisi_sas_complete_v2_hdr *complete_queue; | |
d177c408 | 2558 | u32 rd_point = cq->rd_point, wr_point, dev_id; |
31a9cfa6 JG |
2559 | int queue = cq->id; |
2560 | ||
2561 | complete_queue = hisi_hba->complete_hdr[queue]; | |
31a9cfa6 | 2562 | |
64d63187 | 2563 | spin_lock(&hisi_hba->lock); |
31a9cfa6 JG |
2564 | wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR + |
2565 | (0x14 * queue)); | |
2566 | ||
2567 | while (rd_point != wr_point) { | |
2568 | struct hisi_sas_complete_v2_hdr *complete_hdr; | |
2569 | int iptt; | |
2570 | ||
2571 | complete_hdr = &complete_queue[rd_point]; | |
2572 | ||
2573 | /* Check for NCQ completion */ | |
2574 | if (complete_hdr->act) { | |
2575 | u32 act_tmp = complete_hdr->act; | |
2576 | int ncq_tag_count = ffs(act_tmp); | |
2577 | ||
2578 | dev_id = (complete_hdr->dw1 & CMPLT_HDR_DEV_ID_MSK) >> | |
2579 | CMPLT_HDR_DEV_ID_OFF; | |
2580 | itct = &hisi_hba->itct[dev_id]; | |
2581 | ||
2582 | /* The NCQ tags are held in the itct header */ | |
2583 | while (ncq_tag_count) { | |
2584 | __le64 *ncq_tag = &itct->qw4_15[0]; | |
2585 | ||
2586 | ncq_tag_count -= 1; | |
2587 | iptt = (ncq_tag[ncq_tag_count / 5] | |
2588 | >> (ncq_tag_count % 5) * 12) & 0xfff; | |
2589 | ||
2590 | slot = &hisi_hba->slot_info[iptt]; | |
2591 | slot->cmplt_queue_slot = rd_point; | |
2592 | slot->cmplt_queue = queue; | |
2593 | slot_complete_v2_hw(hisi_hba, slot, 0); | |
2594 | ||
2595 | act_tmp &= ~(1 << ncq_tag_count); | |
2596 | ncq_tag_count = ffs(act_tmp); | |
2597 | } | |
2598 | } else { | |
2599 | iptt = (complete_hdr->dw1) & CMPLT_HDR_IPTT_MSK; | |
2600 | slot = &hisi_hba->slot_info[iptt]; | |
2601 | slot->cmplt_queue_slot = rd_point; | |
2602 | slot->cmplt_queue = queue; | |
2603 | slot_complete_v2_hw(hisi_hba, slot, 0); | |
2604 | } | |
2605 | ||
2606 | if (++rd_point >= HISI_SAS_QUEUE_SLOTS) | |
2607 | rd_point = 0; | |
2608 | } | |
2609 | ||
2610 | /* update rd_point */ | |
e6c346f3 | 2611 | cq->rd_point = rd_point; |
31a9cfa6 | 2612 | hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point); |
64d63187 | 2613 | spin_unlock(&hisi_hba->lock); |
d177c408 JG |
2614 | } |
2615 | ||
2616 | static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p) | |
2617 | { | |
2618 | struct hisi_sas_cq *cq = p; | |
2619 | struct hisi_hba *hisi_hba = cq->hisi_hba; | |
2620 | int queue = cq->id; | |
2621 | ||
2622 | hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue); | |
2623 | ||
2624 | tasklet_schedule(&cq->tasklet); | |
2625 | ||
31a9cfa6 JG |
2626 | return IRQ_HANDLED; |
2627 | } | |
2628 | ||
d43f9cdb JG |
2629 | static irqreturn_t sata_int_v2_hw(int irq_no, void *p) |
2630 | { | |
2631 | struct hisi_sas_phy *phy = p; | |
2632 | struct hisi_hba *hisi_hba = phy->hisi_hba; | |
2633 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
2634 | struct device *dev = &hisi_hba->pdev->dev; | |
2635 | struct hisi_sas_initial_fis *initial_fis; | |
2636 | struct dev_to_host_fis *fis; | |
2637 | u32 ent_tmp, ent_msk, ent_int, port_id, link_rate, hard_phy_linkrate; | |
2638 | irqreturn_t res = IRQ_HANDLED; | |
2639 | u8 attached_sas_addr[SAS_ADDR_SIZE] = {0}; | |
11826e5d | 2640 | int phy_no, offset; |
d43f9cdb JG |
2641 | |
2642 | phy_no = sas_phy->id; | |
2643 | initial_fis = &hisi_hba->initial_fis[phy_no]; | |
2644 | fis = &initial_fis->fis; | |
2645 | ||
11826e5d JG |
2646 | offset = 4 * (phy_no / 4); |
2647 | ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK1 + offset); | |
2648 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset, | |
2649 | ent_msk | 1 << ((phy_no % 4) * 8)); | |
d43f9cdb | 2650 | |
11826e5d JG |
2651 | ent_int = hisi_sas_read32(hisi_hba, ENT_INT_SRC1 + offset); |
2652 | ent_tmp = ent_int & (1 << (ENT_INT_SRC1_D2H_FIS_CH1_OFF * | |
2653 | (phy_no % 4))); | |
d43f9cdb JG |
2654 | ent_int >>= ENT_INT_SRC1_D2H_FIS_CH1_OFF * (phy_no % 4); |
2655 | if ((ent_int & ENT_INT_SRC1_D2H_FIS_CH0_MSK) == 0) { | |
2656 | dev_warn(dev, "sata int: phy%d did not receive FIS\n", phy_no); | |
d43f9cdb JG |
2657 | res = IRQ_NONE; |
2658 | goto end; | |
04708ff4 XC |
2659 | } |
2660 | ||
2661 | /* check ERR bit of Status Register */ | |
2662 | if (fis->status & ATA_ERR) { | |
2663 | dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n", phy_no, | |
2664 | fis->status); | |
2665 | disable_phy_v2_hw(hisi_hba, phy_no); | |
2666 | enable_phy_v2_hw(hisi_hba, phy_no); | |
2667 | res = IRQ_NONE; | |
2668 | goto end; | |
d43f9cdb JG |
2669 | } |
2670 | ||
2671 | if (unlikely(phy_no == 8)) { | |
2672 | u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE); | |
2673 | ||
2674 | port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >> | |
2675 | PORT_STATE_PHY8_PORT_NUM_OFF; | |
2676 | link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >> | |
2677 | PORT_STATE_PHY8_CONN_RATE_OFF; | |
2678 | } else { | |
2679 | port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
2680 | port_id = (port_id >> (4 * phy_no)) & 0xf; | |
2681 | link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE); | |
2682 | link_rate = (link_rate >> (phy_no * 4)) & 0xf; | |
2683 | } | |
2684 | ||
2685 | if (port_id == 0xf) { | |
2686 | dev_err(dev, "sata int: phy%d invalid portid\n", phy_no); | |
2687 | res = IRQ_NONE; | |
2688 | goto end; | |
2689 | } | |
2690 | ||
2691 | sas_phy->linkrate = link_rate; | |
2692 | hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no, | |
2693 | HARD_PHY_LINKRATE); | |
2694 | phy->maximum_linkrate = hard_phy_linkrate & 0xf; | |
2695 | phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf; | |
2696 | ||
2697 | sas_phy->oob_mode = SATA_OOB_MODE; | |
2698 | /* Make up some unique SAS address */ | |
2699 | attached_sas_addr[0] = 0x50; | |
2700 | attached_sas_addr[7] = phy_no; | |
2701 | memcpy(sas_phy->attached_sas_addr, attached_sas_addr, SAS_ADDR_SIZE); | |
2702 | memcpy(sas_phy->frame_rcvd, fis, sizeof(struct dev_to_host_fis)); | |
2703 | dev_info(dev, "sata int phyup: phy%d link_rate=%d\n", phy_no, link_rate); | |
2704 | phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); | |
2705 | phy->port_id = port_id; | |
2706 | phy->phy_type |= PORT_TYPE_SATA; | |
2707 | phy->phy_attached = 1; | |
2708 | phy->identify.device_type = SAS_SATA_DEV; | |
2709 | phy->frame_rcvd_size = sizeof(struct dev_to_host_fis); | |
2710 | phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; | |
2711 | queue_work(hisi_hba->wq, &phy->phyup_ws); | |
2712 | ||
2713 | end: | |
11826e5d JG |
2714 | hisi_sas_write32(hisi_hba, ENT_INT_SRC1 + offset, ent_tmp); |
2715 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset, ent_msk); | |
d43f9cdb JG |
2716 | |
2717 | return res; | |
2718 | } | |
2719 | ||
7911e66f JG |
2720 | static irq_handler_t phy_interrupts[HISI_SAS_PHY_INT_NR] = { |
2721 | int_phy_updown_v2_hw, | |
d3bf3d84 | 2722 | int_chnl_int_v2_hw, |
7911e66f JG |
2723 | }; |
2724 | ||
d3b688d3 XC |
2725 | static irq_handler_t fatal_interrupts[HISI_SAS_FATAL_INT_NR] = { |
2726 | fatal_ecc_int_v2_hw, | |
2727 | fatal_axi_int_v2_hw | |
2728 | }; | |
2729 | ||
7911e66f JG |
2730 | /** |
2731 | * There is a limitation in the hip06 chipset that we need | |
2732 | * to map in all mbigen interrupts, even if they are not used. | |
2733 | */ | |
2734 | static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) | |
2735 | { | |
2736 | struct platform_device *pdev = hisi_hba->pdev; | |
2737 | struct device *dev = &pdev->dev; | |
2738 | int i, irq, rc, irq_map[128]; | |
2739 | ||
2740 | ||
2741 | for (i = 0; i < 128; i++) | |
2742 | irq_map[i] = platform_get_irq(pdev, i); | |
2743 | ||
2744 | for (i = 0; i < HISI_SAS_PHY_INT_NR; i++) { | |
2745 | int idx = i; | |
2746 | ||
2747 | irq = irq_map[idx + 1]; /* Phy up/down is irq1 */ | |
2748 | if (!irq) { | |
2749 | dev_err(dev, "irq init: fail map phy interrupt %d\n", | |
2750 | idx); | |
2751 | return -ENOENT; | |
2752 | } | |
2753 | ||
2754 | rc = devm_request_irq(dev, irq, phy_interrupts[i], 0, | |
2755 | DRV_NAME " phy", hisi_hba); | |
2756 | if (rc) { | |
2757 | dev_err(dev, "irq init: could not request " | |
2758 | "phy interrupt %d, rc=%d\n", | |
2759 | irq, rc); | |
2760 | return -ENOENT; | |
2761 | } | |
2762 | } | |
2763 | ||
d43f9cdb JG |
2764 | for (i = 0; i < hisi_hba->n_phy; i++) { |
2765 | struct hisi_sas_phy *phy = &hisi_hba->phy[i]; | |
2766 | int idx = i + 72; /* First SATA interrupt is irq72 */ | |
2767 | ||
2768 | irq = irq_map[idx]; | |
2769 | if (!irq) { | |
2770 | dev_err(dev, "irq init: fail map phy interrupt %d\n", | |
2771 | idx); | |
2772 | return -ENOENT; | |
2773 | } | |
2774 | ||
2775 | rc = devm_request_irq(dev, irq, sata_int_v2_hw, 0, | |
2776 | DRV_NAME " sata", phy); | |
2777 | if (rc) { | |
2778 | dev_err(dev, "irq init: could not request " | |
2779 | "sata interrupt %d, rc=%d\n", | |
2780 | irq, rc); | |
2781 | return -ENOENT; | |
2782 | } | |
2783 | } | |
31a9cfa6 | 2784 | |
d3b688d3 XC |
2785 | for (i = 0; i < HISI_SAS_FATAL_INT_NR; i++) { |
2786 | int idx = i; | |
2787 | ||
2788 | irq = irq_map[idx + 81]; | |
2789 | if (!irq) { | |
2790 | dev_err(dev, "irq init: fail map fatal interrupt %d\n", | |
2791 | idx); | |
2792 | return -ENOENT; | |
2793 | } | |
2794 | ||
2795 | rc = devm_request_irq(dev, irq, fatal_interrupts[i], 0, | |
2796 | DRV_NAME " fatal", hisi_hba); | |
2797 | if (rc) { | |
2798 | dev_err(dev, | |
2799 | "irq init: could not request fatal interrupt %d, rc=%d\n", | |
2800 | irq, rc); | |
2801 | return -ENOENT; | |
2802 | } | |
2803 | } | |
2804 | ||
31a9cfa6 JG |
2805 | for (i = 0; i < hisi_hba->queue_count; i++) { |
2806 | int idx = i + 96; /* First cq interrupt is irq96 */ | |
d177c408 JG |
2807 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; |
2808 | struct tasklet_struct *t = &cq->tasklet; | |
31a9cfa6 JG |
2809 | |
2810 | irq = irq_map[idx]; | |
2811 | if (!irq) { | |
2812 | dev_err(dev, | |
2813 | "irq init: could not map cq interrupt %d\n", | |
2814 | idx); | |
2815 | return -ENOENT; | |
2816 | } | |
2817 | rc = devm_request_irq(dev, irq, cq_interrupt_v2_hw, 0, | |
2818 | DRV_NAME " cq", &hisi_hba->cq[i]); | |
2819 | if (rc) { | |
2820 | dev_err(dev, | |
2821 | "irq init: could not request cq interrupt %d, rc=%d\n", | |
2822 | irq, rc); | |
2823 | return -ENOENT; | |
2824 | } | |
d177c408 | 2825 | tasklet_init(t, cq_tasklet_v2_hw, (unsigned long)cq); |
31a9cfa6 JG |
2826 | } |
2827 | ||
7911e66f JG |
2828 | return 0; |
2829 | } | |
2830 | ||
94eac9e1 JG |
2831 | static int hisi_sas_v2_init(struct hisi_hba *hisi_hba) |
2832 | { | |
2833 | int rc; | |
2834 | ||
2835 | rc = hw_init_v2_hw(hisi_hba); | |
2836 | if (rc) | |
2837 | return rc; | |
2838 | ||
7911e66f JG |
2839 | rc = interrupt_init_v2_hw(hisi_hba); |
2840 | if (rc) | |
2841 | return rc; | |
2842 | ||
29a20428 JG |
2843 | phys_init_v2_hw(hisi_hba); |
2844 | ||
94eac9e1 JG |
2845 | return 0; |
2846 | } | |
2847 | ||
3417ba8a | 2848 | static const struct hisi_sas_hw hisi_sas_v2_hw = { |
94eac9e1 | 2849 | .hw_init = hisi_sas_v2_init, |
85b2c3c0 | 2850 | .setup_itct = setup_itct_v2_hw, |
330fa7f3 | 2851 | .slot_index_alloc = slot_index_alloc_quirk_v2_hw, |
b2bdaf2b | 2852 | .alloc_dev = alloc_dev_quirk_v2_hw, |
7911e66f | 2853 | .sl_notify = sl_notify_v2_hw, |
5473c060 | 2854 | .get_wideport_bitmap = get_wideport_bitmap_v2_hw, |
85b2c3c0 | 2855 | .free_device = free_device_v2_hw, |
c2d89392 | 2856 | .prep_smp = prep_smp_v2_hw, |
8c36e31d | 2857 | .prep_ssp = prep_ssp_v2_hw, |
6f2ff1a1 | 2858 | .prep_stp = prep_ata_v2_hw, |
a3e665d9 | 2859 | .prep_abort = prep_abort_v2_hw, |
8c36e31d JG |
2860 | .get_free_slot = get_free_slot_v2_hw, |
2861 | .start_delivery = start_delivery_v2_hw, | |
31a9cfa6 | 2862 | .slot_complete = slot_complete_v2_hw, |
63fb11b8 JG |
2863 | .phy_enable = enable_phy_v2_hw, |
2864 | .phy_disable = disable_phy_v2_hw, | |
2865 | .phy_hard_reset = phy_hard_reset_v2_hw, | |
2ae75787 XC |
2866 | .phy_set_linkrate = phy_set_linkrate_v2_hw, |
2867 | .phy_get_max_linkrate = phy_get_max_linkrate_v2_hw, | |
94eac9e1 JG |
2868 | .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V2_HW, |
2869 | .complete_hdr_size = sizeof(struct hisi_sas_complete_v2_hdr), | |
3417ba8a JG |
2870 | }; |
2871 | ||
2872 | static int hisi_sas_v2_probe(struct platform_device *pdev) | |
2873 | { | |
26f3ba96 JG |
2874 | /* |
2875 | * Check if we should defer the probe before we probe the | |
2876 | * upper layer, as it's hard to defer later on. | |
2877 | */ | |
2878 | int ret = platform_get_irq(pdev, 0); | |
2879 | ||
2880 | if (ret < 0) { | |
2881 | if (ret != -EPROBE_DEFER) | |
2882 | dev_err(&pdev->dev, "cannot obtain irq\n"); | |
2883 | return ret; | |
2884 | } | |
2885 | ||
3417ba8a JG |
2886 | return hisi_sas_probe(pdev, &hisi_sas_v2_hw); |
2887 | } | |
2888 | ||
2889 | static int hisi_sas_v2_remove(struct platform_device *pdev) | |
2890 | { | |
f2f89c32 XC |
2891 | struct sas_ha_struct *sha = platform_get_drvdata(pdev); |
2892 | struct hisi_hba *hisi_hba = sha->lldd_ha; | |
2893 | ||
2894 | if (timer_pending(&hisi_hba->timer)) | |
2895 | del_timer(&hisi_hba->timer); | |
2896 | ||
3417ba8a JG |
2897 | return hisi_sas_remove(pdev); |
2898 | } | |
2899 | ||
2900 | static const struct of_device_id sas_v2_of_match[] = { | |
2901 | { .compatible = "hisilicon,hip06-sas-v2",}, | |
039ae102 | 2902 | { .compatible = "hisilicon,hip07-sas-v2",}, |
3417ba8a JG |
2903 | {}, |
2904 | }; | |
2905 | MODULE_DEVICE_TABLE(of, sas_v2_of_match); | |
2906 | ||
50408712 JG |
2907 | static const struct acpi_device_id sas_v2_acpi_match[] = { |
2908 | { "HISI0162", 0 }, | |
2909 | { } | |
2910 | }; | |
2911 | ||
2912 | MODULE_DEVICE_TABLE(acpi, sas_v2_acpi_match); | |
2913 | ||
3417ba8a JG |
2914 | static struct platform_driver hisi_sas_v2_driver = { |
2915 | .probe = hisi_sas_v2_probe, | |
2916 | .remove = hisi_sas_v2_remove, | |
2917 | .driver = { | |
2918 | .name = DRV_NAME, | |
2919 | .of_match_table = sas_v2_of_match, | |
50408712 | 2920 | .acpi_match_table = ACPI_PTR(sas_v2_acpi_match), |
3417ba8a JG |
2921 | }, |
2922 | }; | |
2923 | ||
2924 | module_platform_driver(hisi_sas_v2_driver); | |
2925 | ||
2926 | MODULE_LICENSE("GPL"); | |
2927 | MODULE_AUTHOR("John Garry <john.garry@huawei.com>"); | |
2928 | MODULE_DESCRIPTION("HISILICON SAS controller v2 hw driver"); | |
2929 | MODULE_ALIAS("platform:" DRV_NAME); |