1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2017 Hisilicon Limited.
4 */
5
6 #include <linux/sched/clock.h>
7 #include "hisi_sas.h"
8 #define DRV_NAME "hisi_sas_v3_hw"
9
10 /* global registers need init */
11 #define DLVRY_QUEUE_ENABLE 0x0
12 #define IOST_BASE_ADDR_LO 0x8
13 #define IOST_BASE_ADDR_HI 0xc
14 #define ITCT_BASE_ADDR_LO 0x10
15 #define ITCT_BASE_ADDR_HI 0x14
16 #define IO_BROKEN_MSG_ADDR_LO 0x18
17 #define IO_BROKEN_MSG_ADDR_HI 0x1c
18 #define PHY_CONTEXT 0x20
19 #define PHY_STATE 0x24
20 #define PHY_PORT_NUM_MA 0x28
21 #define PHY_CONN_RATE 0x30
22 #define ITCT_CLR 0x44
23 #define ITCT_CLR_EN_OFF 16
24 #define ITCT_CLR_EN_MSK (0x1 << ITCT_CLR_EN_OFF)
25 #define ITCT_DEV_OFF 0
26 #define ITCT_DEV_MSK (0x7ff << ITCT_DEV_OFF)
27 #define SAS_AXI_USER3 0x50
28 #define IO_SATA_BROKEN_MSG_ADDR_LO 0x58
29 #define IO_SATA_BROKEN_MSG_ADDR_HI 0x5c
30 #define SATA_INITI_D2H_STORE_ADDR_LO 0x60
31 #define SATA_INITI_D2H_STORE_ADDR_HI 0x64
32 #define CFG_MAX_TAG 0x68
33 #define TRANS_LOCK_ICT_TIME 0X70
34 #define HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL 0x84
35 #define HGC_SAS_TXFAIL_RETRY_CTRL 0x88
36 #define HGC_GET_ITV_TIME 0x90
37 #define DEVICE_MSG_WORK_MODE 0x94
38 #define OPENA_WT_CONTI_TIME 0x9c
39 #define I_T_NEXUS_LOSS_TIME 0xa0
40 #define MAX_CON_TIME_LIMIT_TIME 0xa4
41 #define BUS_INACTIVE_LIMIT_TIME 0xa8
42 #define REJECT_TO_OPEN_LIMIT_TIME 0xac
43 #define CQ_INT_CONVERGE_EN 0xb0
44 #define CFG_AGING_TIME 0xbc
45 #define HGC_DFX_CFG2 0xc0
46 #define CFG_ABT_SET_QUERY_IPTT 0xd4
47 #define CFG_SET_ABORTED_IPTT_OFF 0
48 #define CFG_SET_ABORTED_IPTT_MSK (0xfff << CFG_SET_ABORTED_IPTT_OFF)
49 #define CFG_SET_ABORTED_EN_OFF 12
50 #define CFG_ABT_SET_IPTT_DONE 0xd8
51 #define CFG_ABT_SET_IPTT_DONE_OFF 0
52 #define HGC_IOMB_PROC1_STATUS 0x104
53 #define HGC_LM_DFX_STATUS2 0x128
54 #define HGC_LM_DFX_STATUS2_IOSTLIST_OFF 0
55 #define HGC_LM_DFX_STATUS2_IOSTLIST_MSK (0xfff << \
56 HGC_LM_DFX_STATUS2_IOSTLIST_OFF)
57 #define HGC_LM_DFX_STATUS2_ITCTLIST_OFF 12
58 #define HGC_LM_DFX_STATUS2_ITCTLIST_MSK (0x7ff << \
59 HGC_LM_DFX_STATUS2_ITCTLIST_OFF)
60 #define HGC_CQE_ECC_ADDR 0x13c
61 #define HGC_CQE_ECC_1B_ADDR_OFF 0
62 #define HGC_CQE_ECC_1B_ADDR_MSK (0x3f << HGC_CQE_ECC_1B_ADDR_OFF)
63 #define HGC_CQE_ECC_MB_ADDR_OFF 8
64 #define HGC_CQE_ECC_MB_ADDR_MSK (0x3f << HGC_CQE_ECC_MB_ADDR_OFF)
65 #define HGC_IOST_ECC_ADDR 0x140
66 #define HGC_IOST_ECC_1B_ADDR_OFF 0
67 #define HGC_IOST_ECC_1B_ADDR_MSK (0x3ff << HGC_IOST_ECC_1B_ADDR_OFF)
68 #define HGC_IOST_ECC_MB_ADDR_OFF 16
69 #define HGC_IOST_ECC_MB_ADDR_MSK (0x3ff << HGC_IOST_ECC_MB_ADDR_OFF)
70 #define HGC_DQE_ECC_ADDR 0x144
71 #define HGC_DQE_ECC_1B_ADDR_OFF 0
72 #define HGC_DQE_ECC_1B_ADDR_MSK (0xfff << HGC_DQE_ECC_1B_ADDR_OFF)
73 #define HGC_DQE_ECC_MB_ADDR_OFF 16
74 #define HGC_DQE_ECC_MB_ADDR_MSK (0xfff << HGC_DQE_ECC_MB_ADDR_OFF)
75 #define CHNL_INT_STATUS 0x148
76 #define TAB_DFX 0x14c
77 #define HGC_ITCT_ECC_ADDR 0x150
78 #define HGC_ITCT_ECC_1B_ADDR_OFF 0
79 #define HGC_ITCT_ECC_1B_ADDR_MSK (0x3ff << \
80 HGC_ITCT_ECC_1B_ADDR_OFF)
81 #define HGC_ITCT_ECC_MB_ADDR_OFF 16
82 #define HGC_ITCT_ECC_MB_ADDR_MSK (0x3ff << \
83 HGC_ITCT_ECC_MB_ADDR_OFF)
84 #define HGC_AXI_FIFO_ERR_INFO 0x154
85 #define AXI_ERR_INFO_OFF 0
86 #define AXI_ERR_INFO_MSK (0xff << AXI_ERR_INFO_OFF)
87 #define FIFO_ERR_INFO_OFF 8
88 #define FIFO_ERR_INFO_MSK (0xff << FIFO_ERR_INFO_OFF)
89 #define TAB_RD_TYPE 0x15c
90 #define INT_COAL_EN 0x19c
91 #define OQ_INT_COAL_TIME 0x1a0
92 #define OQ_INT_COAL_CNT 0x1a4
93 #define ENT_INT_COAL_TIME 0x1a8
94 #define ENT_INT_COAL_CNT 0x1ac
95 #define OQ_INT_SRC 0x1b0
96 #define OQ_INT_SRC_MSK 0x1b4
97 #define ENT_INT_SRC1 0x1b8
98 #define ENT_INT_SRC1_D2H_FIS_CH0_OFF 0
99 #define ENT_INT_SRC1_D2H_FIS_CH0_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH0_OFF)
100 #define ENT_INT_SRC1_D2H_FIS_CH1_OFF 8
101 #define ENT_INT_SRC1_D2H_FIS_CH1_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH1_OFF)
102 #define ENT_INT_SRC2 0x1bc
103 #define ENT_INT_SRC3 0x1c0
104 #define ENT_INT_SRC3_WP_DEPTH_OFF 8
105 #define ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF 9
106 #define ENT_INT_SRC3_RP_DEPTH_OFF 10
107 #define ENT_INT_SRC3_AXI_OFF 11
108 #define ENT_INT_SRC3_FIFO_OFF 12
109 #define ENT_INT_SRC3_LM_OFF 14
110 #define ENT_INT_SRC3_ITC_INT_OFF 15
111 #define ENT_INT_SRC3_ITC_INT_MSK (0x1 << ENT_INT_SRC3_ITC_INT_OFF)
112 #define ENT_INT_SRC3_ABT_OFF 16
113 #define ENT_INT_SRC3_DQE_POISON_OFF 18
114 #define ENT_INT_SRC3_IOST_POISON_OFF 19
115 #define ENT_INT_SRC3_ITCT_POISON_OFF 20
116 #define ENT_INT_SRC3_ITCT_NCQ_POISON_OFF 21
117 #define ENT_INT_SRC_MSK1 0x1c4
118 #define ENT_INT_SRC_MSK2 0x1c8
119 #define ENT_INT_SRC_MSK3 0x1cc
120 #define ENT_INT_SRC_MSK3_ENT95_MSK_OFF 31
121 #define CHNL_PHYUPDOWN_INT_MSK 0x1d0
122 #define CHNL_ENT_INT_MSK 0x1d4
123 #define HGC_COM_INT_MSK 0x1d8
124 #define ENT_INT_SRC_MSK3_ENT95_MSK_MSK (0x1 << ENT_INT_SRC_MSK3_ENT95_MSK_OFF)
125 #define SAS_ECC_INTR 0x1e8
126 #define SAS_ECC_INTR_DQE_ECC_1B_OFF 0
127 #define SAS_ECC_INTR_DQE_ECC_MB_OFF 1
128 #define SAS_ECC_INTR_IOST_ECC_1B_OFF 2
129 #define SAS_ECC_INTR_IOST_ECC_MB_OFF 3
130 #define SAS_ECC_INTR_ITCT_ECC_1B_OFF 4
131 #define SAS_ECC_INTR_ITCT_ECC_MB_OFF 5
132 #define SAS_ECC_INTR_ITCTLIST_ECC_1B_OFF 6
133 #define SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF 7
134 #define SAS_ECC_INTR_IOSTLIST_ECC_1B_OFF 8
135 #define SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF 9
136 #define SAS_ECC_INTR_CQE_ECC_1B_OFF 10
137 #define SAS_ECC_INTR_CQE_ECC_MB_OFF 11
138 #define SAS_ECC_INTR_NCQ_MEM0_ECC_1B_OFF 12
139 #define SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF 13
140 #define SAS_ECC_INTR_NCQ_MEM1_ECC_1B_OFF 14
141 #define SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF 15
142 #define SAS_ECC_INTR_NCQ_MEM2_ECC_1B_OFF 16
143 #define SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF 17
144 #define SAS_ECC_INTR_NCQ_MEM3_ECC_1B_OFF 18
145 #define SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF 19
146 #define SAS_ECC_INTR_OOO_RAM_ECC_1B_OFF 20
147 #define SAS_ECC_INTR_OOO_RAM_ECC_MB_OFF 21
148 #define SAS_ECC_INTR_MSK 0x1ec
149 #define HGC_ERR_STAT_EN 0x238
150 #define CQE_SEND_CNT 0x248
151 #define DLVRY_Q_0_BASE_ADDR_LO 0x260
152 #define DLVRY_Q_0_BASE_ADDR_HI 0x264
153 #define DLVRY_Q_0_DEPTH 0x268
154 #define DLVRY_Q_0_WR_PTR 0x26c
155 #define DLVRY_Q_0_RD_PTR 0x270
156 #define HYPER_STREAM_ID_EN_CFG 0xc80
157 #define OQ0_INT_SRC_MSK 0xc90
158 #define COMPL_Q_0_BASE_ADDR_LO 0x4e0
159 #define COMPL_Q_0_BASE_ADDR_HI 0x4e4
160 #define COMPL_Q_0_DEPTH 0x4e8
161 #define COMPL_Q_0_WR_PTR 0x4ec
162 #define COMPL_Q_0_RD_PTR 0x4f0
163 #define HGC_RXM_DFX_STATUS14 0xae8
164 #define HGC_RXM_DFX_STATUS14_MEM0_OFF 0
165 #define HGC_RXM_DFX_STATUS14_MEM0_MSK (0x1ff << \
166 HGC_RXM_DFX_STATUS14_MEM0_OFF)
167 #define HGC_RXM_DFX_STATUS14_MEM1_OFF 9
168 #define HGC_RXM_DFX_STATUS14_MEM1_MSK (0x1ff << \
169 HGC_RXM_DFX_STATUS14_MEM1_OFF)
170 #define HGC_RXM_DFX_STATUS14_MEM2_OFF 18
171 #define HGC_RXM_DFX_STATUS14_MEM2_MSK (0x1ff << \
172 HGC_RXM_DFX_STATUS14_MEM2_OFF)
173 #define HGC_RXM_DFX_STATUS15 0xaec
174 #define HGC_RXM_DFX_STATUS15_MEM3_OFF 0
175 #define HGC_RXM_DFX_STATUS15_MEM3_MSK (0x1ff << \
176 HGC_RXM_DFX_STATUS15_MEM3_OFF)
177 #define AWQOS_AWCACHE_CFG 0xc84
178 #define ARQOS_ARCACHE_CFG 0xc88
179 #define HILINK_ERR_DFX 0xe04
180 #define SAS_GPIO_CFG_0 0x1000
181 #define SAS_GPIO_CFG_1 0x1004
182 #define SAS_GPIO_TX_0_1 0x1040
183 #define SAS_CFG_DRIVE_VLD 0x1070
184
185 /* phy registers requiring init */
186 #define PORT_BASE (0x2000)
187 #define PHY_CFG (PORT_BASE + 0x0)
188 #define HARD_PHY_LINKRATE (PORT_BASE + 0x4)
189 #define PHY_CFG_ENA_OFF 0
190 #define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF)
191 #define PHY_CFG_DC_OPT_OFF 2
192 #define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF)
193 #define PHY_CFG_PHY_RST_OFF 3
194 #define PHY_CFG_PHY_RST_MSK (0x1 << PHY_CFG_PHY_RST_OFF)
195 #define PROG_PHY_LINK_RATE (PORT_BASE + 0x8)
196 #define CFG_PROG_PHY_LINK_RATE_OFF 0
197 #define CFG_PROG_PHY_LINK_RATE_MSK (0xff << CFG_PROG_PHY_LINK_RATE_OFF)
198 #define CFG_PROG_OOB_PHY_LINK_RATE_OFF 8
199 #define CFG_PROG_OOB_PHY_LINK_RATE_MSK (0xf << CFG_PROG_OOB_PHY_LINK_RATE_OFF)
200 #define PHY_CTRL (PORT_BASE + 0x14)
201 #define PHY_CTRL_RESET_OFF 0
202 #define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF)
203 #define CMD_HDR_PIR_OFF 8
204 #define CMD_HDR_PIR_MSK (0x1 << CMD_HDR_PIR_OFF)
205 #define SERDES_CFG (PORT_BASE + 0x1c)
206 #define CFG_ALOS_CHK_DISABLE_OFF 9
207 #define CFG_ALOS_CHK_DISABLE_MSK (0x1 << CFG_ALOS_CHK_DISABLE_OFF)
208 #define SAS_PHY_BIST_CTRL (PORT_BASE + 0x2c)
209 #define CFG_BIST_MODE_SEL_OFF 0
210 #define CFG_BIST_MODE_SEL_MSK (0xf << CFG_BIST_MODE_SEL_OFF)
211 #define CFG_LOOP_TEST_MODE_OFF 14
212 #define CFG_LOOP_TEST_MODE_MSK (0x3 << CFG_LOOP_TEST_MODE_OFF)
213 #define CFG_RX_BIST_EN_OFF 16
214 #define CFG_RX_BIST_EN_MSK (0x1 << CFG_RX_BIST_EN_OFF)
215 #define CFG_TX_BIST_EN_OFF 17
216 #define CFG_TX_BIST_EN_MSK (0x1 << CFG_TX_BIST_EN_OFF)
217 #define CFG_BIST_TEST_OFF 18
218 #define CFG_BIST_TEST_MSK (0x1 << CFG_BIST_TEST_OFF)
219 #define SAS_PHY_BIST_CODE (PORT_BASE + 0x30)
220 #define SAS_PHY_BIST_CODE1 (PORT_BASE + 0x34)
221 #define SAS_BIST_ERR_CNT (PORT_BASE + 0x38)
222 #define SL_CFG (PORT_BASE + 0x84)
223 #define AIP_LIMIT (PORT_BASE + 0x90)
224 #define SL_CONTROL (PORT_BASE + 0x94)
225 #define SL_CONTROL_NOTIFY_EN_OFF 0
226 #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF)
227 #define SL_CTA_OFF 17
228 #define SL_CTA_MSK (0x1 << SL_CTA_OFF)
229 #define RX_PRIMS_STATUS (PORT_BASE + 0x98)
230 #define RX_BCAST_CHG_OFF 1
231 #define RX_BCAST_CHG_MSK (0x1 << RX_BCAST_CHG_OFF)
232 #define TX_ID_DWORD0 (PORT_BASE + 0x9c)
233 #define TX_ID_DWORD1 (PORT_BASE + 0xa0)
234 #define TX_ID_DWORD2 (PORT_BASE + 0xa4)
235 #define TX_ID_DWORD3 (PORT_BASE + 0xa8)
236 #define TX_ID_DWORD4 (PORT_BASE + 0xaC)
237 #define TX_ID_DWORD5 (PORT_BASE + 0xb0)
238 #define TX_ID_DWORD6 (PORT_BASE + 0xb4)
239 #define TXID_AUTO (PORT_BASE + 0xb8)
240 #define CT3_OFF 1
241 #define CT3_MSK (0x1 << CT3_OFF)
242 #define TX_HARDRST_OFF 2
243 #define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF)
244 #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4)
245 #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc)
246 #define STP_LINK_TIMER (PORT_BASE + 0x120)
247 #define STP_LINK_TIMEOUT_STATE (PORT_BASE + 0x124)
248 #define CON_CFG_DRIVER (PORT_BASE + 0x130)
249 #define SAS_SSP_CON_TIMER_CFG (PORT_BASE + 0x134)
250 #define SAS_SMP_CON_TIMER_CFG (PORT_BASE + 0x138)
251 #define SAS_STP_CON_TIMER_CFG (PORT_BASE + 0x13c)
252 #define CHL_INT0 (PORT_BASE + 0x1b4)
253 #define CHL_INT0_HOTPLUG_TOUT_OFF 0
254 #define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF)
255 #define CHL_INT0_SL_RX_BCST_ACK_OFF 1
256 #define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF)
257 #define CHL_INT0_SL_PHY_ENABLE_OFF 2
258 #define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF)
259 #define CHL_INT0_NOT_RDY_OFF 4
260 #define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF)
261 #define CHL_INT0_PHY_RDY_OFF 5
262 #define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF)
263 #define CHL_INT1 (PORT_BASE + 0x1b8)
264 #define CHL_INT1_DMAC_TX_ECC_MB_ERR_OFF 15
265 #define CHL_INT1_DMAC_TX_ECC_1B_ERR_OFF 16
266 #define CHL_INT1_DMAC_RX_ECC_MB_ERR_OFF 17
267 #define CHL_INT1_DMAC_RX_ECC_1B_ERR_OFF 18
268 #define CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF 19
269 #define CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF 20
270 #define CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF 21
271 #define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22
272 #define CHL_INT1_DMAC_TX_FIFO_ERR_OFF 23
273 #define CHL_INT1_DMAC_RX_FIFO_ERR_OFF 24
274 #define CHL_INT1_DMAC_TX_AXI_RUSER_ERR_OFF 26
275 #define CHL_INT1_DMAC_RX_AXI_RUSER_ERR_OFF 27
276 #define CHL_INT2 (PORT_BASE + 0x1bc)
277 #define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0
278 #define CHL_INT2_RX_DISP_ERR_OFF 28
279 #define CHL_INT2_RX_CODE_ERR_OFF 29
280 #define CHL_INT2_RX_INVLD_DW_OFF 30
281 #define CHL_INT2_STP_LINK_TIMEOUT_OFF 31
282 #define CHL_INT0_MSK (PORT_BASE + 0x1c0)
283 #define CHL_INT1_MSK (PORT_BASE + 0x1c4)
284 #define CHL_INT2_MSK (PORT_BASE + 0x1c8)
285 #define SAS_EC_INT_COAL_TIME (PORT_BASE + 0x1cc)
286 #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0)
287 #define SAS_RX_TRAIN_TIMER (PORT_BASE + 0x2a4)
288 #define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0)
289 #define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4)
290 #define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8)
291 #define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc)
292 #define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0)
293 #define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4)
294 #define DMA_TX_STATUS (PORT_BASE + 0x2d0)
295 #define DMA_TX_STATUS_BUSY_OFF 0
296 #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF)
297 #define DMA_RX_STATUS (PORT_BASE + 0x2e8)
298 #define DMA_RX_STATUS_BUSY_OFF 0
299 #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF)
300
301 #define COARSETUNE_TIME (PORT_BASE + 0x304)
302 #define TXDEEMPH_G1 (PORT_BASE + 0x350)
303 #define ERR_CNT_DWS_LOST (PORT_BASE + 0x380)
304 #define ERR_CNT_RESET_PROB (PORT_BASE + 0x384)
305 #define ERR_CNT_INVLD_DW (PORT_BASE + 0x390)
306 #define ERR_CNT_CODE_ERR (PORT_BASE + 0x394)
307 #define ERR_CNT_DISP_ERR (PORT_BASE + 0x398)
308 #define DFX_FIFO_CTRL (PORT_BASE + 0x3a0)
309 #define DFX_FIFO_CTRL_TRIGGER_MODE_OFF 0
310 #define DFX_FIFO_CTRL_TRIGGER_MODE_MSK (0x7 << DFX_FIFO_CTRL_TRIGGER_MODE_OFF)
311 #define DFX_FIFO_CTRL_DUMP_MODE_OFF 3
312 #define DFX_FIFO_CTRL_DUMP_MODE_MSK (0x7 << DFX_FIFO_CTRL_DUMP_MODE_OFF)
313 #define DFX_FIFO_CTRL_SIGNAL_SEL_OFF 6
314 #define DFX_FIFO_CTRL_SIGNAL_SEL_MSK (0xF << DFX_FIFO_CTRL_SIGNAL_SEL_OFF)
315 #define DFX_FIFO_CTRL_DUMP_DISABLE_OFF 10
316 #define DFX_FIFO_CTRL_DUMP_DISABLE_MSK (0x1 << DFX_FIFO_CTRL_DUMP_DISABLE_OFF)
317 #define DFX_FIFO_TRIGGER (PORT_BASE + 0x3a4)
318 #define DFX_FIFO_TRIGGER_MSK (PORT_BASE + 0x3a8)
319 #define DFX_FIFO_DUMP_MSK (PORT_BASE + 0x3aC)
320 #define DFX_FIFO_RD_DATA (PORT_BASE + 0x3b0)
321
322 #define DEFAULT_ITCT_HW 2048 /* reset value, not reprogrammed */
323 #if (HISI_SAS_MAX_DEVICES > DEFAULT_ITCT_HW)
324 #error Max ITCT exceeded
325 #endif
326
327 #define AXI_MASTER_CFG_BASE (0x5000)
328 #define AM_CTRL_GLOBAL (0x0)
329 #define AM_CTRL_SHUTDOWN_REQ_OFF 0
330 #define AM_CTRL_SHUTDOWN_REQ_MSK (0x1 << AM_CTRL_SHUTDOWN_REQ_OFF)
331 #define AM_CURR_TRANS_RETURN (0x150)
332
333 #define AM_CFG_MAX_TRANS (0x5010)
334 #define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014)
335 #define AXI_CFG (0x5100)
336 #define AM_ROB_ECC_ERR_ADDR (0x510c)
337 #define AM_ROB_ECC_ERR_ADDR_OFF 0
338 #define AM_ROB_ECC_ERR_ADDR_MSK 0xffffffff
339
340 /* RAS registers need init */
341 #define RAS_BASE (0x6000)
342 #define SAS_RAS_INTR0 (RAS_BASE)
343 #define SAS_RAS_INTR1 (RAS_BASE + 0x04)
344 #define SAS_RAS_INTR0_MASK (RAS_BASE + 0x08)
345 #define SAS_RAS_INTR1_MASK (RAS_BASE + 0x0c)
346 #define CFG_SAS_RAS_INTR_MASK (RAS_BASE + 0x1c)
347 #define SAS_RAS_INTR2 (RAS_BASE + 0x20)
348 #define SAS_RAS_INTR2_MASK (RAS_BASE + 0x24)
349
350 /* HW dma structures */
351 /* Delivery queue header */
352 /* dw0 */
353 #define CMD_HDR_ABORT_FLAG_OFF 0
354 #define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF)
355 #define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2
356 #define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF)
357 #define CMD_HDR_RESP_REPORT_OFF 5
358 #define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF)
359 #define CMD_HDR_TLR_CTRL_OFF 6
360 #define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF)
361 #define CMD_HDR_PHY_ID_OFF 8
362 #define CMD_HDR_PHY_ID_MSK (0x1ff << CMD_HDR_PHY_ID_OFF)
363 #define CMD_HDR_FORCE_PHY_OFF 17
364 #define CMD_HDR_FORCE_PHY_MSK (0x1U << CMD_HDR_FORCE_PHY_OFF)
365 #define CMD_HDR_PORT_OFF 18
366 #define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF)
367 #define CMD_HDR_PRIORITY_OFF 27
368 #define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF)
369 #define CMD_HDR_CMD_OFF 29
370 #define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF)
371 /* dw1 */
372 #define CMD_HDR_UNCON_CMD_OFF 3
373 #define CMD_HDR_DIR_OFF 5
374 #define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF)
375 #define CMD_HDR_RESET_OFF 7
376 #define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF)
377 #define CMD_HDR_VDTL_OFF 10
378 #define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF)
379 #define CMD_HDR_FRAME_TYPE_OFF 11
380 #define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF)
381 #define CMD_HDR_DEV_ID_OFF 16
382 #define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF)
383 /* dw2 */
384 #define CMD_HDR_CFL_OFF 0
385 #define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF)
386 #define CMD_HDR_NCQ_TAG_OFF 10
387 #define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF)
388 #define CMD_HDR_MRFL_OFF 15
389 #define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF)
390 #define CMD_HDR_SG_MOD_OFF 24
391 #define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF)
392 /* dw3 */
393 #define CMD_HDR_IPTT_OFF 0
394 #define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF)
395 /* dw6 */
396 #define CMD_HDR_DIF_SGL_LEN_OFF 0
397 #define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF)
398 #define CMD_HDR_DATA_SGL_LEN_OFF 16
399 #define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF)
400 /* dw7 */
401 #define CMD_HDR_ADDR_MODE_SEL_OFF 15
402 #define CMD_HDR_ADDR_MODE_SEL_MSK (1 << CMD_HDR_ADDR_MODE_SEL_OFF)
403 #define CMD_HDR_ABORT_IPTT_OFF 16
404 #define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF)
405
406 /* Completion header */
407 /* dw0 */
408 #define CMPLT_HDR_CMPLT_OFF 0
409 #define CMPLT_HDR_CMPLT_MSK (0x3 << CMPLT_HDR_CMPLT_OFF)
410 #define CMPLT_HDR_ERROR_PHASE_OFF 2
411 #define CMPLT_HDR_ERROR_PHASE_MSK (0xff << CMPLT_HDR_ERROR_PHASE_OFF)
412 /* bit[9:2] Error Phase */
413 #define ERR_PHASE_RESPONSE_FRAME_REV_STAGE_OFF \
414 8
415 #define ERR_PHASE_RESPONSE_FRAME_REV_STAGE_MSK \
416 (0x1 << ERR_PHASE_RESPONSE_FRAME_REV_STAGE_OFF)
417 #define CMPLT_HDR_RSPNS_XFRD_OFF 10
418 #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF)
419 #define CMPLT_HDR_RSPNS_GOOD_OFF 11
420 #define CMPLT_HDR_RSPNS_GOOD_MSK (0x1 << CMPLT_HDR_RSPNS_GOOD_OFF)
421 #define CMPLT_HDR_ERX_OFF 12
422 #define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF)
423 #define CMPLT_HDR_ABORT_STAT_OFF 13
424 #define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF)
425 /* abort_stat */
426 #define STAT_IO_NOT_VALID 0x1
427 #define STAT_IO_NO_DEVICE 0x2
428 #define STAT_IO_COMPLETE 0x3
429 #define STAT_IO_ABORTED 0x4
430 /* dw1 */
431 #define CMPLT_HDR_IPTT_OFF 0
432 #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF)
433 #define CMPLT_HDR_DEV_ID_OFF 16
434 #define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF)
435 /* dw3 */
436 #define SATA_DISK_IN_ERROR_STATUS_OFF 8
437 #define SATA_DISK_IN_ERROR_STATUS_MSK (0x1 << SATA_DISK_IN_ERROR_STATUS_OFF)
438 #define CMPLT_HDR_SATA_DISK_ERR_OFF 16
439 #define CMPLT_HDR_SATA_DISK_ERR_MSK (0x1 << CMPLT_HDR_SATA_DISK_ERR_OFF)
440 #define CMPLT_HDR_IO_IN_TARGET_OFF 17
441 #define CMPLT_HDR_IO_IN_TARGET_MSK (0x1 << CMPLT_HDR_IO_IN_TARGET_OFF)
442 /* bit[23:18] ERR_FIS_ATA_STATUS */
443 #define FIS_ATA_STATUS_ERR_OFF 18
444 #define FIS_ATA_STATUS_ERR_MSK (0x1 << FIS_ATA_STATUS_ERR_OFF)
445 #define FIS_TYPE_SDB_OFF 31
446 #define FIS_TYPE_SDB_MSK (0x1 << FIS_TYPE_SDB_OFF)
447
448 /* ITCT header */
449 /* qw0 */
450 #define ITCT_HDR_DEV_TYPE_OFF 0
451 #define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF)
452 #define ITCT_HDR_VALID_OFF 2
453 #define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF)
454 #define ITCT_HDR_MCR_OFF 5
455 #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF)
456 #define ITCT_HDR_VLN_OFF 9
457 #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF)
458 #define ITCT_HDR_SMP_TIMEOUT_OFF 16
459 #define ITCT_HDR_AWT_CONTINUE_OFF 25
460 #define ITCT_HDR_PORT_ID_OFF 28
461 #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF)
462 /* qw2 */
463 #define ITCT_HDR_INLT_OFF 0
464 #define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF)
465 #define ITCT_HDR_RTOLT_OFF 48
466 #define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF)
467
468 struct hisi_sas_protect_iu_v3_hw {
469 u32 dw0;
470 u32 lbrtcv;
471 u32 lbrtgv;
472 u32 dw3;
473 u32 dw4;
474 u32 dw5;
475 u32 rsv;
476 };
477
478 struct hisi_sas_complete_v3_hdr {
479 __le32 dw0;
480 __le32 dw1;
481 __le32 act;
482 __le32 dw3;
483 };
484
485 struct hisi_sas_err_record_v3 {
486 /* dw0 */
487 __le32 trans_tx_fail_type;
488
489 /* dw1 */
490 __le32 trans_rx_fail_type;
491
492 /* dw2 */
493 __le16 dma_tx_err_type;
494 __le16 sipc_rx_err_type;
495
496 /* dw3 */
497 __le32 dma_rx_err_type;
498 };
499
500 #define RX_DATA_LEN_UNDERFLOW_OFF 6
501 #define RX_DATA_LEN_UNDERFLOW_MSK (1 << RX_DATA_LEN_UNDERFLOW_OFF)
502
503 #define RX_FIS_STATUS_ERR_OFF 0
504 #define RX_FIS_STATUS_ERR_MSK (1 << RX_FIS_STATUS_ERR_OFF)
505
506 #define HISI_SAS_COMMAND_ENTRIES_V3_HW 4096
507 #define HISI_SAS_MSI_COUNT_V3_HW 32
508
509 #define DIR_NO_DATA 0
510 #define DIR_TO_INI 1
511 #define DIR_TO_DEVICE 2
512 #define DIR_RESERVED 3
513
514 #define FIS_CMD_IS_UNCONSTRAINED(fis) \
515 ((fis.command == ATA_CMD_READ_LOG_EXT) || \
516 (fis.command == ATA_CMD_READ_LOG_DMA_EXT) || \
517 ((fis.command == ATA_CMD_DEV_RESET) && \
518 ((fis.control & ATA_SRST) != 0)))
519
520 #define T10_INSRT_EN_OFF 0
521 #define T10_INSRT_EN_MSK (1 << T10_INSRT_EN_OFF)
522 #define T10_RMV_EN_OFF 1
523 #define T10_RMV_EN_MSK (1 << T10_RMV_EN_OFF)
524 #define T10_RPLC_EN_OFF 2
525 #define T10_RPLC_EN_MSK (1 << T10_RPLC_EN_OFF)
526 #define T10_CHK_EN_OFF 3
527 #define T10_CHK_EN_MSK (1 << T10_CHK_EN_OFF)
528 #define INCR_LBRT_OFF 5
529 #define INCR_LBRT_MSK (1 << INCR_LBRT_OFF)
530 #define USR_DATA_BLOCK_SZ_OFF 20
531 #define USR_DATA_BLOCK_SZ_MSK (0x3 << USR_DATA_BLOCK_SZ_OFF)
532 #define T10_CHK_MSK_OFF 16
533 #define T10_CHK_REF_TAG_MSK (0xf0 << T10_CHK_MSK_OFF)
534 #define T10_CHK_APP_TAG_MSK (0xc << T10_CHK_MSK_OFF)
535
536 #define BASE_VECTORS_V3_HW 16
537 #define MIN_AFFINE_VECTORS_V3_HW (BASE_VECTORS_V3_HW + 1)
538
539 #define CHNL_INT_STS_MSK 0xeeeeeeee
540 #define CHNL_INT_STS_PHY_MSK 0xe
541 #define CHNL_INT_STS_INT0_MSK BIT(1)
542 #define CHNL_INT_STS_INT1_MSK BIT(2)
543 #define CHNL_INT_STS_INT2_MSK BIT(3)
544 #define CHNL_WIDTH 4
545
546 #define BAR_NO_V3_HW 5
547
548 enum {
549 DSM_FUNC_ERR_HANDLE_MSI = 0,
550 };
551
552 static bool hisi_sas_intr_conv;
553 MODULE_PARM_DESC(intr_conv, "interrupt converge enable (0-1)");
554
555 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
556 static int prot_mask;
557 module_param(prot_mask, int, 0444);
558 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=0x0 ");
559
560 /* the index of iopoll queues are bigger than interrupt queues' */
561 static int experimental_iopoll_q_cnt;
562 module_param(experimental_iopoll_q_cnt, int, 0444);
563 MODULE_PARM_DESC(experimental_iopoll_q_cnt, "number of queues to be used as poll mode, def=0");
564
565 static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba);
566
hisi_sas_read32(struct hisi_hba * hisi_hba,u32 off)567 static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
568 {
569 void __iomem *regs = hisi_hba->regs + off;
570
571 return readl(regs);
572 }
573
hisi_sas_write32(struct hisi_hba * hisi_hba,u32 off,u32 val)574 static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val)
575 {
576 void __iomem *regs = hisi_hba->regs + off;
577
578 writel(val, regs);
579 }
580
hisi_sas_phy_write32(struct hisi_hba * hisi_hba,int phy_no,u32 off,u32 val)581 static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no,
582 u32 off, u32 val)
583 {
584 void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
585
586 writel(val, regs);
587 }
588
hisi_sas_phy_read32(struct hisi_hba * hisi_hba,int phy_no,u32 off)589 static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
590 int phy_no, u32 off)
591 {
592 void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
593
594 return readl(regs);
595 }
596
597 #define hisi_sas_read32_poll_timeout(off, val, cond, delay_us, \
598 timeout_us) \
599 ({ \
600 void __iomem *regs = hisi_hba->regs + off; \
601 readl_poll_timeout(regs, val, cond, delay_us, timeout_us); \
602 })
603
604 #define hisi_sas_read32_poll_timeout_atomic(off, val, cond, delay_us, \
605 timeout_us) \
606 ({ \
607 void __iomem *regs = hisi_hba->regs + off; \
608 readl_poll_timeout_atomic(regs, val, cond, delay_us, timeout_us);\
609 })
610
interrupt_enable_v3_hw(struct hisi_hba * hisi_hba)611 static void interrupt_enable_v3_hw(struct hisi_hba *hisi_hba)
612 {
613 int i;
614
615 for (i = 0; i < hisi_hba->queue_count; i++)
616 hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0);
617
618 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xfefefefe);
619 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xfefefefe);
620 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffc220ff);
621 hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0x155555);
622
623 for (i = 0; i < hisi_hba->n_phy; i++) {
624 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xf2057fff);
625 hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffbfe);
626 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0);
627 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0);
628 hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0);
629 }
630 }
631
init_reg_v3_hw(struct hisi_hba * hisi_hba)632 static void init_reg_v3_hw(struct hisi_hba *hisi_hba)
633 {
634 struct pci_dev *pdev = hisi_hba->pci_dev;
635 int i, j;
636
637 /* Global registers init */
638 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
639 (u32)((1ULL << hisi_hba->queue_count) - 1));
640 hisi_sas_write32(hisi_hba, CFG_MAX_TAG, 0xfff0400);
641 /* time / CLK_AHB = 2.5s / 2ns = 0x4A817C80 */
642 hisi_sas_write32(hisi_hba, TRANS_LOCK_ICT_TIME, 0x4A817C80);
643 hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x108);
644 hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1);
645 hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1);
646 hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1);
647 hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1);
648 hisi_sas_write32(hisi_hba, CQ_INT_CONVERGE_EN,
649 hisi_sas_intr_conv);
650 hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0xffff);
651 hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
652 hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
653 hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff);
654 hisi_sas_write32(hisi_hba, CHNL_PHYUPDOWN_INT_MSK, 0x0);
655 hisi_sas_write32(hisi_hba, CHNL_ENT_INT_MSK, 0x0);
656 hisi_sas_write32(hisi_hba, HGC_COM_INT_MSK, 0x0);
657 hisi_sas_write32(hisi_hba, AWQOS_AWCACHE_CFG, 0xf0f0);
658 hisi_sas_write32(hisi_hba, ARQOS_ARCACHE_CFG, 0xf0f0);
659 hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1);
660
661 if (pdev->revision < 0x30)
662 hisi_sas_write32(hisi_hba, SAS_AXI_USER3, 0);
663
664 interrupt_enable_v3_hw(hisi_hba);
665 for (i = 0; i < hisi_hba->n_phy; i++) {
666 enum sas_linkrate max;
667 struct hisi_sas_phy *phy = &hisi_hba->phy[i];
668 struct asd_sas_phy *sas_phy = &phy->sas_phy;
669 u32 prog_phy_link_rate = hisi_sas_phy_read32(hisi_hba, i,
670 PROG_PHY_LINK_RATE);
671
672 prog_phy_link_rate &= ~CFG_PROG_PHY_LINK_RATE_MSK;
673 if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate <
674 SAS_LINK_RATE_1_5_GBPS))
675 max = SAS_LINK_RATE_12_0_GBPS;
676 else
677 max = sas_phy->phy->maximum_linkrate;
678 prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
679 hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE,
680 prog_phy_link_rate);
681 hisi_sas_phy_write32(hisi_hba, i, SAS_RX_TRAIN_TIMER, 0x13e80);
682 hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff);
683 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff);
684 hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xffffffff);
685 hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
686 hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0);
687 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0);
688 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x1);
689 hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, 0x7f7a120);
690 hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x2a0a01);
691 hisi_sas_phy_write32(hisi_hba, i, SAS_EC_INT_COAL_TIME,
692 0x30f4240);
693 hisi_sas_phy_write32(hisi_hba, i, AIP_LIMIT, 0x2ffff);
694
695 /* set value through firmware for 920B and later version */
696 if (pdev->revision < 0x30) {
697 hisi_sas_phy_write32(hisi_hba, i, SAS_SSP_CON_TIMER_CFG, 0x32);
698 hisi_sas_phy_write32(hisi_hba, i, SERDES_CFG, 0xffc00);
699 /* used for 12G negotiate */
700 hisi_sas_phy_write32(hisi_hba, i, COARSETUNE_TIME, 0x1e);
701 }
702
703 /* get default FFE configuration for BIST */
704 for (j = 0; j < FFE_CFG_MAX; j++) {
705 u32 val = hisi_sas_phy_read32(hisi_hba, i,
706 TXDEEMPH_G1 + (j * 0x4));
707 hisi_hba->debugfs_bist_ffe[i][j] = val;
708 }
709 }
710
711 for (i = 0; i < hisi_hba->queue_count; i++) {
712 /* Delivery queue */
713 hisi_sas_write32(hisi_hba,
714 DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
715 upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
716
717 hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
718 lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
719
720 hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14),
721 HISI_SAS_QUEUE_SLOTS);
722
723 /* Completion queue */
724 hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
725 upper_32_bits(hisi_hba->complete_hdr_dma[i]));
726
727 hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
728 lower_32_bits(hisi_hba->complete_hdr_dma[i]));
729
730 hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
731 HISI_SAS_QUEUE_SLOTS);
732 }
733
734 /* itct */
735 hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
736 lower_32_bits(hisi_hba->itct_dma));
737
738 hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
739 upper_32_bits(hisi_hba->itct_dma));
740
741 /* iost */
742 hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
743 lower_32_bits(hisi_hba->iost_dma));
744
745 hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
746 upper_32_bits(hisi_hba->iost_dma));
747
748 /* breakpoint */
749 hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO,
750 lower_32_bits(hisi_hba->breakpoint_dma));
751
752 hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI,
753 upper_32_bits(hisi_hba->breakpoint_dma));
754
755 /* SATA broken msg */
756 hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO,
757 lower_32_bits(hisi_hba->sata_breakpoint_dma));
758
759 hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI,
760 upper_32_bits(hisi_hba->sata_breakpoint_dma));
761
762 /* SATA initial fis */
763 hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO,
764 lower_32_bits(hisi_hba->initial_fis_dma));
765
766 hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI,
767 upper_32_bits(hisi_hba->initial_fis_dma));
768
769 /* RAS registers init */
770 hisi_sas_write32(hisi_hba, SAS_RAS_INTR0_MASK, 0x0);
771 hisi_sas_write32(hisi_hba, SAS_RAS_INTR1_MASK, 0x0);
772 hisi_sas_write32(hisi_hba, SAS_RAS_INTR2_MASK, 0x0);
773 hisi_sas_write32(hisi_hba, CFG_SAS_RAS_INTR_MASK, 0x0);
774
775 /* LED registers init */
776 hisi_sas_write32(hisi_hba, SAS_CFG_DRIVE_VLD, 0x80000ff);
777 hisi_sas_write32(hisi_hba, SAS_GPIO_TX_0_1, 0x80808080);
778 hisi_sas_write32(hisi_hba, SAS_GPIO_TX_0_1 + 0x4, 0x80808080);
779 /* Configure blink generator rate A to 1Hz and B to 4Hz */
780 hisi_sas_write32(hisi_hba, SAS_GPIO_CFG_1, 0x121700);
781 hisi_sas_write32(hisi_hba, SAS_GPIO_CFG_0, 0x800000);
782 }
783
config_phy_opt_mode_v3_hw(struct hisi_hba * hisi_hba,int phy_no)784 static void config_phy_opt_mode_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
785 {
786 u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
787
788 cfg &= ~PHY_CFG_DC_OPT_MSK;
789 cfg |= 1 << PHY_CFG_DC_OPT_OFF;
790 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
791 }
792
config_id_frame_v3_hw(struct hisi_hba * hisi_hba,int phy_no)793 static void config_id_frame_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
794 {
795 struct sas_identify_frame identify_frame;
796 u32 *identify_buffer;
797
798 memset(&identify_frame, 0, sizeof(identify_frame));
799 identify_frame.dev_type = SAS_END_DEVICE;
800 identify_frame.frame_type = 0;
801 identify_frame._un1 = 1;
802 identify_frame.initiator_bits = SAS_PROTOCOL_ALL;
803 identify_frame.target_bits = SAS_PROTOCOL_NONE;
804 memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
805 memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
806 identify_frame.phy_id = phy_no;
807 identify_buffer = (u32 *)(&identify_frame);
808
809 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0,
810 __swab32(identify_buffer[0]));
811 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1,
812 __swab32(identify_buffer[1]));
813 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2,
814 __swab32(identify_buffer[2]));
815 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3,
816 __swab32(identify_buffer[3]));
817 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4,
818 __swab32(identify_buffer[4]));
819 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5,
820 __swab32(identify_buffer[5]));
821 }
822
setup_itct_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_device * sas_dev)823 static void setup_itct_v3_hw(struct hisi_hba *hisi_hba,
824 struct hisi_sas_device *sas_dev)
825 {
826 struct domain_device *device = sas_dev->sas_device;
827 struct device *dev = hisi_hba->dev;
828 u64 qw0, device_id = sas_dev->device_id;
829 struct hisi_sas_itct *itct = &hisi_hba->itct[device_id];
830 struct domain_device *parent_dev = device->parent;
831 struct asd_sas_port *sas_port = device->port;
832 struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
833 u64 sas_addr;
834
835 memset(itct, 0, sizeof(*itct));
836
837 /* qw0 */
838 qw0 = 0;
839 switch (sas_dev->dev_type) {
840 case SAS_END_DEVICE:
841 case SAS_EDGE_EXPANDER_DEVICE:
842 case SAS_FANOUT_EXPANDER_DEVICE:
843 qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
844 break;
845 case SAS_SATA_DEV:
846 case SAS_SATA_PENDING:
847 if (parent_dev && dev_is_expander(parent_dev->dev_type))
848 qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF;
849 else
850 qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF;
851 break;
852 default:
853 dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
854 sas_dev->dev_type);
855 }
856
857 qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
858 (device->linkrate << ITCT_HDR_MCR_OFF) |
859 (1 << ITCT_HDR_VLN_OFF) |
860 (0xfa << ITCT_HDR_SMP_TIMEOUT_OFF) |
861 (1 << ITCT_HDR_AWT_CONTINUE_OFF) |
862 (port->id << ITCT_HDR_PORT_ID_OFF));
863 itct->qw0 = cpu_to_le64(qw0);
864
865 /* qw1 */
866 memcpy(&sas_addr, device->sas_addr, SAS_ADDR_SIZE);
867 itct->sas_addr = cpu_to_le64(__swab64(sas_addr));
868
869 /* qw2 */
870 if (!dev_is_sata(device))
871 itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) |
872 (0x1ULL << ITCT_HDR_RTOLT_OFF));
873 }
874
clear_itct_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_device * sas_dev)875 static int clear_itct_v3_hw(struct hisi_hba *hisi_hba,
876 struct hisi_sas_device *sas_dev)
877 {
878 DECLARE_COMPLETION_ONSTACK(completion);
879 u64 dev_id = sas_dev->device_id;
880 struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
881 u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
882 struct device *dev = hisi_hba->dev;
883
884 sas_dev->completion = &completion;
885
886 /* clear the itct interrupt state */
887 if (ENT_INT_SRC3_ITC_INT_MSK & reg_val)
888 hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
889 ENT_INT_SRC3_ITC_INT_MSK);
890
891 /* clear the itct table */
892 reg_val = ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK);
893 hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val);
894
895 if (!wait_for_completion_timeout(sas_dev->completion,
896 HISI_SAS_CLEAR_ITCT_TIMEOUT)) {
897 dev_warn(dev, "failed to clear ITCT\n");
898 return -ETIMEDOUT;
899 }
900
901 memset(itct, 0, sizeof(struct hisi_sas_itct));
902 return 0;
903 }
904
dereg_device_v3_hw(struct hisi_hba * hisi_hba,struct domain_device * device)905 static void dereg_device_v3_hw(struct hisi_hba *hisi_hba,
906 struct domain_device *device)
907 {
908 struct hisi_sas_slot *slot, *slot2;
909 struct hisi_sas_device *sas_dev = device->lldd_dev;
910 u32 cfg_abt_set_query_iptt;
911
912 cfg_abt_set_query_iptt = hisi_sas_read32(hisi_hba,
913 CFG_ABT_SET_QUERY_IPTT);
914 spin_lock(&sas_dev->lock);
915 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) {
916 cfg_abt_set_query_iptt &= ~CFG_SET_ABORTED_IPTT_MSK;
917 cfg_abt_set_query_iptt |= (1 << CFG_SET_ABORTED_EN_OFF) |
918 (slot->idx << CFG_SET_ABORTED_IPTT_OFF);
919 hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT,
920 cfg_abt_set_query_iptt);
921 }
922 spin_unlock(&sas_dev->lock);
923 cfg_abt_set_query_iptt &= ~(1 << CFG_SET_ABORTED_EN_OFF);
924 hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT,
925 cfg_abt_set_query_iptt);
926 hisi_sas_write32(hisi_hba, CFG_ABT_SET_IPTT_DONE,
927 1 << CFG_ABT_SET_IPTT_DONE_OFF);
928 }
929
reset_hw_v3_hw(struct hisi_hba * hisi_hba)930 static int reset_hw_v3_hw(struct hisi_hba *hisi_hba)
931 {
932 struct device *dev = hisi_hba->dev;
933 int ret;
934 u32 val;
935
936 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
937
938 /* Disable all of the PHYs */
939 hisi_sas_stop_phys(hisi_hba);
940 udelay(50);
941
942 /* Ensure axi bus idle */
943 ret = hisi_sas_read32_poll_timeout(AXI_CFG, val, !val,
944 20000, 1000000);
945 if (ret) {
946 dev_err(dev, "axi bus is not idle, ret = %d!\n", ret);
947 return -EIO;
948 }
949
950 if (ACPI_HANDLE(dev)) {
951 acpi_status s;
952
953 s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
954 if (ACPI_FAILURE(s)) {
955 dev_err(dev, "Reset failed\n");
956 return -EIO;
957 }
958 } else {
959 dev_err(dev, "no reset method!\n");
960 return -EINVAL;
961 }
962
963 return 0;
964 }
965
hw_init_v3_hw(struct hisi_hba * hisi_hba)966 static int hw_init_v3_hw(struct hisi_hba *hisi_hba)
967 {
968 struct device *dev = hisi_hba->dev;
969 struct acpi_device *acpi_dev;
970 union acpi_object *obj;
971 guid_t guid;
972 int rc;
973
974 rc = reset_hw_v3_hw(hisi_hba);
975 if (rc) {
976 dev_err(dev, "hisi_sas_reset_hw failed, rc=%d\n", rc);
977 return rc;
978 }
979
980 msleep(100);
981 init_reg_v3_hw(hisi_hba);
982
983 if (guid_parse("D5918B4B-37AE-4E10-A99F-E5E8A6EF4C1F", &guid)) {
984 dev_err(dev, "Parse GUID failed\n");
985 return -EINVAL;
986 }
987
988 /*
989 * This DSM handles some hardware-related configurations:
990 * 1. Switch over to MSI error handling in kernel
991 * 2. BIOS *may* reset some register values through this method
992 */
993 obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), &guid, 0,
994 DSM_FUNC_ERR_HANDLE_MSI, NULL);
995 if (!obj)
996 dev_warn(dev, "can not find DSM method, ignore\n");
997 else
998 ACPI_FREE(obj);
999
1000 acpi_dev = ACPI_COMPANION(dev);
1001 if (!acpi_device_power_manageable(acpi_dev))
1002 dev_notice(dev, "neither _PS0 nor _PR0 is defined\n");
1003 return 0;
1004 }
1005
enable_phy_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1006 static void enable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1007 {
1008 u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
1009
1010 cfg |= PHY_CFG_ENA_MSK;
1011 cfg &= ~PHY_CFG_PHY_RST_MSK;
1012 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
1013 }
1014
disable_phy_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1015 static void disable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1016 {
1017 u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
1018 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2_MSK);
1019 static const u32 msk = BIT(CHL_INT2_RX_DISP_ERR_OFF) |
1020 BIT(CHL_INT2_RX_CODE_ERR_OFF) |
1021 BIT(CHL_INT2_RX_INVLD_DW_OFF);
1022 u32 state;
1023
1024 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2_MSK, msk | irq_msk);
1025
1026 cfg &= ~PHY_CFG_ENA_MSK;
1027 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
1028
1029 mdelay(50);
1030
1031 state = hisi_sas_read32(hisi_hba, PHY_STATE);
1032 if (state & BIT(phy_no)) {
1033 cfg |= PHY_CFG_PHY_RST_MSK;
1034 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
1035 }
1036
1037 udelay(1);
1038
1039 hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_INVLD_DW);
1040 hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DISP_ERR);
1041 hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_CODE_ERR);
1042
1043 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2, msk);
1044 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2_MSK, irq_msk);
1045 }
1046
start_phy_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1047 static void start_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1048 {
1049 config_id_frame_v3_hw(hisi_hba, phy_no);
1050 config_phy_opt_mode_v3_hw(hisi_hba, phy_no);
1051 enable_phy_v3_hw(hisi_hba, phy_no);
1052 }
1053
phy_hard_reset_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1054 static void phy_hard_reset_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1055 {
1056 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1057 u32 txid_auto;
1058
1059 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1060 if (phy->identify.device_type == SAS_END_DEVICE) {
1061 txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
1062 hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
1063 txid_auto | TX_HARDRST_MSK);
1064 }
1065 msleep(100);
1066 hisi_sas_phy_enable(hisi_hba, phy_no, 1);
1067 }
1068
phy_get_max_linkrate_v3_hw(void)1069 static enum sas_linkrate phy_get_max_linkrate_v3_hw(void)
1070 {
1071 return SAS_LINK_RATE_12_0_GBPS;
1072 }
1073
phys_init_v3_hw(struct hisi_hba * hisi_hba)1074 static void phys_init_v3_hw(struct hisi_hba *hisi_hba)
1075 {
1076 int i;
1077
1078 for (i = 0; i < hisi_hba->n_phy; i++) {
1079 struct hisi_sas_phy *phy = &hisi_hba->phy[i];
1080 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1081
1082 if (!sas_phy->phy->enabled)
1083 continue;
1084
1085 hisi_sas_phy_enable(hisi_hba, i, 1);
1086 }
1087 }
1088
sl_notify_ssp_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1089 static void sl_notify_ssp_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1090 {
1091 u32 sl_control;
1092
1093 sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
1094 sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
1095 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
1096 msleep(1);
1097 sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
1098 sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
1099 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
1100 }
1101
get_wideport_bitmap_v3_hw(struct hisi_hba * hisi_hba,int port_id)1102 static int get_wideport_bitmap_v3_hw(struct hisi_hba *hisi_hba, int port_id)
1103 {
1104 int i, bitmap = 0;
1105 u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
1106 u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
1107
1108 for (i = 0; i < hisi_hba->n_phy; i++)
1109 if (phy_state & BIT(i))
1110 if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
1111 bitmap |= BIT(i);
1112
1113 return bitmap;
1114 }
1115
start_delivery_v3_hw(struct hisi_sas_dq * dq)1116 static void start_delivery_v3_hw(struct hisi_sas_dq *dq)
1117 {
1118 struct hisi_hba *hisi_hba = dq->hisi_hba;
1119 struct hisi_sas_slot *s, *s1, *s2 = NULL;
1120 int dlvry_queue = dq->id;
1121 int wp;
1122
1123 list_for_each_entry_safe(s, s1, &dq->list, delivery) {
1124 if (!s->ready)
1125 break;
1126 s2 = s;
1127 list_del(&s->delivery);
1128 }
1129
1130 if (!s2)
1131 return;
1132
1133 /*
1134 * Ensure that memories for slots built on other CPUs is observed.
1135 */
1136 smp_rmb();
1137 wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
1138
1139 hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
1140 }
1141
prep_prd_sge_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot,struct hisi_sas_cmd_hdr * hdr,struct scatterlist * scatter,int n_elem)1142 static void prep_prd_sge_v3_hw(struct hisi_hba *hisi_hba,
1143 struct hisi_sas_slot *slot,
1144 struct hisi_sas_cmd_hdr *hdr,
1145 struct scatterlist *scatter,
1146 int n_elem)
1147 {
1148 struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
1149 struct scatterlist *sg;
1150 int i;
1151
1152 for_each_sg(scatter, sg, n_elem, i) {
1153 struct hisi_sas_sge *entry = &sge_page->sge[i];
1154
1155 entry->addr = cpu_to_le64(sg_dma_address(sg));
1156 entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
1157 entry->data_len = cpu_to_le32(sg_dma_len(sg));
1158 entry->data_off = 0;
1159 }
1160
1161 hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
1162
1163 hdr->sg_len |= cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
1164 }
1165
prep_prd_sge_dif_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot,struct hisi_sas_cmd_hdr * hdr,struct scatterlist * scatter,int n_elem)1166 static void prep_prd_sge_dif_v3_hw(struct hisi_hba *hisi_hba,
1167 struct hisi_sas_slot *slot,
1168 struct hisi_sas_cmd_hdr *hdr,
1169 struct scatterlist *scatter,
1170 int n_elem)
1171 {
1172 struct hisi_sas_sge_dif_page *sge_dif_page;
1173 struct scatterlist *sg;
1174 int i;
1175
1176 sge_dif_page = hisi_sas_sge_dif_addr_mem(slot);
1177
1178 for_each_sg(scatter, sg, n_elem, i) {
1179 struct hisi_sas_sge *entry = &sge_dif_page->sge[i];
1180
1181 entry->addr = cpu_to_le64(sg_dma_address(sg));
1182 entry->page_ctrl_0 = 0;
1183 entry->page_ctrl_1 = 0;
1184 entry->data_len = cpu_to_le32(sg_dma_len(sg));
1185 entry->data_off = 0;
1186 }
1187
1188 hdr->dif_prd_table_addr =
1189 cpu_to_le64(hisi_sas_sge_dif_addr_dma(slot));
1190
1191 hdr->sg_len |= cpu_to_le32(n_elem << CMD_HDR_DIF_SGL_LEN_OFF);
1192 }
1193
get_prot_chk_msk_v3_hw(struct scsi_cmnd * scsi_cmnd)1194 static u32 get_prot_chk_msk_v3_hw(struct scsi_cmnd *scsi_cmnd)
1195 {
1196 unsigned char prot_flags = scsi_cmnd->prot_flags;
1197
1198 if (prot_flags & SCSI_PROT_REF_CHECK)
1199 return T10_CHK_APP_TAG_MSK;
1200 return T10_CHK_REF_TAG_MSK | T10_CHK_APP_TAG_MSK;
1201 }
1202
fill_prot_v3_hw(struct scsi_cmnd * scsi_cmnd,struct hisi_sas_protect_iu_v3_hw * prot)1203 static void fill_prot_v3_hw(struct scsi_cmnd *scsi_cmnd,
1204 struct hisi_sas_protect_iu_v3_hw *prot)
1205 {
1206 unsigned char prot_op = scsi_get_prot_op(scsi_cmnd);
1207 unsigned int interval = scsi_prot_interval(scsi_cmnd);
1208 u32 lbrt_chk_val = t10_pi_ref_tag(scsi_cmd_to_rq(scsi_cmnd));
1209
1210 switch (prot_op) {
1211 case SCSI_PROT_READ_INSERT:
1212 prot->dw0 |= T10_INSRT_EN_MSK;
1213 prot->lbrtgv = lbrt_chk_val;
1214 break;
1215 case SCSI_PROT_READ_STRIP:
1216 prot->dw0 |= (T10_RMV_EN_MSK | T10_CHK_EN_MSK);
1217 prot->lbrtcv = lbrt_chk_val;
1218 prot->dw4 |= get_prot_chk_msk_v3_hw(scsi_cmnd);
1219 break;
1220 case SCSI_PROT_READ_PASS:
1221 prot->dw0 |= T10_CHK_EN_MSK;
1222 prot->lbrtcv = lbrt_chk_val;
1223 prot->dw4 |= get_prot_chk_msk_v3_hw(scsi_cmnd);
1224 break;
1225 case SCSI_PROT_WRITE_INSERT:
1226 prot->dw0 |= T10_INSRT_EN_MSK;
1227 prot->lbrtgv = lbrt_chk_val;
1228 break;
1229 case SCSI_PROT_WRITE_STRIP:
1230 prot->dw0 |= (T10_RMV_EN_MSK | T10_CHK_EN_MSK);
1231 prot->lbrtcv = lbrt_chk_val;
1232 break;
1233 case SCSI_PROT_WRITE_PASS:
1234 prot->dw0 |= T10_CHK_EN_MSK;
1235 prot->lbrtcv = lbrt_chk_val;
1236 prot->dw4 |= get_prot_chk_msk_v3_hw(scsi_cmnd);
1237 break;
1238 default:
1239 WARN(1, "prot_op(0x%x) is not valid\n", prot_op);
1240 break;
1241 }
1242
1243 switch (interval) {
1244 case 512:
1245 break;
1246 case 4096:
1247 prot->dw0 |= (0x1 << USR_DATA_BLOCK_SZ_OFF);
1248 break;
1249 case 520:
1250 prot->dw0 |= (0x2 << USR_DATA_BLOCK_SZ_OFF);
1251 break;
1252 default:
1253 WARN(1, "protection interval (0x%x) invalid\n",
1254 interval);
1255 break;
1256 }
1257
1258 prot->dw0 |= INCR_LBRT_MSK;
1259 }
1260
prep_ssp_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot)1261 static void prep_ssp_v3_hw(struct hisi_hba *hisi_hba,
1262 struct hisi_sas_slot *slot)
1263 {
1264 struct sas_task *task = slot->task;
1265 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1266 struct domain_device *device = task->dev;
1267 struct hisi_sas_device *sas_dev = device->lldd_dev;
1268 struct hisi_sas_port *port = slot->port;
1269 struct sas_ssp_task *ssp_task = &task->ssp_task;
1270 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
1271 struct sas_tmf_task *tmf = slot->tmf;
1272 int has_data = 0, priority = !!tmf;
1273 unsigned char prot_op;
1274 u8 *buf_cmd;
1275 u32 dw1 = 0, dw2 = 0, len = 0;
1276
1277 hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
1278 (2 << CMD_HDR_TLR_CTRL_OFF) |
1279 (port->id << CMD_HDR_PORT_OFF) |
1280 (priority << CMD_HDR_PRIORITY_OFF) |
1281 (1 << CMD_HDR_CMD_OFF)); /* ssp */
1282
1283 dw1 = 1 << CMD_HDR_VDTL_OFF;
1284 if (tmf) {
1285 dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF;
1286 dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF;
1287 } else {
1288 prot_op = scsi_get_prot_op(scsi_cmnd);
1289 dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF;
1290 switch (scsi_cmnd->sc_data_direction) {
1291 case DMA_TO_DEVICE:
1292 has_data = 1;
1293 dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
1294 break;
1295 case DMA_FROM_DEVICE:
1296 has_data = 1;
1297 dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
1298 break;
1299 default:
1300 dw1 &= ~CMD_HDR_DIR_MSK;
1301 }
1302 }
1303
1304 /* map itct entry */
1305 dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
1306
1307 dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr)
1308 + 3) / 4) << CMD_HDR_CFL_OFF) |
1309 ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) |
1310 (2 << CMD_HDR_SG_MOD_OFF);
1311 hdr->dw2 = cpu_to_le32(dw2);
1312 hdr->transfer_tags = cpu_to_le32(slot->idx);
1313
1314 if (has_data) {
1315 prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter,
1316 slot->n_elem);
1317
1318 if (scsi_prot_sg_count(scsi_cmnd))
1319 prep_prd_sge_dif_v3_hw(hisi_hba, slot, hdr,
1320 scsi_prot_sglist(scsi_cmnd),
1321 slot->n_elem_dif);
1322 }
1323
1324 hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
1325 hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
1326
1327 buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
1328 sizeof(struct ssp_frame_hdr);
1329
1330 memcpy(buf_cmd, &task->ssp_task.LUN, 8);
1331 if (!tmf) {
1332 buf_cmd[9] = ssp_task->task_attr;
1333 memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
1334 } else {
1335 buf_cmd[10] = tmf->tmf;
1336 switch (tmf->tmf) {
1337 case TMF_ABORT_TASK:
1338 case TMF_QUERY_TASK:
1339 buf_cmd[12] =
1340 (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
1341 buf_cmd[13] =
1342 tmf->tag_of_task_to_be_managed & 0xff;
1343 break;
1344 default:
1345 break;
1346 }
1347 }
1348
1349 if (has_data && (prot_op != SCSI_PROT_NORMAL)) {
1350 struct hisi_sas_protect_iu_v3_hw prot;
1351 u8 *buf_cmd_prot;
1352
1353 hdr->dw7 |= cpu_to_le32(1 << CMD_HDR_ADDR_MODE_SEL_OFF);
1354 dw1 |= CMD_HDR_PIR_MSK;
1355 buf_cmd_prot = hisi_sas_cmd_hdr_addr_mem(slot) +
1356 sizeof(struct ssp_frame_hdr) +
1357 sizeof(struct ssp_command_iu);
1358
1359 memset(&prot, 0, sizeof(struct hisi_sas_protect_iu_v3_hw));
1360 fill_prot_v3_hw(scsi_cmnd, &prot);
1361 memcpy(buf_cmd_prot, &prot,
1362 sizeof(struct hisi_sas_protect_iu_v3_hw));
1363 /*
1364 * For READ, we need length of info read to memory, while for
1365 * WRITE we need length of data written to the disk.
1366 */
1367 if (prot_op == SCSI_PROT_WRITE_INSERT ||
1368 prot_op == SCSI_PROT_READ_INSERT ||
1369 prot_op == SCSI_PROT_WRITE_PASS ||
1370 prot_op == SCSI_PROT_READ_PASS) {
1371 unsigned int interval = scsi_prot_interval(scsi_cmnd);
1372 unsigned int ilog2_interval = ilog2(interval);
1373
1374 len = (task->total_xfer_len >> ilog2_interval) * 8;
1375 }
1376 }
1377
1378 hdr->dw1 = cpu_to_le32(dw1);
1379
1380 hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len + len);
1381 }
1382
prep_smp_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot)1383 static void prep_smp_v3_hw(struct hisi_hba *hisi_hba,
1384 struct hisi_sas_slot *slot)
1385 {
1386 struct sas_task *task = slot->task;
1387 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1388 struct domain_device *device = task->dev;
1389 struct hisi_sas_port *port = slot->port;
1390 struct scatterlist *sg_req;
1391 struct hisi_sas_device *sas_dev = device->lldd_dev;
1392 dma_addr_t req_dma_addr;
1393 unsigned int req_len;
1394
1395 /* req */
1396 sg_req = &task->smp_task.smp_req;
1397 req_len = sg_dma_len(sg_req);
1398 req_dma_addr = sg_dma_address(sg_req);
1399
1400 /* create header */
1401 /* dw0 */
1402 hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
1403 (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
1404 (2 << CMD_HDR_CMD_OFF)); /* smp */
1405
1406 /* map itct entry */
1407 hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) |
1408 (1 << CMD_HDR_FRAME_TYPE_OFF) |
1409 (DIR_NO_DATA << CMD_HDR_DIR_OFF));
1410
1411 /* dw2 */
1412 hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) |
1413 (HISI_SAS_MAX_SMP_RESP_SZ / 4 <<
1414 CMD_HDR_MRFL_OFF));
1415
1416 hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
1417
1418 hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
1419 hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
1420 }
1421
prep_ata_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot)1422 static void prep_ata_v3_hw(struct hisi_hba *hisi_hba,
1423 struct hisi_sas_slot *slot)
1424 {
1425 struct sas_task *task = slot->task;
1426 struct domain_device *device = task->dev;
1427 struct domain_device *parent_dev = device->parent;
1428 struct hisi_sas_device *sas_dev = device->lldd_dev;
1429 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1430 struct asd_sas_port *sas_port = device->port;
1431 struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
1432 int phy_id;
1433 u8 *buf_cmd;
1434 int has_data = 0, hdr_tag = 0;
1435 u32 dw1 = 0, dw2 = 0;
1436
1437 hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF);
1438 if (parent_dev && dev_is_expander(parent_dev->dev_type)) {
1439 hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF);
1440 } else {
1441 phy_id = device->phy->identify.phy_identifier;
1442 hdr->dw0 |= cpu_to_le32((1U << phy_id)
1443 << CMD_HDR_PHY_ID_OFF);
1444 hdr->dw0 |= CMD_HDR_FORCE_PHY_MSK;
1445 hdr->dw0 |= cpu_to_le32(4U << CMD_HDR_CMD_OFF);
1446 }
1447
1448 switch (task->data_dir) {
1449 case DMA_TO_DEVICE:
1450 has_data = 1;
1451 dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
1452 break;
1453 case DMA_FROM_DEVICE:
1454 has_data = 1;
1455 dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
1456 break;
1457 default:
1458 dw1 &= ~CMD_HDR_DIR_MSK;
1459 }
1460
1461 if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) &&
1462 (task->ata_task.fis.control & ATA_SRST))
1463 dw1 |= 1 << CMD_HDR_RESET_OFF;
1464
1465 dw1 |= (hisi_sas_get_ata_protocol(
1466 &task->ata_task.fis, task->data_dir))
1467 << CMD_HDR_FRAME_TYPE_OFF;
1468 dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
1469
1470 if (FIS_CMD_IS_UNCONSTRAINED(task->ata_task.fis))
1471 dw1 |= 1 << CMD_HDR_UNCON_CMD_OFF;
1472
1473 hdr->dw1 = cpu_to_le32(dw1);
1474
1475 /* dw2 */
1476 if (task->ata_task.use_ncq) {
1477 struct ata_queued_cmd *qc = task->uldd_task;
1478
1479 hdr_tag = qc->tag;
1480 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
1481 dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF;
1482 }
1483
1484 dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF |
1485 2 << CMD_HDR_SG_MOD_OFF;
1486 hdr->dw2 = cpu_to_le32(dw2);
1487
1488 /* dw3 */
1489 hdr->transfer_tags = cpu_to_le32(slot->idx);
1490
1491 if (has_data)
1492 prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter,
1493 slot->n_elem);
1494
1495 hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
1496 hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
1497 hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
1498
1499 buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot);
1500
1501 if (likely(!task->ata_task.device_control_reg_update))
1502 task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */
1503 /* fill in command FIS */
1504 memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
1505 }
1506
prep_abort_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot)1507 static void prep_abort_v3_hw(struct hisi_hba *hisi_hba,
1508 struct hisi_sas_slot *slot)
1509 {
1510 struct sas_task *task = slot->task;
1511 struct sas_internal_abort_task *abort = &task->abort_task;
1512 struct domain_device *dev = task->dev;
1513 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1514 struct hisi_sas_port *port = slot->port;
1515 struct hisi_sas_device *sas_dev = dev->lldd_dev;
1516 bool sata = dev_is_sata(dev);
1517
1518 /* dw0 */
1519 hdr->dw0 = cpu_to_le32((5U << CMD_HDR_CMD_OFF) | /* abort */
1520 (port->id << CMD_HDR_PORT_OFF) |
1521 (sata << CMD_HDR_ABORT_DEVICE_TYPE_OFF) |
1522 (abort->type << CMD_HDR_ABORT_FLAG_OFF));
1523
1524 /* dw1 */
1525 hdr->dw1 = cpu_to_le32(sas_dev->device_id
1526 << CMD_HDR_DEV_ID_OFF);
1527
1528 /* dw7 */
1529 hdr->dw7 = cpu_to_le32(abort->tag << CMD_HDR_ABORT_IPTT_OFF);
1530 hdr->transfer_tags = cpu_to_le32(slot->idx);
1531 }
1532
phy_up_v3_hw(int phy_no,struct hisi_hba * hisi_hba)1533 static irqreturn_t phy_up_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
1534 {
1535 int i;
1536 irqreturn_t res;
1537 u32 context, port_id, link_rate;
1538 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1539 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1540 struct device *dev = hisi_hba->dev;
1541
1542 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1);
1543
1544 port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
1545 port_id = (port_id >> (4 * phy_no)) & 0xf;
1546 link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
1547 link_rate = (link_rate >> (phy_no * 4)) & 0xf;
1548
1549 if (port_id == 0xf) {
1550 dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
1551 res = IRQ_NONE;
1552 goto end;
1553 }
1554 sas_phy->linkrate = link_rate;
1555 phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
1556
1557 /* Check for SATA dev */
1558 context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
1559 if (context & (1 << phy_no)) {
1560 struct hisi_sas_initial_fis *initial_fis;
1561 struct dev_to_host_fis *fis;
1562 u8 attached_sas_addr[SAS_ADDR_SIZE] = {0};
1563 struct Scsi_Host *shost = hisi_hba->shost;
1564
1565 dev_info(dev, "phyup: phy%d link_rate=%d(sata)\n", phy_no, link_rate);
1566 initial_fis = &hisi_hba->initial_fis[phy_no];
1567 fis = &initial_fis->fis;
1568
1569 /* check ERR bit of Status Register */
1570 if (fis->status & ATA_ERR) {
1571 dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n",
1572 phy_no, fis->status);
1573 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1574 res = IRQ_NONE;
1575 goto end;
1576 }
1577
1578 sas_phy->oob_mode = SATA_OOB_MODE;
1579 attached_sas_addr[0] = 0x50;
1580 attached_sas_addr[6] = shost->host_no;
1581 attached_sas_addr[7] = phy_no;
1582 memcpy(sas_phy->attached_sas_addr,
1583 attached_sas_addr,
1584 SAS_ADDR_SIZE);
1585 memcpy(sas_phy->frame_rcvd, fis,
1586 sizeof(struct dev_to_host_fis));
1587 phy->phy_type |= PORT_TYPE_SATA;
1588 phy->identify.device_type = SAS_SATA_DEV;
1589 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
1590 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
1591 } else {
1592 u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
1593 struct sas_identify_frame *id =
1594 (struct sas_identify_frame *)frame_rcvd;
1595
1596 dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate);
1597 for (i = 0; i < 6; i++) {
1598 u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
1599 RX_IDAF_DWORD0 + (i * 4));
1600 frame_rcvd[i] = __swab32(idaf);
1601 }
1602 sas_phy->oob_mode = SAS_OOB_MODE;
1603 memcpy(sas_phy->attached_sas_addr,
1604 &id->sas_addr,
1605 SAS_ADDR_SIZE);
1606 phy->phy_type |= PORT_TYPE_SAS;
1607 phy->identify.device_type = id->dev_type;
1608 phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
1609 if (phy->identify.device_type == SAS_END_DEVICE)
1610 phy->identify.target_port_protocols =
1611 SAS_PROTOCOL_SSP;
1612 else if (phy->identify.device_type != SAS_PHY_UNUSED)
1613 phy->identify.target_port_protocols =
1614 SAS_PROTOCOL_SMP;
1615 }
1616
1617 phy->port_id = port_id;
1618 spin_lock(&phy->lock);
1619 /* Delete timer and set phy_attached atomically */
1620 del_timer(&phy->timer);
1621 phy->phy_attached = 1;
1622 spin_unlock(&phy->lock);
1623
1624 /*
1625 * Call pm_runtime_get_noresume() which pairs with
1626 * hisi_sas_phyup_pm_work() -> pm_runtime_put_sync().
1627 * For failure call pm_runtime_put() as we are in a hardirq context.
1628 */
1629 pm_runtime_get_noresume(dev);
1630 res = hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP_PM);
1631 if (!res)
1632 pm_runtime_put(dev);
1633
1634 res = IRQ_HANDLED;
1635
1636 end:
1637 if (phy->reset_completion)
1638 complete(phy->reset_completion);
1639 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
1640 CHL_INT0_SL_PHY_ENABLE_MSK);
1641 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0);
1642
1643 return res;
1644 }
1645
phy_down_v3_hw(int phy_no,struct hisi_hba * hisi_hba)1646 static irqreturn_t phy_down_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
1647 {
1648 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1649 u32 phy_state, sl_ctrl, txid_auto;
1650 struct device *dev = hisi_hba->dev;
1651
1652 atomic_inc(&phy->down_cnt);
1653
1654 del_timer(&phy->timer);
1655 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1);
1656
1657 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
1658 dev_info(dev, "phydown: phy%d phy_state=0x%x\n", phy_no, phy_state);
1659 hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0,
1660 GFP_ATOMIC);
1661
1662 sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
1663 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL,
1664 sl_ctrl&(~SL_CTA_MSK));
1665
1666 txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
1667 hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
1668 txid_auto | CT3_MSK);
1669
1670 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK);
1671 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0);
1672
1673 return IRQ_HANDLED;
1674 }
1675
phy_bcast_v3_hw(int phy_no,struct hisi_hba * hisi_hba)1676 static irqreturn_t phy_bcast_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
1677 {
1678 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1679 u32 bcast_status;
1680
1681 hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1);
1682 bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS);
1683 if (bcast_status & RX_BCAST_CHG_MSK)
1684 hisi_sas_phy_bcast(phy);
1685 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
1686 CHL_INT0_SL_RX_BCST_ACK_MSK);
1687 hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0);
1688
1689 return IRQ_HANDLED;
1690 }
1691
int_phy_up_down_bcast_v3_hw(int irq_no,void * p)1692 static irqreturn_t int_phy_up_down_bcast_v3_hw(int irq_no, void *p)
1693 {
1694 struct hisi_hba *hisi_hba = p;
1695 u32 irq_msk;
1696 int phy_no = 0;
1697 irqreturn_t res = IRQ_NONE;
1698
1699 irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS)
1700 & 0x11111111;
1701 while (irq_msk) {
1702 if (irq_msk & 1) {
1703 u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no,
1704 CHL_INT0);
1705 u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
1706 int rdy = phy_state & (1 << phy_no);
1707
1708 if (rdy) {
1709 if (irq_value & CHL_INT0_SL_PHY_ENABLE_MSK)
1710 /* phy up */
1711 if (phy_up_v3_hw(phy_no, hisi_hba)
1712 == IRQ_HANDLED)
1713 res = IRQ_HANDLED;
1714 if (irq_value & CHL_INT0_SL_RX_BCST_ACK_MSK)
1715 /* phy bcast */
1716 if (phy_bcast_v3_hw(phy_no, hisi_hba)
1717 == IRQ_HANDLED)
1718 res = IRQ_HANDLED;
1719 } else {
1720 if (irq_value & CHL_INT0_NOT_RDY_MSK)
1721 /* phy down */
1722 if (phy_down_v3_hw(phy_no, hisi_hba)
1723 == IRQ_HANDLED)
1724 res = IRQ_HANDLED;
1725 }
1726 }
1727 irq_msk >>= 4;
1728 phy_no++;
1729 }
1730
1731 return res;
1732 }
1733
1734 static const struct hisi_sas_hw_error port_axi_error[] = {
1735 {
1736 .irq_msk = BIT(CHL_INT1_DMAC_TX_ECC_MB_ERR_OFF),
1737 .msg = "dmac_tx_ecc_bad_err",
1738 },
1739 {
1740 .irq_msk = BIT(CHL_INT1_DMAC_RX_ECC_MB_ERR_OFF),
1741 .msg = "dmac_rx_ecc_bad_err",
1742 },
1743 {
1744 .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF),
1745 .msg = "dma_tx_axi_wr_err",
1746 },
1747 {
1748 .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF),
1749 .msg = "dma_tx_axi_rd_err",
1750 },
1751 {
1752 .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF),
1753 .msg = "dma_rx_axi_wr_err",
1754 },
1755 {
1756 .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF),
1757 .msg = "dma_rx_axi_rd_err",
1758 },
1759 {
1760 .irq_msk = BIT(CHL_INT1_DMAC_TX_FIFO_ERR_OFF),
1761 .msg = "dma_tx_fifo_err",
1762 },
1763 {
1764 .irq_msk = BIT(CHL_INT1_DMAC_RX_FIFO_ERR_OFF),
1765 .msg = "dma_rx_fifo_err",
1766 },
1767 {
1768 .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_RUSER_ERR_OFF),
1769 .msg = "dma_tx_axi_ruser_err",
1770 },
1771 {
1772 .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_RUSER_ERR_OFF),
1773 .msg = "dma_rx_axi_ruser_err",
1774 },
1775 };
1776
handle_chl_int1_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1777 static void handle_chl_int1_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1778 {
1779 u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT1);
1780 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT1_MSK);
1781 struct device *dev = hisi_hba->dev;
1782 int i;
1783
1784 irq_value &= ~irq_msk;
1785 if (!irq_value) {
1786 dev_warn(dev, "phy%d channel int 1 received with status bits cleared\n",
1787 phy_no);
1788 return;
1789 }
1790
1791 for (i = 0; i < ARRAY_SIZE(port_axi_error); i++) {
1792 const struct hisi_sas_hw_error *error = &port_axi_error[i];
1793
1794 if (!(irq_value & error->irq_msk))
1795 continue;
1796
1797 dev_err(dev, "%s error (phy%d 0x%x) found!\n",
1798 error->msg, phy_no, irq_value);
1799 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
1800 }
1801
1802 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT1, irq_value);
1803 }
1804
phy_get_events_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1805 static void phy_get_events_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1806 {
1807 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1808 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1809 struct sas_phy *sphy = sas_phy->phy;
1810 unsigned long flags;
1811 u32 reg_value;
1812
1813 spin_lock_irqsave(&phy->lock, flags);
1814
1815 /* loss dword sync */
1816 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DWS_LOST);
1817 sphy->loss_of_dword_sync_count += reg_value;
1818
1819 /* phy reset problem */
1820 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_RESET_PROB);
1821 sphy->phy_reset_problem_count += reg_value;
1822
1823 /* invalid dword */
1824 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_INVLD_DW);
1825 sphy->invalid_dword_count += reg_value;
1826
1827 /* disparity err */
1828 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DISP_ERR);
1829 sphy->running_disparity_error_count += reg_value;
1830
1831 /* code violation error */
1832 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_CODE_ERR);
1833 phy->code_violation_err_count += reg_value;
1834
1835 spin_unlock_irqrestore(&phy->lock, flags);
1836 }
1837
handle_chl_int2_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1838 static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1839 {
1840 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2_MSK);
1841 u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
1842 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1843 struct pci_dev *pci_dev = hisi_hba->pci_dev;
1844 struct device *dev = hisi_hba->dev;
1845 static const u32 msk = BIT(CHL_INT2_RX_DISP_ERR_OFF) |
1846 BIT(CHL_INT2_RX_CODE_ERR_OFF) |
1847 BIT(CHL_INT2_RX_INVLD_DW_OFF);
1848
1849 irq_value &= ~irq_msk;
1850 if (!irq_value) {
1851 dev_warn(dev, "phy%d channel int 2 received with status bits cleared\n",
1852 phy_no);
1853 return;
1854 }
1855
1856 if (irq_value & BIT(CHL_INT2_SL_IDAF_TOUT_CONF_OFF)) {
1857 dev_warn(dev, "phy%d identify timeout\n", phy_no);
1858 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1859 }
1860
1861 if (irq_value & BIT(CHL_INT2_STP_LINK_TIMEOUT_OFF)) {
1862 u32 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no,
1863 STP_LINK_TIMEOUT_STATE);
1864
1865 dev_warn(dev, "phy%d stp link timeout (0x%x)\n",
1866 phy_no, reg_value);
1867 if (reg_value & BIT(4))
1868 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1869 }
1870
1871 if (pci_dev->revision > 0x20 && (irq_value & msk)) {
1872 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1873 struct sas_phy *sphy = sas_phy->phy;
1874
1875 phy_get_events_v3_hw(hisi_hba, phy_no);
1876
1877 if (irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF))
1878 dev_info(dev, "phy%d invalid dword cnt: %u\n", phy_no,
1879 sphy->invalid_dword_count);
1880
1881 if (irq_value & BIT(CHL_INT2_RX_CODE_ERR_OFF))
1882 dev_info(dev, "phy%d code violation cnt: %u\n", phy_no,
1883 phy->code_violation_err_count);
1884
1885 if (irq_value & BIT(CHL_INT2_RX_DISP_ERR_OFF))
1886 dev_info(dev, "phy%d disparity error cnt: %u\n", phy_no,
1887 sphy->running_disparity_error_count);
1888 }
1889
1890 if ((irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF)) &&
1891 (pci_dev->revision == 0x20)) {
1892 u32 reg_value;
1893 int rc;
1894
1895 rc = hisi_sas_read32_poll_timeout_atomic(
1896 HILINK_ERR_DFX, reg_value,
1897 !((reg_value >> 8) & BIT(phy_no)),
1898 1000, 10000);
1899 if (rc)
1900 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1901 }
1902
1903 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2, irq_value);
1904 }
1905
handle_chl_int0_v3_hw(struct hisi_hba * hisi_hba,int phy_no)1906 static void handle_chl_int0_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1907 {
1908 u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0);
1909
1910 if (irq_value0 & CHL_INT0_PHY_RDY_MSK)
1911 hisi_sas_phy_oob_ready(hisi_hba, phy_no);
1912
1913 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
1914 irq_value0 & (~CHL_INT0_SL_RX_BCST_ACK_MSK)
1915 & (~CHL_INT0_SL_PHY_ENABLE_MSK)
1916 & (~CHL_INT0_NOT_RDY_MSK));
1917 }
1918
int_chnl_int_v3_hw(int irq_no,void * p)1919 static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p)
1920 {
1921 struct hisi_hba *hisi_hba = p;
1922 u32 irq_msk;
1923 int phy_no = 0;
1924
1925 irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS)
1926 & CHNL_INT_STS_MSK;
1927
1928 while (irq_msk) {
1929 if (irq_msk & (CHNL_INT_STS_INT0_MSK << (phy_no * CHNL_WIDTH)))
1930 handle_chl_int0_v3_hw(hisi_hba, phy_no);
1931
1932 if (irq_msk & (CHNL_INT_STS_INT1_MSK << (phy_no * CHNL_WIDTH)))
1933 handle_chl_int1_v3_hw(hisi_hba, phy_no);
1934
1935 if (irq_msk & (CHNL_INT_STS_INT2_MSK << (phy_no * CHNL_WIDTH)))
1936 handle_chl_int2_v3_hw(hisi_hba, phy_no);
1937
1938 irq_msk &= ~(CHNL_INT_STS_PHY_MSK << (phy_no * CHNL_WIDTH));
1939 phy_no++;
1940 }
1941
1942 return IRQ_HANDLED;
1943 }
1944
1945 static const struct hisi_sas_hw_error multi_bit_ecc_errors[] = {
1946 {
1947 .irq_msk = BIT(SAS_ECC_INTR_DQE_ECC_MB_OFF),
1948 .msk = HGC_DQE_ECC_MB_ADDR_MSK,
1949 .shift = HGC_DQE_ECC_MB_ADDR_OFF,
1950 .msg = "hgc_dqe_eccbad_intr",
1951 .reg = HGC_DQE_ECC_ADDR,
1952 },
1953 {
1954 .irq_msk = BIT(SAS_ECC_INTR_IOST_ECC_MB_OFF),
1955 .msk = HGC_IOST_ECC_MB_ADDR_MSK,
1956 .shift = HGC_IOST_ECC_MB_ADDR_OFF,
1957 .msg = "hgc_iost_eccbad_intr",
1958 .reg = HGC_IOST_ECC_ADDR,
1959 },
1960 {
1961 .irq_msk = BIT(SAS_ECC_INTR_ITCT_ECC_MB_OFF),
1962 .msk = HGC_ITCT_ECC_MB_ADDR_MSK,
1963 .shift = HGC_ITCT_ECC_MB_ADDR_OFF,
1964 .msg = "hgc_itct_eccbad_intr",
1965 .reg = HGC_ITCT_ECC_ADDR,
1966 },
1967 {
1968 .irq_msk = BIT(SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF),
1969 .msk = HGC_LM_DFX_STATUS2_IOSTLIST_MSK,
1970 .shift = HGC_LM_DFX_STATUS2_IOSTLIST_OFF,
1971 .msg = "hgc_iostl_eccbad_intr",
1972 .reg = HGC_LM_DFX_STATUS2,
1973 },
1974 {
1975 .irq_msk = BIT(SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF),
1976 .msk = HGC_LM_DFX_STATUS2_ITCTLIST_MSK,
1977 .shift = HGC_LM_DFX_STATUS2_ITCTLIST_OFF,
1978 .msg = "hgc_itctl_eccbad_intr",
1979 .reg = HGC_LM_DFX_STATUS2,
1980 },
1981 {
1982 .irq_msk = BIT(SAS_ECC_INTR_CQE_ECC_MB_OFF),
1983 .msk = HGC_CQE_ECC_MB_ADDR_MSK,
1984 .shift = HGC_CQE_ECC_MB_ADDR_OFF,
1985 .msg = "hgc_cqe_eccbad_intr",
1986 .reg = HGC_CQE_ECC_ADDR,
1987 },
1988 {
1989 .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF),
1990 .msk = HGC_RXM_DFX_STATUS14_MEM0_MSK,
1991 .shift = HGC_RXM_DFX_STATUS14_MEM0_OFF,
1992 .msg = "rxm_mem0_eccbad_intr",
1993 .reg = HGC_RXM_DFX_STATUS14,
1994 },
1995 {
1996 .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF),
1997 .msk = HGC_RXM_DFX_STATUS14_MEM1_MSK,
1998 .shift = HGC_RXM_DFX_STATUS14_MEM1_OFF,
1999 .msg = "rxm_mem1_eccbad_intr",
2000 .reg = HGC_RXM_DFX_STATUS14,
2001 },
2002 {
2003 .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF),
2004 .msk = HGC_RXM_DFX_STATUS14_MEM2_MSK,
2005 .shift = HGC_RXM_DFX_STATUS14_MEM2_OFF,
2006 .msg = "rxm_mem2_eccbad_intr",
2007 .reg = HGC_RXM_DFX_STATUS14,
2008 },
2009 {
2010 .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF),
2011 .msk = HGC_RXM_DFX_STATUS15_MEM3_MSK,
2012 .shift = HGC_RXM_DFX_STATUS15_MEM3_OFF,
2013 .msg = "rxm_mem3_eccbad_intr",
2014 .reg = HGC_RXM_DFX_STATUS15,
2015 },
2016 {
2017 .irq_msk = BIT(SAS_ECC_INTR_OOO_RAM_ECC_MB_OFF),
2018 .msk = AM_ROB_ECC_ERR_ADDR_MSK,
2019 .shift = AM_ROB_ECC_ERR_ADDR_OFF,
2020 .msg = "ooo_ram_eccbad_intr",
2021 .reg = AM_ROB_ECC_ERR_ADDR,
2022 },
2023 };
2024
multi_bit_ecc_error_process_v3_hw(struct hisi_hba * hisi_hba,u32 irq_value)2025 static void multi_bit_ecc_error_process_v3_hw(struct hisi_hba *hisi_hba,
2026 u32 irq_value)
2027 {
2028 struct device *dev = hisi_hba->dev;
2029 const struct hisi_sas_hw_error *ecc_error;
2030 u32 val;
2031 int i;
2032
2033 for (i = 0; i < ARRAY_SIZE(multi_bit_ecc_errors); i++) {
2034 ecc_error = &multi_bit_ecc_errors[i];
2035 if (irq_value & ecc_error->irq_msk) {
2036 val = hisi_sas_read32(hisi_hba, ecc_error->reg);
2037 val &= ecc_error->msk;
2038 val >>= ecc_error->shift;
2039 dev_err(dev, "%s (0x%x) found: mem addr is 0x%08X\n",
2040 ecc_error->msg, irq_value, val);
2041 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2042 }
2043 }
2044 }
2045
fatal_ecc_int_v3_hw(struct hisi_hba * hisi_hba)2046 static void fatal_ecc_int_v3_hw(struct hisi_hba *hisi_hba)
2047 {
2048 u32 irq_value, irq_msk;
2049
2050 irq_msk = hisi_sas_read32(hisi_hba, SAS_ECC_INTR_MSK);
2051 hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff);
2052
2053 irq_value = hisi_sas_read32(hisi_hba, SAS_ECC_INTR);
2054 if (irq_value)
2055 multi_bit_ecc_error_process_v3_hw(hisi_hba, irq_value);
2056
2057 hisi_sas_write32(hisi_hba, SAS_ECC_INTR, irq_value);
2058 hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk);
2059 }
2060
2061 static const struct hisi_sas_hw_error axi_error[] = {
2062 { .msk = BIT(0), .msg = "IOST_AXI_W_ERR" },
2063 { .msk = BIT(1), .msg = "IOST_AXI_R_ERR" },
2064 { .msk = BIT(2), .msg = "ITCT_AXI_W_ERR" },
2065 { .msk = BIT(3), .msg = "ITCT_AXI_R_ERR" },
2066 { .msk = BIT(4), .msg = "SATA_AXI_W_ERR" },
2067 { .msk = BIT(5), .msg = "SATA_AXI_R_ERR" },
2068 { .msk = BIT(6), .msg = "DQE_AXI_R_ERR" },
2069 { .msk = BIT(7), .msg = "CQE_AXI_W_ERR" },
2070 {}
2071 };
2072
2073 static const struct hisi_sas_hw_error fifo_error[] = {
2074 { .msk = BIT(8), .msg = "CQE_WINFO_FIFO" },
2075 { .msk = BIT(9), .msg = "CQE_MSG_FIFIO" },
2076 { .msk = BIT(10), .msg = "GETDQE_FIFO" },
2077 { .msk = BIT(11), .msg = "CMDP_FIFO" },
2078 { .msk = BIT(12), .msg = "AWTCTRL_FIFO" },
2079 {}
2080 };
2081
2082 static const struct hisi_sas_hw_error fatal_axi_error[] = {
2083 {
2084 .irq_msk = BIT(ENT_INT_SRC3_WP_DEPTH_OFF),
2085 .msg = "write pointer and depth",
2086 },
2087 {
2088 .irq_msk = BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF),
2089 .msg = "iptt no match slot",
2090 },
2091 {
2092 .irq_msk = BIT(ENT_INT_SRC3_RP_DEPTH_OFF),
2093 .msg = "read pointer and depth",
2094 },
2095 {
2096 .irq_msk = BIT(ENT_INT_SRC3_AXI_OFF),
2097 .reg = HGC_AXI_FIFO_ERR_INFO,
2098 .sub = axi_error,
2099 },
2100 {
2101 .irq_msk = BIT(ENT_INT_SRC3_FIFO_OFF),
2102 .reg = HGC_AXI_FIFO_ERR_INFO,
2103 .sub = fifo_error,
2104 },
2105 {
2106 .irq_msk = BIT(ENT_INT_SRC3_LM_OFF),
2107 .msg = "LM add/fetch list",
2108 },
2109 {
2110 .irq_msk = BIT(ENT_INT_SRC3_ABT_OFF),
2111 .msg = "SAS_HGC_ABT fetch LM list",
2112 },
2113 {
2114 .irq_msk = BIT(ENT_INT_SRC3_DQE_POISON_OFF),
2115 .msg = "read dqe poison",
2116 },
2117 {
2118 .irq_msk = BIT(ENT_INT_SRC3_IOST_POISON_OFF),
2119 .msg = "read iost poison",
2120 },
2121 {
2122 .irq_msk = BIT(ENT_INT_SRC3_ITCT_POISON_OFF),
2123 .msg = "read itct poison",
2124 },
2125 {
2126 .irq_msk = BIT(ENT_INT_SRC3_ITCT_NCQ_POISON_OFF),
2127 .msg = "read itct ncq poison",
2128 },
2129
2130 };
2131
fatal_axi_int_v3_hw(int irq_no,void * p)2132 static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p)
2133 {
2134 u32 irq_value, irq_msk;
2135 struct hisi_hba *hisi_hba = p;
2136 struct device *dev = hisi_hba->dev;
2137 struct pci_dev *pdev = hisi_hba->pci_dev;
2138 int i;
2139
2140 irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
2141 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0x1df00);
2142
2143 irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
2144 irq_value &= ~irq_msk;
2145
2146 for (i = 0; i < ARRAY_SIZE(fatal_axi_error); i++) {
2147 const struct hisi_sas_hw_error *error = &fatal_axi_error[i];
2148
2149 if (!(irq_value & error->irq_msk))
2150 continue;
2151
2152 if (error->sub) {
2153 const struct hisi_sas_hw_error *sub = error->sub;
2154 u32 err_value = hisi_sas_read32(hisi_hba, error->reg);
2155
2156 for (; sub->msk || sub->msg; sub++) {
2157 if (!(err_value & sub->msk))
2158 continue;
2159
2160 dev_err(dev, "%s error (0x%x) found!\n",
2161 sub->msg, irq_value);
2162 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2163 }
2164 } else {
2165 dev_err(dev, "%s error (0x%x) found!\n",
2166 error->msg, irq_value);
2167 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2168 }
2169
2170 if (pdev->revision < 0x21) {
2171 u32 reg_val;
2172
2173 reg_val = hisi_sas_read32(hisi_hba,
2174 AXI_MASTER_CFG_BASE +
2175 AM_CTRL_GLOBAL);
2176 reg_val |= AM_CTRL_SHUTDOWN_REQ_MSK;
2177 hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
2178 AM_CTRL_GLOBAL, reg_val);
2179 }
2180 }
2181
2182 fatal_ecc_int_v3_hw(hisi_hba);
2183
2184 if (irq_value & BIT(ENT_INT_SRC3_ITC_INT_OFF)) {
2185 u32 reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR);
2186 u32 dev_id = reg_val & ITCT_DEV_MSK;
2187 struct hisi_sas_device *sas_dev =
2188 &hisi_hba->devices[dev_id];
2189
2190 hisi_sas_write32(hisi_hba, ITCT_CLR, 0);
2191 dev_dbg(dev, "clear ITCT ok\n");
2192 complete(sas_dev->completion);
2193 }
2194
2195 hisi_sas_write32(hisi_hba, ENT_INT_SRC3, irq_value & 0x1df00);
2196 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk);
2197
2198 return IRQ_HANDLED;
2199 }
2200
is_ncq_err_v3_hw(struct hisi_sas_complete_v3_hdr * complete_hdr)2201 static bool is_ncq_err_v3_hw(struct hisi_sas_complete_v3_hdr *complete_hdr)
2202 {
2203 u32 dw0, dw3;
2204
2205 dw0 = le32_to_cpu(complete_hdr->dw0);
2206 dw3 = le32_to_cpu(complete_hdr->dw3);
2207
2208 return (dw0 & ERR_PHASE_RESPONSE_FRAME_REV_STAGE_MSK) &&
2209 (dw3 & FIS_TYPE_SDB_MSK) &&
2210 (dw3 & FIS_ATA_STATUS_ERR_MSK);
2211 }
2212
2213 static bool
slot_err_v3_hw(struct hisi_hba * hisi_hba,struct sas_task * task,struct hisi_sas_slot * slot)2214 slot_err_v3_hw(struct hisi_hba *hisi_hba, struct sas_task *task,
2215 struct hisi_sas_slot *slot)
2216 {
2217 struct task_status_struct *ts = &task->task_status;
2218 struct hisi_sas_complete_v3_hdr *complete_queue =
2219 hisi_hba->complete_hdr[slot->cmplt_queue];
2220 struct hisi_sas_complete_v3_hdr *complete_hdr =
2221 &complete_queue[slot->cmplt_queue_slot];
2222 struct hisi_sas_err_record_v3 *record =
2223 hisi_sas_status_buf_addr_mem(slot);
2224 u32 dma_rx_err_type = le32_to_cpu(record->dma_rx_err_type);
2225 u32 trans_tx_fail_type = le32_to_cpu(record->trans_tx_fail_type);
2226 u16 sipc_rx_err_type = le16_to_cpu(record->sipc_rx_err_type);
2227 u32 dw3 = le32_to_cpu(complete_hdr->dw3);
2228 u32 dw0 = le32_to_cpu(complete_hdr->dw0);
2229
2230 switch (task->task_proto) {
2231 case SAS_PROTOCOL_SSP:
2232 if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) {
2233 /*
2234 * If returned response frame is incorrect because of data underflow,
2235 * but I/O information has been written to the host memory, we examine
2236 * response IU.
2237 */
2238 if (!(dw0 & CMPLT_HDR_RSPNS_GOOD_MSK) &&
2239 (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK))
2240 return false;
2241
2242 ts->residual = trans_tx_fail_type;
2243 ts->stat = SAS_DATA_UNDERRUN;
2244 } else if (dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) {
2245 ts->stat = SAS_QUEUE_FULL;
2246 slot->abort = 1;
2247 } else {
2248 ts->stat = SAS_OPEN_REJECT;
2249 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2250 }
2251 break;
2252 case SAS_PROTOCOL_SATA:
2253 case SAS_PROTOCOL_STP:
2254 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
2255 if ((dw0 & CMPLT_HDR_RSPNS_XFRD_MSK) &&
2256 (sipc_rx_err_type & RX_FIS_STATUS_ERR_MSK)) {
2257 if (task->ata_task.use_ncq) {
2258 struct domain_device *device = task->dev;
2259 struct hisi_sas_device *sas_dev = device->lldd_dev;
2260
2261 sas_dev->dev_status = HISI_SAS_DEV_NCQ_ERR;
2262 slot->abort = 1;
2263 } else {
2264 ts->stat = SAS_PROTO_RESPONSE;
2265 }
2266 } else if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) {
2267 ts->residual = trans_tx_fail_type;
2268 ts->stat = SAS_DATA_UNDERRUN;
2269 } else if ((dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) ||
2270 (dw3 & SATA_DISK_IN_ERROR_STATUS_MSK)) {
2271 ts->stat = SAS_PHY_DOWN;
2272 slot->abort = 1;
2273 } else {
2274 ts->stat = SAS_OPEN_REJECT;
2275 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2276 }
2277 if (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK)
2278 hisi_sas_sata_done(task, slot);
2279 break;
2280 case SAS_PROTOCOL_SMP:
2281 ts->stat = SAS_SAM_STAT_CHECK_CONDITION;
2282 break;
2283 default:
2284 break;
2285 }
2286 return true;
2287 }
2288
slot_complete_v3_hw(struct hisi_hba * hisi_hba,struct hisi_sas_slot * slot)2289 static void slot_complete_v3_hw(struct hisi_hba *hisi_hba,
2290 struct hisi_sas_slot *slot)
2291 {
2292 struct sas_task *task = slot->task;
2293 struct hisi_sas_device *sas_dev;
2294 struct device *dev = hisi_hba->dev;
2295 struct task_status_struct *ts;
2296 struct domain_device *device;
2297 struct sas_ha_struct *ha;
2298 struct hisi_sas_complete_v3_hdr *complete_queue =
2299 hisi_hba->complete_hdr[slot->cmplt_queue];
2300 struct hisi_sas_complete_v3_hdr *complete_hdr =
2301 &complete_queue[slot->cmplt_queue_slot];
2302 unsigned long flags;
2303 bool is_internal = slot->is_internal;
2304 u32 dw0, dw1, dw3;
2305
2306 if (unlikely(!task || !task->lldd_task || !task->dev))
2307 return;
2308
2309 ts = &task->task_status;
2310 device = task->dev;
2311 ha = device->port->ha;
2312 sas_dev = device->lldd_dev;
2313
2314 spin_lock_irqsave(&task->task_state_lock, flags);
2315 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2316 spin_unlock_irqrestore(&task->task_state_lock, flags);
2317
2318 memset(ts, 0, sizeof(*ts));
2319 ts->resp = SAS_TASK_COMPLETE;
2320
2321 if (unlikely(!sas_dev)) {
2322 dev_dbg(dev, "slot complete: port has not device\n");
2323 ts->stat = SAS_PHY_DOWN;
2324 goto out;
2325 }
2326
2327 dw0 = le32_to_cpu(complete_hdr->dw0);
2328 dw1 = le32_to_cpu(complete_hdr->dw1);
2329 dw3 = le32_to_cpu(complete_hdr->dw3);
2330
2331 /*
2332 * Use SAS+TMF status codes
2333 */
2334 switch ((dw0 & CMPLT_HDR_ABORT_STAT_MSK) >> CMPLT_HDR_ABORT_STAT_OFF) {
2335 case STAT_IO_ABORTED:
2336 /* this IO has been aborted by abort command */
2337 ts->stat = SAS_ABORTED_TASK;
2338 goto out;
2339 case STAT_IO_COMPLETE:
2340 /* internal abort command complete */
2341 ts->stat = TMF_RESP_FUNC_SUCC;
2342 goto out;
2343 case STAT_IO_NO_DEVICE:
2344 ts->stat = TMF_RESP_FUNC_COMPLETE;
2345 goto out;
2346 case STAT_IO_NOT_VALID:
2347 /*
2348 * abort single IO, the controller can't find the IO
2349 */
2350 ts->stat = TMF_RESP_FUNC_FAILED;
2351 goto out;
2352 default:
2353 break;
2354 }
2355
2356 /* check for erroneous completion */
2357 if ((dw0 & CMPLT_HDR_CMPLT_MSK) == 0x3) {
2358 u32 *error_info = hisi_sas_status_buf_addr_mem(slot);
2359
2360 if (slot_err_v3_hw(hisi_hba, task, slot)) {
2361 if (ts->stat != SAS_DATA_UNDERRUN)
2362 dev_info(dev, "erroneous completion iptt=%d task=%pK dev id=%d addr=%016llx CQ hdr: 0x%x 0x%x 0x%x 0x%x Error info: 0x%x 0x%x 0x%x 0x%x\n",
2363 slot->idx, task, sas_dev->device_id,
2364 SAS_ADDR(device->sas_addr),
2365 dw0, dw1, complete_hdr->act, dw3,
2366 error_info[0], error_info[1],
2367 error_info[2], error_info[3]);
2368 if (unlikely(slot->abort)) {
2369 if (dev_is_sata(device) && task->ata_task.use_ncq)
2370 sas_ata_device_link_abort(device, true);
2371 else
2372 sas_task_abort(task);
2373
2374 return;
2375 }
2376 goto out;
2377 }
2378 }
2379
2380 switch (task->task_proto) {
2381 case SAS_PROTOCOL_SSP: {
2382 struct ssp_response_iu *iu =
2383 hisi_sas_status_buf_addr_mem(slot) +
2384 sizeof(struct hisi_sas_err_record);
2385
2386 sas_ssp_task_response(dev, task, iu);
2387 break;
2388 }
2389 case SAS_PROTOCOL_SMP: {
2390 struct scatterlist *sg_resp = &task->smp_task.smp_resp;
2391 void *to = page_address(sg_page(sg_resp));
2392
2393 ts->stat = SAS_SAM_STAT_GOOD;
2394
2395 memcpy(to + sg_resp->offset,
2396 hisi_sas_status_buf_addr_mem(slot) +
2397 sizeof(struct hisi_sas_err_record),
2398 sg_resp->length);
2399 break;
2400 }
2401 case SAS_PROTOCOL_SATA:
2402 case SAS_PROTOCOL_STP:
2403 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
2404 ts->stat = SAS_SAM_STAT_GOOD;
2405 if (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK)
2406 hisi_sas_sata_done(task, slot);
2407 break;
2408 default:
2409 ts->stat = SAS_SAM_STAT_CHECK_CONDITION;
2410 break;
2411 }
2412
2413 if (!slot->port->port_attached) {
2414 dev_warn(dev, "slot complete: port %d has removed\n",
2415 slot->port->sas_port.id);
2416 ts->stat = SAS_PHY_DOWN;
2417 }
2418
2419 out:
2420 spin_lock_irqsave(&task->task_state_lock, flags);
2421 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
2422 spin_unlock_irqrestore(&task->task_state_lock, flags);
2423 dev_info(dev, "slot complete: task(%pK) aborted\n", task);
2424 return;
2425 }
2426 task->task_state_flags |= SAS_TASK_STATE_DONE;
2427 spin_unlock_irqrestore(&task->task_state_lock, flags);
2428 hisi_sas_slot_task_free(hisi_hba, task, slot, true);
2429
2430 if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) {
2431 spin_lock_irqsave(&device->done_lock, flags);
2432 if (test_bit(SAS_HA_FROZEN, &ha->state)) {
2433 spin_unlock_irqrestore(&device->done_lock, flags);
2434 dev_info(dev, "slot complete: task(%pK) ignored\n",
2435 task);
2436 return;
2437 }
2438 spin_unlock_irqrestore(&device->done_lock, flags);
2439 }
2440
2441 if (task->task_done)
2442 task->task_done(task);
2443 }
2444
complete_v3_hw(struct hisi_sas_cq * cq)2445 static int complete_v3_hw(struct hisi_sas_cq *cq)
2446 {
2447 struct hisi_sas_complete_v3_hdr *complete_queue;
2448 struct hisi_hba *hisi_hba = cq->hisi_hba;
2449 u32 rd_point, wr_point;
2450 int queue = cq->id;
2451 int completed;
2452
2453 rd_point = cq->rd_point;
2454 complete_queue = hisi_hba->complete_hdr[queue];
2455
2456 wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR +
2457 (0x14 * queue));
2458 completed = (wr_point + HISI_SAS_QUEUE_SLOTS - rd_point) % HISI_SAS_QUEUE_SLOTS;
2459
2460 while (rd_point != wr_point) {
2461 struct hisi_sas_complete_v3_hdr *complete_hdr;
2462 struct device *dev = hisi_hba->dev;
2463 struct hisi_sas_slot *slot;
2464 u32 dw0, dw1, dw3;
2465 int iptt;
2466
2467 complete_hdr = &complete_queue[rd_point];
2468 dw0 = le32_to_cpu(complete_hdr->dw0);
2469 dw1 = le32_to_cpu(complete_hdr->dw1);
2470 dw3 = le32_to_cpu(complete_hdr->dw3);
2471
2472 iptt = dw1 & CMPLT_HDR_IPTT_MSK;
2473 if (unlikely((dw0 & CMPLT_HDR_CMPLT_MSK) == 0x3) &&
2474 (dw3 & CMPLT_HDR_SATA_DISK_ERR_MSK)) {
2475 int device_id = (dw1 & CMPLT_HDR_DEV_ID_MSK) >>
2476 CMPLT_HDR_DEV_ID_OFF;
2477 struct hisi_sas_itct *itct =
2478 &hisi_hba->itct[device_id];
2479 struct hisi_sas_device *sas_dev =
2480 &hisi_hba->devices[device_id];
2481 struct domain_device *device = sas_dev->sas_device;
2482
2483 dev_err(dev, "erroneous completion disk err dev id=%d sas_addr=0x%llx CQ hdr: 0x%x 0x%x 0x%x 0x%x\n",
2484 device_id, itct->sas_addr, dw0, dw1,
2485 complete_hdr->act, dw3);
2486
2487 if (is_ncq_err_v3_hw(complete_hdr))
2488 sas_dev->dev_status = HISI_SAS_DEV_NCQ_ERR;
2489
2490 sas_ata_device_link_abort(device, true);
2491 } else if (likely(iptt < HISI_SAS_COMMAND_ENTRIES_V3_HW)) {
2492 slot = &hisi_hba->slot_info[iptt];
2493 slot->cmplt_queue_slot = rd_point;
2494 slot->cmplt_queue = queue;
2495 slot_complete_v3_hw(hisi_hba, slot);
2496 } else
2497 dev_err(dev, "IPTT %d is invalid, discard it.\n", iptt);
2498
2499 if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
2500 rd_point = 0;
2501 }
2502
2503 /* update rd_point */
2504 cq->rd_point = rd_point;
2505 hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
2506 cond_resched();
2507
2508 return completed;
2509 }
2510
queue_complete_v3_hw(struct Scsi_Host * shost,unsigned int queue)2511 static int queue_complete_v3_hw(struct Scsi_Host *shost, unsigned int queue)
2512 {
2513 struct hisi_hba *hisi_hba = shost_priv(shost);
2514 struct hisi_sas_cq *cq = &hisi_hba->cq[queue];
2515 int completed;
2516
2517 spin_lock(&cq->poll_lock);
2518 completed = complete_v3_hw(cq);
2519 spin_unlock(&cq->poll_lock);
2520
2521 return completed;
2522 }
2523
cq_thread_v3_hw(int irq_no,void * p)2524 static irqreturn_t cq_thread_v3_hw(int irq_no, void *p)
2525 {
2526 struct hisi_sas_cq *cq = p;
2527
2528 complete_v3_hw(cq);
2529
2530 return IRQ_HANDLED;
2531 }
2532
cq_interrupt_v3_hw(int irq_no,void * p)2533 static irqreturn_t cq_interrupt_v3_hw(int irq_no, void *p)
2534 {
2535 struct hisi_sas_cq *cq = p;
2536 struct hisi_hba *hisi_hba = cq->hisi_hba;
2537 int queue = cq->id;
2538
2539 hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
2540
2541 return IRQ_WAKE_THREAD;
2542 }
2543
hisi_sas_v3_free_vectors(void * data)2544 static void hisi_sas_v3_free_vectors(void *data)
2545 {
2546 struct pci_dev *pdev = data;
2547
2548 pci_free_irq_vectors(pdev);
2549 }
2550
interrupt_preinit_v3_hw(struct hisi_hba * hisi_hba)2551 static int interrupt_preinit_v3_hw(struct hisi_hba *hisi_hba)
2552 {
2553 /* Allocate all MSI vectors to avoid re-insertion issue */
2554 int max_msi = HISI_SAS_MSI_COUNT_V3_HW;
2555 int vectors, min_msi;
2556 struct Scsi_Host *shost = hisi_hba->shost;
2557 struct pci_dev *pdev = hisi_hba->pci_dev;
2558 struct irq_affinity desc = {
2559 .pre_vectors = BASE_VECTORS_V3_HW,
2560 };
2561
2562 min_msi = MIN_AFFINE_VECTORS_V3_HW;
2563 vectors = pci_alloc_irq_vectors_affinity(pdev,
2564 min_msi, max_msi,
2565 PCI_IRQ_MSI |
2566 PCI_IRQ_AFFINITY,
2567 &desc);
2568 if (vectors < 0)
2569 return -ENOENT;
2570
2571
2572 hisi_hba->cq_nvecs = vectors - BASE_VECTORS_V3_HW - hisi_hba->iopoll_q_cnt;
2573 shost->nr_hw_queues = hisi_hba->cq_nvecs + hisi_hba->iopoll_q_cnt;
2574
2575 return devm_add_action(&pdev->dev, hisi_sas_v3_free_vectors, pdev);
2576 }
2577
interrupt_init_v3_hw(struct hisi_hba * hisi_hba)2578 static int interrupt_init_v3_hw(struct hisi_hba *hisi_hba)
2579 {
2580 struct device *dev = hisi_hba->dev;
2581 struct pci_dev *pdev = hisi_hba->pci_dev;
2582 int rc, i;
2583
2584 rc = devm_request_irq(dev, pci_irq_vector(pdev, 1),
2585 int_phy_up_down_bcast_v3_hw, 0,
2586 DRV_NAME " phy", hisi_hba);
2587 if (rc) {
2588 dev_err(dev, "could not request phy interrupt, rc=%d\n", rc);
2589 return -ENOENT;
2590 }
2591
2592 rc = devm_request_irq(dev, pci_irq_vector(pdev, 2),
2593 int_chnl_int_v3_hw, 0,
2594 DRV_NAME " channel", hisi_hba);
2595 if (rc) {
2596 dev_err(dev, "could not request chnl interrupt, rc=%d\n", rc);
2597 return -ENOENT;
2598 }
2599
2600 rc = devm_request_irq(dev, pci_irq_vector(pdev, 11),
2601 fatal_axi_int_v3_hw, 0,
2602 DRV_NAME " fatal", hisi_hba);
2603 if (rc) {
2604 dev_err(dev, "could not request fatal interrupt, rc=%d\n", rc);
2605 return -ENOENT;
2606 }
2607
2608 if (hisi_sas_intr_conv)
2609 dev_info(dev, "Enable interrupt converge\n");
2610
2611 for (i = 0; i < hisi_hba->cq_nvecs; i++) {
2612 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2613 int nr = hisi_sas_intr_conv ? 16 : 16 + i;
2614 unsigned long irqflags = hisi_sas_intr_conv ? IRQF_SHARED :
2615 IRQF_ONESHOT;
2616
2617 cq->irq_no = pci_irq_vector(pdev, nr);
2618 rc = devm_request_threaded_irq(dev, cq->irq_no,
2619 cq_interrupt_v3_hw,
2620 cq_thread_v3_hw,
2621 irqflags,
2622 DRV_NAME " cq", cq);
2623 if (rc) {
2624 dev_err(dev, "could not request cq%d interrupt, rc=%d\n",
2625 i, rc);
2626 return -ENOENT;
2627 }
2628 cq->irq_mask = pci_irq_get_affinity(pdev, i + BASE_VECTORS_V3_HW);
2629 if (!cq->irq_mask) {
2630 dev_err(dev, "could not get cq%d irq affinity!\n", i);
2631 return -ENOENT;
2632 }
2633 }
2634
2635 return 0;
2636 }
2637
hisi_sas_v3_init(struct hisi_hba * hisi_hba)2638 static int hisi_sas_v3_init(struct hisi_hba *hisi_hba)
2639 {
2640 int rc;
2641
2642 rc = hw_init_v3_hw(hisi_hba);
2643 if (rc)
2644 return rc;
2645
2646 rc = interrupt_init_v3_hw(hisi_hba);
2647 if (rc)
2648 return rc;
2649
2650 return 0;
2651 }
2652
phy_set_linkrate_v3_hw(struct hisi_hba * hisi_hba,int phy_no,struct sas_phy_linkrates * r)2653 static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no,
2654 struct sas_phy_linkrates *r)
2655 {
2656 enum sas_linkrate max = r->maximum_linkrate;
2657 u32 prog_phy_link_rate = hisi_sas_phy_read32(hisi_hba, phy_no,
2658 PROG_PHY_LINK_RATE);
2659
2660 prog_phy_link_rate &= ~CFG_PROG_PHY_LINK_RATE_MSK;
2661 prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
2662 hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
2663 prog_phy_link_rate);
2664 }
2665
interrupt_disable_v3_hw(struct hisi_hba * hisi_hba)2666 static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba)
2667 {
2668 struct pci_dev *pdev = hisi_hba->pci_dev;
2669 int i;
2670
2671 synchronize_irq(pci_irq_vector(pdev, 1));
2672 synchronize_irq(pci_irq_vector(pdev, 2));
2673 synchronize_irq(pci_irq_vector(pdev, 11));
2674 for (i = 0; i < hisi_hba->queue_count; i++)
2675 hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1);
2676
2677 for (i = 0; i < hisi_hba->cq_nvecs; i++)
2678 synchronize_irq(pci_irq_vector(pdev, i + 16));
2679
2680 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff);
2681 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff);
2682 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff);
2683 hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff);
2684
2685 for (i = 0; i < hisi_hba->n_phy; i++) {
2686 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff);
2687 hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff);
2688 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x1);
2689 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x1);
2690 hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x1);
2691 }
2692 }
2693
get_phys_state_v3_hw(struct hisi_hba * hisi_hba)2694 static u32 get_phys_state_v3_hw(struct hisi_hba *hisi_hba)
2695 {
2696 return hisi_sas_read32(hisi_hba, PHY_STATE);
2697 }
2698
disable_host_v3_hw(struct hisi_hba * hisi_hba)2699 static int disable_host_v3_hw(struct hisi_hba *hisi_hba)
2700 {
2701 struct device *dev = hisi_hba->dev;
2702 u32 status, reg_val;
2703 int rc;
2704
2705 hisi_sas_sync_poll_cqs(hisi_hba);
2706 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0);
2707
2708 hisi_sas_stop_phys(hisi_hba);
2709
2710 mdelay(10);
2711
2712 reg_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE +
2713 AM_CTRL_GLOBAL);
2714 reg_val |= AM_CTRL_SHUTDOWN_REQ_MSK;
2715 hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
2716 AM_CTRL_GLOBAL, reg_val);
2717
2718 /* wait until bus idle */
2719 rc = hisi_sas_read32_poll_timeout(AXI_MASTER_CFG_BASE +
2720 AM_CURR_TRANS_RETURN, status,
2721 status == 0x3, 10, 100);
2722 if (rc) {
2723 dev_err(dev, "axi bus is not idle, rc=%d\n", rc);
2724 return rc;
2725 }
2726
2727 return 0;
2728 }
2729
soft_reset_v3_hw(struct hisi_hba * hisi_hba)2730 static int soft_reset_v3_hw(struct hisi_hba *hisi_hba)
2731 {
2732 struct device *dev = hisi_hba->dev;
2733 int rc;
2734
2735 interrupt_disable_v3_hw(hisi_hba);
2736 rc = disable_host_v3_hw(hisi_hba);
2737 if (rc) {
2738 dev_err(dev, "soft reset: disable host failed rc=%d\n", rc);
2739 return rc;
2740 }
2741
2742 hisi_sas_init_mem(hisi_hba);
2743
2744 return hw_init_v3_hw(hisi_hba);
2745 }
2746
write_gpio_v3_hw(struct hisi_hba * hisi_hba,u8 reg_type,u8 reg_index,u8 reg_count,u8 * write_data)2747 static int write_gpio_v3_hw(struct hisi_hba *hisi_hba, u8 reg_type,
2748 u8 reg_index, u8 reg_count, u8 *write_data)
2749 {
2750 struct device *dev = hisi_hba->dev;
2751 u32 *data = (u32 *)write_data;
2752 int i;
2753
2754 switch (reg_type) {
2755 case SAS_GPIO_REG_TX:
2756 if ((reg_index + reg_count) > ((hisi_hba->n_phy + 3) / 4)) {
2757 dev_err(dev, "write gpio: invalid reg range[%d, %d]\n",
2758 reg_index, reg_index + reg_count - 1);
2759 return -EINVAL;
2760 }
2761
2762 for (i = 0; i < reg_count; i++)
2763 hisi_sas_write32(hisi_hba,
2764 SAS_GPIO_TX_0_1 + (reg_index + i) * 4,
2765 data[i]);
2766 break;
2767 default:
2768 dev_err(dev, "write gpio: unsupported or bad reg type %d\n",
2769 reg_type);
2770 return -EINVAL;
2771 }
2772
2773 return 0;
2774 }
2775
wait_cmds_complete_timeout_v3_hw(struct hisi_hba * hisi_hba,int delay_ms,int timeout_ms)2776 static void wait_cmds_complete_timeout_v3_hw(struct hisi_hba *hisi_hba,
2777 int delay_ms, int timeout_ms)
2778 {
2779 struct device *dev = hisi_hba->dev;
2780 int entries, entries_old = 0, time;
2781
2782 for (time = 0; time < timeout_ms; time += delay_ms) {
2783 entries = hisi_sas_read32(hisi_hba, CQE_SEND_CNT);
2784 if (entries == entries_old)
2785 break;
2786
2787 entries_old = entries;
2788 msleep(delay_ms);
2789 }
2790
2791 if (time >= timeout_ms) {
2792 dev_dbg(dev, "Wait commands complete timeout!\n");
2793 return;
2794 }
2795
2796 dev_dbg(dev, "wait commands complete %dms\n", time);
2797 }
2798
intr_conv_v3_hw_show(struct device * dev,struct device_attribute * attr,char * buf)2799 static ssize_t intr_conv_v3_hw_show(struct device *dev,
2800 struct device_attribute *attr, char *buf)
2801 {
2802 return scnprintf(buf, PAGE_SIZE, "%u\n", hisi_sas_intr_conv);
2803 }
2804 static DEVICE_ATTR_RO(intr_conv_v3_hw);
2805
config_intr_coal_v3_hw(struct hisi_hba * hisi_hba)2806 static void config_intr_coal_v3_hw(struct hisi_hba *hisi_hba)
2807 {
2808 /* config those registers between enable and disable PHYs */
2809 hisi_sas_stop_phys(hisi_hba);
2810
2811 if (hisi_hba->intr_coal_ticks == 0 ||
2812 hisi_hba->intr_coal_count == 0) {
2813 hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1);
2814 hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1);
2815 hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1);
2816 } else {
2817 hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x3);
2818 hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME,
2819 hisi_hba->intr_coal_ticks);
2820 hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT,
2821 hisi_hba->intr_coal_count);
2822 }
2823 phys_init_v3_hw(hisi_hba);
2824 }
2825
intr_coal_ticks_v3_hw_show(struct device * dev,struct device_attribute * attr,char * buf)2826 static ssize_t intr_coal_ticks_v3_hw_show(struct device *dev,
2827 struct device_attribute *attr,
2828 char *buf)
2829 {
2830 struct Scsi_Host *shost = class_to_shost(dev);
2831 struct hisi_hba *hisi_hba = shost_priv(shost);
2832
2833 return scnprintf(buf, PAGE_SIZE, "%u\n",
2834 hisi_hba->intr_coal_ticks);
2835 }
2836
intr_coal_ticks_v3_hw_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)2837 static ssize_t intr_coal_ticks_v3_hw_store(struct device *dev,
2838 struct device_attribute *attr,
2839 const char *buf, size_t count)
2840 {
2841 struct Scsi_Host *shost = class_to_shost(dev);
2842 struct hisi_hba *hisi_hba = shost_priv(shost);
2843 u32 intr_coal_ticks;
2844 int ret;
2845
2846 ret = kstrtou32(buf, 10, &intr_coal_ticks);
2847 if (ret) {
2848 dev_err(dev, "Input data of interrupt coalesce unmatch\n");
2849 return -EINVAL;
2850 }
2851
2852 if (intr_coal_ticks >= BIT(24)) {
2853 dev_err(dev, "intr_coal_ticks must be less than 2^24!\n");
2854 return -EINVAL;
2855 }
2856
2857 hisi_hba->intr_coal_ticks = intr_coal_ticks;
2858
2859 config_intr_coal_v3_hw(hisi_hba);
2860
2861 return count;
2862 }
2863 static DEVICE_ATTR_RW(intr_coal_ticks_v3_hw);
2864
intr_coal_count_v3_hw_show(struct device * dev,struct device_attribute * attr,char * buf)2865 static ssize_t intr_coal_count_v3_hw_show(struct device *dev,
2866 struct device_attribute
2867 *attr, char *buf)
2868 {
2869 struct Scsi_Host *shost = class_to_shost(dev);
2870 struct hisi_hba *hisi_hba = shost_priv(shost);
2871
2872 return scnprintf(buf, PAGE_SIZE, "%u\n",
2873 hisi_hba->intr_coal_count);
2874 }
2875
intr_coal_count_v3_hw_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)2876 static ssize_t intr_coal_count_v3_hw_store(struct device *dev,
2877 struct device_attribute
2878 *attr, const char *buf, size_t count)
2879 {
2880 struct Scsi_Host *shost = class_to_shost(dev);
2881 struct hisi_hba *hisi_hba = shost_priv(shost);
2882 u32 intr_coal_count;
2883 int ret;
2884
2885 ret = kstrtou32(buf, 10, &intr_coal_count);
2886 if (ret) {
2887 dev_err(dev, "Input data of interrupt coalesce unmatch\n");
2888 return -EINVAL;
2889 }
2890
2891 if (intr_coal_count >= BIT(8)) {
2892 dev_err(dev, "intr_coal_count must be less than 2^8!\n");
2893 return -EINVAL;
2894 }
2895
2896 hisi_hba->intr_coal_count = intr_coal_count;
2897
2898 config_intr_coal_v3_hw(hisi_hba);
2899
2900 return count;
2901 }
2902 static DEVICE_ATTR_RW(intr_coal_count_v3_hw);
2903
iopoll_q_cnt_v3_hw_show(struct device * dev,struct device_attribute * attr,char * buf)2904 static ssize_t iopoll_q_cnt_v3_hw_show(struct device *dev,
2905 struct device_attribute
2906 *attr, char *buf)
2907 {
2908 struct Scsi_Host *shost = class_to_shost(dev);
2909 struct hisi_hba *hisi_hba = shost_priv(shost);
2910
2911 return scnprintf(buf, PAGE_SIZE, "%u\n",
2912 hisi_hba->iopoll_q_cnt);
2913 }
2914 static DEVICE_ATTR_RO(iopoll_q_cnt_v3_hw);
2915
device_configure_v3_hw(struct scsi_device * sdev,struct queue_limits * lim)2916 static int device_configure_v3_hw(struct scsi_device *sdev,
2917 struct queue_limits *lim)
2918 {
2919 struct Scsi_Host *shost = dev_to_shost(&sdev->sdev_gendev);
2920 struct hisi_hba *hisi_hba = shost_priv(shost);
2921 int ret = hisi_sas_device_configure(sdev, lim);
2922 struct device *dev = hisi_hba->dev;
2923
2924 if (ret)
2925 return ret;
2926
2927 if (sdev->type == TYPE_ENCLOSURE)
2928 return 0;
2929
2930 if (!device_link_add(&sdev->sdev_gendev, dev,
2931 DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE)) {
2932 if (pm_runtime_enabled(dev)) {
2933 dev_info(dev, "add device link failed, disable runtime PM for the host\n");
2934 pm_runtime_disable(dev);
2935 }
2936 }
2937
2938 return 0;
2939 }
2940
2941 static struct attribute *host_v3_hw_attrs[] = {
2942 &dev_attr_phy_event_threshold.attr,
2943 &dev_attr_intr_conv_v3_hw.attr,
2944 &dev_attr_intr_coal_ticks_v3_hw.attr,
2945 &dev_attr_intr_coal_count_v3_hw.attr,
2946 &dev_attr_iopoll_q_cnt_v3_hw.attr,
2947 NULL
2948 };
2949
2950 ATTRIBUTE_GROUPS(host_v3_hw);
2951
2952 static const struct attribute_group *sdev_groups_v3_hw[] = {
2953 &sas_ata_sdev_attr_group,
2954 NULL
2955 };
2956
2957 #define HISI_SAS_DEBUGFS_REG(x) {#x, x}
2958
2959 struct hisi_sas_debugfs_reg_lu {
2960 char *name;
2961 int off;
2962 };
2963
2964 struct hisi_sas_debugfs_reg {
2965 const struct hisi_sas_debugfs_reg_lu *lu;
2966 int count;
2967 int base_off;
2968 };
2969
2970 static const struct hisi_sas_debugfs_reg_lu debugfs_port_reg_lu[] = {
2971 HISI_SAS_DEBUGFS_REG(PHY_CFG),
2972 HISI_SAS_DEBUGFS_REG(HARD_PHY_LINKRATE),
2973 HISI_SAS_DEBUGFS_REG(PROG_PHY_LINK_RATE),
2974 HISI_SAS_DEBUGFS_REG(PHY_CTRL),
2975 HISI_SAS_DEBUGFS_REG(SL_CFG),
2976 HISI_SAS_DEBUGFS_REG(AIP_LIMIT),
2977 HISI_SAS_DEBUGFS_REG(SL_CONTROL),
2978 HISI_SAS_DEBUGFS_REG(RX_PRIMS_STATUS),
2979 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD0),
2980 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD1),
2981 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD2),
2982 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD3),
2983 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD4),
2984 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD5),
2985 HISI_SAS_DEBUGFS_REG(TX_ID_DWORD6),
2986 HISI_SAS_DEBUGFS_REG(TXID_AUTO),
2987 HISI_SAS_DEBUGFS_REG(RX_IDAF_DWORD0),
2988 HISI_SAS_DEBUGFS_REG(RXOP_CHECK_CFG_H),
2989 HISI_SAS_DEBUGFS_REG(STP_LINK_TIMER),
2990 HISI_SAS_DEBUGFS_REG(STP_LINK_TIMEOUT_STATE),
2991 HISI_SAS_DEBUGFS_REG(CON_CFG_DRIVER),
2992 HISI_SAS_DEBUGFS_REG(SAS_SSP_CON_TIMER_CFG),
2993 HISI_SAS_DEBUGFS_REG(SAS_SMP_CON_TIMER_CFG),
2994 HISI_SAS_DEBUGFS_REG(SAS_STP_CON_TIMER_CFG),
2995 HISI_SAS_DEBUGFS_REG(CHL_INT0),
2996 HISI_SAS_DEBUGFS_REG(CHL_INT1),
2997 HISI_SAS_DEBUGFS_REG(CHL_INT2),
2998 HISI_SAS_DEBUGFS_REG(CHL_INT0_MSK),
2999 HISI_SAS_DEBUGFS_REG(CHL_INT1_MSK),
3000 HISI_SAS_DEBUGFS_REG(CHL_INT2_MSK),
3001 HISI_SAS_DEBUGFS_REG(SAS_EC_INT_COAL_TIME),
3002 HISI_SAS_DEBUGFS_REG(CHL_INT_COAL_EN),
3003 HISI_SAS_DEBUGFS_REG(SAS_RX_TRAIN_TIMER),
3004 HISI_SAS_DEBUGFS_REG(PHY_CTRL_RDY_MSK),
3005 HISI_SAS_DEBUGFS_REG(PHYCTRL_NOT_RDY_MSK),
3006 HISI_SAS_DEBUGFS_REG(PHYCTRL_DWS_RESET_MSK),
3007 HISI_SAS_DEBUGFS_REG(PHYCTRL_PHY_ENA_MSK),
3008 HISI_SAS_DEBUGFS_REG(SL_RX_BCAST_CHK_MSK),
3009 HISI_SAS_DEBUGFS_REG(PHYCTRL_OOB_RESTART_MSK),
3010 HISI_SAS_DEBUGFS_REG(DMA_TX_STATUS),
3011 HISI_SAS_DEBUGFS_REG(DMA_RX_STATUS),
3012 HISI_SAS_DEBUGFS_REG(COARSETUNE_TIME),
3013 HISI_SAS_DEBUGFS_REG(ERR_CNT_DWS_LOST),
3014 HISI_SAS_DEBUGFS_REG(ERR_CNT_RESET_PROB),
3015 HISI_SAS_DEBUGFS_REG(ERR_CNT_INVLD_DW),
3016 HISI_SAS_DEBUGFS_REG(ERR_CNT_CODE_ERR),
3017 HISI_SAS_DEBUGFS_REG(ERR_CNT_DISP_ERR),
3018 {}
3019 };
3020
3021 static const struct hisi_sas_debugfs_reg debugfs_port_reg = {
3022 .lu = debugfs_port_reg_lu,
3023 .count = 0x100,
3024 .base_off = PORT_BASE,
3025 };
3026
3027 static const struct hisi_sas_debugfs_reg_lu debugfs_global_reg_lu[] = {
3028 HISI_SAS_DEBUGFS_REG(DLVRY_QUEUE_ENABLE),
3029 HISI_SAS_DEBUGFS_REG(PHY_CONTEXT),
3030 HISI_SAS_DEBUGFS_REG(PHY_STATE),
3031 HISI_SAS_DEBUGFS_REG(PHY_PORT_NUM_MA),
3032 HISI_SAS_DEBUGFS_REG(PHY_CONN_RATE),
3033 HISI_SAS_DEBUGFS_REG(ITCT_CLR),
3034 HISI_SAS_DEBUGFS_REG(IO_SATA_BROKEN_MSG_ADDR_LO),
3035 HISI_SAS_DEBUGFS_REG(IO_SATA_BROKEN_MSG_ADDR_HI),
3036 HISI_SAS_DEBUGFS_REG(SATA_INITI_D2H_STORE_ADDR_LO),
3037 HISI_SAS_DEBUGFS_REG(SATA_INITI_D2H_STORE_ADDR_HI),
3038 HISI_SAS_DEBUGFS_REG(CFG_MAX_TAG),
3039 HISI_SAS_DEBUGFS_REG(TRANS_LOCK_ICT_TIME),
3040 HISI_SAS_DEBUGFS_REG(HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL),
3041 HISI_SAS_DEBUGFS_REG(HGC_SAS_TXFAIL_RETRY_CTRL),
3042 HISI_SAS_DEBUGFS_REG(HGC_GET_ITV_TIME),
3043 HISI_SAS_DEBUGFS_REG(DEVICE_MSG_WORK_MODE),
3044 HISI_SAS_DEBUGFS_REG(OPENA_WT_CONTI_TIME),
3045 HISI_SAS_DEBUGFS_REG(I_T_NEXUS_LOSS_TIME),
3046 HISI_SAS_DEBUGFS_REG(MAX_CON_TIME_LIMIT_TIME),
3047 HISI_SAS_DEBUGFS_REG(BUS_INACTIVE_LIMIT_TIME),
3048 HISI_SAS_DEBUGFS_REG(REJECT_TO_OPEN_LIMIT_TIME),
3049 HISI_SAS_DEBUGFS_REG(CQ_INT_CONVERGE_EN),
3050 HISI_SAS_DEBUGFS_REG(CFG_AGING_TIME),
3051 HISI_SAS_DEBUGFS_REG(HGC_DFX_CFG2),
3052 HISI_SAS_DEBUGFS_REG(CFG_ABT_SET_QUERY_IPTT),
3053 HISI_SAS_DEBUGFS_REG(CFG_ABT_SET_IPTT_DONE),
3054 HISI_SAS_DEBUGFS_REG(HGC_IOMB_PROC1_STATUS),
3055 HISI_SAS_DEBUGFS_REG(CHNL_INT_STATUS),
3056 HISI_SAS_DEBUGFS_REG(HGC_AXI_FIFO_ERR_INFO),
3057 HISI_SAS_DEBUGFS_REG(INT_COAL_EN),
3058 HISI_SAS_DEBUGFS_REG(OQ_INT_COAL_TIME),
3059 HISI_SAS_DEBUGFS_REG(OQ_INT_COAL_CNT),
3060 HISI_SAS_DEBUGFS_REG(ENT_INT_COAL_TIME),
3061 HISI_SAS_DEBUGFS_REG(ENT_INT_COAL_CNT),
3062 HISI_SAS_DEBUGFS_REG(OQ_INT_SRC),
3063 HISI_SAS_DEBUGFS_REG(OQ_INT_SRC_MSK),
3064 HISI_SAS_DEBUGFS_REG(ENT_INT_SRC1),
3065 HISI_SAS_DEBUGFS_REG(ENT_INT_SRC2),
3066 HISI_SAS_DEBUGFS_REG(ENT_INT_SRC3),
3067 HISI_SAS_DEBUGFS_REG(ENT_INT_SRC_MSK1),
3068 HISI_SAS_DEBUGFS_REG(ENT_INT_SRC_MSK2),
3069 HISI_SAS_DEBUGFS_REG(ENT_INT_SRC_MSK3),
3070 HISI_SAS_DEBUGFS_REG(CHNL_PHYUPDOWN_INT_MSK),
3071 HISI_SAS_DEBUGFS_REG(CHNL_ENT_INT_MSK),
3072 HISI_SAS_DEBUGFS_REG(HGC_COM_INT_MSK),
3073 HISI_SAS_DEBUGFS_REG(SAS_ECC_INTR),
3074 HISI_SAS_DEBUGFS_REG(SAS_ECC_INTR_MSK),
3075 HISI_SAS_DEBUGFS_REG(HGC_ERR_STAT_EN),
3076 HISI_SAS_DEBUGFS_REG(CQE_SEND_CNT),
3077 HISI_SAS_DEBUGFS_REG(DLVRY_Q_0_DEPTH),
3078 HISI_SAS_DEBUGFS_REG(DLVRY_Q_0_WR_PTR),
3079 HISI_SAS_DEBUGFS_REG(DLVRY_Q_0_RD_PTR),
3080 HISI_SAS_DEBUGFS_REG(HYPER_STREAM_ID_EN_CFG),
3081 HISI_SAS_DEBUGFS_REG(OQ0_INT_SRC_MSK),
3082 HISI_SAS_DEBUGFS_REG(COMPL_Q_0_DEPTH),
3083 HISI_SAS_DEBUGFS_REG(COMPL_Q_0_WR_PTR),
3084 HISI_SAS_DEBUGFS_REG(COMPL_Q_0_RD_PTR),
3085 HISI_SAS_DEBUGFS_REG(AWQOS_AWCACHE_CFG),
3086 HISI_SAS_DEBUGFS_REG(ARQOS_ARCACHE_CFG),
3087 HISI_SAS_DEBUGFS_REG(HILINK_ERR_DFX),
3088 HISI_SAS_DEBUGFS_REG(SAS_GPIO_CFG_0),
3089 HISI_SAS_DEBUGFS_REG(SAS_GPIO_CFG_1),
3090 HISI_SAS_DEBUGFS_REG(SAS_GPIO_TX_0_1),
3091 HISI_SAS_DEBUGFS_REG(SAS_CFG_DRIVE_VLD),
3092 {}
3093 };
3094
3095 static const struct hisi_sas_debugfs_reg debugfs_global_reg = {
3096 .lu = debugfs_global_reg_lu,
3097 .count = 0x800,
3098 };
3099
3100 static const struct hisi_sas_debugfs_reg_lu debugfs_axi_reg_lu[] = {
3101 HISI_SAS_DEBUGFS_REG(AM_CFG_MAX_TRANS),
3102 HISI_SAS_DEBUGFS_REG(AM_CFG_SINGLE_PORT_MAX_TRANS),
3103 HISI_SAS_DEBUGFS_REG(AXI_CFG),
3104 HISI_SAS_DEBUGFS_REG(AM_ROB_ECC_ERR_ADDR),
3105 {}
3106 };
3107
3108 static const struct hisi_sas_debugfs_reg debugfs_axi_reg = {
3109 .lu = debugfs_axi_reg_lu,
3110 .count = 0x61,
3111 .base_off = AXI_MASTER_CFG_BASE,
3112 };
3113
3114 static const struct hisi_sas_debugfs_reg_lu debugfs_ras_reg_lu[] = {
3115 HISI_SAS_DEBUGFS_REG(SAS_RAS_INTR0),
3116 HISI_SAS_DEBUGFS_REG(SAS_RAS_INTR1),
3117 HISI_SAS_DEBUGFS_REG(SAS_RAS_INTR0_MASK),
3118 HISI_SAS_DEBUGFS_REG(SAS_RAS_INTR1_MASK),
3119 HISI_SAS_DEBUGFS_REG(CFG_SAS_RAS_INTR_MASK),
3120 HISI_SAS_DEBUGFS_REG(SAS_RAS_INTR2),
3121 HISI_SAS_DEBUGFS_REG(SAS_RAS_INTR2_MASK),
3122 {}
3123 };
3124
3125 static const struct hisi_sas_debugfs_reg debugfs_ras_reg = {
3126 .lu = debugfs_ras_reg_lu,
3127 .count = 0x10,
3128 .base_off = RAS_BASE,
3129 };
3130
debugfs_snapshot_prepare_v3_hw(struct hisi_hba * hisi_hba)3131 static void debugfs_snapshot_prepare_v3_hw(struct hisi_hba *hisi_hba)
3132 {
3133 struct Scsi_Host *shost = hisi_hba->shost;
3134
3135 scsi_block_requests(shost);
3136 wait_cmds_complete_timeout_v3_hw(hisi_hba, 100, 5000);
3137
3138 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
3139 hisi_sas_sync_cqs(hisi_hba);
3140 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
3141 }
3142
debugfs_snapshot_restore_v3_hw(struct hisi_hba * hisi_hba)3143 static void debugfs_snapshot_restore_v3_hw(struct hisi_hba *hisi_hba)
3144 {
3145 struct Scsi_Host *shost = hisi_hba->shost;
3146
3147 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
3148 (u32)((1ULL << hisi_hba->queue_count) - 1));
3149
3150 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
3151 scsi_unblock_requests(shost);
3152 }
3153
read_iost_itct_cache_v3_hw(struct hisi_hba * hisi_hba,enum hisi_sas_debugfs_cache_type type,u32 * cache)3154 static void read_iost_itct_cache_v3_hw(struct hisi_hba *hisi_hba,
3155 enum hisi_sas_debugfs_cache_type type,
3156 u32 *cache)
3157 {
3158 u32 cache_dw_size = HISI_SAS_IOST_ITCT_CACHE_DW_SZ *
3159 HISI_SAS_IOST_ITCT_CACHE_NUM;
3160 struct device *dev = hisi_hba->dev;
3161 u32 *buf = cache;
3162 u32 i, val;
3163
3164 hisi_sas_write32(hisi_hba, TAB_RD_TYPE, type);
3165
3166 for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_DW_SZ; i++) {
3167 val = hisi_sas_read32(hisi_hba, TAB_DFX);
3168 if (val == 0xffffffff)
3169 break;
3170 }
3171
3172 if (val != 0xffffffff) {
3173 dev_err(dev, "Issue occurred in reading IOST/ITCT cache!\n");
3174 return;
3175 }
3176
3177 memset(buf, 0, cache_dw_size * 4);
3178 buf[0] = val;
3179
3180 for (i = 1; i < cache_dw_size; i++)
3181 buf[i] = hisi_sas_read32(hisi_hba, TAB_DFX);
3182 }
3183
hisi_sas_bist_test_prep_v3_hw(struct hisi_hba * hisi_hba)3184 static void hisi_sas_bist_test_prep_v3_hw(struct hisi_hba *hisi_hba)
3185 {
3186 u32 reg_val;
3187 int phy_no = hisi_hba->debugfs_bist_phy_no;
3188 int i;
3189
3190 /* disable PHY */
3191 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
3192
3193 /* update FFE */
3194 for (i = 0; i < FFE_CFG_MAX; i++)
3195 hisi_sas_phy_write32(hisi_hba, phy_no, TXDEEMPH_G1 + (i * 0x4),
3196 hisi_hba->debugfs_bist_ffe[phy_no][i]);
3197
3198 /* disable ALOS */
3199 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SERDES_CFG);
3200 reg_val |= CFG_ALOS_CHK_DISABLE_MSK;
3201 hisi_sas_phy_write32(hisi_hba, phy_no, SERDES_CFG, reg_val);
3202 }
3203
hisi_sas_bist_test_restore_v3_hw(struct hisi_hba * hisi_hba)3204 static void hisi_sas_bist_test_restore_v3_hw(struct hisi_hba *hisi_hba)
3205 {
3206 u32 reg_val;
3207 int phy_no = hisi_hba->debugfs_bist_phy_no;
3208
3209 /* disable loopback */
3210 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_PHY_BIST_CTRL);
3211 reg_val &= ~(CFG_RX_BIST_EN_MSK | CFG_TX_BIST_EN_MSK |
3212 CFG_BIST_TEST_MSK);
3213 hisi_sas_phy_write32(hisi_hba, phy_no, SAS_PHY_BIST_CTRL, reg_val);
3214
3215 /* enable ALOS */
3216 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SERDES_CFG);
3217 reg_val &= ~CFG_ALOS_CHK_DISABLE_MSK;
3218 hisi_sas_phy_write32(hisi_hba, phy_no, SERDES_CFG, reg_val);
3219
3220 /* restore the linkrate */
3221 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE);
3222 /* init OOB link rate as 1.5 Gbits */
3223 reg_val &= ~CFG_PROG_OOB_PHY_LINK_RATE_MSK;
3224 reg_val |= (0x8 << CFG_PROG_OOB_PHY_LINK_RATE_OFF);
3225 hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, reg_val);
3226
3227 /* enable PHY */
3228 hisi_sas_phy_enable(hisi_hba, phy_no, 1);
3229 }
3230
3231 #define SAS_PHY_BIST_CODE_INIT 0x1
3232 #define SAS_PHY_BIST_CODE1_INIT 0X80
debugfs_set_bist_v3_hw(struct hisi_hba * hisi_hba,bool enable)3233 static int debugfs_set_bist_v3_hw(struct hisi_hba *hisi_hba, bool enable)
3234 {
3235 u32 reg_val, mode_tmp;
3236 u32 linkrate = hisi_hba->debugfs_bist_linkrate;
3237 u32 phy_no = hisi_hba->debugfs_bist_phy_no;
3238 u32 *ffe = hisi_hba->debugfs_bist_ffe[phy_no];
3239 u32 code_mode = hisi_hba->debugfs_bist_code_mode;
3240 u32 path_mode = hisi_hba->debugfs_bist_mode;
3241 u32 *fix_code = &hisi_hba->debugfs_bist_fixed_code[0];
3242 struct device *dev = hisi_hba->dev;
3243
3244 dev_info(dev, "BIST info:phy%d link_rate=%d code_mode=%d path_mode=%d ffe={0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x} fixed_code={0x%x, 0x%x}\n",
3245 phy_no, linkrate, code_mode, path_mode,
3246 ffe[FFE_SAS_1_5_GBPS], ffe[FFE_SAS_3_0_GBPS],
3247 ffe[FFE_SAS_6_0_GBPS], ffe[FFE_SAS_12_0_GBPS],
3248 ffe[FFE_SATA_1_5_GBPS], ffe[FFE_SATA_3_0_GBPS],
3249 ffe[FFE_SATA_6_0_GBPS], fix_code[FIXED_CODE],
3250 fix_code[FIXED_CODE_1]);
3251 mode_tmp = path_mode ? 2 : 1;
3252 if (enable) {
3253 /* some preparations before bist test */
3254 hisi_sas_bist_test_prep_v3_hw(hisi_hba);
3255
3256 /* set linkrate of bit test*/
3257 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no,
3258 PROG_PHY_LINK_RATE);
3259 reg_val &= ~CFG_PROG_OOB_PHY_LINK_RATE_MSK;
3260 reg_val |= (linkrate << CFG_PROG_OOB_PHY_LINK_RATE_OFF);
3261 hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
3262 reg_val);
3263
3264 /* set code mode of bit test */
3265 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no,
3266 SAS_PHY_BIST_CTRL);
3267 reg_val &= ~(CFG_BIST_MODE_SEL_MSK | CFG_LOOP_TEST_MODE_MSK |
3268 CFG_RX_BIST_EN_MSK | CFG_TX_BIST_EN_MSK |
3269 CFG_BIST_TEST_MSK);
3270 reg_val |= ((code_mode << CFG_BIST_MODE_SEL_OFF) |
3271 (mode_tmp << CFG_LOOP_TEST_MODE_OFF) |
3272 CFG_BIST_TEST_MSK);
3273 hisi_sas_phy_write32(hisi_hba, phy_no, SAS_PHY_BIST_CTRL,
3274 reg_val);
3275
3276 /* set the bist init value */
3277 if (code_mode == HISI_SAS_BIST_CODE_MODE_FIXED_DATA) {
3278 reg_val = hisi_hba->debugfs_bist_fixed_code[0];
3279 hisi_sas_phy_write32(hisi_hba, phy_no,
3280 SAS_PHY_BIST_CODE, reg_val);
3281
3282 reg_val = hisi_hba->debugfs_bist_fixed_code[1];
3283 hisi_sas_phy_write32(hisi_hba, phy_no,
3284 SAS_PHY_BIST_CODE1, reg_val);
3285 } else {
3286 hisi_sas_phy_write32(hisi_hba, phy_no,
3287 SAS_PHY_BIST_CODE,
3288 SAS_PHY_BIST_CODE_INIT);
3289 hisi_sas_phy_write32(hisi_hba, phy_no,
3290 SAS_PHY_BIST_CODE1,
3291 SAS_PHY_BIST_CODE1_INIT);
3292 }
3293
3294 mdelay(100);
3295 reg_val |= (CFG_RX_BIST_EN_MSK | CFG_TX_BIST_EN_MSK);
3296 hisi_sas_phy_write32(hisi_hba, phy_no, SAS_PHY_BIST_CTRL,
3297 reg_val);
3298
3299 /* clear error bit */
3300 mdelay(100);
3301 hisi_sas_phy_read32(hisi_hba, phy_no, SAS_BIST_ERR_CNT);
3302 } else {
3303 /* disable bist test and recover it */
3304 hisi_hba->debugfs_bist_cnt += hisi_sas_phy_read32(hisi_hba,
3305 phy_no, SAS_BIST_ERR_CNT);
3306 hisi_sas_bist_test_restore_v3_hw(hisi_hba);
3307 }
3308
3309 return 0;
3310 }
3311
hisi_sas_map_queues(struct Scsi_Host * shost)3312 static void hisi_sas_map_queues(struct Scsi_Host *shost)
3313 {
3314 struct hisi_hba *hisi_hba = shost_priv(shost);
3315 struct blk_mq_queue_map *qmap;
3316 int i, qoff;
3317
3318 for (i = 0, qoff = 0; i < shost->nr_maps; i++) {
3319 qmap = &shost->tag_set.map[i];
3320 if (i == HCTX_TYPE_DEFAULT) {
3321 qmap->nr_queues = hisi_hba->cq_nvecs;
3322 } else if (i == HCTX_TYPE_POLL) {
3323 qmap->nr_queues = hisi_hba->iopoll_q_cnt;
3324 } else {
3325 qmap->nr_queues = 0;
3326 continue;
3327 }
3328
3329 /* At least one interrupt hardware queue */
3330 if (!qmap->nr_queues)
3331 WARN_ON(i == HCTX_TYPE_DEFAULT);
3332 qmap->queue_offset = qoff;
3333 if (i == HCTX_TYPE_POLL)
3334 blk_mq_map_queues(qmap);
3335 else
3336 blk_mq_pci_map_queues(qmap, hisi_hba->pci_dev,
3337 BASE_VECTORS_V3_HW);
3338 qoff += qmap->nr_queues;
3339 }
3340 }
3341
3342 static const struct scsi_host_template sht_v3_hw = {
3343 LIBSAS_SHT_BASE_NO_SLAVE_INIT
3344 .device_configure = device_configure_v3_hw,
3345 .scan_finished = hisi_sas_scan_finished,
3346 .scan_start = hisi_sas_scan_start,
3347 .map_queues = hisi_sas_map_queues,
3348 .sg_tablesize = HISI_SAS_SGE_PAGE_CNT,
3349 .sg_prot_tablesize = HISI_SAS_SGE_PAGE_CNT,
3350 .slave_alloc = hisi_sas_slave_alloc,
3351 .shost_groups = host_v3_hw_groups,
3352 .sdev_groups = sdev_groups_v3_hw,
3353 .tag_alloc_policy = BLK_TAG_ALLOC_RR,
3354 .host_reset = hisi_sas_host_reset,
3355 .host_tagset = 1,
3356 .mq_poll = queue_complete_v3_hw,
3357 };
3358
3359 static const struct hisi_sas_hw hisi_sas_v3_hw = {
3360 .setup_itct = setup_itct_v3_hw,
3361 .get_wideport_bitmap = get_wideport_bitmap_v3_hw,
3362 .complete_hdr_size = sizeof(struct hisi_sas_complete_v3_hdr),
3363 .clear_itct = clear_itct_v3_hw,
3364 .sl_notify_ssp = sl_notify_ssp_v3_hw,
3365 .prep_ssp = prep_ssp_v3_hw,
3366 .prep_smp = prep_smp_v3_hw,
3367 .prep_stp = prep_ata_v3_hw,
3368 .prep_abort = prep_abort_v3_hw,
3369 .start_delivery = start_delivery_v3_hw,
3370 .phys_init = phys_init_v3_hw,
3371 .phy_start = start_phy_v3_hw,
3372 .phy_disable = disable_phy_v3_hw,
3373 .phy_hard_reset = phy_hard_reset_v3_hw,
3374 .phy_get_max_linkrate = phy_get_max_linkrate_v3_hw,
3375 .phy_set_linkrate = phy_set_linkrate_v3_hw,
3376 .dereg_device = dereg_device_v3_hw,
3377 .soft_reset = soft_reset_v3_hw,
3378 .get_phys_state = get_phys_state_v3_hw,
3379 .get_events = phy_get_events_v3_hw,
3380 .write_gpio = write_gpio_v3_hw,
3381 .wait_cmds_complete_timeout = wait_cmds_complete_timeout_v3_hw,
3382 .debugfs_snapshot_regs = debugfs_snapshot_regs_v3_hw,
3383 };
3384
3385 static struct Scsi_Host *
hisi_sas_shost_alloc_pci(struct pci_dev * pdev)3386 hisi_sas_shost_alloc_pci(struct pci_dev *pdev)
3387 {
3388 struct Scsi_Host *shost;
3389 struct hisi_hba *hisi_hba;
3390 struct device *dev = &pdev->dev;
3391
3392 shost = scsi_host_alloc(&sht_v3_hw, sizeof(*hisi_hba));
3393 if (!shost) {
3394 dev_err(dev, "shost alloc failed\n");
3395 return NULL;
3396 }
3397 hisi_hba = shost_priv(shost);
3398
3399 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
3400 hisi_hba->hw = &hisi_sas_v3_hw;
3401 hisi_hba->pci_dev = pdev;
3402 hisi_hba->dev = dev;
3403 hisi_hba->shost = shost;
3404 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
3405
3406 if (prot_mask & ~HISI_SAS_PROT_MASK)
3407 dev_err(dev, "unsupported protection mask 0x%x, using default (0x0)\n",
3408 prot_mask);
3409 else
3410 hisi_hba->prot_mask = prot_mask;
3411
3412 if (hisi_sas_get_fw_info(hisi_hba) < 0)
3413 goto err_out;
3414
3415 if (experimental_iopoll_q_cnt < 0 ||
3416 experimental_iopoll_q_cnt >= hisi_hba->queue_count)
3417 dev_err(dev, "iopoll queue count %d cannot exceed or equal 16, using default 0\n",
3418 experimental_iopoll_q_cnt);
3419 else
3420 hisi_hba->iopoll_q_cnt = experimental_iopoll_q_cnt;
3421
3422 if (hisi_sas_alloc(hisi_hba)) {
3423 hisi_sas_free(hisi_hba);
3424 goto err_out;
3425 }
3426
3427 return shost;
3428 err_out:
3429 scsi_host_put(shost);
3430 dev_err(dev, "shost alloc failed\n");
3431 return NULL;
3432 }
3433
debugfs_snapshot_cq_reg_v3_hw(struct hisi_hba * hisi_hba)3434 static void debugfs_snapshot_cq_reg_v3_hw(struct hisi_hba *hisi_hba)
3435 {
3436 int queue_entry_size = hisi_hba->hw->complete_hdr_size;
3437 int dump_index = hisi_hba->debugfs_dump_index;
3438 int i;
3439
3440 for (i = 0; i < hisi_hba->queue_count; i++)
3441 memcpy(hisi_hba->debugfs_cq[dump_index][i].complete_hdr,
3442 hisi_hba->complete_hdr[i],
3443 HISI_SAS_QUEUE_SLOTS * queue_entry_size);
3444 }
3445
debugfs_snapshot_dq_reg_v3_hw(struct hisi_hba * hisi_hba)3446 static void debugfs_snapshot_dq_reg_v3_hw(struct hisi_hba *hisi_hba)
3447 {
3448 int queue_entry_size = sizeof(struct hisi_sas_cmd_hdr);
3449 int dump_index = hisi_hba->debugfs_dump_index;
3450 int i;
3451
3452 for (i = 0; i < hisi_hba->queue_count; i++) {
3453 struct hisi_sas_cmd_hdr *debugfs_cmd_hdr, *cmd_hdr;
3454 int j;
3455
3456 debugfs_cmd_hdr = hisi_hba->debugfs_dq[dump_index][i].hdr;
3457 cmd_hdr = hisi_hba->cmd_hdr[i];
3458
3459 for (j = 0; j < HISI_SAS_QUEUE_SLOTS; j++)
3460 memcpy(&debugfs_cmd_hdr[j], &cmd_hdr[j],
3461 queue_entry_size);
3462 }
3463 }
3464
debugfs_snapshot_port_reg_v3_hw(struct hisi_hba * hisi_hba)3465 static void debugfs_snapshot_port_reg_v3_hw(struct hisi_hba *hisi_hba)
3466 {
3467 int dump_index = hisi_hba->debugfs_dump_index;
3468 const struct hisi_sas_debugfs_reg *port = &debugfs_port_reg;
3469 int i, phy_cnt;
3470 u32 offset;
3471 u32 *databuf;
3472
3473 for (phy_cnt = 0; phy_cnt < hisi_hba->n_phy; phy_cnt++) {
3474 databuf = hisi_hba->debugfs_port_reg[dump_index][phy_cnt].data;
3475 for (i = 0; i < port->count; i++, databuf++) {
3476 offset = port->base_off + 4 * i;
3477 *databuf = hisi_sas_phy_read32(hisi_hba, phy_cnt,
3478 offset);
3479 }
3480 }
3481 }
3482
debugfs_snapshot_global_reg_v3_hw(struct hisi_hba * hisi_hba)3483 static void debugfs_snapshot_global_reg_v3_hw(struct hisi_hba *hisi_hba)
3484 {
3485 int dump_index = hisi_hba->debugfs_dump_index;
3486 u32 *databuf = hisi_hba->debugfs_regs[dump_index][DEBUGFS_GLOBAL].data;
3487 int i;
3488
3489 for (i = 0; i < debugfs_global_reg.count; i++, databuf++)
3490 *databuf = hisi_sas_read32(hisi_hba, 4 * i);
3491 }
3492
debugfs_snapshot_axi_reg_v3_hw(struct hisi_hba * hisi_hba)3493 static void debugfs_snapshot_axi_reg_v3_hw(struct hisi_hba *hisi_hba)
3494 {
3495 int dump_index = hisi_hba->debugfs_dump_index;
3496 u32 *databuf = hisi_hba->debugfs_regs[dump_index][DEBUGFS_AXI].data;
3497 const struct hisi_sas_debugfs_reg *axi = &debugfs_axi_reg;
3498 int i;
3499
3500 for (i = 0; i < axi->count; i++, databuf++)
3501 *databuf = hisi_sas_read32(hisi_hba, 4 * i + axi->base_off);
3502 }
3503
debugfs_snapshot_ras_reg_v3_hw(struct hisi_hba * hisi_hba)3504 static void debugfs_snapshot_ras_reg_v3_hw(struct hisi_hba *hisi_hba)
3505 {
3506 int dump_index = hisi_hba->debugfs_dump_index;
3507 u32 *databuf = hisi_hba->debugfs_regs[dump_index][DEBUGFS_RAS].data;
3508 const struct hisi_sas_debugfs_reg *ras = &debugfs_ras_reg;
3509 int i;
3510
3511 for (i = 0; i < ras->count; i++, databuf++)
3512 *databuf = hisi_sas_read32(hisi_hba, 4 * i + ras->base_off);
3513 }
3514
debugfs_snapshot_itct_reg_v3_hw(struct hisi_hba * hisi_hba)3515 static void debugfs_snapshot_itct_reg_v3_hw(struct hisi_hba *hisi_hba)
3516 {
3517 int dump_index = hisi_hba->debugfs_dump_index;
3518 void *cachebuf = hisi_hba->debugfs_itct_cache[dump_index].cache;
3519 void *databuf = hisi_hba->debugfs_itct[dump_index].itct;
3520 struct hisi_sas_itct *itct;
3521 int i;
3522
3523 read_iost_itct_cache_v3_hw(hisi_hba, HISI_SAS_ITCT_CACHE, cachebuf);
3524
3525 itct = hisi_hba->itct;
3526
3527 for (i = 0; i < HISI_SAS_MAX_ITCT_ENTRIES; i++, itct++) {
3528 memcpy(databuf, itct, sizeof(struct hisi_sas_itct));
3529 databuf += sizeof(struct hisi_sas_itct);
3530 }
3531 }
3532
debugfs_snapshot_iost_reg_v3_hw(struct hisi_hba * hisi_hba)3533 static void debugfs_snapshot_iost_reg_v3_hw(struct hisi_hba *hisi_hba)
3534 {
3535 int dump_index = hisi_hba->debugfs_dump_index;
3536 int max_command_entries = HISI_SAS_MAX_COMMANDS;
3537 void *cachebuf = hisi_hba->debugfs_iost_cache[dump_index].cache;
3538 void *databuf = hisi_hba->debugfs_iost[dump_index].iost;
3539 struct hisi_sas_iost *iost;
3540 int i;
3541
3542 read_iost_itct_cache_v3_hw(hisi_hba, HISI_SAS_IOST_CACHE, cachebuf);
3543
3544 iost = hisi_hba->iost;
3545
3546 for (i = 0; i < max_command_entries; i++, iost++) {
3547 memcpy(databuf, iost, sizeof(struct hisi_sas_iost));
3548 databuf += sizeof(struct hisi_sas_iost);
3549 }
3550 }
3551
3552 static const char *
debugfs_to_reg_name_v3_hw(int off,int base_off,const struct hisi_sas_debugfs_reg_lu * lu)3553 debugfs_to_reg_name_v3_hw(int off, int base_off,
3554 const struct hisi_sas_debugfs_reg_lu *lu)
3555 {
3556 for (; lu->name; lu++) {
3557 if (off == lu->off - base_off)
3558 return lu->name;
3559 }
3560
3561 return NULL;
3562 }
3563
debugfs_dump_is_generated_v3_hw(void * p)3564 static bool debugfs_dump_is_generated_v3_hw(void *p)
3565 {
3566 return p ? true : false;
3567 }
3568
debugfs_print_reg_v3_hw(u32 * regs_val,struct seq_file * s,const struct hisi_sas_debugfs_reg * reg)3569 static void debugfs_print_reg_v3_hw(u32 *regs_val, struct seq_file *s,
3570 const struct hisi_sas_debugfs_reg *reg)
3571 {
3572 int i;
3573
3574 for (i = 0; i < reg->count; i++) {
3575 int off = i * 4;
3576 const char *name;
3577
3578 name = debugfs_to_reg_name_v3_hw(off, reg->base_off,
3579 reg->lu);
3580
3581 if (name)
3582 seq_printf(s, "0x%08x 0x%08x %s\n", off,
3583 regs_val[i], name);
3584 else
3585 seq_printf(s, "0x%08x 0x%08x\n", off,
3586 regs_val[i]);
3587 }
3588 }
3589
debugfs_global_v3_hw_show(struct seq_file * s,void * p)3590 static int debugfs_global_v3_hw_show(struct seq_file *s, void *p)
3591 {
3592 struct hisi_sas_debugfs_regs *global = s->private;
3593
3594 if (!debugfs_dump_is_generated_v3_hw(global->data))
3595 return -EPERM;
3596
3597 debugfs_print_reg_v3_hw(global->data, s,
3598 &debugfs_global_reg);
3599
3600 return 0;
3601 }
3602 DEFINE_SHOW_ATTRIBUTE(debugfs_global_v3_hw);
3603
debugfs_axi_v3_hw_show(struct seq_file * s,void * p)3604 static int debugfs_axi_v3_hw_show(struct seq_file *s, void *p)
3605 {
3606 struct hisi_sas_debugfs_regs *axi = s->private;
3607
3608 if (!debugfs_dump_is_generated_v3_hw(axi->data))
3609 return -EPERM;
3610
3611 debugfs_print_reg_v3_hw(axi->data, s,
3612 &debugfs_axi_reg);
3613
3614 return 0;
3615 }
3616 DEFINE_SHOW_ATTRIBUTE(debugfs_axi_v3_hw);
3617
debugfs_ras_v3_hw_show(struct seq_file * s,void * p)3618 static int debugfs_ras_v3_hw_show(struct seq_file *s, void *p)
3619 {
3620 struct hisi_sas_debugfs_regs *ras = s->private;
3621
3622 if (!debugfs_dump_is_generated_v3_hw(ras->data))
3623 return -EPERM;
3624
3625 debugfs_print_reg_v3_hw(ras->data, s,
3626 &debugfs_ras_reg);
3627
3628 return 0;
3629 }
3630 DEFINE_SHOW_ATTRIBUTE(debugfs_ras_v3_hw);
3631
debugfs_port_v3_hw_show(struct seq_file * s,void * p)3632 static int debugfs_port_v3_hw_show(struct seq_file *s, void *p)
3633 {
3634 struct hisi_sas_debugfs_port *port = s->private;
3635 const struct hisi_sas_debugfs_reg *reg_port = &debugfs_port_reg;
3636
3637 if (!debugfs_dump_is_generated_v3_hw(port->data))
3638 return -EPERM;
3639
3640 debugfs_print_reg_v3_hw(port->data, s, reg_port);
3641
3642 return 0;
3643 }
3644 DEFINE_SHOW_ATTRIBUTE(debugfs_port_v3_hw);
3645
debugfs_show_row_64_v3_hw(struct seq_file * s,int index,int sz,__le64 * ptr)3646 static void debugfs_show_row_64_v3_hw(struct seq_file *s, int index,
3647 int sz, __le64 *ptr)
3648 {
3649 int i;
3650
3651 /* completion header size not fixed per HW version */
3652 seq_printf(s, "index %04d:\n\t", index);
3653 for (i = 1; i <= sz / 8; i++, ptr++) {
3654 seq_printf(s, " 0x%016llx", le64_to_cpu(*ptr));
3655 if (!(i % 2))
3656 seq_puts(s, "\n\t");
3657 }
3658
3659 seq_puts(s, "\n");
3660 }
3661
debugfs_show_row_32_v3_hw(struct seq_file * s,int index,int sz,__le32 * ptr)3662 static void debugfs_show_row_32_v3_hw(struct seq_file *s, int index,
3663 int sz, __le32 *ptr)
3664 {
3665 int i;
3666
3667 /* completion header size not fixed per HW version */
3668 seq_printf(s, "index %04d:\n\t", index);
3669 for (i = 1; i <= sz / 4; i++, ptr++) {
3670 seq_printf(s, " 0x%08x", le32_to_cpu(*ptr));
3671 if (!(i % 4))
3672 seq_puts(s, "\n\t");
3673 }
3674 seq_puts(s, "\n");
3675 }
3676
debugfs_cq_show_slot_v3_hw(struct seq_file * s,int slot,struct hisi_sas_debugfs_cq * debugfs_cq)3677 static void debugfs_cq_show_slot_v3_hw(struct seq_file *s, int slot,
3678 struct hisi_sas_debugfs_cq *debugfs_cq)
3679 {
3680 struct hisi_sas_cq *cq = debugfs_cq->cq;
3681 struct hisi_hba *hisi_hba = cq->hisi_hba;
3682 __le32 *complete_hdr = debugfs_cq->complete_hdr +
3683 (hisi_hba->hw->complete_hdr_size * slot);
3684
3685 debugfs_show_row_32_v3_hw(s, slot,
3686 hisi_hba->hw->complete_hdr_size,
3687 complete_hdr);
3688 }
3689
debugfs_cq_v3_hw_show(struct seq_file * s,void * p)3690 static int debugfs_cq_v3_hw_show(struct seq_file *s, void *p)
3691 {
3692 struct hisi_sas_debugfs_cq *debugfs_cq = s->private;
3693 int slot;
3694
3695 if (!debugfs_dump_is_generated_v3_hw(debugfs_cq->complete_hdr))
3696 return -EPERM;
3697
3698 for (slot = 0; slot < HISI_SAS_QUEUE_SLOTS; slot++)
3699 debugfs_cq_show_slot_v3_hw(s, slot, debugfs_cq);
3700
3701 return 0;
3702 }
3703 DEFINE_SHOW_ATTRIBUTE(debugfs_cq_v3_hw);
3704
debugfs_dq_show_slot_v3_hw(struct seq_file * s,int slot,void * dq_ptr)3705 static void debugfs_dq_show_slot_v3_hw(struct seq_file *s, int slot,
3706 void *dq_ptr)
3707 {
3708 struct hisi_sas_debugfs_dq *debugfs_dq = dq_ptr;
3709 void *cmd_queue = debugfs_dq->hdr;
3710 __le32 *cmd_hdr = cmd_queue +
3711 sizeof(struct hisi_sas_cmd_hdr) * slot;
3712
3713 debugfs_show_row_32_v3_hw(s, slot, sizeof(struct hisi_sas_cmd_hdr),
3714 cmd_hdr);
3715 }
3716
debugfs_dq_v3_hw_show(struct seq_file * s,void * p)3717 static int debugfs_dq_v3_hw_show(struct seq_file *s, void *p)
3718 {
3719 struct hisi_sas_debugfs_dq *debugfs_dq = s->private;
3720 int slot;
3721
3722 if (!debugfs_dump_is_generated_v3_hw(debugfs_dq->hdr))
3723 return -EPERM;
3724
3725 for (slot = 0; slot < HISI_SAS_QUEUE_SLOTS; slot++)
3726 debugfs_dq_show_slot_v3_hw(s, slot, s->private);
3727
3728 return 0;
3729 }
3730 DEFINE_SHOW_ATTRIBUTE(debugfs_dq_v3_hw);
3731
debugfs_iost_v3_hw_show(struct seq_file * s,void * p)3732 static int debugfs_iost_v3_hw_show(struct seq_file *s, void *p)
3733 {
3734 struct hisi_sas_debugfs_iost *debugfs_iost = s->private;
3735 struct hisi_sas_iost *iost = debugfs_iost->iost;
3736 int i, max_command_entries = HISI_SAS_MAX_COMMANDS;
3737
3738 if (!debugfs_dump_is_generated_v3_hw(iost))
3739 return -EPERM;
3740
3741 for (i = 0; i < max_command_entries; i++, iost++) {
3742 __le64 *data = &iost->qw0;
3743
3744 debugfs_show_row_64_v3_hw(s, i, sizeof(*iost), data);
3745 }
3746
3747 return 0;
3748 }
3749 DEFINE_SHOW_ATTRIBUTE(debugfs_iost_v3_hw);
3750
debugfs_iost_cache_v3_hw_show(struct seq_file * s,void * p)3751 static int debugfs_iost_cache_v3_hw_show(struct seq_file *s, void *p)
3752 {
3753 struct hisi_sas_debugfs_iost_cache *debugfs_iost_cache = s->private;
3754 struct hisi_sas_iost_itct_cache *iost_cache =
3755 debugfs_iost_cache->cache;
3756 u32 cache_size = HISI_SAS_IOST_ITCT_CACHE_DW_SZ * 4;
3757 int i, tab_idx;
3758 __le64 *iost;
3759
3760 if (!debugfs_dump_is_generated_v3_hw(iost_cache))
3761 return -EPERM;
3762
3763 for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_NUM; i++, iost_cache++) {
3764 /*
3765 * Data struct of IOST cache:
3766 * Data[1]: BIT0~15: Table index
3767 * Bit16: Valid mask
3768 * Data[2]~[9]: IOST table
3769 */
3770 tab_idx = (iost_cache->data[1] & 0xffff);
3771 iost = (__le64 *)iost_cache;
3772
3773 debugfs_show_row_64_v3_hw(s, tab_idx, cache_size, iost);
3774 }
3775
3776 return 0;
3777 }
3778 DEFINE_SHOW_ATTRIBUTE(debugfs_iost_cache_v3_hw);
3779
debugfs_itct_v3_hw_show(struct seq_file * s,void * p)3780 static int debugfs_itct_v3_hw_show(struct seq_file *s, void *p)
3781 {
3782 int i;
3783 struct hisi_sas_debugfs_itct *debugfs_itct = s->private;
3784 struct hisi_sas_itct *itct = debugfs_itct->itct;
3785
3786 if (!debugfs_dump_is_generated_v3_hw(itct))
3787 return -EPERM;
3788
3789 for (i = 0; i < HISI_SAS_MAX_ITCT_ENTRIES; i++, itct++) {
3790 __le64 *data = &itct->qw0;
3791
3792 debugfs_show_row_64_v3_hw(s, i, sizeof(*itct), data);
3793 }
3794
3795 return 0;
3796 }
3797 DEFINE_SHOW_ATTRIBUTE(debugfs_itct_v3_hw);
3798
debugfs_itct_cache_v3_hw_show(struct seq_file * s,void * p)3799 static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
3800 {
3801 struct hisi_sas_debugfs_itct_cache *debugfs_itct_cache = s->private;
3802 struct hisi_sas_iost_itct_cache *itct_cache =
3803 debugfs_itct_cache->cache;
3804 u32 cache_size = HISI_SAS_IOST_ITCT_CACHE_DW_SZ * 4;
3805 int i, tab_idx;
3806 __le64 *itct;
3807
3808 if (!debugfs_dump_is_generated_v3_hw(itct_cache))
3809 return -EPERM;
3810
3811 for (i = 0; i < HISI_SAS_IOST_ITCT_CACHE_NUM; i++, itct_cache++) {
3812 /*
3813 * Data struct of ITCT cache:
3814 * Data[1]: BIT0~15: Table index
3815 * Bit16: Valid mask
3816 * Data[2]~[9]: ITCT table
3817 */
3818 tab_idx = itct_cache->data[1] & 0xffff;
3819 itct = (__le64 *)itct_cache;
3820
3821 debugfs_show_row_64_v3_hw(s, tab_idx, cache_size, itct);
3822 }
3823
3824 return 0;
3825 }
3826 DEFINE_SHOW_ATTRIBUTE(debugfs_itct_cache_v3_hw);
3827
debugfs_create_files_v3_hw(struct hisi_hba * hisi_hba,int index)3828 static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba, int index)
3829 {
3830 u64 *debugfs_timestamp;
3831 struct dentry *dump_dentry;
3832 struct dentry *dentry;
3833 char name[256];
3834 int p;
3835 int c;
3836 int d;
3837
3838 snprintf(name, 256, "%d", index);
3839
3840 dump_dentry = debugfs_create_dir(name, hisi_hba->debugfs_dump_dentry);
3841
3842 debugfs_timestamp = &hisi_hba->debugfs_timestamp[index];
3843
3844 debugfs_create_u64("timestamp", 0400, dump_dentry,
3845 debugfs_timestamp);
3846
3847 debugfs_create_file("global", 0400, dump_dentry,
3848 &hisi_hba->debugfs_regs[index][DEBUGFS_GLOBAL],
3849 &debugfs_global_v3_hw_fops);
3850
3851 /* Create port dir and files */
3852 dentry = debugfs_create_dir("port", dump_dentry);
3853 for (p = 0; p < hisi_hba->n_phy; p++) {
3854 snprintf(name, 256, "%d", p);
3855
3856 debugfs_create_file(name, 0400, dentry,
3857 &hisi_hba->debugfs_port_reg[index][p],
3858 &debugfs_port_v3_hw_fops);
3859 }
3860
3861 /* Create CQ dir and files */
3862 dentry = debugfs_create_dir("cq", dump_dentry);
3863 for (c = 0; c < hisi_hba->queue_count; c++) {
3864 snprintf(name, 256, "%d", c);
3865
3866 debugfs_create_file(name, 0400, dentry,
3867 &hisi_hba->debugfs_cq[index][c],
3868 &debugfs_cq_v3_hw_fops);
3869 }
3870
3871 /* Create DQ dir and files */
3872 dentry = debugfs_create_dir("dq", dump_dentry);
3873 for (d = 0; d < hisi_hba->queue_count; d++) {
3874 snprintf(name, 256, "%d", d);
3875
3876 debugfs_create_file(name, 0400, dentry,
3877 &hisi_hba->debugfs_dq[index][d],
3878 &debugfs_dq_v3_hw_fops);
3879 }
3880
3881 debugfs_create_file("iost", 0400, dump_dentry,
3882 &hisi_hba->debugfs_iost[index],
3883 &debugfs_iost_v3_hw_fops);
3884
3885 debugfs_create_file("iost_cache", 0400, dump_dentry,
3886 &hisi_hba->debugfs_iost_cache[index],
3887 &debugfs_iost_cache_v3_hw_fops);
3888
3889 debugfs_create_file("itct", 0400, dump_dentry,
3890 &hisi_hba->debugfs_itct[index],
3891 &debugfs_itct_v3_hw_fops);
3892
3893 debugfs_create_file("itct_cache", 0400, dump_dentry,
3894 &hisi_hba->debugfs_itct_cache[index],
3895 &debugfs_itct_cache_v3_hw_fops);
3896
3897 debugfs_create_file("axi", 0400, dump_dentry,
3898 &hisi_hba->debugfs_regs[index][DEBUGFS_AXI],
3899 &debugfs_axi_v3_hw_fops);
3900
3901 debugfs_create_file("ras", 0400, dump_dentry,
3902 &hisi_hba->debugfs_regs[index][DEBUGFS_RAS],
3903 &debugfs_ras_v3_hw_fops);
3904 }
3905
debugfs_trigger_dump_v3_hw_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)3906 static ssize_t debugfs_trigger_dump_v3_hw_write(struct file *file,
3907 const char __user *user_buf,
3908 size_t count, loff_t *ppos)
3909 {
3910 struct hisi_hba *hisi_hba = file->f_inode->i_private;
3911 char buf[8];
3912
3913 if (count > 8)
3914 return -EFAULT;
3915
3916 if (copy_from_user(buf, user_buf, count))
3917 return -EFAULT;
3918
3919 if (buf[0] != '1')
3920 return -EFAULT;
3921
3922 down(&hisi_hba->sem);
3923 if (debugfs_snapshot_regs_v3_hw(hisi_hba)) {
3924 up(&hisi_hba->sem);
3925 return -EFAULT;
3926 }
3927 up(&hisi_hba->sem);
3928
3929 return count;
3930 }
3931
3932 static const struct file_operations debugfs_trigger_dump_v3_hw_fops = {
3933 .write = &debugfs_trigger_dump_v3_hw_write,
3934 .owner = THIS_MODULE,
3935 };
3936
3937 enum {
3938 HISI_SAS_BIST_LOOPBACK_MODE_DIGITAL = 0,
3939 HISI_SAS_BIST_LOOPBACK_MODE_SERDES,
3940 HISI_SAS_BIST_LOOPBACK_MODE_REMOTE,
3941 };
3942
3943 static const struct {
3944 int value;
3945 char *name;
3946 } debugfs_loop_linkrate_v3_hw[] = {
3947 { SAS_LINK_RATE_1_5_GBPS, "1.5 Gbit" },
3948 { SAS_LINK_RATE_3_0_GBPS, "3.0 Gbit" },
3949 { SAS_LINK_RATE_6_0_GBPS, "6.0 Gbit" },
3950 { SAS_LINK_RATE_12_0_GBPS, "12.0 Gbit" },
3951 };
3952
debugfs_bist_linkrate_v3_hw_show(struct seq_file * s,void * p)3953 static int debugfs_bist_linkrate_v3_hw_show(struct seq_file *s, void *p)
3954 {
3955 struct hisi_hba *hisi_hba = s->private;
3956 int i;
3957
3958 for (i = 0; i < ARRAY_SIZE(debugfs_loop_linkrate_v3_hw); i++) {
3959 int match = (hisi_hba->debugfs_bist_linkrate ==
3960 debugfs_loop_linkrate_v3_hw[i].value);
3961
3962 seq_printf(s, "%s%s%s ", match ? "[" : "",
3963 debugfs_loop_linkrate_v3_hw[i].name,
3964 match ? "]" : "");
3965 }
3966 seq_puts(s, "\n");
3967
3968 return 0;
3969 }
3970
debugfs_bist_linkrate_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)3971 static ssize_t debugfs_bist_linkrate_v3_hw_write(struct file *filp,
3972 const char __user *buf,
3973 size_t count, loff_t *ppos)
3974 {
3975 struct seq_file *m = filp->private_data;
3976 struct hisi_hba *hisi_hba = m->private;
3977 char kbuf[16] = {}, *pkbuf;
3978 bool found = false;
3979 int i;
3980
3981 if (hisi_hba->debugfs_bist_enable)
3982 return -EPERM;
3983
3984 if (count >= sizeof(kbuf))
3985 return -EOVERFLOW;
3986
3987 if (copy_from_user(kbuf, buf, count))
3988 return -EINVAL;
3989
3990 pkbuf = strstrip(kbuf);
3991
3992 for (i = 0; i < ARRAY_SIZE(debugfs_loop_linkrate_v3_hw); i++) {
3993 if (!strncmp(debugfs_loop_linkrate_v3_hw[i].name,
3994 pkbuf, 16)) {
3995 hisi_hba->debugfs_bist_linkrate =
3996 debugfs_loop_linkrate_v3_hw[i].value;
3997 found = true;
3998 break;
3999 }
4000 }
4001
4002 if (!found)
4003 return -EINVAL;
4004
4005 return count;
4006 }
4007 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_bist_linkrate_v3_hw);
4008
4009 static const struct {
4010 int value;
4011 char *name;
4012 } debugfs_loop_code_mode_v3_hw[] = {
4013 { HISI_SAS_BIST_CODE_MODE_PRBS7, "PRBS7" },
4014 { HISI_SAS_BIST_CODE_MODE_PRBS23, "PRBS23" },
4015 { HISI_SAS_BIST_CODE_MODE_PRBS31, "PRBS31" },
4016 { HISI_SAS_BIST_CODE_MODE_JTPAT, "JTPAT" },
4017 { HISI_SAS_BIST_CODE_MODE_CJTPAT, "CJTPAT" },
4018 { HISI_SAS_BIST_CODE_MODE_SCRAMBED_0, "SCRAMBED_0" },
4019 { HISI_SAS_BIST_CODE_MODE_TRAIN, "TRAIN" },
4020 { HISI_SAS_BIST_CODE_MODE_TRAIN_DONE, "TRAIN_DONE" },
4021 { HISI_SAS_BIST_CODE_MODE_HFTP, "HFTP" },
4022 { HISI_SAS_BIST_CODE_MODE_MFTP, "MFTP" },
4023 { HISI_SAS_BIST_CODE_MODE_LFTP, "LFTP" },
4024 { HISI_SAS_BIST_CODE_MODE_FIXED_DATA, "FIXED_DATA" },
4025 };
4026
debugfs_bist_code_mode_v3_hw_show(struct seq_file * s,void * p)4027 static int debugfs_bist_code_mode_v3_hw_show(struct seq_file *s, void *p)
4028 {
4029 struct hisi_hba *hisi_hba = s->private;
4030 int i;
4031
4032 for (i = 0; i < ARRAY_SIZE(debugfs_loop_code_mode_v3_hw); i++) {
4033 int match = (hisi_hba->debugfs_bist_code_mode ==
4034 debugfs_loop_code_mode_v3_hw[i].value);
4035
4036 seq_printf(s, "%s%s%s ", match ? "[" : "",
4037 debugfs_loop_code_mode_v3_hw[i].name,
4038 match ? "]" : "");
4039 }
4040 seq_puts(s, "\n");
4041
4042 return 0;
4043 }
4044
debugfs_bist_code_mode_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4045 static ssize_t debugfs_bist_code_mode_v3_hw_write(struct file *filp,
4046 const char __user *buf,
4047 size_t count,
4048 loff_t *ppos)
4049 {
4050 struct seq_file *m = filp->private_data;
4051 struct hisi_hba *hisi_hba = m->private;
4052 char kbuf[16] = {}, *pkbuf;
4053 bool found = false;
4054 int i;
4055
4056 if (hisi_hba->debugfs_bist_enable)
4057 return -EPERM;
4058
4059 if (count >= sizeof(kbuf))
4060 return -EINVAL;
4061
4062 if (copy_from_user(kbuf, buf, count))
4063 return -EOVERFLOW;
4064
4065 pkbuf = strstrip(kbuf);
4066
4067 for (i = 0; i < ARRAY_SIZE(debugfs_loop_code_mode_v3_hw); i++) {
4068 if (!strncmp(debugfs_loop_code_mode_v3_hw[i].name,
4069 pkbuf, 16)) {
4070 hisi_hba->debugfs_bist_code_mode =
4071 debugfs_loop_code_mode_v3_hw[i].value;
4072 found = true;
4073 break;
4074 }
4075 }
4076
4077 if (!found)
4078 return -EINVAL;
4079
4080 return count;
4081 }
4082 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_bist_code_mode_v3_hw);
4083
debugfs_bist_phy_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4084 static ssize_t debugfs_bist_phy_v3_hw_write(struct file *filp,
4085 const char __user *buf,
4086 size_t count, loff_t *ppos)
4087 {
4088 struct seq_file *m = filp->private_data;
4089 struct hisi_hba *hisi_hba = m->private;
4090 unsigned int phy_no;
4091 int val;
4092
4093 if (hisi_hba->debugfs_bist_enable)
4094 return -EPERM;
4095
4096 val = kstrtouint_from_user(buf, count, 0, &phy_no);
4097 if (val)
4098 return val;
4099
4100 if (phy_no >= hisi_hba->n_phy)
4101 return -EINVAL;
4102
4103 hisi_hba->debugfs_bist_phy_no = phy_no;
4104
4105 return count;
4106 }
4107
debugfs_bist_phy_v3_hw_show(struct seq_file * s,void * p)4108 static int debugfs_bist_phy_v3_hw_show(struct seq_file *s, void *p)
4109 {
4110 struct hisi_hba *hisi_hba = s->private;
4111
4112 seq_printf(s, "%d\n", hisi_hba->debugfs_bist_phy_no);
4113
4114 return 0;
4115 }
4116 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_bist_phy_v3_hw);
4117
debugfs_bist_cnt_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4118 static ssize_t debugfs_bist_cnt_v3_hw_write(struct file *filp,
4119 const char __user *buf,
4120 size_t count, loff_t *ppos)
4121 {
4122 struct seq_file *m = filp->private_data;
4123 struct hisi_hba *hisi_hba = m->private;
4124 unsigned int cnt;
4125 int val;
4126
4127 if (hisi_hba->debugfs_bist_enable)
4128 return -EPERM;
4129
4130 val = kstrtouint_from_user(buf, count, 0, &cnt);
4131 if (val)
4132 return val;
4133
4134 if (cnt)
4135 return -EINVAL;
4136
4137 hisi_hba->debugfs_bist_cnt = 0;
4138 return count;
4139 }
4140
debugfs_bist_cnt_v3_hw_show(struct seq_file * s,void * p)4141 static int debugfs_bist_cnt_v3_hw_show(struct seq_file *s, void *p)
4142 {
4143 struct hisi_hba *hisi_hba = s->private;
4144
4145 seq_printf(s, "%u\n", hisi_hba->debugfs_bist_cnt);
4146
4147 return 0;
4148 }
4149 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_bist_cnt_v3_hw);
4150
4151 static const struct {
4152 int value;
4153 char *name;
4154 } debugfs_loop_modes_v3_hw[] = {
4155 { HISI_SAS_BIST_LOOPBACK_MODE_DIGITAL, "digital" },
4156 { HISI_SAS_BIST_LOOPBACK_MODE_SERDES, "serdes" },
4157 { HISI_SAS_BIST_LOOPBACK_MODE_REMOTE, "remote" },
4158 };
4159
debugfs_bist_mode_v3_hw_show(struct seq_file * s,void * p)4160 static int debugfs_bist_mode_v3_hw_show(struct seq_file *s, void *p)
4161 {
4162 struct hisi_hba *hisi_hba = s->private;
4163 int i;
4164
4165 for (i = 0; i < ARRAY_SIZE(debugfs_loop_modes_v3_hw); i++) {
4166 int match = (hisi_hba->debugfs_bist_mode ==
4167 debugfs_loop_modes_v3_hw[i].value);
4168
4169 seq_printf(s, "%s%s%s ", match ? "[" : "",
4170 debugfs_loop_modes_v3_hw[i].name,
4171 match ? "]" : "");
4172 }
4173 seq_puts(s, "\n");
4174
4175 return 0;
4176 }
4177
debugfs_bist_mode_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4178 static ssize_t debugfs_bist_mode_v3_hw_write(struct file *filp,
4179 const char __user *buf,
4180 size_t count, loff_t *ppos)
4181 {
4182 struct seq_file *m = filp->private_data;
4183 struct hisi_hba *hisi_hba = m->private;
4184 char kbuf[16] = {}, *pkbuf;
4185 bool found = false;
4186 int i;
4187
4188 if (hisi_hba->debugfs_bist_enable)
4189 return -EPERM;
4190
4191 if (count >= sizeof(kbuf))
4192 return -EINVAL;
4193
4194 if (copy_from_user(kbuf, buf, count))
4195 return -EOVERFLOW;
4196
4197 pkbuf = strstrip(kbuf);
4198
4199 for (i = 0; i < ARRAY_SIZE(debugfs_loop_modes_v3_hw); i++) {
4200 if (!strncmp(debugfs_loop_modes_v3_hw[i].name, pkbuf, 16)) {
4201 hisi_hba->debugfs_bist_mode =
4202 debugfs_loop_modes_v3_hw[i].value;
4203 found = true;
4204 break;
4205 }
4206 }
4207
4208 if (!found)
4209 return -EINVAL;
4210
4211 return count;
4212 }
4213 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_bist_mode_v3_hw);
4214
debugfs_bist_enable_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4215 static ssize_t debugfs_bist_enable_v3_hw_write(struct file *filp,
4216 const char __user *buf,
4217 size_t count, loff_t *ppos)
4218 {
4219 struct seq_file *m = filp->private_data;
4220 struct hisi_hba *hisi_hba = m->private;
4221 unsigned int enable;
4222 int val;
4223
4224 val = kstrtouint_from_user(buf, count, 0, &enable);
4225 if (val)
4226 return val;
4227
4228 if (enable > 1)
4229 return -EINVAL;
4230
4231 if (enable == hisi_hba->debugfs_bist_enable)
4232 return count;
4233
4234 val = debugfs_set_bist_v3_hw(hisi_hba, enable);
4235 if (val < 0)
4236 return val;
4237
4238 hisi_hba->debugfs_bist_enable = enable;
4239
4240 return count;
4241 }
4242
debugfs_bist_enable_v3_hw_show(struct seq_file * s,void * p)4243 static int debugfs_bist_enable_v3_hw_show(struct seq_file *s, void *p)
4244 {
4245 struct hisi_hba *hisi_hba = s->private;
4246
4247 seq_printf(s, "%d\n", hisi_hba->debugfs_bist_enable);
4248
4249 return 0;
4250 }
4251 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_bist_enable_v3_hw);
4252
4253 static const struct {
4254 char *name;
4255 } debugfs_ffe_name_v3_hw[FFE_CFG_MAX] = {
4256 { "SAS_1_5_GBPS" },
4257 { "SAS_3_0_GBPS" },
4258 { "SAS_6_0_GBPS" },
4259 { "SAS_12_0_GBPS" },
4260 { "FFE_RESV" },
4261 { "SATA_1_5_GBPS" },
4262 { "SATA_3_0_GBPS" },
4263 { "SATA_6_0_GBPS" },
4264 };
4265
debugfs_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4266 static ssize_t debugfs_v3_hw_write(struct file *filp,
4267 const char __user *buf,
4268 size_t count, loff_t *ppos)
4269 {
4270 struct seq_file *m = filp->private_data;
4271 u32 *val = m->private;
4272 int res;
4273
4274 res = kstrtouint_from_user(buf, count, 0, val);
4275 if (res)
4276 return res;
4277
4278 return count;
4279 }
4280
debugfs_v3_hw_show(struct seq_file * s,void * p)4281 static int debugfs_v3_hw_show(struct seq_file *s, void *p)
4282 {
4283 u32 *val = s->private;
4284
4285 seq_printf(s, "0x%x\n", *val);
4286
4287 return 0;
4288 }
4289 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_v3_hw);
4290
debugfs_phy_down_cnt_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4291 static ssize_t debugfs_phy_down_cnt_v3_hw_write(struct file *filp,
4292 const char __user *buf,
4293 size_t count, loff_t *ppos)
4294 {
4295 struct seq_file *s = filp->private_data;
4296 struct hisi_sas_phy *phy = s->private;
4297 unsigned int set_val;
4298 int res;
4299
4300 res = kstrtouint_from_user(buf, count, 0, &set_val);
4301 if (res)
4302 return res;
4303
4304 if (set_val > 0)
4305 return -EINVAL;
4306
4307 atomic_set(&phy->down_cnt, 0);
4308
4309 return count;
4310 }
4311
debugfs_phy_down_cnt_v3_hw_show(struct seq_file * s,void * p)4312 static int debugfs_phy_down_cnt_v3_hw_show(struct seq_file *s, void *p)
4313 {
4314 struct hisi_sas_phy *phy = s->private;
4315
4316 seq_printf(s, "%d\n", atomic_read(&phy->down_cnt));
4317
4318 return 0;
4319 }
4320 DEFINE_SHOW_STORE_ATTRIBUTE(debugfs_phy_down_cnt_v3_hw);
4321
4322 enum fifo_dump_mode_v3_hw {
4323 FIFO_DUMP_FORVER = (1U << 0),
4324 FIFO_DUMP_AFTER_TRIGGER = (1U << 1),
4325 FIFO_DUMP_UNTILL_TRIGGER = (1U << 2),
4326 };
4327
4328 enum fifo_trigger_mode_v3_hw {
4329 FIFO_TRIGGER_EDGE = (1U << 0),
4330 FIFO_TRIGGER_SAME_LEVEL = (1U << 1),
4331 FIFO_TRIGGER_DIFF_LEVEL = (1U << 2),
4332 };
4333
debugfs_is_fifo_config_valid_v3_hw(struct hisi_sas_phy * phy)4334 static int debugfs_is_fifo_config_valid_v3_hw(struct hisi_sas_phy *phy)
4335 {
4336 struct hisi_hba *hisi_hba = phy->hisi_hba;
4337
4338 if (phy->fifo.signal_sel > 0xf) {
4339 dev_info(hisi_hba->dev, "Invalid signal select: %u\n",
4340 phy->fifo.signal_sel);
4341 return -EINVAL;
4342 }
4343
4344 switch (phy->fifo.dump_mode) {
4345 case FIFO_DUMP_FORVER:
4346 case FIFO_DUMP_AFTER_TRIGGER:
4347 case FIFO_DUMP_UNTILL_TRIGGER:
4348 break;
4349 default:
4350 dev_info(hisi_hba->dev, "Invalid dump mode: %u\n",
4351 phy->fifo.dump_mode);
4352 return -EINVAL;
4353 }
4354
4355 /* when FIFO_DUMP_FORVER, no need to check trigger_mode */
4356 if (phy->fifo.dump_mode == FIFO_DUMP_FORVER)
4357 return 0;
4358
4359 switch (phy->fifo.trigger_mode) {
4360 case FIFO_TRIGGER_EDGE:
4361 case FIFO_TRIGGER_SAME_LEVEL:
4362 case FIFO_TRIGGER_DIFF_LEVEL:
4363 break;
4364 default:
4365 dev_info(hisi_hba->dev, "Invalid trigger mode: %u\n",
4366 phy->fifo.trigger_mode);
4367 return -EINVAL;
4368 }
4369 return 0;
4370 }
4371
debugfs_update_fifo_config_v3_hw(struct hisi_sas_phy * phy)4372 static int debugfs_update_fifo_config_v3_hw(struct hisi_sas_phy *phy)
4373 {
4374 u32 trigger_mode = phy->fifo.trigger_mode;
4375 u32 signal_sel = phy->fifo.signal_sel;
4376 u32 dump_mode = phy->fifo.dump_mode;
4377 struct hisi_hba *hisi_hba = phy->hisi_hba;
4378 int phy_no = phy->sas_phy.id;
4379 u32 reg_val;
4380 int res;
4381
4382 /* Check the validity of trace FIFO configuration */
4383 res = debugfs_is_fifo_config_valid_v3_hw(phy);
4384 if (res)
4385 return res;
4386
4387 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4388 /* Disable trace FIFO before update configuration */
4389 reg_val |= DFX_FIFO_CTRL_DUMP_DISABLE_MSK;
4390
4391 /* Update trace FIFO configuration */
4392 reg_val &= ~(DFX_FIFO_CTRL_DUMP_MODE_MSK |
4393 DFX_FIFO_CTRL_SIGNAL_SEL_MSK |
4394 DFX_FIFO_CTRL_TRIGGER_MODE_MSK);
4395
4396 reg_val |= ((trigger_mode << DFX_FIFO_CTRL_TRIGGER_MODE_OFF) |
4397 (dump_mode << DFX_FIFO_CTRL_DUMP_MODE_OFF) |
4398 (signal_sel << DFX_FIFO_CTRL_SIGNAL_SEL_OFF));
4399 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_CTRL, reg_val);
4400
4401 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_DUMP_MSK,
4402 phy->fifo.dump_msk);
4403
4404 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_TRIGGER,
4405 phy->fifo.trigger);
4406
4407 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_TRIGGER_MSK,
4408 phy->fifo.trigger_msk);
4409
4410 /* Enable trace FIFO after updated configuration */
4411 reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4412 reg_val &= ~DFX_FIFO_CTRL_DUMP_DISABLE_MSK;
4413 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_CTRL, reg_val);
4414
4415 return 0;
4416 }
4417
debugfs_fifo_update_cfg_v3_hw_write(struct file * filp,const char __user * buf,size_t count,loff_t * ppos)4418 static ssize_t debugfs_fifo_update_cfg_v3_hw_write(struct file *filp,
4419 const char __user *buf,
4420 size_t count, loff_t *ppos)
4421 {
4422 struct hisi_sas_phy *phy = filp->private_data;
4423 bool update;
4424 int val;
4425
4426 val = kstrtobool_from_user(buf, count, &update);
4427 if (val)
4428 return val;
4429
4430 if (update != 1)
4431 return -EINVAL;
4432
4433 val = debugfs_update_fifo_config_v3_hw(phy);
4434 if (val)
4435 return val;
4436
4437 return count;
4438 }
4439
4440 static const struct file_operations debugfs_fifo_update_cfg_v3_hw_fops = {
4441 .open = simple_open,
4442 .write = debugfs_fifo_update_cfg_v3_hw_write,
4443 .owner = THIS_MODULE,
4444 };
4445
debugfs_read_fifo_data_v3_hw(struct hisi_sas_phy * phy)4446 static void debugfs_read_fifo_data_v3_hw(struct hisi_sas_phy *phy)
4447 {
4448 struct hisi_hba *hisi_hba = phy->hisi_hba;
4449 u32 *buf = phy->fifo.rd_data;
4450 int phy_no = phy->sas_phy.id;
4451 u32 val;
4452 int i;
4453
4454 memset(buf, 0, sizeof(phy->fifo.rd_data));
4455
4456 /* Disable trace FIFO before read data */
4457 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4458 val |= DFX_FIFO_CTRL_DUMP_DISABLE_MSK;
4459 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_CTRL, val);
4460
4461 for (i = 0; i < HISI_SAS_FIFO_DATA_DW_SIZE; i++) {
4462 val = hisi_sas_phy_read32(hisi_hba, phy_no,
4463 DFX_FIFO_RD_DATA);
4464 buf[i] = val;
4465 }
4466
4467 /* Enable trace FIFO after read data */
4468 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4469 val &= ~DFX_FIFO_CTRL_DUMP_DISABLE_MSK;
4470 hisi_sas_phy_write32(hisi_hba, phy_no, DFX_FIFO_CTRL, val);
4471 }
4472
debugfs_fifo_data_v3_hw_show(struct seq_file * s,void * p)4473 static int debugfs_fifo_data_v3_hw_show(struct seq_file *s, void *p)
4474 {
4475 struct hisi_sas_phy *phy = s->private;
4476
4477 debugfs_read_fifo_data_v3_hw(phy);
4478
4479 debugfs_show_row_32_v3_hw(s, 0, HISI_SAS_FIFO_DATA_DW_SIZE * 4,
4480 (__le32 *)phy->fifo.rd_data);
4481
4482 return 0;
4483 }
4484 DEFINE_SHOW_ATTRIBUTE(debugfs_fifo_data_v3_hw);
4485
debugfs_fifo_init_v3_hw(struct hisi_hba * hisi_hba)4486 static void debugfs_fifo_init_v3_hw(struct hisi_hba *hisi_hba)
4487 {
4488 int phy_no;
4489
4490 hisi_hba->debugfs_fifo_dentry =
4491 debugfs_create_dir("fifo", hisi_hba->debugfs_dir);
4492
4493 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
4494 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
4495 struct dentry *port_dentry;
4496 char name[256];
4497 u32 val;
4498
4499 /* get default configuration for trace FIFO */
4500 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4501 val &= DFX_FIFO_CTRL_DUMP_MODE_MSK;
4502 val >>= DFX_FIFO_CTRL_DUMP_MODE_OFF;
4503 phy->fifo.dump_mode = val;
4504
4505 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4506 val &= DFX_FIFO_CTRL_TRIGGER_MODE_MSK;
4507 val >>= DFX_FIFO_CTRL_TRIGGER_MODE_OFF;
4508 phy->fifo.trigger_mode = val;
4509
4510 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_CTRL);
4511 val &= DFX_FIFO_CTRL_SIGNAL_SEL_MSK;
4512 val >>= DFX_FIFO_CTRL_SIGNAL_SEL_OFF;
4513 phy->fifo.signal_sel = val;
4514
4515 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_DUMP_MSK);
4516 phy->fifo.dump_msk = val;
4517
4518 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_TRIGGER);
4519 phy->fifo.trigger = val;
4520 val = hisi_sas_phy_read32(hisi_hba, phy_no, DFX_FIFO_TRIGGER_MSK);
4521 phy->fifo.trigger_msk = val;
4522
4523 snprintf(name, 256, "%d", phy_no);
4524 port_dentry = debugfs_create_dir(name,
4525 hisi_hba->debugfs_fifo_dentry);
4526
4527 debugfs_create_file("update_config", 0200, port_dentry, phy,
4528 &debugfs_fifo_update_cfg_v3_hw_fops);
4529
4530 debugfs_create_file("signal_sel", 0600, port_dentry,
4531 &phy->fifo.signal_sel,
4532 &debugfs_v3_hw_fops);
4533
4534 debugfs_create_file("dump_msk", 0600, port_dentry,
4535 &phy->fifo.dump_msk,
4536 &debugfs_v3_hw_fops);
4537
4538 debugfs_create_file("dump_mode", 0600, port_dentry,
4539 &phy->fifo.dump_mode,
4540 &debugfs_v3_hw_fops);
4541
4542 debugfs_create_file("trigger_mode", 0600, port_dentry,
4543 &phy->fifo.trigger_mode,
4544 &debugfs_v3_hw_fops);
4545
4546 debugfs_create_file("trigger", 0600, port_dentry,
4547 &phy->fifo.trigger,
4548 &debugfs_v3_hw_fops);
4549
4550 debugfs_create_file("trigger_msk", 0600, port_dentry,
4551 &phy->fifo.trigger_msk,
4552 &debugfs_v3_hw_fops);
4553
4554 debugfs_create_file("fifo_data", 0400, port_dentry, phy,
4555 &debugfs_fifo_data_v3_hw_fops);
4556 }
4557 }
4558
debugfs_release_v3_hw(struct hisi_hba * hisi_hba,int dump_index)4559 static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
4560 {
4561 struct device *dev = hisi_hba->dev;
4562 int i;
4563
4564 devm_kfree(dev, hisi_hba->debugfs_iost_cache[dump_index].cache);
4565 hisi_hba->debugfs_iost_cache[dump_index].cache = NULL;
4566 devm_kfree(dev, hisi_hba->debugfs_itct_cache[dump_index].cache);
4567 hisi_hba->debugfs_itct_cache[dump_index].cache = NULL;
4568 devm_kfree(dev, hisi_hba->debugfs_iost[dump_index].iost);
4569 hisi_hba->debugfs_iost[dump_index].iost = NULL;
4570 devm_kfree(dev, hisi_hba->debugfs_itct[dump_index].itct);
4571 hisi_hba->debugfs_itct[dump_index].itct = NULL;
4572
4573 for (i = 0; i < hisi_hba->queue_count; i++) {
4574 devm_kfree(dev, hisi_hba->debugfs_dq[dump_index][i].hdr);
4575 hisi_hba->debugfs_dq[dump_index][i].hdr = NULL;
4576 }
4577
4578 for (i = 0; i < hisi_hba->queue_count; i++) {
4579 devm_kfree(dev,
4580 hisi_hba->debugfs_cq[dump_index][i].complete_hdr);
4581 hisi_hba->debugfs_cq[dump_index][i].complete_hdr = NULL;
4582 }
4583
4584 for (i = 0; i < DEBUGFS_REGS_NUM; i++) {
4585 devm_kfree(dev, hisi_hba->debugfs_regs[dump_index][i].data);
4586 hisi_hba->debugfs_regs[dump_index][i].data = NULL;
4587 }
4588
4589 for (i = 0; i < hisi_hba->n_phy; i++) {
4590 devm_kfree(dev, hisi_hba->debugfs_port_reg[dump_index][i].data);
4591 hisi_hba->debugfs_port_reg[dump_index][i].data = NULL;
4592 }
4593 }
4594
4595 static const struct hisi_sas_debugfs_reg *debugfs_reg_array_v3_hw[DEBUGFS_REGS_NUM] = {
4596 [DEBUGFS_GLOBAL] = &debugfs_global_reg,
4597 [DEBUGFS_AXI] = &debugfs_axi_reg,
4598 [DEBUGFS_RAS] = &debugfs_ras_reg,
4599 };
4600
debugfs_alloc_v3_hw(struct hisi_hba * hisi_hba,int dump_index)4601 static int debugfs_alloc_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
4602 {
4603 const struct hisi_sas_hw *hw = hisi_hba->hw;
4604 struct device *dev = hisi_hba->dev;
4605 int p, c, d, r;
4606 size_t sz;
4607
4608 for (r = 0; r < DEBUGFS_REGS_NUM; r++) {
4609 struct hisi_sas_debugfs_regs *regs =
4610 &hisi_hba->debugfs_regs[dump_index][r];
4611
4612 sz = debugfs_reg_array_v3_hw[r]->count * 4;
4613 regs->data = devm_kmalloc(dev, sz, GFP_KERNEL);
4614 if (!regs->data)
4615 goto fail;
4616 regs->hisi_hba = hisi_hba;
4617 }
4618
4619 sz = debugfs_port_reg.count * 4;
4620 for (p = 0; p < hisi_hba->n_phy; p++) {
4621 struct hisi_sas_debugfs_port *port =
4622 &hisi_hba->debugfs_port_reg[dump_index][p];
4623
4624 port->data = devm_kmalloc(dev, sz, GFP_KERNEL);
4625 if (!port->data)
4626 goto fail;
4627 port->phy = &hisi_hba->phy[p];
4628 }
4629
4630 sz = hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
4631 for (c = 0; c < hisi_hba->queue_count; c++) {
4632 struct hisi_sas_debugfs_cq *cq =
4633 &hisi_hba->debugfs_cq[dump_index][c];
4634
4635 cq->complete_hdr = devm_kmalloc(dev, sz, GFP_KERNEL);
4636 if (!cq->complete_hdr)
4637 goto fail;
4638 cq->cq = &hisi_hba->cq[c];
4639 }
4640
4641 sz = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS;
4642 for (d = 0; d < hisi_hba->queue_count; d++) {
4643 struct hisi_sas_debugfs_dq *dq =
4644 &hisi_hba->debugfs_dq[dump_index][d];
4645
4646 dq->hdr = devm_kmalloc(dev, sz, GFP_KERNEL);
4647 if (!dq->hdr)
4648 goto fail;
4649 dq->dq = &hisi_hba->dq[d];
4650 }
4651
4652 sz = HISI_SAS_MAX_COMMANDS * sizeof(struct hisi_sas_iost);
4653
4654 hisi_hba->debugfs_iost[dump_index].iost =
4655 devm_kmalloc(dev, sz, GFP_KERNEL);
4656 if (!hisi_hba->debugfs_iost[dump_index].iost)
4657 goto fail;
4658
4659 sz = HISI_SAS_IOST_ITCT_CACHE_NUM *
4660 sizeof(struct hisi_sas_iost_itct_cache);
4661
4662 hisi_hba->debugfs_iost_cache[dump_index].cache =
4663 devm_kmalloc(dev, sz, GFP_KERNEL);
4664 if (!hisi_hba->debugfs_iost_cache[dump_index].cache)
4665 goto fail;
4666
4667 sz = HISI_SAS_IOST_ITCT_CACHE_NUM *
4668 sizeof(struct hisi_sas_iost_itct_cache);
4669
4670 hisi_hba->debugfs_itct_cache[dump_index].cache =
4671 devm_kmalloc(dev, sz, GFP_KERNEL);
4672 if (!hisi_hba->debugfs_itct_cache[dump_index].cache)
4673 goto fail;
4674
4675 /* New memory allocation must be locate before itct */
4676 sz = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct);
4677
4678 hisi_hba->debugfs_itct[dump_index].itct =
4679 devm_kmalloc(dev, sz, GFP_KERNEL);
4680 if (!hisi_hba->debugfs_itct[dump_index].itct)
4681 goto fail;
4682
4683 return 0;
4684 fail:
4685 debugfs_release_v3_hw(hisi_hba, dump_index);
4686 return -ENOMEM;
4687 }
4688
debugfs_snapshot_regs_v3_hw(struct hisi_hba * hisi_hba)4689 static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
4690 {
4691 int debugfs_dump_index = hisi_hba->debugfs_dump_index;
4692 struct device *dev = hisi_hba->dev;
4693 u64 timestamp = local_clock();
4694
4695 if (debugfs_dump_index >= hisi_sas_debugfs_dump_count) {
4696 dev_warn(dev, "dump count exceeded!\n");
4697 return -EINVAL;
4698 }
4699
4700 if (debugfs_alloc_v3_hw(hisi_hba, debugfs_dump_index)) {
4701 dev_warn(dev, "failed to alloc memory\n");
4702 return -ENOMEM;
4703 }
4704
4705 do_div(timestamp, NSEC_PER_MSEC);
4706 hisi_hba->debugfs_timestamp[debugfs_dump_index] = timestamp;
4707
4708 debugfs_snapshot_prepare_v3_hw(hisi_hba);
4709
4710 debugfs_snapshot_global_reg_v3_hw(hisi_hba);
4711 debugfs_snapshot_port_reg_v3_hw(hisi_hba);
4712 debugfs_snapshot_axi_reg_v3_hw(hisi_hba);
4713 debugfs_snapshot_ras_reg_v3_hw(hisi_hba);
4714 debugfs_snapshot_cq_reg_v3_hw(hisi_hba);
4715 debugfs_snapshot_dq_reg_v3_hw(hisi_hba);
4716 debugfs_snapshot_itct_reg_v3_hw(hisi_hba);
4717 debugfs_snapshot_iost_reg_v3_hw(hisi_hba);
4718
4719 debugfs_snapshot_restore_v3_hw(hisi_hba);
4720 hisi_hba->debugfs_dump_index++;
4721
4722 return 0;
4723 }
4724
debugfs_phy_down_cnt_init_v3_hw(struct hisi_hba * hisi_hba)4725 static void debugfs_phy_down_cnt_init_v3_hw(struct hisi_hba *hisi_hba)
4726 {
4727 struct dentry *dir = debugfs_create_dir("phy_down_cnt",
4728 hisi_hba->debugfs_dir);
4729 char name[16];
4730 int phy_no;
4731
4732 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
4733 snprintf(name, 16, "%d", phy_no);
4734 debugfs_create_file(name, 0600, dir,
4735 &hisi_hba->phy[phy_no],
4736 &debugfs_phy_down_cnt_v3_hw_fops);
4737 }
4738 }
4739
debugfs_bist_init_v3_hw(struct hisi_hba * hisi_hba)4740 static void debugfs_bist_init_v3_hw(struct hisi_hba *hisi_hba)
4741 {
4742 struct dentry *ports_dentry;
4743 int phy_no;
4744
4745 hisi_hba->debugfs_bist_dentry =
4746 debugfs_create_dir("bist", hisi_hba->debugfs_dir);
4747 debugfs_create_file("link_rate", 0600,
4748 hisi_hba->debugfs_bist_dentry, hisi_hba,
4749 &debugfs_bist_linkrate_v3_hw_fops);
4750
4751 debugfs_create_file("code_mode", 0600,
4752 hisi_hba->debugfs_bist_dentry, hisi_hba,
4753 &debugfs_bist_code_mode_v3_hw_fops);
4754
4755 debugfs_create_file("fixed_code", 0600,
4756 hisi_hba->debugfs_bist_dentry,
4757 &hisi_hba->debugfs_bist_fixed_code[0],
4758 &debugfs_v3_hw_fops);
4759
4760 debugfs_create_file("fixed_code_1", 0600,
4761 hisi_hba->debugfs_bist_dentry,
4762 &hisi_hba->debugfs_bist_fixed_code[1],
4763 &debugfs_v3_hw_fops);
4764
4765 debugfs_create_file("phy_id", 0600, hisi_hba->debugfs_bist_dentry,
4766 hisi_hba, &debugfs_bist_phy_v3_hw_fops);
4767
4768 debugfs_create_file("cnt", 0600, hisi_hba->debugfs_bist_dentry,
4769 hisi_hba, &debugfs_bist_cnt_v3_hw_fops);
4770
4771 debugfs_create_file("loopback_mode", 0600,
4772 hisi_hba->debugfs_bist_dentry,
4773 hisi_hba, &debugfs_bist_mode_v3_hw_fops);
4774
4775 debugfs_create_file("enable", 0600, hisi_hba->debugfs_bist_dentry,
4776 hisi_hba, &debugfs_bist_enable_v3_hw_fops);
4777
4778 ports_dentry = debugfs_create_dir("port", hisi_hba->debugfs_bist_dentry);
4779
4780 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
4781 struct dentry *port_dentry;
4782 struct dentry *ffe_dentry;
4783 char name[256];
4784 int i;
4785
4786 snprintf(name, 256, "%d", phy_no);
4787 port_dentry = debugfs_create_dir(name, ports_dentry);
4788 ffe_dentry = debugfs_create_dir("ffe", port_dentry);
4789 for (i = 0; i < FFE_CFG_MAX; i++) {
4790 if (i == FFE_RESV)
4791 continue;
4792 debugfs_create_file(debugfs_ffe_name_v3_hw[i].name,
4793 0600, ffe_dentry,
4794 &hisi_hba->debugfs_bist_ffe[phy_no][i],
4795 &debugfs_v3_hw_fops);
4796 }
4797 }
4798
4799 hisi_hba->debugfs_bist_linkrate = SAS_LINK_RATE_1_5_GBPS;
4800 }
4801
debugfs_dump_init_v3_hw(struct hisi_hba * hisi_hba)4802 static void debugfs_dump_init_v3_hw(struct hisi_hba *hisi_hba)
4803 {
4804 int i;
4805
4806 hisi_hba->debugfs_dump_dentry =
4807 debugfs_create_dir("dump", hisi_hba->debugfs_dir);
4808
4809 for (i = 0; i < hisi_sas_debugfs_dump_count; i++)
4810 debugfs_create_files_v3_hw(hisi_hba, i);
4811 }
4812
debugfs_exit_v3_hw(struct hisi_hba * hisi_hba)4813 static void debugfs_exit_v3_hw(struct hisi_hba *hisi_hba)
4814 {
4815 debugfs_remove_recursive(hisi_hba->debugfs_dir);
4816 hisi_hba->debugfs_dir = NULL;
4817 }
4818
debugfs_init_v3_hw(struct hisi_hba * hisi_hba)4819 static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
4820 {
4821 struct device *dev = hisi_hba->dev;
4822
4823 hisi_hba->debugfs_dir = debugfs_create_dir(dev_name(dev),
4824 hisi_sas_debugfs_dir);
4825 debugfs_create_file("trigger_dump", 0200,
4826 hisi_hba->debugfs_dir,
4827 hisi_hba,
4828 &debugfs_trigger_dump_v3_hw_fops);
4829
4830 /* create bist structures */
4831 debugfs_bist_init_v3_hw(hisi_hba);
4832
4833 debugfs_dump_init_v3_hw(hisi_hba);
4834
4835 debugfs_phy_down_cnt_init_v3_hw(hisi_hba);
4836 debugfs_fifo_init_v3_hw(hisi_hba);
4837 }
4838
4839 static int
hisi_sas_v3_probe(struct pci_dev * pdev,const struct pci_device_id * id)4840 hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
4841 {
4842 struct Scsi_Host *shost;
4843 struct hisi_hba *hisi_hba;
4844 struct device *dev = &pdev->dev;
4845 struct asd_sas_phy **arr_phy;
4846 struct asd_sas_port **arr_port;
4847 struct sas_ha_struct *sha;
4848 int rc, phy_nr, port_nr, i;
4849
4850 rc = pcim_enable_device(pdev);
4851 if (rc)
4852 goto err_out;
4853
4854 pci_set_master(pdev);
4855
4856 rc = pcim_iomap_regions(pdev, 1 << BAR_NO_V3_HW, DRV_NAME);
4857 if (rc)
4858 goto err_out;
4859
4860 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
4861 if (rc) {
4862 dev_err(dev, "No usable DMA addressing method\n");
4863 rc = -ENODEV;
4864 goto err_out;
4865 }
4866
4867 shost = hisi_sas_shost_alloc_pci(pdev);
4868 if (!shost) {
4869 rc = -ENOMEM;
4870 goto err_out;
4871 }
4872
4873 sha = SHOST_TO_SAS_HA(shost);
4874 hisi_hba = shost_priv(shost);
4875 dev_set_drvdata(dev, sha);
4876
4877 hisi_hba->regs = pcim_iomap_table(pdev)[BAR_NO_V3_HW];
4878 if (!hisi_hba->regs) {
4879 dev_err(dev, "cannot map register\n");
4880 rc = -ENOMEM;
4881 goto err_out_free_host;
4882 }
4883
4884 phy_nr = port_nr = hisi_hba->n_phy;
4885
4886 arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
4887 arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
4888 if (!arr_phy || !arr_port) {
4889 rc = -ENOMEM;
4890 goto err_out_free_host;
4891 }
4892
4893 sha->sas_phy = arr_phy;
4894 sha->sas_port = arr_port;
4895 sha->shost = shost;
4896 sha->lldd_ha = hisi_hba;
4897
4898 shost->transportt = hisi_sas_stt;
4899 shost->max_id = HISI_SAS_MAX_DEVICES;
4900 shost->max_lun = ~0;
4901 shost->max_channel = 1;
4902 shost->max_cmd_len = 16;
4903 shost->can_queue = HISI_SAS_UNRESERVED_IPTT;
4904 shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT;
4905 if (hisi_hba->iopoll_q_cnt)
4906 shost->nr_maps = 3;
4907 else
4908 shost->nr_maps = 1;
4909
4910 sha->sas_ha_name = DRV_NAME;
4911 sha->dev = dev;
4912 sha->sas_addr = &hisi_hba->sas_addr[0];
4913 sha->num_phys = hisi_hba->n_phy;
4914
4915 for (i = 0; i < hisi_hba->n_phy; i++) {
4916 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
4917 sha->sas_port[i] = &hisi_hba->port[i].sas_port;
4918 }
4919
4920 if (hisi_hba->prot_mask) {
4921 dev_info(dev, "Registering for DIF/DIX prot_mask=0x%x\n",
4922 prot_mask);
4923 scsi_host_set_prot(hisi_hba->shost, prot_mask);
4924 if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK)
4925 scsi_host_set_guard(hisi_hba->shost,
4926 SHOST_DIX_GUARD_CRC);
4927 }
4928
4929 if (hisi_sas_debugfs_enable)
4930 debugfs_init_v3_hw(hisi_hba);
4931
4932 rc = interrupt_preinit_v3_hw(hisi_hba);
4933 if (rc)
4934 goto err_out_undo_debugfs;
4935
4936 rc = scsi_add_host(shost, dev);
4937 if (rc)
4938 goto err_out_undo_debugfs;
4939
4940 rc = sas_register_ha(sha);
4941 if (rc)
4942 goto err_out_remove_host;
4943
4944 rc = hisi_sas_v3_init(hisi_hba);
4945 if (rc)
4946 goto err_out_unregister_ha;
4947
4948 scsi_scan_host(shost);
4949
4950 pm_runtime_set_autosuspend_delay(dev, 5000);
4951 pm_runtime_use_autosuspend(dev);
4952 /*
4953 * For the situation that there are ATA disks connected with SAS
4954 * controller, it additionally creates ata_port which will affect the
4955 * child_count of hisi_hba->dev. Even if suspended all the disks,
4956 * ata_port is still and the child_count of hisi_hba->dev is not 0.
4957 * So use pm_suspend_ignore_children() to ignore the effect to
4958 * hisi_hba->dev.
4959 */
4960 pm_suspend_ignore_children(dev, true);
4961 pm_runtime_put_noidle(&pdev->dev);
4962
4963 return 0;
4964
4965 err_out_unregister_ha:
4966 sas_unregister_ha(sha);
4967 err_out_remove_host:
4968 scsi_remove_host(shost);
4969 err_out_undo_debugfs:
4970 if (hisi_sas_debugfs_enable)
4971 debugfs_exit_v3_hw(hisi_hba);
4972 err_out_free_host:
4973 hisi_sas_free(hisi_hba);
4974 scsi_host_put(shost);
4975 err_out:
4976 return rc;
4977 }
4978
4979 static void
hisi_sas_v3_destroy_irqs(struct pci_dev * pdev,struct hisi_hba * hisi_hba)4980 hisi_sas_v3_destroy_irqs(struct pci_dev *pdev, struct hisi_hba *hisi_hba)
4981 {
4982 int i;
4983
4984 devm_free_irq(&pdev->dev, pci_irq_vector(pdev, 1), hisi_hba);
4985 devm_free_irq(&pdev->dev, pci_irq_vector(pdev, 2), hisi_hba);
4986 devm_free_irq(&pdev->dev, pci_irq_vector(pdev, 11), hisi_hba);
4987 for (i = 0; i < hisi_hba->cq_nvecs; i++) {
4988 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
4989 int nr = hisi_sas_intr_conv ? 16 : 16 + i;
4990
4991 devm_free_irq(&pdev->dev, pci_irq_vector(pdev, nr), cq);
4992 }
4993 }
4994
hisi_sas_v3_remove(struct pci_dev * pdev)4995 static void hisi_sas_v3_remove(struct pci_dev *pdev)
4996 {
4997 struct device *dev = &pdev->dev;
4998 struct sas_ha_struct *sha = dev_get_drvdata(dev);
4999 struct hisi_hba *hisi_hba = sha->lldd_ha;
5000 struct Scsi_Host *shost = sha->shost;
5001
5002 pm_runtime_get_noresume(dev);
5003
5004 sas_unregister_ha(sha);
5005 flush_workqueue(hisi_hba->wq);
5006 sas_remove_host(shost);
5007
5008 hisi_sas_v3_destroy_irqs(pdev, hisi_hba);
5009 hisi_sas_free(hisi_hba);
5010 if (hisi_sas_debugfs_enable)
5011 debugfs_exit_v3_hw(hisi_hba);
5012
5013 scsi_host_put(shost);
5014 }
5015
hisi_sas_reset_prepare_v3_hw(struct pci_dev * pdev)5016 static void hisi_sas_reset_prepare_v3_hw(struct pci_dev *pdev)
5017 {
5018 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
5019 struct hisi_hba *hisi_hba = sha->lldd_ha;
5020 struct device *dev = hisi_hba->dev;
5021 int rc;
5022
5023 dev_info(dev, "FLR prepare\n");
5024 down(&hisi_hba->sem);
5025 set_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
5026 hisi_sas_controller_reset_prepare(hisi_hba);
5027
5028 interrupt_disable_v3_hw(hisi_hba);
5029 rc = disable_host_v3_hw(hisi_hba);
5030 if (rc)
5031 dev_err(dev, "FLR: disable host failed rc=%d\n", rc);
5032 }
5033
hisi_sas_reset_done_v3_hw(struct pci_dev * pdev)5034 static void hisi_sas_reset_done_v3_hw(struct pci_dev *pdev)
5035 {
5036 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
5037 struct hisi_hba *hisi_hba = sha->lldd_ha;
5038 struct Scsi_Host *shost = hisi_hba->shost;
5039 struct device *dev = hisi_hba->dev;
5040 int rc;
5041
5042 hisi_sas_init_mem(hisi_hba);
5043
5044 rc = hw_init_v3_hw(hisi_hba);
5045 if (rc) {
5046 dev_err(dev, "FLR: hw init failed rc=%d\n", rc);
5047 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
5048 scsi_unblock_requests(shost);
5049 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
5050 up(&hisi_hba->sem);
5051 return;
5052 }
5053
5054 hisi_sas_controller_reset_done(hisi_hba);
5055 dev_info(dev, "FLR done\n");
5056 }
5057
5058 enum {
5059 /* instances of the controller */
5060 hip08,
5061 };
5062
enable_host_v3_hw(struct hisi_hba * hisi_hba)5063 static void enable_host_v3_hw(struct hisi_hba *hisi_hba)
5064 {
5065 u32 reg_val;
5066
5067 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
5068 (u32)((1ULL << hisi_hba->queue_count) - 1));
5069
5070 phys_init_v3_hw(hisi_hba);
5071 reg_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE +
5072 AM_CTRL_GLOBAL);
5073 reg_val &= ~AM_CTRL_SHUTDOWN_REQ_MSK;
5074 hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
5075 AM_CTRL_GLOBAL, reg_val);
5076 }
5077
_suspend_v3_hw(struct device * device)5078 static int _suspend_v3_hw(struct device *device)
5079 {
5080 struct pci_dev *pdev = to_pci_dev(device);
5081 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
5082 struct hisi_hba *hisi_hba = sha->lldd_ha;
5083 struct device *dev = hisi_hba->dev;
5084 struct Scsi_Host *shost = hisi_hba->shost;
5085 int rc;
5086
5087 if (!pdev->pm_cap) {
5088 dev_err(dev, "PCI PM not supported\n");
5089 return -ENODEV;
5090 }
5091
5092 if (test_and_set_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags))
5093 return -EPERM;
5094
5095 dev_warn(dev, "entering suspend state\n");
5096
5097 scsi_block_requests(shost);
5098 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
5099 flush_workqueue(hisi_hba->wq);
5100 interrupt_disable_v3_hw(hisi_hba);
5101
5102 #ifdef CONFIG_PM
5103 if (atomic_read(&device->power.usage_count)) {
5104 dev_err(dev, "PM suspend: host status cannot be suspended\n");
5105 rc = -EBUSY;
5106 goto err_out;
5107 }
5108 #endif
5109
5110 rc = disable_host_v3_hw(hisi_hba);
5111 if (rc) {
5112 dev_err(dev, "PM suspend: disable host failed rc=%d\n", rc);
5113 goto err_out_recover_host;
5114 }
5115
5116 hisi_sas_init_mem(hisi_hba);
5117
5118 hisi_sas_release_tasks(hisi_hba);
5119
5120 sas_suspend_ha(sha);
5121
5122 dev_warn(dev, "end of suspending controller\n");
5123 return 0;
5124
5125 err_out_recover_host:
5126 enable_host_v3_hw(hisi_hba);
5127 #ifdef CONFIG_PM
5128 err_out:
5129 #endif
5130 interrupt_enable_v3_hw(hisi_hba);
5131 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
5132 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
5133 scsi_unblock_requests(shost);
5134 return rc;
5135 }
5136
_resume_v3_hw(struct device * device)5137 static int _resume_v3_hw(struct device *device)
5138 {
5139 struct pci_dev *pdev = to_pci_dev(device);
5140 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
5141 struct hisi_hba *hisi_hba = sha->lldd_ha;
5142 struct Scsi_Host *shost = hisi_hba->shost;
5143 struct device *dev = hisi_hba->dev;
5144 unsigned int rc;
5145 pci_power_t device_state = pdev->current_state;
5146
5147 dev_warn(dev, "resuming from operating state [D%d]\n",
5148 device_state);
5149
5150 scsi_unblock_requests(shost);
5151 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
5152
5153 sas_prep_resume_ha(sha);
5154 rc = hw_init_v3_hw(hisi_hba);
5155 if (rc) {
5156 scsi_remove_host(shost);
5157 return rc;
5158 }
5159 phys_init_v3_hw(hisi_hba);
5160
5161 /*
5162 * If a directly-attached disk is removed during suspend, a deadlock
5163 * may occur, as the PHYE_RESUME_TIMEOUT processing will require the
5164 * hisi_hba->device to be active, which can only happen when resume
5165 * completes. So don't wait for the HA event workqueue to drain upon
5166 * resume.
5167 */
5168 sas_resume_ha_no_sync(sha);
5169 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
5170
5171 dev_warn(dev, "end of resuming controller\n");
5172
5173 return 0;
5174 }
5175
suspend_v3_hw(struct device * device)5176 static int __maybe_unused suspend_v3_hw(struct device *device)
5177 {
5178 struct pci_dev *pdev = to_pci_dev(device);
5179 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
5180 struct hisi_hba *hisi_hba = sha->lldd_ha;
5181 int rc;
5182
5183 set_bit(HISI_SAS_PM_BIT, &hisi_hba->flags);
5184
5185 rc = _suspend_v3_hw(device);
5186 if (rc)
5187 clear_bit(HISI_SAS_PM_BIT, &hisi_hba->flags);
5188
5189 return rc;
5190 }
5191
resume_v3_hw(struct device * device)5192 static int __maybe_unused resume_v3_hw(struct device *device)
5193 {
5194 struct pci_dev *pdev = to_pci_dev(device);
5195 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
5196 struct hisi_hba *hisi_hba = sha->lldd_ha;
5197 int rc = _resume_v3_hw(device);
5198
5199 clear_bit(HISI_SAS_PM_BIT, &hisi_hba->flags);
5200
5201 return rc;
5202 }
5203
5204 static const struct pci_device_id sas_v3_pci_table[] = {
5205 { PCI_VDEVICE(HUAWEI, 0xa230), hip08 },
5206 {}
5207 };
5208 MODULE_DEVICE_TABLE(pci, sas_v3_pci_table);
5209
5210 static const struct pci_error_handlers hisi_sas_err_handler = {
5211 .reset_prepare = hisi_sas_reset_prepare_v3_hw,
5212 .reset_done = hisi_sas_reset_done_v3_hw,
5213 };
5214
5215 static UNIVERSAL_DEV_PM_OPS(hisi_sas_v3_pm_ops,
5216 suspend_v3_hw,
5217 resume_v3_hw,
5218 NULL);
5219
5220 static struct pci_driver sas_v3_pci_driver = {
5221 .name = DRV_NAME,
5222 .id_table = sas_v3_pci_table,
5223 .probe = hisi_sas_v3_probe,
5224 .remove = hisi_sas_v3_remove,
5225 .err_handler = &hisi_sas_err_handler,
5226 .driver.pm = &hisi_sas_v3_pm_ops,
5227 };
5228
5229 module_pci_driver(sas_v3_pci_driver);
5230 module_param_named(intr_conv, hisi_sas_intr_conv, bool, 0444);
5231
5232 MODULE_LICENSE("GPL");
5233 MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
5234 MODULE_DESCRIPTION("HISILICON SAS controller v3 hw driver based on pci device");
5235 MODULE_ALIAS("pci:" DRV_NAME);
5236