blob: 42602d8d5ccf3dadb47036131bd2206bc1eb5206 [file] [log] [blame]
Sakthivel Kf5860992013-04-17 16:37:02 +05301/*
2 * PMC-Sierra SPCv/ve 8088/8089 SAS/SATA based host adapters driver
3 *
4 * Copyright (c) 2008-2009 PMC-Sierra, Inc.,
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * substantially similar to the "NO WARRANTY" disclaimer below
15 * ("Disclaimer") and any redistribution must be conditioned upon
16 * including a substantially similar Disclaimer requirement for further
17 * binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * Alternatively, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2 as published by the Free
24 * Software Foundation.
25 *
26 * NO WARRANTY
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
38 *
39 */
40 #include <linux/slab.h>
41 #include "pm8001_sas.h"
42 #include "pm80xx_hwi.h"
43 #include "pm8001_chips.h"
44 #include "pm8001_ctl.h"
45
46#define SMP_DIRECT 1
47#define SMP_INDIRECT 2
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +053048
49
50int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shift_value)
51{
52 u32 reg_val;
53 unsigned long start;
54 pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER, shift_value);
55 /* confirm the setting is written */
56 start = jiffies + HZ; /* 1 sec */
57 do {
58 reg_val = pm8001_cr32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER);
59 } while ((reg_val != shift_value) && time_before(jiffies, start));
60 if (reg_val != shift_value) {
Joe Perches1b5d2792020-11-20 15:16:09 -080061 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:MEMBASE_II_SHIFT_REGISTER = 0x%x\n",
62 reg_val);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +053063 return -1;
64 }
65 return 0;
66}
67
Lee Jonesea310f52020-07-21 17:41:33 +010068static void pm80xx_pci_mem_copy(struct pm8001_hba_info *pm8001_ha, u32 soffset,
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +053069 const void *destination,
70 u32 dw_count, u32 bus_base_number)
71{
72 u32 index, value, offset;
73 u32 *destination1;
74 destination1 = (u32 *)destination;
75
76 for (index = 0; index < dw_count; index += 4, destination1++) {
Deepak Ukey044f59d2019-11-14 15:39:10 +053077 offset = (soffset + index);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +053078 if (offset < (64 * 1024)) {
79 value = pm8001_cr32(pm8001_ha, bus_base_number, offset);
80 *destination1 = cpu_to_le32(value);
81 }
82 }
83 return;
84}
85
86ssize_t pm80xx_get_fatal_dump(struct device *cdev,
87 struct device_attribute *attr, char *buf)
88{
89 struct Scsi_Host *shost = class_to_shost(cdev);
90 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
91 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
92 void __iomem *fatal_table_address = pm8001_ha->fatal_tbl_addr;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +053093 u32 accum_len , reg_val, index, *temp;
Deepak Ukey044f59d2019-11-14 15:39:10 +053094 u32 status = 1;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +053095 unsigned long start;
96 u8 *direct_data;
97 char *fatal_error_data = buf;
Deepak Ukey044f59d2019-11-14 15:39:10 +053098 u32 length_to_read;
99 u32 offset;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530100
101 pm8001_ha->forensic_info.data_buf.direct_data = buf;
102 if (pm8001_ha->chip_id == chip_8001) {
103 pm8001_ha->forensic_info.data_buf.direct_data +=
104 sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
105 "Not supported for SPC controller");
106 return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
107 (char *)buf;
108 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530109 /* initialize variables for very first call from host application */
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530110 if (pm8001_ha->forensic_info.data_buf.direct_offset == 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800111 pm8001_dbg(pm8001_ha, IO,
112 "forensic_info TYPE_NON_FATAL..............\n");
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530113 direct_data = (u8 *)fatal_error_data;
114 pm8001_ha->forensic_info.data_type = TYPE_NON_FATAL;
115 pm8001_ha->forensic_info.data_buf.direct_len = SYSFS_OFFSET;
Deepak Ukey044f59d2019-11-14 15:39:10 +0530116 pm8001_ha->forensic_info.data_buf.direct_offset = 0;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530117 pm8001_ha->forensic_info.data_buf.read_len = 0;
Deepak Ukey044f59d2019-11-14 15:39:10 +0530118 pm8001_ha->forensic_preserved_accumulated_transfer = 0;
119
120 /* Write signature to fatal dump table */
121 pm8001_mw32(fatal_table_address,
122 MPI_FATAL_EDUMP_TABLE_SIGNATURE, 0x1234abcd);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530123
124 pm8001_ha->forensic_info.data_buf.direct_data = direct_data;
Joe Perches1b5d2792020-11-20 15:16:09 -0800125 pm8001_dbg(pm8001_ha, IO, "ossaHwCB: status1 %d\n", status);
126 pm8001_dbg(pm8001_ha, IO, "ossaHwCB: read_len 0x%x\n",
127 pm8001_ha->forensic_info.data_buf.read_len);
128 pm8001_dbg(pm8001_ha, IO, "ossaHwCB: direct_len 0x%x\n",
129 pm8001_ha->forensic_info.data_buf.direct_len);
130 pm8001_dbg(pm8001_ha, IO, "ossaHwCB: direct_offset 0x%x\n",
131 pm8001_ha->forensic_info.data_buf.direct_offset);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530132 }
133 if (pm8001_ha->forensic_info.data_buf.direct_offset == 0) {
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530134 /* start to get data */
135 /* Program the MEMBASE II Shifting Register with 0x00.*/
136 pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
137 pm8001_ha->fatal_forensic_shift_offset);
138 pm8001_ha->forensic_last_offset = 0;
139 pm8001_ha->forensic_fatal_step = 0;
140 pm8001_ha->fatal_bar_loc = 0;
141 }
Viswas Gcf370062013-12-10 10:31:38 +0530142
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530143 /* Read until accum_len is retrived */
144 accum_len = pm8001_mr32(fatal_table_address,
145 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530146 /* Determine length of data between previously stored transfer length
147 * and current accumulated transfer length
148 */
149 length_to_read =
150 accum_len - pm8001_ha->forensic_preserved_accumulated_transfer;
Joe Perches1b5d2792020-11-20 15:16:09 -0800151 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: accum_len 0x%x\n",
152 accum_len);
153 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: length_to_read 0x%x\n",
154 length_to_read);
155 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: last_offset 0x%x\n",
156 pm8001_ha->forensic_last_offset);
157 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: read_len 0x%x\n",
158 pm8001_ha->forensic_info.data_buf.read_len);
159 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv:: direct_len 0x%x\n",
160 pm8001_ha->forensic_info.data_buf.direct_len);
161 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv:: direct_offset 0x%x\n",
162 pm8001_ha->forensic_info.data_buf.direct_offset);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530163
164 /* If accumulated length failed to read correctly fail the attempt.*/
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530165 if (accum_len == 0xFFFFFFFF) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800166 pm8001_dbg(pm8001_ha, IO,
167 "Possible PCI issue 0x%x not expected\n",
168 accum_len);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530169 return status;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530170 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530171 /* If accumulated length is zero fail the attempt */
172 if (accum_len == 0) {
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530173 pm8001_ha->forensic_info.data_buf.direct_data +=
174 sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
Deepak Ukey044f59d2019-11-14 15:39:10 +0530175 "%08x ", 0xFFFFFFFF);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530176 return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
177 (char *)buf;
178 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530179 /* Accumulated length is good so start capturing the first data */
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530180 temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
181 if (pm8001_ha->forensic_fatal_step == 0) {
182moreData:
Deepak Ukey044f59d2019-11-14 15:39:10 +0530183 /* If data to read is less than SYSFS_OFFSET then reduce the
184 * length of dataLen
185 */
186 if (pm8001_ha->forensic_last_offset + SYSFS_OFFSET
187 > length_to_read) {
188 pm8001_ha->forensic_info.data_buf.direct_len =
189 length_to_read -
190 pm8001_ha->forensic_last_offset;
191 } else {
192 pm8001_ha->forensic_info.data_buf.direct_len =
193 SYSFS_OFFSET;
194 }
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530195 if (pm8001_ha->forensic_info.data_buf.direct_data) {
196 /* Data is in bar, copy to host memory */
Deepak Ukey044f59d2019-11-14 15:39:10 +0530197 pm80xx_pci_mem_copy(pm8001_ha,
198 pm8001_ha->fatal_bar_loc,
199 pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr,
200 pm8001_ha->forensic_info.data_buf.direct_len, 1);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530201 }
202 pm8001_ha->fatal_bar_loc +=
203 pm8001_ha->forensic_info.data_buf.direct_len;
204 pm8001_ha->forensic_info.data_buf.direct_offset +=
205 pm8001_ha->forensic_info.data_buf.direct_len;
206 pm8001_ha->forensic_last_offset +=
207 pm8001_ha->forensic_info.data_buf.direct_len;
208 pm8001_ha->forensic_info.data_buf.read_len =
209 pm8001_ha->forensic_info.data_buf.direct_len;
210
Deepak Ukey044f59d2019-11-14 15:39:10 +0530211 if (pm8001_ha->forensic_last_offset >= length_to_read) {
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530212 pm8001_ha->forensic_info.data_buf.direct_data +=
213 sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
214 "%08x ", 3);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530215 for (index = 0; index <
216 (pm8001_ha->forensic_info.data_buf.direct_len
217 / 4); index++) {
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530218 pm8001_ha->forensic_info.data_buf.direct_data +=
Deepak Ukey044f59d2019-11-14 15:39:10 +0530219 sprintf(
220 pm8001_ha->forensic_info.data_buf.direct_data,
221 "%08x ", *(temp + index));
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530222 }
223
224 pm8001_ha->fatal_bar_loc = 0;
225 pm8001_ha->forensic_fatal_step = 1;
226 pm8001_ha->fatal_forensic_shift_offset = 0;
227 pm8001_ha->forensic_last_offset = 0;
Deepak Ukey044f59d2019-11-14 15:39:10 +0530228 status = 0;
229 offset = (int)
230 ((char *)pm8001_ha->forensic_info.data_buf.direct_data
231 - (char *)buf);
Joe Perches1b5d2792020-11-20 15:16:09 -0800232 pm8001_dbg(pm8001_ha, IO,
233 "get_fatal_spcv:return1 0x%x\n", offset);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530234 return (char *)pm8001_ha->
235 forensic_info.data_buf.direct_data -
236 (char *)buf;
237 }
238 if (pm8001_ha->fatal_bar_loc < (64 * 1024)) {
239 pm8001_ha->forensic_info.data_buf.direct_data +=
240 sprintf(pm8001_ha->
241 forensic_info.data_buf.direct_data,
242 "%08x ", 2);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530243 for (index = 0; index <
244 (pm8001_ha->forensic_info.data_buf.direct_len
245 / 4); index++) {
246 pm8001_ha->forensic_info.data_buf.direct_data
247 += sprintf(pm8001_ha->
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530248 forensic_info.data_buf.direct_data,
249 "%08x ", *(temp + index));
250 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530251 status = 0;
252 offset = (int)
253 ((char *)pm8001_ha->forensic_info.data_buf.direct_data
254 - (char *)buf);
Joe Perches1b5d2792020-11-20 15:16:09 -0800255 pm8001_dbg(pm8001_ha, IO,
256 "get_fatal_spcv:return2 0x%x\n", offset);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530257 return (char *)pm8001_ha->
258 forensic_info.data_buf.direct_data -
259 (char *)buf;
260 }
261
262 /* Increment the MEMBASE II Shifting Register value by 0x100.*/
263 pm8001_ha->forensic_info.data_buf.direct_data +=
264 sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
265 "%08x ", 2);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530266 for (index = 0; index <
267 (pm8001_ha->forensic_info.data_buf.direct_len
268 / 4) ; index++) {
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530269 pm8001_ha->forensic_info.data_buf.direct_data +=
270 sprintf(pm8001_ha->
Deepak Ukey044f59d2019-11-14 15:39:10 +0530271 forensic_info.data_buf.direct_data,
272 "%08x ", *(temp + index));
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530273 }
274 pm8001_ha->fatal_forensic_shift_offset += 0x100;
275 pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
276 pm8001_ha->fatal_forensic_shift_offset);
277 pm8001_ha->fatal_bar_loc = 0;
Deepak Ukey044f59d2019-11-14 15:39:10 +0530278 status = 0;
279 offset = (int)
280 ((char *)pm8001_ha->forensic_info.data_buf.direct_data
281 - (char *)buf);
Joe Perches1b5d2792020-11-20 15:16:09 -0800282 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: return3 0x%x\n",
283 offset);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530284 return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
285 (char *)buf;
286 }
287 if (pm8001_ha->forensic_fatal_step == 1) {
Deepak Ukey044f59d2019-11-14 15:39:10 +0530288 /* store previous accumulated length before triggering next
289 * accumulated length update
290 */
291 pm8001_ha->forensic_preserved_accumulated_transfer =
292 pm8001_mr32(fatal_table_address,
293 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
294
295 /* continue capturing the fatal log until Dump status is 0x3 */
296 if (pm8001_mr32(fatal_table_address,
297 MPI_FATAL_EDUMP_TABLE_STATUS) <
298 MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) {
299
300 /* reset fddstat bit by writing to zero*/
301 pm8001_mw32(fatal_table_address,
302 MPI_FATAL_EDUMP_TABLE_STATUS, 0x0);
303
304 /* set dump control value to '1' so that new data will
305 * be transferred to shared memory
306 */
307 pm8001_mw32(fatal_table_address,
308 MPI_FATAL_EDUMP_TABLE_HANDSHAKE,
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530309 MPI_FATAL_EDUMP_HANDSHAKE_RDY);
310
Deepak Ukey044f59d2019-11-14 15:39:10 +0530311 /*Poll FDDHSHK until clear */
312 start = jiffies + (2 * HZ); /* 2 sec */
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530313
Deepak Ukey044f59d2019-11-14 15:39:10 +0530314 do {
315 reg_val = pm8001_mr32(fatal_table_address,
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530316 MPI_FATAL_EDUMP_TABLE_HANDSHAKE);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530317 } while ((reg_val) && time_before(jiffies, start));
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530318
Deepak Ukey044f59d2019-11-14 15:39:10 +0530319 if (reg_val != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800320 pm8001_dbg(pm8001_ha, FAIL,
321 "TIMEOUT:MPI_FATAL_EDUMP_TABLE_HDSHAKE 0x%x\n",
322 reg_val);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530323 /* Fail the dump if a timeout occurs */
324 pm8001_ha->forensic_info.data_buf.direct_data +=
325 sprintf(
326 pm8001_ha->forensic_info.data_buf.direct_data,
327 "%08x ", 0xFFFFFFFF);
328 return((char *)
329 pm8001_ha->forensic_info.data_buf.direct_data
330 - (char *)buf);
331 }
332 /* Poll status register until set to 2 or
333 * 3 for up to 2 seconds
334 */
335 start = jiffies + (2 * HZ); /* 2 sec */
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530336
Deepak Ukey044f59d2019-11-14 15:39:10 +0530337 do {
338 reg_val = pm8001_mr32(fatal_table_address,
339 MPI_FATAL_EDUMP_TABLE_STATUS);
Colin Ian King0e7c3532019-11-20 13:50:31 +0000340 } while (((reg_val != 2) && (reg_val != 3)) &&
Deepak Ukey044f59d2019-11-14 15:39:10 +0530341 time_before(jiffies, start));
342
343 if (reg_val < 2) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800344 pm8001_dbg(pm8001_ha, FAIL,
345 "TIMEOUT:MPI_FATAL_EDUMP_TABLE_STATUS = 0x%x\n",
346 reg_val);
Deepak Ukey044f59d2019-11-14 15:39:10 +0530347 /* Fail the dump if a timeout occurs */
348 pm8001_ha->forensic_info.data_buf.direct_data +=
349 sprintf(
350 pm8001_ha->forensic_info.data_buf.direct_data,
351 "%08x ", 0xFFFFFFFF);
Viswas Gec2e7e12021-01-09 18:08:46 +0530352 return((char *)pm8001_ha->forensic_info.data_buf.direct_data -
353 (char *)buf);
354 }
355 /* reset fatal_forensic_shift_offset back to zero and reset MEMBASE 2 register to zero */
356 pm8001_ha->fatal_forensic_shift_offset = 0; /* location in 64k region */
357 pm8001_cw32(pm8001_ha, 0,
Deepak Ukey044f59d2019-11-14 15:39:10 +0530358 MEMBASE_II_SHIFT_REGISTER,
359 pm8001_ha->fatal_forensic_shift_offset);
Viswas Gec2e7e12021-01-09 18:08:46 +0530360 }
Colin Ian King7b382122021-01-15 09:58:24 +0000361 /* Read the next block of the debug data.*/
362 length_to_read = pm8001_mr32(fatal_table_address,
363 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN) -
364 pm8001_ha->forensic_preserved_accumulated_transfer;
365 if (length_to_read != 0x0) {
366 pm8001_ha->forensic_fatal_step = 0;
367 goto moreData;
368 } else {
369 pm8001_ha->forensic_info.data_buf.direct_data +=
370 sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
Deepak Ukey044f59d2019-11-14 15:39:10 +0530371 "%08x ", 4);
Colin Ian King7b382122021-01-15 09:58:24 +0000372 pm8001_ha->forensic_info.data_buf.read_len = 0xFFFFFFFF;
373 pm8001_ha->forensic_info.data_buf.direct_len = 0;
374 pm8001_ha->forensic_info.data_buf.direct_offset = 0;
375 pm8001_ha->forensic_info.data_buf.read_len = 0;
376 }
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530377 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530378 offset = (int)((char *)pm8001_ha->forensic_info.data_buf.direct_data
379 - (char *)buf);
Joe Perches1b5d2792020-11-20 15:16:09 -0800380 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: return4 0x%x\n", offset);
Viswas Gec2e7e12021-01-09 18:08:46 +0530381 return ((char *)pm8001_ha->forensic_info.data_buf.direct_data -
382 (char *)buf);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530383}
384
Deepak Ukeydba2cc02020-03-16 13:19:05 +0530385/* pm80xx_get_non_fatal_dump - dump the nonfatal data from the dma
386 * location by the firmware.
387 */
388ssize_t pm80xx_get_non_fatal_dump(struct device *cdev,
389 struct device_attribute *attr, char *buf)
390{
391 struct Scsi_Host *shost = class_to_shost(cdev);
392 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
393 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
394 void __iomem *nonfatal_table_address = pm8001_ha->fatal_tbl_addr;
395 u32 accum_len = 0;
396 u32 total_len = 0;
397 u32 reg_val = 0;
398 u32 *temp = NULL;
399 u32 index = 0;
400 u32 output_length;
401 unsigned long start = 0;
402 char *buf_copy = buf;
403
404 temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
405 if (++pm8001_ha->non_fatal_count == 1) {
406 if (pm8001_ha->chip_id == chip_8001) {
407 snprintf(pm8001_ha->forensic_info.data_buf.direct_data,
408 PAGE_SIZE, "Not supported for SPC controller");
409 return 0;
410 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800411 pm8001_dbg(pm8001_ha, IO, "forensic_info TYPE_NON_FATAL...\n");
Deepak Ukeydba2cc02020-03-16 13:19:05 +0530412 /*
413 * Step 1: Write the host buffer parameters in the MPI Fatal and
414 * Non-Fatal Error Dump Capture Table.This is the buffer
415 * where debug data will be DMAed to.
416 */
417 pm8001_mw32(nonfatal_table_address,
418 MPI_FATAL_EDUMP_TABLE_LO_OFFSET,
419 pm8001_ha->memoryMap.region[FORENSIC_MEM].phys_addr_lo);
420
421 pm8001_mw32(nonfatal_table_address,
422 MPI_FATAL_EDUMP_TABLE_HI_OFFSET,
423 pm8001_ha->memoryMap.region[FORENSIC_MEM].phys_addr_hi);
424
425 pm8001_mw32(nonfatal_table_address,
426 MPI_FATAL_EDUMP_TABLE_LENGTH, SYSFS_OFFSET);
427
428 /* Optionally, set the DUMPCTRL bit to 1 if the host
429 * keeps sending active I/Os while capturing the non-fatal
430 * debug data. Otherwise, leave this bit set to zero
431 */
432 pm8001_mw32(nonfatal_table_address,
433 MPI_FATAL_EDUMP_TABLE_HANDSHAKE, MPI_FATAL_EDUMP_HANDSHAKE_RDY);
434
435 /*
436 * Step 2: Clear Accumulative Length of Debug Data Transferred
437 * [ACCDDLEN] field in the MPI Fatal and Non-Fatal Error Dump
438 * Capture Table to zero.
439 */
440 pm8001_mw32(nonfatal_table_address,
441 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN, 0);
442
443 /* initiallize previous accumulated length to 0 */
444 pm8001_ha->forensic_preserved_accumulated_transfer = 0;
445 pm8001_ha->non_fatal_read_length = 0;
446 }
447
448 total_len = pm8001_mr32(nonfatal_table_address,
449 MPI_FATAL_EDUMP_TABLE_TOTAL_LEN);
450 /*
451 * Step 3:Clear Fatal/Non-Fatal Debug Data Transfer Status [FDDTSTAT]
452 * field and then request that the SPCv controller transfer the debug
453 * data by setting bit 7 of the Inbound Doorbell Set Register.
454 */
455 pm8001_mw32(nonfatal_table_address, MPI_FATAL_EDUMP_TABLE_STATUS, 0);
456 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET,
457 SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP);
458
459 /*
460 * Step 4.1: Read back the Inbound Doorbell Set Register (by polling for
461 * 2 seconds) until register bit 7 is cleared.
462 * This step only indicates the request is accepted by the controller.
463 */
464 start = jiffies + (2 * HZ); /* 2 sec */
465 do {
466 reg_val = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET) &
467 SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP;
468 } while ((reg_val != 0) && time_before(jiffies, start));
469
470 /* Step 4.2: To check the completion of the transfer, poll the Fatal/Non
471 * Fatal Debug Data Transfer Status [FDDTSTAT] field for 2 seconds in
472 * the MPI Fatal and Non-Fatal Error Dump Capture Table.
473 */
474 start = jiffies + (2 * HZ); /* 2 sec */
475 do {
476 reg_val = pm8001_mr32(nonfatal_table_address,
477 MPI_FATAL_EDUMP_TABLE_STATUS);
478 } while ((!reg_val) && time_before(jiffies, start));
479
480 if ((reg_val == 0x00) ||
481 (reg_val == MPI_FATAL_EDUMP_TABLE_STAT_DMA_FAILED) ||
482 (reg_val > MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE)) {
483 pm8001_ha->non_fatal_read_length = 0;
484 buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 0xFFFFFFFF);
485 pm8001_ha->non_fatal_count = 0;
486 return (buf_copy - buf);
487 } else if (reg_val ==
488 MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_MORE_DATA) {
489 buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 2);
490 } else if ((reg_val == MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) ||
491 (pm8001_ha->non_fatal_read_length >= total_len)) {
492 pm8001_ha->non_fatal_read_length = 0;
493 buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 4);
494 pm8001_ha->non_fatal_count = 0;
495 }
496 accum_len = pm8001_mr32(nonfatal_table_address,
497 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
498 output_length = accum_len -
499 pm8001_ha->forensic_preserved_accumulated_transfer;
500
501 for (index = 0; index < output_length/4; index++)
502 buf_copy += snprintf(buf_copy, PAGE_SIZE,
503 "%08x ", *(temp+index));
504
505 pm8001_ha->non_fatal_read_length += output_length;
506
507 /* store current accumulated length to use in next iteration as
508 * the previous accumulated length
509 */
510 pm8001_ha->forensic_preserved_accumulated_transfer = accum_len;
511 return (buf_copy - buf);
512}
513
Sakthivel Kf5860992013-04-17 16:37:02 +0530514/**
515 * read_main_config_table - read the configure table and save it.
516 * @pm8001_ha: our hba card information
517 */
518static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
519{
520 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
521
522 pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature =
523 pm8001_mr32(address, MAIN_SIGNATURE_OFFSET);
524 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev =
525 pm8001_mr32(address, MAIN_INTERFACE_REVISION);
526 pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev =
527 pm8001_mr32(address, MAIN_FW_REVISION);
528 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io =
529 pm8001_mr32(address, MAIN_MAX_OUTSTANDING_IO_OFFSET);
530 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl =
531 pm8001_mr32(address, MAIN_MAX_SGL_OFFSET);
532 pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag =
533 pm8001_mr32(address, MAIN_CNTRL_CAP_OFFSET);
534 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset =
535 pm8001_mr32(address, MAIN_GST_OFFSET);
536 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset =
537 pm8001_mr32(address, MAIN_IBQ_OFFSET);
538 pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset =
539 pm8001_mr32(address, MAIN_OBQ_OFFSET);
540
541 /* read Error Dump Offset and Length */
542 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset0 =
543 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
544 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length0 =
545 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
546 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset1 =
547 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
548 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length1 =
549 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
550
551 /* read GPIO LED settings from the configuration table */
552 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping =
553 pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET);
554
555 /* read analog Setting offset from the configuration table */
556 pm8001_ha->main_cfg_tbl.pm80xx_tbl.analog_setup_table_offset =
557 pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
558
559 pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset =
560 pm8001_mr32(address, MAIN_INT_VECTOR_TABLE_OFFSET);
561 pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset =
562 pm8001_mr32(address, MAIN_SAS_PHY_ATTR_TABLE_OFFSET);
Viswas G8414cd82015-08-11 15:06:30 +0530563 /* read port recover and reset timeout */
564 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer =
565 pm8001_mr32(address, MAIN_PORT_RECOVERY_TIMER);
Viswas G24fff012017-10-18 11:39:08 +0530566 /* read ILA and inactive firmware version */
567 pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version =
568 pm8001_mr32(address, MAIN_MPI_ILA_RELEASE_TYPE);
569 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version =
570 pm8001_mr32(address, MAIN_MPI_INACTIVE_FW_VERSION);
peter chang73706722019-11-14 15:39:02 +0530571
Joe Perches1b5d2792020-11-20 15:16:09 -0800572 pm8001_dbg(pm8001_ha, DEV,
573 "Main cfg table: sign:%x interface rev:%x fw_rev:%x\n",
574 pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature,
575 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev,
576 pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev);
peter chang73706722019-11-14 15:39:02 +0530577
Joe Perches1b5d2792020-11-20 15:16:09 -0800578 pm8001_dbg(pm8001_ha, DEV,
579 "table offset: gst:%x iq:%x oq:%x int vec:%x phy attr:%x\n",
580 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset,
581 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset,
582 pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset,
583 pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset,
584 pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset);
peter chang73706722019-11-14 15:39:02 +0530585
Joe Perches1b5d2792020-11-20 15:16:09 -0800586 pm8001_dbg(pm8001_ha, DEV,
587 "Main cfg table; ila rev:%x Inactive fw rev:%x\n",
588 pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version,
589 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version);
Sakthivel Kf5860992013-04-17 16:37:02 +0530590}
591
592/**
593 * read_general_status_table - read the general status table and save it.
594 * @pm8001_ha: our hba card information
595 */
596static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
597{
598 void __iomem *address = pm8001_ha->general_stat_tbl_addr;
599 pm8001_ha->gs_tbl.pm80xx_tbl.gst_len_mpistate =
600 pm8001_mr32(address, GST_GSTLEN_MPIS_OFFSET);
601 pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state0 =
602 pm8001_mr32(address, GST_IQ_FREEZE_STATE0_OFFSET);
603 pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state1 =
604 pm8001_mr32(address, GST_IQ_FREEZE_STATE1_OFFSET);
605 pm8001_ha->gs_tbl.pm80xx_tbl.msgu_tcnt =
606 pm8001_mr32(address, GST_MSGUTCNT_OFFSET);
607 pm8001_ha->gs_tbl.pm80xx_tbl.iop_tcnt =
608 pm8001_mr32(address, GST_IOPTCNT_OFFSET);
609 pm8001_ha->gs_tbl.pm80xx_tbl.gpio_input_val =
610 pm8001_mr32(address, GST_GPIO_INPUT_VAL);
611 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[0] =
612 pm8001_mr32(address, GST_RERRINFO_OFFSET0);
613 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[1] =
614 pm8001_mr32(address, GST_RERRINFO_OFFSET1);
615 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[2] =
616 pm8001_mr32(address, GST_RERRINFO_OFFSET2);
617 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[3] =
618 pm8001_mr32(address, GST_RERRINFO_OFFSET3);
619 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[4] =
620 pm8001_mr32(address, GST_RERRINFO_OFFSET4);
621 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[5] =
622 pm8001_mr32(address, GST_RERRINFO_OFFSET5);
623 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[6] =
624 pm8001_mr32(address, GST_RERRINFO_OFFSET6);
625 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[7] =
626 pm8001_mr32(address, GST_RERRINFO_OFFSET7);
627}
628/**
629 * read_phy_attr_table - read the phy attribute table and save it.
630 * @pm8001_ha: our hba card information
631 */
632static void read_phy_attr_table(struct pm8001_hba_info *pm8001_ha)
633{
634 void __iomem *address = pm8001_ha->pspa_q_tbl_addr;
635 pm8001_ha->phy_attr_table.phystart1_16[0] =
636 pm8001_mr32(address, PSPA_PHYSTATE0_OFFSET);
637 pm8001_ha->phy_attr_table.phystart1_16[1] =
638 pm8001_mr32(address, PSPA_PHYSTATE1_OFFSET);
639 pm8001_ha->phy_attr_table.phystart1_16[2] =
640 pm8001_mr32(address, PSPA_PHYSTATE2_OFFSET);
641 pm8001_ha->phy_attr_table.phystart1_16[3] =
642 pm8001_mr32(address, PSPA_PHYSTATE3_OFFSET);
643 pm8001_ha->phy_attr_table.phystart1_16[4] =
644 pm8001_mr32(address, PSPA_PHYSTATE4_OFFSET);
645 pm8001_ha->phy_attr_table.phystart1_16[5] =
646 pm8001_mr32(address, PSPA_PHYSTATE5_OFFSET);
647 pm8001_ha->phy_attr_table.phystart1_16[6] =
648 pm8001_mr32(address, PSPA_PHYSTATE6_OFFSET);
649 pm8001_ha->phy_attr_table.phystart1_16[7] =
650 pm8001_mr32(address, PSPA_PHYSTATE7_OFFSET);
651 pm8001_ha->phy_attr_table.phystart1_16[8] =
652 pm8001_mr32(address, PSPA_PHYSTATE8_OFFSET);
653 pm8001_ha->phy_attr_table.phystart1_16[9] =
654 pm8001_mr32(address, PSPA_PHYSTATE9_OFFSET);
655 pm8001_ha->phy_attr_table.phystart1_16[10] =
656 pm8001_mr32(address, PSPA_PHYSTATE10_OFFSET);
657 pm8001_ha->phy_attr_table.phystart1_16[11] =
658 pm8001_mr32(address, PSPA_PHYSTATE11_OFFSET);
659 pm8001_ha->phy_attr_table.phystart1_16[12] =
660 pm8001_mr32(address, PSPA_PHYSTATE12_OFFSET);
661 pm8001_ha->phy_attr_table.phystart1_16[13] =
662 pm8001_mr32(address, PSPA_PHYSTATE13_OFFSET);
663 pm8001_ha->phy_attr_table.phystart1_16[14] =
664 pm8001_mr32(address, PSPA_PHYSTATE14_OFFSET);
665 pm8001_ha->phy_attr_table.phystart1_16[15] =
666 pm8001_mr32(address, PSPA_PHYSTATE15_OFFSET);
667
668 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[0] =
669 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID0_OFFSET);
670 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[1] =
671 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID1_OFFSET);
672 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[2] =
673 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID2_OFFSET);
674 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[3] =
675 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID3_OFFSET);
676 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[4] =
677 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID4_OFFSET);
678 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[5] =
679 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID5_OFFSET);
680 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[6] =
681 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID6_OFFSET);
682 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[7] =
683 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID7_OFFSET);
684 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[8] =
685 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID8_OFFSET);
686 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[9] =
687 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID9_OFFSET);
688 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[10] =
689 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID10_OFFSET);
690 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[11] =
691 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID11_OFFSET);
692 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[12] =
693 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID12_OFFSET);
694 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[13] =
695 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID13_OFFSET);
696 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[14] =
697 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID14_OFFSET);
698 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[15] =
699 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID15_OFFSET);
700
701}
702
703/**
704 * read_inbnd_queue_table - read the inbound queue table and save it.
705 * @pm8001_ha: our hba card information
706 */
707static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
708{
709 int i;
710 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530711 for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530712 u32 offset = i * 0x20;
713 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
714 get_pci_bar_index(pm8001_mr32(address,
715 (offset + IB_PIPCI_BAR)));
716 pm8001_ha->inbnd_q_tbl[i].pi_offset =
717 pm8001_mr32(address, (offset + IB_PIPCI_BAR_OFFSET));
718 }
719}
720
721/**
722 * read_outbnd_queue_table - read the outbound queue table and save it.
723 * @pm8001_ha: our hba card information
724 */
725static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
726{
727 int i;
728 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530729 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530730 u32 offset = i * 0x24;
731 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
732 get_pci_bar_index(pm8001_mr32(address,
733 (offset + OB_CIPCI_BAR)));
734 pm8001_ha->outbnd_q_tbl[i].ci_offset =
735 pm8001_mr32(address, (offset + OB_CIPCI_BAR_OFFSET));
736 }
737}
738
739/**
740 * init_default_table_values - init the default table.
741 * @pm8001_ha: our hba card information
742 */
743static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
744{
745 int i;
746 u32 offsetib, offsetob;
747 void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
748 void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530749 u32 ib_offset = pm8001_ha->ib_offset;
750 u32 ob_offset = pm8001_ha->ob_offset;
751 u32 ci_offset = pm8001_ha->ci_offset;
752 u32 pi_offset = pm8001_ha->pi_offset;
Sakthivel Kf5860992013-04-17 16:37:02 +0530753
754 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr =
755 pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
756 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr =
757 pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
758 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size =
759 PM8001_EVENT_LOG_SIZE;
760 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity = 0x01;
761 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr =
762 pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
763 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr =
764 pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
765 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size =
766 PM8001_EVENT_LOG_SIZE;
767 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity = 0x01;
768 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt = 0x01;
769
Sakthivel Kc6b9ef52013-03-19 18:08:08 +0530770 /* Disable end to end CRC checking */
771 pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump = (0x1 << 16);
772
Viswas G05c6c022020-10-05 20:20:08 +0530773 for (i = 0; i < pm8001_ha->max_q_num; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530774 pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200775 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
Sakthivel Kf5860992013-04-17 16:37:02 +0530776 pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530777 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530778 pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530779 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530780 pm8001_ha->inbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530781 (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530782 pm8001_ha->inbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530783 pm8001_ha->memoryMap.region[ib_offset + i].total_len;
Sakthivel Kf5860992013-04-17 16:37:02 +0530784 pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530785 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530786 pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530787 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530788 pm8001_ha->inbnd_q_tbl[i].ci_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530789 pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530790 offsetib = i * 0x20;
791 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
792 get_pci_bar_index(pm8001_mr32(addressib,
793 (offsetib + 0x14)));
794 pm8001_ha->inbnd_q_tbl[i].pi_offset =
795 pm8001_mr32(addressib, (offsetib + 0x18));
796 pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
797 pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
peter chang73706722019-11-14 15:39:02 +0530798
Joe Perches1b5d2792020-11-20 15:16:09 -0800799 pm8001_dbg(pm8001_ha, DEV,
800 "IQ %d pi_bar 0x%x pi_offset 0x%x\n", i,
801 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar,
802 pm8001_ha->inbnd_q_tbl[i].pi_offset);
Sakthivel Kf5860992013-04-17 16:37:02 +0530803 }
Viswas G05c6c022020-10-05 20:20:08 +0530804 for (i = 0; i < pm8001_ha->max_q_num; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530805 pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200806 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
Sakthivel Kf5860992013-04-17 16:37:02 +0530807 pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530808 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530809 pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530810 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530811 pm8001_ha->outbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530812 (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530813 pm8001_ha->outbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530814 pm8001_ha->memoryMap.region[ob_offset + i].total_len;
Sakthivel Kf5860992013-04-17 16:37:02 +0530815 pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530816 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530817 pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530818 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530819 /* interrupt vector based on oq */
820 pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = (i << 24);
821 pm8001_ha->outbnd_q_tbl[i].pi_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530822 pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530823 offsetob = i * 0x24;
824 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
825 get_pci_bar_index(pm8001_mr32(addressob,
826 offsetob + 0x14));
827 pm8001_ha->outbnd_q_tbl[i].ci_offset =
828 pm8001_mr32(addressob, (offsetob + 0x18));
829 pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
830 pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
peter chang73706722019-11-14 15:39:02 +0530831
Joe Perches1b5d2792020-11-20 15:16:09 -0800832 pm8001_dbg(pm8001_ha, DEV,
833 "OQ %d ci_bar 0x%x ci_offset 0x%x\n", i,
834 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar,
835 pm8001_ha->outbnd_q_tbl[i].ci_offset);
Sakthivel Kf5860992013-04-17 16:37:02 +0530836 }
837}
838
839/**
840 * update_main_config_table - update the main default table to the HBA.
841 * @pm8001_ha: our hba card information
842 */
843static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
844{
845 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
846 pm8001_mw32(address, MAIN_IQNPPD_HPPD_OFFSET,
847 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_q_nppd_hppd);
848 pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_HI,
849 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr);
850 pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_LO,
851 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr);
852 pm8001_mw32(address, MAIN_EVENT_LOG_BUFF_SIZE,
853 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
854 pm8001_mw32(address, MAIN_EVENT_LOG_OPTION,
855 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity);
856 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_HI,
857 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr);
858 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_LO,
859 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr);
860 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_BUFF_SIZE,
861 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size);
862 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_OPTION,
863 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity);
Deepak Ukey72349b62018-09-11 14:18:04 +0530864 /* Update Fatal error interrupt vector */
865 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt |=
Viswas G05c6c022020-10-05 20:20:08 +0530866 ((pm8001_ha->max_q_num - 1) << 8);
Sakthivel Kf5860992013-04-17 16:37:02 +0530867 pm8001_mw32(address, MAIN_FATAL_ERROR_INTERRUPT,
868 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt);
Joe Perches1b5d2792020-11-20 15:16:09 -0800869 pm8001_dbg(pm8001_ha, DEV,
870 "Updated Fatal error interrupt vector 0x%x\n",
871 pm8001_mr32(address, MAIN_FATAL_ERROR_INTERRUPT));
peter chang73706722019-11-14 15:39:02 +0530872
Sakthivel Kc6b9ef52013-03-19 18:08:08 +0530873 pm8001_mw32(address, MAIN_EVENT_CRC_CHECK,
874 pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump);
Sakthivel Kf5860992013-04-17 16:37:02 +0530875
876 /* SPCv specific */
877 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping &= 0xCFFFFFFF;
878 /* Set GPIOLED to 0x2 for LED indicator */
879 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping |= 0x20000000;
880 pm8001_mw32(address, MAIN_GPIO_LED_FLAGS_OFFSET,
881 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping);
Joe Perches1b5d2792020-11-20 15:16:09 -0800882 pm8001_dbg(pm8001_ha, DEV,
883 "Programming DW 0x21 in main cfg table with 0x%x\n",
884 pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET));
Sakthivel Kf5860992013-04-17 16:37:02 +0530885
886 pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
887 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
888 pm8001_mw32(address, MAIN_INT_REASSERTION_DELAY,
889 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interrupt_reassertion_delay);
Viswas G8414cd82015-08-11 15:06:30 +0530890
891 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &= 0xffff0000;
892 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
893 PORT_RECOVERY_TIMEOUT;
Viswas G61daffd2017-10-18 11:39:12 +0530894 if (pm8001_ha->chip_id == chip_8006) {
895 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &=
896 0x0000ffff;
897 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
Deepak Ukey196ba662019-07-09 15:30:48 +0530898 CHIP_8006_PORT_RECOVERY_TIMEOUT;
Viswas G61daffd2017-10-18 11:39:12 +0530899 }
Viswas G8414cd82015-08-11 15:06:30 +0530900 pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
901 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
Sakthivel Kf5860992013-04-17 16:37:02 +0530902}
903
904/**
905 * update_inbnd_queue_table - update the inbound queue table to the HBA.
906 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +0100907 * @number: entry in the queue
Sakthivel Kf5860992013-04-17 16:37:02 +0530908 */
909static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
910 int number)
911{
912 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
913 u16 offset = number * 0x20;
914 pm8001_mw32(address, offset + IB_PROPERITY_OFFSET,
915 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
916 pm8001_mw32(address, offset + IB_BASE_ADDR_HI_OFFSET,
917 pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
918 pm8001_mw32(address, offset + IB_BASE_ADDR_LO_OFFSET,
919 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
920 pm8001_mw32(address, offset + IB_CI_BASE_ADDR_HI_OFFSET,
921 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
922 pm8001_mw32(address, offset + IB_CI_BASE_ADDR_LO_OFFSET,
923 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
peter chang73706722019-11-14 15:39:02 +0530924
Joe Perches1b5d2792020-11-20 15:16:09 -0800925 pm8001_dbg(pm8001_ha, DEV,
926 "IQ %d: Element pri size 0x%x\n",
927 number,
928 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
peter chang73706722019-11-14 15:39:02 +0530929
Joe Perches1b5d2792020-11-20 15:16:09 -0800930 pm8001_dbg(pm8001_ha, DEV,
931 "IQ upr base addr 0x%x IQ lwr base addr 0x%x\n",
932 pm8001_ha->inbnd_q_tbl[number].upper_base_addr,
933 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
peter chang73706722019-11-14 15:39:02 +0530934
Joe Perches1b5d2792020-11-20 15:16:09 -0800935 pm8001_dbg(pm8001_ha, DEV,
936 "CI upper base addr 0x%x CI lower base addr 0x%x\n",
937 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr,
938 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
Sakthivel Kf5860992013-04-17 16:37:02 +0530939}
940
941/**
942 * update_outbnd_queue_table - update the outbound queue table to the HBA.
943 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +0100944 * @number: entry in the queue
Sakthivel Kf5860992013-04-17 16:37:02 +0530945 */
946static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
947 int number)
948{
949 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
950 u16 offset = number * 0x24;
951 pm8001_mw32(address, offset + OB_PROPERITY_OFFSET,
952 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
953 pm8001_mw32(address, offset + OB_BASE_ADDR_HI_OFFSET,
954 pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
955 pm8001_mw32(address, offset + OB_BASE_ADDR_LO_OFFSET,
956 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
957 pm8001_mw32(address, offset + OB_PI_BASE_ADDR_HI_OFFSET,
958 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
959 pm8001_mw32(address, offset + OB_PI_BASE_ADDR_LO_OFFSET,
960 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
961 pm8001_mw32(address, offset + OB_INTERRUPT_COALES_OFFSET,
962 pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
peter chang73706722019-11-14 15:39:02 +0530963
Joe Perches1b5d2792020-11-20 15:16:09 -0800964 pm8001_dbg(pm8001_ha, DEV,
965 "OQ %d: Element pri size 0x%x\n",
966 number,
967 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
peter chang73706722019-11-14 15:39:02 +0530968
Joe Perches1b5d2792020-11-20 15:16:09 -0800969 pm8001_dbg(pm8001_ha, DEV,
970 "OQ upr base addr 0x%x OQ lwr base addr 0x%x\n",
971 pm8001_ha->outbnd_q_tbl[number].upper_base_addr,
972 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
peter chang73706722019-11-14 15:39:02 +0530973
Joe Perches1b5d2792020-11-20 15:16:09 -0800974 pm8001_dbg(pm8001_ha, DEV,
975 "PI upper base addr 0x%x PI lower base addr 0x%x\n",
976 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr,
977 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
Sakthivel Kf5860992013-04-17 16:37:02 +0530978}
979
980/**
981 * mpi_init_check - check firmware initialization status.
982 * @pm8001_ha: our hba card information
983 */
984static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
985{
986 u32 max_wait_count;
987 u32 value;
988 u32 gst_len_mpistate;
989
990 /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
991 table is updated */
992 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_UPDATE);
993 /* wait until Inbound DoorBell Clear Register toggled */
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +0530994 if (IS_SPCV_12G(pm8001_ha->pdev)) {
ianyare90e23622019-11-14 15:39:03 +0530995 max_wait_count = SPCV_DOORBELL_CLEAR_TIMEOUT;
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +0530996 } else {
ianyare90e23622019-11-14 15:39:03 +0530997 max_wait_count = SPC_DOORBELL_CLEAR_TIMEOUT;
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +0530998 }
Sakthivel Kf5860992013-04-17 16:37:02 +0530999 do {
akshatzend71023a2021-01-09 18:08:42 +05301000 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301001 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1002 value &= SPCv_MSGU_CFG_TABLE_UPDATE;
1003 } while ((value != 0) && (--max_wait_count));
1004
Viswas G05c6c022020-10-05 20:20:08 +05301005 if (!max_wait_count) {
1006 /* additional check */
Joe Perches1b5d2792020-11-20 15:16:09 -08001007 pm8001_dbg(pm8001_ha, FAIL,
1008 "Inb doorbell clear not toggled[value:%x]\n",
1009 value);
Viswas G05c6c022020-10-05 20:20:08 +05301010 return -EBUSY;
1011 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301012 /* check the MPI-State for initialization upto 100ms*/
akshatzend71023a2021-01-09 18:08:42 +05301013 max_wait_count = 5;/* 100 msec */
Sakthivel Kf5860992013-04-17 16:37:02 +05301014 do {
akshatzend71023a2021-01-09 18:08:42 +05301015 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301016 gst_len_mpistate =
1017 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1018 GST_GSTLEN_MPIS_OFFSET);
1019 } while ((GST_MPI_STATE_INIT !=
1020 (gst_len_mpistate & GST_MPI_STATE_MASK)) && (--max_wait_count));
1021 if (!max_wait_count)
Viswas G05c6c022020-10-05 20:20:08 +05301022 return -EBUSY;
Sakthivel Kf5860992013-04-17 16:37:02 +05301023
1024 /* check MPI Initialization error */
1025 gst_len_mpistate = gst_len_mpistate >> 16;
1026 if (0x0000 != gst_len_mpistate)
Viswas G05c6c022020-10-05 20:20:08 +05301027 return -EBUSY;
Sakthivel Kf5860992013-04-17 16:37:02 +05301028
1029 return 0;
1030}
1031
1032/**
1033 * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
akshatzen48cd6b32020-11-02 22:25:27 +05301034 * This function sleeps hence it must not be used in atomic context.
Sakthivel Kf5860992013-04-17 16:37:02 +05301035 * @pm8001_ha: our hba card information
1036 */
1037static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
1038{
1039 u32 value;
1040 u32 max_wait_count;
1041 u32 max_wait_time;
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301042 u32 expected_mask;
Sakthivel Kf5860992013-04-17 16:37:02 +05301043 int ret = 0;
1044
1045 /* reset / PCIe ready */
akshatzen48cd6b32020-11-02 22:25:27 +05301046 max_wait_time = max_wait_count = 5; /* 100 milli sec */
Sakthivel Kf5860992013-04-17 16:37:02 +05301047 do {
akshatzen48cd6b32020-11-02 22:25:27 +05301048 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301049 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1050 } while ((value == 0xFFFFFFFF) && (--max_wait_count));
1051
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301052 /* check ila, RAAE and iops status */
Sakthivel Kf5860992013-04-17 16:37:02 +05301053 if ((pm8001_ha->chip_id != chip_8008) &&
1054 (pm8001_ha->chip_id != chip_8009)) {
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301055 max_wait_time = max_wait_count = 180; /* 3600 milli sec */
1056 expected_mask = SCRATCH_PAD_ILA_READY |
1057 SCRATCH_PAD_RAAE_READY |
1058 SCRATCH_PAD_IOP0_READY |
1059 SCRATCH_PAD_IOP1_READY;
1060 } else {
1061 max_wait_time = max_wait_count = 170; /* 3400 milli sec */
1062 expected_mask = SCRATCH_PAD_ILA_READY |
1063 SCRATCH_PAD_RAAE_READY |
1064 SCRATCH_PAD_IOP0_READY;
Sakthivel Kf5860992013-04-17 16:37:02 +05301065 }
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301066 do {
1067 msleep(FW_READY_INTERVAL);
1068 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1069 } while (((value & expected_mask) !=
1070 expected_mask) && (--max_wait_count));
1071 if (!max_wait_count) {
1072 pm8001_dbg(pm8001_ha, INIT,
1073 "At least one FW component failed to load within %d millisec: Scratchpad1: 0x%x\n",
1074 max_wait_time * FW_READY_INTERVAL, value);
1075 ret = -1;
1076 } else {
1077 pm8001_dbg(pm8001_ha, MSG,
1078 "All FW components ready by %d ms\n",
1079 (max_wait_time - max_wait_count) * FW_READY_INTERVAL);
1080 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301081 return ret;
1082}
1083
akshatzen95652f92021-01-09 18:08:44 +05301084static int init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
Sakthivel Kf5860992013-04-17 16:37:02 +05301085{
1086 void __iomem *base_addr;
1087 u32 value;
1088 u32 offset;
1089 u32 pcibar;
1090 u32 pcilogic;
1091
1092 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
akshatzen95652f92021-01-09 18:08:44 +05301093
1094 /**
1095 * lower 26 bits of SCRATCHPAD0 register describes offset within the
1096 * PCIe BAR where the MPI configuration table is present
1097 */
Sakthivel Kf5860992013-04-17 16:37:02 +05301098 offset = value & 0x03FFFFFF; /* scratch pad 0 TBL address */
1099
Joe Perches1b5d2792020-11-20 15:16:09 -08001100 pm8001_dbg(pm8001_ha, DEV, "Scratchpad 0 Offset: 0x%x value 0x%x\n",
1101 offset, value);
akshatzen95652f92021-01-09 18:08:44 +05301102 /**
1103 * Upper 6 bits describe the offset within PCI config space where BAR
1104 * is located.
1105 */
Sakthivel Kf5860992013-04-17 16:37:02 +05301106 pcilogic = (value & 0xFC000000) >> 26;
1107 pcibar = get_pci_bar_index(pcilogic);
Joe Perches1b5d2792020-11-20 15:16:09 -08001108 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar);
akshatzen95652f92021-01-09 18:08:44 +05301109
1110 /**
1111 * Make sure the offset falls inside the ioremapped PCI BAR
1112 */
1113 if (offset > pm8001_ha->io_mem[pcibar].memsize) {
1114 pm8001_dbg(pm8001_ha, FAIL,
1115 "Main cfg tbl offset outside %u > %u\n",
1116 offset, pm8001_ha->io_mem[pcibar].memsize);
1117 return -EBUSY;
1118 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301119 pm8001_ha->main_cfg_tbl_addr = base_addr =
1120 pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
akshatzen95652f92021-01-09 18:08:44 +05301121
1122 /**
1123 * Validate main configuration table address: first DWord should read
1124 * "PMCS"
1125 */
1126 value = pm8001_mr32(pm8001_ha->main_cfg_tbl_addr, 0);
1127 if (memcmp(&value, "PMCS", 4) != 0) {
1128 pm8001_dbg(pm8001_ha, FAIL,
1129 "BAD main config signature 0x%x\n",
1130 value);
1131 return -EBUSY;
1132 }
1133 pm8001_dbg(pm8001_ha, INIT,
1134 "VALID main config signature 0x%x\n", value);
Sakthivel Kf5860992013-04-17 16:37:02 +05301135 pm8001_ha->general_stat_tbl_addr =
1136 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x18) &
1137 0xFFFFFF);
1138 pm8001_ha->inbnd_q_tbl_addr =
1139 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C) &
1140 0xFFFFFF);
1141 pm8001_ha->outbnd_q_tbl_addr =
1142 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x20) &
1143 0xFFFFFF);
1144 pm8001_ha->ivt_tbl_addr =
1145 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C) &
1146 0xFFFFFF);
1147 pm8001_ha->pspa_q_tbl_addr =
1148 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x90) &
1149 0xFFFFFF);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05301150 pm8001_ha->fatal_tbl_addr =
1151 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0xA0) &
1152 0xFFFFFF);
Sakthivel Kf5860992013-04-17 16:37:02 +05301153
Joe Perches1b5d2792020-11-20 15:16:09 -08001154 pm8001_dbg(pm8001_ha, INIT, "GST OFFSET 0x%x\n",
1155 pm8001_cr32(pm8001_ha, pcibar, offset + 0x18));
1156 pm8001_dbg(pm8001_ha, INIT, "INBND OFFSET 0x%x\n",
1157 pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C));
1158 pm8001_dbg(pm8001_ha, INIT, "OBND OFFSET 0x%x\n",
1159 pm8001_cr32(pm8001_ha, pcibar, offset + 0x20));
1160 pm8001_dbg(pm8001_ha, INIT, "IVT OFFSET 0x%x\n",
1161 pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C));
1162 pm8001_dbg(pm8001_ha, INIT, "PSPA OFFSET 0x%x\n",
1163 pm8001_cr32(pm8001_ha, pcibar, offset + 0x90));
1164 pm8001_dbg(pm8001_ha, INIT, "addr - main cfg %p general status %p\n",
1165 pm8001_ha->main_cfg_tbl_addr,
1166 pm8001_ha->general_stat_tbl_addr);
1167 pm8001_dbg(pm8001_ha, INIT, "addr - inbnd %p obnd %p\n",
1168 pm8001_ha->inbnd_q_tbl_addr,
1169 pm8001_ha->outbnd_q_tbl_addr);
1170 pm8001_dbg(pm8001_ha, INIT, "addr - pspa %p ivt %p\n",
1171 pm8001_ha->pspa_q_tbl_addr,
1172 pm8001_ha->ivt_tbl_addr);
akshatzen95652f92021-01-09 18:08:44 +05301173 return 0;
Sakthivel Kf5860992013-04-17 16:37:02 +05301174}
1175
1176/**
1177 * pm80xx_set_thermal_config - support the thermal configuration
1178 * @pm8001_ha: our hba card information.
1179 */
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301180int
Sakthivel Kf5860992013-04-17 16:37:02 +05301181pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha)
1182{
1183 struct set_ctrl_cfg_req payload;
1184 struct inbound_queue_table *circularQ;
1185 int rc;
1186 u32 tag;
1187 u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
Viswas G842784e2015-08-11 15:06:27 +05301188 u32 page_code;
Sakthivel Kf5860992013-04-17 16:37:02 +05301189
1190 memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
1191 rc = pm8001_tag_alloc(pm8001_ha, &tag);
1192 if (rc)
1193 return -1;
1194
1195 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1196 payload.tag = cpu_to_le32(tag);
Viswas G842784e2015-08-11 15:06:27 +05301197
1198 if (IS_SPCV_12G(pm8001_ha->pdev))
1199 page_code = THERMAL_PAGE_CODE_7H;
1200 else
1201 page_code = THERMAL_PAGE_CODE_8H;
1202
Sakthivel Kf5860992013-04-17 16:37:02 +05301203 payload.cfg_pg[0] = (THERMAL_LOG_ENABLE << 9) |
Viswas G842784e2015-08-11 15:06:27 +05301204 (THERMAL_ENABLE << 8) | page_code;
Sakthivel Kf5860992013-04-17 16:37:02 +05301205 payload.cfg_pg[1] = (LTEMPHIL << 24) | (RTEMPHIL << 8);
1206
Joe Perches1b5d2792020-11-20 15:16:09 -08001207 pm8001_dbg(pm8001_ha, DEV,
1208 "Setting up thermal config. cfg_pg 0 0x%x cfg_pg 1 0x%x\n",
1209 payload.cfg_pg[0], payload.cfg_pg[1]);
peter chang73706722019-11-14 15:39:02 +05301210
peter chang91a43fa2019-11-14 15:39:05 +05301211 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
1212 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301213 if (rc)
1214 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05301215 return rc;
1216
1217}
1218
1219/**
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301220* pm80xx_set_sas_protocol_timer_config - support the SAS Protocol
1221* Timer configuration page
1222* @pm8001_ha: our hba card information.
1223*/
1224static int
1225pm80xx_set_sas_protocol_timer_config(struct pm8001_hba_info *pm8001_ha)
1226{
1227 struct set_ctrl_cfg_req payload;
1228 struct inbound_queue_table *circularQ;
1229 SASProtocolTimerConfig_t SASConfigPage;
1230 int rc;
1231 u32 tag;
1232 u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
1233
1234 memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
1235 memset(&SASConfigPage, 0, sizeof(SASProtocolTimerConfig_t));
1236
1237 rc = pm8001_tag_alloc(pm8001_ha, &tag);
1238
1239 if (rc)
1240 return -1;
1241
1242 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1243 payload.tag = cpu_to_le32(tag);
1244
1245 SASConfigPage.pageCode = SAS_PROTOCOL_TIMER_CONFIG_PAGE;
1246 SASConfigPage.MST_MSI = 3 << 15;
1247 SASConfigPage.STP_SSP_MCT_TMO = (STP_MCT_TMO << 16) | SSP_MCT_TMO;
1248 SASConfigPage.STP_FRM_TMO = (SAS_MAX_OPEN_TIME << 24) |
1249 (SMP_MAX_CONN_TIMER << 16) | STP_FRM_TIMER;
1250 SASConfigPage.STP_IDLE_TMO = STP_IDLE_TIME;
1251
1252 if (SASConfigPage.STP_IDLE_TMO > 0x3FFFFFF)
1253 SASConfigPage.STP_IDLE_TMO = 0x3FFFFFF;
1254
1255
1256 SASConfigPage.OPNRJT_RTRY_INTVL = (SAS_MFD << 16) |
1257 SAS_OPNRJT_RTRY_INTVL;
1258 SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO = (SAS_DOPNRJT_RTRY_TMO << 16)
1259 | SAS_COPNRJT_RTRY_TMO;
1260 SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR = (SAS_DOPNRJT_RTRY_THR << 16)
1261 | SAS_COPNRJT_RTRY_THR;
1262 SASConfigPage.MAX_AIP = SAS_MAX_AIP;
1263
Joe Perches1b5d2792020-11-20 15:16:09 -08001264 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.pageCode 0x%08x\n",
1265 SASConfigPage.pageCode);
1266 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.MST_MSI 0x%08x\n",
1267 SASConfigPage.MST_MSI);
1268 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_SSP_MCT_TMO 0x%08x\n",
1269 SASConfigPage.STP_SSP_MCT_TMO);
1270 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_FRM_TMO 0x%08x\n",
1271 SASConfigPage.STP_FRM_TMO);
1272 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_IDLE_TMO 0x%08x\n",
1273 SASConfigPage.STP_IDLE_TMO);
1274 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.OPNRJT_RTRY_INTVL 0x%08x\n",
1275 SASConfigPage.OPNRJT_RTRY_INTVL);
1276 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO 0x%08x\n",
1277 SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO);
1278 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR 0x%08x\n",
1279 SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR);
1280 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.MAX_AIP 0x%08x\n",
1281 SASConfigPage.MAX_AIP);
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301282
1283 memcpy(&payload.cfg_pg, &SASConfigPage,
1284 sizeof(SASProtocolTimerConfig_t));
1285
peter chang91a43fa2019-11-14 15:39:05 +05301286 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
1287 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301288 if (rc)
1289 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301290
1291 return rc;
1292}
1293
1294/**
Sakthivel Kf5860992013-04-17 16:37:02 +05301295 * pm80xx_get_encrypt_info - Check for encryption
1296 * @pm8001_ha: our hba card information.
1297 */
1298static int
1299pm80xx_get_encrypt_info(struct pm8001_hba_info *pm8001_ha)
1300{
1301 u32 scratch3_value;
Rickard Strandqvistda225492014-07-09 17:20:10 +05301302 int ret = -1;
Sakthivel Kf5860992013-04-17 16:37:02 +05301303
1304 /* Read encryption status from SCRATCH PAD 3 */
1305 scratch3_value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
1306
1307 if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1308 SCRATCH_PAD3_ENC_READY) {
1309 if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1310 pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1311 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1312 SCRATCH_PAD3_SMF_ENABLED)
1313 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1314 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1315 SCRATCH_PAD3_SMA_ENABLED)
1316 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1317 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1318 SCRATCH_PAD3_SMB_ENABLED)
1319 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1320 pm8001_ha->encrypt_info.status = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08001321 pm8001_dbg(pm8001_ha, INIT,
1322 "Encryption: SCRATCH_PAD3_ENC_READY 0x%08X.Cipher mode 0x%x Sec mode 0x%x status 0x%x\n",
1323 scratch3_value,
1324 pm8001_ha->encrypt_info.cipher_mode,
1325 pm8001_ha->encrypt_info.sec_mode,
1326 pm8001_ha->encrypt_info.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301327 ret = 0;
1328 } else if ((scratch3_value & SCRATCH_PAD3_ENC_READY) ==
1329 SCRATCH_PAD3_ENC_DISABLED) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001330 pm8001_dbg(pm8001_ha, INIT,
1331 "Encryption: SCRATCH_PAD3_ENC_DISABLED 0x%08X\n",
1332 scratch3_value);
Sakthivel Kf5860992013-04-17 16:37:02 +05301333 pm8001_ha->encrypt_info.status = 0xFFFFFFFF;
1334 pm8001_ha->encrypt_info.cipher_mode = 0;
1335 pm8001_ha->encrypt_info.sec_mode = 0;
Rickard Strandqvistda225492014-07-09 17:20:10 +05301336 ret = 0;
Sakthivel Kf5860992013-04-17 16:37:02 +05301337 } else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1338 SCRATCH_PAD3_ENC_DIS_ERR) {
1339 pm8001_ha->encrypt_info.status =
1340 (scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1341 if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1342 pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1343 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1344 SCRATCH_PAD3_SMF_ENABLED)
1345 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1346 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1347 SCRATCH_PAD3_SMA_ENABLED)
1348 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1349 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1350 SCRATCH_PAD3_SMB_ENABLED)
1351 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
Joe Perches1b5d2792020-11-20 15:16:09 -08001352 pm8001_dbg(pm8001_ha, INIT,
1353 "Encryption: SCRATCH_PAD3_DIS_ERR 0x%08X.Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
1354 scratch3_value,
1355 pm8001_ha->encrypt_info.cipher_mode,
1356 pm8001_ha->encrypt_info.sec_mode,
1357 pm8001_ha->encrypt_info.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301358 } else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1359 SCRATCH_PAD3_ENC_ENA_ERR) {
1360
1361 pm8001_ha->encrypt_info.status =
1362 (scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1363 if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1364 pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1365 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1366 SCRATCH_PAD3_SMF_ENABLED)
1367 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1368 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1369 SCRATCH_PAD3_SMA_ENABLED)
1370 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1371 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1372 SCRATCH_PAD3_SMB_ENABLED)
1373 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1374
Joe Perches1b5d2792020-11-20 15:16:09 -08001375 pm8001_dbg(pm8001_ha, INIT,
1376 "Encryption: SCRATCH_PAD3_ENA_ERR 0x%08X.Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
1377 scratch3_value,
1378 pm8001_ha->encrypt_info.cipher_mode,
1379 pm8001_ha->encrypt_info.sec_mode,
1380 pm8001_ha->encrypt_info.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301381 }
1382 return ret;
1383}
1384
1385/**
1386 * pm80xx_encrypt_update - update flash with encryption informtion
1387 * @pm8001_ha: our hba card information.
1388 */
1389static int pm80xx_encrypt_update(struct pm8001_hba_info *pm8001_ha)
1390{
1391 struct kek_mgmt_req payload;
1392 struct inbound_queue_table *circularQ;
1393 int rc;
1394 u32 tag;
1395 u32 opc = OPC_INB_KEK_MANAGEMENT;
1396
1397 memset(&payload, 0, sizeof(struct kek_mgmt_req));
1398 rc = pm8001_tag_alloc(pm8001_ha, &tag);
1399 if (rc)
1400 return -1;
1401
1402 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1403 payload.tag = cpu_to_le32(tag);
1404 /* Currently only one key is used. New KEK index is 1.
1405 * Current KEK index is 1. Store KEK to NVRAM is 1.
1406 */
1407 payload.new_curidx_ksop = ((1 << 24) | (1 << 16) | (1 << 8) |
1408 KEK_MGMT_SUBOP_KEYCARDUPDATE);
1409
Joe Perches1b5d2792020-11-20 15:16:09 -08001410 pm8001_dbg(pm8001_ha, DEV,
1411 "Saving Encryption info to flash. payload 0x%x\n",
1412 payload.new_curidx_ksop);
peter chang73706722019-11-14 15:39:02 +05301413
peter chang91a43fa2019-11-14 15:39:05 +05301414 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
1415 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301416 if (rc)
1417 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05301418
1419 return rc;
1420}
1421
1422/**
Lee Jones7cdaf122021-03-03 14:46:23 +00001423 * pm80xx_chip_init - the main init function that initialize whole PM8001 chip.
Sakthivel Kf5860992013-04-17 16:37:02 +05301424 * @pm8001_ha: our hba card information
1425 */
1426static int pm80xx_chip_init(struct pm8001_hba_info *pm8001_ha)
1427{
1428 int ret;
1429 u8 i = 0;
1430
1431 /* check the firmware status */
1432 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001433 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301434 return -EBUSY;
1435 }
1436
Deepak Ukey72349b62018-09-11 14:18:04 +05301437 /* Initialize the controller fatal error flag */
1438 pm8001_ha->controller_fatal_error = false;
1439
Sakthivel Kf5860992013-04-17 16:37:02 +05301440 /* Initialize pci space address eg: mpi offset */
akshatzen95652f92021-01-09 18:08:44 +05301441 ret = init_pci_device_addresses(pm8001_ha);
1442 if (ret) {
1443 pm8001_dbg(pm8001_ha, FAIL,
1444 "Failed to init pci addresses");
1445 return ret;
1446 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301447 init_default_table_values(pm8001_ha);
1448 read_main_config_table(pm8001_ha);
1449 read_general_status_table(pm8001_ha);
1450 read_inbnd_queue_table(pm8001_ha);
1451 read_outbnd_queue_table(pm8001_ha);
1452 read_phy_attr_table(pm8001_ha);
1453
1454 /* update main config table ,inbound table and outbound table */
1455 update_main_config_table(pm8001_ha);
Viswas G05c6c022020-10-05 20:20:08 +05301456 for (i = 0; i < pm8001_ha->max_q_num; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +05301457 update_inbnd_queue_table(pm8001_ha, i);
Sakthivel Kf5860992013-04-17 16:37:02 +05301458 update_outbnd_queue_table(pm8001_ha, i);
Viswas G05c6c022020-10-05 20:20:08 +05301459 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301460 /* notify firmware update finished and check initialization status */
1461 if (0 == mpi_init_check(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001462 pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301463 } else
1464 return -EBUSY;
1465
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301466 /* send SAS protocol timer configuration page to FW */
1467 ret = pm80xx_set_sas_protocol_timer_config(pm8001_ha);
Sakthivel Kf5860992013-04-17 16:37:02 +05301468
1469 /* Check for encryption */
1470 if (pm8001_ha->chip->encrypt) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001471 pm8001_dbg(pm8001_ha, INIT, "Checking for encryption\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301472 ret = pm80xx_get_encrypt_info(pm8001_ha);
1473 if (ret == -1) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001474 pm8001_dbg(pm8001_ha, INIT, "Encryption error !!\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301475 if (pm8001_ha->encrypt_info.status == 0x81) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001476 pm8001_dbg(pm8001_ha, INIT,
1477 "Encryption enabled with error.Saving encryption key to flash\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301478 pm80xx_encrypt_update(pm8001_ha);
1479 }
1480 }
1481 }
1482 return 0;
1483}
1484
1485static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
1486{
1487 u32 max_wait_count;
1488 u32 value;
1489 u32 gst_len_mpistate;
akshatzen95652f92021-01-09 18:08:44 +05301490 int ret;
1491
1492 ret = init_pci_device_addresses(pm8001_ha);
1493 if (ret) {
1494 pm8001_dbg(pm8001_ha, FAIL,
1495 "Failed to init pci addresses");
1496 return ret;
1497 }
1498
Sakthivel Kf5860992013-04-17 16:37:02 +05301499 /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
1500 table is stop */
1501 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_RESET);
1502
1503 /* wait until Inbound DoorBell Clear Register toggled */
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301504 if (IS_SPCV_12G(pm8001_ha->pdev)) {
Igor Pylypiv6f305bf2021-04-06 11:05:34 -07001505 max_wait_count = SPCV_DOORBELL_CLEAR_TIMEOUT;
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301506 } else {
Igor Pylypiv6f305bf2021-04-06 11:05:34 -07001507 max_wait_count = SPC_DOORBELL_CLEAR_TIMEOUT;
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301508 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301509 do {
Igor Pylypiv6f305bf2021-04-06 11:05:34 -07001510 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301511 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1512 value &= SPCv_MSGU_CFG_TABLE_RESET;
1513 } while ((value != 0) && (--max_wait_count));
1514
1515 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001516 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=%x\n", value);
Sakthivel Kf5860992013-04-17 16:37:02 +05301517 return -1;
1518 }
1519
1520 /* check the MPI-State for termination in progress */
1521 /* wait until Inbound DoorBell Clear Register toggled */
Igor Pylypiv6f305bf2021-04-06 11:05:34 -07001522 max_wait_count = 100; /* 2 sec for spcv/ve */
Sakthivel Kf5860992013-04-17 16:37:02 +05301523 do {
Igor Pylypiv6f305bf2021-04-06 11:05:34 -07001524 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301525 gst_len_mpistate =
1526 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1527 GST_GSTLEN_MPIS_OFFSET);
1528 if (GST_MPI_STATE_UNINIT ==
1529 (gst_len_mpistate & GST_MPI_STATE_MASK))
1530 break;
1531 } while (--max_wait_count);
1532 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001533 pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n",
1534 gst_len_mpistate & GST_MPI_STATE_MASK);
Sakthivel Kf5860992013-04-17 16:37:02 +05301535 return -1;
1536 }
1537
1538 return 0;
1539}
1540
1541/**
akshatzena961ea02021-01-09 18:08:43 +05301542 * pm80xx_fatal_errors - returns non zero *ONLY* when fatal errors
1543 * @pm8001_ha: our hba card information
1544 *
1545 * Fatal errors are recoverable only after a host reboot.
1546 */
1547int
1548pm80xx_fatal_errors(struct pm8001_hba_info *pm8001_ha)
1549{
1550 int ret = 0;
1551 u32 scratch_pad_rsvd0 = pm8001_cr32(pm8001_ha, 0,
1552 MSGU_HOST_SCRATCH_PAD_6);
1553 u32 scratch_pad_rsvd1 = pm8001_cr32(pm8001_ha, 0,
1554 MSGU_HOST_SCRATCH_PAD_7);
1555 u32 scratch_pad1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1556 u32 scratch_pad2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1557 u32 scratch_pad3 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
1558
1559 if (pm8001_ha->chip_id != chip_8006 &&
1560 pm8001_ha->chip_id != chip_8074 &&
1561 pm8001_ha->chip_id != chip_8076) {
1562 return 0;
1563 }
1564
1565 if (MSGU_SCRATCHPAD1_STATE_FATAL_ERROR(scratch_pad1)) {
1566 pm8001_dbg(pm8001_ha, FAIL,
1567 "Fatal error SCRATCHPAD1 = 0x%x SCRATCHPAD2 = 0x%x SCRATCHPAD3 = 0x%x SCRATCHPAD_RSVD0 = 0x%x SCRATCHPAD_RSVD1 = 0x%x\n",
1568 scratch_pad1, scratch_pad2, scratch_pad3,
1569 scratch_pad_rsvd0, scratch_pad_rsvd1);
1570 ret = 1;
1571 }
1572
1573 return ret;
1574}
1575
1576/**
Lee Jones7cdaf122021-03-03 14:46:23 +00001577 * pm80xx_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
Sakthivel Kf5860992013-04-17 16:37:02 +05301578 * the FW register status to the originated status.
1579 * @pm8001_ha: our hba card information
1580 */
1581
1582static int
1583pm80xx_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
1584{
1585 u32 regval;
1586 u32 bootloader_state;
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301587 u32 ibutton0, ibutton1;
Sakthivel Kf5860992013-04-17 16:37:02 +05301588
Deepak Ukey72349b62018-09-11 14:18:04 +05301589 /* Process MPI table uninitialization only if FW is ready */
1590 if (!pm8001_ha->controller_fatal_error) {
1591 /* Check if MPI is in ready state to reset */
1592 if (mpi_uninit_check(pm8001_ha) != 0) {
Vikram Auradkard384be62020-03-16 13:19:02 +05301593 u32 r0 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
1594 u32 r1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1595 u32 r2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1596 u32 r3 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
Joe Perches1b5d2792020-11-20 15:16:09 -08001597 pm8001_dbg(pm8001_ha, FAIL,
1598 "MPI state is not ready scratch: %x:%x:%x:%x\n",
1599 r0, r1, r2, r3);
Vikram Auradkard384be62020-03-16 13:19:02 +05301600 /* if things aren't ready but the bootloader is ok then
1601 * try the reset anyway.
1602 */
1603 if (r1 & SCRATCH_PAD1_BOOTSTATE_MASK)
1604 return -1;
Deepak Ukey72349b62018-09-11 14:18:04 +05301605 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301606 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301607 /* checked for reset register normal state; 0x0 */
1608 regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -08001609 pm8001_dbg(pm8001_ha, INIT, "reset register before write : 0x%x\n",
1610 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301611
1612 pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, SPCv_NORMAL_RESET_VALUE);
Vikram Auradkar4daf1ef2019-11-14 15:39:01 +05301613 msleep(500);
Sakthivel Kf5860992013-04-17 16:37:02 +05301614
1615 regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -08001616 pm8001_dbg(pm8001_ha, INIT, "reset register after write 0x%x\n",
1617 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301618
1619 if ((regval & SPCv_SOFT_RESET_READ_MASK) ==
1620 SPCv_SOFT_RESET_NORMAL_RESET_OCCURED) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001621 pm8001_dbg(pm8001_ha, MSG,
1622 " soft reset successful [regval: 0x%x]\n",
1623 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301624 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08001625 pm8001_dbg(pm8001_ha, MSG,
1626 " soft reset failed [regval: 0x%x]\n",
1627 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301628
1629 /* check bootloader is successfully executed or in HDA mode */
1630 bootloader_state =
1631 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1632 SCRATCH_PAD1_BOOTSTATE_MASK;
1633
1634 if (bootloader_state == SCRATCH_PAD1_BOOTSTATE_HDA_SEEPROM) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001635 pm8001_dbg(pm8001_ha, MSG,
1636 "Bootloader state - HDA mode SEEPROM\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301637 } else if (bootloader_state ==
1638 SCRATCH_PAD1_BOOTSTATE_HDA_BOOTSTRAP) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001639 pm8001_dbg(pm8001_ha, MSG,
1640 "Bootloader state - HDA mode Bootstrap Pin\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301641 } else if (bootloader_state ==
1642 SCRATCH_PAD1_BOOTSTATE_HDA_SOFTRESET) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001643 pm8001_dbg(pm8001_ha, MSG,
1644 "Bootloader state - HDA mode soft reset\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301645 } else if (bootloader_state ==
1646 SCRATCH_PAD1_BOOTSTATE_CRIT_ERROR) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001647 pm8001_dbg(pm8001_ha, MSG,
1648 "Bootloader state-HDA mode critical error\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301649 }
1650 return -EBUSY;
1651 }
1652
1653 /* check the firmware status after reset */
1654 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001655 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301656 /* check iButton feature support for motherboard controller */
1657 if (pm8001_ha->pdev->subsystem_vendor !=
1658 PCI_VENDOR_ID_ADAPTEC2 &&
Benjamin Roodfaf321b2015-10-30 10:53:29 -04001659 pm8001_ha->pdev->subsystem_vendor !=
1660 PCI_VENDOR_ID_ATTO &&
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301661 pm8001_ha->pdev->subsystem_vendor != 0) {
1662 ibutton0 = pm8001_cr32(pm8001_ha, 0,
1663 MSGU_HOST_SCRATCH_PAD_6);
1664 ibutton1 = pm8001_cr32(pm8001_ha, 0,
1665 MSGU_HOST_SCRATCH_PAD_7);
1666 if (!ibutton0 && !ibutton1) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001667 pm8001_dbg(pm8001_ha, FAIL,
1668 "iButton Feature is not Available!!!\n");
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301669 return -EBUSY;
1670 }
1671 if (ibutton0 == 0xdeadbeef && ibutton1 == 0xdeadbeef) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001672 pm8001_dbg(pm8001_ha, FAIL,
1673 "CRC Check for iButton Feature Failed!!!\n");
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301674 return -EBUSY;
1675 }
1676 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301677 }
Joe Perches1b5d2792020-11-20 15:16:09 -08001678 pm8001_dbg(pm8001_ha, INIT, "SPCv soft reset Complete\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301679 return 0;
1680}
1681
1682static void pm80xx_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1683{
Colin Ian King9e2a07e2019-03-17 18:15:32 +00001684 u32 i;
Sakthivel Kf5860992013-04-17 16:37:02 +05301685
Joe Perches1b5d2792020-11-20 15:16:09 -08001686 pm8001_dbg(pm8001_ha, INIT, "chip reset start\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301687
1688 /* do SPCv chip reset. */
1689 pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, 0x11);
Joe Perches1b5d2792020-11-20 15:16:09 -08001690 pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301691
1692 /* Check this ..whether delay is required or no */
1693 /* delay 10 usec */
1694 udelay(10);
1695
1696 /* wait for 20 msec until the firmware gets reloaded */
1697 i = 20;
1698 do {
1699 mdelay(1);
1700 } while ((--i) != 0);
1701
Joe Perches1b5d2792020-11-20 15:16:09 -08001702 pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301703}
1704
1705/**
Lee Jones7cdaf122021-03-03 14:46:23 +00001706 * pm80xx_chip_intx_interrupt_enable - enable PM8001 chip interrupt
Sakthivel Kf5860992013-04-17 16:37:02 +05301707 * @pm8001_ha: our hba card information
1708 */
1709static void
1710pm80xx_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1711{
1712 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1713 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1714}
1715
1716/**
Lee Jones7cdaf122021-03-03 14:46:23 +00001717 * pm80xx_chip_intx_interrupt_disable - disable PM8001 chip interrupt
Sakthivel Kf5860992013-04-17 16:37:02 +05301718 * @pm8001_ha: our hba card information
1719 */
1720static void
1721pm80xx_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1722{
1723 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, ODMR_MASK_ALL);
1724}
1725
1726/**
Lee Jones7cdaf122021-03-03 14:46:23 +00001727 * pm80xx_chip_interrupt_enable - enable PM8001 chip interrupt
Sakthivel Kf5860992013-04-17 16:37:02 +05301728 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +01001729 * @vec: interrupt number to enable
Sakthivel Kf5860992013-04-17 16:37:02 +05301730 */
1731static void
1732pm80xx_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1733{
1734#ifdef PM8001_USE_MSIX
1735 u32 mask;
1736 mask = (u32)(1 << vec);
1737
1738 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, (u32)(mask & 0xFFFFFFFF));
1739 return;
1740#endif
1741 pm80xx_chip_intx_interrupt_enable(pm8001_ha);
1742
1743}
1744
1745/**
Lee Jones7cdaf122021-03-03 14:46:23 +00001746 * pm80xx_chip_interrupt_disable - disable PM8001 chip interrupt
Sakthivel Kf5860992013-04-17 16:37:02 +05301747 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +01001748 * @vec: interrupt number to disable
Sakthivel Kf5860992013-04-17 16:37:02 +05301749 */
1750static void
1751pm80xx_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1752{
1753#ifdef PM8001_USE_MSIX
1754 u32 mask;
1755 if (vec == 0xFF)
1756 mask = 0xFFFFFFFF;
1757 else
1758 mask = (u32)(1 << vec);
1759 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, (u32)(mask & 0xFFFFFFFF));
1760 return;
1761#endif
1762 pm80xx_chip_intx_interrupt_disable(pm8001_ha);
1763}
1764
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301765static void pm80xx_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1766 struct pm8001_device *pm8001_ha_dev)
1767{
1768 int res;
1769 u32 ccb_tag;
1770 struct pm8001_ccb_info *ccb;
1771 struct sas_task *task = NULL;
1772 struct task_abort_req task_abort;
1773 struct inbound_queue_table *circularQ;
1774 u32 opc = OPC_INB_SATA_ABORT;
1775 int ret;
1776
1777 if (!pm8001_ha_dev) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001778 pm8001_dbg(pm8001_ha, FAIL, "dev is null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301779 return;
1780 }
1781
1782 task = sas_alloc_slow_task(GFP_ATOMIC);
1783
1784 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001785 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301786 return;
1787 }
1788
1789 task->task_done = pm8001_task_done;
1790
1791 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301792 if (res) {
1793 sas_free_task(task);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301794 return;
Tomas Henzl5533abc2014-07-09 17:20:49 +05301795 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301796
1797 ccb = &pm8001_ha->ccb_info[ccb_tag];
1798 ccb->device = pm8001_ha_dev;
1799 ccb->ccb_tag = ccb_tag;
1800 ccb->task = task;
1801
1802 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1803
1804 memset(&task_abort, 0, sizeof(task_abort));
1805 task_abort.abort_all = cpu_to_le32(1);
1806 task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1807 task_abort.tag = cpu_to_le32(ccb_tag);
1808
peter chang91a43fa2019-11-14 15:39:05 +05301809 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
1810 sizeof(task_abort), 0);
Joe Perches1b5d2792020-11-20 15:16:09 -08001811 pm8001_dbg(pm8001_ha, FAIL, "Executing abort task end\n");
Tomas Henzl5533abc2014-07-09 17:20:49 +05301812 if (ret) {
1813 sas_free_task(task);
1814 pm8001_tag_free(pm8001_ha, ccb_tag);
1815 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301816}
1817
1818static void pm80xx_send_read_log(struct pm8001_hba_info *pm8001_ha,
1819 struct pm8001_device *pm8001_ha_dev)
1820{
1821 struct sata_start_req sata_cmd;
1822 int res;
1823 u32 ccb_tag;
1824 struct pm8001_ccb_info *ccb;
1825 struct sas_task *task = NULL;
1826 struct host_to_dev_fis fis;
1827 struct domain_device *dev;
1828 struct inbound_queue_table *circularQ;
1829 u32 opc = OPC_INB_SATA_HOST_OPSTART;
1830
1831 task = sas_alloc_slow_task(GFP_ATOMIC);
1832
1833 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001834 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301835 return;
1836 }
1837 task->task_done = pm8001_task_done;
1838
1839 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1840 if (res) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301841 sas_free_task(task);
Joe Perches1b5d2792020-11-20 15:16:09 -08001842 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate tag !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301843 return;
1844 }
1845
1846 /* allocate domain device by ourselves as libsas
1847 * is not going to provide any
1848 */
1849 dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1850 if (!dev) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301851 sas_free_task(task);
1852 pm8001_tag_free(pm8001_ha, ccb_tag);
Joe Perches1b5d2792020-11-20 15:16:09 -08001853 pm8001_dbg(pm8001_ha, FAIL,
1854 "Domain device cannot be allocated\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301855 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301856 }
1857
Tomas Henzl5533abc2014-07-09 17:20:49 +05301858 task->dev = dev;
1859 task->dev->lldd_dev = pm8001_ha_dev;
1860
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301861 ccb = &pm8001_ha->ccb_info[ccb_tag];
1862 ccb->device = pm8001_ha_dev;
1863 ccb->ccb_tag = ccb_tag;
1864 ccb->task = task;
Viswas G0b6df112017-10-18 11:39:14 +05301865 ccb->n_elem = 0;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301866 pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1867 pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1868
1869 memset(&sata_cmd, 0, sizeof(sata_cmd));
1870 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1871
1872 /* construct read log FIS */
1873 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1874 fis.fis_type = 0x27;
1875 fis.flags = 0x80;
1876 fis.command = ATA_CMD_READ_LOG_EXT;
1877 fis.lbal = 0x10;
1878 fis.sector_count = 0x1;
1879
1880 sata_cmd.tag = cpu_to_le32(ccb_tag);
1881 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1882 sata_cmd.ncqtag_atap_dir_m_dad |= ((0x1 << 7) | (0x5 << 9));
1883 memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1884
peter chang91a43fa2019-11-14 15:39:05 +05301885 res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
1886 sizeof(sata_cmd), 0);
Joe Perches1b5d2792020-11-20 15:16:09 -08001887 pm8001_dbg(pm8001_ha, FAIL, "Executing read log end\n");
Tomas Henzl5533abc2014-07-09 17:20:49 +05301888 if (res) {
1889 sas_free_task(task);
1890 pm8001_tag_free(pm8001_ha, ccb_tag);
1891 kfree(dev);
1892 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301893}
1894
Sakthivel Kf5860992013-04-17 16:37:02 +05301895/**
1896 * mpi_ssp_completion- process the event that FW response to the SSP request.
1897 * @pm8001_ha: our hba card information
1898 * @piomb: the message contents of this outbound message.
1899 *
1900 * When FW has completed a ssp request for example a IO request, after it has
1901 * filled the SG data with the data, it will trigger this event represent
1902 * that he has finished the job,please check the coresponding buffer.
1903 * So we will tell the caller who maybe waiting the result to tell upper layer
1904 * that the task has been finished.
1905 */
1906static void
1907mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
1908{
1909 struct sas_task *t;
1910 struct pm8001_ccb_info *ccb;
1911 unsigned long flags;
1912 u32 status;
1913 u32 param;
1914 u32 tag;
1915 struct ssp_completion_resp *psspPayload;
1916 struct task_status_struct *ts;
1917 struct ssp_response_iu *iu;
1918 struct pm8001_device *pm8001_dev;
1919 psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1920 status = le32_to_cpu(psspPayload->status);
1921 tag = le32_to_cpu(psspPayload->tag);
1922 ccb = &pm8001_ha->ccb_info[tag];
1923 if ((status == IO_ABORTED) && ccb->open_retry) {
1924 /* Being completed by another */
1925 ccb->open_retry = 0;
1926 return;
1927 }
1928 pm8001_dev = ccb->device;
1929 param = le32_to_cpu(psspPayload->param);
1930 t = ccb->task;
1931
1932 if (status && status != IO_UNDERFLOW)
Joe Perches1b5d2792020-11-20 15:16:09 -08001933 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301934 if (unlikely(!t || !t->lldd_task || !t->dev))
1935 return;
1936 ts = &t->task_status;
peter chang73706722019-11-14 15:39:02 +05301937
Joe Perches1b5d2792020-11-20 15:16:09 -08001938 pm8001_dbg(pm8001_ha, DEV,
1939 "tag::0x%x, status::0x%x task::0x%p\n", tag, status, t);
peter chang73706722019-11-14 15:39:02 +05301940
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301941 /* Print sas address of IO failed device */
1942 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1943 (status != IO_UNDERFLOW))
Joe Perches1b5d2792020-11-20 15:16:09 -08001944 pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n",
1945 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301946
Sakthivel Kf5860992013-04-17 16:37:02 +05301947 switch (status) {
1948 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001949 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS ,param = 0x%x\n",
1950 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05301951 if (param == 0) {
1952 ts->resp = SAS_TASK_COMPLETE;
1953 ts->stat = SAM_STAT_GOOD;
1954 } else {
1955 ts->resp = SAS_TASK_COMPLETE;
1956 ts->stat = SAS_PROTO_RESPONSE;
1957 ts->residual = param;
1958 iu = &psspPayload->ssp_resp_iu;
1959 sas_ssp_task_response(pm8001_ha->dev, t, iu);
1960 }
1961 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301962 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301963 break;
1964 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001965 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301966 ts->resp = SAS_TASK_COMPLETE;
1967 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05301968 if (pm8001_dev)
1969 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301970 break;
1971 case IO_UNDERFLOW:
1972 /* SSP Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08001973 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW ,param = 0x%x\n",
1974 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05301975 ts->resp = SAS_TASK_COMPLETE;
1976 ts->stat = SAS_DATA_UNDERRUN;
1977 ts->residual = param;
1978 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301979 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301980 break;
1981 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08001982 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301983 ts->resp = SAS_TASK_UNDELIVERED;
1984 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05301985 if (pm8001_dev)
1986 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301987 break;
1988 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001989 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301990 ts->resp = SAS_TASK_COMPLETE;
1991 ts->stat = SAS_OPEN_REJECT;
1992 /* Force the midlayer to retry */
1993 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05301994 if (pm8001_dev)
1995 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301996 break;
1997 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08001998 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301999 ts->resp = SAS_TASK_COMPLETE;
2000 ts->stat = SAS_OPEN_REJECT;
2001 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302002 if (pm8001_dev)
2003 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302004 break;
Viswas G27ecfa52015-08-11 15:06:31 +05302005 case IO_XFER_ERROR_INVALID_SSP_RSP_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08002006 pm8001_dbg(pm8001_ha, IO,
2007 "IO_XFER_ERROR_INVALID_SSP_RSP_FRAME\n");
Viswas G27ecfa52015-08-11 15:06:31 +05302008 ts->resp = SAS_TASK_COMPLETE;
2009 ts->stat = SAS_OPEN_REJECT;
2010 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302011 if (pm8001_dev)
2012 atomic_dec(&pm8001_dev->running_req);
Viswas G27ecfa52015-08-11 15:06:31 +05302013 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302014 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002015 pm8001_dbg(pm8001_ha, IO,
2016 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302017 ts->resp = SAS_TASK_COMPLETE;
2018 ts->stat = SAS_OPEN_REJECT;
2019 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302020 if (pm8001_dev)
2021 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302022 break;
2023 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002024 pm8001_dbg(pm8001_ha, IO,
2025 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302026 ts->resp = SAS_TASK_COMPLETE;
2027 ts->stat = SAS_OPEN_REJECT;
2028 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302029 if (pm8001_dev)
2030 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302031 break;
2032 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002033 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302034 ts->resp = SAS_TASK_COMPLETE;
2035 ts->stat = SAS_OPEN_REJECT;
2036 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302037 if (pm8001_dev)
2038 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302039 break;
2040 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302041 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2042 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2043 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2044 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2045 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002046 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302047 ts->resp = SAS_TASK_COMPLETE;
2048 ts->stat = SAS_OPEN_REJECT;
2049 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2050 if (!t->uldd_task)
2051 pm8001_handle_event(pm8001_ha,
2052 pm8001_dev,
2053 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2054 break;
2055 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002056 pm8001_dbg(pm8001_ha, IO,
2057 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302058 ts->resp = SAS_TASK_COMPLETE;
2059 ts->stat = SAS_OPEN_REJECT;
2060 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302061 if (pm8001_dev)
2062 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302063 break;
2064 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002065 pm8001_dbg(pm8001_ha, IO,
2066 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302067 ts->resp = SAS_TASK_COMPLETE;
2068 ts->stat = SAS_OPEN_REJECT;
2069 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302070 if (pm8001_dev)
2071 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302072 break;
2073 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002074 pm8001_dbg(pm8001_ha, IO,
2075 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302076 ts->resp = SAS_TASK_UNDELIVERED;
2077 ts->stat = SAS_OPEN_REJECT;
2078 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302079 if (pm8001_dev)
2080 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302081 break;
2082 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002083 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302084 ts->resp = SAS_TASK_COMPLETE;
2085 ts->stat = SAS_OPEN_REJECT;
2086 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302087 if (pm8001_dev)
2088 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302089 break;
2090 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002091 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302092 ts->resp = SAS_TASK_COMPLETE;
2093 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302094 if (pm8001_dev)
2095 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302096 break;
2097 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002098 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302099 ts->resp = SAS_TASK_COMPLETE;
2100 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302101 if (pm8001_dev)
2102 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302103 break;
2104 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002105 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302106 ts->resp = SAS_TASK_COMPLETE;
2107 ts->stat = SAS_OPEN_REJECT;
2108 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302109 if (pm8001_dev)
2110 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302111 break;
2112 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002113 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302114 ts->resp = SAS_TASK_COMPLETE;
2115 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302116 if (pm8001_dev)
2117 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302118 break;
2119 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002120 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302121 ts->resp = SAS_TASK_COMPLETE;
2122 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302123 if (pm8001_dev)
2124 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302125 break;
2126 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002127 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302128 ts->resp = SAS_TASK_COMPLETE;
2129 ts->stat = SAS_OPEN_REJECT;
2130 if (!t->uldd_task)
2131 pm8001_handle_event(pm8001_ha,
2132 pm8001_dev,
2133 IO_DS_NON_OPERATIONAL);
2134 break;
2135 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002136 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302137 ts->resp = SAS_TASK_COMPLETE;
2138 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302139 if (pm8001_dev)
2140 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302141 break;
2142 case IO_TM_TAG_NOT_FOUND:
Joe Perches1b5d2792020-11-20 15:16:09 -08002143 pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302144 ts->resp = SAS_TASK_COMPLETE;
2145 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302146 if (pm8001_dev)
2147 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302148 break;
2149 case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002150 pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302151 ts->resp = SAS_TASK_COMPLETE;
2152 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302153 if (pm8001_dev)
2154 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302155 break;
2156 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002157 pm8001_dbg(pm8001_ha, IO,
2158 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302159 ts->resp = SAS_TASK_COMPLETE;
2160 ts->stat = SAS_OPEN_REJECT;
2161 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302162 if (pm8001_dev)
2163 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302164 break;
2165 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002166 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05302167 /* not allowed case. Therefore, return failed status */
2168 ts->resp = SAS_TASK_COMPLETE;
2169 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302170 if (pm8001_dev)
2171 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302172 break;
2173 }
Joe Perches1b5d2792020-11-20 15:16:09 -08002174 pm8001_dbg(pm8001_ha, IO, "scsi_status = 0x%x\n ",
2175 psspPayload->ssp_resp_iu.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05302176 spin_lock_irqsave(&t->task_state_lock, flags);
2177 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2178 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2179 t->task_state_flags |= SAS_TASK_STATE_DONE;
2180 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2181 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002182 pm8001_dbg(pm8001_ha, FAIL,
2183 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2184 t, status, ts->resp, ts->stat);
Viswas G869ddbd2017-10-18 11:39:13 +05302185 if (t->slow_task)
2186 complete(&t->slow_task->completion);
Sakthivel Kf5860992013-04-17 16:37:02 +05302187 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2188 } else {
2189 spin_unlock_irqrestore(&t->task_state_lock, flags);
2190 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2191 mb();/* in order to force CPU ordering */
2192 t->task_done(t);
2193 }
2194}
2195
2196/*See the comments for mpi_ssp_completion */
2197static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
2198{
2199 struct sas_task *t;
2200 unsigned long flags;
2201 struct task_status_struct *ts;
2202 struct pm8001_ccb_info *ccb;
2203 struct pm8001_device *pm8001_dev;
2204 struct ssp_event_resp *psspPayload =
2205 (struct ssp_event_resp *)(piomb + 4);
2206 u32 event = le32_to_cpu(psspPayload->event);
2207 u32 tag = le32_to_cpu(psspPayload->tag);
2208 u32 port_id = le32_to_cpu(psspPayload->port_id);
2209
2210 ccb = &pm8001_ha->ccb_info[tag];
2211 t = ccb->task;
2212 pm8001_dev = ccb->device;
2213 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002214 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302215 if (unlikely(!t || !t->lldd_task || !t->dev))
2216 return;
2217 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002218 pm8001_dbg(pm8001_ha, IOERR, "port_id:0x%x, tag:0x%x, event:0x%x\n",
2219 port_id, tag, event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302220 switch (event) {
2221 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002222 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302223 ts->resp = SAS_TASK_COMPLETE;
2224 ts->stat = SAS_DATA_OVERRUN;
2225 ts->residual = 0;
2226 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302227 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302228 break;
2229 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002230 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302231 pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2232 return;
2233 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002234 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302235 ts->resp = SAS_TASK_COMPLETE;
2236 ts->stat = SAS_OPEN_REJECT;
2237 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2238 break;
2239 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002240 pm8001_dbg(pm8001_ha, IO,
2241 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302242 ts->resp = SAS_TASK_COMPLETE;
2243 ts->stat = SAS_OPEN_REJECT;
2244 ts->open_rej_reason = SAS_OREJ_EPROTO;
2245 break;
2246 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002247 pm8001_dbg(pm8001_ha, IO,
2248 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302249 ts->resp = SAS_TASK_COMPLETE;
2250 ts->stat = SAS_OPEN_REJECT;
2251 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2252 break;
2253 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002254 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302255 ts->resp = SAS_TASK_COMPLETE;
2256 ts->stat = SAS_OPEN_REJECT;
2257 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2258 break;
2259 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302260 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2261 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2262 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2263 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2264 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002265 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302266 ts->resp = SAS_TASK_COMPLETE;
2267 ts->stat = SAS_OPEN_REJECT;
2268 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2269 if (!t->uldd_task)
2270 pm8001_handle_event(pm8001_ha,
2271 pm8001_dev,
2272 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2273 break;
2274 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002275 pm8001_dbg(pm8001_ha, IO,
2276 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302277 ts->resp = SAS_TASK_COMPLETE;
2278 ts->stat = SAS_OPEN_REJECT;
2279 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2280 break;
2281 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002282 pm8001_dbg(pm8001_ha, IO,
2283 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302284 ts->resp = SAS_TASK_COMPLETE;
2285 ts->stat = SAS_OPEN_REJECT;
2286 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2287 break;
2288 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002289 pm8001_dbg(pm8001_ha, IO,
2290 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302291 ts->resp = SAS_TASK_COMPLETE;
2292 ts->stat = SAS_OPEN_REJECT;
2293 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2294 break;
2295 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002296 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302297 ts->resp = SAS_TASK_COMPLETE;
2298 ts->stat = SAS_OPEN_REJECT;
2299 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2300 break;
2301 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002302 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302303 ts->resp = SAS_TASK_COMPLETE;
2304 ts->stat = SAS_NAK_R_ERR;
2305 break;
2306 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002307 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302308 pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2309 return;
2310 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002311 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302312 ts->resp = SAS_TASK_COMPLETE;
2313 ts->stat = SAS_DATA_OVERRUN;
2314 break;
2315 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002316 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302317 ts->resp = SAS_TASK_COMPLETE;
2318 ts->stat = SAS_DATA_OVERRUN;
2319 break;
2320 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002321 pm8001_dbg(pm8001_ha, IO,
2322 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302323 ts->resp = SAS_TASK_COMPLETE;
2324 ts->stat = SAS_DATA_OVERRUN;
2325 break;
2326 case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002327 pm8001_dbg(pm8001_ha, IO,
2328 "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302329 ts->resp = SAS_TASK_COMPLETE;
2330 ts->stat = SAS_DATA_OVERRUN;
2331 break;
2332 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002333 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302334 ts->resp = SAS_TASK_COMPLETE;
2335 ts->stat = SAS_DATA_OVERRUN;
2336 break;
2337 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002338 pm8001_dbg(pm8001_ha, IO,
2339 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302340 ts->resp = SAS_TASK_COMPLETE;
2341 ts->stat = SAS_DATA_OVERRUN;
2342 break;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302343 case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002344 pm8001_dbg(pm8001_ha, IOERR,
2345 "IO_XFR_ERROR_INTERNAL_CRC_ERROR\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302346 /* TBC: used default set values */
2347 ts->resp = SAS_TASK_COMPLETE;
2348 ts->stat = SAS_DATA_OVERRUN;
2349 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302350 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002351 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302352 return;
2353 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002354 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302355 /* not allowed case. Therefore, return failed status */
2356 ts->resp = SAS_TASK_COMPLETE;
2357 ts->stat = SAS_DATA_OVERRUN;
2358 break;
2359 }
2360 spin_lock_irqsave(&t->task_state_lock, flags);
2361 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2362 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2363 t->task_state_flags |= SAS_TASK_STATE_DONE;
2364 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2365 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002366 pm8001_dbg(pm8001_ha, FAIL,
2367 "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2368 t, event, ts->resp, ts->stat);
Sakthivel Kf5860992013-04-17 16:37:02 +05302369 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2370 } else {
2371 spin_unlock_irqrestore(&t->task_state_lock, flags);
2372 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2373 mb();/* in order to force CPU ordering */
2374 t->task_done(t);
2375 }
2376}
2377
2378/*See the comments for mpi_ssp_completion */
2379static void
2380mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2381{
2382 struct sas_task *t;
2383 struct pm8001_ccb_info *ccb;
2384 u32 param;
2385 u32 status;
2386 u32 tag;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302387 int i, j;
2388 u8 sata_addr_low[4];
2389 u32 temp_sata_addr_low, temp_sata_addr_hi;
2390 u8 sata_addr_hi[4];
Sakthivel Kf5860992013-04-17 16:37:02 +05302391 struct sata_completion_resp *psataPayload;
2392 struct task_status_struct *ts;
2393 struct ata_task_resp *resp ;
2394 u32 *sata_resp;
2395 struct pm8001_device *pm8001_dev;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302396 unsigned long flags;
Sakthivel Kf5860992013-04-17 16:37:02 +05302397
2398 psataPayload = (struct sata_completion_resp *)(piomb + 4);
2399 status = le32_to_cpu(psataPayload->status);
2400 tag = le32_to_cpu(psataPayload->tag);
2401
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302402 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002403 pm8001_dbg(pm8001_ha, FAIL, "tag null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302404 return;
2405 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302406 ccb = &pm8001_ha->ccb_info[tag];
2407 param = le32_to_cpu(psataPayload->param);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302408 if (ccb) {
2409 t = ccb->task;
2410 pm8001_dev = ccb->device;
2411 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002412 pm8001_dbg(pm8001_ha, FAIL, "ccb null\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302413 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302414 }
2415
2416 if (t) {
2417 if (t->dev && (t->dev->lldd_dev))
2418 pm8001_dev = t->dev->lldd_dev;
2419 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002420 pm8001_dbg(pm8001_ha, FAIL, "task null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302421 return;
2422 }
2423
2424 if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2425 && unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002426 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302427 return;
2428 }
2429
2430 ts = &t->task_status;
2431 if (!ts) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002432 pm8001_dbg(pm8001_ha, FAIL, "ts null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302433 return;
2434 }
peter chang73706722019-11-14 15:39:02 +05302435
Vishakha Channapattan4f608fb2021-01-09 18:08:48 +05302436 if (status != IO_SUCCESS) {
2437 pm8001_dbg(pm8001_ha, FAIL,
2438 "IO failed device_id %u status 0x%x tag %d\n",
2439 pm8001_dev->device_id, status, tag);
2440 }
peter chang73706722019-11-14 15:39:02 +05302441
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302442 /* Print sas address of IO failed device */
2443 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2444 (status != IO_UNDERFLOW)) {
2445 if (!((t->dev->parent) &&
John Garry924a3542019-06-10 20:41:41 +08002446 (dev_is_expander(t->dev->parent->dev_type)))) {
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302447 for (i = 0 , j = 4; i <= 3 && j <= 7; i++ , j++)
2448 sata_addr_low[i] = pm8001_ha->sas_addr[j];
2449 for (i = 0 , j = 0; i <= 3 && j <= 3; i++ , j++)
2450 sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2451 memcpy(&temp_sata_addr_low, sata_addr_low,
2452 sizeof(sata_addr_low));
2453 memcpy(&temp_sata_addr_hi, sata_addr_hi,
2454 sizeof(sata_addr_hi));
2455 temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2456 |((temp_sata_addr_hi << 8) &
2457 0xff0000) |
2458 ((temp_sata_addr_hi >> 8)
2459 & 0xff00) |
2460 ((temp_sata_addr_hi << 24) &
2461 0xff000000));
2462 temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2463 & 0xff) |
2464 ((temp_sata_addr_low << 8)
2465 & 0xff0000) |
2466 ((temp_sata_addr_low >> 8)
2467 & 0xff00) |
2468 ((temp_sata_addr_low << 24)
2469 & 0xff000000)) +
2470 pm8001_dev->attached_phy +
2471 0x10);
Joe Perches1b5d2792020-11-20 15:16:09 -08002472 pm8001_dbg(pm8001_ha, FAIL,
2473 "SAS Address of IO Failure Drive:%08x%08x\n",
2474 temp_sata_addr_hi,
2475 temp_sata_addr_low);
Sakthivel Kf5860992013-04-17 16:37:02 +05302476
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302477 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002478 pm8001_dbg(pm8001_ha, FAIL,
2479 "SAS Address of IO Failure Drive:%016llx\n",
2480 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302481 }
2482 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302483 switch (status) {
2484 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002485 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302486 if (param == 0) {
2487 ts->resp = SAS_TASK_COMPLETE;
2488 ts->stat = SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302489 /* check if response is for SEND READ LOG */
2490 if (pm8001_dev &&
2491 (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2492 /* set new bit for abort_all */
2493 pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2494 /* clear bit for read log */
2495 pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2496 pm80xx_send_abort_all(pm8001_ha, pm8001_dev);
2497 /* Free the tag */
2498 pm8001_tag_free(pm8001_ha, tag);
2499 sas_free_task(t);
2500 return;
2501 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302502 } else {
2503 u8 len;
2504 ts->resp = SAS_TASK_COMPLETE;
2505 ts->stat = SAS_PROTO_RESPONSE;
2506 ts->residual = param;
Joe Perches1b5d2792020-11-20 15:16:09 -08002507 pm8001_dbg(pm8001_ha, IO,
2508 "SAS_PROTO_RESPONSE len = %d\n",
2509 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05302510 sata_resp = &psataPayload->sata_resp[0];
2511 resp = (struct ata_task_resp *)ts->buf;
2512 if (t->ata_task.dma_xfer == 0 &&
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02002513 t->data_dir == DMA_FROM_DEVICE) {
Sakthivel Kf5860992013-04-17 16:37:02 +05302514 len = sizeof(struct pio_setup_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002515 pm8001_dbg(pm8001_ha, IO,
2516 "PIO read len = %d\n", len);
Sakthivel Kf5860992013-04-17 16:37:02 +05302517 } else if (t->ata_task.use_ncq) {
2518 len = sizeof(struct set_dev_bits_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002519 pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n",
2520 len);
Sakthivel Kf5860992013-04-17 16:37:02 +05302521 } else {
2522 len = sizeof(struct dev_to_host_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002523 pm8001_dbg(pm8001_ha, IO, "other len = %d\n",
2524 len);
Sakthivel Kf5860992013-04-17 16:37:02 +05302525 }
2526 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2527 resp->frame_len = len;
2528 memcpy(&resp->ending_fis[0], sata_resp, len);
2529 ts->buf_valid_size = sizeof(*resp);
2530 } else
Joe Perches1b5d2792020-11-20 15:16:09 -08002531 pm8001_dbg(pm8001_ha, IO,
2532 "response too large\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302533 }
2534 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302535 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302536 break;
2537 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002538 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302539 ts->resp = SAS_TASK_COMPLETE;
2540 ts->stat = SAS_ABORTED_TASK;
2541 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302542 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302543 break;
2544 /* following cases are to do cases */
2545 case IO_UNDERFLOW:
2546 /* SATA Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08002547 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param);
Sakthivel Kf5860992013-04-17 16:37:02 +05302548 ts->resp = SAS_TASK_COMPLETE;
2549 ts->stat = SAS_DATA_UNDERRUN;
2550 ts->residual = param;
2551 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302552 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302553 break;
2554 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002555 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302556 ts->resp = SAS_TASK_UNDELIVERED;
2557 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302558 if (pm8001_dev)
2559 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302560 break;
2561 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002562 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302563 ts->resp = SAS_TASK_COMPLETE;
2564 ts->stat = SAS_INTERRUPTED;
Viswas G4a2efd42020-11-02 22:25:26 +05302565 if (pm8001_dev)
2566 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302567 break;
2568 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002569 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302570 ts->resp = SAS_TASK_COMPLETE;
2571 ts->stat = SAS_OPEN_REJECT;
2572 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302573 if (pm8001_dev)
2574 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302575 break;
2576 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002577 pm8001_dbg(pm8001_ha, IO,
2578 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302579 ts->resp = SAS_TASK_COMPLETE;
2580 ts->stat = SAS_OPEN_REJECT;
2581 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302582 if (pm8001_dev)
2583 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302584 break;
2585 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002586 pm8001_dbg(pm8001_ha, IO,
2587 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302588 ts->resp = SAS_TASK_COMPLETE;
2589 ts->stat = SAS_OPEN_REJECT;
2590 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302591 if (pm8001_dev)
2592 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302593 break;
2594 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002595 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302596 ts->resp = SAS_TASK_COMPLETE;
2597 ts->stat = SAS_OPEN_REJECT;
2598 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
Viswas G4a2efd42020-11-02 22:25:26 +05302599 if (pm8001_dev)
2600 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302601 break;
2602 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302603 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2604 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2605 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2606 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2607 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002608 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302609 ts->resp = SAS_TASK_COMPLETE;
2610 ts->stat = SAS_DEV_NO_RESPONSE;
2611 if (!t->uldd_task) {
2612 pm8001_handle_event(pm8001_ha,
2613 pm8001_dev,
2614 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2615 ts->resp = SAS_TASK_UNDELIVERED;
2616 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302617 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302618 return;
2619 }
2620 break;
2621 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002622 pm8001_dbg(pm8001_ha, IO,
2623 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302624 ts->resp = SAS_TASK_UNDELIVERED;
2625 ts->stat = SAS_OPEN_REJECT;
2626 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2627 if (!t->uldd_task) {
2628 pm8001_handle_event(pm8001_ha,
2629 pm8001_dev,
2630 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2631 ts->resp = SAS_TASK_UNDELIVERED;
2632 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302633 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302634 return;
2635 }
2636 break;
2637 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002638 pm8001_dbg(pm8001_ha, IO,
2639 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302640 ts->resp = SAS_TASK_COMPLETE;
2641 ts->stat = SAS_OPEN_REJECT;
2642 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302643 if (pm8001_dev)
2644 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302645 break;
2646 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002647 pm8001_dbg(pm8001_ha, IO,
2648 "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302649 ts->resp = SAS_TASK_COMPLETE;
2650 ts->stat = SAS_DEV_NO_RESPONSE;
2651 if (!t->uldd_task) {
2652 pm8001_handle_event(pm8001_ha,
2653 pm8001_dev,
2654 IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2655 ts->resp = SAS_TASK_UNDELIVERED;
2656 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302657 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302658 return;
2659 }
2660 break;
2661 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002662 pm8001_dbg(pm8001_ha, IO,
2663 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302664 ts->resp = SAS_TASK_COMPLETE;
2665 ts->stat = SAS_OPEN_REJECT;
2666 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302667 if (pm8001_dev)
2668 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302669 break;
2670 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002671 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302672 ts->resp = SAS_TASK_COMPLETE;
2673 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302674 if (pm8001_dev)
2675 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302676 break;
2677 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002678 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302679 ts->resp = SAS_TASK_COMPLETE;
2680 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302681 if (pm8001_dev)
2682 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302683 break;
2684 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002685 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302686 ts->resp = SAS_TASK_COMPLETE;
2687 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05302688 if (pm8001_dev)
2689 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302690 break;
2691 case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002692 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302693 ts->resp = SAS_TASK_UNDELIVERED;
2694 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302695 if (pm8001_dev)
2696 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302697 break;
2698 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002699 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302700 ts->resp = SAS_TASK_COMPLETE;
2701 ts->stat = SAS_DATA_UNDERRUN;
Viswas G4a2efd42020-11-02 22:25:26 +05302702 if (pm8001_dev)
2703 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302704 break;
2705 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002706 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302707 ts->resp = SAS_TASK_COMPLETE;
2708 ts->stat = SAS_OPEN_TO;
Viswas G4a2efd42020-11-02 22:25:26 +05302709 if (pm8001_dev)
2710 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302711 break;
2712 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002713 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302714 ts->resp = SAS_TASK_COMPLETE;
2715 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302716 if (pm8001_dev)
2717 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302718 break;
2719 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002720 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302721 ts->resp = SAS_TASK_COMPLETE;
2722 ts->stat = SAS_DEV_NO_RESPONSE;
2723 if (!t->uldd_task) {
2724 pm8001_handle_event(pm8001_ha, pm8001_dev,
2725 IO_DS_NON_OPERATIONAL);
2726 ts->resp = SAS_TASK_UNDELIVERED;
2727 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302728 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302729 return;
2730 }
2731 break;
2732 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002733 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302734 ts->resp = SAS_TASK_COMPLETE;
2735 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302736 if (pm8001_dev)
2737 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302738 break;
2739 case IO_DS_IN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002740 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302741 ts->resp = SAS_TASK_COMPLETE;
2742 ts->stat = SAS_DEV_NO_RESPONSE;
2743 if (!t->uldd_task) {
2744 pm8001_handle_event(pm8001_ha, pm8001_dev,
2745 IO_DS_IN_ERROR);
2746 ts->resp = SAS_TASK_UNDELIVERED;
2747 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302748 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302749 return;
2750 }
2751 break;
2752 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002753 pm8001_dbg(pm8001_ha, IO,
2754 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302755 ts->resp = SAS_TASK_COMPLETE;
2756 ts->stat = SAS_OPEN_REJECT;
2757 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302758 if (pm8001_dev)
2759 atomic_dec(&pm8001_dev->running_req);
Johannes Thumshirn50acde82015-08-17 15:52:32 +02002760 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302761 default:
Vishakha Channapattan4f608fb2021-01-09 18:08:48 +05302762 pm8001_dbg(pm8001_ha, DEVIO,
2763 "Unknown status device_id %u status 0x%x tag %d\n",
2764 pm8001_dev->device_id, status, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302765 /* not allowed case. Therefore, return failed status */
2766 ts->resp = SAS_TASK_COMPLETE;
2767 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302768 if (pm8001_dev)
2769 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302770 break;
2771 }
2772 spin_lock_irqsave(&t->task_state_lock, flags);
2773 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2774 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2775 t->task_state_flags |= SAS_TASK_STATE_DONE;
2776 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2777 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002778 pm8001_dbg(pm8001_ha, FAIL,
2779 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2780 t, status, ts->resp, ts->stat);
peter changce21c632019-11-14 15:38:58 +05302781 if (t->slow_task)
2782 complete(&t->slow_task->completion);
Sakthivel Kf5860992013-04-17 16:37:02 +05302783 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302784 } else {
Sakthivel Kf5860992013-04-17 16:37:02 +05302785 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302786 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302787 }
2788}
2789
2790/*See the comments for mpi_ssp_completion */
2791static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
2792{
2793 struct sas_task *t;
2794 struct task_status_struct *ts;
2795 struct pm8001_ccb_info *ccb;
2796 struct pm8001_device *pm8001_dev;
2797 struct sata_event_resp *psataPayload =
2798 (struct sata_event_resp *)(piomb + 4);
2799 u32 event = le32_to_cpu(psataPayload->event);
2800 u32 tag = le32_to_cpu(psataPayload->tag);
2801 u32 port_id = le32_to_cpu(psataPayload->port_id);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302802 u32 dev_id = le32_to_cpu(psataPayload->device_id);
2803 unsigned long flags;
Sakthivel Kf5860992013-04-17 16:37:02 +05302804
2805 ccb = &pm8001_ha->ccb_info[tag];
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302806
2807 if (ccb) {
2808 t = ccb->task;
2809 pm8001_dev = ccb->device;
2810 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002811 pm8001_dbg(pm8001_ha, FAIL, "No CCB !!!. returning\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302812 return;
2813 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302814 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002815 pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302816
2817 /* Check if this is NCQ error */
2818 if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2819 /* find device using device id */
2820 pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2821 /* send read log extension */
2822 if (pm8001_dev)
2823 pm80xx_send_read_log(pm8001_ha, pm8001_dev);
Sakthivel Kf5860992013-04-17 16:37:02 +05302824 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302825 }
2826
2827 if (unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002828 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302829 return;
2830 }
2831
Sakthivel Kf5860992013-04-17 16:37:02 +05302832 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002833 pm8001_dbg(pm8001_ha, IOERR, "port_id:0x%x, tag:0x%x, event:0x%x\n",
2834 port_id, tag, event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302835 switch (event) {
2836 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002837 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302838 ts->resp = SAS_TASK_COMPLETE;
2839 ts->stat = SAS_DATA_OVERRUN;
2840 ts->residual = 0;
2841 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302842 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302843 break;
2844 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002845 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302846 ts->resp = SAS_TASK_COMPLETE;
2847 ts->stat = SAS_INTERRUPTED;
2848 break;
2849 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002850 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302851 ts->resp = SAS_TASK_COMPLETE;
2852 ts->stat = SAS_OPEN_REJECT;
2853 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2854 break;
2855 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002856 pm8001_dbg(pm8001_ha, IO,
2857 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302858 ts->resp = SAS_TASK_COMPLETE;
2859 ts->stat = SAS_OPEN_REJECT;
2860 ts->open_rej_reason = SAS_OREJ_EPROTO;
2861 break;
2862 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002863 pm8001_dbg(pm8001_ha, IO,
2864 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302865 ts->resp = SAS_TASK_COMPLETE;
2866 ts->stat = SAS_OPEN_REJECT;
2867 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2868 break;
2869 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002870 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302871 ts->resp = SAS_TASK_COMPLETE;
2872 ts->stat = SAS_OPEN_REJECT;
2873 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2874 break;
2875 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302876 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2877 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2878 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2879 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2880 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002881 pm8001_dbg(pm8001_ha, FAIL,
2882 "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302883 ts->resp = SAS_TASK_UNDELIVERED;
2884 ts->stat = SAS_DEV_NO_RESPONSE;
2885 if (!t->uldd_task) {
2886 pm8001_handle_event(pm8001_ha,
2887 pm8001_dev,
2888 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2889 ts->resp = SAS_TASK_COMPLETE;
2890 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302891 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302892 return;
2893 }
2894 break;
2895 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002896 pm8001_dbg(pm8001_ha, IO,
2897 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302898 ts->resp = SAS_TASK_UNDELIVERED;
2899 ts->stat = SAS_OPEN_REJECT;
2900 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2901 break;
2902 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002903 pm8001_dbg(pm8001_ha, IO,
2904 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302905 ts->resp = SAS_TASK_COMPLETE;
2906 ts->stat = SAS_OPEN_REJECT;
2907 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2908 break;
2909 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002910 pm8001_dbg(pm8001_ha, IO,
2911 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302912 ts->resp = SAS_TASK_COMPLETE;
2913 ts->stat = SAS_OPEN_REJECT;
2914 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2915 break;
2916 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002917 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302918 ts->resp = SAS_TASK_COMPLETE;
2919 ts->stat = SAS_NAK_R_ERR;
2920 break;
2921 case IO_XFER_ERROR_PEER_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002922 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302923 ts->resp = SAS_TASK_COMPLETE;
2924 ts->stat = SAS_NAK_R_ERR;
2925 break;
2926 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002927 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302928 ts->resp = SAS_TASK_COMPLETE;
2929 ts->stat = SAS_DATA_UNDERRUN;
2930 break;
2931 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002932 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302933 ts->resp = SAS_TASK_COMPLETE;
2934 ts->stat = SAS_OPEN_TO;
2935 break;
2936 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002937 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302938 ts->resp = SAS_TASK_COMPLETE;
2939 ts->stat = SAS_OPEN_TO;
2940 break;
2941 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002942 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302943 ts->resp = SAS_TASK_COMPLETE;
2944 ts->stat = SAS_OPEN_TO;
2945 break;
2946 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002947 pm8001_dbg(pm8001_ha, IO,
2948 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302949 ts->resp = SAS_TASK_COMPLETE;
2950 ts->stat = SAS_OPEN_TO;
2951 break;
2952 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002953 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302954 ts->resp = SAS_TASK_COMPLETE;
2955 ts->stat = SAS_OPEN_TO;
2956 break;
2957 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002958 pm8001_dbg(pm8001_ha, IO,
2959 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302960 ts->resp = SAS_TASK_COMPLETE;
2961 ts->stat = SAS_OPEN_TO;
2962 break;
2963 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002964 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302965 break;
2966 case IO_XFER_PIO_SETUP_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002967 pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302968 ts->resp = SAS_TASK_COMPLETE;
2969 ts->stat = SAS_OPEN_TO;
2970 break;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302971 case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002972 pm8001_dbg(pm8001_ha, FAIL,
2973 "IO_XFR_ERROR_INTERNAL_CRC_ERROR\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302974 /* TBC: used default set values */
2975 ts->resp = SAS_TASK_COMPLETE;
2976 ts->stat = SAS_OPEN_TO;
2977 break;
2978 case IO_XFER_DMA_ACTIVATE_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002979 pm8001_dbg(pm8001_ha, FAIL, "IO_XFR_DMA_ACTIVATE_TIMEOUT\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302980 /* TBC: used default set values */
2981 ts->resp = SAS_TASK_COMPLETE;
2982 ts->stat = SAS_OPEN_TO;
2983 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302984 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002985 pm8001_dbg(pm8001_ha, IO, "Unknown status 0x%x\n", event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302986 /* not allowed case. Therefore, return failed status */
2987 ts->resp = SAS_TASK_COMPLETE;
2988 ts->stat = SAS_OPEN_TO;
2989 break;
2990 }
2991 spin_lock_irqsave(&t->task_state_lock, flags);
2992 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2993 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2994 t->task_state_flags |= SAS_TASK_STATE_DONE;
2995 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2996 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002997 pm8001_dbg(pm8001_ha, FAIL,
2998 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2999 t, event, ts->resp, ts->stat);
Sakthivel Kf5860992013-04-17 16:37:02 +05303000 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05303001 } else {
Sakthivel Kf5860992013-04-17 16:37:02 +05303002 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05303003 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05303004 }
3005}
3006
3007/*See the comments for mpi_ssp_completion */
3008static void
3009mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
3010{
3011 u32 param, i;
3012 struct sas_task *t;
3013 struct pm8001_ccb_info *ccb;
3014 unsigned long flags;
3015 u32 status;
3016 u32 tag;
3017 struct smp_completion_resp *psmpPayload;
3018 struct task_status_struct *ts;
3019 struct pm8001_device *pm8001_dev;
3020 char *pdma_respaddr = NULL;
3021
3022 psmpPayload = (struct smp_completion_resp *)(piomb + 4);
3023 status = le32_to_cpu(psmpPayload->status);
3024 tag = le32_to_cpu(psmpPayload->tag);
3025
3026 ccb = &pm8001_ha->ccb_info[tag];
3027 param = le32_to_cpu(psmpPayload->param);
3028 t = ccb->task;
3029 ts = &t->task_status;
3030 pm8001_dev = ccb->device;
3031 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08003032 pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303033 if (unlikely(!t || !t->lldd_task || !t->dev))
3034 return;
3035
Joe Perches1b5d2792020-11-20 15:16:09 -08003036 pm8001_dbg(pm8001_ha, DEV, "tag::0x%x status::0x%x\n", tag, status);
peter chang73706722019-11-14 15:39:02 +05303037
Sakthivel Kf5860992013-04-17 16:37:02 +05303038 switch (status) {
3039
3040 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003041 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303042 ts->resp = SAS_TASK_COMPLETE;
3043 ts->stat = SAM_STAT_GOOD;
3044 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303045 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05303046 if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003047 pm8001_dbg(pm8001_ha, IO,
3048 "DIRECT RESPONSE Length:%d\n",
3049 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05303050 pdma_respaddr = (char *)(phys_to_virt(cpu_to_le64
3051 ((u64)sg_dma_address
3052 (&t->smp_task.smp_resp))));
3053 for (i = 0; i < param; i++) {
3054 *(pdma_respaddr+i) = psmpPayload->_r_a[i];
Joe Perches1b5d2792020-11-20 15:16:09 -08003055 pm8001_dbg(pm8001_ha, IO,
3056 "SMP Byte%d DMA data 0x%x psmp 0x%x\n",
3057 i, *(pdma_respaddr + i),
3058 psmpPayload->_r_a[i]);
Sakthivel Kf5860992013-04-17 16:37:02 +05303059 }
3060 }
3061 break;
3062 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003063 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303064 ts->resp = SAS_TASK_COMPLETE;
3065 ts->stat = SAS_ABORTED_TASK;
3066 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303067 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05303068 break;
3069 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08003070 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303071 ts->resp = SAS_TASK_COMPLETE;
3072 ts->stat = SAS_DATA_OVERRUN;
3073 ts->residual = 0;
3074 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303075 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05303076 break;
3077 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003078 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303079 ts->resp = SAS_TASK_COMPLETE;
3080 ts->stat = SAS_PHY_DOWN;
3081 break;
3082 case IO_ERROR_HW_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003083 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303084 ts->resp = SAS_TASK_COMPLETE;
3085 ts->stat = SAM_STAT_BUSY;
3086 break;
3087 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003088 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303089 ts->resp = SAS_TASK_COMPLETE;
3090 ts->stat = SAM_STAT_BUSY;
3091 break;
3092 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003093 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303094 ts->resp = SAS_TASK_COMPLETE;
3095 ts->stat = SAM_STAT_BUSY;
3096 break;
3097 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003098 pm8001_dbg(pm8001_ha, IO,
3099 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303100 ts->resp = SAS_TASK_COMPLETE;
3101 ts->stat = SAS_OPEN_REJECT;
3102 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3103 break;
3104 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003105 pm8001_dbg(pm8001_ha, IO,
3106 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303107 ts->resp = SAS_TASK_COMPLETE;
3108 ts->stat = SAS_OPEN_REJECT;
3109 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3110 break;
3111 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003112 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303113 ts->resp = SAS_TASK_COMPLETE;
3114 ts->stat = SAS_OPEN_REJECT;
3115 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
3116 break;
3117 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05303118 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
3119 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
3120 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
3121 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
3122 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003123 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303124 ts->resp = SAS_TASK_COMPLETE;
3125 ts->stat = SAS_OPEN_REJECT;
3126 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3127 pm8001_handle_event(pm8001_ha,
3128 pm8001_dev,
3129 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
3130 break;
3131 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003132 pm8001_dbg(pm8001_ha, IO,
3133 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303134 ts->resp = SAS_TASK_COMPLETE;
3135 ts->stat = SAS_OPEN_REJECT;
3136 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
3137 break;
3138 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003139 pm8001_dbg(pm8001_ha, IO,
3140 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303141 ts->resp = SAS_TASK_COMPLETE;
3142 ts->stat = SAS_OPEN_REJECT;
3143 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
3144 break;
3145 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003146 pm8001_dbg(pm8001_ha, IO,
3147 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303148 ts->resp = SAS_TASK_COMPLETE;
3149 ts->stat = SAS_OPEN_REJECT;
3150 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
3151 break;
3152 case IO_XFER_ERROR_RX_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08003153 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303154 ts->resp = SAS_TASK_COMPLETE;
3155 ts->stat = SAS_DEV_NO_RESPONSE;
3156 break;
3157 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003158 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303159 ts->resp = SAS_TASK_COMPLETE;
3160 ts->stat = SAS_OPEN_REJECT;
3161 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3162 break;
3163 case IO_ERROR_INTERNAL_SMP_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003164 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303165 ts->resp = SAS_TASK_COMPLETE;
3166 ts->stat = SAS_QUEUE_FULL;
3167 break;
3168 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003169 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303170 ts->resp = SAS_TASK_COMPLETE;
3171 ts->stat = SAS_OPEN_REJECT;
3172 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3173 break;
3174 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003175 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303176 ts->resp = SAS_TASK_COMPLETE;
3177 ts->stat = SAS_DEV_NO_RESPONSE;
3178 break;
3179 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003180 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303181 ts->resp = SAS_TASK_COMPLETE;
3182 ts->stat = SAS_OPEN_REJECT;
3183 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3184 break;
3185 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003186 pm8001_dbg(pm8001_ha, IO,
3187 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303188 ts->resp = SAS_TASK_COMPLETE;
3189 ts->stat = SAS_OPEN_REJECT;
3190 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3191 break;
3192 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003193 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303194 ts->resp = SAS_TASK_COMPLETE;
3195 ts->stat = SAS_DEV_NO_RESPONSE;
3196 /* not allowed case. Therefore, return failed status */
3197 break;
3198 }
3199 spin_lock_irqsave(&t->task_state_lock, flags);
3200 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3201 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3202 t->task_state_flags |= SAS_TASK_STATE_DONE;
3203 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3204 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08003205 pm8001_dbg(pm8001_ha, FAIL,
3206 "task 0x%p done with io_status 0x%x resp 0x%xstat 0x%x but aborted by upper layer!\n",
3207 t, status, ts->resp, ts->stat);
Sakthivel Kf5860992013-04-17 16:37:02 +05303208 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3209 } else {
3210 spin_unlock_irqrestore(&t->task_state_lock, flags);
3211 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3212 mb();/* in order to force CPU ordering */
3213 t->task_done(t);
3214 }
3215}
3216
3217/**
3218 * pm80xx_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
3219 * @pm8001_ha: our hba card information
3220 * @Qnum: the outbound queue message number.
3221 * @SEA: source of event to ack
3222 * @port_id: port id.
3223 * @phyId: phy id.
3224 * @param0: parameter 0.
3225 * @param1: parameter 1.
3226 */
3227static void pm80xx_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3228 u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3229{
3230 struct hw_event_ack_req payload;
3231 u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3232
3233 struct inbound_queue_table *circularQ;
3234
3235 memset((u8 *)&payload, 0, sizeof(payload));
3236 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
3237 payload.tag = cpu_to_le32(1);
3238 payload.phyid_sea_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3239 ((phyId & 0xFF) << 24) | (port_id & 0xFF));
3240 payload.param0 = cpu_to_le32(param0);
3241 payload.param1 = cpu_to_le32(param1);
peter chang91a43fa2019-11-14 15:39:05 +05303242 pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
3243 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303244}
3245
3246static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3247 u32 phyId, u32 phy_op);
3248
Viswas G8414cd82015-08-11 15:06:30 +05303249static void hw_event_port_recover(struct pm8001_hba_info *pm8001_ha,
3250 void *piomb)
3251{
3252 struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4);
3253 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3254 u8 phy_id = (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3255 u32 lr_status_evt_portid =
3256 le32_to_cpu(pPayload->lr_status_evt_portid);
3257 u8 deviceType = pPayload->sas_identify.dev_type;
3258 u8 link_rate = (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3259 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3260 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3261 struct pm8001_port *port = &pm8001_ha->port[port_id];
3262
3263 if (deviceType == SAS_END_DEVICE) {
3264 pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
3265 PHY_NOTIFY_ENABLE_SPINUP);
3266 }
3267
3268 port->wide_port_phymap |= (1U << phy_id);
3269 pm8001_get_lrate_mode(phy, link_rate);
3270 phy->sas_phy.oob_mode = SAS_OOB_MODE;
3271 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
3272 phy->phy_attached = 1;
3273}
3274
Sakthivel Kf5860992013-04-17 16:37:02 +05303275/**
3276 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
3277 * @pm8001_ha: our hba card information
3278 * @piomb: IO message buffer
3279 */
3280static void
3281hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3282{
3283 struct hw_event_resp *pPayload =
3284 (struct hw_event_resp *)(piomb + 4);
3285 u32 lr_status_evt_portid =
3286 le32_to_cpu(pPayload->lr_status_evt_portid);
3287 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3288
3289 u8 link_rate =
3290 (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3291 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3292 u8 phy_id =
3293 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3294 u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3295
3296 struct pm8001_port *port = &pm8001_ha->port[port_id];
Sakthivel Kf5860992013-04-17 16:37:02 +05303297 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3298 unsigned long flags;
3299 u8 deviceType = pPayload->sas_identify.dev_type;
3300 port->port_state = portstate;
Viswas G8414cd82015-08-11 15:06:30 +05303301 port->wide_port_phymap |= (1U << phy_id);
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303302 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
Joe Perches1b5d2792020-11-20 15:16:09 -08003303 pm8001_dbg(pm8001_ha, MSG,
3304 "portid:%d; phyid:%d; linkrate:%d; portstate:%x; devicetype:%x\n",
3305 port_id, phy_id, link_rate, portstate, deviceType);
Sakthivel Kf5860992013-04-17 16:37:02 +05303306
3307 switch (deviceType) {
3308 case SAS_PHY_UNUSED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003309 pm8001_dbg(pm8001_ha, MSG, "device type no device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303310 break;
3311 case SAS_END_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003312 pm8001_dbg(pm8001_ha, MSG, "end device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303313 pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
3314 PHY_NOTIFY_ENABLE_SPINUP);
3315 port->port_attached = 1;
3316 pm8001_get_lrate_mode(phy, link_rate);
3317 break;
3318 case SAS_EDGE_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003319 pm8001_dbg(pm8001_ha, MSG, "expander device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303320 port->port_attached = 1;
3321 pm8001_get_lrate_mode(phy, link_rate);
3322 break;
3323 case SAS_FANOUT_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003324 pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303325 port->port_attached = 1;
3326 pm8001_get_lrate_mode(phy, link_rate);
3327 break;
3328 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003329 pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n",
3330 deviceType);
Sakthivel Kf5860992013-04-17 16:37:02 +05303331 break;
3332 }
3333 phy->phy_type |= PORT_TYPE_SAS;
3334 phy->identify.device_type = deviceType;
3335 phy->phy_attached = 1;
3336 if (phy->identify.device_type == SAS_END_DEVICE)
3337 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
3338 else if (phy->identify.device_type != SAS_PHY_UNUSED)
3339 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3340 phy->sas_phy.oob_mode = SAS_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003341 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303342 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3343 memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3344 sizeof(struct sas_identify_frame)-4);
3345 phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3346 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3347 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3348 if (pm8001_ha->flags == PM8001F_RUN_TIME)
Ahmed S. Darwish4ba9e512020-11-26 14:29:39 +01003349 mdelay(200); /* delay a moment to wait for disk to spin up */
Sakthivel Kf5860992013-04-17 16:37:02 +05303350 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3351}
3352
3353/**
3354 * hw_event_sata_phy_up -FW tells me a SATA phy up event.
3355 * @pm8001_ha: our hba card information
3356 * @piomb: IO message buffer
3357 */
3358static void
3359hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3360{
3361 struct hw_event_resp *pPayload =
3362 (struct hw_event_resp *)(piomb + 4);
3363 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3364 u32 lr_status_evt_portid =
3365 le32_to_cpu(pPayload->lr_status_evt_portid);
3366 u8 link_rate =
3367 (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3368 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3369 u8 phy_id =
3370 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3371
3372 u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3373
3374 struct pm8001_port *port = &pm8001_ha->port[port_id];
Sakthivel Kf5860992013-04-17 16:37:02 +05303375 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3376 unsigned long flags;
Joe Perches1b5d2792020-11-20 15:16:09 -08003377 pm8001_dbg(pm8001_ha, DEVIO,
3378 "port id %d, phy id %d link_rate %d portstate 0x%x\n",
3379 port_id, phy_id, link_rate, portstate);
Sakthivel Kf5860992013-04-17 16:37:02 +05303380
3381 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303382 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
Sakthivel Kf5860992013-04-17 16:37:02 +05303383 port->port_attached = 1;
3384 pm8001_get_lrate_mode(phy, link_rate);
3385 phy->phy_type |= PORT_TYPE_SATA;
3386 phy->phy_attached = 1;
3387 phy->sas_phy.oob_mode = SATA_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003388 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303389 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3390 memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3391 sizeof(struct dev_to_host_fis));
3392 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3393 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
James Bottomleyaa9f8322013-05-07 14:44:06 -07003394 phy->identify.device_type = SAS_SATA_DEV;
Sakthivel Kf5860992013-04-17 16:37:02 +05303395 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3396 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3397 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3398}
3399
3400/**
3401 * hw_event_phy_down -we should notify the libsas the phy is down.
3402 * @pm8001_ha: our hba card information
3403 * @piomb: IO message buffer
3404 */
3405static void
3406hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3407{
3408 struct hw_event_resp *pPayload =
3409 (struct hw_event_resp *)(piomb + 4);
3410
3411 u32 lr_status_evt_portid =
3412 le32_to_cpu(pPayload->lr_status_evt_portid);
3413 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3414 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3415 u8 phy_id =
3416 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3417 u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3418
3419 struct pm8001_port *port = &pm8001_ha->port[port_id];
3420 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
Viswas G869ddbd2017-10-18 11:39:13 +05303421 u32 port_sata = (phy->phy_type & PORT_TYPE_SATA);
Sakthivel Kf5860992013-04-17 16:37:02 +05303422 port->port_state = portstate;
Sakthivel Kf5860992013-04-17 16:37:02 +05303423 phy->identify.device_type = 0;
3424 phy->phy_attached = 0;
Sakthivel Kf5860992013-04-17 16:37:02 +05303425 switch (portstate) {
3426 case PORT_VALID:
3427 break;
3428 case PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003429 pm8001_dbg(pm8001_ha, MSG, " PortInvalid portID %d\n",
3430 port_id);
3431 pm8001_dbg(pm8001_ha, MSG,
3432 " Last phy Down and port invalid\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303433 if (port_sata) {
Viswas G8414cd82015-08-11 15:06:30 +05303434 phy->phy_type = 0;
3435 port->port_attached = 0;
3436 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3437 port_id, phy_id, 0, 0);
3438 }
3439 sas_phy_disconnected(&phy->sas_phy);
Sakthivel Kf5860992013-04-17 16:37:02 +05303440 break;
3441 case PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003442 pm8001_dbg(pm8001_ha, MSG, " Port In Reset portID %d\n",
3443 port_id);
Sakthivel Kf5860992013-04-17 16:37:02 +05303444 break;
3445 case PORT_NOT_ESTABLISHED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003446 pm8001_dbg(pm8001_ha, MSG,
3447 " Phy Down and PORT_NOT_ESTABLISHED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303448 port->port_attached = 0;
3449 break;
3450 case PORT_LOSTCOMM:
Joe Perches1b5d2792020-11-20 15:16:09 -08003451 pm8001_dbg(pm8001_ha, MSG, " Phy Down and PORT_LOSTCOMM\n");
3452 pm8001_dbg(pm8001_ha, MSG,
3453 " Last phy Down and port invalid\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303454 if (port_sata) {
Viswas G8414cd82015-08-11 15:06:30 +05303455 port->port_attached = 0;
3456 phy->phy_type = 0;
3457 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3458 port_id, phy_id, 0, 0);
3459 }
3460 sas_phy_disconnected(&phy->sas_phy);
Sakthivel Kf5860992013-04-17 16:37:02 +05303461 break;
3462 default:
3463 port->port_attached = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08003464 pm8001_dbg(pm8001_ha, DEVIO,
3465 " Phy Down and(default) = 0x%x\n",
3466 portstate);
Sakthivel Kf5860992013-04-17 16:37:02 +05303467 break;
3468
3469 }
John Garry121181f2021-01-18 11:09:38 +01003470 if (port_sata && (portstate != PORT_IN_RESET))
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003471 sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL,
3472 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303473}
3474
3475static int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3476{
3477 struct phy_start_resp *pPayload =
3478 (struct phy_start_resp *)(piomb + 4);
3479 u32 status =
3480 le32_to_cpu(pPayload->status);
3481 u32 phy_id =
3482 le32_to_cpu(pPayload->phyid);
3483 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3484
Joe Perches1b5d2792020-11-20 15:16:09 -08003485 pm8001_dbg(pm8001_ha, INIT,
3486 "phy start resp status:0x%x, phyid:0x%x\n",
3487 status, phy_id);
Sakthivel Kf5860992013-04-17 16:37:02 +05303488 if (status == 0) {
Deepak Ukeycd135752018-09-11 14:18:02 +05303489 phy->phy_state = PHY_LINK_DOWN;
3490 if (pm8001_ha->flags == PM8001F_RUN_TIME &&
peter change7039772019-11-14 15:38:59 +05303491 phy->enable_completion != NULL) {
Sakthivel Kf5860992013-04-17 16:37:02 +05303492 complete(phy->enable_completion);
peter change7039772019-11-14 15:38:59 +05303493 phy->enable_completion = NULL;
3494 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303495 }
3496 return 0;
3497
3498}
3499
3500/**
3501 * mpi_thermal_hw_event -The hw event has come.
3502 * @pm8001_ha: our hba card information
3503 * @piomb: IO message buffer
3504 */
3505static int mpi_thermal_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3506{
3507 struct thermal_hw_event *pPayload =
3508 (struct thermal_hw_event *)(piomb + 4);
3509
3510 u32 thermal_event = le32_to_cpu(pPayload->thermal_event);
3511 u32 rht_lht = le32_to_cpu(pPayload->rht_lht);
3512
3513 if (thermal_event & 0x40) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003514 pm8001_dbg(pm8001_ha, IO,
3515 "Thermal Event: Local high temperature violated!\n");
3516 pm8001_dbg(pm8001_ha, IO,
3517 "Thermal Event: Measured local high temperature %d\n",
3518 ((rht_lht & 0xFF00) >> 8));
Sakthivel Kf5860992013-04-17 16:37:02 +05303519 }
3520 if (thermal_event & 0x10) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003521 pm8001_dbg(pm8001_ha, IO,
3522 "Thermal Event: Remote high temperature violated!\n");
3523 pm8001_dbg(pm8001_ha, IO,
3524 "Thermal Event: Measured remote high temperature %d\n",
3525 ((rht_lht & 0xFF000000) >> 24));
Sakthivel Kf5860992013-04-17 16:37:02 +05303526 }
3527 return 0;
3528}
3529
3530/**
3531 * mpi_hw_event -The hw event has come.
3532 * @pm8001_ha: our hba card information
3533 * @piomb: IO message buffer
3534 */
3535static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3536{
Viswas G8414cd82015-08-11 15:06:30 +05303537 unsigned long flags, i;
Sakthivel Kf5860992013-04-17 16:37:02 +05303538 struct hw_event_resp *pPayload =
3539 (struct hw_event_resp *)(piomb + 4);
3540 u32 lr_status_evt_portid =
3541 le32_to_cpu(pPayload->lr_status_evt_portid);
3542 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3543 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3544 u8 phy_id =
3545 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3546 u16 eventType =
3547 (u16)((lr_status_evt_portid & 0x00FFFF00) >> 8);
3548 u8 status =
3549 (u8)((lr_status_evt_portid & 0x0F000000) >> 24);
Sakthivel Kf5860992013-04-17 16:37:02 +05303550 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3551 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
Viswas G8414cd82015-08-11 15:06:30 +05303552 struct pm8001_port *port = &pm8001_ha->port[port_id];
Sakthivel Kf5860992013-04-17 16:37:02 +05303553 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
Joe Perches1b5d2792020-11-20 15:16:09 -08003554 pm8001_dbg(pm8001_ha, DEV,
3555 "portid:%d phyid:%d event:0x%x status:0x%x\n",
3556 port_id, phy_id, eventType, status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303557
3558 switch (eventType) {
3559
3560 case HW_EVENT_SAS_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003561 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303562 hw_event_sas_phy_up(pm8001_ha, piomb);
3563 break;
3564 case HW_EVENT_SATA_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003565 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_PHY_UP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303566 hw_event_sata_phy_up(pm8001_ha, piomb);
3567 break;
3568 case HW_EVENT_SATA_SPINUP_HOLD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003569 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_SPINUP_HOLD\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003570 sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003571 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303572 break;
3573 case HW_EVENT_PHY_DOWN:
Joe Perches1b5d2792020-11-20 15:16:09 -08003574 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_DOWN\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303575 hw_event_phy_down(pm8001_ha, piomb);
3576 if (pm8001_ha->reset_in_progress) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003577 pm8001_dbg(pm8001_ha, MSG, "Reset in progress\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303578 return 0;
3579 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303580 phy->phy_attached = 0;
Deepak Ukeycd135752018-09-11 14:18:02 +05303581 phy->phy_state = PHY_LINK_DISABLE;
Sakthivel Kf5860992013-04-17 16:37:02 +05303582 break;
3583 case HW_EVENT_PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003584 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_INVALID\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303585 sas_phy_disconnected(sas_phy);
3586 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003587 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003588 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303589 break;
3590 /* the broadcast change primitive received, tell the LIBSAS this event
3591 to revalidate the sas domain*/
3592 case HW_EVENT_BROADCAST_CHANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003593 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303594 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3595 port_id, phy_id, 1, 0);
3596 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3597 sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3598 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003599 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003600 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303601 break;
3602 case HW_EVENT_PHY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003603 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303604 sas_phy_disconnected(&phy->sas_phy);
3605 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003606 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR, GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303607 break;
3608 case HW_EVENT_BROADCAST_EXP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003609 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303610 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3611 sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3612 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003613 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003614 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303615 break;
3616 case HW_EVENT_LINK_ERR_INVALID_DWORD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003617 pm8001_dbg(pm8001_ha, MSG,
3618 "HW_EVENT_LINK_ERR_INVALID_DWORD\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303619 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3620 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303621 break;
3622 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003623 pm8001_dbg(pm8001_ha, MSG,
3624 "HW_EVENT_LINK_ERR_DISPARITY_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303625 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3626 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3627 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303628 break;
3629 case HW_EVENT_LINK_ERR_CODE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003630 pm8001_dbg(pm8001_ha, MSG,
3631 "HW_EVENT_LINK_ERR_CODE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303632 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3633 HW_EVENT_LINK_ERR_CODE_VIOLATION,
3634 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303635 break;
3636 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08003637 pm8001_dbg(pm8001_ha, MSG,
3638 "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303639 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3640 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3641 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303642 break;
3643 case HW_EVENT_MALFUNCTION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003644 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_MALFUNCTION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303645 break;
3646 case HW_EVENT_BROADCAST_SES:
Joe Perches1b5d2792020-11-20 15:16:09 -08003647 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303648 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3649 sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3650 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003651 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003652 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303653 break;
3654 case HW_EVENT_INBOUND_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003655 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_INBOUND_CRC_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303656 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3657 HW_EVENT_INBOUND_CRC_ERROR,
3658 port_id, phy_id, 0, 0);
3659 break;
3660 case HW_EVENT_HARD_RESET_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003661 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_HARD_RESET_RECEIVED\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003662 sas_notify_port_event(sas_phy, PORTE_HARD_RESET, GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303663 break;
3664 case HW_EVENT_ID_FRAME_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003665 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_ID_FRAME_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303666 sas_phy_disconnected(sas_phy);
3667 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003668 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003669 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303670 break;
3671 case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003672 pm8001_dbg(pm8001_ha, MSG,
3673 "HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303674 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3675 HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3676 port_id, phy_id, 0, 0);
3677 sas_phy_disconnected(sas_phy);
3678 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003679 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003680 GFP_ATOMIC);
Sakthivel Kf5860992013-04-17 16:37:02 +05303681 break;
3682 case HW_EVENT_PORT_RESET_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003683 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_TIMER_TMO\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303684 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3685 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303686 sas_phy_disconnected(sas_phy);
3687 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003688 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003689 GFP_ATOMIC);
Viswas G869ddbd2017-10-18 11:39:13 +05303690 if (pm8001_ha->phy[phy_id].reset_completion) {
3691 pm8001_ha->phy[phy_id].port_reset_status =
3692 PORT_RESET_TMO;
3693 complete(pm8001_ha->phy[phy_id].reset_completion);
3694 pm8001_ha->phy[phy_id].reset_completion = NULL;
3695 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303696 break;
3697 case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003698 pm8001_dbg(pm8001_ha, MSG,
3699 "HW_EVENT_PORT_RECOVERY_TIMER_TMO\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05303700 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3701 HW_EVENT_PORT_RECOVERY_TIMER_TMO,
3702 port_id, phy_id, 0, 0);
Viswas G8414cd82015-08-11 15:06:30 +05303703 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
3704 if (port->wide_port_phymap & (1 << i)) {
3705 phy = &pm8001_ha->phy[i];
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003706 sas_notify_phy_event(&phy->sas_phy,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003707 PHYE_LOSS_OF_SIGNAL, GFP_ATOMIC);
Viswas G8414cd82015-08-11 15:06:30 +05303708 port->wide_port_phymap &= ~(1 << i);
3709 }
3710 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303711 break;
3712 case HW_EVENT_PORT_RECOVER:
Joe Perches1b5d2792020-11-20 15:16:09 -08003713 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RECOVER\n");
Viswas G8414cd82015-08-11 15:06:30 +05303714 hw_event_port_recover(pm8001_ha, piomb);
Sakthivel Kf5860992013-04-17 16:37:02 +05303715 break;
3716 case HW_EVENT_PORT_RESET_COMPLETE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003717 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_COMPLETE\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303718 if (pm8001_ha->phy[phy_id].reset_completion) {
3719 pm8001_ha->phy[phy_id].port_reset_status =
3720 PORT_RESET_SUCCESS;
3721 complete(pm8001_ha->phy[phy_id].reset_completion);
3722 pm8001_ha->phy[phy_id].reset_completion = NULL;
3723 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303724 break;
3725 case EVENT_BROADCAST_ASYNCH_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003726 pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303727 break;
3728 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003729 pm8001_dbg(pm8001_ha, DEVIO, "Unknown event type 0x%x\n",
3730 eventType);
Sakthivel Kf5860992013-04-17 16:37:02 +05303731 break;
3732 }
3733 return 0;
3734}
3735
3736/**
3737 * mpi_phy_stop_resp - SPCv specific
3738 * @pm8001_ha: our hba card information
3739 * @piomb: IO message buffer
3740 */
3741static int mpi_phy_stop_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3742{
3743 struct phy_stop_resp *pPayload =
3744 (struct phy_stop_resp *)(piomb + 4);
3745 u32 status =
3746 le32_to_cpu(pPayload->status);
3747 u32 phyid =
Deepak Ukeycd135752018-09-11 14:18:02 +05303748 le32_to_cpu(pPayload->phyid) & 0xFF;
Sakthivel Kf5860992013-04-17 16:37:02 +05303749 struct pm8001_phy *phy = &pm8001_ha->phy[phyid];
Joe Perches1b5d2792020-11-20 15:16:09 -08003750 pm8001_dbg(pm8001_ha, MSG, "phy:0x%x status:0x%x\n",
3751 phyid, status);
Deepak Ukeycd135752018-09-11 14:18:02 +05303752 if (status == PHY_STOP_SUCCESS ||
3753 status == PHY_STOP_ERR_DEVICE_ATTACHED)
3754 phy->phy_state = PHY_LINK_DISABLE;
Sakthivel Kf5860992013-04-17 16:37:02 +05303755 return 0;
3756}
3757
3758/**
3759 * mpi_set_controller_config_resp - SPCv specific
3760 * @pm8001_ha: our hba card information
3761 * @piomb: IO message buffer
3762 */
3763static int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3764 void *piomb)
3765{
3766 struct set_ctrl_cfg_resp *pPayload =
3767 (struct set_ctrl_cfg_resp *)(piomb + 4);
3768 u32 status = le32_to_cpu(pPayload->status);
3769 u32 err_qlfr_pgcd = le32_to_cpu(pPayload->err_qlfr_pgcd);
3770
Joe Perches1b5d2792020-11-20 15:16:09 -08003771 pm8001_dbg(pm8001_ha, MSG,
3772 "SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
3773 status, err_qlfr_pgcd);
Sakthivel Kf5860992013-04-17 16:37:02 +05303774
3775 return 0;
3776}
3777
3778/**
3779 * mpi_get_controller_config_resp - SPCv specific
3780 * @pm8001_ha: our hba card information
3781 * @piomb: IO message buffer
3782 */
3783static int mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3784 void *piomb)
3785{
Joe Perches1b5d2792020-11-20 15:16:09 -08003786 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303787
3788 return 0;
3789}
3790
3791/**
3792 * mpi_get_phy_profile_resp - SPCv specific
3793 * @pm8001_ha: our hba card information
3794 * @piomb: IO message buffer
3795 */
3796static int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3797 void *piomb)
3798{
Joe Perches1b5d2792020-11-20 15:16:09 -08003799 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303800
3801 return 0;
3802}
3803
3804/**
3805 * mpi_flash_op_ext_resp - SPCv specific
3806 * @pm8001_ha: our hba card information
3807 * @piomb: IO message buffer
3808 */
3809static int mpi_flash_op_ext_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3810{
Joe Perches1b5d2792020-11-20 15:16:09 -08003811 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303812
3813 return 0;
3814}
3815
3816/**
3817 * mpi_set_phy_profile_resp - SPCv specific
3818 * @pm8001_ha: our hba card information
3819 * @piomb: IO message buffer
3820 */
3821static int mpi_set_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3822 void *piomb)
3823{
yuuzheng9d9c7c22020-03-16 13:19:03 +05303824 u32 tag;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303825 u8 page_code;
yuuzheng9d9c7c22020-03-16 13:19:03 +05303826 int rc = 0;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303827 struct set_phy_profile_resp *pPayload =
3828 (struct set_phy_profile_resp *)(piomb + 4);
3829 u32 ppc_phyid = le32_to_cpu(pPayload->ppc_phyid);
3830 u32 status = le32_to_cpu(pPayload->status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303831
yuuzheng9d9c7c22020-03-16 13:19:03 +05303832 tag = le32_to_cpu(pPayload->tag);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303833 page_code = (u8)((ppc_phyid & 0xFF00) >> 8);
3834 if (status) {
3835 /* status is FAILED */
Joe Perches1b5d2792020-11-20 15:16:09 -08003836 pm8001_dbg(pm8001_ha, FAIL,
3837 "PhyProfile command failed with status 0x%08X\n",
3838 status);
yuuzheng9d9c7c22020-03-16 13:19:03 +05303839 rc = -1;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303840 } else {
3841 if (page_code != SAS_PHY_ANALOG_SETTINGS_PAGE) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003842 pm8001_dbg(pm8001_ha, FAIL, "Invalid page code 0x%X\n",
3843 page_code);
yuuzheng9d9c7c22020-03-16 13:19:03 +05303844 rc = -1;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303845 }
3846 }
yuuzheng9d9c7c22020-03-16 13:19:03 +05303847 pm8001_tag_free(pm8001_ha, tag);
3848 return rc;
Sakthivel Kf5860992013-04-17 16:37:02 +05303849}
3850
3851/**
3852 * mpi_kek_management_resp - SPCv specific
3853 * @pm8001_ha: our hba card information
3854 * @piomb: IO message buffer
3855 */
3856static int mpi_kek_management_resp(struct pm8001_hba_info *pm8001_ha,
3857 void *piomb)
3858{
3859 struct kek_mgmt_resp *pPayload = (struct kek_mgmt_resp *)(piomb + 4);
3860
3861 u32 status = le32_to_cpu(pPayload->status);
3862 u32 kidx_new_curr_ksop = le32_to_cpu(pPayload->kidx_new_curr_ksop);
3863 u32 err_qlfr = le32_to_cpu(pPayload->err_qlfr);
3864
Joe Perches1b5d2792020-11-20 15:16:09 -08003865 pm8001_dbg(pm8001_ha, MSG,
3866 "KEK MGMT RESP. Status 0x%x idx_ksop 0x%x err_qlfr 0x%x\n",
3867 status, kidx_new_curr_ksop, err_qlfr);
Sakthivel Kf5860992013-04-17 16:37:02 +05303868
3869 return 0;
3870}
3871
3872/**
3873 * mpi_dek_management_resp - SPCv specific
3874 * @pm8001_ha: our hba card information
3875 * @piomb: IO message buffer
3876 */
3877static int mpi_dek_management_resp(struct pm8001_hba_info *pm8001_ha,
3878 void *piomb)
3879{
Joe Perches1b5d2792020-11-20 15:16:09 -08003880 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303881
3882 return 0;
3883}
3884
3885/**
3886 * ssp_coalesced_comp_resp - SPCv specific
3887 * @pm8001_ha: our hba card information
3888 * @piomb: IO message buffer
3889 */
3890static int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
3891 void *piomb)
3892{
Joe Perches1b5d2792020-11-20 15:16:09 -08003893 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303894
3895 return 0;
3896}
3897
3898/**
3899 * process_one_iomb - process one outbound Queue memory block
3900 * @pm8001_ha: our hba card information
3901 * @piomb: IO message buffer
3902 */
3903static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3904{
3905 __le32 pHeader = *(__le32 *)piomb;
3906 u32 opc = (u32)((le32_to_cpu(pHeader)) & 0xFFF);
3907
3908 switch (opc) {
3909 case OPC_OUB_ECHO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003910 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303911 break;
3912 case OPC_OUB_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003913 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303914 mpi_hw_event(pm8001_ha, piomb);
3915 break;
3916 case OPC_OUB_THERM_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003917 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_THERMAL_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303918 mpi_thermal_hw_event(pm8001_ha, piomb);
3919 break;
3920 case OPC_OUB_SSP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003921 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303922 mpi_ssp_completion(pm8001_ha, piomb);
3923 break;
3924 case OPC_OUB_SMP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003925 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303926 mpi_smp_completion(pm8001_ha, piomb);
3927 break;
3928 case OPC_OUB_LOCAL_PHY_CNTRL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003929 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303930 pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
3931 break;
3932 case OPC_OUB_DEV_REGIST:
Joe Perches1b5d2792020-11-20 15:16:09 -08003933 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303934 pm8001_mpi_reg_resp(pm8001_ha, piomb);
3935 break;
3936 case OPC_OUB_DEREG_DEV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003937 pm8001_dbg(pm8001_ha, MSG, "unregister the device\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303938 pm8001_mpi_dereg_resp(pm8001_ha, piomb);
3939 break;
3940 case OPC_OUB_GET_DEV_HANDLE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003941 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303942 break;
3943 case OPC_OUB_SATA_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003944 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303945 mpi_sata_completion(pm8001_ha, piomb);
3946 break;
3947 case OPC_OUB_SATA_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003948 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303949 mpi_sata_event(pm8001_ha, piomb);
3950 break;
3951 case OPC_OUB_SSP_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003952 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303953 mpi_ssp_event(pm8001_ha, piomb);
3954 break;
3955 case OPC_OUB_DEV_HANDLE_ARRIV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003956 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303957 /*This is for target*/
3958 break;
3959 case OPC_OUB_SSP_RECV_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003960 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303961 /*This is for target*/
3962 break;
3963 case OPC_OUB_FW_FLASH_UPDATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003964 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303965 pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
3966 break;
3967 case OPC_OUB_GPIO_RESPONSE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003968 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303969 break;
3970 case OPC_OUB_GPIO_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003971 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303972 break;
3973 case OPC_OUB_GENERAL_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003974 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303975 pm8001_mpi_general_event(pm8001_ha, piomb);
3976 break;
3977 case OPC_OUB_SSP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003978 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303979 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3980 break;
3981 case OPC_OUB_SATA_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003982 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303983 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3984 break;
3985 case OPC_OUB_SAS_DIAG_MODE_START_END:
Joe Perches1b5d2792020-11-20 15:16:09 -08003986 pm8001_dbg(pm8001_ha, MSG,
3987 "OPC_OUB_SAS_DIAG_MODE_START_END\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303988 break;
3989 case OPC_OUB_SAS_DIAG_EXECUTE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003990 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303991 break;
3992 case OPC_OUB_GET_TIME_STAMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003993 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303994 break;
3995 case OPC_OUB_SAS_HW_EVENT_ACK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003996 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303997 break;
3998 case OPC_OUB_PORT_CONTROL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003999 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304000 break;
4001 case OPC_OUB_SMP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004002 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304003 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
4004 break;
4005 case OPC_OUB_GET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004006 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304007 pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
4008 break;
4009 case OPC_OUB_SET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004010 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304011 pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
4012 break;
4013 case OPC_OUB_DEVICE_HANDLE_REMOVAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004014 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304015 break;
4016 case OPC_OUB_SET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004017 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304018 pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
4019 break;
4020 case OPC_OUB_GET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004021 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304022 break;
4023 case OPC_OUB_SET_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08004024 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304025 break;
4026 /* spcv specifc commands */
4027 case OPC_OUB_PHY_START_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004028 pm8001_dbg(pm8001_ha, MSG,
4029 "OPC_OUB_PHY_START_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304030 mpi_phy_start_resp(pm8001_ha, piomb);
4031 break;
4032 case OPC_OUB_PHY_STOP_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004033 pm8001_dbg(pm8001_ha, MSG,
4034 "OPC_OUB_PHY_STOP_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304035 mpi_phy_stop_resp(pm8001_ha, piomb);
4036 break;
4037 case OPC_OUB_SET_CONTROLLER_CONFIG:
Joe Perches1b5d2792020-11-20 15:16:09 -08004038 pm8001_dbg(pm8001_ha, MSG,
4039 "OPC_OUB_SET_CONTROLLER_CONFIG opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304040 mpi_set_controller_config_resp(pm8001_ha, piomb);
4041 break;
4042 case OPC_OUB_GET_CONTROLLER_CONFIG:
Joe Perches1b5d2792020-11-20 15:16:09 -08004043 pm8001_dbg(pm8001_ha, MSG,
4044 "OPC_OUB_GET_CONTROLLER_CONFIG opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304045 mpi_get_controller_config_resp(pm8001_ha, piomb);
4046 break;
4047 case OPC_OUB_GET_PHY_PROFILE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004048 pm8001_dbg(pm8001_ha, MSG,
4049 "OPC_OUB_GET_PHY_PROFILE opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304050 mpi_get_phy_profile_resp(pm8001_ha, piomb);
4051 break;
4052 case OPC_OUB_FLASH_OP_EXT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004053 pm8001_dbg(pm8001_ha, MSG,
4054 "OPC_OUB_FLASH_OP_EXT opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304055 mpi_flash_op_ext_resp(pm8001_ha, piomb);
4056 break;
4057 case OPC_OUB_SET_PHY_PROFILE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004058 pm8001_dbg(pm8001_ha, MSG,
4059 "OPC_OUB_SET_PHY_PROFILE opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304060 mpi_set_phy_profile_resp(pm8001_ha, piomb);
4061 break;
4062 case OPC_OUB_KEK_MANAGEMENT_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004063 pm8001_dbg(pm8001_ha, MSG,
4064 "OPC_OUB_KEK_MANAGEMENT_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304065 mpi_kek_management_resp(pm8001_ha, piomb);
4066 break;
4067 case OPC_OUB_DEK_MANAGEMENT_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004068 pm8001_dbg(pm8001_ha, MSG,
4069 "OPC_OUB_DEK_MANAGEMENT_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304070 mpi_dek_management_resp(pm8001_ha, piomb);
4071 break;
4072 case OPC_OUB_SSP_COALESCED_COMP_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004073 pm8001_dbg(pm8001_ha, MSG,
4074 "OPC_OUB_SSP_COALESCED_COMP_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304075 ssp_coalesced_comp_resp(pm8001_ha, piomb);
4076 break;
4077 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08004078 pm8001_dbg(pm8001_ha, DEVIO,
4079 "Unknown outbound Queue IOMB OPC = 0x%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304080 break;
4081 }
4082}
4083
Deepak Ukey72349b62018-09-11 14:18:04 +05304084static void print_scratchpad_registers(struct pm8001_hba_info *pm8001_ha)
4085{
Joe Perches1b5d2792020-11-20 15:16:09 -08004086 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_0: 0x%x\n",
4087 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0));
4088 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_1:0x%x\n",
4089 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1));
4090 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_2: 0x%x\n",
4091 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2));
4092 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_3: 0x%x\n",
4093 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3));
4094 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_0: 0x%x\n",
4095 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0));
4096 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_1: 0x%x\n",
4097 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_1));
4098 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_2: 0x%x\n",
4099 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_2));
4100 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_3: 0x%x\n",
4101 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_3));
4102 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_4: 0x%x\n",
4103 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_4));
4104 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_5: 0x%x\n",
4105 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_5));
4106 pm8001_dbg(pm8001_ha, FAIL, "MSGU_RSVD_SCRATCH_PAD_0: 0x%x\n",
4107 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_6));
4108 pm8001_dbg(pm8001_ha, FAIL, "MSGU_RSVD_SCRATCH_PAD_1: 0x%x\n",
4109 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_7));
Deepak Ukey72349b62018-09-11 14:18:04 +05304110}
4111
Sakthivel Kf5860992013-04-17 16:37:02 +05304112static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
4113{
4114 struct outbound_queue_table *circularQ;
4115 void *pMsg1 = NULL;
Kees Cook3f649ab2020-06-03 13:09:38 -07004116 u8 bc;
Sakthivel Kf5860992013-04-17 16:37:02 +05304117 u32 ret = MPI_IO_STATUS_FAIL;
4118 unsigned long flags;
Deepak Ukey72349b62018-09-11 14:18:04 +05304119 u32 regval;
Sakthivel Kf5860992013-04-17 16:37:02 +05304120
Viswas G05c6c022020-10-05 20:20:08 +05304121 if (vec == (pm8001_ha->max_q_num - 1)) {
Deepak Ukey72349b62018-09-11 14:18:04 +05304122 regval = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
4123 if ((regval & SCRATCH_PAD_MIPSALL_READY) !=
4124 SCRATCH_PAD_MIPSALL_READY) {
4125 pm8001_ha->controller_fatal_error = true;
Joe Perches1b5d2792020-11-20 15:16:09 -08004126 pm8001_dbg(pm8001_ha, FAIL,
4127 "Firmware Fatal error! Regval:0x%x\n",
4128 regval);
Deepak Ukey72349b62018-09-11 14:18:04 +05304129 print_scratchpad_registers(pm8001_ha);
4130 return ret;
4131 }
4132 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304133 spin_lock_irqsave(&pm8001_ha->lock, flags);
4134 circularQ = &pm8001_ha->outbnd_q_tbl[vec];
4135 do {
Deepak Ukey72349b62018-09-11 14:18:04 +05304136 /* spurious interrupt during setup if kexec-ing and
4137 * driver doing a doorbell access w/ the pre-kexec oq
4138 * interrupt setup.
4139 */
4140 if (!circularQ->pi_virt)
4141 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05304142 ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
4143 if (MPI_IO_STATUS_SUCCESS == ret) {
4144 /* process the outbound message */
4145 process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
4146 /* free the message from the outbound circular buffer */
4147 pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4148 circularQ, bc);
4149 }
4150 if (MPI_IO_STATUS_BUSY == ret) {
4151 /* Update the producer index from SPC */
4152 circularQ->producer_index =
4153 cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4154 if (le32_to_cpu(circularQ->producer_index) ==
4155 circularQ->consumer_idx)
4156 /* OQ is empty */
4157 break;
4158 }
4159 } while (1);
4160 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
4161 return ret;
4162}
4163
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004164/* DMA_... to our direction translation. */
Sakthivel Kf5860992013-04-17 16:37:02 +05304165static const u8 data_dir_flags[] = {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004166 [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
4167 [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
4168 [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */
4169 [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */
Sakthivel Kf5860992013-04-17 16:37:02 +05304170};
4171
4172static void build_smp_cmd(u32 deviceID, __le32 hTag,
4173 struct smp_req *psmp_cmd, int mode, int length)
4174{
4175 psmp_cmd->tag = hTag;
4176 psmp_cmd->device_id = cpu_to_le32(deviceID);
4177 if (mode == SMP_DIRECT) {
4178 length = length - 4; /* subtract crc */
4179 psmp_cmd->len_ip_ir = cpu_to_le32(length << 16);
4180 } else {
4181 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4182 }
4183}
4184
4185/**
Lee Jones7cdaf122021-03-03 14:46:23 +00004186 * pm80xx_chip_smp_req - send a SMP task to FW
Sakthivel Kf5860992013-04-17 16:37:02 +05304187 * @pm8001_ha: our hba card information.
4188 * @ccb: the ccb information this request used.
4189 */
4190static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4191 struct pm8001_ccb_info *ccb)
4192{
4193 int elem, rc;
4194 struct sas_task *task = ccb->task;
4195 struct domain_device *dev = task->dev;
4196 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4197 struct scatterlist *sg_req, *sg_resp;
4198 u32 req_len, resp_len;
4199 struct smp_req smp_cmd;
4200 u32 opc;
4201 struct inbound_queue_table *circularQ;
4202 char *preq_dma_addr = NULL;
4203 __le64 tmp_addr;
4204 u32 i, length;
4205
4206 memset(&smp_cmd, 0, sizeof(smp_cmd));
4207 /*
4208 * DMA-map SMP request, response buffers
4209 */
4210 sg_req = &task->smp_task.smp_req;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004211 elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304212 if (!elem)
4213 return -ENOMEM;
4214 req_len = sg_dma_len(sg_req);
4215
4216 sg_resp = &task->smp_task.smp_resp;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004217 elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304218 if (!elem) {
4219 rc = -ENOMEM;
4220 goto err_out;
4221 }
4222 resp_len = sg_dma_len(sg_resp);
4223 /* must be in dwords */
4224 if ((req_len & 0x3) || (resp_len & 0x3)) {
4225 rc = -EINVAL;
4226 goto err_out_2;
4227 }
4228
4229 opc = OPC_INB_SMP_REQUEST;
4230 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4231 smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4232
4233 length = sg_req->length;
Joe Perches1b5d2792020-11-20 15:16:09 -08004234 pm8001_dbg(pm8001_ha, IO, "SMP Frame Length %d\n", sg_req->length);
Sakthivel Kf5860992013-04-17 16:37:02 +05304235 if (!(length - 8))
4236 pm8001_ha->smp_exp_mode = SMP_DIRECT;
4237 else
4238 pm8001_ha->smp_exp_mode = SMP_INDIRECT;
4239
Sakthivel Kf5860992013-04-17 16:37:02 +05304240
4241 tmp_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4242 preq_dma_addr = (char *)phys_to_virt(tmp_addr);
4243
4244 /* INDIRECT MODE command settings. Use DMA */
4245 if (pm8001_ha->smp_exp_mode == SMP_INDIRECT) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004246 pm8001_dbg(pm8001_ha, IO, "SMP REQUEST INDIRECT MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304247 /* for SPCv indirect mode. Place the top 4 bytes of
4248 * SMP Request header here. */
4249 for (i = 0; i < 4; i++)
4250 smp_cmd.smp_req16[i] = *(preq_dma_addr + i);
4251 /* exclude top 4 bytes for SMP req header */
4252 smp_cmd.long_smp_req.long_req_addr =
4253 cpu_to_le64((u64)sg_dma_address
Anand Kumar Santhanamcb993e52013-09-17 14:37:14 +05304254 (&task->smp_task.smp_req) + 4);
Sakthivel Kf5860992013-04-17 16:37:02 +05304255 /* exclude 4 bytes for SMP req header and CRC */
4256 smp_cmd.long_smp_req.long_req_size =
4257 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-8);
4258 smp_cmd.long_smp_req.long_resp_addr =
4259 cpu_to_le64((u64)sg_dma_address
4260 (&task->smp_task.smp_resp));
4261 smp_cmd.long_smp_req.long_resp_size =
4262 cpu_to_le32((u32)sg_dma_len
4263 (&task->smp_task.smp_resp)-4);
4264 } else { /* DIRECT MODE */
4265 smp_cmd.long_smp_req.long_req_addr =
4266 cpu_to_le64((u64)sg_dma_address
4267 (&task->smp_task.smp_req));
4268 smp_cmd.long_smp_req.long_req_size =
4269 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4270 smp_cmd.long_smp_req.long_resp_addr =
4271 cpu_to_le64((u64)sg_dma_address
4272 (&task->smp_task.smp_resp));
4273 smp_cmd.long_smp_req.long_resp_size =
4274 cpu_to_le32
4275 ((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4276 }
4277 if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004278 pm8001_dbg(pm8001_ha, IO, "SMP REQUEST DIRECT MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304279 for (i = 0; i < length; i++)
4280 if (i < 16) {
4281 smp_cmd.smp_req16[i] = *(preq_dma_addr+i);
Joe Perches1b5d2792020-11-20 15:16:09 -08004282 pm8001_dbg(pm8001_ha, IO,
4283 "Byte[%d]:%x (DMA data:%x)\n",
4284 i, smp_cmd.smp_req16[i],
4285 *(preq_dma_addr));
Sakthivel Kf5860992013-04-17 16:37:02 +05304286 } else {
4287 smp_cmd.smp_req[i] = *(preq_dma_addr+i);
Joe Perches1b5d2792020-11-20 15:16:09 -08004288 pm8001_dbg(pm8001_ha, IO,
4289 "Byte[%d]:%x (DMA data:%x)\n",
4290 i, smp_cmd.smp_req[i],
4291 *(preq_dma_addr));
Sakthivel Kf5860992013-04-17 16:37:02 +05304292 }
4293 }
4294
4295 build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag,
4296 &smp_cmd, pm8001_ha->smp_exp_mode, length);
peter chang91a43fa2019-11-14 15:39:05 +05304297 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &smp_cmd,
4298 sizeof(smp_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304299 if (rc)
4300 goto err_out_2;
Sakthivel Kf5860992013-04-17 16:37:02 +05304301 return 0;
4302
4303err_out_2:
4304 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004305 DMA_FROM_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304306err_out:
4307 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004308 DMA_TO_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304309 return rc;
4310}
4311
4312static int check_enc_sas_cmd(struct sas_task *task)
4313{
James Bottomleye73823f2013-05-07 15:38:18 -07004314 u8 cmd = task->ssp_task.cmd->cmnd[0];
4315
4316 if (cmd == READ_10 || cmd == WRITE_10 || cmd == WRITE_VERIFY)
Sakthivel Kf5860992013-04-17 16:37:02 +05304317 return 1;
4318 else
4319 return 0;
4320}
4321
4322static int check_enc_sat_cmd(struct sas_task *task)
4323{
4324 int ret = 0;
4325 switch (task->ata_task.fis.command) {
4326 case ATA_CMD_FPDMA_READ:
4327 case ATA_CMD_READ_EXT:
4328 case ATA_CMD_READ:
4329 case ATA_CMD_FPDMA_WRITE:
4330 case ATA_CMD_WRITE_EXT:
4331 case ATA_CMD_WRITE:
4332 case ATA_CMD_PIO_READ:
4333 case ATA_CMD_PIO_READ_EXT:
4334 case ATA_CMD_PIO_WRITE:
4335 case ATA_CMD_PIO_WRITE_EXT:
4336 ret = 1;
4337 break;
4338 default:
4339 ret = 0;
4340 break;
4341 }
4342 return ret;
4343}
4344
4345/**
4346 * pm80xx_chip_ssp_io_req - send a SSP task to FW
4347 * @pm8001_ha: our hba card information.
4348 * @ccb: the ccb information this request used.
4349 */
4350static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4351 struct pm8001_ccb_info *ccb)
4352{
4353 struct sas_task *task = ccb->task;
4354 struct domain_device *dev = task->dev;
4355 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4356 struct ssp_ini_io_start_req ssp_cmd;
4357 u32 tag = ccb->ccb_tag;
4358 int ret;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304359 u64 phys_addr, start_addr, end_addr;
4360 u32 end_addr_high, end_addr_low;
Sakthivel Kf5860992013-04-17 16:37:02 +05304361 struct inbound_queue_table *circularQ;
Viswas G05c6c022020-10-05 20:20:08 +05304362 u32 q_index, cpu_id;
Sakthivel Kf5860992013-04-17 16:37:02 +05304363 u32 opc = OPC_INB_SSPINIIOSTART;
4364 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4365 memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
4366 /* data address domain added for spcv; set to 0 by host,
4367 * used internally by controller
4368 * 0 for SAS 1.1 and SAS 2.0 compatible TLR
4369 */
4370 ssp_cmd.dad_dir_m_tlr =
4371 cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);
4372 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4373 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4374 ssp_cmd.tag = cpu_to_le32(tag);
4375 if (task->ssp_task.enable_first_burst)
4376 ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
4377 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
4378 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
James Bottomleye73823f2013-05-07 15:38:18 -07004379 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4380 task->ssp_task.cmd->cmd_len);
Viswas G05c6c022020-10-05 20:20:08 +05304381 cpu_id = smp_processor_id();
4382 q_index = (u32) (cpu_id) % (pm8001_ha->max_q_num);
Anand Kumar Santhanamf9cd6cb2013-09-18 11:12:59 +05304383 circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
Sakthivel Kf5860992013-04-17 16:37:02 +05304384
4385 /* Check if encryption is set */
4386 if (pm8001_ha->chip->encrypt &&
4387 !(pm8001_ha->encrypt_info.status) && check_enc_sas_cmd(task)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004388 pm8001_dbg(pm8001_ha, IO,
4389 "Encryption enabled.Sending Encrypt SAS command 0x%x\n",
4390 task->ssp_task.cmd->cmnd[0]);
Sakthivel Kf5860992013-04-17 16:37:02 +05304391 opc = OPC_INB_SSP_INI_DIF_ENC_IO;
4392 /* enable encryption. 0 for SAS 1.1 and SAS 2.0 compatible TLR*/
4393 ssp_cmd.dad_dir_m_tlr = cpu_to_le32
4394 ((data_dir_flags[task->data_dir] << 8) | 0x20 | 0x0);
4395
4396 /* fill in PRD (scatter/gather) table, if any */
4397 if (task->num_scatter > 1) {
4398 pm8001_chip_make_sg(task->scatter,
4399 ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304400 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304401 ssp_cmd.enc_addr_low =
4402 cpu_to_le32(lower_32_bits(phys_addr));
4403 ssp_cmd.enc_addr_high =
4404 cpu_to_le32(upper_32_bits(phys_addr));
4405 ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
4406 } else if (task->num_scatter == 1) {
4407 u64 dma_addr = sg_dma_address(task->scatter);
4408 ssp_cmd.enc_addr_low =
4409 cpu_to_le32(lower_32_bits(dma_addr));
4410 ssp_cmd.enc_addr_high =
4411 cpu_to_le32(upper_32_bits(dma_addr));
4412 ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4413 ssp_cmd.enc_esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304414 /* Check 4G Boundary */
4415 start_addr = cpu_to_le64(dma_addr);
4416 end_addr = (start_addr + ssp_cmd.enc_len) - 1;
4417 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4418 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4419 if (end_addr_high != ssp_cmd.enc_addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004420 pm8001_dbg(pm8001_ha, FAIL,
4421 "The sg list address start_addr=0x%016llx data_len=0x%x end_addr_high=0x%08x end_addr_low=0x%08x has crossed 4G boundary\n",
4422 start_addr, ssp_cmd.enc_len,
4423 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304424 pm8001_chip_make_sg(task->scatter, 1,
4425 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304426 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304427 ssp_cmd.enc_addr_low =
4428 cpu_to_le32(lower_32_bits(phys_addr));
4429 ssp_cmd.enc_addr_high =
4430 cpu_to_le32(upper_32_bits(phys_addr));
4431 ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
4432 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304433 } else if (task->num_scatter == 0) {
4434 ssp_cmd.enc_addr_low = 0;
4435 ssp_cmd.enc_addr_high = 0;
4436 ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4437 ssp_cmd.enc_esgl = 0;
4438 }
4439 /* XTS mode. All other fields are 0 */
4440 ssp_cmd.key_cmode = 0x6 << 4;
4441 /* set tweak values. Should be the start lba */
James Bottomleye73823f2013-05-07 15:38:18 -07004442 ssp_cmd.twk_val0 = cpu_to_le32((task->ssp_task.cmd->cmnd[2] << 24) |
4443 (task->ssp_task.cmd->cmnd[3] << 16) |
4444 (task->ssp_task.cmd->cmnd[4] << 8) |
4445 (task->ssp_task.cmd->cmnd[5]));
Sakthivel Kf5860992013-04-17 16:37:02 +05304446 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08004447 pm8001_dbg(pm8001_ha, IO,
4448 "Sending Normal SAS command 0x%x inb q %x\n",
4449 task->ssp_task.cmd->cmnd[0], q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304450 /* fill in PRD (scatter/gather) table, if any */
4451 if (task->num_scatter > 1) {
4452 pm8001_chip_make_sg(task->scatter, ccb->n_elem,
4453 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304454 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304455 ssp_cmd.addr_low =
4456 cpu_to_le32(lower_32_bits(phys_addr));
4457 ssp_cmd.addr_high =
4458 cpu_to_le32(upper_32_bits(phys_addr));
4459 ssp_cmd.esgl = cpu_to_le32(1<<31);
4460 } else if (task->num_scatter == 1) {
4461 u64 dma_addr = sg_dma_address(task->scatter);
4462 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4463 ssp_cmd.addr_high =
4464 cpu_to_le32(upper_32_bits(dma_addr));
4465 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4466 ssp_cmd.esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304467 /* Check 4G Boundary */
4468 start_addr = cpu_to_le64(dma_addr);
4469 end_addr = (start_addr + ssp_cmd.len) - 1;
4470 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4471 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4472 if (end_addr_high != ssp_cmd.addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004473 pm8001_dbg(pm8001_ha, FAIL,
4474 "The sg list address start_addr=0x%016llx data_len=0x%x end_addr_high=0x%08x end_addr_low=0x%08x has crossed 4G boundary\n",
4475 start_addr, ssp_cmd.len,
4476 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304477 pm8001_chip_make_sg(task->scatter, 1,
4478 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304479 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304480 ssp_cmd.addr_low =
4481 cpu_to_le32(lower_32_bits(phys_addr));
4482 ssp_cmd.addr_high =
4483 cpu_to_le32(upper_32_bits(phys_addr));
4484 ssp_cmd.esgl = cpu_to_le32(1<<31);
4485 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304486 } else if (task->num_scatter == 0) {
4487 ssp_cmd.addr_low = 0;
4488 ssp_cmd.addr_high = 0;
4489 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4490 ssp_cmd.esgl = 0;
4491 }
4492 }
Anand Kumar Santhanamf9cd6cb2013-09-18 11:12:59 +05304493 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304494 &ssp_cmd, sizeof(ssp_cmd), q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304495 return ret;
4496}
4497
4498static int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4499 struct pm8001_ccb_info *ccb)
4500{
4501 struct sas_task *task = ccb->task;
4502 struct domain_device *dev = task->dev;
4503 struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4504 u32 tag = ccb->ccb_tag;
4505 int ret;
Viswas G05c6c022020-10-05 20:20:08 +05304506 u32 q_index, cpu_id;
Sakthivel Kf5860992013-04-17 16:37:02 +05304507 struct sata_start_req sata_cmd;
4508 u32 hdr_tag, ncg_tag = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304509 u64 phys_addr, start_addr, end_addr;
4510 u32 end_addr_high, end_addr_low;
Sakthivel Kf5860992013-04-17 16:37:02 +05304511 u32 ATAP = 0x0;
4512 u32 dir;
4513 struct inbound_queue_table *circularQ;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304514 unsigned long flags;
Sakthivel Kf5860992013-04-17 16:37:02 +05304515 u32 opc = OPC_INB_SATA_HOST_OPSTART;
4516 memset(&sata_cmd, 0, sizeof(sata_cmd));
Viswas G05c6c022020-10-05 20:20:08 +05304517 cpu_id = smp_processor_id();
4518 q_index = (u32) (cpu_id) % (pm8001_ha->max_q_num);
Anand Kumar Santhanamf9cd6cb2013-09-18 11:12:59 +05304519 circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
Sakthivel Kf5860992013-04-17 16:37:02 +05304520
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004521 if (task->data_dir == DMA_NONE) {
Sakthivel Kf5860992013-04-17 16:37:02 +05304522 ATAP = 0x04; /* no data*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004523 pm8001_dbg(pm8001_ha, IO, "no data\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304524 } else if (likely(!task->ata_task.device_control_reg_update)) {
4525 if (task->ata_task.dma_xfer) {
4526 ATAP = 0x06; /* DMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004527 pm8001_dbg(pm8001_ha, IO, "DMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304528 } else {
4529 ATAP = 0x05; /* PIO*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004530 pm8001_dbg(pm8001_ha, IO, "PIO\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304531 }
4532 if (task->ata_task.use_ncq &&
Hannes Reinecke1cbd7722014-11-05 13:08:20 +01004533 dev->sata_dev.class != ATA_DEV_ATAPI) {
Sakthivel Kf5860992013-04-17 16:37:02 +05304534 ATAP = 0x07; /* FPDMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004535 pm8001_dbg(pm8001_ha, IO, "FPDMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304536 }
4537 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304538 if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4539 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
Sakthivel Kf5860992013-04-17 16:37:02 +05304540 ncg_tag = hdr_tag;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304541 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304542 dir = data_dir_flags[task->data_dir] << 8;
4543 sata_cmd.tag = cpu_to_le32(tag);
4544 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4545 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4546
4547 sata_cmd.sata_fis = task->ata_task.fis;
4548 if (likely(!task->ata_task.device_control_reg_update))
4549 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4550 sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4551
4552 /* Check if encryption is set */
4553 if (pm8001_ha->chip->encrypt &&
4554 !(pm8001_ha->encrypt_info.status) && check_enc_sat_cmd(task)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004555 pm8001_dbg(pm8001_ha, IO,
4556 "Encryption enabled.Sending Encrypt SATA cmd 0x%x\n",
4557 sata_cmd.sata_fis.command);
Sakthivel Kf5860992013-04-17 16:37:02 +05304558 opc = OPC_INB_SATA_DIF_ENC_IO;
4559
4560 /* set encryption bit */
4561 sata_cmd.ncqtag_atap_dir_m_dad =
4562 cpu_to_le32(((ncg_tag & 0xff)<<16)|
4563 ((ATAP & 0x3f) << 10) | 0x20 | dir);
4564 /* dad (bit 0-1) is 0 */
4565 /* fill in PRD (scatter/gather) table, if any */
4566 if (task->num_scatter > 1) {
4567 pm8001_chip_make_sg(task->scatter,
4568 ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304569 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304570 sata_cmd.enc_addr_low = lower_32_bits(phys_addr);
4571 sata_cmd.enc_addr_high = upper_32_bits(phys_addr);
4572 sata_cmd.enc_esgl = cpu_to_le32(1 << 31);
4573 } else if (task->num_scatter == 1) {
4574 u64 dma_addr = sg_dma_address(task->scatter);
4575 sata_cmd.enc_addr_low = lower_32_bits(dma_addr);
4576 sata_cmd.enc_addr_high = upper_32_bits(dma_addr);
4577 sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4578 sata_cmd.enc_esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304579 /* Check 4G Boundary */
4580 start_addr = cpu_to_le64(dma_addr);
4581 end_addr = (start_addr + sata_cmd.enc_len) - 1;
4582 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4583 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4584 if (end_addr_high != sata_cmd.enc_addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004585 pm8001_dbg(pm8001_ha, FAIL,
4586 "The sg list address start_addr=0x%016llx data_len=0x%x end_addr_high=0x%08x end_addr_low=0x%08x has crossed 4G boundary\n",
4587 start_addr, sata_cmd.enc_len,
4588 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304589 pm8001_chip_make_sg(task->scatter, 1,
4590 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304591 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304592 sata_cmd.enc_addr_low =
4593 lower_32_bits(phys_addr);
4594 sata_cmd.enc_addr_high =
4595 upper_32_bits(phys_addr);
4596 sata_cmd.enc_esgl =
4597 cpu_to_le32(1 << 31);
4598 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304599 } else if (task->num_scatter == 0) {
4600 sata_cmd.enc_addr_low = 0;
4601 sata_cmd.enc_addr_high = 0;
4602 sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4603 sata_cmd.enc_esgl = 0;
4604 }
4605 /* XTS mode. All other fields are 0 */
4606 sata_cmd.key_index_mode = 0x6 << 4;
4607 /* set tweak values. Should be the start lba */
4608 sata_cmd.twk_val0 =
4609 cpu_to_le32((sata_cmd.sata_fis.lbal_exp << 24) |
4610 (sata_cmd.sata_fis.lbah << 16) |
4611 (sata_cmd.sata_fis.lbam << 8) |
4612 (sata_cmd.sata_fis.lbal));
4613 sata_cmd.twk_val1 =
4614 cpu_to_le32((sata_cmd.sata_fis.lbah_exp << 8) |
4615 (sata_cmd.sata_fis.lbam_exp));
4616 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08004617 pm8001_dbg(pm8001_ha, IO,
4618 "Sending Normal SATA command 0x%x inb %x\n",
4619 sata_cmd.sata_fis.command, q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304620 /* dad (bit 0-1) is 0 */
4621 sata_cmd.ncqtag_atap_dir_m_dad =
4622 cpu_to_le32(((ncg_tag & 0xff)<<16) |
4623 ((ATAP & 0x3f) << 10) | dir);
4624
4625 /* fill in PRD (scatter/gather) table, if any */
4626 if (task->num_scatter > 1) {
4627 pm8001_chip_make_sg(task->scatter,
4628 ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304629 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304630 sata_cmd.addr_low = lower_32_bits(phys_addr);
4631 sata_cmd.addr_high = upper_32_bits(phys_addr);
4632 sata_cmd.esgl = cpu_to_le32(1 << 31);
4633 } else if (task->num_scatter == 1) {
4634 u64 dma_addr = sg_dma_address(task->scatter);
4635 sata_cmd.addr_low = lower_32_bits(dma_addr);
4636 sata_cmd.addr_high = upper_32_bits(dma_addr);
4637 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4638 sata_cmd.esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304639 /* Check 4G Boundary */
4640 start_addr = cpu_to_le64(dma_addr);
4641 end_addr = (start_addr + sata_cmd.len) - 1;
4642 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4643 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4644 if (end_addr_high != sata_cmd.addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004645 pm8001_dbg(pm8001_ha, FAIL,
4646 "The sg list address start_addr=0x%016llx data_len=0x%xend_addr_high=0x%08x end_addr_low=0x%08x has crossed 4G boundary\n",
4647 start_addr, sata_cmd.len,
4648 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304649 pm8001_chip_make_sg(task->scatter, 1,
4650 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304651 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304652 sata_cmd.addr_low =
4653 lower_32_bits(phys_addr);
4654 sata_cmd.addr_high =
4655 upper_32_bits(phys_addr);
4656 sata_cmd.esgl = cpu_to_le32(1 << 31);
4657 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304658 } else if (task->num_scatter == 0) {
4659 sata_cmd.addr_low = 0;
4660 sata_cmd.addr_high = 0;
4661 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4662 sata_cmd.esgl = 0;
4663 }
Colin Ian King9e2a07e2019-03-17 18:15:32 +00004664 /* scsi cdb */
4665 sata_cmd.atapi_scsi_cdb[0] =
4666 cpu_to_le32(((task->ata_task.atapi_packet[0]) |
4667 (task->ata_task.atapi_packet[1] << 8) |
4668 (task->ata_task.atapi_packet[2] << 16) |
4669 (task->ata_task.atapi_packet[3] << 24)));
4670 sata_cmd.atapi_scsi_cdb[1] =
4671 cpu_to_le32(((task->ata_task.atapi_packet[4]) |
4672 (task->ata_task.atapi_packet[5] << 8) |
4673 (task->ata_task.atapi_packet[6] << 16) |
4674 (task->ata_task.atapi_packet[7] << 24)));
4675 sata_cmd.atapi_scsi_cdb[2] =
4676 cpu_to_le32(((task->ata_task.atapi_packet[8]) |
4677 (task->ata_task.atapi_packet[9] << 8) |
4678 (task->ata_task.atapi_packet[10] << 16) |
4679 (task->ata_task.atapi_packet[11] << 24)));
4680 sata_cmd.atapi_scsi_cdb[3] =
4681 cpu_to_le32(((task->ata_task.atapi_packet[12]) |
4682 (task->ata_task.atapi_packet[13] << 8) |
4683 (task->ata_task.atapi_packet[14] << 16) |
4684 (task->ata_task.atapi_packet[15] << 24)));
Sakthivel Kf5860992013-04-17 16:37:02 +05304685 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304686
4687 /* Check for read log for failed drive and return */
4688 if (sata_cmd.sata_fis.command == 0x2f) {
4689 if (pm8001_ha_dev && ((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
4690 (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4691 (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4692 struct task_status_struct *ts;
4693
4694 pm8001_ha_dev->id &= 0xDFFFFFFF;
4695 ts = &task->task_status;
4696
4697 spin_lock_irqsave(&task->task_state_lock, flags);
4698 ts->resp = SAS_TASK_COMPLETE;
4699 ts->stat = SAM_STAT_GOOD;
4700 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4701 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4702 task->task_state_flags |= SAS_TASK_STATE_DONE;
4703 if (unlikely((task->task_state_flags &
4704 SAS_TASK_STATE_ABORTED))) {
4705 spin_unlock_irqrestore(&task->task_state_lock,
4706 flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08004707 pm8001_dbg(pm8001_ha, FAIL,
4708 "task 0x%p resp 0x%x stat 0x%x but aborted by upper layer\n",
4709 task, ts->resp,
4710 ts->stat);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304711 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
4712 return 0;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304713 } else {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304714 spin_unlock_irqrestore(&task->task_state_lock,
4715 flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304716 pm8001_ccb_task_free_done(pm8001_ha, task,
4717 ccb, tag);
Viswas G4a2efd42020-11-02 22:25:26 +05304718 atomic_dec(&pm8001_ha_dev->running_req);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304719 return 0;
4720 }
4721 }
4722 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304723 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304724 &sata_cmd, sizeof(sata_cmd), q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304725 return ret;
4726}
4727
4728/**
4729 * pm80xx_chip_phy_start_req - start phy via PHY_START COMMAND
4730 * @pm8001_ha: our hba card information.
Sakthivel Kf5860992013-04-17 16:37:02 +05304731 * @phy_id: the phy id which we wanted to start up.
4732 */
4733static int
4734pm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4735{
4736 struct phy_start_req payload;
4737 struct inbound_queue_table *circularQ;
4738 int ret;
4739 u32 tag = 0x01;
4740 u32 opcode = OPC_INB_PHYSTART;
4741 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4742 memset(&payload, 0, sizeof(payload));
4743 payload.tag = cpu_to_le32(tag);
4744
Joe Perches1b5d2792020-11-20 15:16:09 -08004745 pm8001_dbg(pm8001_ha, INIT, "PHY START REQ for phy_id %d\n", phy_id);
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05304746
peter chang3e253d92019-11-14 15:39:07 +05304747 payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4748 LINKMODE_AUTO | pm8001_ha->link_rate | phy_id);
Sakthivel Kf5860992013-04-17 16:37:02 +05304749 /* SSC Disable and SAS Analog ST configuration */
4750 /**
4751 payload.ase_sh_lm_slr_phyid =
4752 cpu_to_le32(SSC_DISABLE_30 | SAS_ASE | SPINHOLD_DISABLE |
4753 LINKMODE_AUTO | LINKRATE_15 | LINKRATE_30 | LINKRATE_60 |
4754 phy_id);
4755 Have to add "SAS PHY Analog Setup SPASTI 1 Byte" Based on need
4756 **/
4757
James Bottomleyaa9f8322013-05-07 14:44:06 -07004758 payload.sas_identify.dev_type = SAS_END_DEVICE;
Sakthivel Kf5860992013-04-17 16:37:02 +05304759 payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4760 memcpy(payload.sas_identify.sas_addr,
peter chang3e253d92019-11-14 15:39:07 +05304761 &pm8001_ha->sas_addr, SAS_ADDR_SIZE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304762 payload.sas_identify.phy_id = phy_id;
peter chang91a43fa2019-11-14 15:39:05 +05304763 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4764 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05304765 return ret;
4766}
4767
4768/**
Lee Jones7cdaf122021-03-03 14:46:23 +00004769 * pm80xx_chip_phy_stop_req - start phy via PHY_STOP COMMAND
Sakthivel Kf5860992013-04-17 16:37:02 +05304770 * @pm8001_ha: our hba card information.
Sakthivel Kf5860992013-04-17 16:37:02 +05304771 * @phy_id: the phy id which we wanted to start up.
4772 */
4773static int pm80xx_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4774 u8 phy_id)
4775{
4776 struct phy_stop_req payload;
4777 struct inbound_queue_table *circularQ;
4778 int ret;
4779 u32 tag = 0x01;
4780 u32 opcode = OPC_INB_PHYSTOP;
4781 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4782 memset(&payload, 0, sizeof(payload));
4783 payload.tag = cpu_to_le32(tag);
4784 payload.phy_id = cpu_to_le32(phy_id);
peter chang91a43fa2019-11-14 15:39:05 +05304785 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4786 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05304787 return ret;
4788}
4789
Lee Jones6ad4a512020-07-21 17:41:25 +01004790/*
Sakthivel Kf5860992013-04-17 16:37:02 +05304791 * see comments on pm8001_mpi_reg_resp.
4792 */
4793static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4794 struct pm8001_device *pm8001_dev, u32 flag)
4795{
4796 struct reg_dev_req payload;
4797 u32 opc;
4798 u32 stp_sspsmp_sata = 0x4;
4799 struct inbound_queue_table *circularQ;
4800 u32 linkrate, phy_id;
4801 int rc, tag = 0xdeadbeef;
4802 struct pm8001_ccb_info *ccb;
4803 u8 retryFlag = 0x1;
4804 u16 firstBurstSize = 0;
4805 u16 ITNT = 2000;
4806 struct domain_device *dev = pm8001_dev->sas_device;
4807 struct domain_device *parent_dev = dev->parent;
4808 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4809
4810 memset(&payload, 0, sizeof(payload));
4811 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4812 if (rc)
4813 return rc;
4814 ccb = &pm8001_ha->ccb_info[tag];
4815 ccb->device = pm8001_dev;
4816 ccb->ccb_tag = tag;
4817 payload.tag = cpu_to_le32(tag);
4818
4819 if (flag == 1) {
4820 stp_sspsmp_sata = 0x02; /*direct attached sata */
4821 } else {
James Bottomleyaa9f8322013-05-07 14:44:06 -07004822 if (pm8001_dev->dev_type == SAS_SATA_DEV)
Sakthivel Kf5860992013-04-17 16:37:02 +05304823 stp_sspsmp_sata = 0x00; /* stp*/
James Bottomleyaa9f8322013-05-07 14:44:06 -07004824 else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
4825 pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
4826 pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
Sakthivel Kf5860992013-04-17 16:37:02 +05304827 stp_sspsmp_sata = 0x01; /*ssp or smp*/
4828 }
John Garry924a3542019-06-10 20:41:41 +08004829 if (parent_dev && dev_is_expander(parent_dev->dev_type))
Sakthivel Kf5860992013-04-17 16:37:02 +05304830 phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4831 else
4832 phy_id = pm8001_dev->attached_phy;
4833
4834 opc = OPC_INB_REG_DEV;
4835
4836 linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4837 pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4838
4839 payload.phyid_portid =
4840 cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0xFF) |
4841 ((phy_id & 0xFF) << 8));
4842
4843 payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 0x01) |
4844 ((linkrate & 0x0F) << 24) |
4845 ((stp_sspsmp_sata & 0x03) << 28));
4846 payload.firstburstsize_ITNexustimeout =
4847 cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
4848
4849 memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
4850 SAS_ADDR_SIZE);
4851
peter chang91a43fa2019-11-14 15:39:05 +05304852 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4853 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304854 if (rc)
4855 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05304856
4857 return rc;
4858}
4859
4860/**
4861 * pm80xx_chip_phy_ctl_req - support the local phy operation
4862 * @pm8001_ha: our hba card information.
Lee Jones6ad4a512020-07-21 17:41:25 +01004863 * @phyId: the phy id which we wanted to operate
4864 * @phy_op: phy operation to request
Sakthivel Kf5860992013-04-17 16:37:02 +05304865 */
4866static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4867 u32 phyId, u32 phy_op)
4868{
Viswas G25c6edb2017-10-18 11:39:10 +05304869 u32 tag;
4870 int rc;
Sakthivel Kf5860992013-04-17 16:37:02 +05304871 struct local_phy_ctl_req payload;
4872 struct inbound_queue_table *circularQ;
Sakthivel Kf5860992013-04-17 16:37:02 +05304873 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
4874 memset(&payload, 0, sizeof(payload));
Viswas G25c6edb2017-10-18 11:39:10 +05304875 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4876 if (rc)
4877 return rc;
Sakthivel Kf5860992013-04-17 16:37:02 +05304878 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Viswas G25c6edb2017-10-18 11:39:10 +05304879 payload.tag = cpu_to_le32(tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05304880 payload.phyop_phyid =
4881 cpu_to_le32(((phy_op & 0xFF) << 8) | (phyId & 0xFF));
peter chang91a43fa2019-11-14 15:39:05 +05304882 return pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4883 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05304884}
4885
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004886static u32 pm80xx_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
Sakthivel Kf5860992013-04-17 16:37:02 +05304887{
Sakthivel Kf5860992013-04-17 16:37:02 +05304888#ifdef PM8001_USE_MSIX
4889 return 1;
Colin Ian King292c04c2019-03-28 23:43:28 +00004890#else
4891 u32 value;
4892
Sakthivel Kf5860992013-04-17 16:37:02 +05304893 value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4894 if (value)
4895 return 1;
4896 return 0;
Colin Ian King292c04c2019-03-28 23:43:28 +00004897#endif
Sakthivel Kf5860992013-04-17 16:37:02 +05304898}
4899
4900/**
Lee Jones7cdaf122021-03-03 14:46:23 +00004901 * pm80xx_chip_isr - PM8001 isr handler.
Sakthivel Kf5860992013-04-17 16:37:02 +05304902 * @pm8001_ha: our hba card information.
Lee Jones6ad4a512020-07-21 17:41:25 +01004903 * @vec: irq number.
Sakthivel Kf5860992013-04-17 16:37:02 +05304904 */
4905static irqreturn_t
4906pm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
4907{
4908 pm80xx_chip_interrupt_disable(pm8001_ha, vec);
Joe Perches1b5d2792020-11-20 15:16:09 -08004909 pm8001_dbg(pm8001_ha, DEVIO,
4910 "irq vec %d, ODMR:0x%x\n",
4911 vec, pm8001_cr32(pm8001_ha, 0, 0x30));
Sakthivel Kf5860992013-04-17 16:37:02 +05304912 process_oq(pm8001_ha, vec);
4913 pm80xx_chip_interrupt_enable(pm8001_ha, vec);
4914 return IRQ_HANDLED;
4915}
4916
Lee Jonesea310f52020-07-21 17:41:33 +01004917static void mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
4918 u32 operation, u32 phyid,
4919 u32 length, u32 *buf)
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304920{
4921 u32 tag , i, j = 0;
4922 int rc;
4923 struct set_phy_profile_req payload;
4924 struct inbound_queue_table *circularQ;
4925 u32 opc = OPC_INB_SET_PHY_PROFILE;
4926
4927 memset(&payload, 0, sizeof(payload));
4928 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4929 if (rc)
Joe Perches1b5d2792020-11-20 15:16:09 -08004930 pm8001_dbg(pm8001_ha, FAIL, "Invalid tag\n");
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304931 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4932 payload.tag = cpu_to_le32(tag);
4933 payload.ppc_phyid = (((operation & 0xF) << 8) | (phyid & 0xFF));
Joe Perches1b5d2792020-11-20 15:16:09 -08004934 pm8001_dbg(pm8001_ha, INIT,
4935 " phy profile command for phy %x ,length is %d\n",
4936 payload.ppc_phyid, length);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304937 for (i = length; i < (length + PHY_DWORD_LENGTH - 1); i++) {
4938 payload.reserved[j] = cpu_to_le32(*((u32 *)buf + i));
4939 j++;
4940 }
peter chang91a43fa2019-11-14 15:39:05 +05304941 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4942 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304943 if (rc)
4944 pm8001_tag_free(pm8001_ha, tag);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304945}
4946
4947void pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha,
4948 u32 length, u8 *buf)
4949{
YueHaibingfdd0a662018-09-14 01:38:56 +00004950 u32 i;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304951
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304952 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
4953 mpi_set_phy_profile_req(pm8001_ha,
4954 SAS_PHY_ANALOG_SETTINGS_PAGE, i, length, (u32 *)buf);
4955 length = length + PHY_DWORD_LENGTH;
4956 }
Joe Perches1b5d2792020-11-20 15:16:09 -08004957 pm8001_dbg(pm8001_ha, INIT, "phy settings completed\n");
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304958}
Benjamin Roodc5614df2015-10-30 10:53:28 -04004959
4960void pm8001_set_phy_profile_single(struct pm8001_hba_info *pm8001_ha,
4961 u32 phy, u32 length, u32 *buf)
4962{
4963 u32 tag, opc;
4964 int rc, i;
4965 struct set_phy_profile_req payload;
4966 struct inbound_queue_table *circularQ;
4967
4968 memset(&payload, 0, sizeof(payload));
4969
4970 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4971 if (rc)
Joe Perches1b5d2792020-11-20 15:16:09 -08004972 pm8001_dbg(pm8001_ha, INIT, "Invalid tag\n");
Benjamin Roodc5614df2015-10-30 10:53:28 -04004973
4974 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4975 opc = OPC_INB_SET_PHY_PROFILE;
4976
4977 payload.tag = cpu_to_le32(tag);
4978 payload.ppc_phyid = (((SAS_PHY_ANALOG_SETTINGS_PAGE & 0xF) << 8)
4979 | (phy & 0xFF));
4980
4981 for (i = 0; i < length; i++)
4982 payload.reserved[i] = cpu_to_le32(*(buf + i));
4983
peter chang91a43fa2019-11-14 15:39:05 +05304984 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4985 sizeof(payload), 0);
Benjamin Roodc5614df2015-10-30 10:53:28 -04004986 if (rc)
4987 pm8001_tag_free(pm8001_ha, tag);
4988
Joe Perches1b5d2792020-11-20 15:16:09 -08004989 pm8001_dbg(pm8001_ha, INIT, "PHY %d settings applied\n", phy);
Benjamin Roodc5614df2015-10-30 10:53:28 -04004990}
Sakthivel Kf5860992013-04-17 16:37:02 +05304991const struct pm8001_dispatch pm8001_80xx_dispatch = {
4992 .name = "pmc80xx",
4993 .chip_init = pm80xx_chip_init,
4994 .chip_soft_rst = pm80xx_chip_soft_rst,
4995 .chip_rst = pm80xx_hw_chip_rst,
4996 .chip_iounmap = pm8001_chip_iounmap,
4997 .isr = pm80xx_chip_isr,
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004998 .is_our_interrupt = pm80xx_chip_is_our_interrupt,
Sakthivel Kf5860992013-04-17 16:37:02 +05304999 .isr_process_oq = process_oq,
5000 .interrupt_enable = pm80xx_chip_interrupt_enable,
5001 .interrupt_disable = pm80xx_chip_interrupt_disable,
5002 .make_prd = pm8001_chip_make_sg,
5003 .smp_req = pm80xx_chip_smp_req,
5004 .ssp_io_req = pm80xx_chip_ssp_io_req,
5005 .sata_req = pm80xx_chip_sata_req,
5006 .phy_start_req = pm80xx_chip_phy_start_req,
5007 .phy_stop_req = pm80xx_chip_phy_stop_req,
5008 .reg_dev_req = pm80xx_chip_reg_dev_req,
5009 .dereg_dev_req = pm8001_chip_dereg_dev_req,
5010 .phy_ctl_req = pm80xx_chip_phy_ctl_req,
5011 .task_abort = pm8001_chip_abort_task,
5012 .ssp_tm_req = pm8001_chip_ssp_tm_req,
5013 .get_nvmd_req = pm8001_chip_get_nvmd_req,
5014 .set_nvmd_req = pm8001_chip_set_nvmd_req,
5015 .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
5016 .set_dev_state_req = pm8001_chip_set_dev_state_req,
akshatzena961ea02021-01-09 18:08:43 +05305017 .fatal_errors = pm80xx_fatal_errors,
Sakthivel Kf5860992013-04-17 16:37:02 +05305018};