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