]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
scsi: hisi_sas: Make sg_tablesize consistent value
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / hisi_sas / hisi_sas_v3_hw.c
CommitLineData
92f61e3b
JG
1/*
2 * Copyright (c) 2017 Hisilicon Limited.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 */
10
11#include "hisi_sas.h"
12#define DRV_NAME "hisi_sas_v3_hw"
13
c94d8ca2
XC
14/* global registers need init*/
15#define DLVRY_QUEUE_ENABLE 0x0
16#define IOST_BASE_ADDR_LO 0x8
17#define IOST_BASE_ADDR_HI 0xc
18#define ITCT_BASE_ADDR_LO 0x10
19#define ITCT_BASE_ADDR_HI 0x14
20#define IO_BROKEN_MSG_ADDR_LO 0x18
21#define IO_BROKEN_MSG_ADDR_HI 0x1c
3975f605
XC
22#define PHY_CONTEXT 0x20
23#define PHY_STATE 0x24
24#define PHY_PORT_NUM_MA 0x28
25#define PHY_CONN_RATE 0x30
182e7222
XC
26#define ITCT_CLR 0x44
27#define ITCT_CLR_EN_OFF 16
28#define ITCT_CLR_EN_MSK (0x1 << ITCT_CLR_EN_OFF)
29#define ITCT_DEV_OFF 0
30#define ITCT_DEV_MSK (0x7ff << ITCT_DEV_OFF)
c94d8ca2
XC
31#define IO_SATA_BROKEN_MSG_ADDR_LO 0x58
32#define IO_SATA_BROKEN_MSG_ADDR_HI 0x5c
33#define SATA_INITI_D2H_STORE_ADDR_LO 0x60
34#define SATA_INITI_D2H_STORE_ADDR_HI 0x64
35#define CFG_MAX_TAG 0x68
36#define HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL 0x84
37#define HGC_SAS_TXFAIL_RETRY_CTRL 0x88
38#define HGC_GET_ITV_TIME 0x90
39#define DEVICE_MSG_WORK_MODE 0x94
40#define OPENA_WT_CONTI_TIME 0x9c
41#define I_T_NEXUS_LOSS_TIME 0xa0
42#define MAX_CON_TIME_LIMIT_TIME 0xa4
43#define BUS_INACTIVE_LIMIT_TIME 0xa8
44#define REJECT_TO_OPEN_LIMIT_TIME 0xac
6cc8d8f2 45#define CQ_INT_CONVERGE_EN 0xb0
c94d8ca2
XC
46#define CFG_AGING_TIME 0xbc
47#define HGC_DFX_CFG2 0xc0
48#define CFG_ABT_SET_QUERY_IPTT 0xd4
49#define CFG_SET_ABORTED_IPTT_OFF 0
50#define CFG_SET_ABORTED_IPTT_MSK (0xfff << CFG_SET_ABORTED_IPTT_OFF)
d30ff263
XC
51#define CFG_SET_ABORTED_EN_OFF 12
52#define CFG_ABT_SET_IPTT_DONE 0xd8
53#define CFG_ABT_SET_IPTT_DONE_OFF 0
54#define HGC_IOMB_PROC1_STATUS 0x104
3975f605 55#define CHNL_INT_STATUS 0x148
fa231408
XT
56#define HGC_AXI_FIFO_ERR_INFO 0x154
57#define AXI_ERR_INFO_OFF 0
58#define AXI_ERR_INFO_MSK (0xff << AXI_ERR_INFO_OFF)
59#define FIFO_ERR_INFO_OFF 8
60#define FIFO_ERR_INFO_MSK (0xff << FIFO_ERR_INFO_OFF)
c94d8ca2
XC
61#define INT_COAL_EN 0x19c
62#define OQ_INT_COAL_TIME 0x1a0
63#define OQ_INT_COAL_CNT 0x1a4
64#define ENT_INT_COAL_TIME 0x1a8
65#define ENT_INT_COAL_CNT 0x1ac
66#define OQ_INT_SRC 0x1b0
67#define OQ_INT_SRC_MSK 0x1b4
68#define ENT_INT_SRC1 0x1b8
69#define ENT_INT_SRC1_D2H_FIS_CH0_OFF 0
70#define ENT_INT_SRC1_D2H_FIS_CH0_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH0_OFF)
71#define ENT_INT_SRC1_D2H_FIS_CH1_OFF 8
72#define ENT_INT_SRC1_D2H_FIS_CH1_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH1_OFF)
73#define ENT_INT_SRC2 0x1bc
74#define ENT_INT_SRC3 0x1c0
75#define ENT_INT_SRC3_WP_DEPTH_OFF 8
76#define ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF 9
77#define ENT_INT_SRC3_RP_DEPTH_OFF 10
78#define ENT_INT_SRC3_AXI_OFF 11
79#define ENT_INT_SRC3_FIFO_OFF 12
80#define ENT_INT_SRC3_LM_OFF 14
81#define ENT_INT_SRC3_ITC_INT_OFF 15
82#define ENT_INT_SRC3_ITC_INT_MSK (0x1 << ENT_INT_SRC3_ITC_INT_OFF)
83#define ENT_INT_SRC3_ABT_OFF 16
84#define ENT_INT_SRC_MSK1 0x1c4
85#define ENT_INT_SRC_MSK2 0x1c8
86#define ENT_INT_SRC_MSK3 0x1cc
3975f605 87#define ENT_INT_SRC_MSK3_ENT95_MSK_OFF 31
c94d8ca2
XC
88#define CHNL_PHYUPDOWN_INT_MSK 0x1d0
89#define CHNL_ENT_INT_MSK 0x1d4
90#define HGC_COM_INT_MSK 0x1d8
3975f605 91#define ENT_INT_SRC_MSK3_ENT95_MSK_MSK (0x1 << ENT_INT_SRC_MSK3_ENT95_MSK_OFF)
c94d8ca2
XC
92#define SAS_ECC_INTR 0x1e8
93#define SAS_ECC_INTR_MSK 0x1ec
94#define HGC_ERR_STAT_EN 0x238
1a7068b3 95#define CQE_SEND_CNT 0x248
c94d8ca2
XC
96#define DLVRY_Q_0_BASE_ADDR_LO 0x260
97#define DLVRY_Q_0_BASE_ADDR_HI 0x264
98#define DLVRY_Q_0_DEPTH 0x268
99#define DLVRY_Q_0_WR_PTR 0x26c
100#define DLVRY_Q_0_RD_PTR 0x270
101#define HYPER_STREAM_ID_EN_CFG 0xc80
102#define OQ0_INT_SRC_MSK 0xc90
103#define COMPL_Q_0_BASE_ADDR_LO 0x4e0
104#define COMPL_Q_0_BASE_ADDR_HI 0x4e4
105#define COMPL_Q_0_DEPTH 0x4e8
106#define COMPL_Q_0_WR_PTR 0x4ec
107#define COMPL_Q_0_RD_PTR 0x4f0
108#define AWQOS_AWCACHE_CFG 0xc84
109#define ARQOS_ARCACHE_CFG 0xc88
70230be3 110#define HILINK_ERR_DFX 0xe04
e24fe507
XT
111#define SAS_GPIO_CFG_0 0x1000
112#define SAS_GPIO_CFG_1 0x1004
113#define SAS_GPIO_TX_0_1 0x1040
114#define SAS_CFG_DRIVE_VLD 0x1070
c94d8ca2
XC
115
116/* phy registers requiring init */
117#define PORT_BASE (0x2000)
3975f605
XC
118#define PHY_CFG (PORT_BASE + 0x0)
119#define HARD_PHY_LINKRATE (PORT_BASE + 0x4)
120#define PHY_CFG_ENA_OFF 0
121#define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF)
122#define PHY_CFG_DC_OPT_OFF 2
123#define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF)
17d59a57
XT
124#define PHY_CFG_PHY_RST_OFF 3
125#define PHY_CFG_PHY_RST_MSK (0x1 << PHY_CFG_PHY_RST_OFF)
c94d8ca2
XC
126#define PROG_PHY_LINK_RATE (PORT_BASE + 0x8)
127#define PHY_CTRL (PORT_BASE + 0x14)
128#define PHY_CTRL_RESET_OFF 0
129#define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF)
130#define SL_CFG (PORT_BASE + 0x84)
7ab742dc 131#define AIP_LIMIT (PORT_BASE + 0x90)
3975f605
XC
132#define SL_CONTROL (PORT_BASE + 0x94)
133#define SL_CONTROL_NOTIFY_EN_OFF 0
134#define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF)
135#define SL_CTA_OFF 17
136#define SL_CTA_MSK (0x1 << SL_CTA_OFF)
45651175
XT
137#define RX_PRIMS_STATUS (PORT_BASE + 0x98)
138#define RX_BCAST_CHG_OFF 1
139#define RX_BCAST_CHG_MSK (0x1 << RX_BCAST_CHG_OFF)
3975f605
XC
140#define TX_ID_DWORD0 (PORT_BASE + 0x9c)
141#define TX_ID_DWORD1 (PORT_BASE + 0xa0)
142#define TX_ID_DWORD2 (PORT_BASE + 0xa4)
143#define TX_ID_DWORD3 (PORT_BASE + 0xa8)
144#define TX_ID_DWORD4 (PORT_BASE + 0xaC)
145#define TX_ID_DWORD5 (PORT_BASE + 0xb0)
146#define TX_ID_DWORD6 (PORT_BASE + 0xb4)
147#define TXID_AUTO (PORT_BASE + 0xb8)
148#define CT3_OFF 1
149#define CT3_MSK (0x1 << CT3_OFF)
402cd9f0
XC
150#define TX_HARDRST_OFF 2
151#define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF)
3975f605 152#define RX_IDAF_DWORD0 (PORT_BASE + 0xc4)
c94d8ca2 153#define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc)
81036731 154#define STP_LINK_TIMER (PORT_BASE + 0x120)
066312f6 155#define STP_LINK_TIMEOUT_STATE (PORT_BASE + 0x124)
d40bfb0d 156#define CON_CFG_DRIVER (PORT_BASE + 0x130)
c94d8ca2
XC
157#define SAS_SSP_CON_TIMER_CFG (PORT_BASE + 0x134)
158#define SAS_SMP_CON_TIMER_CFG (PORT_BASE + 0x138)
159#define SAS_STP_CON_TIMER_CFG (PORT_BASE + 0x13c)
160#define CHL_INT0 (PORT_BASE + 0x1b4)
161#define CHL_INT0_HOTPLUG_TOUT_OFF 0
162#define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF)
163#define CHL_INT0_SL_RX_BCST_ACK_OFF 1
164#define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF)
165#define CHL_INT0_SL_PHY_ENABLE_OFF 2
166#define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF)
167#define CHL_INT0_NOT_RDY_OFF 4
168#define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF)
169#define CHL_INT0_PHY_RDY_OFF 5
170#define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF)
171#define CHL_INT1 (PORT_BASE + 0x1b8)
172#define CHL_INT1_DMAC_TX_ECC_ERR_OFF 15
173#define CHL_INT1_DMAC_TX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_TX_ECC_ERR_OFF)
174#define CHL_INT1_DMAC_RX_ECC_ERR_OFF 17
175#define CHL_INT1_DMAC_RX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_RX_ECC_ERR_OFF)
4a6125c5
XT
176#define CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF 19
177#define CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF 20
178#define CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF 21
179#define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22
c94d8ca2 180#define CHL_INT2 (PORT_BASE + 0x1bc)
066312f6 181#define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0
70230be3 182#define CHL_INT2_RX_INVLD_DW_OFF 30
066312f6 183#define CHL_INT2_STP_LINK_TIMEOUT_OFF 31
c94d8ca2
XC
184#define CHL_INT0_MSK (PORT_BASE + 0x1c0)
185#define CHL_INT1_MSK (PORT_BASE + 0x1c4)
186#define CHL_INT2_MSK (PORT_BASE + 0x1c8)
187#define CHL_INT_COAL_EN (PORT_BASE + 0x1d0)
2b9174ae 188#define SAS_RX_TRAIN_TIMER (PORT_BASE + 0x2a4)
c94d8ca2
XC
189#define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0)
190#define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4)
191#define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8)
192#define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc)
193#define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0)
194#define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4)
a25d0d3d
XC
195#define DMA_TX_STATUS (PORT_BASE + 0x2d0)
196#define DMA_TX_STATUS_BUSY_OFF 0
197#define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF)
198#define DMA_RX_STATUS (PORT_BASE + 0x2e8)
199#define DMA_RX_STATUS_BUSY_OFF 0
200#define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF)
2b9174ae
XT
201
202#define COARSETUNE_TIME (PORT_BASE + 0x304)
ffc8f149
XT
203#define ERR_CNT_DWS_LOST (PORT_BASE + 0x380)
204#define ERR_CNT_RESET_PROB (PORT_BASE + 0x384)
205#define ERR_CNT_INVLD_DW (PORT_BASE + 0x390)
206#define ERR_CNT_DISP_ERR (PORT_BASE + 0x398)
a25d0d3d 207
a25d0d3d
XC
208#define DEFAULT_ITCT_HW 2048 /* reset value, not reprogrammed */
209#if (HISI_SAS_MAX_DEVICES > DEFAULT_ITCT_HW)
210#error Max ITCT exceeded
211#endif
212
213#define AXI_MASTER_CFG_BASE (0x5000)
214#define AM_CTRL_GLOBAL (0x0)
1d51757d
XT
215#define AM_CTRL_SHUTDOWN_REQ_OFF 0
216#define AM_CTRL_SHUTDOWN_REQ_MSK (0x1 << AM_CTRL_SHUTDOWN_REQ_OFF)
a25d0d3d
XC
217#define AM_CURR_TRANS_RETURN (0x150)
218
219#define AM_CFG_MAX_TRANS (0x5010)
220#define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014)
221#define AXI_CFG (0x5100)
222#define AM_ROB_ECC_ERR_ADDR (0x510c)
223#define AM_ROB_ECC_ONEBIT_ERR_ADDR_OFF 0
224#define AM_ROB_ECC_ONEBIT_ERR_ADDR_MSK (0xff << AM_ROB_ECC_ONEBIT_ERR_ADDR_OFF)
225#define AM_ROB_ECC_MULBIT_ERR_ADDR_OFF 8
226#define AM_ROB_ECC_MULBIT_ERR_ADDR_MSK (0xff << AM_ROB_ECC_MULBIT_ERR_ADDR_OFF)
c94d8ca2 227
56b72168
XT
228/* RAS registers need init */
229#define RAS_BASE (0x6000)
230#define SAS_RAS_INTR0 (RAS_BASE)
231#define SAS_RAS_INTR1 (RAS_BASE + 0x04)
232#define SAS_RAS_INTR0_MASK (RAS_BASE + 0x08)
233#define SAS_RAS_INTR1_MASK (RAS_BASE + 0x0c)
c13c7ac5
XT
234#define CFG_SAS_RAS_INTR_MASK (RAS_BASE + 0x1c)
235#define SAS_RAS_INTR2 (RAS_BASE + 0x20)
236#define SAS_RAS_INTR2_MASK (RAS_BASE + 0x24)
56b72168 237
a2204723
XC
238/* HW dma structures */
239/* Delivery queue header */
240/* dw0 */
4de0ca69
XC
241#define CMD_HDR_ABORT_FLAG_OFF 0
242#define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF)
243#define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2
244#define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF)
a2204723
XC
245#define CMD_HDR_RESP_REPORT_OFF 5
246#define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF)
247#define CMD_HDR_TLR_CTRL_OFF 6
248#define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF)
249#define CMD_HDR_PORT_OFF 18
250#define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF)
251#define CMD_HDR_PRIORITY_OFF 27
252#define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF)
253#define CMD_HDR_CMD_OFF 29
254#define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF)
255/* dw1 */
ce60689e 256#define CMD_HDR_UNCON_CMD_OFF 3
a2204723
XC
257#define CMD_HDR_DIR_OFF 5
258#define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF)
ce60689e
XC
259#define CMD_HDR_RESET_OFF 7
260#define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF)
a2204723
XC
261#define CMD_HDR_VDTL_OFF 10
262#define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF)
263#define CMD_HDR_FRAME_TYPE_OFF 11
264#define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF)
265#define CMD_HDR_DEV_ID_OFF 16
266#define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF)
267/* dw2 */
268#define CMD_HDR_CFL_OFF 0
269#define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF)
ce60689e
XC
270#define CMD_HDR_NCQ_TAG_OFF 10
271#define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF)
a2204723
XC
272#define CMD_HDR_MRFL_OFF 15
273#define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF)
274#define CMD_HDR_SG_MOD_OFF 24
275#define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF)
fa913de2
XC
276/* dw3 */
277#define CMD_HDR_IPTT_OFF 0
278#define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF)
a2204723
XC
279/* dw6 */
280#define CMD_HDR_DIF_SGL_LEN_OFF 0
281#define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF)
282#define CMD_HDR_DATA_SGL_LEN_OFF 16
283#define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF)
4de0ca69
XC
284/* dw7 */
285#define CMD_HDR_ADDR_MODE_SEL_OFF 15
286#define CMD_HDR_ADDR_MODE_SEL_MSK (1 << CMD_HDR_ADDR_MODE_SEL_OFF)
287#define CMD_HDR_ABORT_IPTT_OFF 16
288#define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF)
a2204723 289
60b4a5ee
XC
290/* Completion header */
291/* dw0 */
292#define CMPLT_HDR_CMPLT_OFF 0
293#define CMPLT_HDR_CMPLT_MSK (0x3 << CMPLT_HDR_CMPLT_OFF)
294#define CMPLT_HDR_ERROR_PHASE_OFF 2
295#define CMPLT_HDR_ERROR_PHASE_MSK (0xff << CMPLT_HDR_ERROR_PHASE_OFF)
296#define CMPLT_HDR_RSPNS_XFRD_OFF 10
297#define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF)
298#define CMPLT_HDR_ERX_OFF 12
299#define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF)
300#define CMPLT_HDR_ABORT_STAT_OFF 13
301#define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF)
302/* abort_stat */
303#define STAT_IO_NOT_VALID 0x1
304#define STAT_IO_NO_DEVICE 0x2
305#define STAT_IO_COMPLETE 0x3
306#define STAT_IO_ABORTED 0x4
307/* dw1 */
308#define CMPLT_HDR_IPTT_OFF 0
309#define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF)
310#define CMPLT_HDR_DEV_ID_OFF 16
311#define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF)
312/* dw3 */
313#define CMPLT_HDR_IO_IN_TARGET_OFF 17
314#define CMPLT_HDR_IO_IN_TARGET_MSK (0x1 << CMPLT_HDR_IO_IN_TARGET_OFF)
315
182e7222
XC
316/* ITCT header */
317/* qw0 */
318#define ITCT_HDR_DEV_TYPE_OFF 0
319#define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF)
320#define ITCT_HDR_VALID_OFF 2
321#define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF)
322#define ITCT_HDR_MCR_OFF 5
323#define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF)
324#define ITCT_HDR_VLN_OFF 9
325#define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF)
326#define ITCT_HDR_SMP_TIMEOUT_OFF 16
327#define ITCT_HDR_AWT_CONTINUE_OFF 25
328#define ITCT_HDR_PORT_ID_OFF 28
329#define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF)
330/* qw2 */
331#define ITCT_HDR_INLT_OFF 0
332#define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF)
333#define ITCT_HDR_RTOLT_OFF 48
334#define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF)
335
c94d8ca2
XC
336struct hisi_sas_complete_v3_hdr {
337 __le32 dw0;
338 __le32 dw1;
339 __le32 act;
340 __le32 dw3;
341};
342
60b4a5ee
XC
343struct hisi_sas_err_record_v3 {
344 /* dw0 */
345 __le32 trans_tx_fail_type;
346
347 /* dw1 */
348 __le32 trans_rx_fail_type;
349
350 /* dw2 */
351 __le16 dma_tx_err_type;
352 __le16 sipc_rx_err_type;
353
354 /* dw3 */
355 __le32 dma_rx_err_type;
356};
357
358#define RX_DATA_LEN_UNDERFLOW_OFF 6
359#define RX_DATA_LEN_UNDERFLOW_MSK (1 << RX_DATA_LEN_UNDERFLOW_OFF)
360
c94d8ca2 361#define HISI_SAS_COMMAND_ENTRIES_V3_HW 4096
3975f605
XC
362#define HISI_SAS_MSI_COUNT_V3_HW 32
363
a2204723
XC
364#define DIR_NO_DATA 0
365#define DIR_TO_INI 1
366#define DIR_TO_DEVICE 2
367#define DIR_RESERVED 3
368
ed80f9c4
XC
369#define FIS_CMD_IS_UNCONSTRAINED(fis) \
370 ((fis.command == ATA_CMD_READ_LOG_EXT) || \
371 (fis.command == ATA_CMD_READ_LOG_DMA_EXT) || \
372 ((fis.command == ATA_CMD_DEV_RESET) && \
373 ((fis.control & ATA_SRST) != 0)))
ce60689e 374
6cc8d8f2
XC
375static bool hisi_sas_intr_conv;
376MODULE_PARM_DESC(intr_conv, "interrupt converge enable (0-1)");
377
54edeee1
XC
378static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
379{
380 void __iomem *regs = hisi_hba->regs + off;
381
382 return readl(regs);
383}
384
a2204723
XC
385static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off)
386{
387 void __iomem *regs = hisi_hba->regs + off;
388
389 return readl_relaxed(regs);
390}
391
c94d8ca2
XC
392static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val)
393{
394 void __iomem *regs = hisi_hba->regs + off;
395
396 writel(val, regs);
397}
398
399static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no,
400 u32 off, u32 val)
401{
402 void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
403
404 writel(val, regs);
405}
406
3975f605
XC
407static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
408 int phy_no, u32 off)
409{
410 void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
411
412 return readl(regs);
413}
414
70bfdcae
JG
415#define hisi_sas_read32_poll_timeout(off, val, cond, delay_us, \
416 timeout_us) \
417({ \
418 void __iomem *regs = hisi_hba->regs + off; \
419 readl_poll_timeout(regs, val, cond, delay_us, timeout_us); \
420})
421
422#define hisi_sas_read32_poll_timeout_atomic(off, val, cond, delay_us, \
423 timeout_us) \
424({ \
425 void __iomem *regs = hisi_hba->regs + off; \
426 readl_poll_timeout_atomic(regs, val, cond, delay_us, timeout_us);\
427})
428
c94d8ca2
XC
429static void init_reg_v3_hw(struct hisi_hba *hisi_hba)
430{
c13c7ac5 431 struct pci_dev *pdev = hisi_hba->pci_dev;
c94d8ca2
XC
432 int i;
433
434 /* Global registers init */
435 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
436 (u32)((1ULL << hisi_hba->queue_count) - 1));
3297ded1 437 hisi_sas_write32(hisi_hba, CFG_MAX_TAG, 0xfff0400);
c94d8ca2 438 hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x108);
7ab742dc 439 hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1);
c94d8ca2
XC
440 hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1);
441 hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1);
442 hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1);
6cc8d8f2
XC
443 hisi_sas_write32(hisi_hba, CQ_INT_CONVERGE_EN,
444 hisi_sas_intr_conv);
c94d8ca2
XC
445 hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0xffff);
446 hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
447 hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
448 hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff);
449 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xfefefefe);
450 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xfefefefe);
c13c7ac5 451 if (pdev->revision >= 0x21)
f0b06432 452 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffff7aff);
c13c7ac5
XT
453 else
454 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xfffe20ff);
c94d8ca2
XC
455 hisi_sas_write32(hisi_hba, CHNL_PHYUPDOWN_INT_MSK, 0x0);
456 hisi_sas_write32(hisi_hba, CHNL_ENT_INT_MSK, 0x0);
457 hisi_sas_write32(hisi_hba, HGC_COM_INT_MSK, 0x0);
056e4cc6 458 hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0x0);
c94d8ca2
XC
459 hisi_sas_write32(hisi_hba, AWQOS_AWCACHE_CFG, 0xf0f0);
460 hisi_sas_write32(hisi_hba, ARQOS_ARCACHE_CFG, 0xf0f0);
461 for (i = 0; i < hisi_hba->queue_count; i++)
462 hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0);
463
c94d8ca2 464 hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1);
c94d8ca2
XC
465
466 for (i = 0; i < hisi_hba->n_phy; i++) {
f385b4ff
XC
467 struct hisi_sas_phy *phy = &hisi_hba->phy[i];
468 struct asd_sas_phy *sas_phy = &phy->sas_phy;
469 u32 prog_phy_link_rate = 0x800;
470
471 if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate <
472 SAS_LINK_RATE_1_5_GBPS)) {
473 prog_phy_link_rate = 0x855;
474 } else {
475 enum sas_linkrate max = sas_phy->phy->maximum_linkrate;
476
477 prog_phy_link_rate =
478 hisi_sas_get_prog_phy_linkrate_mask(max) |
479 0x800;
480 }
481 hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE,
482 prog_phy_link_rate);
2b9174ae 483 hisi_sas_phy_write32(hisi_hba, i, SAS_RX_TRAIN_TIMER, 0x13e80);
c94d8ca2
XC
484 hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff);
485 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff);
486 hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xffffffff);
487 hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
c13c7ac5
XT
488 if (pdev->revision >= 0x21)
489 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK,
490 0xffffffff);
491 else
492 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK,
493 0xff87ffff);
066312f6 494 hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffbfe);
c94d8ca2
XC
495 hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0);
496 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0);
497 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0);
498 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0);
499 hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0);
2b9174ae
XT
500 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x1);
501 hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, 0x7f7a120);
fe058330 502 hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x2a0a01);
806561bf 503 hisi_sas_phy_write32(hisi_hba, i, SAS_SSP_CON_TIMER_CFG, 0x32);
2b9174ae
XT
504 /* used for 12G negotiate */
505 hisi_sas_phy_write32(hisi_hba, i, COARSETUNE_TIME, 0x1e);
7ab742dc 506 hisi_sas_phy_write32(hisi_hba, i, AIP_LIMIT, 0x2ffff);
c94d8ca2 507 }
2b9174ae 508
c94d8ca2
XC
509 for (i = 0; i < hisi_hba->queue_count; i++) {
510 /* Delivery queue */
511 hisi_sas_write32(hisi_hba,
512 DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
513 upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
514
515 hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
516 lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
517
518 hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14),
519 HISI_SAS_QUEUE_SLOTS);
520
521 /* Completion queue */
522 hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
523 upper_32_bits(hisi_hba->complete_hdr_dma[i]));
524
525 hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
526 lower_32_bits(hisi_hba->complete_hdr_dma[i]));
527
528 hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
529 HISI_SAS_QUEUE_SLOTS);
530 }
531
532 /* itct */
533 hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
534 lower_32_bits(hisi_hba->itct_dma));
535
536 hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
537 upper_32_bits(hisi_hba->itct_dma));
538
539 /* iost */
540 hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
541 lower_32_bits(hisi_hba->iost_dma));
542
543 hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
544 upper_32_bits(hisi_hba->iost_dma));
545
546 /* breakpoint */
547 hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO,
548 lower_32_bits(hisi_hba->breakpoint_dma));
549
550 hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI,
551 upper_32_bits(hisi_hba->breakpoint_dma));
552
553 /* SATA broken msg */
554 hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO,
555 lower_32_bits(hisi_hba->sata_breakpoint_dma));
556
557 hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI,
558 upper_32_bits(hisi_hba->sata_breakpoint_dma));
559
560 /* SATA initial fis */
561 hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO,
562 lower_32_bits(hisi_hba->initial_fis_dma));
563
564 hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI,
565 upper_32_bits(hisi_hba->initial_fis_dma));
56b72168
XT
566
567 /* RAS registers init */
568 hisi_sas_write32(hisi_hba, SAS_RAS_INTR0_MASK, 0x0);
569 hisi_sas_write32(hisi_hba, SAS_RAS_INTR1_MASK, 0x0);
c13c7ac5
XT
570 hisi_sas_write32(hisi_hba, SAS_RAS_INTR2_MASK, 0x0);
571 hisi_sas_write32(hisi_hba, CFG_SAS_RAS_INTR_MASK, 0x0);
e24fe507
XT
572
573 /* LED registers init */
574 hisi_sas_write32(hisi_hba, SAS_CFG_DRIVE_VLD, 0x80000ff);
575 hisi_sas_write32(hisi_hba, SAS_GPIO_TX_0_1, 0x80808080);
576 hisi_sas_write32(hisi_hba, SAS_GPIO_TX_0_1 + 0x4, 0x80808080);
577 /* Configure blink generator rate A to 1Hz and B to 4Hz */
578 hisi_sas_write32(hisi_hba, SAS_GPIO_CFG_1, 0x121700);
579 hisi_sas_write32(hisi_hba, SAS_GPIO_CFG_0, 0x800000);
c94d8ca2
XC
580}
581
3975f605
XC
582static void config_phy_opt_mode_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
583{
584 u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
585
586 cfg &= ~PHY_CFG_DC_OPT_MSK;
587 cfg |= 1 << PHY_CFG_DC_OPT_OFF;
588 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
589}
590
591static void config_id_frame_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
592{
593 struct sas_identify_frame identify_frame;
594 u32 *identify_buffer;
595
596 memset(&identify_frame, 0, sizeof(identify_frame));
597 identify_frame.dev_type = SAS_END_DEVICE;
598 identify_frame.frame_type = 0;
599 identify_frame._un1 = 1;
600 identify_frame.initiator_bits = SAS_PROTOCOL_ALL;
601 identify_frame.target_bits = SAS_PROTOCOL_NONE;
602 memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
603 memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
604 identify_frame.phy_id = phy_no;
605 identify_buffer = (u32 *)(&identify_frame);
606
607 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0,
608 __swab32(identify_buffer[0]));
609 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1,
610 __swab32(identify_buffer[1]));
611 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2,
612 __swab32(identify_buffer[2]));
613 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3,
614 __swab32(identify_buffer[3]));
615 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4,
616 __swab32(identify_buffer[4]));
617 hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5,
618 __swab32(identify_buffer[5]));
619}
620
182e7222
XC
621static void setup_itct_v3_hw(struct hisi_hba *hisi_hba,
622 struct hisi_sas_device *sas_dev)
623{
624 struct domain_device *device = sas_dev->sas_device;
625 struct device *dev = hisi_hba->dev;
626 u64 qw0, device_id = sas_dev->device_id;
627 struct hisi_sas_itct *itct = &hisi_hba->itct[device_id];
628 struct domain_device *parent_dev = device->parent;
629 struct asd_sas_port *sas_port = device->port;
630 struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
b8438c40 631 u64 sas_addr;
182e7222
XC
632
633 memset(itct, 0, sizeof(*itct));
634
635 /* qw0 */
636 qw0 = 0;
637 switch (sas_dev->dev_type) {
638 case SAS_END_DEVICE:
639 case SAS_EDGE_EXPANDER_DEVICE:
640 case SAS_FANOUT_EXPANDER_DEVICE:
641 qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
642 break;
643 case SAS_SATA_DEV:
644 case SAS_SATA_PENDING:
645 if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
646 qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF;
647 else
648 qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF;
649 break;
650 default:
651 dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
652 sas_dev->dev_type);
653 }
654
655 qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
656 (device->linkrate << ITCT_HDR_MCR_OFF) |
657 (1 << ITCT_HDR_VLN_OFF) |
658 (0xfa << ITCT_HDR_SMP_TIMEOUT_OFF) |
659 (1 << ITCT_HDR_AWT_CONTINUE_OFF) |
660 (port->id << ITCT_HDR_PORT_ID_OFF));
661 itct->qw0 = cpu_to_le64(qw0);
662
663 /* qw1 */
b8438c40
JG
664 memcpy(&sas_addr, device->sas_addr, SAS_ADDR_SIZE);
665 itct->sas_addr = cpu_to_le64(__swab64(sas_addr));
182e7222
XC
666
667 /* qw2 */
668 if (!dev_is_sata(device))
669 itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) |
670 (0x1ULL << ITCT_HDR_RTOLT_OFF));
671}
672
f39943ee 673static void clear_itct_v3_hw(struct hisi_hba *hisi_hba,
182e7222
XC
674 struct hisi_sas_device *sas_dev)
675{
13cd5ed6 676 DECLARE_COMPLETION_ONSTACK(completion);
182e7222 677 u64 dev_id = sas_dev->device_id;
182e7222
XC
678 struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
679 u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
680
13cd5ed6
XC
681 sas_dev->completion = &completion;
682
182e7222
XC
683 /* clear the itct interrupt state */
684 if (ENT_INT_SRC3_ITC_INT_MSK & reg_val)
685 hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
686 ENT_INT_SRC3_ITC_INT_MSK);
687
688 /* clear the itct table*/
13cd5ed6 689 reg_val = ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK);
182e7222
XC
690 hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val);
691
13cd5ed6
XC
692 wait_for_completion(sas_dev->completion);
693 memset(itct, 0, sizeof(struct hisi_sas_itct));
182e7222
XC
694}
695
d30ff263
XC
696static void dereg_device_v3_hw(struct hisi_hba *hisi_hba,
697 struct domain_device *device)
698{
699 struct hisi_sas_slot *slot, *slot2;
700 struct hisi_sas_device *sas_dev = device->lldd_dev;
701 u32 cfg_abt_set_query_iptt;
702
703 cfg_abt_set_query_iptt = hisi_sas_read32(hisi_hba,
704 CFG_ABT_SET_QUERY_IPTT);
705 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) {
706 cfg_abt_set_query_iptt &= ~CFG_SET_ABORTED_IPTT_MSK;
707 cfg_abt_set_query_iptt |= (1 << CFG_SET_ABORTED_EN_OFF) |
708 (slot->idx << CFG_SET_ABORTED_IPTT_OFF);
709 hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT,
710 cfg_abt_set_query_iptt);
711 }
712 cfg_abt_set_query_iptt &= ~(1 << CFG_SET_ABORTED_EN_OFF);
713 hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT,
714 cfg_abt_set_query_iptt);
715 hisi_sas_write32(hisi_hba, CFG_ABT_SET_IPTT_DONE,
716 1 << CFG_ABT_SET_IPTT_DONE_OFF);
717}
718
a25d0d3d
XC
719static int reset_hw_v3_hw(struct hisi_hba *hisi_hba)
720{
721 struct device *dev = hisi_hba->dev;
722 int ret;
723 u32 val;
724
725 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
726
727 /* Disable all of the PHYs */
728 hisi_sas_stop_phys(hisi_hba);
729 udelay(50);
730
731 /* Ensure axi bus idle */
70bfdcae
JG
732 ret = hisi_sas_read32_poll_timeout(AXI_CFG, val, !val,
733 20000, 1000000);
a25d0d3d
XC
734 if (ret) {
735 dev_err(dev, "axi bus is not idle, ret = %d!\n", ret);
736 return -EIO;
737 }
738
739 if (ACPI_HANDLE(dev)) {
740 acpi_status s;
741
742 s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
743 if (ACPI_FAILURE(s)) {
744 dev_err(dev, "Reset failed\n");
745 return -EIO;
746 }
bcbc7f1c 747 } else {
a25d0d3d 748 dev_err(dev, "no reset method!\n");
bcbc7f1c
XC
749 return -EINVAL;
750 }
a25d0d3d
XC
751
752 return 0;
753}
754
c94d8ca2
XC
755static int hw_init_v3_hw(struct hisi_hba *hisi_hba)
756{
a25d0d3d
XC
757 struct device *dev = hisi_hba->dev;
758 int rc;
759
760 rc = reset_hw_v3_hw(hisi_hba);
761 if (rc) {
762 dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc);
763 return rc;
764 }
765
766 msleep(100);
c94d8ca2
XC
767 init_reg_v3_hw(hisi_hba);
768
769 return 0;
770}
771
3975f605
XC
772static void enable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
773{
774 u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
775
776 cfg |= PHY_CFG_ENA_MSK;
17d59a57 777 cfg &= ~PHY_CFG_PHY_RST_MSK;
3975f605
XC
778 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
779}
780
402cd9f0
XC
781static void disable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
782{
783 u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
17d59a57 784 u32 state;
402cd9f0
XC
785
786 cfg &= ~PHY_CFG_ENA_MSK;
787 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
17d59a57
XT
788
789 mdelay(50);
790
791 state = hisi_sas_read32(hisi_hba, PHY_STATE);
792 if (state & BIT(phy_no)) {
793 cfg |= PHY_CFG_PHY_RST_MSK;
794 hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
795 }
402cd9f0
XC
796}
797
3975f605
XC
798static void start_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
799{
800 config_id_frame_v3_hw(hisi_hba, phy_no);
801 config_phy_opt_mode_v3_hw(hisi_hba, phy_no);
802 enable_phy_v3_hw(hisi_hba, phy_no);
803}
804
402cd9f0
XC
805static void phy_hard_reset_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
806{
807 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
808 u32 txid_auto;
809
a25d0d3d 810 disable_phy_v3_hw(hisi_hba, phy_no);
402cd9f0
XC
811 if (phy->identify.device_type == SAS_END_DEVICE) {
812 txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
813 hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
814 txid_auto | TX_HARDRST_MSK);
815 }
816 msleep(100);
817 start_phy_v3_hw(hisi_hba, phy_no);
818}
819
bcbc7f1c 820static enum sas_linkrate phy_get_max_linkrate_v3_hw(void)
402cd9f0
XC
821{
822 return SAS_LINK_RATE_12_0_GBPS;
823}
824
3975f605
XC
825static void phys_init_v3_hw(struct hisi_hba *hisi_hba)
826{
a25d0d3d
XC
827 int i;
828
829 for (i = 0; i < hisi_hba->n_phy; i++) {
830 struct hisi_sas_phy *phy = &hisi_hba->phy[i];
831 struct asd_sas_phy *sas_phy = &phy->sas_phy;
832
833 if (!sas_phy->phy->enabled)
834 continue;
835
836 start_phy_v3_hw(hisi_hba, i);
837 }
3975f605
XC
838}
839
840static void sl_notify_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
841{
842 u32 sl_control;
843
844 sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
845 sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
846 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
847 msleep(1);
848 sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
849 sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
850 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
851}
852
f771d3b0
XC
853static int get_wideport_bitmap_v3_hw(struct hisi_hba *hisi_hba, int port_id)
854{
855 int i, bitmap = 0;
856 u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
0e3231fc 857 u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
f771d3b0
XC
858
859 for (i = 0; i < hisi_hba->n_phy; i++)
0e3231fc
XT
860 if (phy_state & BIT(i))
861 if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
862 bitmap |= BIT(i);
f771d3b0
XC
863
864 return bitmap;
865}
866
a2204723
XC
867/**
868 * The callpath to this function and upto writing the write
869 * queue pointer should be safe from interruption.
870 */
871static int
872get_free_slot_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
873{
874 struct device *dev = hisi_hba->dev;
875 int queue = dq->id;
876 u32 r, w;
877
878 w = dq->wr_point;
879 r = hisi_sas_read32_relaxed(hisi_hba,
880 DLVRY_Q_0_RD_PTR + (queue * 0x14));
881 if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
c58ec824 882 dev_warn(dev, "full queue=%d r=%d w=%d\n",
a2204723
XC
883 queue, r, w);
884 return -EAGAIN;
885 }
886
c58ec824
XC
887 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
888
889 return w;
a2204723
XC
890}
891
892static void start_delivery_v3_hw(struct hisi_sas_dq *dq)
893{
894 struct hisi_hba *hisi_hba = dq->hisi_hba;
5a61a535 895 struct hisi_sas_slot *s, *s1, *s2 = NULL;
c58ec824 896 int dlvry_queue = dq->id;
5a61a535 897 int wp;
c58ec824 898
c58ec824
XC
899 list_for_each_entry_safe(s, s1, &dq->list, delivery) {
900 if (!s->ready)
901 break;
5a61a535 902 s2 = s;
c58ec824
XC
903 list_del(&s->delivery);
904 }
905
5a61a535 906 if (!s2)
c58ec824 907 return;
a2204723 908
5a61a535
XT
909 /*
910 * Ensure that memories for slots built on other CPUs is observed.
911 */
912 smp_rmb();
913 wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
914
c58ec824 915 hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
a2204723
XC
916}
917
81d115ec 918static void prep_prd_sge_v3_hw(struct hisi_hba *hisi_hba,
a2204723
XC
919 struct hisi_sas_slot *slot,
920 struct hisi_sas_cmd_hdr *hdr,
921 struct scatterlist *scatter,
922 int n_elem)
923{
f557e32c 924 struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
a2204723
XC
925 struct scatterlist *sg;
926 int i;
927
a2204723 928 for_each_sg(scatter, sg, n_elem, i) {
f557e32c 929 struct hisi_sas_sge *entry = &sge_page->sge[i];
a2204723
XC
930
931 entry->addr = cpu_to_le64(sg_dma_address(sg));
932 entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
933 entry->data_len = cpu_to_le32(sg_dma_len(sg));
934 entry->data_off = 0;
935 }
936
f557e32c
XT
937 hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
938
a2204723 939 hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
a2204723
XC
940}
941
81d115ec 942static void prep_ssp_v3_hw(struct hisi_hba *hisi_hba,
9a98d728 943 struct hisi_sas_slot *slot)
a2204723
XC
944{
945 struct sas_task *task = slot->task;
946 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
947 struct domain_device *device = task->dev;
948 struct hisi_sas_device *sas_dev = device->lldd_dev;
949 struct hisi_sas_port *port = slot->port;
950 struct sas_ssp_task *ssp_task = &task->ssp_task;
951 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
9a98d728
XT
952 struct hisi_sas_tmf_task *tmf = slot->tmf;
953 int has_data = 0, priority = !!tmf;
a2204723
XC
954 u8 *buf_cmd;
955 u32 dw1 = 0, dw2 = 0;
956
957 hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
958 (2 << CMD_HDR_TLR_CTRL_OFF) |
959 (port->id << CMD_HDR_PORT_OFF) |
960 (priority << CMD_HDR_PRIORITY_OFF) |
961 (1 << CMD_HDR_CMD_OFF)); /* ssp */
962
963 dw1 = 1 << CMD_HDR_VDTL_OFF;
9a98d728 964 if (tmf) {
a2204723
XC
965 dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF;
966 dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF;
967 } else {
968 dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF;
969 switch (scsi_cmnd->sc_data_direction) {
970 case DMA_TO_DEVICE:
971 has_data = 1;
972 dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
973 break;
974 case DMA_FROM_DEVICE:
975 has_data = 1;
976 dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
977 break;
978 default:
979 dw1 &= ~CMD_HDR_DIR_MSK;
980 }
981 }
982
983 /* map itct entry */
984 dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
985 hdr->dw1 = cpu_to_le32(dw1);
986
987 dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr)
988 + 3) / 4) << CMD_HDR_CFL_OFF) |
989 ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) |
990 (2 << CMD_HDR_SG_MOD_OFF);
991 hdr->dw2 = cpu_to_le32(dw2);
992 hdr->transfer_tags = cpu_to_le32(slot->idx);
993
81d115ec
XC
994 if (has_data)
995 prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter,
a2204723 996 slot->n_elem);
a2204723
XC
997
998 hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
f557e32c
XT
999 hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
1000 hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
a2204723 1001
f557e32c
XT
1002 buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
1003 sizeof(struct ssp_frame_hdr);
a2204723 1004
f557e32c 1005 memcpy(buf_cmd, &task->ssp_task.LUN, 8);
9a98d728 1006 if (!tmf) {
a2204723
XC
1007 buf_cmd[9] = ssp_task->task_attr | (ssp_task->task_prio << 3);
1008 memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
1009 } else {
1010 buf_cmd[10] = tmf->tmf;
1011 switch (tmf->tmf) {
1012 case TMF_ABORT_TASK:
1013 case TMF_QUERY_TASK:
1014 buf_cmd[12] =
1015 (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
1016 buf_cmd[13] =
1017 tmf->tag_of_task_to_be_managed & 0xff;
1018 break;
1019 default:
1020 break;
1021 }
1022 }
a2204723
XC
1023}
1024
81d115ec 1025static void prep_smp_v3_hw(struct hisi_hba *hisi_hba,
fa913de2
XC
1026 struct hisi_sas_slot *slot)
1027{
1028 struct sas_task *task = slot->task;
1029 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1030 struct domain_device *device = task->dev;
fa913de2 1031 struct hisi_sas_port *port = slot->port;
8118ae07 1032 struct scatterlist *sg_req;
fa913de2
XC
1033 struct hisi_sas_device *sas_dev = device->lldd_dev;
1034 dma_addr_t req_dma_addr;
8118ae07 1035 unsigned int req_len;
fa913de2 1036
fa913de2
XC
1037 /* req */
1038 sg_req = &task->smp_task.smp_req;
fa913de2
XC
1039 req_len = sg_dma_len(sg_req);
1040 req_dma_addr = sg_dma_address(sg_req);
1041
fa913de2
XC
1042 /* create header */
1043 /* dw0 */
1044 hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
1045 (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
1046 (2 << CMD_HDR_CMD_OFF)); /* smp */
1047
1048 /* map itct entry */
1049 hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) |
1050 (1 << CMD_HDR_FRAME_TYPE_OFF) |
1051 (DIR_NO_DATA << CMD_HDR_DIR_OFF));
1052
1053 /* dw2 */
1054 hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) |
1055 (HISI_SAS_MAX_SMP_RESP_SZ / 4 <<
1056 CMD_HDR_MRFL_OFF));
1057
1058 hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
1059
1060 hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
f557e32c 1061 hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
fa913de2 1062
fa913de2
XC
1063}
1064
81d115ec 1065static void prep_ata_v3_hw(struct hisi_hba *hisi_hba,
ce60689e
XC
1066 struct hisi_sas_slot *slot)
1067{
1068 struct sas_task *task = slot->task;
1069 struct domain_device *device = task->dev;
1070 struct domain_device *parent_dev = device->parent;
1071 struct hisi_sas_device *sas_dev = device->lldd_dev;
1072 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1073 struct asd_sas_port *sas_port = device->port;
1074 struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
1075 u8 *buf_cmd;
81d115ec 1076 int has_data = 0, hdr_tag = 0;
ce60689e
XC
1077 u32 dw1 = 0, dw2 = 0;
1078
1079 hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF);
1080 if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
1081 hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF);
1082 else
1083 hdr->dw0 |= cpu_to_le32(4 << CMD_HDR_CMD_OFF);
1084
1085 switch (task->data_dir) {
1086 case DMA_TO_DEVICE:
1087 has_data = 1;
1088 dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
1089 break;
1090 case DMA_FROM_DEVICE:
1091 has_data = 1;
1092 dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
1093 break;
1094 default:
1095 dw1 &= ~CMD_HDR_DIR_MSK;
1096 }
1097
1098 if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) &&
1099 (task->ata_task.fis.control & ATA_SRST))
1100 dw1 |= 1 << CMD_HDR_RESET_OFF;
1101
1102 dw1 |= (hisi_sas_get_ata_protocol(
ba0bb2be 1103 &task->ata_task.fis, task->data_dir))
ce60689e
XC
1104 << CMD_HDR_FRAME_TYPE_OFF;
1105 dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
1106
ed80f9c4 1107 if (FIS_CMD_IS_UNCONSTRAINED(task->ata_task.fis))
ce60689e
XC
1108 dw1 |= 1 << CMD_HDR_UNCON_CMD_OFF;
1109
1110 hdr->dw1 = cpu_to_le32(dw1);
1111
1112 /* dw2 */
8ae6725d 1113 if (task->ata_task.use_ncq && hisi_sas_get_ncq_tag(task, &hdr_tag)) {
ce60689e
XC
1114 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
1115 dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF;
1116 }
1117
1118 dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF |
1119 2 << CMD_HDR_SG_MOD_OFF;
1120 hdr->dw2 = cpu_to_le32(dw2);
1121
1122 /* dw3 */
1123 hdr->transfer_tags = cpu_to_le32(slot->idx);
1124
81d115ec
XC
1125 if (has_data)
1126 prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter,
ce60689e 1127 slot->n_elem);
ce60689e
XC
1128
1129 hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
f557e32c
XT
1130 hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
1131 hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
ce60689e 1132
f557e32c 1133 buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot);
ce60689e
XC
1134
1135 if (likely(!task->ata_task.device_control_reg_update))
1136 task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */
1137 /* fill in command FIS */
1138 memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
ce60689e
XC
1139}
1140
81d115ec 1141static void prep_abort_v3_hw(struct hisi_hba *hisi_hba,
4de0ca69
XC
1142 struct hisi_sas_slot *slot,
1143 int device_id, int abort_flag, int tag_to_abort)
1144{
1145 struct sas_task *task = slot->task;
1146 struct domain_device *dev = task->dev;
1147 struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
1148 struct hisi_sas_port *port = slot->port;
1149
1150 /* dw0 */
1151 hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/
1152 (port->id << CMD_HDR_PORT_OFF) |
bcbc7f1c 1153 (dev_is_sata(dev)
4de0ca69
XC
1154 << CMD_HDR_ABORT_DEVICE_TYPE_OFF) |
1155 (abort_flag
1156 << CMD_HDR_ABORT_FLAG_OFF));
1157
1158 /* dw1 */
1159 hdr->dw1 = cpu_to_le32(device_id
1160 << CMD_HDR_DEV_ID_OFF);
1161
1162 /* dw7 */
1163 hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF);
1164 hdr->transfer_tags = cpu_to_le32(slot->idx);
1165
4de0ca69
XC
1166}
1167
bcbc7f1c 1168static irqreturn_t phy_up_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
54edeee1 1169{
bcbc7f1c 1170 int i, res;
c57eb4e4 1171 u32 context, port_id, link_rate;
54edeee1
XC
1172 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1173 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1174 struct device *dev = hisi_hba->dev;
cca25cbc 1175 unsigned long flags;
54edeee1
XC
1176
1177 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1);
1178
1179 port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
1180 port_id = (port_id >> (4 * phy_no)) & 0xf;
1181 link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
1182 link_rate = (link_rate >> (phy_no * 4)) & 0xf;
1183
1184 if (port_id == 0xf) {
1185 dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
1186 res = IRQ_NONE;
1187 goto end;
1188 }
1189 sas_phy->linkrate = link_rate;
54edeee1
XC
1190 phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
1191
1192 /* Check for SATA dev */
1193 context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
1194 if (context & (1 << phy_no)) {
1195 struct hisi_sas_initial_fis *initial_fis;
1196 struct dev_to_host_fis *fis;
1197 u8 attached_sas_addr[SAS_ADDR_SIZE] = {0};
1198
081a1608 1199 dev_info(dev, "phyup: phy%d link_rate=%d(sata)\n", phy_no, link_rate);
54edeee1
XC
1200 initial_fis = &hisi_hba->initial_fis[phy_no];
1201 fis = &initial_fis->fis;
a2d76b6b
XC
1202
1203 /* check ERR bit of Status Register */
1204 if (fis->status & ATA_ERR) {
1205 dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n",
1206 phy_no, fis->status);
1207 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1208 res = IRQ_NONE;
1209 goto end;
1210 }
1211
54edeee1
XC
1212 sas_phy->oob_mode = SATA_OOB_MODE;
1213 attached_sas_addr[0] = 0x50;
1214 attached_sas_addr[7] = phy_no;
1215 memcpy(sas_phy->attached_sas_addr,
1216 attached_sas_addr,
1217 SAS_ADDR_SIZE);
1218 memcpy(sas_phy->frame_rcvd, fis,
1219 sizeof(struct dev_to_host_fis));
1220 phy->phy_type |= PORT_TYPE_SATA;
1221 phy->identify.device_type = SAS_SATA_DEV;
1222 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
1223 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
1224 } else {
1225 u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
1226 struct sas_identify_frame *id =
1227 (struct sas_identify_frame *)frame_rcvd;
1228
1229 dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate);
1230 for (i = 0; i < 6; i++) {
1231 u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
1232 RX_IDAF_DWORD0 + (i * 4));
1233 frame_rcvd[i] = __swab32(idaf);
1234 }
1235 sas_phy->oob_mode = SAS_OOB_MODE;
1236 memcpy(sas_phy->attached_sas_addr,
1237 &id->sas_addr,
1238 SAS_ADDR_SIZE);
1239 phy->phy_type |= PORT_TYPE_SAS;
1240 phy->identify.device_type = id->dev_type;
1241 phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
1242 if (phy->identify.device_type == SAS_END_DEVICE)
1243 phy->identify.target_port_protocols =
1244 SAS_PROTOCOL_SSP;
1245 else if (phy->identify.device_type != SAS_PHY_UNUSED)
1246 phy->identify.target_port_protocols =
1247 SAS_PROTOCOL_SMP;
1248 }
1249
1250 phy->port_id = port_id;
1251 phy->phy_attached = 1;
320cd6f1 1252 hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
bcbc7f1c 1253 res = IRQ_HANDLED;
cca25cbc
XC
1254 spin_lock_irqsave(&phy->lock, flags);
1255 if (phy->reset_completion) {
1256 phy->in_reset = 0;
1257 complete(phy->reset_completion);
1258 }
1259 spin_unlock_irqrestore(&phy->lock, flags);
54edeee1
XC
1260end:
1261 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
1262 CHL_INT0_SL_PHY_ENABLE_MSK);
1263 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0);
1264
1265 return res;
1266}
1267
bcbc7f1c 1268static irqreturn_t phy_down_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
54edeee1 1269{
54edeee1
XC
1270 u32 phy_state, sl_ctrl, txid_auto;
1271 struct device *dev = hisi_hba->dev;
1272
1273 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1);
1274
1275 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
1276 dev_info(dev, "phydown: phy%d phy_state=0x%x\n", phy_no, phy_state);
1277 hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0);
1278
1279 sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
1280 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL,
1281 sl_ctrl&(~SL_CTA_MSK));
1282
1283 txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
1284 hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
1285 txid_auto | CT3_MSK);
1286
1287 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK);
1288 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0);
1289
bcbc7f1c 1290 return IRQ_HANDLED;
54edeee1
XC
1291}
1292
bcbc7f1c 1293static irqreturn_t phy_bcast_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
54edeee1
XC
1294{
1295 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1296 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1297 struct sas_ha_struct *sas_ha = &hisi_hba->sha;
45651175 1298 u32 bcast_status;
54edeee1
XC
1299
1300 hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1);
45651175 1301 bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS);
df48a904
XT
1302 if ((bcast_status & RX_BCAST_CHG_MSK) &&
1303 !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
45651175 1304 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
54edeee1
XC
1305 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
1306 CHL_INT0_SL_RX_BCST_ACK_MSK);
1307 hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0);
bcbc7f1c
XC
1308
1309 return IRQ_HANDLED;
54edeee1
XC
1310}
1311
1312static irqreturn_t int_phy_up_down_bcast_v3_hw(int irq_no, void *p)
1313{
1314 struct hisi_hba *hisi_hba = p;
1315 u32 irq_msk;
1316 int phy_no = 0;
1317 irqreturn_t res = IRQ_NONE;
1318
1319 irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS)
1320 & 0x11111111;
1321 while (irq_msk) {
1322 if (irq_msk & 1) {
1323 u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no,
1324 CHL_INT0);
1325 u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
1326 int rdy = phy_state & (1 << phy_no);
1327
1328 if (rdy) {
1329 if (irq_value & CHL_INT0_SL_PHY_ENABLE_MSK)
1330 /* phy up */
1331 if (phy_up_v3_hw(phy_no, hisi_hba)
1332 == IRQ_HANDLED)
1333 res = IRQ_HANDLED;
1334 if (irq_value & CHL_INT0_SL_RX_BCST_ACK_MSK)
1335 /* phy bcast */
bcbc7f1c
XC
1336 if (phy_bcast_v3_hw(phy_no, hisi_hba)
1337 == IRQ_HANDLED)
1338 res = IRQ_HANDLED;
54edeee1
XC
1339 } else {
1340 if (irq_value & CHL_INT0_NOT_RDY_MSK)
1341 /* phy down */
1342 if (phy_down_v3_hw(phy_no, hisi_hba)
1343 == IRQ_HANDLED)
1344 res = IRQ_HANDLED;
1345 }
1346 }
1347 irq_msk >>= 4;
1348 phy_no++;
1349 }
1350
1351 return res;
1352}
1353
4a6125c5
XT
1354static const struct hisi_sas_hw_error port_axi_error[] = {
1355 {
1356 .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF),
1357 .msg = "dma_tx_axi_wr_err",
1358 },
1359 {
1360 .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF),
1361 .msg = "dma_tx_axi_rd_err",
1362 },
1363 {
1364 .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF),
1365 .msg = "dma_rx_axi_wr_err",
1366 },
1367 {
1368 .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF),
1369 .msg = "dma_rx_axi_rd_err",
1370 },
1371};
1372
cdb76c15 1373static void handle_chl_int1_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
54edeee1 1374{
cdb76c15
XT
1375 u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT1);
1376 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT1_MSK);
54edeee1 1377 struct device *dev = hisi_hba->dev;
cdb76c15
XT
1378 int i;
1379
1380 irq_value &= ~irq_msk;
1381 if (!irq_value)
1382 return;
1383
1384 for (i = 0; i < ARRAY_SIZE(port_axi_error); i++) {
1385 const struct hisi_sas_hw_error *error = &port_axi_error[i];
1386
1387 if (!(irq_value & error->irq_msk))
1388 continue;
1389
1390 dev_err(dev, "%s error (phy%d 0x%x) found!\n",
1391 error->msg, phy_no, irq_value);
1392 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
1393 }
1394
1395 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT1, irq_value);
1396}
1397
1398static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1399{
1400 u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2_MSK);
1401 u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
1402 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
70230be3 1403 struct pci_dev *pci_dev = hisi_hba->pci_dev;
cdb76c15
XT
1404 struct device *dev = hisi_hba->dev;
1405
1406 irq_value &= ~irq_msk;
1407 if (!irq_value)
1408 return;
1409
1410 if (irq_value & BIT(CHL_INT2_SL_IDAF_TOUT_CONF_OFF)) {
1411 dev_warn(dev, "phy%d identify timeout\n", phy_no);
1412 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1413 }
1414
1415 if (irq_value & BIT(CHL_INT2_STP_LINK_TIMEOUT_OFF)) {
1416 u32 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no,
1417 STP_LINK_TIMEOUT_STATE);
1418
1419 dev_warn(dev, "phy%d stp link timeout (0x%x)\n",
1420 phy_no, reg_value);
1421 if (reg_value & BIT(4))
1422 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
1423 }
1424
cdb76c15
XT
1425 if ((irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF)) &&
1426 (pci_dev->revision == 0x20)) {
1427 u32 reg_value;
1428 int rc;
1429
1430 rc = hisi_sas_read32_poll_timeout_atomic(
1431 HILINK_ERR_DFX, reg_value,
1432 !((reg_value >> 8) & BIT(phy_no)),
1433 1000, 10000);
17d59a57
XT
1434 if (rc)
1435 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
cdb76c15 1436 }
17d59a57
XT
1437
1438 hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2, irq_value);
cdb76c15
XT
1439}
1440
1441static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p)
1442{
1443 struct hisi_hba *hisi_hba = p;
ab39f052 1444 u32 irq_msk;
54edeee1
XC
1445 int phy_no = 0;
1446
54edeee1
XC
1447 irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS)
1448 & 0xeeeeeeee;
1449
1450 while (irq_msk) {
1451 u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no,
1452 CHL_INT0);
066312f6 1453
cdb76c15
XT
1454 if (irq_msk & (4 << (phy_no * 4)))
1455 handle_chl_int1_v3_hw(hisi_hba, phy_no);
066312f6 1456
cdb76c15
XT
1457 if (irq_msk & (8 << (phy_no * 4)))
1458 handle_chl_int2_v3_hw(hisi_hba, phy_no);
54edeee1
XC
1459
1460 if (irq_msk & (2 << (phy_no * 4)) && irq_value0) {
1461 hisi_sas_phy_write32(hisi_hba, phy_no,
1462 CHL_INT0, irq_value0
4f73575a 1463 & (~CHL_INT0_SL_RX_BCST_ACK_MSK)
54edeee1
XC
1464 & (~CHL_INT0_SL_PHY_ENABLE_MSK)
1465 & (~CHL_INT0_NOT_RDY_MSK));
1466 }
1467 irq_msk &= ~(0xe << (phy_no * 4));
1468 phy_no++;
1469 }
1470
54edeee1
XC
1471 return IRQ_HANDLED;
1472}
1473
fa231408
XT
1474static const struct hisi_sas_hw_error axi_error[] = {
1475 { .msk = BIT(0), .msg = "IOST_AXI_W_ERR" },
1476 { .msk = BIT(1), .msg = "IOST_AXI_R_ERR" },
1477 { .msk = BIT(2), .msg = "ITCT_AXI_W_ERR" },
1478 { .msk = BIT(3), .msg = "ITCT_AXI_R_ERR" },
1479 { .msk = BIT(4), .msg = "SATA_AXI_W_ERR" },
1480 { .msk = BIT(5), .msg = "SATA_AXI_R_ERR" },
1481 { .msk = BIT(6), .msg = "DQE_AXI_R_ERR" },
1482 { .msk = BIT(7), .msg = "CQE_AXI_W_ERR" },
1483 {},
1484};
1485
1486static const struct hisi_sas_hw_error fifo_error[] = {
1487 { .msk = BIT(8), .msg = "CQE_WINFO_FIFO" },
1488 { .msk = BIT(9), .msg = "CQE_MSG_FIFIO" },
1489 { .msk = BIT(10), .msg = "GETDQE_FIFO" },
1490 { .msk = BIT(11), .msg = "CMDP_FIFO" },
1491 { .msk = BIT(12), .msg = "AWTCTRL_FIFO" },
1492 {},
1493};
1494
1495static const struct hisi_sas_hw_error fatal_axi_error[] = {
1496 {
1497 .irq_msk = BIT(ENT_INT_SRC3_WP_DEPTH_OFF),
1498 .msg = "write pointer and depth",
1499 },
1500 {
1501 .irq_msk = BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF),
1502 .msg = "iptt no match slot",
1503 },
1504 {
1505 .irq_msk = BIT(ENT_INT_SRC3_RP_DEPTH_OFF),
1506 .msg = "read pointer and depth",
1507 },
1508 {
1509 .irq_msk = BIT(ENT_INT_SRC3_AXI_OFF),
1510 .reg = HGC_AXI_FIFO_ERR_INFO,
1511 .sub = axi_error,
1512 },
1513 {
1514 .irq_msk = BIT(ENT_INT_SRC3_FIFO_OFF),
1515 .reg = HGC_AXI_FIFO_ERR_INFO,
1516 .sub = fifo_error,
1517 },
1518 {
1519 .irq_msk = BIT(ENT_INT_SRC3_LM_OFF),
1520 .msg = "LM add/fetch list",
1521 },
1522 {
1523 .irq_msk = BIT(ENT_INT_SRC3_ABT_OFF),
1524 .msg = "SAS_HGC_ABT fetch LM list",
1525 },
1526};
1527
1528static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p)
1529{
1530 u32 irq_value, irq_msk;
1531 struct hisi_hba *hisi_hba = p;
1532 struct device *dev = hisi_hba->dev;
1533 int i;
1534
1535 irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
1536 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0x1df00);
1537
1538 irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
c13c7ac5 1539 irq_value &= ~irq_msk;
fa231408
XT
1540
1541 for (i = 0; i < ARRAY_SIZE(fatal_axi_error); i++) {
1542 const struct hisi_sas_hw_error *error = &fatal_axi_error[i];
1543
1544 if (!(irq_value & error->irq_msk))
1545 continue;
1546
1547 if (error->sub) {
1548 const struct hisi_sas_hw_error *sub = error->sub;
1549 u32 err_value = hisi_sas_read32(hisi_hba, error->reg);
1550
1551 for (; sub->msk || sub->msg; sub++) {
1552 if (!(err_value & sub->msk))
1553 continue;
1554
081a1608 1555 dev_err(dev, "%s error (0x%x) found!\n",
fa231408
XT
1556 sub->msg, irq_value);
1557 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
1558 }
1559 } else {
081a1608 1560 dev_err(dev, "%s error (0x%x) found!\n",
fa231408
XT
1561 error->msg, irq_value);
1562 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
1563 }
1564 }
1565
1566 if (irq_value & BIT(ENT_INT_SRC3_ITC_INT_OFF)) {
1567 u32 reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR);
1568 u32 dev_id = reg_val & ITCT_DEV_MSK;
1569 struct hisi_sas_device *sas_dev =
1570 &hisi_hba->devices[dev_id];
1571
1572 hisi_sas_write32(hisi_hba, ITCT_CLR, 0);
1573 dev_dbg(dev, "clear ITCT ok\n");
1574 complete(sas_dev->completion);
1575 }
1576
1577 hisi_sas_write32(hisi_hba, ENT_INT_SRC3, irq_value & 0x1df00);
1578 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk);
1579
1580 return IRQ_HANDLED;
1581}
1582
60b4a5ee
XC
1583static void
1584slot_err_v3_hw(struct hisi_hba *hisi_hba, struct sas_task *task,
1585 struct hisi_sas_slot *slot)
1586{
1587 struct task_status_struct *ts = &task->task_status;
1588 struct hisi_sas_complete_v3_hdr *complete_queue =
1589 hisi_hba->complete_hdr[slot->cmplt_queue];
1590 struct hisi_sas_complete_v3_hdr *complete_hdr =
1591 &complete_queue[slot->cmplt_queue_slot];
f557e32c
XT
1592 struct hisi_sas_err_record_v3 *record =
1593 hisi_sas_status_buf_addr_mem(slot);
b8438c40
JG
1594 u32 dma_rx_err_type = le32_to_cpu(record->dma_rx_err_type);
1595 u32 trans_tx_fail_type = le32_to_cpu(record->trans_tx_fail_type);
1596 u32 dw3 = le32_to_cpu(complete_hdr->dw3);
60b4a5ee
XC
1597
1598 switch (task->task_proto) {
1599 case SAS_PROTOCOL_SSP:
1600 if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) {
1601 ts->residual = trans_tx_fail_type;
1602 ts->stat = SAS_DATA_UNDERRUN;
b8438c40 1603 } else if (dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) {
60b4a5ee
XC
1604 ts->stat = SAS_QUEUE_FULL;
1605 slot->abort = 1;
1606 } else {
1607 ts->stat = SAS_OPEN_REJECT;
1608 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1609 }
1610 break;
1611 case SAS_PROTOCOL_SATA:
1612 case SAS_PROTOCOL_STP:
1613 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
1614 if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) {
1615 ts->residual = trans_tx_fail_type;
1616 ts->stat = SAS_DATA_UNDERRUN;
b8438c40 1617 } else if (dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) {
60b4a5ee
XC
1618 ts->stat = SAS_PHY_DOWN;
1619 slot->abort = 1;
1620 } else {
1621 ts->stat = SAS_OPEN_REJECT;
1622 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1623 }
1624 hisi_sas_sata_done(task, slot);
1625 break;
1626 case SAS_PROTOCOL_SMP:
1627 ts->stat = SAM_STAT_CHECK_CONDITION;
1628 break;
1629 default:
1630 break;
1631 }
1632}
1633
1634static int
1635slot_complete_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot)
1636{
1637 struct sas_task *task = slot->task;
1638 struct hisi_sas_device *sas_dev;
1639 struct device *dev = hisi_hba->dev;
1640 struct task_status_struct *ts;
1641 struct domain_device *device;
68e6bace 1642 struct sas_ha_struct *ha;
60b4a5ee
XC
1643 enum exec_status sts;
1644 struct hisi_sas_complete_v3_hdr *complete_queue =
1645 hisi_hba->complete_hdr[slot->cmplt_queue];
1646 struct hisi_sas_complete_v3_hdr *complete_hdr =
1647 &complete_queue[slot->cmplt_queue_slot];
60b4a5ee 1648 unsigned long flags;
68e6bace 1649 bool is_internal = slot->is_internal;
b8438c40 1650 u32 dw0, dw1, dw3;
60b4a5ee
XC
1651
1652 if (unlikely(!task || !task->lldd_task || !task->dev))
1653 return -EINVAL;
1654
1655 ts = &task->task_status;
1656 device = task->dev;
68e6bace 1657 ha = device->port->ha;
60b4a5ee
XC
1658 sas_dev = device->lldd_dev;
1659
1660 spin_lock_irqsave(&task->task_state_lock, flags);
60b4a5ee
XC
1661 task->task_state_flags &=
1662 ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
1663 spin_unlock_irqrestore(&task->task_state_lock, flags);
1664
1665 memset(ts, 0, sizeof(*ts));
1666 ts->resp = SAS_TASK_COMPLETE;
60b4a5ee
XC
1667
1668 if (unlikely(!sas_dev)) {
1669 dev_dbg(dev, "slot complete: port has not device\n");
1670 ts->stat = SAS_PHY_DOWN;
1671 goto out;
1672 }
1673
b8438c40
JG
1674 dw0 = le32_to_cpu(complete_hdr->dw0);
1675 dw1 = le32_to_cpu(complete_hdr->dw1);
1676 dw3 = le32_to_cpu(complete_hdr->dw3);
1677
60b4a5ee
XC
1678 /*
1679 * Use SAS+TMF status codes
1680 */
b8438c40 1681 switch ((dw0 & CMPLT_HDR_ABORT_STAT_MSK) >> CMPLT_HDR_ABORT_STAT_OFF) {
60b4a5ee
XC
1682 case STAT_IO_ABORTED:
1683 /* this IO has been aborted by abort command */
1684 ts->stat = SAS_ABORTED_TASK;
1685 goto out;
1686 case STAT_IO_COMPLETE:
1687 /* internal abort command complete */
1688 ts->stat = TMF_RESP_FUNC_SUCC;
1689 goto out;
1690 case STAT_IO_NO_DEVICE:
1691 ts->stat = TMF_RESP_FUNC_COMPLETE;
1692 goto out;
1693 case STAT_IO_NOT_VALID:
1694 /*
1695 * abort single IO, the controller can't find the IO
1696 */
1697 ts->stat = TMF_RESP_FUNC_FAILED;
1698 goto out;
1699 default:
1700 break;
1701 }
1702
1703 /* check for erroneous completion */
b8438c40 1704 if ((dw0 & CMPLT_HDR_CMPLT_MSK) == 0x3) {
081a1608
XC
1705 u32 *error_info = hisi_sas_status_buf_addr_mem(slot);
1706
60b4a5ee 1707 slot_err_v3_hw(hisi_hba, task, slot);
081a1608 1708 if (ts->stat != SAS_DATA_UNDERRUN)
ab2d8bd6 1709 dev_info(dev, "erroneous completion iptt=%d task=%p dev id=%d "
081a1608
XC
1710 "CQ hdr: 0x%x 0x%x 0x%x 0x%x "
1711 "Error info: 0x%x 0x%x 0x%x 0x%x\n",
ab2d8bd6 1712 slot->idx, task, sas_dev->device_id,
b8438c40 1713 dw0, dw1, complete_hdr->act, dw3,
081a1608
XC
1714 error_info[0], error_info[1],
1715 error_info[2], error_info[3]);
60b4a5ee
XC
1716 if (unlikely(slot->abort))
1717 return ts->stat;
1718 goto out;
1719 }
1720
1721 switch (task->task_proto) {
1722 case SAS_PROTOCOL_SSP: {
f557e32c
XT
1723 struct ssp_response_iu *iu =
1724 hisi_sas_status_buf_addr_mem(slot) +
60b4a5ee
XC
1725 sizeof(struct hisi_sas_err_record);
1726
1727 sas_ssp_task_response(dev, task, iu);
1728 break;
1729 }
1730 case SAS_PROTOCOL_SMP: {
1731 struct scatterlist *sg_resp = &task->smp_task.smp_resp;
1732 void *to;
1733
1734 ts->stat = SAM_STAT_GOOD;
1735 to = kmap_atomic(sg_page(sg_resp));
1736
1737 dma_unmap_sg(dev, &task->smp_task.smp_resp, 1,
1738 DMA_FROM_DEVICE);
1739 dma_unmap_sg(dev, &task->smp_task.smp_req, 1,
1740 DMA_TO_DEVICE);
1741 memcpy(to + sg_resp->offset,
f557e32c 1742 hisi_sas_status_buf_addr_mem(slot) +
60b4a5ee
XC
1743 sizeof(struct hisi_sas_err_record),
1744 sg_dma_len(sg_resp));
1745 kunmap_atomic(to);
1746 break;
1747 }
1748 case SAS_PROTOCOL_SATA:
1749 case SAS_PROTOCOL_STP:
1750 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
1751 ts->stat = SAM_STAT_GOOD;
1752 hisi_sas_sata_done(task, slot);
1753 break;
1754 default:
1755 ts->stat = SAM_STAT_CHECK_CONDITION;
1756 break;
1757 }
1758
1759 if (!slot->port->port_attached) {
081a1608 1760 dev_warn(dev, "slot complete: port %d has removed\n",
60b4a5ee
XC
1761 slot->port->sas_port.id);
1762 ts->stat = SAS_PHY_DOWN;
1763 }
1764
1765out:
52ed2bba 1766 sts = ts->stat;
60b4a5ee 1767 spin_lock_irqsave(&task->task_state_lock, flags);
52ed2bba
XC
1768 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
1769 spin_unlock_irqrestore(&task->task_state_lock, flags);
1770 dev_info(dev, "slot complete: task(%p) aborted\n", task);
1771 return SAS_ABORTED_TASK;
1772 }
60b4a5ee
XC
1773 task->task_state_flags |= SAS_TASK_STATE_DONE;
1774 spin_unlock_irqrestore(&task->task_state_lock, flags);
bb03e124 1775 hisi_sas_slot_task_free(hisi_hba, task, slot);
60b4a5ee 1776
68e6bace
XC
1777 if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) {
1778 spin_lock_irqsave(&device->done_lock, flags);
1779 if (test_bit(SAS_HA_FROZEN, &ha->state)) {
1780 spin_unlock_irqrestore(&device->done_lock, flags);
1781 dev_info(dev, "slot complete: task(%p) ignored\n ",
1782 task);
1783 return sts;
1784 }
1785 spin_unlock_irqrestore(&device->done_lock, flags);
1786 }
1787
60b4a5ee
XC
1788 if (task->task_done)
1789 task->task_done(task);
1790
1791 return sts;
1792}
1793
1794static void cq_tasklet_v3_hw(unsigned long val)
1795{
1796 struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val;
1797 struct hisi_hba *hisi_hba = cq->hisi_hba;
1798 struct hisi_sas_slot *slot;
60b4a5ee 1799 struct hisi_sas_complete_v3_hdr *complete_queue;
ee076d5b 1800 u32 rd_point = cq->rd_point, wr_point;
60b4a5ee 1801 int queue = cq->id;
60b4a5ee
XC
1802
1803 complete_queue = hisi_hba->complete_hdr[queue];
1804
60b4a5ee
XC
1805 wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR +
1806 (0x14 * queue));
1807
1808 while (rd_point != wr_point) {
1809 struct hisi_sas_complete_v3_hdr *complete_hdr;
e812cf8c 1810 struct device *dev = hisi_hba->dev;
b8438c40 1811 u32 dw1;
60b4a5ee
XC
1812 int iptt;
1813
1814 complete_hdr = &complete_queue[rd_point];
b8438c40 1815 dw1 = le32_to_cpu(complete_hdr->dw1);
60b4a5ee 1816
b8438c40 1817 iptt = dw1 & CMPLT_HDR_IPTT_MSK;
e812cf8c
XT
1818 if (likely(iptt < HISI_SAS_COMMAND_ENTRIES_V3_HW)) {
1819 slot = &hisi_hba->slot_info[iptt];
1820 slot->cmplt_queue_slot = rd_point;
1821 slot->cmplt_queue = queue;
1822 slot_complete_v3_hw(hisi_hba, slot);
1823 } else
1824 dev_err(dev, "IPTT %d is invalid, discard it.\n", iptt);
60b4a5ee
XC
1825
1826 if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
1827 rd_point = 0;
1828 }
1829
1830 /* update rd_point */
1831 cq->rd_point = rd_point;
1832 hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
60b4a5ee
XC
1833}
1834
1835static irqreturn_t cq_interrupt_v3_hw(int irq_no, void *p)
1836{
1837 struct hisi_sas_cq *cq = p;
1838 struct hisi_hba *hisi_hba = cq->hisi_hba;
1839 int queue = cq->id;
1840
1841 hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
1842
1843 tasklet_schedule(&cq->tasklet);
1844
1845 return IRQ_HANDLED;
1846}
1847
54edeee1
XC
1848static int interrupt_init_v3_hw(struct hisi_hba *hisi_hba)
1849{
1850 struct device *dev = hisi_hba->dev;
1851 struct pci_dev *pdev = hisi_hba->pci_dev;
1852 int vectors, rc;
60b4a5ee 1853 int i, k;
54edeee1
XC
1854 int max_msi = HISI_SAS_MSI_COUNT_V3_HW;
1855
1856 vectors = pci_alloc_irq_vectors(hisi_hba->pci_dev, 1,
1857 max_msi, PCI_IRQ_MSI);
1858 if (vectors < max_msi) {
1859 dev_err(dev, "could not allocate all msi (%d)\n", vectors);
1860 return -ENOENT;
1861 }
1862
1863 rc = devm_request_irq(dev, pci_irq_vector(pdev, 1),
1864 int_phy_up_down_bcast_v3_hw, 0,
1865 DRV_NAME " phy", hisi_hba);
1866 if (rc) {
1867 dev_err(dev, "could not request phy interrupt, rc=%d\n", rc);
1868 rc = -ENOENT;
1869 goto free_irq_vectors;
1870 }
1871
1872 rc = devm_request_irq(dev, pci_irq_vector(pdev, 2),
1873 int_chnl_int_v3_hw, 0,
1874 DRV_NAME " channel", hisi_hba);
1875 if (rc) {
1876 dev_err(dev, "could not request chnl interrupt, rc=%d\n", rc);
1877 rc = -ENOENT;
1878 goto free_phy_irq;
1879 }
1880
fa231408
XT
1881 rc = devm_request_irq(dev, pci_irq_vector(pdev, 11),
1882 fatal_axi_int_v3_hw, 0,
1883 DRV_NAME " fatal", hisi_hba);
1884 if (rc) {
1885 dev_err(dev, "could not request fatal interrupt, rc=%d\n", rc);
1886 rc = -ENOENT;
1887 goto free_chnl_interrupt;
1888 }
1889
60b4a5ee
XC
1890 /* Init tasklets for cq only */
1891 for (i = 0; i < hisi_hba->queue_count; i++) {
1892 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
1893 struct tasklet_struct *t = &cq->tasklet;
6cc8d8f2
XC
1894 int nr = hisi_sas_intr_conv ? 16 : 16 + i;
1895 unsigned long irqflags = hisi_sas_intr_conv ? IRQF_SHARED : 0;
60b4a5ee 1896
6cc8d8f2
XC
1897 rc = devm_request_irq(dev, pci_irq_vector(pdev, nr),
1898 cq_interrupt_v3_hw, irqflags,
1899 DRV_NAME " cq", cq);
60b4a5ee
XC
1900 if (rc) {
1901 dev_err(dev,
1902 "could not request cq%d interrupt, rc=%d\n",
1903 i, rc);
1904 rc = -ENOENT;
1905 goto free_cq_irqs;
1906 }
1907
1908 tasklet_init(t, cq_tasklet_v3_hw, (unsigned long)cq);
1909 }
54edeee1
XC
1910
1911 return 0;
1912
60b4a5ee
XC
1913free_cq_irqs:
1914 for (k = 0; k < i; k++) {
1915 struct hisi_sas_cq *cq = &hisi_hba->cq[k];
6cc8d8f2 1916 int nr = hisi_sas_intr_conv ? 16 : 16 + k;
60b4a5ee 1917
6cc8d8f2 1918 free_irq(pci_irq_vector(pdev, nr), cq);
60b4a5ee 1919 }
fa231408
XT
1920 free_irq(pci_irq_vector(pdev, 11), hisi_hba);
1921free_chnl_interrupt:
60b4a5ee 1922 free_irq(pci_irq_vector(pdev, 2), hisi_hba);
54edeee1
XC
1923free_phy_irq:
1924 free_irq(pci_irq_vector(pdev, 1), hisi_hba);
1925free_irq_vectors:
1926 pci_free_irq_vectors(pdev);
1927 return rc;
1928}
1929
c94d8ca2
XC
1930static int hisi_sas_v3_init(struct hisi_hba *hisi_hba)
1931{
1932 int rc;
1933
1934 rc = hw_init_v3_hw(hisi_hba);
1935 if (rc)
1936 return rc;
1937
54edeee1
XC
1938 rc = interrupt_init_v3_hw(hisi_hba);
1939 if (rc)
1940 return rc;
1941
c94d8ca2
XC
1942 return 0;
1943}
1944
2400620c
XC
1945static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no,
1946 struct sas_phy_linkrates *r)
1947{
5193a533 1948 enum sas_linkrate max = r->maximum_linkrate;
f385b4ff 1949 u32 prog_phy_link_rate = 0x800;
2400620c 1950
f385b4ff 1951 prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
2400620c 1952 hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
5193a533 1953 prog_phy_link_rate);
2400620c
XC
1954}
1955
a25d0d3d
XC
1956static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba)
1957{
1958 struct pci_dev *pdev = hisi_hba->pci_dev;
1959 int i;
1960
1961 synchronize_irq(pci_irq_vector(pdev, 1));
1962 synchronize_irq(pci_irq_vector(pdev, 2));
1963 synchronize_irq(pci_irq_vector(pdev, 11));
1964 for (i = 0; i < hisi_hba->queue_count; i++) {
1965 hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1);
1966 synchronize_irq(pci_irq_vector(pdev, i + 16));
1967 }
1968
1969 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff);
1970 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff);
1971 hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff);
1972 hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff);
1973
1974 for (i = 0; i < hisi_hba->n_phy; i++) {
1975 hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff);
1976 hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff);
1977 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x1);
1978 hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x1);
1979 hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x1);
1980 }
1981}
1982
1983static u32 get_phys_state_v3_hw(struct hisi_hba *hisi_hba)
1984{
1985 return hisi_sas_read32(hisi_hba, PHY_STATE);
1986}
1987
ffc8f149
XT
1988static void phy_get_events_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
1989{
1990 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1991 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1992 struct sas_phy *sphy = sas_phy->phy;
1993 u32 reg_value;
1994
1995 /* loss dword sync */
1996 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DWS_LOST);
1997 sphy->loss_of_dword_sync_count += reg_value;
1998
1999 /* phy reset problem */
2000 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_RESET_PROB);
2001 sphy->phy_reset_problem_count += reg_value;
2002
2003 /* invalid dword */
2004 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_INVLD_DW);
2005 sphy->invalid_dword_count += reg_value;
2006
2007 /* disparity err */
2008 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DISP_ERR);
2009 sphy->running_disparity_error_count += reg_value;
2010
2011}
2012
1d51757d 2013static int disable_host_v3_hw(struct hisi_hba *hisi_hba)
a25d0d3d
XC
2014{
2015 struct device *dev = hisi_hba->dev;
1d51757d 2016 u32 status, reg_val;
a25d0d3d 2017 int rc;
a25d0d3d
XC
2018
2019 interrupt_disable_v3_hw(hisi_hba);
2020 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0);
571295f8 2021 hisi_sas_kill_tasklets(hisi_hba);
a25d0d3d
XC
2022
2023 hisi_sas_stop_phys(hisi_hba);
2024
2025 mdelay(10);
2026
1d51757d
XT
2027 reg_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE +
2028 AM_CTRL_GLOBAL);
2029 reg_val |= AM_CTRL_SHUTDOWN_REQ_MSK;
2030 hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
2031 AM_CTRL_GLOBAL, reg_val);
a25d0d3d
XC
2032
2033 /* wait until bus idle */
70bfdcae
JG
2034 rc = hisi_sas_read32_poll_timeout(AXI_MASTER_CFG_BASE +
2035 AM_CURR_TRANS_RETURN, status,
2036 status == 0x3, 10, 100);
a25d0d3d 2037 if (rc) {
1d51757d
XT
2038 dev_err(dev, "axi bus is not idle, rc=%d\n", rc);
2039 return rc;
2040 }
2041
2042 return 0;
2043}
2044
2045static int soft_reset_v3_hw(struct hisi_hba *hisi_hba)
2046{
2047 struct device *dev = hisi_hba->dev;
2048 int rc;
2049
2050 rc = disable_host_v3_hw(hisi_hba);
2051 if (rc) {
2052 dev_err(dev, "soft reset: disable host failed rc=%d\n", rc);
a25d0d3d
XC
2053 return rc;
2054 }
2055
2056 hisi_sas_init_mem(hisi_hba);
2057
2058 return hw_init_v3_hw(hisi_hba);
2059}
2060
e24fe507
XT
2061static int write_gpio_v3_hw(struct hisi_hba *hisi_hba, u8 reg_type,
2062 u8 reg_index, u8 reg_count, u8 *write_data)
2063{
2064 struct device *dev = hisi_hba->dev;
2065 u32 *data = (u32 *)write_data;
2066 int i;
2067
2068 switch (reg_type) {
2069 case SAS_GPIO_REG_TX:
2070 if ((reg_index + reg_count) > ((hisi_hba->n_phy + 3) / 4)) {
2071 dev_err(dev, "write gpio: invalid reg range[%d, %d]\n",
2072 reg_index, reg_index + reg_count - 1);
2073 return -EINVAL;
2074 }
2075
2076 for (i = 0; i < reg_count; i++)
2077 hisi_sas_write32(hisi_hba,
2078 SAS_GPIO_TX_0_1 + (reg_index + i) * 4,
2079 data[i]);
2080 break;
2081 default:
2082 dev_err(dev, "write gpio: unsupported or bad reg type %d\n",
2083 reg_type);
2084 return -EINVAL;
2085 }
2086
2087 return 0;
2088}
2089
1a7068b3
XT
2090static void wait_cmds_complete_timeout_v3_hw(struct hisi_hba *hisi_hba,
2091 int delay_ms, int timeout_ms)
2092{
2093 struct device *dev = hisi_hba->dev;
2094 int entries, entries_old = 0, time;
2095
2096 for (time = 0; time < timeout_ms; time += delay_ms) {
2097 entries = hisi_sas_read32(hisi_hba, CQE_SEND_CNT);
2098 if (entries == entries_old)
2099 break;
2100
2101 entries_old = entries;
2102 msleep(delay_ms);
2103 }
2104
2105 dev_dbg(dev, "wait commands complete %dms\n", time);
2106}
2107
6cc8d8f2
XC
2108static ssize_t intr_conv_v3_hw_show(struct device *dev,
2109 struct device_attribute *attr, char *buf)
2110{
2111 return scnprintf(buf, PAGE_SIZE, "%u\n", hisi_sas_intr_conv);
2112}
2113static DEVICE_ATTR_RO(intr_conv_v3_hw);
2114
3e45e10b
XC
2115static void config_intr_coal_v3_hw(struct hisi_hba *hisi_hba)
2116{
2117 /* config those registers between enable and disable PHYs */
2118 hisi_sas_stop_phys(hisi_hba);
2119
2120 if (hisi_hba->intr_coal_ticks == 0 ||
2121 hisi_hba->intr_coal_count == 0) {
2122 hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1);
2123 hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1);
2124 hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1);
2125 } else {
2126 hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x3);
2127 hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME,
2128 hisi_hba->intr_coal_ticks);
2129 hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT,
2130 hisi_hba->intr_coal_count);
2131 }
2132 phys_init_v3_hw(hisi_hba);
2133}
2134
2135static ssize_t intr_coal_ticks_v3_hw_show(struct device *dev,
2136 struct device_attribute *attr,
2137 char *buf)
2138{
2139 struct Scsi_Host *shost = class_to_shost(dev);
2140 struct hisi_hba *hisi_hba = shost_priv(shost);
2141
2142 return scnprintf(buf, PAGE_SIZE, "%u\n",
2143 hisi_hba->intr_coal_ticks);
2144}
2145
2146static ssize_t intr_coal_ticks_v3_hw_store(struct device *dev,
2147 struct device_attribute *attr,
2148 const char *buf, size_t count)
2149{
2150 struct Scsi_Host *shost = class_to_shost(dev);
2151 struct hisi_hba *hisi_hba = shost_priv(shost);
2152 u32 intr_coal_ticks;
2153 int ret;
2154
2155 ret = kstrtou32(buf, 10, &intr_coal_ticks);
2156 if (ret) {
2157 dev_err(dev, "Input data of interrupt coalesce unmatch\n");
2158 return -EINVAL;
2159 }
2160
2161 if (intr_coal_ticks >= BIT(24)) {
2162 dev_err(dev, "intr_coal_ticks must be less than 2^24!\n");
2163 return -EINVAL;
2164 }
2165
2166 hisi_hba->intr_coal_ticks = intr_coal_ticks;
2167
2168 config_intr_coal_v3_hw(hisi_hba);
2169
2170 return count;
2171}
2172static DEVICE_ATTR_RW(intr_coal_ticks_v3_hw);
2173
2174static ssize_t intr_coal_count_v3_hw_show(struct device *dev,
2175 struct device_attribute
2176 *attr, char *buf)
2177{
2178 struct Scsi_Host *shost = class_to_shost(dev);
2179 struct hisi_hba *hisi_hba = shost_priv(shost);
2180
2181 return scnprintf(buf, PAGE_SIZE, "%u\n",
2182 hisi_hba->intr_coal_count);
2183}
2184
2185static ssize_t intr_coal_count_v3_hw_store(struct device *dev,
2186 struct device_attribute
2187 *attr, const char *buf, size_t count)
2188{
2189 struct Scsi_Host *shost = class_to_shost(dev);
2190 struct hisi_hba *hisi_hba = shost_priv(shost);
2191 u32 intr_coal_count;
2192 int ret;
2193
2194 ret = kstrtou32(buf, 10, &intr_coal_count);
2195 if (ret) {
2196 dev_err(dev, "Input data of interrupt coalesce unmatch\n");
2197 return -EINVAL;
2198 }
2199
2200 if (intr_coal_count >= BIT(8)) {
2201 dev_err(dev, "intr_coal_count must be less than 2^8!\n");
2202 return -EINVAL;
2203 }
2204
2205 hisi_hba->intr_coal_count = intr_coal_count;
2206
2207 config_intr_coal_v3_hw(hisi_hba);
2208
2209 return count;
2210}
2211static DEVICE_ATTR_RW(intr_coal_count_v3_hw);
2212
b8438c40 2213static struct device_attribute *host_attrs_v3_hw[] = {
4659b074 2214 &dev_attr_phy_event_threshold,
6cc8d8f2 2215 &dev_attr_intr_conv_v3_hw,
3e45e10b
XC
2216 &dev_attr_intr_coal_ticks_v3_hw,
2217 &dev_attr_intr_coal_count_v3_hw,
4659b074
XC
2218 NULL
2219};
2220
b1793064
XC
2221static struct scsi_host_template sht_v3_hw = {
2222 .name = DRV_NAME,
2223 .module = THIS_MODULE,
2224 .queuecommand = sas_queuecommand,
2225 .target_alloc = sas_target_alloc,
2226 .slave_configure = hisi_sas_slave_configure,
2227 .scan_finished = hisi_sas_scan_finished,
2228 .scan_start = hisi_sas_scan_start,
2229 .change_queue_depth = sas_change_queue_depth,
2230 .bios_param = sas_bios_param,
b1793064 2231 .this_id = -1,
3c42dba0 2232 .sg_tablesize = HISI_SAS_SGE_PAGE_CNT,
b1793064
XC
2233 .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
2234 .use_clustering = ENABLE_CLUSTERING,
2235 .eh_device_reset_handler = sas_eh_device_reset_handler,
2236 .eh_target_reset_handler = sas_eh_target_reset_handler,
2237 .target_destroy = sas_target_destroy,
2238 .ioctl = sas_ioctl,
4659b074 2239 .shost_attrs = host_attrs_v3_hw,
8041484f 2240 .tag_alloc_policy = BLK_TAG_ALLOC_RR,
b1793064
XC
2241};
2242
e21fe3a5 2243static const struct hisi_sas_hw hisi_sas_v3_hw = {
c94d8ca2 2244 .hw_init = hisi_sas_v3_init,
182e7222 2245 .setup_itct = setup_itct_v3_hw,
c94d8ca2 2246 .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V3_HW,
f771d3b0 2247 .get_wideport_bitmap = get_wideport_bitmap_v3_hw,
c94d8ca2 2248 .complete_hdr_size = sizeof(struct hisi_sas_complete_v3_hdr),
f39943ee 2249 .clear_itct = clear_itct_v3_hw,
3975f605 2250 .sl_notify = sl_notify_v3_hw,
a2204723 2251 .prep_ssp = prep_ssp_v3_hw,
fa913de2 2252 .prep_smp = prep_smp_v3_hw,
ce60689e 2253 .prep_stp = prep_ata_v3_hw,
4de0ca69 2254 .prep_abort = prep_abort_v3_hw,
a2204723
XC
2255 .get_free_slot = get_free_slot_v3_hw,
2256 .start_delivery = start_delivery_v3_hw,
2257 .slot_complete = slot_complete_v3_hw,
3975f605 2258 .phys_init = phys_init_v3_hw,
1eb8eeac 2259 .phy_start = start_phy_v3_hw,
402cd9f0
XC
2260 .phy_disable = disable_phy_v3_hw,
2261 .phy_hard_reset = phy_hard_reset_v3_hw,
2262 .phy_get_max_linkrate = phy_get_max_linkrate_v3_hw,
2400620c 2263 .phy_set_linkrate = phy_set_linkrate_v3_hw,
d30ff263 2264 .dereg_device = dereg_device_v3_hw,
a25d0d3d
XC
2265 .soft_reset = soft_reset_v3_hw,
2266 .get_phys_state = get_phys_state_v3_hw,
ffc8f149 2267 .get_events = phy_get_events_v3_hw,
e24fe507 2268 .write_gpio = write_gpio_v3_hw,
1a7068b3 2269 .wait_cmds_complete_timeout = wait_cmds_complete_timeout_v3_hw,
e21fe3a5
JG
2270};
2271
2272static struct Scsi_Host *
2273hisi_sas_shost_alloc_pci(struct pci_dev *pdev)
2274{
2275 struct Scsi_Host *shost;
2276 struct hisi_hba *hisi_hba;
2277 struct device *dev = &pdev->dev;
2278
b1793064 2279 shost = scsi_host_alloc(&sht_v3_hw, sizeof(*hisi_hba));
76aae5f6
JG
2280 if (!shost) {
2281 dev_err(dev, "shost alloc failed\n");
2282 return NULL;
2283 }
e21fe3a5
JG
2284 hisi_hba = shost_priv(shost);
2285
b4241f0f 2286 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
e21fe3a5
JG
2287 hisi_hba->hw = &hisi_sas_v3_hw;
2288 hisi_hba->pci_dev = pdev;
2289 hisi_hba->dev = dev;
2290 hisi_hba->shost = shost;
2291 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
2292
77570eed 2293 timer_setup(&hisi_hba->timer, NULL, 0);
e21fe3a5
JG
2294
2295 if (hisi_sas_get_fw_info(hisi_hba) < 0)
2296 goto err_out;
2297
2298 if (hisi_sas_alloc(hisi_hba, shost)) {
2299 hisi_sas_free(hisi_hba);
2300 goto err_out;
2301 }
2302
2303 return shost;
2304err_out:
76aae5f6 2305 scsi_host_put(shost);
e21fe3a5
JG
2306 dev_err(dev, "shost alloc failed\n");
2307 return NULL;
2308}
2309
92f61e3b
JG
2310static int
2311hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2312{
e21fe3a5
JG
2313 struct Scsi_Host *shost;
2314 struct hisi_hba *hisi_hba;
2315 struct device *dev = &pdev->dev;
2316 struct asd_sas_phy **arr_phy;
2317 struct asd_sas_port **arr_port;
2318 struct sas_ha_struct *sha;
2319 int rc, phy_nr, port_nr, i;
2320
2321 rc = pci_enable_device(pdev);
2322 if (rc)
2323 goto err_out;
2324
2325 pci_set_master(pdev);
2326
2327 rc = pci_request_regions(pdev, DRV_NAME);
2328 if (rc)
2329 goto err_out_disable_device;
2330
745d4335
CH
2331 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
2332 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
2333 dev_err(dev, "No usable DMA addressing method\n");
2334 rc = -EIO;
2335 goto err_out_regions;
e21fe3a5
JG
2336 }
2337
2338 shost = hisi_sas_shost_alloc_pci(pdev);
2339 if (!shost) {
2340 rc = -ENOMEM;
2341 goto err_out_regions;
2342 }
2343
2344 sha = SHOST_TO_SAS_HA(shost);
2345 hisi_hba = shost_priv(shost);
2346 dev_set_drvdata(dev, sha);
2347
2348 hisi_hba->regs = pcim_iomap(pdev, 5, 0);
2349 if (!hisi_hba->regs) {
2350 dev_err(dev, "cannot map register.\n");
2351 rc = -ENOMEM;
2352 goto err_out_ha;
2353 }
2354
2355 phy_nr = port_nr = hisi_hba->n_phy;
2356
2357 arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
2358 arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
2359 if (!arr_phy || !arr_port) {
2360 rc = -ENOMEM;
2361 goto err_out_ha;
2362 }
2363
2364 sha->sas_phy = arr_phy;
2365 sha->sas_port = arr_port;
2366 sha->core.shost = shost;
2367 sha->lldd_ha = hisi_hba;
2368
2369 shost->transportt = hisi_sas_stt;
2370 shost->max_id = HISI_SAS_MAX_DEVICES;
2371 shost->max_lun = ~0;
2372 shost->max_channel = 1;
2373 shost->max_cmd_len = 16;
8041484f
XC
2374 shost->can_queue = hisi_hba->hw->max_command_entries -
2375 HISI_SAS_RESERVED_IPTT_CNT;
2376 shost->cmd_per_lun = hisi_hba->hw->max_command_entries -
2377 HISI_SAS_RESERVED_IPTT_CNT;
e21fe3a5
JG
2378
2379 sha->sas_ha_name = DRV_NAME;
2380 sha->dev = dev;
2381 sha->lldd_module = THIS_MODULE;
2382 sha->sas_addr = &hisi_hba->sas_addr[0];
2383 sha->num_phys = hisi_hba->n_phy;
2384 sha->core.shost = hisi_hba->shost;
2385
2386 for (i = 0; i < hisi_hba->n_phy; i++) {
2387 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
2388 sha->sas_port[i] = &hisi_hba->port[i].sas_port;
2389 }
2390
e21fe3a5
JG
2391 rc = scsi_add_host(shost, dev);
2392 if (rc)
2393 goto err_out_ha;
2394
2395 rc = sas_register_ha(sha);
2396 if (rc)
2397 goto err_out_register_ha;
2398
2399 rc = hisi_hba->hw->hw_init(hisi_hba);
2400 if (rc)
2401 goto err_out_register_ha;
2402
2403 scsi_scan_host(shost);
2404
92f61e3b 2405 return 0;
e21fe3a5
JG
2406
2407err_out_register_ha:
2408 scsi_remove_host(shost);
2409err_out_ha:
76aae5f6 2410 scsi_host_put(shost);
e21fe3a5
JG
2411err_out_regions:
2412 pci_release_regions(pdev);
2413err_out_disable_device:
2414 pci_disable_device(pdev);
2415err_out:
2416 return rc;
92f61e3b
JG
2417}
2418
54edeee1
XC
2419static void
2420hisi_sas_v3_destroy_irqs(struct pci_dev *pdev, struct hisi_hba *hisi_hba)
2421{
60b4a5ee
XC
2422 int i;
2423
54edeee1
XC
2424 free_irq(pci_irq_vector(pdev, 1), hisi_hba);
2425 free_irq(pci_irq_vector(pdev, 2), hisi_hba);
fa231408 2426 free_irq(pci_irq_vector(pdev, 11), hisi_hba);
60b4a5ee
XC
2427 for (i = 0; i < hisi_hba->queue_count; i++) {
2428 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
6cc8d8f2 2429 int nr = hisi_sas_intr_conv ? 16 : 16 + i;
60b4a5ee 2430
6cc8d8f2 2431 free_irq(pci_irq_vector(pdev, nr), cq);
60b4a5ee 2432 }
54edeee1
XC
2433 pci_free_irq_vectors(pdev);
2434}
2435
92f61e3b
JG
2436static void hisi_sas_v3_remove(struct pci_dev *pdev)
2437{
e21fe3a5
JG
2438 struct device *dev = &pdev->dev;
2439 struct sas_ha_struct *sha = dev_get_drvdata(dev);
2440 struct hisi_hba *hisi_hba = sha->lldd_ha;
76aae5f6 2441 struct Scsi_Host *shost = sha->core.shost;
e21fe3a5 2442
a417a9c1
XC
2443 if (timer_pending(&hisi_hba->timer))
2444 del_timer(&hisi_hba->timer);
2445
e21fe3a5
JG
2446 sas_unregister_ha(sha);
2447 sas_remove_host(sha->core.shost);
2448
54edeee1 2449 hisi_sas_v3_destroy_irqs(pdev, hisi_hba);
571295f8 2450 hisi_sas_kill_tasklets(hisi_hba);
e21fe3a5
JG
2451 pci_release_regions(pdev);
2452 pci_disable_device(pdev);
76aae5f6
JG
2453 hisi_sas_free(hisi_hba);
2454 scsi_host_put(shost);
92f61e3b
JG
2455}
2456
56b72168
XT
2457static const struct hisi_sas_hw_error sas_ras_intr0_nfe[] = {
2458 { .irq_msk = BIT(19), .msg = "HILINK_INT" },
2459 { .irq_msk = BIT(20), .msg = "HILINK_PLL0_OUT_OF_LOCK" },
2460 { .irq_msk = BIT(21), .msg = "HILINK_PLL1_OUT_OF_LOCK" },
2461 { .irq_msk = BIT(22), .msg = "HILINK_LOSS_OF_REFCLK0" },
2462 { .irq_msk = BIT(23), .msg = "HILINK_LOSS_OF_REFCLK1" },
2463 { .irq_msk = BIT(24), .msg = "DMAC0_TX_POISON" },
2464 { .irq_msk = BIT(25), .msg = "DMAC1_TX_POISON" },
2465 { .irq_msk = BIT(26), .msg = "DMAC2_TX_POISON" },
2466 { .irq_msk = BIT(27), .msg = "DMAC3_TX_POISON" },
2467 { .irq_msk = BIT(28), .msg = "DMAC4_TX_POISON" },
2468 { .irq_msk = BIT(29), .msg = "DMAC5_TX_POISON" },
2469 { .irq_msk = BIT(30), .msg = "DMAC6_TX_POISON" },
2470 { .irq_msk = BIT(31), .msg = "DMAC7_TX_POISON" },
2471};
2472
2473static const struct hisi_sas_hw_error sas_ras_intr1_nfe[] = {
2474 { .irq_msk = BIT(0), .msg = "RXM_CFG_MEM3_ECC2B_INTR" },
2475 { .irq_msk = BIT(1), .msg = "RXM_CFG_MEM2_ECC2B_INTR" },
2476 { .irq_msk = BIT(2), .msg = "RXM_CFG_MEM1_ECC2B_INTR" },
2477 { .irq_msk = BIT(3), .msg = "RXM_CFG_MEM0_ECC2B_INTR" },
2478 { .irq_msk = BIT(4), .msg = "HGC_CQE_ECC2B_INTR" },
2479 { .irq_msk = BIT(5), .msg = "LM_CFG_IOSTL_ECC2B_INTR" },
2480 { .irq_msk = BIT(6), .msg = "LM_CFG_ITCTL_ECC2B_INTR" },
2481 { .irq_msk = BIT(7), .msg = "HGC_ITCT_ECC2B_INTR" },
2482 { .irq_msk = BIT(8), .msg = "HGC_IOST_ECC2B_INTR" },
2483 { .irq_msk = BIT(9), .msg = "HGC_DQE_ECC2B_INTR" },
2484 { .irq_msk = BIT(10), .msg = "DMAC0_RAM_ECC2B_INTR" },
2485 { .irq_msk = BIT(11), .msg = "DMAC1_RAM_ECC2B_INTR" },
2486 { .irq_msk = BIT(12), .msg = "DMAC2_RAM_ECC2B_INTR" },
2487 { .irq_msk = BIT(13), .msg = "DMAC3_RAM_ECC2B_INTR" },
2488 { .irq_msk = BIT(14), .msg = "DMAC4_RAM_ECC2B_INTR" },
2489 { .irq_msk = BIT(15), .msg = "DMAC5_RAM_ECC2B_INTR" },
2490 { .irq_msk = BIT(16), .msg = "DMAC6_RAM_ECC2B_INTR" },
2491 { .irq_msk = BIT(17), .msg = "DMAC7_RAM_ECC2B_INTR" },
2492 { .irq_msk = BIT(18), .msg = "OOO_RAM_ECC2B_INTR" },
2493 { .irq_msk = BIT(20), .msg = "HGC_DQE_POISON_INTR" },
2494 { .irq_msk = BIT(21), .msg = "HGC_IOST_POISON_INTR" },
2495 { .irq_msk = BIT(22), .msg = "HGC_ITCT_POISON_INTR" },
2496 { .irq_msk = BIT(23), .msg = "HGC_ITCT_NCQ_POISON_INTR" },
2497 { .irq_msk = BIT(24), .msg = "DMAC0_RX_POISON" },
2498 { .irq_msk = BIT(25), .msg = "DMAC1_RX_POISON" },
2499 { .irq_msk = BIT(26), .msg = "DMAC2_RX_POISON" },
2500 { .irq_msk = BIT(27), .msg = "DMAC3_RX_POISON" },
2501 { .irq_msk = BIT(28), .msg = "DMAC4_RX_POISON" },
2502 { .irq_msk = BIT(29), .msg = "DMAC5_RX_POISON" },
2503 { .irq_msk = BIT(30), .msg = "DMAC6_RX_POISON" },
2504 { .irq_msk = BIT(31), .msg = "DMAC7_RX_POISON" },
2505};
2506
c13c7ac5
XT
2507static const struct hisi_sas_hw_error sas_ras_intr2_nfe[] = {
2508 { .irq_msk = BIT(0), .msg = "DMAC0_AXI_BUS_ERR" },
2509 { .irq_msk = BIT(1), .msg = "DMAC1_AXI_BUS_ERR" },
2510 { .irq_msk = BIT(2), .msg = "DMAC2_AXI_BUS_ERR" },
2511 { .irq_msk = BIT(3), .msg = "DMAC3_AXI_BUS_ERR" },
2512 { .irq_msk = BIT(4), .msg = "DMAC4_AXI_BUS_ERR" },
2513 { .irq_msk = BIT(5), .msg = "DMAC5_AXI_BUS_ERR" },
2514 { .irq_msk = BIT(6), .msg = "DMAC6_AXI_BUS_ERR" },
2515 { .irq_msk = BIT(7), .msg = "DMAC7_AXI_BUS_ERR" },
2516 { .irq_msk = BIT(8), .msg = "DMAC0_FIFO_OMIT_ERR" },
2517 { .irq_msk = BIT(9), .msg = "DMAC1_FIFO_OMIT_ERR" },
2518 { .irq_msk = BIT(10), .msg = "DMAC2_FIFO_OMIT_ERR" },
2519 { .irq_msk = BIT(11), .msg = "DMAC3_FIFO_OMIT_ERR" },
2520 { .irq_msk = BIT(12), .msg = "DMAC4_FIFO_OMIT_ERR" },
2521 { .irq_msk = BIT(13), .msg = "DMAC5_FIFO_OMIT_ERR" },
2522 { .irq_msk = BIT(14), .msg = "DMAC6_FIFO_OMIT_ERR" },
2523 { .irq_msk = BIT(15), .msg = "DMAC7_FIFO_OMIT_ERR" },
2524 { .irq_msk = BIT(16), .msg = "HGC_RLSE_SLOT_UNMATCH" },
2525 { .irq_msk = BIT(17), .msg = "HGC_LM_ADD_FCH_LIST_ERR" },
2526 { .irq_msk = BIT(18), .msg = "HGC_AXI_BUS_ERR" },
2527 { .irq_msk = BIT(19), .msg = "HGC_FIFO_OMIT_ERR" },
2528};
2529
56b72168
XT
2530static bool process_non_fatal_error_v3_hw(struct hisi_hba *hisi_hba)
2531{
2532 struct device *dev = hisi_hba->dev;
2533 const struct hisi_sas_hw_error *ras_error;
2534 bool need_reset = false;
2535 u32 irq_value;
2536 int i;
2537
2538 irq_value = hisi_sas_read32(hisi_hba, SAS_RAS_INTR0);
2539 for (i = 0; i < ARRAY_SIZE(sas_ras_intr0_nfe); i++) {
2540 ras_error = &sas_ras_intr0_nfe[i];
2541 if (ras_error->irq_msk & irq_value) {
2542 dev_warn(dev, "SAS_RAS_INTR0: %s(irq_value=0x%x) found.\n",
2543 ras_error->msg, irq_value);
2544 need_reset = true;
2545 }
2546 }
2547 hisi_sas_write32(hisi_hba, SAS_RAS_INTR0, irq_value);
2548
2549 irq_value = hisi_sas_read32(hisi_hba, SAS_RAS_INTR1);
2550 for (i = 0; i < ARRAY_SIZE(sas_ras_intr1_nfe); i++) {
2551 ras_error = &sas_ras_intr1_nfe[i];
2552 if (ras_error->irq_msk & irq_value) {
2553 dev_warn(dev, "SAS_RAS_INTR1: %s(irq_value=0x%x) found.\n",
2554 ras_error->msg, irq_value);
2555 need_reset = true;
2556 }
2557 }
2558 hisi_sas_write32(hisi_hba, SAS_RAS_INTR1, irq_value);
2559
c13c7ac5
XT
2560 irq_value = hisi_sas_read32(hisi_hba, SAS_RAS_INTR2);
2561 for (i = 0; i < ARRAY_SIZE(sas_ras_intr2_nfe); i++) {
2562 ras_error = &sas_ras_intr2_nfe[i];
2563 if (ras_error->irq_msk & irq_value) {
2564 dev_warn(dev, "SAS_RAS_INTR2: %s(irq_value=0x%x) found.\n",
2565 ras_error->msg, irq_value);
2566 need_reset = true;
2567 }
2568 }
2569 hisi_sas_write32(hisi_hba, SAS_RAS_INTR2, irq_value);
2570
56b72168
XT
2571 return need_reset;
2572}
2573
2574static pci_ers_result_t hisi_sas_error_detected_v3_hw(struct pci_dev *pdev,
2575 pci_channel_state_t state)
2576{
2577 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
2578 struct hisi_hba *hisi_hba = sha->lldd_ha;
2579 struct device *dev = hisi_hba->dev;
2580
2581 dev_info(dev, "PCI error: detected callback, state(%d)!!\n", state);
2582 if (state == pci_channel_io_perm_failure)
2583 return PCI_ERS_RESULT_DISCONNECT;
2584
2585 if (process_non_fatal_error_v3_hw(hisi_hba))
2586 return PCI_ERS_RESULT_NEED_RESET;
2587
2588 return PCI_ERS_RESULT_CAN_RECOVER;
2589}
2590
2591static pci_ers_result_t hisi_sas_mmio_enabled_v3_hw(struct pci_dev *pdev)
2592{
2593 return PCI_ERS_RESULT_RECOVERED;
2594}
2595
2596static pci_ers_result_t hisi_sas_slot_reset_v3_hw(struct pci_dev *pdev)
2597{
2598 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
2599 struct hisi_hba *hisi_hba = sha->lldd_ha;
2600 struct device *dev = hisi_hba->dev;
2601 HISI_SAS_DECLARE_RST_WORK_ON_STACK(r);
2602
2603 dev_info(dev, "PCI error: slot reset callback!!\n");
2604 queue_work(hisi_hba->wq, &r.work);
2605 wait_for_completion(r.completion);
2606 if (r.done)
2607 return PCI_ERS_RESULT_RECOVERED;
2608
2609 return PCI_ERS_RESULT_DISCONNECT;
2610}
2611
e851852b
XT
2612static void hisi_sas_reset_prepare_v3_hw(struct pci_dev *pdev)
2613{
2614 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
2615 struct hisi_hba *hisi_hba = sha->lldd_ha;
2616 struct device *dev = hisi_hba->dev;
2617 int rc;
2618
2619 dev_info(dev, "FLR prepare\n");
2620 set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags);
2621 hisi_sas_controller_reset_prepare(hisi_hba);
2622
2623 rc = disable_host_v3_hw(hisi_hba);
2624 if (rc)
2625 dev_err(dev, "FLR: disable host failed rc=%d\n", rc);
2626}
2627
2628static void hisi_sas_reset_done_v3_hw(struct pci_dev *pdev)
2629{
2630 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
2631 struct hisi_hba *hisi_hba = sha->lldd_ha;
2632 struct device *dev = hisi_hba->dev;
2633 int rc;
2634
2635 hisi_sas_init_mem(hisi_hba);
2636
2637 rc = hw_init_v3_hw(hisi_hba);
2638 if (rc) {
2639 dev_err(dev, "FLR: hw init failed rc=%d\n", rc);
2640 return;
2641 }
2642
2643 hisi_sas_controller_reset_done(hisi_hba);
2644 dev_info(dev, "FLR done\n");
2645}
2646
92f61e3b
JG
2647enum {
2648 /* instances of the controller */
2649 hip08,
2650};
2651
33623483
XC
2652static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
2653{
2654 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
2655 struct hisi_hba *hisi_hba = sha->lldd_ha;
2656 struct device *dev = hisi_hba->dev;
2657 struct Scsi_Host *shost = hisi_hba->shost;
b8438c40 2658 pci_power_t device_state;
33623483 2659 int rc;
33623483
XC
2660
2661 if (!pdev->pm_cap) {
2662 dev_err(dev, "PCI PM not supported\n");
2663 return -ENODEV;
2664 }
2665
84b58ff9
XT
2666 if (test_and_set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
2667 return -1;
2668
33623483
XC
2669 scsi_block_requests(shost);
2670 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
2671 flush_workqueue(hisi_hba->wq);
33623483 2672
1d51757d 2673 rc = disable_host_v3_hw(hisi_hba);
33623483 2674 if (rc) {
1d51757d 2675 dev_err(dev, "PM suspend: disable host failed rc=%d\n", rc);
33623483
XC
2676 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
2677 clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags);
2678 scsi_unblock_requests(shost);
2679 return rc;
2680 }
2681
2682 hisi_sas_init_mem(hisi_hba);
2683
2684 device_state = pci_choose_state(pdev, state);
2685 dev_warn(dev, "entering operating state [D%d]\n",
2686 device_state);
2687 pci_save_state(pdev);
2688 pci_disable_device(pdev);
2689 pci_set_power_state(pdev, device_state);
2690
33623483 2691 hisi_sas_release_tasks(hisi_hba);
33623483
XC
2692
2693 sas_suspend_ha(sha);
2694 return 0;
2695}
2696
2697static int hisi_sas_v3_resume(struct pci_dev *pdev)
2698{
2699 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
2700 struct hisi_hba *hisi_hba = sha->lldd_ha;
2701 struct Scsi_Host *shost = hisi_hba->shost;
2702 struct device *dev = hisi_hba->dev;
2703 unsigned int rc;
b8438c40 2704 pci_power_t device_state = pdev->current_state;
33623483
XC
2705
2706 dev_warn(dev, "resuming from operating state [D%d]\n",
2707 device_state);
2708 pci_set_power_state(pdev, PCI_D0);
2709 pci_enable_wake(pdev, PCI_D0, 0);
2710 pci_restore_state(pdev);
2711 rc = pci_enable_device(pdev);
2712 if (rc)
2713 dev_err(dev, "enable device failed during resume (%d)\n", rc);
2714
2715 pci_set_master(pdev);
2716 scsi_unblock_requests(shost);
2717 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
2718
2719 sas_prep_resume_ha(sha);
2720 init_reg_v3_hw(hisi_hba);
2721 hisi_hba->hw->phys_init(hisi_hba);
2722 sas_resume_ha(sha);
2723 clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags);
2724
2725 return 0;
2726}
2727
92f61e3b
JG
2728static const struct pci_device_id sas_v3_pci_table[] = {
2729 { PCI_VDEVICE(HUAWEI, 0xa230), hip08 },
2730 {}
2731};
a48c4524 2732MODULE_DEVICE_TABLE(pci, sas_v3_pci_table);
92f61e3b 2733
56b72168
XT
2734static const struct pci_error_handlers hisi_sas_err_handler = {
2735 .error_detected = hisi_sas_error_detected_v3_hw,
2736 .mmio_enabled = hisi_sas_mmio_enabled_v3_hw,
2737 .slot_reset = hisi_sas_slot_reset_v3_hw,
e851852b
XT
2738 .reset_prepare = hisi_sas_reset_prepare_v3_hw,
2739 .reset_done = hisi_sas_reset_done_v3_hw,
56b72168
XT
2740};
2741
92f61e3b
JG
2742static struct pci_driver sas_v3_pci_driver = {
2743 .name = DRV_NAME,
2744 .id_table = sas_v3_pci_table,
2745 .probe = hisi_sas_v3_probe,
2746 .remove = hisi_sas_v3_remove,
33623483
XC
2747 .suspend = hisi_sas_v3_suspend,
2748 .resume = hisi_sas_v3_resume,
56b72168 2749 .err_handler = &hisi_sas_err_handler,
92f61e3b
JG
2750};
2751
2752module_pci_driver(sas_v3_pci_driver);
6cc8d8f2 2753module_param_named(intr_conv, hisi_sas_intr_conv, bool, 0444);
92f61e3b 2754
92f61e3b
JG
2755MODULE_LICENSE("GPL");
2756MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
2757MODULE_DESCRIPTION("HISILICON SAS controller v3 hw driver based on pci device");
a48c4524 2758MODULE_ALIAS("pci:" DRV_NAME);