]>
Commit | Line | Data |
---|---|---|
92f61e3b JG |
1 | /* |
2 | * Copyright (c) 2017 Hisilicon Limited. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | */ | |
10 | ||
11 | #include "hisi_sas.h" | |
12 | #define DRV_NAME "hisi_sas_v3_hw" | |
13 | ||
c94d8ca2 XC |
14 | /* global registers need init*/ |
15 | #define DLVRY_QUEUE_ENABLE 0x0 | |
16 | #define IOST_BASE_ADDR_LO 0x8 | |
17 | #define IOST_BASE_ADDR_HI 0xc | |
18 | #define ITCT_BASE_ADDR_LO 0x10 | |
19 | #define ITCT_BASE_ADDR_HI 0x14 | |
20 | #define IO_BROKEN_MSG_ADDR_LO 0x18 | |
21 | #define IO_BROKEN_MSG_ADDR_HI 0x1c | |
3975f605 XC |
22 | #define PHY_CONTEXT 0x20 |
23 | #define PHY_STATE 0x24 | |
24 | #define PHY_PORT_NUM_MA 0x28 | |
25 | #define PHY_CONN_RATE 0x30 | |
182e7222 XC |
26 | #define ITCT_CLR 0x44 |
27 | #define ITCT_CLR_EN_OFF 16 | |
28 | #define ITCT_CLR_EN_MSK (0x1 << ITCT_CLR_EN_OFF) | |
29 | #define ITCT_DEV_OFF 0 | |
30 | #define ITCT_DEV_MSK (0x7ff << ITCT_DEV_OFF) | |
c94d8ca2 XC |
31 | #define IO_SATA_BROKEN_MSG_ADDR_LO 0x58 |
32 | #define IO_SATA_BROKEN_MSG_ADDR_HI 0x5c | |
33 | #define SATA_INITI_D2H_STORE_ADDR_LO 0x60 | |
34 | #define SATA_INITI_D2H_STORE_ADDR_HI 0x64 | |
35 | #define CFG_MAX_TAG 0x68 | |
36 | #define HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL 0x84 | |
37 | #define HGC_SAS_TXFAIL_RETRY_CTRL 0x88 | |
38 | #define HGC_GET_ITV_TIME 0x90 | |
39 | #define DEVICE_MSG_WORK_MODE 0x94 | |
40 | #define OPENA_WT_CONTI_TIME 0x9c | |
41 | #define I_T_NEXUS_LOSS_TIME 0xa0 | |
42 | #define MAX_CON_TIME_LIMIT_TIME 0xa4 | |
43 | #define BUS_INACTIVE_LIMIT_TIME 0xa8 | |
44 | #define REJECT_TO_OPEN_LIMIT_TIME 0xac | |
45 | #define CFG_AGING_TIME 0xbc | |
46 | #define HGC_DFX_CFG2 0xc0 | |
47 | #define CFG_ABT_SET_QUERY_IPTT 0xd4 | |
48 | #define CFG_SET_ABORTED_IPTT_OFF 0 | |
49 | #define CFG_SET_ABORTED_IPTT_MSK (0xfff << CFG_SET_ABORTED_IPTT_OFF) | |
d30ff263 XC |
50 | #define CFG_SET_ABORTED_EN_OFF 12 |
51 | #define CFG_ABT_SET_IPTT_DONE 0xd8 | |
52 | #define CFG_ABT_SET_IPTT_DONE_OFF 0 | |
53 | #define HGC_IOMB_PROC1_STATUS 0x104 | |
c94d8ca2 | 54 | #define CFG_1US_TIMER_TRSH 0xcc |
3975f605 | 55 | #define CHNL_INT_STATUS 0x148 |
c94d8ca2 XC |
56 | #define INT_COAL_EN 0x19c |
57 | #define OQ_INT_COAL_TIME 0x1a0 | |
58 | #define OQ_INT_COAL_CNT 0x1a4 | |
59 | #define ENT_INT_COAL_TIME 0x1a8 | |
60 | #define ENT_INT_COAL_CNT 0x1ac | |
61 | #define OQ_INT_SRC 0x1b0 | |
62 | #define OQ_INT_SRC_MSK 0x1b4 | |
63 | #define ENT_INT_SRC1 0x1b8 | |
64 | #define ENT_INT_SRC1_D2H_FIS_CH0_OFF 0 | |
65 | #define ENT_INT_SRC1_D2H_FIS_CH0_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH0_OFF) | |
66 | #define ENT_INT_SRC1_D2H_FIS_CH1_OFF 8 | |
67 | #define ENT_INT_SRC1_D2H_FIS_CH1_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH1_OFF) | |
68 | #define ENT_INT_SRC2 0x1bc | |
69 | #define ENT_INT_SRC3 0x1c0 | |
70 | #define ENT_INT_SRC3_WP_DEPTH_OFF 8 | |
71 | #define ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF 9 | |
72 | #define ENT_INT_SRC3_RP_DEPTH_OFF 10 | |
73 | #define ENT_INT_SRC3_AXI_OFF 11 | |
74 | #define ENT_INT_SRC3_FIFO_OFF 12 | |
75 | #define ENT_INT_SRC3_LM_OFF 14 | |
76 | #define ENT_INT_SRC3_ITC_INT_OFF 15 | |
77 | #define ENT_INT_SRC3_ITC_INT_MSK (0x1 << ENT_INT_SRC3_ITC_INT_OFF) | |
78 | #define ENT_INT_SRC3_ABT_OFF 16 | |
79 | #define ENT_INT_SRC_MSK1 0x1c4 | |
80 | #define ENT_INT_SRC_MSK2 0x1c8 | |
81 | #define ENT_INT_SRC_MSK3 0x1cc | |
3975f605 | 82 | #define ENT_INT_SRC_MSK3_ENT95_MSK_OFF 31 |
c94d8ca2 XC |
83 | #define CHNL_PHYUPDOWN_INT_MSK 0x1d0 |
84 | #define CHNL_ENT_INT_MSK 0x1d4 | |
85 | #define HGC_COM_INT_MSK 0x1d8 | |
3975f605 | 86 | #define ENT_INT_SRC_MSK3_ENT95_MSK_MSK (0x1 << ENT_INT_SRC_MSK3_ENT95_MSK_OFF) |
c94d8ca2 XC |
87 | #define SAS_ECC_INTR 0x1e8 |
88 | #define SAS_ECC_INTR_MSK 0x1ec | |
89 | #define HGC_ERR_STAT_EN 0x238 | |
90 | #define DLVRY_Q_0_BASE_ADDR_LO 0x260 | |
91 | #define DLVRY_Q_0_BASE_ADDR_HI 0x264 | |
92 | #define DLVRY_Q_0_DEPTH 0x268 | |
93 | #define DLVRY_Q_0_WR_PTR 0x26c | |
94 | #define DLVRY_Q_0_RD_PTR 0x270 | |
95 | #define HYPER_STREAM_ID_EN_CFG 0xc80 | |
96 | #define OQ0_INT_SRC_MSK 0xc90 | |
97 | #define COMPL_Q_0_BASE_ADDR_LO 0x4e0 | |
98 | #define COMPL_Q_0_BASE_ADDR_HI 0x4e4 | |
99 | #define COMPL_Q_0_DEPTH 0x4e8 | |
100 | #define COMPL_Q_0_WR_PTR 0x4ec | |
101 | #define COMPL_Q_0_RD_PTR 0x4f0 | |
102 | #define AWQOS_AWCACHE_CFG 0xc84 | |
103 | #define ARQOS_ARCACHE_CFG 0xc88 | |
104 | ||
105 | /* phy registers requiring init */ | |
106 | #define PORT_BASE (0x2000) | |
3975f605 XC |
107 | #define PHY_CFG (PORT_BASE + 0x0) |
108 | #define HARD_PHY_LINKRATE (PORT_BASE + 0x4) | |
109 | #define PHY_CFG_ENA_OFF 0 | |
110 | #define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF) | |
111 | #define PHY_CFG_DC_OPT_OFF 2 | |
112 | #define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF) | |
c94d8ca2 XC |
113 | #define PROG_PHY_LINK_RATE (PORT_BASE + 0x8) |
114 | #define PHY_CTRL (PORT_BASE + 0x14) | |
115 | #define PHY_CTRL_RESET_OFF 0 | |
116 | #define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF) | |
117 | #define SL_CFG (PORT_BASE + 0x84) | |
3975f605 XC |
118 | #define SL_CONTROL (PORT_BASE + 0x94) |
119 | #define SL_CONTROL_NOTIFY_EN_OFF 0 | |
120 | #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF) | |
121 | #define SL_CTA_OFF 17 | |
122 | #define SL_CTA_MSK (0x1 << SL_CTA_OFF) | |
123 | #define TX_ID_DWORD0 (PORT_BASE + 0x9c) | |
124 | #define TX_ID_DWORD1 (PORT_BASE + 0xa0) | |
125 | #define TX_ID_DWORD2 (PORT_BASE + 0xa4) | |
126 | #define TX_ID_DWORD3 (PORT_BASE + 0xa8) | |
127 | #define TX_ID_DWORD4 (PORT_BASE + 0xaC) | |
128 | #define TX_ID_DWORD5 (PORT_BASE + 0xb0) | |
129 | #define TX_ID_DWORD6 (PORT_BASE + 0xb4) | |
130 | #define TXID_AUTO (PORT_BASE + 0xb8) | |
131 | #define CT3_OFF 1 | |
132 | #define CT3_MSK (0x1 << CT3_OFF) | |
402cd9f0 XC |
133 | #define TX_HARDRST_OFF 2 |
134 | #define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF) | |
3975f605 | 135 | #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4) |
c94d8ca2 | 136 | #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc) |
81036731 | 137 | #define STP_LINK_TIMER (PORT_BASE + 0x120) |
c94d8ca2 XC |
138 | #define SAS_SSP_CON_TIMER_CFG (PORT_BASE + 0x134) |
139 | #define SAS_SMP_CON_TIMER_CFG (PORT_BASE + 0x138) | |
140 | #define SAS_STP_CON_TIMER_CFG (PORT_BASE + 0x13c) | |
141 | #define CHL_INT0 (PORT_BASE + 0x1b4) | |
142 | #define CHL_INT0_HOTPLUG_TOUT_OFF 0 | |
143 | #define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF) | |
144 | #define CHL_INT0_SL_RX_BCST_ACK_OFF 1 | |
145 | #define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF) | |
146 | #define CHL_INT0_SL_PHY_ENABLE_OFF 2 | |
147 | #define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF) | |
148 | #define CHL_INT0_NOT_RDY_OFF 4 | |
149 | #define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF) | |
150 | #define CHL_INT0_PHY_RDY_OFF 5 | |
151 | #define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF) | |
152 | #define CHL_INT1 (PORT_BASE + 0x1b8) | |
153 | #define CHL_INT1_DMAC_TX_ECC_ERR_OFF 15 | |
154 | #define CHL_INT1_DMAC_TX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_TX_ECC_ERR_OFF) | |
155 | #define CHL_INT1_DMAC_RX_ECC_ERR_OFF 17 | |
156 | #define CHL_INT1_DMAC_RX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_RX_ECC_ERR_OFF) | |
157 | #define CHL_INT2 (PORT_BASE + 0x1bc) | |
158 | #define CHL_INT0_MSK (PORT_BASE + 0x1c0) | |
159 | #define CHL_INT1_MSK (PORT_BASE + 0x1c4) | |
160 | #define CHL_INT2_MSK (PORT_BASE + 0x1c8) | |
161 | #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0) | |
162 | #define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0) | |
163 | #define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4) | |
164 | #define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8) | |
165 | #define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc) | |
166 | #define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0) | |
167 | #define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4) | |
a25d0d3d XC |
168 | #define DMA_TX_STATUS (PORT_BASE + 0x2d0) |
169 | #define DMA_TX_STATUS_BUSY_OFF 0 | |
170 | #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF) | |
171 | #define DMA_RX_STATUS (PORT_BASE + 0x2e8) | |
172 | #define DMA_RX_STATUS_BUSY_OFF 0 | |
173 | #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF) | |
174 | ||
a25d0d3d XC |
175 | #define DEFAULT_ITCT_HW 2048 /* reset value, not reprogrammed */ |
176 | #if (HISI_SAS_MAX_DEVICES > DEFAULT_ITCT_HW) | |
177 | #error Max ITCT exceeded | |
178 | #endif | |
179 | ||
180 | #define AXI_MASTER_CFG_BASE (0x5000) | |
181 | #define AM_CTRL_GLOBAL (0x0) | |
182 | #define AM_CURR_TRANS_RETURN (0x150) | |
183 | ||
184 | #define AM_CFG_MAX_TRANS (0x5010) | |
185 | #define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014) | |
186 | #define AXI_CFG (0x5100) | |
187 | #define AM_ROB_ECC_ERR_ADDR (0x510c) | |
188 | #define AM_ROB_ECC_ONEBIT_ERR_ADDR_OFF 0 | |
189 | #define AM_ROB_ECC_ONEBIT_ERR_ADDR_MSK (0xff << AM_ROB_ECC_ONEBIT_ERR_ADDR_OFF) | |
190 | #define AM_ROB_ECC_MULBIT_ERR_ADDR_OFF 8 | |
191 | #define AM_ROB_ECC_MULBIT_ERR_ADDR_MSK (0xff << AM_ROB_ECC_MULBIT_ERR_ADDR_OFF) | |
c94d8ca2 | 192 | |
a2204723 XC |
193 | /* HW dma structures */ |
194 | /* Delivery queue header */ | |
195 | /* dw0 */ | |
4de0ca69 XC |
196 | #define CMD_HDR_ABORT_FLAG_OFF 0 |
197 | #define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF) | |
198 | #define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2 | |
199 | #define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF) | |
a2204723 XC |
200 | #define CMD_HDR_RESP_REPORT_OFF 5 |
201 | #define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF) | |
202 | #define CMD_HDR_TLR_CTRL_OFF 6 | |
203 | #define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF) | |
204 | #define CMD_HDR_PORT_OFF 18 | |
205 | #define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF) | |
206 | #define CMD_HDR_PRIORITY_OFF 27 | |
207 | #define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF) | |
208 | #define CMD_HDR_CMD_OFF 29 | |
209 | #define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF) | |
210 | /* dw1 */ | |
ce60689e | 211 | #define CMD_HDR_UNCON_CMD_OFF 3 |
a2204723 XC |
212 | #define CMD_HDR_DIR_OFF 5 |
213 | #define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF) | |
ce60689e XC |
214 | #define CMD_HDR_RESET_OFF 7 |
215 | #define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF) | |
a2204723 XC |
216 | #define CMD_HDR_VDTL_OFF 10 |
217 | #define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF) | |
218 | #define CMD_HDR_FRAME_TYPE_OFF 11 | |
219 | #define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF) | |
220 | #define CMD_HDR_DEV_ID_OFF 16 | |
221 | #define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF) | |
222 | /* dw2 */ | |
223 | #define CMD_HDR_CFL_OFF 0 | |
224 | #define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF) | |
ce60689e XC |
225 | #define CMD_HDR_NCQ_TAG_OFF 10 |
226 | #define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF) | |
a2204723 XC |
227 | #define CMD_HDR_MRFL_OFF 15 |
228 | #define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF) | |
229 | #define CMD_HDR_SG_MOD_OFF 24 | |
230 | #define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF) | |
fa913de2 XC |
231 | /* dw3 */ |
232 | #define CMD_HDR_IPTT_OFF 0 | |
233 | #define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF) | |
a2204723 XC |
234 | /* dw6 */ |
235 | #define CMD_HDR_DIF_SGL_LEN_OFF 0 | |
236 | #define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF) | |
237 | #define CMD_HDR_DATA_SGL_LEN_OFF 16 | |
238 | #define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF) | |
4de0ca69 XC |
239 | /* dw7 */ |
240 | #define CMD_HDR_ADDR_MODE_SEL_OFF 15 | |
241 | #define CMD_HDR_ADDR_MODE_SEL_MSK (1 << CMD_HDR_ADDR_MODE_SEL_OFF) | |
242 | #define CMD_HDR_ABORT_IPTT_OFF 16 | |
243 | #define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF) | |
a2204723 | 244 | |
60b4a5ee XC |
245 | /* Completion header */ |
246 | /* dw0 */ | |
247 | #define CMPLT_HDR_CMPLT_OFF 0 | |
248 | #define CMPLT_HDR_CMPLT_MSK (0x3 << CMPLT_HDR_CMPLT_OFF) | |
249 | #define CMPLT_HDR_ERROR_PHASE_OFF 2 | |
250 | #define CMPLT_HDR_ERROR_PHASE_MSK (0xff << CMPLT_HDR_ERROR_PHASE_OFF) | |
251 | #define CMPLT_HDR_RSPNS_XFRD_OFF 10 | |
252 | #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF) | |
253 | #define CMPLT_HDR_ERX_OFF 12 | |
254 | #define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF) | |
255 | #define CMPLT_HDR_ABORT_STAT_OFF 13 | |
256 | #define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF) | |
257 | /* abort_stat */ | |
258 | #define STAT_IO_NOT_VALID 0x1 | |
259 | #define STAT_IO_NO_DEVICE 0x2 | |
260 | #define STAT_IO_COMPLETE 0x3 | |
261 | #define STAT_IO_ABORTED 0x4 | |
262 | /* dw1 */ | |
263 | #define CMPLT_HDR_IPTT_OFF 0 | |
264 | #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF) | |
265 | #define CMPLT_HDR_DEV_ID_OFF 16 | |
266 | #define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF) | |
267 | /* dw3 */ | |
268 | #define CMPLT_HDR_IO_IN_TARGET_OFF 17 | |
269 | #define CMPLT_HDR_IO_IN_TARGET_MSK (0x1 << CMPLT_HDR_IO_IN_TARGET_OFF) | |
270 | ||
182e7222 XC |
271 | /* ITCT header */ |
272 | /* qw0 */ | |
273 | #define ITCT_HDR_DEV_TYPE_OFF 0 | |
274 | #define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF) | |
275 | #define ITCT_HDR_VALID_OFF 2 | |
276 | #define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF) | |
277 | #define ITCT_HDR_MCR_OFF 5 | |
278 | #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF) | |
279 | #define ITCT_HDR_VLN_OFF 9 | |
280 | #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF) | |
281 | #define ITCT_HDR_SMP_TIMEOUT_OFF 16 | |
282 | #define ITCT_HDR_AWT_CONTINUE_OFF 25 | |
283 | #define ITCT_HDR_PORT_ID_OFF 28 | |
284 | #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF) | |
285 | /* qw2 */ | |
286 | #define ITCT_HDR_INLT_OFF 0 | |
287 | #define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF) | |
288 | #define ITCT_HDR_RTOLT_OFF 48 | |
289 | #define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF) | |
290 | ||
c94d8ca2 XC |
291 | struct hisi_sas_complete_v3_hdr { |
292 | __le32 dw0; | |
293 | __le32 dw1; | |
294 | __le32 act; | |
295 | __le32 dw3; | |
296 | }; | |
297 | ||
60b4a5ee XC |
298 | struct hisi_sas_err_record_v3 { |
299 | /* dw0 */ | |
300 | __le32 trans_tx_fail_type; | |
301 | ||
302 | /* dw1 */ | |
303 | __le32 trans_rx_fail_type; | |
304 | ||
305 | /* dw2 */ | |
306 | __le16 dma_tx_err_type; | |
307 | __le16 sipc_rx_err_type; | |
308 | ||
309 | /* dw3 */ | |
310 | __le32 dma_rx_err_type; | |
311 | }; | |
312 | ||
313 | #define RX_DATA_LEN_UNDERFLOW_OFF 6 | |
314 | #define RX_DATA_LEN_UNDERFLOW_MSK (1 << RX_DATA_LEN_UNDERFLOW_OFF) | |
315 | ||
c94d8ca2 | 316 | #define HISI_SAS_COMMAND_ENTRIES_V3_HW 4096 |
3975f605 XC |
317 | #define HISI_SAS_MSI_COUNT_V3_HW 32 |
318 | ||
319 | enum { | |
320 | HISI_SAS_PHY_PHY_UPDOWN, | |
321 | HISI_SAS_PHY_CHNL_INT, | |
322 | HISI_SAS_PHY_INT_NR | |
323 | }; | |
c94d8ca2 | 324 | |
a2204723 XC |
325 | #define DIR_NO_DATA 0 |
326 | #define DIR_TO_INI 1 | |
327 | #define DIR_TO_DEVICE 2 | |
328 | #define DIR_RESERVED 3 | |
329 | ||
ce60689e XC |
330 | #define CMD_IS_UNCONSTRAINT(cmd) \ |
331 | ((cmd == ATA_CMD_READ_LOG_EXT) || \ | |
332 | (cmd == ATA_CMD_READ_LOG_DMA_EXT) || \ | |
333 | (cmd == ATA_CMD_DEV_RESET)) | |
334 | ||
54edeee1 XC |
335 | static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off) |
336 | { | |
337 | void __iomem *regs = hisi_hba->regs + off; | |
338 | ||
339 | return readl(regs); | |
340 | } | |
341 | ||
a2204723 XC |
342 | static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off) |
343 | { | |
344 | void __iomem *regs = hisi_hba->regs + off; | |
345 | ||
346 | return readl_relaxed(regs); | |
347 | } | |
348 | ||
c94d8ca2 XC |
349 | static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val) |
350 | { | |
351 | void __iomem *regs = hisi_hba->regs + off; | |
352 | ||
353 | writel(val, regs); | |
354 | } | |
355 | ||
356 | static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no, | |
357 | u32 off, u32 val) | |
358 | { | |
359 | void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off; | |
360 | ||
361 | writel(val, regs); | |
362 | } | |
363 | ||
3975f605 XC |
364 | static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba, |
365 | int phy_no, u32 off) | |
366 | { | |
367 | void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off; | |
368 | ||
369 | return readl(regs); | |
370 | } | |
371 | ||
c94d8ca2 XC |
372 | static void init_reg_v3_hw(struct hisi_hba *hisi_hba) |
373 | { | |
374 | int i; | |
375 | ||
376 | /* Global registers init */ | |
377 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, | |
378 | (u32)((1ULL << hisi_hba->queue_count) - 1)); | |
3297ded1 | 379 | hisi_sas_write32(hisi_hba, CFG_MAX_TAG, 0xfff0400); |
c94d8ca2 XC |
380 | hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x108); |
381 | hisi_sas_write32(hisi_hba, CFG_1US_TIMER_TRSH, 0xd); | |
382 | hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1); | |
383 | hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1); | |
384 | hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1); | |
385 | hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0xffff); | |
386 | hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff); | |
387 | hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff); | |
388 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff); | |
389 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xfefefefe); | |
390 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xfefefefe); | |
391 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff); | |
392 | hisi_sas_write32(hisi_hba, CHNL_PHYUPDOWN_INT_MSK, 0x0); | |
393 | hisi_sas_write32(hisi_hba, CHNL_ENT_INT_MSK, 0x0); | |
394 | hisi_sas_write32(hisi_hba, HGC_COM_INT_MSK, 0x0); | |
056e4cc6 | 395 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0x0); |
c94d8ca2 XC |
396 | hisi_sas_write32(hisi_hba, AWQOS_AWCACHE_CFG, 0xf0f0); |
397 | hisi_sas_write32(hisi_hba, ARQOS_ARCACHE_CFG, 0xf0f0); | |
398 | for (i = 0; i < hisi_hba->queue_count; i++) | |
399 | hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0); | |
400 | ||
c94d8ca2 | 401 | hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1); |
056e4cc6 | 402 | hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE, 0x30000); |
c94d8ca2 XC |
403 | |
404 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
405 | hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x801); | |
406 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff); | |
407 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff); | |
408 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xffffffff); | |
409 | hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000); | |
410 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff); | |
411 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8ffffbff); | |
c94d8ca2 XC |
412 | hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0); |
413 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0); | |
414 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0); | |
415 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0); | |
416 | hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0); | |
417 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x0); | |
418 | hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, 0x199b4fa); | |
419 | hisi_sas_phy_write32(hisi_hba, i, SAS_SSP_CON_TIMER_CFG, | |
056e4cc6 | 420 | 0xa03e8); |
c94d8ca2 | 421 | hisi_sas_phy_write32(hisi_hba, i, SAS_STP_CON_TIMER_CFG, |
056e4cc6 | 422 | 0xa03e8); |
81036731 XC |
423 | hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, |
424 | 0x7f7a120); | |
c94d8ca2 XC |
425 | } |
426 | for (i = 0; i < hisi_hba->queue_count; i++) { | |
427 | /* Delivery queue */ | |
428 | hisi_sas_write32(hisi_hba, | |
429 | DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14), | |
430 | upper_32_bits(hisi_hba->cmd_hdr_dma[i])); | |
431 | ||
432 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14), | |
433 | lower_32_bits(hisi_hba->cmd_hdr_dma[i])); | |
434 | ||
435 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14), | |
436 | HISI_SAS_QUEUE_SLOTS); | |
437 | ||
438 | /* Completion queue */ | |
439 | hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14), | |
440 | upper_32_bits(hisi_hba->complete_hdr_dma[i])); | |
441 | ||
442 | hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14), | |
443 | lower_32_bits(hisi_hba->complete_hdr_dma[i])); | |
444 | ||
445 | hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14), | |
446 | HISI_SAS_QUEUE_SLOTS); | |
447 | } | |
448 | ||
449 | /* itct */ | |
450 | hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO, | |
451 | lower_32_bits(hisi_hba->itct_dma)); | |
452 | ||
453 | hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI, | |
454 | upper_32_bits(hisi_hba->itct_dma)); | |
455 | ||
456 | /* iost */ | |
457 | hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO, | |
458 | lower_32_bits(hisi_hba->iost_dma)); | |
459 | ||
460 | hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI, | |
461 | upper_32_bits(hisi_hba->iost_dma)); | |
462 | ||
463 | /* breakpoint */ | |
464 | hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO, | |
465 | lower_32_bits(hisi_hba->breakpoint_dma)); | |
466 | ||
467 | hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI, | |
468 | upper_32_bits(hisi_hba->breakpoint_dma)); | |
469 | ||
470 | /* SATA broken msg */ | |
471 | hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO, | |
472 | lower_32_bits(hisi_hba->sata_breakpoint_dma)); | |
473 | ||
474 | hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI, | |
475 | upper_32_bits(hisi_hba->sata_breakpoint_dma)); | |
476 | ||
477 | /* SATA initial fis */ | |
478 | hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO, | |
479 | lower_32_bits(hisi_hba->initial_fis_dma)); | |
480 | ||
481 | hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI, | |
482 | upper_32_bits(hisi_hba->initial_fis_dma)); | |
483 | } | |
484 | ||
3975f605 XC |
485 | static void config_phy_opt_mode_v3_hw(struct hisi_hba *hisi_hba, int phy_no) |
486 | { | |
487 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
488 | ||
489 | cfg &= ~PHY_CFG_DC_OPT_MSK; | |
490 | cfg |= 1 << PHY_CFG_DC_OPT_OFF; | |
491 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
492 | } | |
493 | ||
494 | static void config_id_frame_v3_hw(struct hisi_hba *hisi_hba, int phy_no) | |
495 | { | |
496 | struct sas_identify_frame identify_frame; | |
497 | u32 *identify_buffer; | |
498 | ||
499 | memset(&identify_frame, 0, sizeof(identify_frame)); | |
500 | identify_frame.dev_type = SAS_END_DEVICE; | |
501 | identify_frame.frame_type = 0; | |
502 | identify_frame._un1 = 1; | |
503 | identify_frame.initiator_bits = SAS_PROTOCOL_ALL; | |
504 | identify_frame.target_bits = SAS_PROTOCOL_NONE; | |
505 | memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE); | |
506 | memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE); | |
507 | identify_frame.phy_id = phy_no; | |
508 | identify_buffer = (u32 *)(&identify_frame); | |
509 | ||
510 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0, | |
511 | __swab32(identify_buffer[0])); | |
512 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1, | |
513 | __swab32(identify_buffer[1])); | |
514 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2, | |
515 | __swab32(identify_buffer[2])); | |
516 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3, | |
517 | __swab32(identify_buffer[3])); | |
518 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4, | |
519 | __swab32(identify_buffer[4])); | |
520 | hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5, | |
521 | __swab32(identify_buffer[5])); | |
522 | } | |
523 | ||
182e7222 XC |
524 | static void setup_itct_v3_hw(struct hisi_hba *hisi_hba, |
525 | struct hisi_sas_device *sas_dev) | |
526 | { | |
527 | struct domain_device *device = sas_dev->sas_device; | |
528 | struct device *dev = hisi_hba->dev; | |
529 | u64 qw0, device_id = sas_dev->device_id; | |
530 | struct hisi_sas_itct *itct = &hisi_hba->itct[device_id]; | |
531 | struct domain_device *parent_dev = device->parent; | |
532 | struct asd_sas_port *sas_port = device->port; | |
533 | struct hisi_sas_port *port = to_hisi_sas_port(sas_port); | |
534 | ||
535 | memset(itct, 0, sizeof(*itct)); | |
536 | ||
537 | /* qw0 */ | |
538 | qw0 = 0; | |
539 | switch (sas_dev->dev_type) { | |
540 | case SAS_END_DEVICE: | |
541 | case SAS_EDGE_EXPANDER_DEVICE: | |
542 | case SAS_FANOUT_EXPANDER_DEVICE: | |
543 | qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF; | |
544 | break; | |
545 | case SAS_SATA_DEV: | |
546 | case SAS_SATA_PENDING: | |
547 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) | |
548 | qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF; | |
549 | else | |
550 | qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF; | |
551 | break; | |
552 | default: | |
553 | dev_warn(dev, "setup itct: unsupported dev type (%d)\n", | |
554 | sas_dev->dev_type); | |
555 | } | |
556 | ||
557 | qw0 |= ((1 << ITCT_HDR_VALID_OFF) | | |
558 | (device->linkrate << ITCT_HDR_MCR_OFF) | | |
559 | (1 << ITCT_HDR_VLN_OFF) | | |
560 | (0xfa << ITCT_HDR_SMP_TIMEOUT_OFF) | | |
561 | (1 << ITCT_HDR_AWT_CONTINUE_OFF) | | |
562 | (port->id << ITCT_HDR_PORT_ID_OFF)); | |
563 | itct->qw0 = cpu_to_le64(qw0); | |
564 | ||
565 | /* qw1 */ | |
566 | memcpy(&itct->sas_addr, device->sas_addr, SAS_ADDR_SIZE); | |
567 | itct->sas_addr = __swab64(itct->sas_addr); | |
568 | ||
569 | /* qw2 */ | |
570 | if (!dev_is_sata(device)) | |
571 | itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) | | |
572 | (0x1ULL << ITCT_HDR_RTOLT_OFF)); | |
573 | } | |
574 | ||
575 | static void free_device_v3_hw(struct hisi_hba *hisi_hba, | |
576 | struct hisi_sas_device *sas_dev) | |
577 | { | |
578 | u64 dev_id = sas_dev->device_id; | |
579 | struct device *dev = hisi_hba->dev; | |
580 | struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id]; | |
581 | u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
582 | ||
583 | /* clear the itct interrupt state */ | |
584 | if (ENT_INT_SRC3_ITC_INT_MSK & reg_val) | |
585 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
586 | ENT_INT_SRC3_ITC_INT_MSK); | |
587 | ||
588 | /* clear the itct table*/ | |
589 | reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR); | |
590 | reg_val |= ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK); | |
591 | hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val); | |
592 | ||
593 | udelay(10); | |
594 | reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3); | |
595 | if (ENT_INT_SRC3_ITC_INT_MSK & reg_val) { | |
596 | dev_dbg(dev, "got clear ITCT done interrupt\n"); | |
597 | ||
598 | /* invalid the itct state*/ | |
599 | memset(itct, 0, sizeof(struct hisi_sas_itct)); | |
600 | hisi_sas_write32(hisi_hba, ENT_INT_SRC3, | |
601 | ENT_INT_SRC3_ITC_INT_MSK); | |
182e7222 XC |
602 | |
603 | /* clear the itct */ | |
604 | hisi_sas_write32(hisi_hba, ITCT_CLR, 0); | |
605 | dev_dbg(dev, "clear ITCT ok\n"); | |
606 | } | |
607 | } | |
608 | ||
d30ff263 XC |
609 | static void dereg_device_v3_hw(struct hisi_hba *hisi_hba, |
610 | struct domain_device *device) | |
611 | { | |
612 | struct hisi_sas_slot *slot, *slot2; | |
613 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
614 | u32 cfg_abt_set_query_iptt; | |
615 | ||
616 | cfg_abt_set_query_iptt = hisi_sas_read32(hisi_hba, | |
617 | CFG_ABT_SET_QUERY_IPTT); | |
618 | list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) { | |
619 | cfg_abt_set_query_iptt &= ~CFG_SET_ABORTED_IPTT_MSK; | |
620 | cfg_abt_set_query_iptt |= (1 << CFG_SET_ABORTED_EN_OFF) | | |
621 | (slot->idx << CFG_SET_ABORTED_IPTT_OFF); | |
622 | hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT, | |
623 | cfg_abt_set_query_iptt); | |
624 | } | |
625 | cfg_abt_set_query_iptt &= ~(1 << CFG_SET_ABORTED_EN_OFF); | |
626 | hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT, | |
627 | cfg_abt_set_query_iptt); | |
628 | hisi_sas_write32(hisi_hba, CFG_ABT_SET_IPTT_DONE, | |
629 | 1 << CFG_ABT_SET_IPTT_DONE_OFF); | |
630 | } | |
631 | ||
a25d0d3d XC |
632 | static int reset_hw_v3_hw(struct hisi_hba *hisi_hba) |
633 | { | |
634 | struct device *dev = hisi_hba->dev; | |
635 | int ret; | |
636 | u32 val; | |
637 | ||
638 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0); | |
639 | ||
640 | /* Disable all of the PHYs */ | |
641 | hisi_sas_stop_phys(hisi_hba); | |
642 | udelay(50); | |
643 | ||
644 | /* Ensure axi bus idle */ | |
645 | ret = readl_poll_timeout(hisi_hba->regs + AXI_CFG, val, !val, | |
646 | 20000, 1000000); | |
647 | if (ret) { | |
648 | dev_err(dev, "axi bus is not idle, ret = %d!\n", ret); | |
649 | return -EIO; | |
650 | } | |
651 | ||
652 | if (ACPI_HANDLE(dev)) { | |
653 | acpi_status s; | |
654 | ||
655 | s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL); | |
656 | if (ACPI_FAILURE(s)) { | |
657 | dev_err(dev, "Reset failed\n"); | |
658 | return -EIO; | |
659 | } | |
660 | } else | |
661 | dev_err(dev, "no reset method!\n"); | |
662 | ||
663 | return 0; | |
664 | } | |
665 | ||
c94d8ca2 XC |
666 | static int hw_init_v3_hw(struct hisi_hba *hisi_hba) |
667 | { | |
a25d0d3d XC |
668 | struct device *dev = hisi_hba->dev; |
669 | int rc; | |
670 | ||
671 | rc = reset_hw_v3_hw(hisi_hba); | |
672 | if (rc) { | |
673 | dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc); | |
674 | return rc; | |
675 | } | |
676 | ||
677 | msleep(100); | |
c94d8ca2 XC |
678 | init_reg_v3_hw(hisi_hba); |
679 | ||
680 | return 0; | |
681 | } | |
682 | ||
3975f605 XC |
683 | static void enable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no) |
684 | { | |
685 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
686 | ||
687 | cfg |= PHY_CFG_ENA_MSK; | |
688 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
689 | } | |
690 | ||
402cd9f0 XC |
691 | static void disable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no) |
692 | { | |
693 | u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG); | |
694 | ||
695 | cfg &= ~PHY_CFG_ENA_MSK; | |
696 | hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg); | |
697 | } | |
698 | ||
3975f605 XC |
699 | static void start_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no) |
700 | { | |
701 | config_id_frame_v3_hw(hisi_hba, phy_no); | |
702 | config_phy_opt_mode_v3_hw(hisi_hba, phy_no); | |
703 | enable_phy_v3_hw(hisi_hba, phy_no); | |
704 | } | |
705 | ||
402cd9f0 XC |
706 | static void phy_hard_reset_v3_hw(struct hisi_hba *hisi_hba, int phy_no) |
707 | { | |
708 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
709 | u32 txid_auto; | |
710 | ||
a25d0d3d | 711 | disable_phy_v3_hw(hisi_hba, phy_no); |
402cd9f0 XC |
712 | if (phy->identify.device_type == SAS_END_DEVICE) { |
713 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO); | |
714 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
715 | txid_auto | TX_HARDRST_MSK); | |
716 | } | |
717 | msleep(100); | |
718 | start_phy_v3_hw(hisi_hba, phy_no); | |
719 | } | |
720 | ||
721 | enum sas_linkrate phy_get_max_linkrate_v3_hw(void) | |
722 | { | |
723 | return SAS_LINK_RATE_12_0_GBPS; | |
724 | } | |
725 | ||
3975f605 XC |
726 | static void phys_init_v3_hw(struct hisi_hba *hisi_hba) |
727 | { | |
a25d0d3d XC |
728 | int i; |
729 | ||
730 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
731 | struct hisi_sas_phy *phy = &hisi_hba->phy[i]; | |
732 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
733 | ||
734 | if (!sas_phy->phy->enabled) | |
735 | continue; | |
736 | ||
737 | start_phy_v3_hw(hisi_hba, i); | |
738 | } | |
3975f605 XC |
739 | } |
740 | ||
741 | static void sl_notify_v3_hw(struct hisi_hba *hisi_hba, int phy_no) | |
742 | { | |
743 | u32 sl_control; | |
744 | ||
745 | sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
746 | sl_control |= SL_CONTROL_NOTIFY_EN_MSK; | |
747 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control); | |
748 | msleep(1); | |
749 | sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
750 | sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK; | |
751 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control); | |
752 | } | |
753 | ||
f771d3b0 XC |
754 | static int get_wideport_bitmap_v3_hw(struct hisi_hba *hisi_hba, int port_id) |
755 | { | |
756 | int i, bitmap = 0; | |
757 | u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
758 | ||
759 | for (i = 0; i < hisi_hba->n_phy; i++) | |
760 | if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id) | |
761 | bitmap |= 1 << i; | |
762 | ||
763 | return bitmap; | |
764 | } | |
765 | ||
a2204723 XC |
766 | /** |
767 | * The callpath to this function and upto writing the write | |
768 | * queue pointer should be safe from interruption. | |
769 | */ | |
770 | static int | |
771 | get_free_slot_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq) | |
772 | { | |
773 | struct device *dev = hisi_hba->dev; | |
774 | int queue = dq->id; | |
775 | u32 r, w; | |
776 | ||
777 | w = dq->wr_point; | |
778 | r = hisi_sas_read32_relaxed(hisi_hba, | |
779 | DLVRY_Q_0_RD_PTR + (queue * 0x14)); | |
780 | if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) { | |
781 | dev_warn(dev, "full queue=%d r=%d w=%d\n\n", | |
782 | queue, r, w); | |
783 | return -EAGAIN; | |
784 | } | |
785 | ||
786 | return 0; | |
787 | } | |
788 | ||
789 | static void start_delivery_v3_hw(struct hisi_sas_dq *dq) | |
790 | { | |
791 | struct hisi_hba *hisi_hba = dq->hisi_hba; | |
792 | int dlvry_queue = dq->slot_prep->dlvry_queue; | |
793 | int dlvry_queue_slot = dq->slot_prep->dlvry_queue_slot; | |
794 | ||
795 | dq->wr_point = ++dlvry_queue_slot % HISI_SAS_QUEUE_SLOTS; | |
796 | hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), | |
797 | dq->wr_point); | |
798 | } | |
799 | ||
800 | static int prep_prd_sge_v3_hw(struct hisi_hba *hisi_hba, | |
801 | struct hisi_sas_slot *slot, | |
802 | struct hisi_sas_cmd_hdr *hdr, | |
803 | struct scatterlist *scatter, | |
804 | int n_elem) | |
805 | { | |
f557e32c | 806 | struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot); |
a2204723 XC |
807 | struct device *dev = hisi_hba->dev; |
808 | struct scatterlist *sg; | |
809 | int i; | |
810 | ||
811 | if (n_elem > HISI_SAS_SGE_PAGE_CNT) { | |
812 | dev_err(dev, "prd err: n_elem(%d) > HISI_SAS_SGE_PAGE_CNT", | |
813 | n_elem); | |
814 | return -EINVAL; | |
815 | } | |
816 | ||
a2204723 | 817 | for_each_sg(scatter, sg, n_elem, i) { |
f557e32c | 818 | struct hisi_sas_sge *entry = &sge_page->sge[i]; |
a2204723 XC |
819 | |
820 | entry->addr = cpu_to_le64(sg_dma_address(sg)); | |
821 | entry->page_ctrl_0 = entry->page_ctrl_1 = 0; | |
822 | entry->data_len = cpu_to_le32(sg_dma_len(sg)); | |
823 | entry->data_off = 0; | |
824 | } | |
825 | ||
f557e32c XT |
826 | hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot)); |
827 | ||
a2204723 XC |
828 | hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF); |
829 | ||
830 | return 0; | |
831 | } | |
832 | ||
833 | static int prep_ssp_v3_hw(struct hisi_hba *hisi_hba, | |
834 | struct hisi_sas_slot *slot, int is_tmf, | |
835 | struct hisi_sas_tmf_task *tmf) | |
836 | { | |
837 | struct sas_task *task = slot->task; | |
838 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
839 | struct domain_device *device = task->dev; | |
840 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
841 | struct hisi_sas_port *port = slot->port; | |
842 | struct sas_ssp_task *ssp_task = &task->ssp_task; | |
843 | struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; | |
844 | int has_data = 0, rc, priority = is_tmf; | |
845 | u8 *buf_cmd; | |
846 | u32 dw1 = 0, dw2 = 0; | |
847 | ||
848 | hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) | | |
849 | (2 << CMD_HDR_TLR_CTRL_OFF) | | |
850 | (port->id << CMD_HDR_PORT_OFF) | | |
851 | (priority << CMD_HDR_PRIORITY_OFF) | | |
852 | (1 << CMD_HDR_CMD_OFF)); /* ssp */ | |
853 | ||
854 | dw1 = 1 << CMD_HDR_VDTL_OFF; | |
855 | if (is_tmf) { | |
856 | dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF; | |
857 | dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF; | |
858 | } else { | |
859 | dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF; | |
860 | switch (scsi_cmnd->sc_data_direction) { | |
861 | case DMA_TO_DEVICE: | |
862 | has_data = 1; | |
863 | dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF; | |
864 | break; | |
865 | case DMA_FROM_DEVICE: | |
866 | has_data = 1; | |
867 | dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF; | |
868 | break; | |
869 | default: | |
870 | dw1 &= ~CMD_HDR_DIR_MSK; | |
871 | } | |
872 | } | |
873 | ||
874 | /* map itct entry */ | |
875 | dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; | |
876 | hdr->dw1 = cpu_to_le32(dw1); | |
877 | ||
878 | dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr) | |
879 | + 3) / 4) << CMD_HDR_CFL_OFF) | | |
880 | ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) | | |
881 | (2 << CMD_HDR_SG_MOD_OFF); | |
882 | hdr->dw2 = cpu_to_le32(dw2); | |
883 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
884 | ||
885 | if (has_data) { | |
886 | rc = prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter, | |
887 | slot->n_elem); | |
888 | if (rc) | |
889 | return rc; | |
890 | } | |
891 | ||
892 | hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len); | |
f557e32c XT |
893 | hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot)); |
894 | hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot)); | |
a2204723 | 895 | |
f557e32c XT |
896 | buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) + |
897 | sizeof(struct ssp_frame_hdr); | |
a2204723 | 898 | |
f557e32c | 899 | memcpy(buf_cmd, &task->ssp_task.LUN, 8); |
a2204723 XC |
900 | if (!is_tmf) { |
901 | buf_cmd[9] = ssp_task->task_attr | (ssp_task->task_prio << 3); | |
902 | memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); | |
903 | } else { | |
904 | buf_cmd[10] = tmf->tmf; | |
905 | switch (tmf->tmf) { | |
906 | case TMF_ABORT_TASK: | |
907 | case TMF_QUERY_TASK: | |
908 | buf_cmd[12] = | |
909 | (tmf->tag_of_task_to_be_managed >> 8) & 0xff; | |
910 | buf_cmd[13] = | |
911 | tmf->tag_of_task_to_be_managed & 0xff; | |
912 | break; | |
913 | default: | |
914 | break; | |
915 | } | |
916 | } | |
917 | ||
918 | return 0; | |
919 | } | |
920 | ||
fa913de2 XC |
921 | static int prep_smp_v3_hw(struct hisi_hba *hisi_hba, |
922 | struct hisi_sas_slot *slot) | |
923 | { | |
924 | struct sas_task *task = slot->task; | |
925 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
926 | struct domain_device *device = task->dev; | |
927 | struct device *dev = hisi_hba->dev; | |
928 | struct hisi_sas_port *port = slot->port; | |
929 | struct scatterlist *sg_req, *sg_resp; | |
930 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
931 | dma_addr_t req_dma_addr; | |
932 | unsigned int req_len, resp_len; | |
933 | int elem, rc; | |
934 | ||
935 | /* | |
936 | * DMA-map SMP request, response buffers | |
937 | */ | |
938 | /* req */ | |
939 | sg_req = &task->smp_task.smp_req; | |
940 | elem = dma_map_sg(dev, sg_req, 1, DMA_TO_DEVICE); | |
941 | if (!elem) | |
942 | return -ENOMEM; | |
943 | req_len = sg_dma_len(sg_req); | |
944 | req_dma_addr = sg_dma_address(sg_req); | |
945 | ||
946 | /* resp */ | |
947 | sg_resp = &task->smp_task.smp_resp; | |
948 | elem = dma_map_sg(dev, sg_resp, 1, DMA_FROM_DEVICE); | |
949 | if (!elem) { | |
950 | rc = -ENOMEM; | |
951 | goto err_out_req; | |
952 | } | |
953 | resp_len = sg_dma_len(sg_resp); | |
954 | if ((req_len & 0x3) || (resp_len & 0x3)) { | |
955 | rc = -EINVAL; | |
956 | goto err_out_resp; | |
957 | } | |
958 | ||
959 | /* create header */ | |
960 | /* dw0 */ | |
961 | hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) | | |
962 | (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */ | |
963 | (2 << CMD_HDR_CMD_OFF)); /* smp */ | |
964 | ||
965 | /* map itct entry */ | |
966 | hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) | | |
967 | (1 << CMD_HDR_FRAME_TYPE_OFF) | | |
968 | (DIR_NO_DATA << CMD_HDR_DIR_OFF)); | |
969 | ||
970 | /* dw2 */ | |
971 | hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) | | |
972 | (HISI_SAS_MAX_SMP_RESP_SZ / 4 << | |
973 | CMD_HDR_MRFL_OFF)); | |
974 | ||
975 | hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF); | |
976 | ||
977 | hdr->cmd_table_addr = cpu_to_le64(req_dma_addr); | |
f557e32c | 978 | hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot)); |
fa913de2 XC |
979 | |
980 | return 0; | |
981 | ||
982 | err_out_resp: | |
983 | dma_unmap_sg(dev, &slot->task->smp_task.smp_resp, 1, | |
984 | DMA_FROM_DEVICE); | |
985 | err_out_req: | |
986 | dma_unmap_sg(dev, &slot->task->smp_task.smp_req, 1, | |
987 | DMA_TO_DEVICE); | |
988 | return rc; | |
989 | } | |
990 | ||
ce60689e XC |
991 | static int prep_ata_v3_hw(struct hisi_hba *hisi_hba, |
992 | struct hisi_sas_slot *slot) | |
993 | { | |
994 | struct sas_task *task = slot->task; | |
995 | struct domain_device *device = task->dev; | |
996 | struct domain_device *parent_dev = device->parent; | |
997 | struct hisi_sas_device *sas_dev = device->lldd_dev; | |
998 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
999 | struct asd_sas_port *sas_port = device->port; | |
1000 | struct hisi_sas_port *port = to_hisi_sas_port(sas_port); | |
1001 | u8 *buf_cmd; | |
1002 | int has_data = 0, rc = 0, hdr_tag = 0; | |
1003 | u32 dw1 = 0, dw2 = 0; | |
1004 | ||
1005 | hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF); | |
1006 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) | |
1007 | hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF); | |
1008 | else | |
1009 | hdr->dw0 |= cpu_to_le32(4 << CMD_HDR_CMD_OFF); | |
1010 | ||
1011 | switch (task->data_dir) { | |
1012 | case DMA_TO_DEVICE: | |
1013 | has_data = 1; | |
1014 | dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF; | |
1015 | break; | |
1016 | case DMA_FROM_DEVICE: | |
1017 | has_data = 1; | |
1018 | dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF; | |
1019 | break; | |
1020 | default: | |
1021 | dw1 &= ~CMD_HDR_DIR_MSK; | |
1022 | } | |
1023 | ||
1024 | if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) && | |
1025 | (task->ata_task.fis.control & ATA_SRST)) | |
1026 | dw1 |= 1 << CMD_HDR_RESET_OFF; | |
1027 | ||
1028 | dw1 |= (hisi_sas_get_ata_protocol( | |
1029 | task->ata_task.fis.command, task->data_dir)) | |
1030 | << CMD_HDR_FRAME_TYPE_OFF; | |
1031 | dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; | |
1032 | ||
1033 | if (CMD_IS_UNCONSTRAINT(task->ata_task.fis.command)) | |
1034 | dw1 |= 1 << CMD_HDR_UNCON_CMD_OFF; | |
1035 | ||
1036 | hdr->dw1 = cpu_to_le32(dw1); | |
1037 | ||
1038 | /* dw2 */ | |
8ae6725d | 1039 | if (task->ata_task.use_ncq && hisi_sas_get_ncq_tag(task, &hdr_tag)) { |
ce60689e XC |
1040 | task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); |
1041 | dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF; | |
1042 | } | |
1043 | ||
1044 | dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF | | |
1045 | 2 << CMD_HDR_SG_MOD_OFF; | |
1046 | hdr->dw2 = cpu_to_le32(dw2); | |
1047 | ||
1048 | /* dw3 */ | |
1049 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
1050 | ||
1051 | if (has_data) { | |
1052 | rc = prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter, | |
1053 | slot->n_elem); | |
1054 | if (rc) | |
1055 | return rc; | |
1056 | } | |
1057 | ||
1058 | hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len); | |
f557e32c XT |
1059 | hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot)); |
1060 | hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot)); | |
ce60689e | 1061 | |
f557e32c | 1062 | buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot); |
ce60689e XC |
1063 | |
1064 | if (likely(!task->ata_task.device_control_reg_update)) | |
1065 | task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */ | |
1066 | /* fill in command FIS */ | |
1067 | memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); | |
1068 | ||
1069 | return 0; | |
1070 | } | |
1071 | ||
4de0ca69 XC |
1072 | static int prep_abort_v3_hw(struct hisi_hba *hisi_hba, |
1073 | struct hisi_sas_slot *slot, | |
1074 | int device_id, int abort_flag, int tag_to_abort) | |
1075 | { | |
1076 | struct sas_task *task = slot->task; | |
1077 | struct domain_device *dev = task->dev; | |
1078 | struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; | |
1079 | struct hisi_sas_port *port = slot->port; | |
1080 | ||
1081 | /* dw0 */ | |
1082 | hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/ | |
1083 | (port->id << CMD_HDR_PORT_OFF) | | |
1084 | ((dev_is_sata(dev) ? 1:0) | |
1085 | << CMD_HDR_ABORT_DEVICE_TYPE_OFF) | | |
1086 | (abort_flag | |
1087 | << CMD_HDR_ABORT_FLAG_OFF)); | |
1088 | ||
1089 | /* dw1 */ | |
1090 | hdr->dw1 = cpu_to_le32(device_id | |
1091 | << CMD_HDR_DEV_ID_OFF); | |
1092 | ||
1093 | /* dw7 */ | |
1094 | hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF); | |
1095 | hdr->transfer_tags = cpu_to_le32(slot->idx); | |
1096 | ||
1097 | return 0; | |
1098 | } | |
1099 | ||
54edeee1 XC |
1100 | static int phy_up_v3_hw(int phy_no, struct hisi_hba *hisi_hba) |
1101 | { | |
1102 | int i, res = 0; | |
1103 | u32 context, port_id, link_rate, hard_phy_linkrate; | |
1104 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
1105 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1106 | struct device *dev = hisi_hba->dev; | |
1107 | ||
1108 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1); | |
1109 | ||
1110 | port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA); | |
1111 | port_id = (port_id >> (4 * phy_no)) & 0xf; | |
1112 | link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE); | |
1113 | link_rate = (link_rate >> (phy_no * 4)) & 0xf; | |
1114 | ||
1115 | if (port_id == 0xf) { | |
1116 | dev_err(dev, "phyup: phy%d invalid portid\n", phy_no); | |
1117 | res = IRQ_NONE; | |
1118 | goto end; | |
1119 | } | |
1120 | sas_phy->linkrate = link_rate; | |
1121 | hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1122 | HARD_PHY_LINKRATE); | |
1123 | phy->maximum_linkrate = hard_phy_linkrate & 0xf; | |
1124 | phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf; | |
1125 | phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); | |
1126 | ||
1127 | /* Check for SATA dev */ | |
1128 | context = hisi_sas_read32(hisi_hba, PHY_CONTEXT); | |
1129 | if (context & (1 << phy_no)) { | |
1130 | struct hisi_sas_initial_fis *initial_fis; | |
1131 | struct dev_to_host_fis *fis; | |
1132 | u8 attached_sas_addr[SAS_ADDR_SIZE] = {0}; | |
1133 | ||
1134 | dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate); | |
1135 | initial_fis = &hisi_hba->initial_fis[phy_no]; | |
1136 | fis = &initial_fis->fis; | |
1137 | sas_phy->oob_mode = SATA_OOB_MODE; | |
1138 | attached_sas_addr[0] = 0x50; | |
1139 | attached_sas_addr[7] = phy_no; | |
1140 | memcpy(sas_phy->attached_sas_addr, | |
1141 | attached_sas_addr, | |
1142 | SAS_ADDR_SIZE); | |
1143 | memcpy(sas_phy->frame_rcvd, fis, | |
1144 | sizeof(struct dev_to_host_fis)); | |
1145 | phy->phy_type |= PORT_TYPE_SATA; | |
1146 | phy->identify.device_type = SAS_SATA_DEV; | |
1147 | phy->frame_rcvd_size = sizeof(struct dev_to_host_fis); | |
1148 | phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; | |
1149 | } else { | |
1150 | u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd; | |
1151 | struct sas_identify_frame *id = | |
1152 | (struct sas_identify_frame *)frame_rcvd; | |
1153 | ||
1154 | dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate); | |
1155 | for (i = 0; i < 6; i++) { | |
1156 | u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1157 | RX_IDAF_DWORD0 + (i * 4)); | |
1158 | frame_rcvd[i] = __swab32(idaf); | |
1159 | } | |
1160 | sas_phy->oob_mode = SAS_OOB_MODE; | |
1161 | memcpy(sas_phy->attached_sas_addr, | |
1162 | &id->sas_addr, | |
1163 | SAS_ADDR_SIZE); | |
1164 | phy->phy_type |= PORT_TYPE_SAS; | |
1165 | phy->identify.device_type = id->dev_type; | |
1166 | phy->frame_rcvd_size = sizeof(struct sas_identify_frame); | |
1167 | if (phy->identify.device_type == SAS_END_DEVICE) | |
1168 | phy->identify.target_port_protocols = | |
1169 | SAS_PROTOCOL_SSP; | |
1170 | else if (phy->identify.device_type != SAS_PHY_UNUSED) | |
1171 | phy->identify.target_port_protocols = | |
1172 | SAS_PROTOCOL_SMP; | |
1173 | } | |
1174 | ||
1175 | phy->port_id = port_id; | |
1176 | phy->phy_attached = 1; | |
1177 | queue_work(hisi_hba->wq, &phy->phyup_ws); | |
1178 | ||
1179 | end: | |
1180 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, | |
1181 | CHL_INT0_SL_PHY_ENABLE_MSK); | |
1182 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0); | |
1183 | ||
1184 | return res; | |
1185 | } | |
1186 | ||
1187 | static int phy_down_v3_hw(int phy_no, struct hisi_hba *hisi_hba) | |
1188 | { | |
54edeee1 XC |
1189 | u32 phy_state, sl_ctrl, txid_auto; |
1190 | struct device *dev = hisi_hba->dev; | |
1191 | ||
1192 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1); | |
1193 | ||
1194 | phy_state = hisi_sas_read32(hisi_hba, PHY_STATE); | |
1195 | dev_info(dev, "phydown: phy%d phy_state=0x%x\n", phy_no, phy_state); | |
1196 | hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0); | |
1197 | ||
1198 | sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL); | |
1199 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, | |
1200 | sl_ctrl&(~SL_CTA_MSK)); | |
1201 | ||
1202 | txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO); | |
1203 | hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO, | |
1204 | txid_auto | CT3_MSK); | |
1205 | ||
1206 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK); | |
1207 | hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0); | |
1208 | ||
5aec704f | 1209 | return 0; |
54edeee1 XC |
1210 | } |
1211 | ||
1212 | static void phy_bcast_v3_hw(int phy_no, struct hisi_hba *hisi_hba) | |
1213 | { | |
1214 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
1215 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1216 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; | |
1217 | ||
1218 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1); | |
1219 | sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); | |
1220 | hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, | |
1221 | CHL_INT0_SL_RX_BCST_ACK_MSK); | |
1222 | hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0); | |
1223 | } | |
1224 | ||
1225 | static irqreturn_t int_phy_up_down_bcast_v3_hw(int irq_no, void *p) | |
1226 | { | |
1227 | struct hisi_hba *hisi_hba = p; | |
1228 | u32 irq_msk; | |
1229 | int phy_no = 0; | |
1230 | irqreturn_t res = IRQ_NONE; | |
1231 | ||
1232 | irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS) | |
1233 | & 0x11111111; | |
1234 | while (irq_msk) { | |
1235 | if (irq_msk & 1) { | |
1236 | u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1237 | CHL_INT0); | |
1238 | u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE); | |
1239 | int rdy = phy_state & (1 << phy_no); | |
1240 | ||
1241 | if (rdy) { | |
1242 | if (irq_value & CHL_INT0_SL_PHY_ENABLE_MSK) | |
1243 | /* phy up */ | |
1244 | if (phy_up_v3_hw(phy_no, hisi_hba) | |
1245 | == IRQ_HANDLED) | |
1246 | res = IRQ_HANDLED; | |
1247 | if (irq_value & CHL_INT0_SL_RX_BCST_ACK_MSK) | |
1248 | /* phy bcast */ | |
1249 | phy_bcast_v3_hw(phy_no, hisi_hba); | |
1250 | } else { | |
1251 | if (irq_value & CHL_INT0_NOT_RDY_MSK) | |
1252 | /* phy down */ | |
1253 | if (phy_down_v3_hw(phy_no, hisi_hba) | |
1254 | == IRQ_HANDLED) | |
1255 | res = IRQ_HANDLED; | |
1256 | } | |
1257 | } | |
1258 | irq_msk >>= 4; | |
1259 | phy_no++; | |
1260 | } | |
1261 | ||
1262 | return res; | |
1263 | } | |
1264 | ||
1265 | static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p) | |
1266 | { | |
1267 | struct hisi_hba *hisi_hba = p; | |
1268 | struct device *dev = hisi_hba->dev; | |
1269 | u32 ent_msk, ent_tmp, irq_msk; | |
1270 | int phy_no = 0; | |
1271 | ||
1272 | ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3); | |
1273 | ent_tmp = ent_msk; | |
1274 | ent_msk |= ENT_INT_SRC_MSK3_ENT95_MSK_MSK; | |
1275 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_msk); | |
1276 | ||
1277 | irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS) | |
1278 | & 0xeeeeeeee; | |
1279 | ||
1280 | while (irq_msk) { | |
1281 | u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1282 | CHL_INT0); | |
1283 | u32 irq_value1 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1284 | CHL_INT1); | |
1285 | u32 irq_value2 = hisi_sas_phy_read32(hisi_hba, phy_no, | |
1286 | CHL_INT2); | |
1287 | ||
1288 | if ((irq_msk & (4 << (phy_no * 4))) && | |
1289 | irq_value1) { | |
1290 | if (irq_value1 & (CHL_INT1_DMAC_RX_ECC_ERR_MSK | | |
1291 | CHL_INT1_DMAC_TX_ECC_ERR_MSK)) | |
1292 | panic("%s: DMAC RX/TX ecc bad error! (0x%x)", | |
1293 | dev_name(dev), irq_value1); | |
1294 | ||
1295 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
1296 | CHL_INT1, irq_value1); | |
1297 | } | |
1298 | ||
1299 | if (irq_msk & (8 << (phy_no * 4)) && irq_value2) | |
1300 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
1301 | CHL_INT2, irq_value2); | |
1302 | ||
1303 | ||
1304 | if (irq_msk & (2 << (phy_no * 4)) && irq_value0) { | |
1305 | hisi_sas_phy_write32(hisi_hba, phy_no, | |
1306 | CHL_INT0, irq_value0 | |
4f73575a | 1307 | & (~CHL_INT0_SL_RX_BCST_ACK_MSK) |
54edeee1 XC |
1308 | & (~CHL_INT0_SL_PHY_ENABLE_MSK) |
1309 | & (~CHL_INT0_NOT_RDY_MSK)); | |
1310 | } | |
1311 | irq_msk &= ~(0xe << (phy_no * 4)); | |
1312 | phy_no++; | |
1313 | } | |
1314 | ||
1315 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_tmp); | |
1316 | ||
1317 | return IRQ_HANDLED; | |
1318 | } | |
1319 | ||
60b4a5ee XC |
1320 | static void |
1321 | slot_err_v3_hw(struct hisi_hba *hisi_hba, struct sas_task *task, | |
1322 | struct hisi_sas_slot *slot) | |
1323 | { | |
1324 | struct task_status_struct *ts = &task->task_status; | |
1325 | struct hisi_sas_complete_v3_hdr *complete_queue = | |
1326 | hisi_hba->complete_hdr[slot->cmplt_queue]; | |
1327 | struct hisi_sas_complete_v3_hdr *complete_hdr = | |
1328 | &complete_queue[slot->cmplt_queue_slot]; | |
f557e32c XT |
1329 | struct hisi_sas_err_record_v3 *record = |
1330 | hisi_sas_status_buf_addr_mem(slot); | |
60b4a5ee XC |
1331 | u32 dma_rx_err_type = record->dma_rx_err_type; |
1332 | u32 trans_tx_fail_type = record->trans_tx_fail_type; | |
1333 | ||
1334 | switch (task->task_proto) { | |
1335 | case SAS_PROTOCOL_SSP: | |
1336 | if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) { | |
1337 | ts->residual = trans_tx_fail_type; | |
1338 | ts->stat = SAS_DATA_UNDERRUN; | |
1339 | } else if (complete_hdr->dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) { | |
1340 | ts->stat = SAS_QUEUE_FULL; | |
1341 | slot->abort = 1; | |
1342 | } else { | |
1343 | ts->stat = SAS_OPEN_REJECT; | |
1344 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; | |
1345 | } | |
1346 | break; | |
1347 | case SAS_PROTOCOL_SATA: | |
1348 | case SAS_PROTOCOL_STP: | |
1349 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
1350 | if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) { | |
1351 | ts->residual = trans_tx_fail_type; | |
1352 | ts->stat = SAS_DATA_UNDERRUN; | |
1353 | } else if (complete_hdr->dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) { | |
1354 | ts->stat = SAS_PHY_DOWN; | |
1355 | slot->abort = 1; | |
1356 | } else { | |
1357 | ts->stat = SAS_OPEN_REJECT; | |
1358 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; | |
1359 | } | |
1360 | hisi_sas_sata_done(task, slot); | |
1361 | break; | |
1362 | case SAS_PROTOCOL_SMP: | |
1363 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
1364 | break; | |
1365 | default: | |
1366 | break; | |
1367 | } | |
1368 | } | |
1369 | ||
1370 | static int | |
1371 | slot_complete_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot) | |
1372 | { | |
1373 | struct sas_task *task = slot->task; | |
1374 | struct hisi_sas_device *sas_dev; | |
1375 | struct device *dev = hisi_hba->dev; | |
1376 | struct task_status_struct *ts; | |
1377 | struct domain_device *device; | |
1378 | enum exec_status sts; | |
1379 | struct hisi_sas_complete_v3_hdr *complete_queue = | |
1380 | hisi_hba->complete_hdr[slot->cmplt_queue]; | |
1381 | struct hisi_sas_complete_v3_hdr *complete_hdr = | |
1382 | &complete_queue[slot->cmplt_queue_slot]; | |
1383 | int aborted; | |
1384 | unsigned long flags; | |
1385 | ||
1386 | if (unlikely(!task || !task->lldd_task || !task->dev)) | |
1387 | return -EINVAL; | |
1388 | ||
1389 | ts = &task->task_status; | |
1390 | device = task->dev; | |
1391 | sas_dev = device->lldd_dev; | |
1392 | ||
1393 | spin_lock_irqsave(&task->task_state_lock, flags); | |
1394 | aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED; | |
1395 | task->task_state_flags &= | |
1396 | ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); | |
1397 | spin_unlock_irqrestore(&task->task_state_lock, flags); | |
1398 | ||
1399 | memset(ts, 0, sizeof(*ts)); | |
1400 | ts->resp = SAS_TASK_COMPLETE; | |
1401 | if (unlikely(aborted)) { | |
1402 | ts->stat = SAS_ABORTED_TASK; | |
9feaf909 | 1403 | spin_lock_irqsave(&hisi_hba->lock, flags); |
60b4a5ee | 1404 | hisi_sas_slot_task_free(hisi_hba, task, slot); |
9feaf909 | 1405 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
60b4a5ee XC |
1406 | return -1; |
1407 | } | |
1408 | ||
1409 | if (unlikely(!sas_dev)) { | |
1410 | dev_dbg(dev, "slot complete: port has not device\n"); | |
1411 | ts->stat = SAS_PHY_DOWN; | |
1412 | goto out; | |
1413 | } | |
1414 | ||
1415 | /* | |
1416 | * Use SAS+TMF status codes | |
1417 | */ | |
1418 | switch ((complete_hdr->dw0 & CMPLT_HDR_ABORT_STAT_MSK) | |
1419 | >> CMPLT_HDR_ABORT_STAT_OFF) { | |
1420 | case STAT_IO_ABORTED: | |
1421 | /* this IO has been aborted by abort command */ | |
1422 | ts->stat = SAS_ABORTED_TASK; | |
1423 | goto out; | |
1424 | case STAT_IO_COMPLETE: | |
1425 | /* internal abort command complete */ | |
1426 | ts->stat = TMF_RESP_FUNC_SUCC; | |
1427 | goto out; | |
1428 | case STAT_IO_NO_DEVICE: | |
1429 | ts->stat = TMF_RESP_FUNC_COMPLETE; | |
1430 | goto out; | |
1431 | case STAT_IO_NOT_VALID: | |
1432 | /* | |
1433 | * abort single IO, the controller can't find the IO | |
1434 | */ | |
1435 | ts->stat = TMF_RESP_FUNC_FAILED; | |
1436 | goto out; | |
1437 | default: | |
1438 | break; | |
1439 | } | |
1440 | ||
1441 | /* check for erroneous completion */ | |
1442 | if ((complete_hdr->dw0 & CMPLT_HDR_CMPLT_MSK) == 0x3) { | |
1443 | slot_err_v3_hw(hisi_hba, task, slot); | |
1444 | if (unlikely(slot->abort)) | |
1445 | return ts->stat; | |
1446 | goto out; | |
1447 | } | |
1448 | ||
1449 | switch (task->task_proto) { | |
1450 | case SAS_PROTOCOL_SSP: { | |
f557e32c XT |
1451 | struct ssp_response_iu *iu = |
1452 | hisi_sas_status_buf_addr_mem(slot) + | |
60b4a5ee XC |
1453 | sizeof(struct hisi_sas_err_record); |
1454 | ||
1455 | sas_ssp_task_response(dev, task, iu); | |
1456 | break; | |
1457 | } | |
1458 | case SAS_PROTOCOL_SMP: { | |
1459 | struct scatterlist *sg_resp = &task->smp_task.smp_resp; | |
1460 | void *to; | |
1461 | ||
1462 | ts->stat = SAM_STAT_GOOD; | |
1463 | to = kmap_atomic(sg_page(sg_resp)); | |
1464 | ||
1465 | dma_unmap_sg(dev, &task->smp_task.smp_resp, 1, | |
1466 | DMA_FROM_DEVICE); | |
1467 | dma_unmap_sg(dev, &task->smp_task.smp_req, 1, | |
1468 | DMA_TO_DEVICE); | |
1469 | memcpy(to + sg_resp->offset, | |
f557e32c | 1470 | hisi_sas_status_buf_addr_mem(slot) + |
60b4a5ee XC |
1471 | sizeof(struct hisi_sas_err_record), |
1472 | sg_dma_len(sg_resp)); | |
1473 | kunmap_atomic(to); | |
1474 | break; | |
1475 | } | |
1476 | case SAS_PROTOCOL_SATA: | |
1477 | case SAS_PROTOCOL_STP: | |
1478 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
1479 | ts->stat = SAM_STAT_GOOD; | |
1480 | hisi_sas_sata_done(task, slot); | |
1481 | break; | |
1482 | default: | |
1483 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
1484 | break; | |
1485 | } | |
1486 | ||
1487 | if (!slot->port->port_attached) { | |
1488 | dev_err(dev, "slot complete: port %d has removed\n", | |
1489 | slot->port->sas_port.id); | |
1490 | ts->stat = SAS_PHY_DOWN; | |
1491 | } | |
1492 | ||
1493 | out: | |
1494 | spin_lock_irqsave(&task->task_state_lock, flags); | |
1495 | task->task_state_flags |= SAS_TASK_STATE_DONE; | |
1496 | spin_unlock_irqrestore(&task->task_state_lock, flags); | |
1497 | spin_lock_irqsave(&hisi_hba->lock, flags); | |
1498 | hisi_sas_slot_task_free(hisi_hba, task, slot); | |
1499 | spin_unlock_irqrestore(&hisi_hba->lock, flags); | |
1500 | sts = ts->stat; | |
1501 | ||
1502 | if (task->task_done) | |
1503 | task->task_done(task); | |
1504 | ||
1505 | return sts; | |
1506 | } | |
1507 | ||
1508 | static void cq_tasklet_v3_hw(unsigned long val) | |
1509 | { | |
1510 | struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val; | |
1511 | struct hisi_hba *hisi_hba = cq->hisi_hba; | |
1512 | struct hisi_sas_slot *slot; | |
1513 | struct hisi_sas_itct *itct; | |
1514 | struct hisi_sas_complete_v3_hdr *complete_queue; | |
1515 | u32 rd_point = cq->rd_point, wr_point, dev_id; | |
1516 | int queue = cq->id; | |
1517 | struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; | |
1518 | ||
1519 | complete_queue = hisi_hba->complete_hdr[queue]; | |
1520 | ||
1521 | spin_lock(&dq->lock); | |
1522 | wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR + | |
1523 | (0x14 * queue)); | |
1524 | ||
1525 | while (rd_point != wr_point) { | |
1526 | struct hisi_sas_complete_v3_hdr *complete_hdr; | |
1527 | int iptt; | |
1528 | ||
1529 | complete_hdr = &complete_queue[rd_point]; | |
1530 | ||
1531 | /* Check for NCQ completion */ | |
1532 | if (complete_hdr->act) { | |
1533 | u32 act_tmp = complete_hdr->act; | |
1534 | int ncq_tag_count = ffs(act_tmp); | |
1535 | ||
1536 | dev_id = (complete_hdr->dw1 & CMPLT_HDR_DEV_ID_MSK) >> | |
1537 | CMPLT_HDR_DEV_ID_OFF; | |
1538 | itct = &hisi_hba->itct[dev_id]; | |
1539 | ||
1540 | /* The NCQ tags are held in the itct header */ | |
1541 | while (ncq_tag_count) { | |
1542 | __le64 *ncq_tag = &itct->qw4_15[0]; | |
1543 | ||
1544 | ncq_tag_count -= 1; | |
1545 | iptt = (ncq_tag[ncq_tag_count / 5] | |
1546 | >> (ncq_tag_count % 5) * 12) & 0xfff; | |
1547 | ||
1548 | slot = &hisi_hba->slot_info[iptt]; | |
1549 | slot->cmplt_queue_slot = rd_point; | |
1550 | slot->cmplt_queue = queue; | |
1551 | slot_complete_v3_hw(hisi_hba, slot); | |
1552 | ||
1553 | act_tmp &= ~(1 << ncq_tag_count); | |
1554 | ncq_tag_count = ffs(act_tmp); | |
1555 | } | |
1556 | } else { | |
1557 | iptt = (complete_hdr->dw1) & CMPLT_HDR_IPTT_MSK; | |
1558 | slot = &hisi_hba->slot_info[iptt]; | |
1559 | slot->cmplt_queue_slot = rd_point; | |
1560 | slot->cmplt_queue = queue; | |
1561 | slot_complete_v3_hw(hisi_hba, slot); | |
1562 | } | |
1563 | ||
1564 | if (++rd_point >= HISI_SAS_QUEUE_SLOTS) | |
1565 | rd_point = 0; | |
1566 | } | |
1567 | ||
1568 | /* update rd_point */ | |
1569 | cq->rd_point = rd_point; | |
1570 | hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point); | |
1571 | spin_unlock(&dq->lock); | |
1572 | } | |
1573 | ||
1574 | static irqreturn_t cq_interrupt_v3_hw(int irq_no, void *p) | |
1575 | { | |
1576 | struct hisi_sas_cq *cq = p; | |
1577 | struct hisi_hba *hisi_hba = cq->hisi_hba; | |
1578 | int queue = cq->id; | |
1579 | ||
1580 | hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue); | |
1581 | ||
1582 | tasklet_schedule(&cq->tasklet); | |
1583 | ||
1584 | return IRQ_HANDLED; | |
1585 | } | |
1586 | ||
54edeee1 XC |
1587 | static int interrupt_init_v3_hw(struct hisi_hba *hisi_hba) |
1588 | { | |
1589 | struct device *dev = hisi_hba->dev; | |
1590 | struct pci_dev *pdev = hisi_hba->pci_dev; | |
1591 | int vectors, rc; | |
60b4a5ee | 1592 | int i, k; |
54edeee1 XC |
1593 | int max_msi = HISI_SAS_MSI_COUNT_V3_HW; |
1594 | ||
1595 | vectors = pci_alloc_irq_vectors(hisi_hba->pci_dev, 1, | |
1596 | max_msi, PCI_IRQ_MSI); | |
1597 | if (vectors < max_msi) { | |
1598 | dev_err(dev, "could not allocate all msi (%d)\n", vectors); | |
1599 | return -ENOENT; | |
1600 | } | |
1601 | ||
1602 | rc = devm_request_irq(dev, pci_irq_vector(pdev, 1), | |
1603 | int_phy_up_down_bcast_v3_hw, 0, | |
1604 | DRV_NAME " phy", hisi_hba); | |
1605 | if (rc) { | |
1606 | dev_err(dev, "could not request phy interrupt, rc=%d\n", rc); | |
1607 | rc = -ENOENT; | |
1608 | goto free_irq_vectors; | |
1609 | } | |
1610 | ||
1611 | rc = devm_request_irq(dev, pci_irq_vector(pdev, 2), | |
1612 | int_chnl_int_v3_hw, 0, | |
1613 | DRV_NAME " channel", hisi_hba); | |
1614 | if (rc) { | |
1615 | dev_err(dev, "could not request chnl interrupt, rc=%d\n", rc); | |
1616 | rc = -ENOENT; | |
1617 | goto free_phy_irq; | |
1618 | } | |
1619 | ||
60b4a5ee XC |
1620 | /* Init tasklets for cq only */ |
1621 | for (i = 0; i < hisi_hba->queue_count; i++) { | |
1622 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; | |
1623 | struct tasklet_struct *t = &cq->tasklet; | |
1624 | ||
1625 | rc = devm_request_irq(dev, pci_irq_vector(pdev, i+16), | |
1626 | cq_interrupt_v3_hw, 0, | |
1627 | DRV_NAME " cq", cq); | |
1628 | if (rc) { | |
1629 | dev_err(dev, | |
1630 | "could not request cq%d interrupt, rc=%d\n", | |
1631 | i, rc); | |
1632 | rc = -ENOENT; | |
1633 | goto free_cq_irqs; | |
1634 | } | |
1635 | ||
1636 | tasklet_init(t, cq_tasklet_v3_hw, (unsigned long)cq); | |
1637 | } | |
54edeee1 XC |
1638 | |
1639 | return 0; | |
1640 | ||
60b4a5ee XC |
1641 | free_cq_irqs: |
1642 | for (k = 0; k < i; k++) { | |
1643 | struct hisi_sas_cq *cq = &hisi_hba->cq[k]; | |
1644 | ||
1645 | free_irq(pci_irq_vector(pdev, k+16), cq); | |
1646 | } | |
1647 | free_irq(pci_irq_vector(pdev, 2), hisi_hba); | |
54edeee1 XC |
1648 | free_phy_irq: |
1649 | free_irq(pci_irq_vector(pdev, 1), hisi_hba); | |
1650 | free_irq_vectors: | |
1651 | pci_free_irq_vectors(pdev); | |
1652 | return rc; | |
1653 | } | |
1654 | ||
c94d8ca2 XC |
1655 | static int hisi_sas_v3_init(struct hisi_hba *hisi_hba) |
1656 | { | |
1657 | int rc; | |
1658 | ||
1659 | rc = hw_init_v3_hw(hisi_hba); | |
1660 | if (rc) | |
1661 | return rc; | |
1662 | ||
54edeee1 XC |
1663 | rc = interrupt_init_v3_hw(hisi_hba); |
1664 | if (rc) | |
1665 | return rc; | |
1666 | ||
c94d8ca2 XC |
1667 | return 0; |
1668 | } | |
1669 | ||
2400620c XC |
1670 | static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no, |
1671 | struct sas_phy_linkrates *r) | |
1672 | { | |
1673 | u32 prog_phy_link_rate = | |
1674 | hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); | |
1675 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; | |
1676 | struct asd_sas_phy *sas_phy = &phy->sas_phy; | |
1677 | int i; | |
1678 | enum sas_linkrate min, max; | |
1679 | u32 rate_mask = 0; | |
1680 | ||
1681 | if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { | |
1682 | max = sas_phy->phy->maximum_linkrate; | |
1683 | min = r->minimum_linkrate; | |
1684 | } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { | |
1685 | max = r->maximum_linkrate; | |
1686 | min = sas_phy->phy->minimum_linkrate; | |
1687 | } else | |
1688 | return; | |
1689 | ||
1690 | sas_phy->phy->maximum_linkrate = max; | |
1691 | sas_phy->phy->minimum_linkrate = min; | |
1692 | ||
1693 | min -= SAS_LINK_RATE_1_5_GBPS; | |
1694 | max -= SAS_LINK_RATE_1_5_GBPS; | |
1695 | ||
1696 | for (i = 0; i <= max; i++) | |
1697 | rate_mask |= 1 << (i * 2); | |
1698 | ||
1699 | prog_phy_link_rate &= ~0xff; | |
1700 | prog_phy_link_rate |= rate_mask; | |
1701 | ||
1702 | hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, | |
1703 | prog_phy_link_rate); | |
1704 | ||
1705 | phy_hard_reset_v3_hw(hisi_hba, phy_no); | |
1706 | } | |
1707 | ||
a25d0d3d XC |
1708 | static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba) |
1709 | { | |
1710 | struct pci_dev *pdev = hisi_hba->pci_dev; | |
1711 | int i; | |
1712 | ||
1713 | synchronize_irq(pci_irq_vector(pdev, 1)); | |
1714 | synchronize_irq(pci_irq_vector(pdev, 2)); | |
1715 | synchronize_irq(pci_irq_vector(pdev, 11)); | |
1716 | for (i = 0; i < hisi_hba->queue_count; i++) { | |
1717 | hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1); | |
1718 | synchronize_irq(pci_irq_vector(pdev, i + 16)); | |
1719 | } | |
1720 | ||
1721 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff); | |
1722 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff); | |
1723 | hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff); | |
1724 | hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff); | |
1725 | ||
1726 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
1727 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff); | |
1728 | hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff); | |
1729 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x1); | |
1730 | hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x1); | |
1731 | hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x1); | |
1732 | } | |
1733 | } | |
1734 | ||
1735 | static u32 get_phys_state_v3_hw(struct hisi_hba *hisi_hba) | |
1736 | { | |
1737 | return hisi_sas_read32(hisi_hba, PHY_STATE); | |
1738 | } | |
1739 | ||
1740 | static int soft_reset_v3_hw(struct hisi_hba *hisi_hba) | |
1741 | { | |
1742 | struct device *dev = hisi_hba->dev; | |
1743 | int rc; | |
1744 | u32 status; | |
1745 | ||
1746 | interrupt_disable_v3_hw(hisi_hba); | |
1747 | hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0); | |
1748 | ||
1749 | hisi_sas_stop_phys(hisi_hba); | |
1750 | ||
1751 | mdelay(10); | |
1752 | ||
1753 | hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + AM_CTRL_GLOBAL, 0x1); | |
1754 | ||
1755 | /* wait until bus idle */ | |
1756 | rc = readl_poll_timeout(hisi_hba->regs + AXI_MASTER_CFG_BASE + | |
1757 | AM_CURR_TRANS_RETURN, status, status == 0x3, 10, 100); | |
1758 | if (rc) { | |
1759 | dev_err(dev, "axi bus is not idle, rc = %d\n", rc); | |
1760 | return rc; | |
1761 | } | |
1762 | ||
1763 | hisi_sas_init_mem(hisi_hba); | |
1764 | ||
1765 | return hw_init_v3_hw(hisi_hba); | |
1766 | } | |
1767 | ||
e21fe3a5 | 1768 | static const struct hisi_sas_hw hisi_sas_v3_hw = { |
c94d8ca2 | 1769 | .hw_init = hisi_sas_v3_init, |
182e7222 | 1770 | .setup_itct = setup_itct_v3_hw, |
c94d8ca2 | 1771 | .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V3_HW, |
f771d3b0 | 1772 | .get_wideport_bitmap = get_wideport_bitmap_v3_hw, |
c94d8ca2 | 1773 | .complete_hdr_size = sizeof(struct hisi_sas_complete_v3_hdr), |
182e7222 | 1774 | .free_device = free_device_v3_hw, |
3975f605 | 1775 | .sl_notify = sl_notify_v3_hw, |
a2204723 | 1776 | .prep_ssp = prep_ssp_v3_hw, |
fa913de2 | 1777 | .prep_smp = prep_smp_v3_hw, |
ce60689e | 1778 | .prep_stp = prep_ata_v3_hw, |
4de0ca69 | 1779 | .prep_abort = prep_abort_v3_hw, |
a2204723 XC |
1780 | .get_free_slot = get_free_slot_v3_hw, |
1781 | .start_delivery = start_delivery_v3_hw, | |
1782 | .slot_complete = slot_complete_v3_hw, | |
3975f605 | 1783 | .phys_init = phys_init_v3_hw, |
1eb8eeac | 1784 | .phy_start = start_phy_v3_hw, |
402cd9f0 XC |
1785 | .phy_disable = disable_phy_v3_hw, |
1786 | .phy_hard_reset = phy_hard_reset_v3_hw, | |
1787 | .phy_get_max_linkrate = phy_get_max_linkrate_v3_hw, | |
2400620c | 1788 | .phy_set_linkrate = phy_set_linkrate_v3_hw, |
d30ff263 | 1789 | .dereg_device = dereg_device_v3_hw, |
a25d0d3d XC |
1790 | .soft_reset = soft_reset_v3_hw, |
1791 | .get_phys_state = get_phys_state_v3_hw, | |
e21fe3a5 JG |
1792 | }; |
1793 | ||
1794 | static struct Scsi_Host * | |
1795 | hisi_sas_shost_alloc_pci(struct pci_dev *pdev) | |
1796 | { | |
1797 | struct Scsi_Host *shost; | |
1798 | struct hisi_hba *hisi_hba; | |
1799 | struct device *dev = &pdev->dev; | |
1800 | ||
1801 | shost = scsi_host_alloc(hisi_sas_sht, sizeof(*hisi_hba)); | |
76aae5f6 JG |
1802 | if (!shost) { |
1803 | dev_err(dev, "shost alloc failed\n"); | |
1804 | return NULL; | |
1805 | } | |
e21fe3a5 JG |
1806 | hisi_hba = shost_priv(shost); |
1807 | ||
1808 | hisi_hba->hw = &hisi_sas_v3_hw; | |
1809 | hisi_hba->pci_dev = pdev; | |
1810 | hisi_hba->dev = dev; | |
1811 | hisi_hba->shost = shost; | |
1812 | SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; | |
1813 | ||
1814 | init_timer(&hisi_hba->timer); | |
1815 | ||
1816 | if (hisi_sas_get_fw_info(hisi_hba) < 0) | |
1817 | goto err_out; | |
1818 | ||
1819 | if (hisi_sas_alloc(hisi_hba, shost)) { | |
1820 | hisi_sas_free(hisi_hba); | |
1821 | goto err_out; | |
1822 | } | |
1823 | ||
1824 | return shost; | |
1825 | err_out: | |
76aae5f6 | 1826 | scsi_host_put(shost); |
e21fe3a5 JG |
1827 | dev_err(dev, "shost alloc failed\n"); |
1828 | return NULL; | |
1829 | } | |
1830 | ||
92f61e3b JG |
1831 | static int |
1832 | hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |
1833 | { | |
e21fe3a5 JG |
1834 | struct Scsi_Host *shost; |
1835 | struct hisi_hba *hisi_hba; | |
1836 | struct device *dev = &pdev->dev; | |
1837 | struct asd_sas_phy **arr_phy; | |
1838 | struct asd_sas_port **arr_port; | |
1839 | struct sas_ha_struct *sha; | |
1840 | int rc, phy_nr, port_nr, i; | |
1841 | ||
1842 | rc = pci_enable_device(pdev); | |
1843 | if (rc) | |
1844 | goto err_out; | |
1845 | ||
1846 | pci_set_master(pdev); | |
1847 | ||
1848 | rc = pci_request_regions(pdev, DRV_NAME); | |
1849 | if (rc) | |
1850 | goto err_out_disable_device; | |
1851 | ||
1852 | if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || | |
1853 | (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { | |
1854 | if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || | |
1855 | (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) { | |
1856 | dev_err(dev, "No usable DMA addressing method\n"); | |
1857 | rc = -EIO; | |
1858 | goto err_out_regions; | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | shost = hisi_sas_shost_alloc_pci(pdev); | |
1863 | if (!shost) { | |
1864 | rc = -ENOMEM; | |
1865 | goto err_out_regions; | |
1866 | } | |
1867 | ||
1868 | sha = SHOST_TO_SAS_HA(shost); | |
1869 | hisi_hba = shost_priv(shost); | |
1870 | dev_set_drvdata(dev, sha); | |
1871 | ||
1872 | hisi_hba->regs = pcim_iomap(pdev, 5, 0); | |
1873 | if (!hisi_hba->regs) { | |
1874 | dev_err(dev, "cannot map register.\n"); | |
1875 | rc = -ENOMEM; | |
1876 | goto err_out_ha; | |
1877 | } | |
1878 | ||
1879 | phy_nr = port_nr = hisi_hba->n_phy; | |
1880 | ||
1881 | arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL); | |
1882 | arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL); | |
1883 | if (!arr_phy || !arr_port) { | |
1884 | rc = -ENOMEM; | |
1885 | goto err_out_ha; | |
1886 | } | |
1887 | ||
1888 | sha->sas_phy = arr_phy; | |
1889 | sha->sas_port = arr_port; | |
1890 | sha->core.shost = shost; | |
1891 | sha->lldd_ha = hisi_hba; | |
1892 | ||
1893 | shost->transportt = hisi_sas_stt; | |
1894 | shost->max_id = HISI_SAS_MAX_DEVICES; | |
1895 | shost->max_lun = ~0; | |
1896 | shost->max_channel = 1; | |
1897 | shost->max_cmd_len = 16; | |
1898 | shost->sg_tablesize = min_t(u16, SG_ALL, HISI_SAS_SGE_PAGE_CNT); | |
1899 | shost->can_queue = hisi_hba->hw->max_command_entries; | |
1900 | shost->cmd_per_lun = hisi_hba->hw->max_command_entries; | |
1901 | ||
1902 | sha->sas_ha_name = DRV_NAME; | |
1903 | sha->dev = dev; | |
1904 | sha->lldd_module = THIS_MODULE; | |
1905 | sha->sas_addr = &hisi_hba->sas_addr[0]; | |
1906 | sha->num_phys = hisi_hba->n_phy; | |
1907 | sha->core.shost = hisi_hba->shost; | |
1908 | ||
1909 | for (i = 0; i < hisi_hba->n_phy; i++) { | |
1910 | sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; | |
1911 | sha->sas_port[i] = &hisi_hba->port[i].sas_port; | |
1912 | } | |
1913 | ||
1914 | hisi_sas_init_add(hisi_hba); | |
1915 | ||
1916 | rc = scsi_add_host(shost, dev); | |
1917 | if (rc) | |
1918 | goto err_out_ha; | |
1919 | ||
1920 | rc = sas_register_ha(sha); | |
1921 | if (rc) | |
1922 | goto err_out_register_ha; | |
1923 | ||
1924 | rc = hisi_hba->hw->hw_init(hisi_hba); | |
1925 | if (rc) | |
1926 | goto err_out_register_ha; | |
1927 | ||
1928 | scsi_scan_host(shost); | |
1929 | ||
92f61e3b | 1930 | return 0; |
e21fe3a5 JG |
1931 | |
1932 | err_out_register_ha: | |
1933 | scsi_remove_host(shost); | |
1934 | err_out_ha: | |
76aae5f6 | 1935 | scsi_host_put(shost); |
e21fe3a5 JG |
1936 | err_out_regions: |
1937 | pci_release_regions(pdev); | |
1938 | err_out_disable_device: | |
1939 | pci_disable_device(pdev); | |
1940 | err_out: | |
1941 | return rc; | |
92f61e3b JG |
1942 | } |
1943 | ||
54edeee1 XC |
1944 | static void |
1945 | hisi_sas_v3_destroy_irqs(struct pci_dev *pdev, struct hisi_hba *hisi_hba) | |
1946 | { | |
60b4a5ee XC |
1947 | int i; |
1948 | ||
54edeee1 XC |
1949 | free_irq(pci_irq_vector(pdev, 1), hisi_hba); |
1950 | free_irq(pci_irq_vector(pdev, 2), hisi_hba); | |
60b4a5ee XC |
1951 | for (i = 0; i < hisi_hba->queue_count; i++) { |
1952 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; | |
1953 | ||
1954 | free_irq(pci_irq_vector(pdev, i+16), cq); | |
d499669f | 1955 | tasklet_kill(&cq->tasklet); |
60b4a5ee | 1956 | } |
54edeee1 XC |
1957 | pci_free_irq_vectors(pdev); |
1958 | } | |
1959 | ||
92f61e3b JG |
1960 | static void hisi_sas_v3_remove(struct pci_dev *pdev) |
1961 | { | |
e21fe3a5 JG |
1962 | struct device *dev = &pdev->dev; |
1963 | struct sas_ha_struct *sha = dev_get_drvdata(dev); | |
1964 | struct hisi_hba *hisi_hba = sha->lldd_ha; | |
76aae5f6 | 1965 | struct Scsi_Host *shost = sha->core.shost; |
e21fe3a5 JG |
1966 | |
1967 | sas_unregister_ha(sha); | |
1968 | sas_remove_host(sha->core.shost); | |
1969 | ||
54edeee1 | 1970 | hisi_sas_v3_destroy_irqs(pdev, hisi_hba); |
e21fe3a5 JG |
1971 | pci_release_regions(pdev); |
1972 | pci_disable_device(pdev); | |
76aae5f6 JG |
1973 | hisi_sas_free(hisi_hba); |
1974 | scsi_host_put(shost); | |
92f61e3b JG |
1975 | } |
1976 | ||
1977 | enum { | |
1978 | /* instances of the controller */ | |
1979 | hip08, | |
1980 | }; | |
1981 | ||
1982 | static const struct pci_device_id sas_v3_pci_table[] = { | |
1983 | { PCI_VDEVICE(HUAWEI, 0xa230), hip08 }, | |
1984 | {} | |
1985 | }; | |
1986 | ||
1987 | static struct pci_driver sas_v3_pci_driver = { | |
1988 | .name = DRV_NAME, | |
1989 | .id_table = sas_v3_pci_table, | |
1990 | .probe = hisi_sas_v3_probe, | |
1991 | .remove = hisi_sas_v3_remove, | |
1992 | }; | |
1993 | ||
1994 | module_pci_driver(sas_v3_pci_driver); | |
1995 | ||
92f61e3b JG |
1996 | MODULE_LICENSE("GPL"); |
1997 | MODULE_AUTHOR("John Garry <john.garry@huawei.com>"); | |
1998 | MODULE_DESCRIPTION("HISILICON SAS controller v3 hw driver based on pci device"); | |
1999 | MODULE_ALIAS("platform:" DRV_NAME); |