blob: df679e36954a8fd938415dc126ea76a71e19b86a [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 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530361 /* 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(
371 pm8001_ha->forensic_info.data_buf.direct_data,
372 "%08x ", 4);
373 pm8001_ha->forensic_info.data_buf.read_len
374 = 0xFFFFFFFF;
375 pm8001_ha->forensic_info.data_buf.direct_len
376 = 0;
377 pm8001_ha->forensic_info.data_buf.direct_offset
378 = 0;
379 pm8001_ha->forensic_info.data_buf.read_len = 0;
380 }
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530381 }
Deepak Ukey044f59d2019-11-14 15:39:10 +0530382 offset = (int)((char *)pm8001_ha->forensic_info.data_buf.direct_data
383 - (char *)buf);
Joe Perches1b5d2792020-11-20 15:16:09 -0800384 pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: return4 0x%x\n", offset);
Viswas Gec2e7e12021-01-09 18:08:46 +0530385 return ((char *)pm8001_ha->forensic_info.data_buf.direct_data -
386 (char *)buf);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530387}
388
Deepak Ukeydba2cc02020-03-16 13:19:05 +0530389/* pm80xx_get_non_fatal_dump - dump the nonfatal data from the dma
390 * location by the firmware.
391 */
392ssize_t pm80xx_get_non_fatal_dump(struct device *cdev,
393 struct device_attribute *attr, char *buf)
394{
395 struct Scsi_Host *shost = class_to_shost(cdev);
396 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
397 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
398 void __iomem *nonfatal_table_address = pm8001_ha->fatal_tbl_addr;
399 u32 accum_len = 0;
400 u32 total_len = 0;
401 u32 reg_val = 0;
402 u32 *temp = NULL;
403 u32 index = 0;
404 u32 output_length;
405 unsigned long start = 0;
406 char *buf_copy = buf;
407
408 temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
409 if (++pm8001_ha->non_fatal_count == 1) {
410 if (pm8001_ha->chip_id == chip_8001) {
411 snprintf(pm8001_ha->forensic_info.data_buf.direct_data,
412 PAGE_SIZE, "Not supported for SPC controller");
413 return 0;
414 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800415 pm8001_dbg(pm8001_ha, IO, "forensic_info TYPE_NON_FATAL...\n");
Deepak Ukeydba2cc02020-03-16 13:19:05 +0530416 /*
417 * Step 1: Write the host buffer parameters in the MPI Fatal and
418 * Non-Fatal Error Dump Capture Table.This is the buffer
419 * where debug data will be DMAed to.
420 */
421 pm8001_mw32(nonfatal_table_address,
422 MPI_FATAL_EDUMP_TABLE_LO_OFFSET,
423 pm8001_ha->memoryMap.region[FORENSIC_MEM].phys_addr_lo);
424
425 pm8001_mw32(nonfatal_table_address,
426 MPI_FATAL_EDUMP_TABLE_HI_OFFSET,
427 pm8001_ha->memoryMap.region[FORENSIC_MEM].phys_addr_hi);
428
429 pm8001_mw32(nonfatal_table_address,
430 MPI_FATAL_EDUMP_TABLE_LENGTH, SYSFS_OFFSET);
431
432 /* Optionally, set the DUMPCTRL bit to 1 if the host
433 * keeps sending active I/Os while capturing the non-fatal
434 * debug data. Otherwise, leave this bit set to zero
435 */
436 pm8001_mw32(nonfatal_table_address,
437 MPI_FATAL_EDUMP_TABLE_HANDSHAKE, MPI_FATAL_EDUMP_HANDSHAKE_RDY);
438
439 /*
440 * Step 2: Clear Accumulative Length of Debug Data Transferred
441 * [ACCDDLEN] field in the MPI Fatal and Non-Fatal Error Dump
442 * Capture Table to zero.
443 */
444 pm8001_mw32(nonfatal_table_address,
445 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN, 0);
446
447 /* initiallize previous accumulated length to 0 */
448 pm8001_ha->forensic_preserved_accumulated_transfer = 0;
449 pm8001_ha->non_fatal_read_length = 0;
450 }
451
452 total_len = pm8001_mr32(nonfatal_table_address,
453 MPI_FATAL_EDUMP_TABLE_TOTAL_LEN);
454 /*
455 * Step 3:Clear Fatal/Non-Fatal Debug Data Transfer Status [FDDTSTAT]
456 * field and then request that the SPCv controller transfer the debug
457 * data by setting bit 7 of the Inbound Doorbell Set Register.
458 */
459 pm8001_mw32(nonfatal_table_address, MPI_FATAL_EDUMP_TABLE_STATUS, 0);
460 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET,
461 SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP);
462
463 /*
464 * Step 4.1: Read back the Inbound Doorbell Set Register (by polling for
465 * 2 seconds) until register bit 7 is cleared.
466 * This step only indicates the request is accepted by the controller.
467 */
468 start = jiffies + (2 * HZ); /* 2 sec */
469 do {
470 reg_val = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET) &
471 SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP;
472 } while ((reg_val != 0) && time_before(jiffies, start));
473
474 /* Step 4.2: To check the completion of the transfer, poll the Fatal/Non
475 * Fatal Debug Data Transfer Status [FDDTSTAT] field for 2 seconds in
476 * the MPI Fatal and Non-Fatal Error Dump Capture Table.
477 */
478 start = jiffies + (2 * HZ); /* 2 sec */
479 do {
480 reg_val = pm8001_mr32(nonfatal_table_address,
481 MPI_FATAL_EDUMP_TABLE_STATUS);
482 } while ((!reg_val) && time_before(jiffies, start));
483
484 if ((reg_val == 0x00) ||
485 (reg_val == MPI_FATAL_EDUMP_TABLE_STAT_DMA_FAILED) ||
486 (reg_val > MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE)) {
487 pm8001_ha->non_fatal_read_length = 0;
488 buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 0xFFFFFFFF);
489 pm8001_ha->non_fatal_count = 0;
490 return (buf_copy - buf);
491 } else if (reg_val ==
492 MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_MORE_DATA) {
493 buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 2);
494 } else if ((reg_val == MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) ||
495 (pm8001_ha->non_fatal_read_length >= total_len)) {
496 pm8001_ha->non_fatal_read_length = 0;
497 buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 4);
498 pm8001_ha->non_fatal_count = 0;
499 }
500 accum_len = pm8001_mr32(nonfatal_table_address,
501 MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
502 output_length = accum_len -
503 pm8001_ha->forensic_preserved_accumulated_transfer;
504
505 for (index = 0; index < output_length/4; index++)
506 buf_copy += snprintf(buf_copy, PAGE_SIZE,
507 "%08x ", *(temp+index));
508
509 pm8001_ha->non_fatal_read_length += output_length;
510
511 /* store current accumulated length to use in next iteration as
512 * the previous accumulated length
513 */
514 pm8001_ha->forensic_preserved_accumulated_transfer = accum_len;
515 return (buf_copy - buf);
516}
517
Sakthivel Kf5860992013-04-17 16:37:02 +0530518/**
519 * read_main_config_table - read the configure table and save it.
520 * @pm8001_ha: our hba card information
521 */
522static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
523{
524 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
525
526 pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature =
527 pm8001_mr32(address, MAIN_SIGNATURE_OFFSET);
528 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev =
529 pm8001_mr32(address, MAIN_INTERFACE_REVISION);
530 pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev =
531 pm8001_mr32(address, MAIN_FW_REVISION);
532 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io =
533 pm8001_mr32(address, MAIN_MAX_OUTSTANDING_IO_OFFSET);
534 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl =
535 pm8001_mr32(address, MAIN_MAX_SGL_OFFSET);
536 pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag =
537 pm8001_mr32(address, MAIN_CNTRL_CAP_OFFSET);
538 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset =
539 pm8001_mr32(address, MAIN_GST_OFFSET);
540 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset =
541 pm8001_mr32(address, MAIN_IBQ_OFFSET);
542 pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset =
543 pm8001_mr32(address, MAIN_OBQ_OFFSET);
544
545 /* read Error Dump Offset and Length */
546 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset0 =
547 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
548 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length0 =
549 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
550 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset1 =
551 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
552 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length1 =
553 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
554
555 /* read GPIO LED settings from the configuration table */
556 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping =
557 pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET);
558
559 /* read analog Setting offset from the configuration table */
560 pm8001_ha->main_cfg_tbl.pm80xx_tbl.analog_setup_table_offset =
561 pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
562
563 pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset =
564 pm8001_mr32(address, MAIN_INT_VECTOR_TABLE_OFFSET);
565 pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset =
566 pm8001_mr32(address, MAIN_SAS_PHY_ATTR_TABLE_OFFSET);
Viswas G8414cd82015-08-11 15:06:30 +0530567 /* read port recover and reset timeout */
568 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer =
569 pm8001_mr32(address, MAIN_PORT_RECOVERY_TIMER);
Viswas G24fff012017-10-18 11:39:08 +0530570 /* read ILA and inactive firmware version */
571 pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version =
572 pm8001_mr32(address, MAIN_MPI_ILA_RELEASE_TYPE);
573 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version =
574 pm8001_mr32(address, MAIN_MPI_INACTIVE_FW_VERSION);
peter chang73706722019-11-14 15:39:02 +0530575
Joe Perches1b5d2792020-11-20 15:16:09 -0800576 pm8001_dbg(pm8001_ha, DEV,
577 "Main cfg table: sign:%x interface rev:%x fw_rev:%x\n",
578 pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature,
579 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev,
580 pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev);
peter chang73706722019-11-14 15:39:02 +0530581
Joe Perches1b5d2792020-11-20 15:16:09 -0800582 pm8001_dbg(pm8001_ha, DEV,
583 "table offset: gst:%x iq:%x oq:%x int vec:%x phy attr:%x\n",
584 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset,
585 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset,
586 pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset,
587 pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset,
588 pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset);
peter chang73706722019-11-14 15:39:02 +0530589
Joe Perches1b5d2792020-11-20 15:16:09 -0800590 pm8001_dbg(pm8001_ha, DEV,
591 "Main cfg table; ila rev:%x Inactive fw rev:%x\n",
592 pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version,
593 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version);
Sakthivel Kf5860992013-04-17 16:37:02 +0530594}
595
596/**
597 * read_general_status_table - read the general status table and save it.
598 * @pm8001_ha: our hba card information
599 */
600static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
601{
602 void __iomem *address = pm8001_ha->general_stat_tbl_addr;
603 pm8001_ha->gs_tbl.pm80xx_tbl.gst_len_mpistate =
604 pm8001_mr32(address, GST_GSTLEN_MPIS_OFFSET);
605 pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state0 =
606 pm8001_mr32(address, GST_IQ_FREEZE_STATE0_OFFSET);
607 pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state1 =
608 pm8001_mr32(address, GST_IQ_FREEZE_STATE1_OFFSET);
609 pm8001_ha->gs_tbl.pm80xx_tbl.msgu_tcnt =
610 pm8001_mr32(address, GST_MSGUTCNT_OFFSET);
611 pm8001_ha->gs_tbl.pm80xx_tbl.iop_tcnt =
612 pm8001_mr32(address, GST_IOPTCNT_OFFSET);
613 pm8001_ha->gs_tbl.pm80xx_tbl.gpio_input_val =
614 pm8001_mr32(address, GST_GPIO_INPUT_VAL);
615 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[0] =
616 pm8001_mr32(address, GST_RERRINFO_OFFSET0);
617 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[1] =
618 pm8001_mr32(address, GST_RERRINFO_OFFSET1);
619 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[2] =
620 pm8001_mr32(address, GST_RERRINFO_OFFSET2);
621 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[3] =
622 pm8001_mr32(address, GST_RERRINFO_OFFSET3);
623 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[4] =
624 pm8001_mr32(address, GST_RERRINFO_OFFSET4);
625 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[5] =
626 pm8001_mr32(address, GST_RERRINFO_OFFSET5);
627 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[6] =
628 pm8001_mr32(address, GST_RERRINFO_OFFSET6);
629 pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[7] =
630 pm8001_mr32(address, GST_RERRINFO_OFFSET7);
631}
632/**
633 * read_phy_attr_table - read the phy attribute table and save it.
634 * @pm8001_ha: our hba card information
635 */
636static void read_phy_attr_table(struct pm8001_hba_info *pm8001_ha)
637{
638 void __iomem *address = pm8001_ha->pspa_q_tbl_addr;
639 pm8001_ha->phy_attr_table.phystart1_16[0] =
640 pm8001_mr32(address, PSPA_PHYSTATE0_OFFSET);
641 pm8001_ha->phy_attr_table.phystart1_16[1] =
642 pm8001_mr32(address, PSPA_PHYSTATE1_OFFSET);
643 pm8001_ha->phy_attr_table.phystart1_16[2] =
644 pm8001_mr32(address, PSPA_PHYSTATE2_OFFSET);
645 pm8001_ha->phy_attr_table.phystart1_16[3] =
646 pm8001_mr32(address, PSPA_PHYSTATE3_OFFSET);
647 pm8001_ha->phy_attr_table.phystart1_16[4] =
648 pm8001_mr32(address, PSPA_PHYSTATE4_OFFSET);
649 pm8001_ha->phy_attr_table.phystart1_16[5] =
650 pm8001_mr32(address, PSPA_PHYSTATE5_OFFSET);
651 pm8001_ha->phy_attr_table.phystart1_16[6] =
652 pm8001_mr32(address, PSPA_PHYSTATE6_OFFSET);
653 pm8001_ha->phy_attr_table.phystart1_16[7] =
654 pm8001_mr32(address, PSPA_PHYSTATE7_OFFSET);
655 pm8001_ha->phy_attr_table.phystart1_16[8] =
656 pm8001_mr32(address, PSPA_PHYSTATE8_OFFSET);
657 pm8001_ha->phy_attr_table.phystart1_16[9] =
658 pm8001_mr32(address, PSPA_PHYSTATE9_OFFSET);
659 pm8001_ha->phy_attr_table.phystart1_16[10] =
660 pm8001_mr32(address, PSPA_PHYSTATE10_OFFSET);
661 pm8001_ha->phy_attr_table.phystart1_16[11] =
662 pm8001_mr32(address, PSPA_PHYSTATE11_OFFSET);
663 pm8001_ha->phy_attr_table.phystart1_16[12] =
664 pm8001_mr32(address, PSPA_PHYSTATE12_OFFSET);
665 pm8001_ha->phy_attr_table.phystart1_16[13] =
666 pm8001_mr32(address, PSPA_PHYSTATE13_OFFSET);
667 pm8001_ha->phy_attr_table.phystart1_16[14] =
668 pm8001_mr32(address, PSPA_PHYSTATE14_OFFSET);
669 pm8001_ha->phy_attr_table.phystart1_16[15] =
670 pm8001_mr32(address, PSPA_PHYSTATE15_OFFSET);
671
672 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[0] =
673 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID0_OFFSET);
674 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[1] =
675 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID1_OFFSET);
676 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[2] =
677 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID2_OFFSET);
678 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[3] =
679 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID3_OFFSET);
680 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[4] =
681 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID4_OFFSET);
682 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[5] =
683 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID5_OFFSET);
684 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[6] =
685 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID6_OFFSET);
686 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[7] =
687 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID7_OFFSET);
688 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[8] =
689 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID8_OFFSET);
690 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[9] =
691 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID9_OFFSET);
692 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[10] =
693 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID10_OFFSET);
694 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[11] =
695 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID11_OFFSET);
696 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[12] =
697 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID12_OFFSET);
698 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[13] =
699 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID13_OFFSET);
700 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[14] =
701 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID14_OFFSET);
702 pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[15] =
703 pm8001_mr32(address, PSPA_OB_HW_EVENT_PID15_OFFSET);
704
705}
706
707/**
708 * read_inbnd_queue_table - read the inbound queue table and save it.
709 * @pm8001_ha: our hba card information
710 */
711static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
712{
713 int i;
714 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530715 for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530716 u32 offset = i * 0x20;
717 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
718 get_pci_bar_index(pm8001_mr32(address,
719 (offset + IB_PIPCI_BAR)));
720 pm8001_ha->inbnd_q_tbl[i].pi_offset =
721 pm8001_mr32(address, (offset + IB_PIPCI_BAR_OFFSET));
722 }
723}
724
725/**
726 * read_outbnd_queue_table - read the outbound queue table and save it.
727 * @pm8001_ha: our hba card information
728 */
729static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
730{
731 int i;
732 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530733 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530734 u32 offset = i * 0x24;
735 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
736 get_pci_bar_index(pm8001_mr32(address,
737 (offset + OB_CIPCI_BAR)));
738 pm8001_ha->outbnd_q_tbl[i].ci_offset =
739 pm8001_mr32(address, (offset + OB_CIPCI_BAR_OFFSET));
740 }
741}
742
743/**
744 * init_default_table_values - init the default table.
745 * @pm8001_ha: our hba card information
746 */
747static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
748{
749 int i;
750 u32 offsetib, offsetob;
751 void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
752 void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530753 u32 ib_offset = pm8001_ha->ib_offset;
754 u32 ob_offset = pm8001_ha->ob_offset;
755 u32 ci_offset = pm8001_ha->ci_offset;
756 u32 pi_offset = pm8001_ha->pi_offset;
Sakthivel Kf5860992013-04-17 16:37:02 +0530757
758 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr =
759 pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
760 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr =
761 pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
762 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size =
763 PM8001_EVENT_LOG_SIZE;
764 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity = 0x01;
765 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr =
766 pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
767 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr =
768 pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
769 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size =
770 PM8001_EVENT_LOG_SIZE;
771 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity = 0x01;
772 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt = 0x01;
773
Sakthivel Kc6b9ef52013-03-19 18:08:08 +0530774 /* Disable end to end CRC checking */
775 pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump = (0x1 << 16);
776
Viswas G05c6c022020-10-05 20:20:08 +0530777 for (i = 0; i < pm8001_ha->max_q_num; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530778 pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200779 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
Sakthivel Kf5860992013-04-17 16:37:02 +0530780 pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530781 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530782 pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530783 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530784 pm8001_ha->inbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530785 (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530786 pm8001_ha->inbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530787 pm8001_ha->memoryMap.region[ib_offset + i].total_len;
Sakthivel Kf5860992013-04-17 16:37:02 +0530788 pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530789 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530790 pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530791 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530792 pm8001_ha->inbnd_q_tbl[i].ci_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530793 pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530794 offsetib = i * 0x20;
795 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
796 get_pci_bar_index(pm8001_mr32(addressib,
797 (offsetib + 0x14)));
798 pm8001_ha->inbnd_q_tbl[i].pi_offset =
799 pm8001_mr32(addressib, (offsetib + 0x18));
800 pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
801 pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
peter chang73706722019-11-14 15:39:02 +0530802
Joe Perches1b5d2792020-11-20 15:16:09 -0800803 pm8001_dbg(pm8001_ha, DEV,
804 "IQ %d pi_bar 0x%x pi_offset 0x%x\n", i,
805 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar,
806 pm8001_ha->inbnd_q_tbl[i].pi_offset);
Sakthivel Kf5860992013-04-17 16:37:02 +0530807 }
Viswas G05c6c022020-10-05 20:20:08 +0530808 for (i = 0; i < pm8001_ha->max_q_num; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +0530809 pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200810 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
Sakthivel Kf5860992013-04-17 16:37:02 +0530811 pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530812 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530813 pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530814 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530815 pm8001_ha->outbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530816 (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530817 pm8001_ha->outbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530818 pm8001_ha->memoryMap.region[ob_offset + i].total_len;
Sakthivel Kf5860992013-04-17 16:37:02 +0530819 pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530820 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
Sakthivel Kf5860992013-04-17 16:37:02 +0530821 pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530822 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
Sakthivel Kf5860992013-04-17 16:37:02 +0530823 /* interrupt vector based on oq */
824 pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = (i << 24);
825 pm8001_ha->outbnd_q_tbl[i].pi_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530826 pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
Sakthivel Kf5860992013-04-17 16:37:02 +0530827 offsetob = i * 0x24;
828 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
829 get_pci_bar_index(pm8001_mr32(addressob,
830 offsetob + 0x14));
831 pm8001_ha->outbnd_q_tbl[i].ci_offset =
832 pm8001_mr32(addressob, (offsetob + 0x18));
833 pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
834 pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
peter chang73706722019-11-14 15:39:02 +0530835
Joe Perches1b5d2792020-11-20 15:16:09 -0800836 pm8001_dbg(pm8001_ha, DEV,
837 "OQ %d ci_bar 0x%x ci_offset 0x%x\n", i,
838 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar,
839 pm8001_ha->outbnd_q_tbl[i].ci_offset);
Sakthivel Kf5860992013-04-17 16:37:02 +0530840 }
841}
842
843/**
844 * update_main_config_table - update the main default table to the HBA.
845 * @pm8001_ha: our hba card information
846 */
847static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
848{
849 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
850 pm8001_mw32(address, MAIN_IQNPPD_HPPD_OFFSET,
851 pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_q_nppd_hppd);
852 pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_HI,
853 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr);
854 pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_LO,
855 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr);
856 pm8001_mw32(address, MAIN_EVENT_LOG_BUFF_SIZE,
857 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
858 pm8001_mw32(address, MAIN_EVENT_LOG_OPTION,
859 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity);
860 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_HI,
861 pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr);
862 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_LO,
863 pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr);
864 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_BUFF_SIZE,
865 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size);
866 pm8001_mw32(address, MAIN_PCS_EVENT_LOG_OPTION,
867 pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity);
Deepak Ukey72349b62018-09-11 14:18:04 +0530868 /* Update Fatal error interrupt vector */
869 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt |=
Viswas G05c6c022020-10-05 20:20:08 +0530870 ((pm8001_ha->max_q_num - 1) << 8);
Sakthivel Kf5860992013-04-17 16:37:02 +0530871 pm8001_mw32(address, MAIN_FATAL_ERROR_INTERRUPT,
872 pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt);
Joe Perches1b5d2792020-11-20 15:16:09 -0800873 pm8001_dbg(pm8001_ha, DEV,
874 "Updated Fatal error interrupt vector 0x%x\n",
875 pm8001_mr32(address, MAIN_FATAL_ERROR_INTERRUPT));
peter chang73706722019-11-14 15:39:02 +0530876
Sakthivel Kc6b9ef52013-03-19 18:08:08 +0530877 pm8001_mw32(address, MAIN_EVENT_CRC_CHECK,
878 pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump);
Sakthivel Kf5860992013-04-17 16:37:02 +0530879
880 /* SPCv specific */
881 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping &= 0xCFFFFFFF;
882 /* Set GPIOLED to 0x2 for LED indicator */
883 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping |= 0x20000000;
884 pm8001_mw32(address, MAIN_GPIO_LED_FLAGS_OFFSET,
885 pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping);
Joe Perches1b5d2792020-11-20 15:16:09 -0800886 pm8001_dbg(pm8001_ha, DEV,
887 "Programming DW 0x21 in main cfg table with 0x%x\n",
888 pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET));
Sakthivel Kf5860992013-04-17 16:37:02 +0530889
890 pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
891 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
892 pm8001_mw32(address, MAIN_INT_REASSERTION_DELAY,
893 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interrupt_reassertion_delay);
Viswas G8414cd82015-08-11 15:06:30 +0530894
895 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &= 0xffff0000;
896 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
897 PORT_RECOVERY_TIMEOUT;
Viswas G61daffd2017-10-18 11:39:12 +0530898 if (pm8001_ha->chip_id == chip_8006) {
899 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &=
900 0x0000ffff;
901 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
Deepak Ukey196ba662019-07-09 15:30:48 +0530902 CHIP_8006_PORT_RECOVERY_TIMEOUT;
Viswas G61daffd2017-10-18 11:39:12 +0530903 }
Viswas G8414cd82015-08-11 15:06:30 +0530904 pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
905 pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
Sakthivel Kf5860992013-04-17 16:37:02 +0530906}
907
908/**
909 * update_inbnd_queue_table - update the inbound queue table to the HBA.
910 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +0100911 * @number: entry in the queue
Sakthivel Kf5860992013-04-17 16:37:02 +0530912 */
913static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
914 int number)
915{
916 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
917 u16 offset = number * 0x20;
918 pm8001_mw32(address, offset + IB_PROPERITY_OFFSET,
919 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
920 pm8001_mw32(address, offset + IB_BASE_ADDR_HI_OFFSET,
921 pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
922 pm8001_mw32(address, offset + IB_BASE_ADDR_LO_OFFSET,
923 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
924 pm8001_mw32(address, offset + IB_CI_BASE_ADDR_HI_OFFSET,
925 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
926 pm8001_mw32(address, offset + IB_CI_BASE_ADDR_LO_OFFSET,
927 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
peter chang73706722019-11-14 15:39:02 +0530928
Joe Perches1b5d2792020-11-20 15:16:09 -0800929 pm8001_dbg(pm8001_ha, DEV,
930 "IQ %d: Element pri size 0x%x\n",
931 number,
932 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
peter chang73706722019-11-14 15:39:02 +0530933
Joe Perches1b5d2792020-11-20 15:16:09 -0800934 pm8001_dbg(pm8001_ha, DEV,
935 "IQ upr base addr 0x%x IQ lwr base addr 0x%x\n",
936 pm8001_ha->inbnd_q_tbl[number].upper_base_addr,
937 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
peter chang73706722019-11-14 15:39:02 +0530938
Joe Perches1b5d2792020-11-20 15:16:09 -0800939 pm8001_dbg(pm8001_ha, DEV,
940 "CI upper base addr 0x%x CI lower base addr 0x%x\n",
941 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr,
942 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
Sakthivel Kf5860992013-04-17 16:37:02 +0530943}
944
945/**
946 * update_outbnd_queue_table - update the outbound queue table to the HBA.
947 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +0100948 * @number: entry in the queue
Sakthivel Kf5860992013-04-17 16:37:02 +0530949 */
950static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
951 int number)
952{
953 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
954 u16 offset = number * 0x24;
955 pm8001_mw32(address, offset + OB_PROPERITY_OFFSET,
956 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
957 pm8001_mw32(address, offset + OB_BASE_ADDR_HI_OFFSET,
958 pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
959 pm8001_mw32(address, offset + OB_BASE_ADDR_LO_OFFSET,
960 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
961 pm8001_mw32(address, offset + OB_PI_BASE_ADDR_HI_OFFSET,
962 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
963 pm8001_mw32(address, offset + OB_PI_BASE_ADDR_LO_OFFSET,
964 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
965 pm8001_mw32(address, offset + OB_INTERRUPT_COALES_OFFSET,
966 pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
peter chang73706722019-11-14 15:39:02 +0530967
Joe Perches1b5d2792020-11-20 15:16:09 -0800968 pm8001_dbg(pm8001_ha, DEV,
969 "OQ %d: Element pri size 0x%x\n",
970 number,
971 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
peter chang73706722019-11-14 15:39:02 +0530972
Joe Perches1b5d2792020-11-20 15:16:09 -0800973 pm8001_dbg(pm8001_ha, DEV,
974 "OQ upr base addr 0x%x OQ lwr base addr 0x%x\n",
975 pm8001_ha->outbnd_q_tbl[number].upper_base_addr,
976 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
peter chang73706722019-11-14 15:39:02 +0530977
Joe Perches1b5d2792020-11-20 15:16:09 -0800978 pm8001_dbg(pm8001_ha, DEV,
979 "PI upper base addr 0x%x PI lower base addr 0x%x\n",
980 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr,
981 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
Sakthivel Kf5860992013-04-17 16:37:02 +0530982}
983
984/**
985 * mpi_init_check - check firmware initialization status.
986 * @pm8001_ha: our hba card information
987 */
988static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
989{
990 u32 max_wait_count;
991 u32 value;
992 u32 gst_len_mpistate;
993
994 /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
995 table is updated */
996 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_UPDATE);
997 /* wait until Inbound DoorBell Clear Register toggled */
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +0530998 if (IS_SPCV_12G(pm8001_ha->pdev)) {
ianyare90e23622019-11-14 15:39:03 +0530999 max_wait_count = SPCV_DOORBELL_CLEAR_TIMEOUT;
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301000 } else {
ianyare90e23622019-11-14 15:39:03 +05301001 max_wait_count = SPC_DOORBELL_CLEAR_TIMEOUT;
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301002 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301003 do {
akshatzend71023a2021-01-09 18:08:42 +05301004 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301005 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1006 value &= SPCv_MSGU_CFG_TABLE_UPDATE;
1007 } while ((value != 0) && (--max_wait_count));
1008
Viswas G05c6c022020-10-05 20:20:08 +05301009 if (!max_wait_count) {
1010 /* additional check */
Joe Perches1b5d2792020-11-20 15:16:09 -08001011 pm8001_dbg(pm8001_ha, FAIL,
1012 "Inb doorbell clear not toggled[value:%x]\n",
1013 value);
Viswas G05c6c022020-10-05 20:20:08 +05301014 return -EBUSY;
1015 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301016 /* check the MPI-State for initialization upto 100ms*/
akshatzend71023a2021-01-09 18:08:42 +05301017 max_wait_count = 5;/* 100 msec */
Sakthivel Kf5860992013-04-17 16:37:02 +05301018 do {
akshatzend71023a2021-01-09 18:08:42 +05301019 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301020 gst_len_mpistate =
1021 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1022 GST_GSTLEN_MPIS_OFFSET);
1023 } while ((GST_MPI_STATE_INIT !=
1024 (gst_len_mpistate & GST_MPI_STATE_MASK)) && (--max_wait_count));
1025 if (!max_wait_count)
Viswas G05c6c022020-10-05 20:20:08 +05301026 return -EBUSY;
Sakthivel Kf5860992013-04-17 16:37:02 +05301027
1028 /* check MPI Initialization error */
1029 gst_len_mpistate = gst_len_mpistate >> 16;
1030 if (0x0000 != gst_len_mpistate)
Viswas G05c6c022020-10-05 20:20:08 +05301031 return -EBUSY;
Sakthivel Kf5860992013-04-17 16:37:02 +05301032
1033 return 0;
1034}
1035
1036/**
1037 * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
akshatzen48cd6b32020-11-02 22:25:27 +05301038 * This function sleeps hence it must not be used in atomic context.
Sakthivel Kf5860992013-04-17 16:37:02 +05301039 * @pm8001_ha: our hba card information
1040 */
1041static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
1042{
1043 u32 value;
1044 u32 max_wait_count;
1045 u32 max_wait_time;
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301046 u32 expected_mask;
Sakthivel Kf5860992013-04-17 16:37:02 +05301047 int ret = 0;
1048
1049 /* reset / PCIe ready */
akshatzen48cd6b32020-11-02 22:25:27 +05301050 max_wait_time = max_wait_count = 5; /* 100 milli sec */
Sakthivel Kf5860992013-04-17 16:37:02 +05301051 do {
akshatzen48cd6b32020-11-02 22:25:27 +05301052 msleep(FW_READY_INTERVAL);
Sakthivel Kf5860992013-04-17 16:37:02 +05301053 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1054 } while ((value == 0xFFFFFFFF) && (--max_wait_count));
1055
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301056 /* check ila, RAAE and iops status */
Sakthivel Kf5860992013-04-17 16:37:02 +05301057 if ((pm8001_ha->chip_id != chip_8008) &&
1058 (pm8001_ha->chip_id != chip_8009)) {
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301059 max_wait_time = max_wait_count = 180; /* 3600 milli sec */
1060 expected_mask = SCRATCH_PAD_ILA_READY |
1061 SCRATCH_PAD_RAAE_READY |
1062 SCRATCH_PAD_IOP0_READY |
1063 SCRATCH_PAD_IOP1_READY;
1064 } else {
1065 max_wait_time = max_wait_count = 170; /* 3400 milli sec */
1066 expected_mask = SCRATCH_PAD_ILA_READY |
1067 SCRATCH_PAD_RAAE_READY |
1068 SCRATCH_PAD_IOP0_READY;
Sakthivel Kf5860992013-04-17 16:37:02 +05301069 }
Bhavesh Jashnani6b2f2d02021-01-09 18:08:47 +05301070 do {
1071 msleep(FW_READY_INTERVAL);
1072 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1073 } while (((value & expected_mask) !=
1074 expected_mask) && (--max_wait_count));
1075 if (!max_wait_count) {
1076 pm8001_dbg(pm8001_ha, INIT,
1077 "At least one FW component failed to load within %d millisec: Scratchpad1: 0x%x\n",
1078 max_wait_time * FW_READY_INTERVAL, value);
1079 ret = -1;
1080 } else {
1081 pm8001_dbg(pm8001_ha, MSG,
1082 "All FW components ready by %d ms\n",
1083 (max_wait_time - max_wait_count) * FW_READY_INTERVAL);
1084 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301085 return ret;
1086}
1087
akshatzen95652f92021-01-09 18:08:44 +05301088static int init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
Sakthivel Kf5860992013-04-17 16:37:02 +05301089{
1090 void __iomem *base_addr;
1091 u32 value;
1092 u32 offset;
1093 u32 pcibar;
1094 u32 pcilogic;
1095
1096 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
akshatzen95652f92021-01-09 18:08:44 +05301097
1098 /**
1099 * lower 26 bits of SCRATCHPAD0 register describes offset within the
1100 * PCIe BAR where the MPI configuration table is present
1101 */
Sakthivel Kf5860992013-04-17 16:37:02 +05301102 offset = value & 0x03FFFFFF; /* scratch pad 0 TBL address */
1103
Joe Perches1b5d2792020-11-20 15:16:09 -08001104 pm8001_dbg(pm8001_ha, DEV, "Scratchpad 0 Offset: 0x%x value 0x%x\n",
1105 offset, value);
akshatzen95652f92021-01-09 18:08:44 +05301106 /**
1107 * Upper 6 bits describe the offset within PCI config space where BAR
1108 * is located.
1109 */
Sakthivel Kf5860992013-04-17 16:37:02 +05301110 pcilogic = (value & 0xFC000000) >> 26;
1111 pcibar = get_pci_bar_index(pcilogic);
Joe Perches1b5d2792020-11-20 15:16:09 -08001112 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar);
akshatzen95652f92021-01-09 18:08:44 +05301113
1114 /**
1115 * Make sure the offset falls inside the ioremapped PCI BAR
1116 */
1117 if (offset > pm8001_ha->io_mem[pcibar].memsize) {
1118 pm8001_dbg(pm8001_ha, FAIL,
1119 "Main cfg tbl offset outside %u > %u\n",
1120 offset, pm8001_ha->io_mem[pcibar].memsize);
1121 return -EBUSY;
1122 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301123 pm8001_ha->main_cfg_tbl_addr = base_addr =
1124 pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
akshatzen95652f92021-01-09 18:08:44 +05301125
1126 /**
1127 * Validate main configuration table address: first DWord should read
1128 * "PMCS"
1129 */
1130 value = pm8001_mr32(pm8001_ha->main_cfg_tbl_addr, 0);
1131 if (memcmp(&value, "PMCS", 4) != 0) {
1132 pm8001_dbg(pm8001_ha, FAIL,
1133 "BAD main config signature 0x%x\n",
1134 value);
1135 return -EBUSY;
1136 }
1137 pm8001_dbg(pm8001_ha, INIT,
1138 "VALID main config signature 0x%x\n", value);
Sakthivel Kf5860992013-04-17 16:37:02 +05301139 pm8001_ha->general_stat_tbl_addr =
1140 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x18) &
1141 0xFFFFFF);
1142 pm8001_ha->inbnd_q_tbl_addr =
1143 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C) &
1144 0xFFFFFF);
1145 pm8001_ha->outbnd_q_tbl_addr =
1146 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x20) &
1147 0xFFFFFF);
1148 pm8001_ha->ivt_tbl_addr =
1149 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C) &
1150 0xFFFFFF);
1151 pm8001_ha->pspa_q_tbl_addr =
1152 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x90) &
1153 0xFFFFFF);
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05301154 pm8001_ha->fatal_tbl_addr =
1155 base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0xA0) &
1156 0xFFFFFF);
Sakthivel Kf5860992013-04-17 16:37:02 +05301157
Joe Perches1b5d2792020-11-20 15:16:09 -08001158 pm8001_dbg(pm8001_ha, INIT, "GST OFFSET 0x%x\n",
1159 pm8001_cr32(pm8001_ha, pcibar, offset + 0x18));
1160 pm8001_dbg(pm8001_ha, INIT, "INBND OFFSET 0x%x\n",
1161 pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C));
1162 pm8001_dbg(pm8001_ha, INIT, "OBND OFFSET 0x%x\n",
1163 pm8001_cr32(pm8001_ha, pcibar, offset + 0x20));
1164 pm8001_dbg(pm8001_ha, INIT, "IVT OFFSET 0x%x\n",
1165 pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C));
1166 pm8001_dbg(pm8001_ha, INIT, "PSPA OFFSET 0x%x\n",
1167 pm8001_cr32(pm8001_ha, pcibar, offset + 0x90));
1168 pm8001_dbg(pm8001_ha, INIT, "addr - main cfg %p general status %p\n",
1169 pm8001_ha->main_cfg_tbl_addr,
1170 pm8001_ha->general_stat_tbl_addr);
1171 pm8001_dbg(pm8001_ha, INIT, "addr - inbnd %p obnd %p\n",
1172 pm8001_ha->inbnd_q_tbl_addr,
1173 pm8001_ha->outbnd_q_tbl_addr);
1174 pm8001_dbg(pm8001_ha, INIT, "addr - pspa %p ivt %p\n",
1175 pm8001_ha->pspa_q_tbl_addr,
1176 pm8001_ha->ivt_tbl_addr);
akshatzen95652f92021-01-09 18:08:44 +05301177 return 0;
Sakthivel Kf5860992013-04-17 16:37:02 +05301178}
1179
1180/**
1181 * pm80xx_set_thermal_config - support the thermal configuration
1182 * @pm8001_ha: our hba card information.
1183 */
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301184int
Sakthivel Kf5860992013-04-17 16:37:02 +05301185pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha)
1186{
1187 struct set_ctrl_cfg_req payload;
1188 struct inbound_queue_table *circularQ;
1189 int rc;
1190 u32 tag;
1191 u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
Viswas G842784e2015-08-11 15:06:27 +05301192 u32 page_code;
Sakthivel Kf5860992013-04-17 16:37:02 +05301193
1194 memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
1195 rc = pm8001_tag_alloc(pm8001_ha, &tag);
1196 if (rc)
1197 return -1;
1198
1199 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1200 payload.tag = cpu_to_le32(tag);
Viswas G842784e2015-08-11 15:06:27 +05301201
1202 if (IS_SPCV_12G(pm8001_ha->pdev))
1203 page_code = THERMAL_PAGE_CODE_7H;
1204 else
1205 page_code = THERMAL_PAGE_CODE_8H;
1206
Sakthivel Kf5860992013-04-17 16:37:02 +05301207 payload.cfg_pg[0] = (THERMAL_LOG_ENABLE << 9) |
Viswas G842784e2015-08-11 15:06:27 +05301208 (THERMAL_ENABLE << 8) | page_code;
Sakthivel Kf5860992013-04-17 16:37:02 +05301209 payload.cfg_pg[1] = (LTEMPHIL << 24) | (RTEMPHIL << 8);
1210
Joe Perches1b5d2792020-11-20 15:16:09 -08001211 pm8001_dbg(pm8001_ha, DEV,
1212 "Setting up thermal config. cfg_pg 0 0x%x cfg_pg 1 0x%x\n",
1213 payload.cfg_pg[0], payload.cfg_pg[1]);
peter chang73706722019-11-14 15:39:02 +05301214
peter chang91a43fa2019-11-14 15:39:05 +05301215 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
1216 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301217 if (rc)
1218 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05301219 return rc;
1220
1221}
1222
1223/**
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301224* pm80xx_set_sas_protocol_timer_config - support the SAS Protocol
1225* Timer configuration page
1226* @pm8001_ha: our hba card information.
1227*/
1228static int
1229pm80xx_set_sas_protocol_timer_config(struct pm8001_hba_info *pm8001_ha)
1230{
1231 struct set_ctrl_cfg_req payload;
1232 struct inbound_queue_table *circularQ;
1233 SASProtocolTimerConfig_t SASConfigPage;
1234 int rc;
1235 u32 tag;
1236 u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
1237
1238 memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
1239 memset(&SASConfigPage, 0, sizeof(SASProtocolTimerConfig_t));
1240
1241 rc = pm8001_tag_alloc(pm8001_ha, &tag);
1242
1243 if (rc)
1244 return -1;
1245
1246 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1247 payload.tag = cpu_to_le32(tag);
1248
1249 SASConfigPage.pageCode = SAS_PROTOCOL_TIMER_CONFIG_PAGE;
1250 SASConfigPage.MST_MSI = 3 << 15;
1251 SASConfigPage.STP_SSP_MCT_TMO = (STP_MCT_TMO << 16) | SSP_MCT_TMO;
1252 SASConfigPage.STP_FRM_TMO = (SAS_MAX_OPEN_TIME << 24) |
1253 (SMP_MAX_CONN_TIMER << 16) | STP_FRM_TIMER;
1254 SASConfigPage.STP_IDLE_TMO = STP_IDLE_TIME;
1255
1256 if (SASConfigPage.STP_IDLE_TMO > 0x3FFFFFF)
1257 SASConfigPage.STP_IDLE_TMO = 0x3FFFFFF;
1258
1259
1260 SASConfigPage.OPNRJT_RTRY_INTVL = (SAS_MFD << 16) |
1261 SAS_OPNRJT_RTRY_INTVL;
1262 SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO = (SAS_DOPNRJT_RTRY_TMO << 16)
1263 | SAS_COPNRJT_RTRY_TMO;
1264 SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR = (SAS_DOPNRJT_RTRY_THR << 16)
1265 | SAS_COPNRJT_RTRY_THR;
1266 SASConfigPage.MAX_AIP = SAS_MAX_AIP;
1267
Joe Perches1b5d2792020-11-20 15:16:09 -08001268 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.pageCode 0x%08x\n",
1269 SASConfigPage.pageCode);
1270 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.MST_MSI 0x%08x\n",
1271 SASConfigPage.MST_MSI);
1272 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_SSP_MCT_TMO 0x%08x\n",
1273 SASConfigPage.STP_SSP_MCT_TMO);
1274 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_FRM_TMO 0x%08x\n",
1275 SASConfigPage.STP_FRM_TMO);
1276 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_IDLE_TMO 0x%08x\n",
1277 SASConfigPage.STP_IDLE_TMO);
1278 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.OPNRJT_RTRY_INTVL 0x%08x\n",
1279 SASConfigPage.OPNRJT_RTRY_INTVL);
1280 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO 0x%08x\n",
1281 SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO);
1282 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR 0x%08x\n",
1283 SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR);
1284 pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.MAX_AIP 0x%08x\n",
1285 SASConfigPage.MAX_AIP);
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301286
1287 memcpy(&payload.cfg_pg, &SASConfigPage,
1288 sizeof(SASProtocolTimerConfig_t));
1289
peter chang91a43fa2019-11-14 15:39:05 +05301290 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
1291 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301292 if (rc)
1293 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301294
1295 return rc;
1296}
1297
1298/**
Sakthivel Kf5860992013-04-17 16:37:02 +05301299 * pm80xx_get_encrypt_info - Check for encryption
1300 * @pm8001_ha: our hba card information.
1301 */
1302static int
1303pm80xx_get_encrypt_info(struct pm8001_hba_info *pm8001_ha)
1304{
1305 u32 scratch3_value;
Rickard Strandqvistda225492014-07-09 17:20:10 +05301306 int ret = -1;
Sakthivel Kf5860992013-04-17 16:37:02 +05301307
1308 /* Read encryption status from SCRATCH PAD 3 */
1309 scratch3_value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
1310
1311 if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1312 SCRATCH_PAD3_ENC_READY) {
1313 if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1314 pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1315 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1316 SCRATCH_PAD3_SMF_ENABLED)
1317 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1318 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1319 SCRATCH_PAD3_SMA_ENABLED)
1320 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1321 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1322 SCRATCH_PAD3_SMB_ENABLED)
1323 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1324 pm8001_ha->encrypt_info.status = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08001325 pm8001_dbg(pm8001_ha, INIT,
1326 "Encryption: SCRATCH_PAD3_ENC_READY 0x%08X.Cipher mode 0x%x Sec mode 0x%x status 0x%x\n",
1327 scratch3_value,
1328 pm8001_ha->encrypt_info.cipher_mode,
1329 pm8001_ha->encrypt_info.sec_mode,
1330 pm8001_ha->encrypt_info.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301331 ret = 0;
1332 } else if ((scratch3_value & SCRATCH_PAD3_ENC_READY) ==
1333 SCRATCH_PAD3_ENC_DISABLED) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001334 pm8001_dbg(pm8001_ha, INIT,
1335 "Encryption: SCRATCH_PAD3_ENC_DISABLED 0x%08X\n",
1336 scratch3_value);
Sakthivel Kf5860992013-04-17 16:37:02 +05301337 pm8001_ha->encrypt_info.status = 0xFFFFFFFF;
1338 pm8001_ha->encrypt_info.cipher_mode = 0;
1339 pm8001_ha->encrypt_info.sec_mode = 0;
Rickard Strandqvistda225492014-07-09 17:20:10 +05301340 ret = 0;
Sakthivel Kf5860992013-04-17 16:37:02 +05301341 } else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1342 SCRATCH_PAD3_ENC_DIS_ERR) {
1343 pm8001_ha->encrypt_info.status =
1344 (scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1345 if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1346 pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1347 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1348 SCRATCH_PAD3_SMF_ENABLED)
1349 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1350 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1351 SCRATCH_PAD3_SMA_ENABLED)
1352 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1353 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1354 SCRATCH_PAD3_SMB_ENABLED)
1355 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
Joe Perches1b5d2792020-11-20 15:16:09 -08001356 pm8001_dbg(pm8001_ha, INIT,
1357 "Encryption: SCRATCH_PAD3_DIS_ERR 0x%08X.Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
1358 scratch3_value,
1359 pm8001_ha->encrypt_info.cipher_mode,
1360 pm8001_ha->encrypt_info.sec_mode,
1361 pm8001_ha->encrypt_info.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301362 } else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1363 SCRATCH_PAD3_ENC_ENA_ERR) {
1364
1365 pm8001_ha->encrypt_info.status =
1366 (scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1367 if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1368 pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1369 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1370 SCRATCH_PAD3_SMF_ENABLED)
1371 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1372 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1373 SCRATCH_PAD3_SMA_ENABLED)
1374 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1375 if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1376 SCRATCH_PAD3_SMB_ENABLED)
1377 pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1378
Joe Perches1b5d2792020-11-20 15:16:09 -08001379 pm8001_dbg(pm8001_ha, INIT,
1380 "Encryption: SCRATCH_PAD3_ENA_ERR 0x%08X.Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
1381 scratch3_value,
1382 pm8001_ha->encrypt_info.cipher_mode,
1383 pm8001_ha->encrypt_info.sec_mode,
1384 pm8001_ha->encrypt_info.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301385 }
1386 return ret;
1387}
1388
1389/**
1390 * pm80xx_encrypt_update - update flash with encryption informtion
1391 * @pm8001_ha: our hba card information.
1392 */
1393static int pm80xx_encrypt_update(struct pm8001_hba_info *pm8001_ha)
1394{
1395 struct kek_mgmt_req payload;
1396 struct inbound_queue_table *circularQ;
1397 int rc;
1398 u32 tag;
1399 u32 opc = OPC_INB_KEK_MANAGEMENT;
1400
1401 memset(&payload, 0, sizeof(struct kek_mgmt_req));
1402 rc = pm8001_tag_alloc(pm8001_ha, &tag);
1403 if (rc)
1404 return -1;
1405
1406 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1407 payload.tag = cpu_to_le32(tag);
1408 /* Currently only one key is used. New KEK index is 1.
1409 * Current KEK index is 1. Store KEK to NVRAM is 1.
1410 */
1411 payload.new_curidx_ksop = ((1 << 24) | (1 << 16) | (1 << 8) |
1412 KEK_MGMT_SUBOP_KEYCARDUPDATE);
1413
Joe Perches1b5d2792020-11-20 15:16:09 -08001414 pm8001_dbg(pm8001_ha, DEV,
1415 "Saving Encryption info to flash. payload 0x%x\n",
1416 payload.new_curidx_ksop);
peter chang73706722019-11-14 15:39:02 +05301417
peter chang91a43fa2019-11-14 15:39:05 +05301418 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
1419 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301420 if (rc)
1421 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05301422
1423 return rc;
1424}
1425
1426/**
1427 * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
1428 * @pm8001_ha: our hba card information
1429 */
1430static int pm80xx_chip_init(struct pm8001_hba_info *pm8001_ha)
1431{
1432 int ret;
1433 u8 i = 0;
1434
1435 /* check the firmware status */
1436 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001437 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301438 return -EBUSY;
1439 }
1440
Deepak Ukey72349b62018-09-11 14:18:04 +05301441 /* Initialize the controller fatal error flag */
1442 pm8001_ha->controller_fatal_error = false;
1443
Sakthivel Kf5860992013-04-17 16:37:02 +05301444 /* Initialize pci space address eg: mpi offset */
akshatzen95652f92021-01-09 18:08:44 +05301445 ret = init_pci_device_addresses(pm8001_ha);
1446 if (ret) {
1447 pm8001_dbg(pm8001_ha, FAIL,
1448 "Failed to init pci addresses");
1449 return ret;
1450 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301451 init_default_table_values(pm8001_ha);
1452 read_main_config_table(pm8001_ha);
1453 read_general_status_table(pm8001_ha);
1454 read_inbnd_queue_table(pm8001_ha);
1455 read_outbnd_queue_table(pm8001_ha);
1456 read_phy_attr_table(pm8001_ha);
1457
1458 /* update main config table ,inbound table and outbound table */
1459 update_main_config_table(pm8001_ha);
Viswas G05c6c022020-10-05 20:20:08 +05301460 for (i = 0; i < pm8001_ha->max_q_num; i++) {
Sakthivel Kf5860992013-04-17 16:37:02 +05301461 update_inbnd_queue_table(pm8001_ha, i);
Sakthivel Kf5860992013-04-17 16:37:02 +05301462 update_outbnd_queue_table(pm8001_ha, i);
Viswas G05c6c022020-10-05 20:20:08 +05301463 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301464 /* notify firmware update finished and check initialization status */
1465 if (0 == mpi_init_check(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001466 pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301467 } else
1468 return -EBUSY;
1469
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301470 /* send SAS protocol timer configuration page to FW */
1471 ret = pm80xx_set_sas_protocol_timer_config(pm8001_ha);
Sakthivel Kf5860992013-04-17 16:37:02 +05301472
1473 /* Check for encryption */
1474 if (pm8001_ha->chip->encrypt) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001475 pm8001_dbg(pm8001_ha, INIT, "Checking for encryption\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301476 ret = pm80xx_get_encrypt_info(pm8001_ha);
1477 if (ret == -1) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001478 pm8001_dbg(pm8001_ha, INIT, "Encryption error !!\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301479 if (pm8001_ha->encrypt_info.status == 0x81) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001480 pm8001_dbg(pm8001_ha, INIT,
1481 "Encryption enabled with error.Saving encryption key to flash\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301482 pm80xx_encrypt_update(pm8001_ha);
1483 }
1484 }
1485 }
1486 return 0;
1487}
1488
1489static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
1490{
1491 u32 max_wait_count;
1492 u32 value;
1493 u32 gst_len_mpistate;
akshatzen95652f92021-01-09 18:08:44 +05301494 int ret;
1495
1496 ret = init_pci_device_addresses(pm8001_ha);
1497 if (ret) {
1498 pm8001_dbg(pm8001_ha, FAIL,
1499 "Failed to init pci addresses");
1500 return ret;
1501 }
1502
Sakthivel Kf5860992013-04-17 16:37:02 +05301503 /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
1504 table is stop */
1505 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_RESET);
1506
1507 /* wait until Inbound DoorBell Clear Register toggled */
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301508 if (IS_SPCV_12G(pm8001_ha->pdev)) {
1509 max_wait_count = 4 * 1000 * 1000;/* 4 sec */
1510 } else {
1511 max_wait_count = 2 * 1000 * 1000;/* 2 sec */
1512 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301513 do {
1514 udelay(1);
1515 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1516 value &= SPCv_MSGU_CFG_TABLE_RESET;
1517 } while ((value != 0) && (--max_wait_count));
1518
1519 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001520 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=%x\n", value);
Sakthivel Kf5860992013-04-17 16:37:02 +05301521 return -1;
1522 }
1523
1524 /* check the MPI-State for termination in progress */
1525 /* wait until Inbound DoorBell Clear Register toggled */
1526 max_wait_count = 2 * 1000 * 1000; /* 2 sec for spcv/ve */
1527 do {
1528 udelay(1);
1529 gst_len_mpistate =
1530 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1531 GST_GSTLEN_MPIS_OFFSET);
1532 if (GST_MPI_STATE_UNINIT ==
1533 (gst_len_mpistate & GST_MPI_STATE_MASK))
1534 break;
1535 } while (--max_wait_count);
1536 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001537 pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n",
1538 gst_len_mpistate & GST_MPI_STATE_MASK);
Sakthivel Kf5860992013-04-17 16:37:02 +05301539 return -1;
1540 }
1541
1542 return 0;
1543}
1544
1545/**
akshatzena961ea02021-01-09 18:08:43 +05301546 * pm80xx_fatal_errors - returns non zero *ONLY* when fatal errors
1547 * @pm8001_ha: our hba card information
1548 *
1549 * Fatal errors are recoverable only after a host reboot.
1550 */
1551int
1552pm80xx_fatal_errors(struct pm8001_hba_info *pm8001_ha)
1553{
1554 int ret = 0;
1555 u32 scratch_pad_rsvd0 = pm8001_cr32(pm8001_ha, 0,
1556 MSGU_HOST_SCRATCH_PAD_6);
1557 u32 scratch_pad_rsvd1 = pm8001_cr32(pm8001_ha, 0,
1558 MSGU_HOST_SCRATCH_PAD_7);
1559 u32 scratch_pad1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1560 u32 scratch_pad2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1561 u32 scratch_pad3 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
1562
1563 if (pm8001_ha->chip_id != chip_8006 &&
1564 pm8001_ha->chip_id != chip_8074 &&
1565 pm8001_ha->chip_id != chip_8076) {
1566 return 0;
1567 }
1568
1569 if (MSGU_SCRATCHPAD1_STATE_FATAL_ERROR(scratch_pad1)) {
1570 pm8001_dbg(pm8001_ha, FAIL,
1571 "Fatal error SCRATCHPAD1 = 0x%x SCRATCHPAD2 = 0x%x SCRATCHPAD3 = 0x%x SCRATCHPAD_RSVD0 = 0x%x SCRATCHPAD_RSVD1 = 0x%x\n",
1572 scratch_pad1, scratch_pad2, scratch_pad3,
1573 scratch_pad_rsvd0, scratch_pad_rsvd1);
1574 ret = 1;
1575 }
1576
1577 return ret;
1578}
1579
1580/**
Sakthivel Kf5860992013-04-17 16:37:02 +05301581 * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
1582 * the FW register status to the originated status.
1583 * @pm8001_ha: our hba card information
1584 */
1585
1586static int
1587pm80xx_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
1588{
1589 u32 regval;
1590 u32 bootloader_state;
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301591 u32 ibutton0, ibutton1;
Sakthivel Kf5860992013-04-17 16:37:02 +05301592
Deepak Ukey72349b62018-09-11 14:18:04 +05301593 /* Process MPI table uninitialization only if FW is ready */
1594 if (!pm8001_ha->controller_fatal_error) {
1595 /* Check if MPI is in ready state to reset */
1596 if (mpi_uninit_check(pm8001_ha) != 0) {
Vikram Auradkard384be62020-03-16 13:19:02 +05301597 u32 r0 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
1598 u32 r1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1599 u32 r2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1600 u32 r3 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
Joe Perches1b5d2792020-11-20 15:16:09 -08001601 pm8001_dbg(pm8001_ha, FAIL,
1602 "MPI state is not ready scratch: %x:%x:%x:%x\n",
1603 r0, r1, r2, r3);
Vikram Auradkard384be62020-03-16 13:19:02 +05301604 /* if things aren't ready but the bootloader is ok then
1605 * try the reset anyway.
1606 */
1607 if (r1 & SCRATCH_PAD1_BOOTSTATE_MASK)
1608 return -1;
Deepak Ukey72349b62018-09-11 14:18:04 +05301609 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301610 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301611 /* checked for reset register normal state; 0x0 */
1612 regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -08001613 pm8001_dbg(pm8001_ha, INIT, "reset register before write : 0x%x\n",
1614 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301615
1616 pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, SPCv_NORMAL_RESET_VALUE);
Vikram Auradkar4daf1ef2019-11-14 15:39:01 +05301617 msleep(500);
Sakthivel Kf5860992013-04-17 16:37:02 +05301618
1619 regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -08001620 pm8001_dbg(pm8001_ha, INIT, "reset register after write 0x%x\n",
1621 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301622
1623 if ((regval & SPCv_SOFT_RESET_READ_MASK) ==
1624 SPCv_SOFT_RESET_NORMAL_RESET_OCCURED) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001625 pm8001_dbg(pm8001_ha, MSG,
1626 " soft reset successful [regval: 0x%x]\n",
1627 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301628 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08001629 pm8001_dbg(pm8001_ha, MSG,
1630 " soft reset failed [regval: 0x%x]\n",
1631 regval);
Sakthivel Kf5860992013-04-17 16:37:02 +05301632
1633 /* check bootloader is successfully executed or in HDA mode */
1634 bootloader_state =
1635 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1636 SCRATCH_PAD1_BOOTSTATE_MASK;
1637
1638 if (bootloader_state == SCRATCH_PAD1_BOOTSTATE_HDA_SEEPROM) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001639 pm8001_dbg(pm8001_ha, MSG,
1640 "Bootloader state - HDA mode SEEPROM\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301641 } else if (bootloader_state ==
1642 SCRATCH_PAD1_BOOTSTATE_HDA_BOOTSTRAP) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001643 pm8001_dbg(pm8001_ha, MSG,
1644 "Bootloader state - HDA mode Bootstrap Pin\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301645 } else if (bootloader_state ==
1646 SCRATCH_PAD1_BOOTSTATE_HDA_SOFTRESET) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001647 pm8001_dbg(pm8001_ha, MSG,
1648 "Bootloader state - HDA mode soft reset\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301649 } else if (bootloader_state ==
1650 SCRATCH_PAD1_BOOTSTATE_CRIT_ERROR) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001651 pm8001_dbg(pm8001_ha, MSG,
1652 "Bootloader state-HDA mode critical error\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301653 }
1654 return -EBUSY;
1655 }
1656
1657 /* check the firmware status after reset */
1658 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001659 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301660 /* check iButton feature support for motherboard controller */
1661 if (pm8001_ha->pdev->subsystem_vendor !=
1662 PCI_VENDOR_ID_ADAPTEC2 &&
Benjamin Roodfaf321b2015-10-30 10:53:29 -04001663 pm8001_ha->pdev->subsystem_vendor !=
1664 PCI_VENDOR_ID_ATTO &&
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301665 pm8001_ha->pdev->subsystem_vendor != 0) {
1666 ibutton0 = pm8001_cr32(pm8001_ha, 0,
1667 MSGU_HOST_SCRATCH_PAD_6);
1668 ibutton1 = pm8001_cr32(pm8001_ha, 0,
1669 MSGU_HOST_SCRATCH_PAD_7);
1670 if (!ibutton0 && !ibutton1) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001671 pm8001_dbg(pm8001_ha, FAIL,
1672 "iButton Feature is not Available!!!\n");
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301673 return -EBUSY;
1674 }
1675 if (ibutton0 == 0xdeadbeef && ibutton1 == 0xdeadbeef) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001676 pm8001_dbg(pm8001_ha, FAIL,
1677 "CRC Check for iButton Feature Failed!!!\n");
Anand Kumar Santhanam06f12f222013-09-17 14:32:20 +05301678 return -EBUSY;
1679 }
1680 }
Sakthivel Kf5860992013-04-17 16:37:02 +05301681 }
Joe Perches1b5d2792020-11-20 15:16:09 -08001682 pm8001_dbg(pm8001_ha, INIT, "SPCv soft reset Complete\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301683 return 0;
1684}
1685
1686static void pm80xx_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1687{
Colin Ian King9e2a07e2019-03-17 18:15:32 +00001688 u32 i;
Sakthivel Kf5860992013-04-17 16:37:02 +05301689
Joe Perches1b5d2792020-11-20 15:16:09 -08001690 pm8001_dbg(pm8001_ha, INIT, "chip reset start\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301691
1692 /* do SPCv chip reset. */
1693 pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, 0x11);
Joe Perches1b5d2792020-11-20 15:16:09 -08001694 pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301695
1696 /* Check this ..whether delay is required or no */
1697 /* delay 10 usec */
1698 udelay(10);
1699
1700 /* wait for 20 msec until the firmware gets reloaded */
1701 i = 20;
1702 do {
1703 mdelay(1);
1704 } while ((--i) != 0);
1705
Joe Perches1b5d2792020-11-20 15:16:09 -08001706 pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301707}
1708
1709/**
1710 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1711 * @pm8001_ha: our hba card information
1712 */
1713static void
1714pm80xx_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1715{
1716 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1717 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1718}
1719
1720/**
1721 * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
1722 * @pm8001_ha: our hba card information
1723 */
1724static void
1725pm80xx_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1726{
1727 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, ODMR_MASK_ALL);
1728}
1729
1730/**
1731 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1732 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +01001733 * @vec: interrupt number to enable
Sakthivel Kf5860992013-04-17 16:37:02 +05301734 */
1735static void
1736pm80xx_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1737{
1738#ifdef PM8001_USE_MSIX
1739 u32 mask;
1740 mask = (u32)(1 << vec);
1741
1742 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, (u32)(mask & 0xFFFFFFFF));
1743 return;
1744#endif
1745 pm80xx_chip_intx_interrupt_enable(pm8001_ha);
1746
1747}
1748
1749/**
1750 * pm8001_chip_interrupt_disable- disable PM8001 chip interrupt
1751 * @pm8001_ha: our hba card information
Lee Jones6ad4a512020-07-21 17:41:25 +01001752 * @vec: interrupt number to disable
Sakthivel Kf5860992013-04-17 16:37:02 +05301753 */
1754static void
1755pm80xx_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1756{
1757#ifdef PM8001_USE_MSIX
1758 u32 mask;
1759 if (vec == 0xFF)
1760 mask = 0xFFFFFFFF;
1761 else
1762 mask = (u32)(1 << vec);
1763 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, (u32)(mask & 0xFFFFFFFF));
1764 return;
1765#endif
1766 pm80xx_chip_intx_interrupt_disable(pm8001_ha);
1767}
1768
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301769static void pm80xx_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1770 struct pm8001_device *pm8001_ha_dev)
1771{
1772 int res;
1773 u32 ccb_tag;
1774 struct pm8001_ccb_info *ccb;
1775 struct sas_task *task = NULL;
1776 struct task_abort_req task_abort;
1777 struct inbound_queue_table *circularQ;
1778 u32 opc = OPC_INB_SATA_ABORT;
1779 int ret;
1780
1781 if (!pm8001_ha_dev) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001782 pm8001_dbg(pm8001_ha, FAIL, "dev is null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301783 return;
1784 }
1785
1786 task = sas_alloc_slow_task(GFP_ATOMIC);
1787
1788 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001789 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301790 return;
1791 }
1792
1793 task->task_done = pm8001_task_done;
1794
1795 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301796 if (res) {
1797 sas_free_task(task);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301798 return;
Tomas Henzl5533abc2014-07-09 17:20:49 +05301799 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301800
1801 ccb = &pm8001_ha->ccb_info[ccb_tag];
1802 ccb->device = pm8001_ha_dev;
1803 ccb->ccb_tag = ccb_tag;
1804 ccb->task = task;
1805
1806 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1807
1808 memset(&task_abort, 0, sizeof(task_abort));
1809 task_abort.abort_all = cpu_to_le32(1);
1810 task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1811 task_abort.tag = cpu_to_le32(ccb_tag);
1812
peter chang91a43fa2019-11-14 15:39:05 +05301813 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
1814 sizeof(task_abort), 0);
Joe Perches1b5d2792020-11-20 15:16:09 -08001815 pm8001_dbg(pm8001_ha, FAIL, "Executing abort task end\n");
Tomas Henzl5533abc2014-07-09 17:20:49 +05301816 if (ret) {
1817 sas_free_task(task);
1818 pm8001_tag_free(pm8001_ha, ccb_tag);
1819 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301820}
1821
1822static void pm80xx_send_read_log(struct pm8001_hba_info *pm8001_ha,
1823 struct pm8001_device *pm8001_ha_dev)
1824{
1825 struct sata_start_req sata_cmd;
1826 int res;
1827 u32 ccb_tag;
1828 struct pm8001_ccb_info *ccb;
1829 struct sas_task *task = NULL;
1830 struct host_to_dev_fis fis;
1831 struct domain_device *dev;
1832 struct inbound_queue_table *circularQ;
1833 u32 opc = OPC_INB_SATA_HOST_OPSTART;
1834
1835 task = sas_alloc_slow_task(GFP_ATOMIC);
1836
1837 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001838 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301839 return;
1840 }
1841 task->task_done = pm8001_task_done;
1842
1843 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1844 if (res) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301845 sas_free_task(task);
Joe Perches1b5d2792020-11-20 15:16:09 -08001846 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate tag !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301847 return;
1848 }
1849
1850 /* allocate domain device by ourselves as libsas
1851 * is not going to provide any
1852 */
1853 dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1854 if (!dev) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301855 sas_free_task(task);
1856 pm8001_tag_free(pm8001_ha, ccb_tag);
Joe Perches1b5d2792020-11-20 15:16:09 -08001857 pm8001_dbg(pm8001_ha, FAIL,
1858 "Domain device cannot be allocated\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301859 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301860 }
1861
Tomas Henzl5533abc2014-07-09 17:20:49 +05301862 task->dev = dev;
1863 task->dev->lldd_dev = pm8001_ha_dev;
1864
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301865 ccb = &pm8001_ha->ccb_info[ccb_tag];
1866 ccb->device = pm8001_ha_dev;
1867 ccb->ccb_tag = ccb_tag;
1868 ccb->task = task;
Viswas G0b6df112017-10-18 11:39:14 +05301869 ccb->n_elem = 0;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301870 pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1871 pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1872
1873 memset(&sata_cmd, 0, sizeof(sata_cmd));
1874 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1875
1876 /* construct read log FIS */
1877 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1878 fis.fis_type = 0x27;
1879 fis.flags = 0x80;
1880 fis.command = ATA_CMD_READ_LOG_EXT;
1881 fis.lbal = 0x10;
1882 fis.sector_count = 0x1;
1883
1884 sata_cmd.tag = cpu_to_le32(ccb_tag);
1885 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1886 sata_cmd.ncqtag_atap_dir_m_dad |= ((0x1 << 7) | (0x5 << 9));
1887 memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1888
peter chang91a43fa2019-11-14 15:39:05 +05301889 res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
1890 sizeof(sata_cmd), 0);
Joe Perches1b5d2792020-11-20 15:16:09 -08001891 pm8001_dbg(pm8001_ha, FAIL, "Executing read log end\n");
Tomas Henzl5533abc2014-07-09 17:20:49 +05301892 if (res) {
1893 sas_free_task(task);
1894 pm8001_tag_free(pm8001_ha, ccb_tag);
1895 kfree(dev);
1896 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301897}
1898
Sakthivel Kf5860992013-04-17 16:37:02 +05301899/**
1900 * mpi_ssp_completion- process the event that FW response to the SSP request.
1901 * @pm8001_ha: our hba card information
1902 * @piomb: the message contents of this outbound message.
1903 *
1904 * When FW has completed a ssp request for example a IO request, after it has
1905 * filled the SG data with the data, it will trigger this event represent
1906 * that he has finished the job,please check the coresponding buffer.
1907 * So we will tell the caller who maybe waiting the result to tell upper layer
1908 * that the task has been finished.
1909 */
1910static void
1911mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
1912{
1913 struct sas_task *t;
1914 struct pm8001_ccb_info *ccb;
1915 unsigned long flags;
1916 u32 status;
1917 u32 param;
1918 u32 tag;
1919 struct ssp_completion_resp *psspPayload;
1920 struct task_status_struct *ts;
1921 struct ssp_response_iu *iu;
1922 struct pm8001_device *pm8001_dev;
1923 psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1924 status = le32_to_cpu(psspPayload->status);
1925 tag = le32_to_cpu(psspPayload->tag);
1926 ccb = &pm8001_ha->ccb_info[tag];
1927 if ((status == IO_ABORTED) && ccb->open_retry) {
1928 /* Being completed by another */
1929 ccb->open_retry = 0;
1930 return;
1931 }
1932 pm8001_dev = ccb->device;
1933 param = le32_to_cpu(psspPayload->param);
1934 t = ccb->task;
1935
1936 if (status && status != IO_UNDERFLOW)
Joe Perches1b5d2792020-11-20 15:16:09 -08001937 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05301938 if (unlikely(!t || !t->lldd_task || !t->dev))
1939 return;
1940 ts = &t->task_status;
peter chang73706722019-11-14 15:39:02 +05301941
Joe Perches1b5d2792020-11-20 15:16:09 -08001942 pm8001_dbg(pm8001_ha, DEV,
1943 "tag::0x%x, status::0x%x task::0x%p\n", tag, status, t);
peter chang73706722019-11-14 15:39:02 +05301944
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301945 /* Print sas address of IO failed device */
1946 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1947 (status != IO_UNDERFLOW))
Joe Perches1b5d2792020-11-20 15:16:09 -08001948 pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n",
1949 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301950
Sakthivel Kf5860992013-04-17 16:37:02 +05301951 switch (status) {
1952 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001953 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS ,param = 0x%x\n",
1954 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05301955 if (param == 0) {
1956 ts->resp = SAS_TASK_COMPLETE;
1957 ts->stat = SAM_STAT_GOOD;
1958 } else {
1959 ts->resp = SAS_TASK_COMPLETE;
1960 ts->stat = SAS_PROTO_RESPONSE;
1961 ts->residual = param;
1962 iu = &psspPayload->ssp_resp_iu;
1963 sas_ssp_task_response(pm8001_ha->dev, t, iu);
1964 }
1965 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301966 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301967 break;
1968 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001969 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301970 ts->resp = SAS_TASK_COMPLETE;
1971 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05301972 if (pm8001_dev)
1973 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301974 break;
1975 case IO_UNDERFLOW:
1976 /* SSP Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08001977 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW ,param = 0x%x\n",
1978 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05301979 ts->resp = SAS_TASK_COMPLETE;
1980 ts->stat = SAS_DATA_UNDERRUN;
1981 ts->residual = param;
1982 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301983 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301984 break;
1985 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08001986 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301987 ts->resp = SAS_TASK_UNDELIVERED;
1988 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05301989 if (pm8001_dev)
1990 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05301991 break;
1992 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001993 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301994 ts->resp = SAS_TASK_COMPLETE;
1995 ts->stat = SAS_OPEN_REJECT;
1996 /* Force the midlayer to retry */
1997 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05301998 if (pm8001_dev)
1999 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302000 break;
2001 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002002 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302003 ts->resp = SAS_TASK_COMPLETE;
2004 ts->stat = SAS_OPEN_REJECT;
2005 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302006 if (pm8001_dev)
2007 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302008 break;
Viswas G27ecfa52015-08-11 15:06:31 +05302009 case IO_XFER_ERROR_INVALID_SSP_RSP_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08002010 pm8001_dbg(pm8001_ha, IO,
2011 "IO_XFER_ERROR_INVALID_SSP_RSP_FRAME\n");
Viswas G27ecfa52015-08-11 15:06:31 +05302012 ts->resp = SAS_TASK_COMPLETE;
2013 ts->stat = SAS_OPEN_REJECT;
2014 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302015 if (pm8001_dev)
2016 atomic_dec(&pm8001_dev->running_req);
Viswas G27ecfa52015-08-11 15:06:31 +05302017 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302018 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002019 pm8001_dbg(pm8001_ha, IO,
2020 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302021 ts->resp = SAS_TASK_COMPLETE;
2022 ts->stat = SAS_OPEN_REJECT;
2023 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302024 if (pm8001_dev)
2025 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302026 break;
2027 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002028 pm8001_dbg(pm8001_ha, IO,
2029 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302030 ts->resp = SAS_TASK_COMPLETE;
2031 ts->stat = SAS_OPEN_REJECT;
2032 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302033 if (pm8001_dev)
2034 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302035 break;
2036 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002037 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302038 ts->resp = SAS_TASK_COMPLETE;
2039 ts->stat = SAS_OPEN_REJECT;
2040 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302041 if (pm8001_dev)
2042 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302043 break;
2044 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302045 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2046 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2047 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2048 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2049 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002050 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302051 ts->resp = SAS_TASK_COMPLETE;
2052 ts->stat = SAS_OPEN_REJECT;
2053 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2054 if (!t->uldd_task)
2055 pm8001_handle_event(pm8001_ha,
2056 pm8001_dev,
2057 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2058 break;
2059 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002060 pm8001_dbg(pm8001_ha, IO,
2061 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302062 ts->resp = SAS_TASK_COMPLETE;
2063 ts->stat = SAS_OPEN_REJECT;
2064 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302065 if (pm8001_dev)
2066 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302067 break;
2068 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002069 pm8001_dbg(pm8001_ha, IO,
2070 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302071 ts->resp = SAS_TASK_COMPLETE;
2072 ts->stat = SAS_OPEN_REJECT;
2073 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302074 if (pm8001_dev)
2075 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302076 break;
2077 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002078 pm8001_dbg(pm8001_ha, IO,
2079 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302080 ts->resp = SAS_TASK_UNDELIVERED;
2081 ts->stat = SAS_OPEN_REJECT;
2082 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302083 if (pm8001_dev)
2084 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302085 break;
2086 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002087 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302088 ts->resp = SAS_TASK_COMPLETE;
2089 ts->stat = SAS_OPEN_REJECT;
2090 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302091 if (pm8001_dev)
2092 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302093 break;
2094 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002095 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302096 ts->resp = SAS_TASK_COMPLETE;
2097 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302098 if (pm8001_dev)
2099 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302100 break;
2101 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002102 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302103 ts->resp = SAS_TASK_COMPLETE;
2104 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302105 if (pm8001_dev)
2106 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302107 break;
2108 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002109 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302110 ts->resp = SAS_TASK_COMPLETE;
2111 ts->stat = SAS_OPEN_REJECT;
2112 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302113 if (pm8001_dev)
2114 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302115 break;
2116 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002117 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302118 ts->resp = SAS_TASK_COMPLETE;
2119 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302120 if (pm8001_dev)
2121 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302122 break;
2123 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002124 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302125 ts->resp = SAS_TASK_COMPLETE;
2126 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302127 if (pm8001_dev)
2128 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302129 break;
2130 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002131 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302132 ts->resp = SAS_TASK_COMPLETE;
2133 ts->stat = SAS_OPEN_REJECT;
2134 if (!t->uldd_task)
2135 pm8001_handle_event(pm8001_ha,
2136 pm8001_dev,
2137 IO_DS_NON_OPERATIONAL);
2138 break;
2139 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002140 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302141 ts->resp = SAS_TASK_COMPLETE;
2142 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302143 if (pm8001_dev)
2144 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302145 break;
2146 case IO_TM_TAG_NOT_FOUND:
Joe Perches1b5d2792020-11-20 15:16:09 -08002147 pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302148 ts->resp = SAS_TASK_COMPLETE;
2149 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302150 if (pm8001_dev)
2151 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302152 break;
2153 case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002154 pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302155 ts->resp = SAS_TASK_COMPLETE;
2156 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302157 if (pm8001_dev)
2158 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302159 break;
2160 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002161 pm8001_dbg(pm8001_ha, IO,
2162 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302163 ts->resp = SAS_TASK_COMPLETE;
2164 ts->stat = SAS_OPEN_REJECT;
2165 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302166 if (pm8001_dev)
2167 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302168 break;
2169 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002170 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05302171 /* not allowed case. Therefore, return failed status */
2172 ts->resp = SAS_TASK_COMPLETE;
2173 ts->stat = SAS_OPEN_REJECT;
Viswas G4a2efd42020-11-02 22:25:26 +05302174 if (pm8001_dev)
2175 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302176 break;
2177 }
Joe Perches1b5d2792020-11-20 15:16:09 -08002178 pm8001_dbg(pm8001_ha, IO, "scsi_status = 0x%x\n ",
2179 psspPayload->ssp_resp_iu.status);
Sakthivel Kf5860992013-04-17 16:37:02 +05302180 spin_lock_irqsave(&t->task_state_lock, flags);
2181 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2182 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2183 t->task_state_flags |= SAS_TASK_STATE_DONE;
2184 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2185 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002186 pm8001_dbg(pm8001_ha, FAIL,
2187 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2188 t, status, ts->resp, ts->stat);
Viswas G869ddbd2017-10-18 11:39:13 +05302189 if (t->slow_task)
2190 complete(&t->slow_task->completion);
Sakthivel Kf5860992013-04-17 16:37:02 +05302191 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2192 } else {
2193 spin_unlock_irqrestore(&t->task_state_lock, flags);
2194 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2195 mb();/* in order to force CPU ordering */
2196 t->task_done(t);
2197 }
2198}
2199
2200/*See the comments for mpi_ssp_completion */
2201static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
2202{
2203 struct sas_task *t;
2204 unsigned long flags;
2205 struct task_status_struct *ts;
2206 struct pm8001_ccb_info *ccb;
2207 struct pm8001_device *pm8001_dev;
2208 struct ssp_event_resp *psspPayload =
2209 (struct ssp_event_resp *)(piomb + 4);
2210 u32 event = le32_to_cpu(psspPayload->event);
2211 u32 tag = le32_to_cpu(psspPayload->tag);
2212 u32 port_id = le32_to_cpu(psspPayload->port_id);
2213
2214 ccb = &pm8001_ha->ccb_info[tag];
2215 t = ccb->task;
2216 pm8001_dev = ccb->device;
2217 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002218 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302219 if (unlikely(!t || !t->lldd_task || !t->dev))
2220 return;
2221 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002222 pm8001_dbg(pm8001_ha, IOERR, "port_id:0x%x, tag:0x%x, event:0x%x\n",
2223 port_id, tag, event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302224 switch (event) {
2225 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002226 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302227 ts->resp = SAS_TASK_COMPLETE;
2228 ts->stat = SAS_DATA_OVERRUN;
2229 ts->residual = 0;
2230 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302231 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302232 break;
2233 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002234 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302235 pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2236 return;
2237 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002238 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302239 ts->resp = SAS_TASK_COMPLETE;
2240 ts->stat = SAS_OPEN_REJECT;
2241 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2242 break;
2243 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002244 pm8001_dbg(pm8001_ha, IO,
2245 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302246 ts->resp = SAS_TASK_COMPLETE;
2247 ts->stat = SAS_OPEN_REJECT;
2248 ts->open_rej_reason = SAS_OREJ_EPROTO;
2249 break;
2250 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002251 pm8001_dbg(pm8001_ha, IO,
2252 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302253 ts->resp = SAS_TASK_COMPLETE;
2254 ts->stat = SAS_OPEN_REJECT;
2255 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2256 break;
2257 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002258 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302259 ts->resp = SAS_TASK_COMPLETE;
2260 ts->stat = SAS_OPEN_REJECT;
2261 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2262 break;
2263 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302264 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2265 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2266 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2267 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2268 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002269 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302270 ts->resp = SAS_TASK_COMPLETE;
2271 ts->stat = SAS_OPEN_REJECT;
2272 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2273 if (!t->uldd_task)
2274 pm8001_handle_event(pm8001_ha,
2275 pm8001_dev,
2276 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2277 break;
2278 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002279 pm8001_dbg(pm8001_ha, IO,
2280 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302281 ts->resp = SAS_TASK_COMPLETE;
2282 ts->stat = SAS_OPEN_REJECT;
2283 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2284 break;
2285 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002286 pm8001_dbg(pm8001_ha, IO,
2287 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302288 ts->resp = SAS_TASK_COMPLETE;
2289 ts->stat = SAS_OPEN_REJECT;
2290 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2291 break;
2292 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002293 pm8001_dbg(pm8001_ha, IO,
2294 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302295 ts->resp = SAS_TASK_COMPLETE;
2296 ts->stat = SAS_OPEN_REJECT;
2297 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2298 break;
2299 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002300 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302301 ts->resp = SAS_TASK_COMPLETE;
2302 ts->stat = SAS_OPEN_REJECT;
2303 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2304 break;
2305 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002306 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302307 ts->resp = SAS_TASK_COMPLETE;
2308 ts->stat = SAS_NAK_R_ERR;
2309 break;
2310 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002311 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302312 pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2313 return;
2314 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002315 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302316 ts->resp = SAS_TASK_COMPLETE;
2317 ts->stat = SAS_DATA_OVERRUN;
2318 break;
2319 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002320 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302321 ts->resp = SAS_TASK_COMPLETE;
2322 ts->stat = SAS_DATA_OVERRUN;
2323 break;
2324 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002325 pm8001_dbg(pm8001_ha, IO,
2326 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302327 ts->resp = SAS_TASK_COMPLETE;
2328 ts->stat = SAS_DATA_OVERRUN;
2329 break;
2330 case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002331 pm8001_dbg(pm8001_ha, IO,
2332 "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302333 ts->resp = SAS_TASK_COMPLETE;
2334 ts->stat = SAS_DATA_OVERRUN;
2335 break;
2336 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002337 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302338 ts->resp = SAS_TASK_COMPLETE;
2339 ts->stat = SAS_DATA_OVERRUN;
2340 break;
2341 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002342 pm8001_dbg(pm8001_ha, IO,
2343 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302344 ts->resp = SAS_TASK_COMPLETE;
2345 ts->stat = SAS_DATA_OVERRUN;
2346 break;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302347 case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002348 pm8001_dbg(pm8001_ha, IOERR,
2349 "IO_XFR_ERROR_INTERNAL_CRC_ERROR\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302350 /* TBC: used default set values */
2351 ts->resp = SAS_TASK_COMPLETE;
2352 ts->stat = SAS_DATA_OVERRUN;
2353 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302354 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002355 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302356 return;
2357 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002358 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302359 /* not allowed case. Therefore, return failed status */
2360 ts->resp = SAS_TASK_COMPLETE;
2361 ts->stat = SAS_DATA_OVERRUN;
2362 break;
2363 }
2364 spin_lock_irqsave(&t->task_state_lock, flags);
2365 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2366 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2367 t->task_state_flags |= SAS_TASK_STATE_DONE;
2368 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2369 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002370 pm8001_dbg(pm8001_ha, FAIL,
2371 "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2372 t, event, ts->resp, ts->stat);
Sakthivel Kf5860992013-04-17 16:37:02 +05302373 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2374 } else {
2375 spin_unlock_irqrestore(&t->task_state_lock, flags);
2376 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2377 mb();/* in order to force CPU ordering */
2378 t->task_done(t);
2379 }
2380}
2381
2382/*See the comments for mpi_ssp_completion */
2383static void
2384mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2385{
2386 struct sas_task *t;
2387 struct pm8001_ccb_info *ccb;
2388 u32 param;
2389 u32 status;
2390 u32 tag;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302391 int i, j;
2392 u8 sata_addr_low[4];
2393 u32 temp_sata_addr_low, temp_sata_addr_hi;
2394 u8 sata_addr_hi[4];
Sakthivel Kf5860992013-04-17 16:37:02 +05302395 struct sata_completion_resp *psataPayload;
2396 struct task_status_struct *ts;
2397 struct ata_task_resp *resp ;
2398 u32 *sata_resp;
2399 struct pm8001_device *pm8001_dev;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302400 unsigned long flags;
Sakthivel Kf5860992013-04-17 16:37:02 +05302401
2402 psataPayload = (struct sata_completion_resp *)(piomb + 4);
2403 status = le32_to_cpu(psataPayload->status);
2404 tag = le32_to_cpu(psataPayload->tag);
2405
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302406 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002407 pm8001_dbg(pm8001_ha, FAIL, "tag null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302408 return;
2409 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302410 ccb = &pm8001_ha->ccb_info[tag];
2411 param = le32_to_cpu(psataPayload->param);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302412 if (ccb) {
2413 t = ccb->task;
2414 pm8001_dev = ccb->device;
2415 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002416 pm8001_dbg(pm8001_ha, FAIL, "ccb null\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302417 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302418 }
2419
2420 if (t) {
2421 if (t->dev && (t->dev->lldd_dev))
2422 pm8001_dev = t->dev->lldd_dev;
2423 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002424 pm8001_dbg(pm8001_ha, FAIL, "task null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302425 return;
2426 }
2427
2428 if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2429 && unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002430 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302431 return;
2432 }
2433
2434 ts = &t->task_status;
2435 if (!ts) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002436 pm8001_dbg(pm8001_ha, FAIL, "ts null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302437 return;
2438 }
peter chang73706722019-11-14 15:39:02 +05302439
2440 if (unlikely(status))
Joe Perches1b5d2792020-11-20 15:16:09 -08002441 pm8001_dbg(pm8001_ha, IOERR,
2442 "status:0x%x, tag:0x%x, task::0x%p\n",
2443 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302444
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302445 /* Print sas address of IO failed device */
2446 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2447 (status != IO_UNDERFLOW)) {
2448 if (!((t->dev->parent) &&
John Garry924a3542019-06-10 20:41:41 +08002449 (dev_is_expander(t->dev->parent->dev_type)))) {
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302450 for (i = 0 , j = 4; i <= 3 && j <= 7; i++ , j++)
2451 sata_addr_low[i] = pm8001_ha->sas_addr[j];
2452 for (i = 0 , j = 0; i <= 3 && j <= 3; i++ , j++)
2453 sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2454 memcpy(&temp_sata_addr_low, sata_addr_low,
2455 sizeof(sata_addr_low));
2456 memcpy(&temp_sata_addr_hi, sata_addr_hi,
2457 sizeof(sata_addr_hi));
2458 temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2459 |((temp_sata_addr_hi << 8) &
2460 0xff0000) |
2461 ((temp_sata_addr_hi >> 8)
2462 & 0xff00) |
2463 ((temp_sata_addr_hi << 24) &
2464 0xff000000));
2465 temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2466 & 0xff) |
2467 ((temp_sata_addr_low << 8)
2468 & 0xff0000) |
2469 ((temp_sata_addr_low >> 8)
2470 & 0xff00) |
2471 ((temp_sata_addr_low << 24)
2472 & 0xff000000)) +
2473 pm8001_dev->attached_phy +
2474 0x10);
Joe Perches1b5d2792020-11-20 15:16:09 -08002475 pm8001_dbg(pm8001_ha, FAIL,
2476 "SAS Address of IO Failure Drive:%08x%08x\n",
2477 temp_sata_addr_hi,
2478 temp_sata_addr_low);
Sakthivel Kf5860992013-04-17 16:37:02 +05302479
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302480 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002481 pm8001_dbg(pm8001_ha, FAIL,
2482 "SAS Address of IO Failure Drive:%016llx\n",
2483 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302484 }
2485 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302486 switch (status) {
2487 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002488 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302489 if (param == 0) {
2490 ts->resp = SAS_TASK_COMPLETE;
2491 ts->stat = SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302492 /* check if response is for SEND READ LOG */
2493 if (pm8001_dev &&
2494 (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2495 /* set new bit for abort_all */
2496 pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2497 /* clear bit for read log */
2498 pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2499 pm80xx_send_abort_all(pm8001_ha, pm8001_dev);
2500 /* Free the tag */
2501 pm8001_tag_free(pm8001_ha, tag);
2502 sas_free_task(t);
2503 return;
2504 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302505 } else {
2506 u8 len;
2507 ts->resp = SAS_TASK_COMPLETE;
2508 ts->stat = SAS_PROTO_RESPONSE;
2509 ts->residual = param;
Joe Perches1b5d2792020-11-20 15:16:09 -08002510 pm8001_dbg(pm8001_ha, IO,
2511 "SAS_PROTO_RESPONSE len = %d\n",
2512 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05302513 sata_resp = &psataPayload->sata_resp[0];
2514 resp = (struct ata_task_resp *)ts->buf;
2515 if (t->ata_task.dma_xfer == 0 &&
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02002516 t->data_dir == DMA_FROM_DEVICE) {
Sakthivel Kf5860992013-04-17 16:37:02 +05302517 len = sizeof(struct pio_setup_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002518 pm8001_dbg(pm8001_ha, IO,
2519 "PIO read len = %d\n", len);
Sakthivel Kf5860992013-04-17 16:37:02 +05302520 } else if (t->ata_task.use_ncq) {
2521 len = sizeof(struct set_dev_bits_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002522 pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n",
2523 len);
Sakthivel Kf5860992013-04-17 16:37:02 +05302524 } else {
2525 len = sizeof(struct dev_to_host_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002526 pm8001_dbg(pm8001_ha, IO, "other len = %d\n",
2527 len);
Sakthivel Kf5860992013-04-17 16:37:02 +05302528 }
2529 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2530 resp->frame_len = len;
2531 memcpy(&resp->ending_fis[0], sata_resp, len);
2532 ts->buf_valid_size = sizeof(*resp);
2533 } else
Joe Perches1b5d2792020-11-20 15:16:09 -08002534 pm8001_dbg(pm8001_ha, IO,
2535 "response too large\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302536 }
2537 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302538 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302539 break;
2540 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002541 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302542 ts->resp = SAS_TASK_COMPLETE;
2543 ts->stat = SAS_ABORTED_TASK;
2544 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302545 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302546 break;
2547 /* following cases are to do cases */
2548 case IO_UNDERFLOW:
2549 /* SATA Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08002550 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param);
Sakthivel Kf5860992013-04-17 16:37:02 +05302551 ts->resp = SAS_TASK_COMPLETE;
2552 ts->stat = SAS_DATA_UNDERRUN;
2553 ts->residual = param;
2554 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302555 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302556 break;
2557 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002558 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302559 ts->resp = SAS_TASK_UNDELIVERED;
2560 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302561 if (pm8001_dev)
2562 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302563 break;
2564 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002565 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302566 ts->resp = SAS_TASK_COMPLETE;
2567 ts->stat = SAS_INTERRUPTED;
Viswas G4a2efd42020-11-02 22:25:26 +05302568 if (pm8001_dev)
2569 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302570 break;
2571 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002572 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302573 ts->resp = SAS_TASK_COMPLETE;
2574 ts->stat = SAS_OPEN_REJECT;
2575 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302576 if (pm8001_dev)
2577 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302578 break;
2579 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002580 pm8001_dbg(pm8001_ha, IO,
2581 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302582 ts->resp = SAS_TASK_COMPLETE;
2583 ts->stat = SAS_OPEN_REJECT;
2584 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302585 if (pm8001_dev)
2586 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302587 break;
2588 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002589 pm8001_dbg(pm8001_ha, IO,
2590 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302591 ts->resp = SAS_TASK_COMPLETE;
2592 ts->stat = SAS_OPEN_REJECT;
2593 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302594 if (pm8001_dev)
2595 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302596 break;
2597 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002598 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302599 ts->resp = SAS_TASK_COMPLETE;
2600 ts->stat = SAS_OPEN_REJECT;
2601 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
Viswas G4a2efd42020-11-02 22:25:26 +05302602 if (pm8001_dev)
2603 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302604 break;
2605 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302606 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2607 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2608 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2609 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2610 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002611 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302612 ts->resp = SAS_TASK_COMPLETE;
2613 ts->stat = SAS_DEV_NO_RESPONSE;
2614 if (!t->uldd_task) {
2615 pm8001_handle_event(pm8001_ha,
2616 pm8001_dev,
2617 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2618 ts->resp = SAS_TASK_UNDELIVERED;
2619 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302620 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302621 return;
2622 }
2623 break;
2624 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002625 pm8001_dbg(pm8001_ha, IO,
2626 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302627 ts->resp = SAS_TASK_UNDELIVERED;
2628 ts->stat = SAS_OPEN_REJECT;
2629 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2630 if (!t->uldd_task) {
2631 pm8001_handle_event(pm8001_ha,
2632 pm8001_dev,
2633 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2634 ts->resp = SAS_TASK_UNDELIVERED;
2635 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302636 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302637 return;
2638 }
2639 break;
2640 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002641 pm8001_dbg(pm8001_ha, IO,
2642 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302643 ts->resp = SAS_TASK_COMPLETE;
2644 ts->stat = SAS_OPEN_REJECT;
2645 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302646 if (pm8001_dev)
2647 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302648 break;
2649 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002650 pm8001_dbg(pm8001_ha, IO,
2651 "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302652 ts->resp = SAS_TASK_COMPLETE;
2653 ts->stat = SAS_DEV_NO_RESPONSE;
2654 if (!t->uldd_task) {
2655 pm8001_handle_event(pm8001_ha,
2656 pm8001_dev,
2657 IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2658 ts->resp = SAS_TASK_UNDELIVERED;
2659 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302660 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302661 return;
2662 }
2663 break;
2664 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002665 pm8001_dbg(pm8001_ha, IO,
2666 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302667 ts->resp = SAS_TASK_COMPLETE;
2668 ts->stat = SAS_OPEN_REJECT;
2669 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302670 if (pm8001_dev)
2671 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302672 break;
2673 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002674 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302675 ts->resp = SAS_TASK_COMPLETE;
2676 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302677 if (pm8001_dev)
2678 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302679 break;
2680 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002681 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302682 ts->resp = SAS_TASK_COMPLETE;
2683 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302684 if (pm8001_dev)
2685 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302686 break;
2687 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002688 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302689 ts->resp = SAS_TASK_COMPLETE;
2690 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05302691 if (pm8001_dev)
2692 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302693 break;
2694 case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002695 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302696 ts->resp = SAS_TASK_UNDELIVERED;
2697 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302698 if (pm8001_dev)
2699 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302700 break;
2701 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002702 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302703 ts->resp = SAS_TASK_COMPLETE;
2704 ts->stat = SAS_DATA_UNDERRUN;
Viswas G4a2efd42020-11-02 22:25:26 +05302705 if (pm8001_dev)
2706 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302707 break;
2708 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002709 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302710 ts->resp = SAS_TASK_COMPLETE;
2711 ts->stat = SAS_OPEN_TO;
Viswas G4a2efd42020-11-02 22:25:26 +05302712 if (pm8001_dev)
2713 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302714 break;
2715 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002716 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302717 ts->resp = SAS_TASK_COMPLETE;
2718 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302719 if (pm8001_dev)
2720 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302721 break;
2722 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002723 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302724 ts->resp = SAS_TASK_COMPLETE;
2725 ts->stat = SAS_DEV_NO_RESPONSE;
2726 if (!t->uldd_task) {
2727 pm8001_handle_event(pm8001_ha, pm8001_dev,
2728 IO_DS_NON_OPERATIONAL);
2729 ts->resp = SAS_TASK_UNDELIVERED;
2730 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302731 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302732 return;
2733 }
2734 break;
2735 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002736 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302737 ts->resp = SAS_TASK_COMPLETE;
2738 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302739 if (pm8001_dev)
2740 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302741 break;
2742 case IO_DS_IN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002743 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302744 ts->resp = SAS_TASK_COMPLETE;
2745 ts->stat = SAS_DEV_NO_RESPONSE;
2746 if (!t->uldd_task) {
2747 pm8001_handle_event(pm8001_ha, pm8001_dev,
2748 IO_DS_IN_ERROR);
2749 ts->resp = SAS_TASK_UNDELIVERED;
2750 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302751 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302752 return;
2753 }
2754 break;
2755 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002756 pm8001_dbg(pm8001_ha, IO,
2757 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302758 ts->resp = SAS_TASK_COMPLETE;
2759 ts->stat = SAS_OPEN_REJECT;
2760 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302761 if (pm8001_dev)
2762 atomic_dec(&pm8001_dev->running_req);
Johannes Thumshirn50acde82015-08-17 15:52:32 +02002763 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302764 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002765 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05302766 /* not allowed case. Therefore, return failed status */
2767 ts->resp = SAS_TASK_COMPLETE;
2768 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302769 if (pm8001_dev)
2770 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302771 break;
2772 }
2773 spin_lock_irqsave(&t->task_state_lock, flags);
2774 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2775 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2776 t->task_state_flags |= SAS_TASK_STATE_DONE;
2777 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2778 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002779 pm8001_dbg(pm8001_ha, FAIL,
2780 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2781 t, status, ts->resp, ts->stat);
peter changce21c632019-11-14 15:38:58 +05302782 if (t->slow_task)
2783 complete(&t->slow_task->completion);
Sakthivel Kf5860992013-04-17 16:37:02 +05302784 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302785 } else {
Sakthivel Kf5860992013-04-17 16:37:02 +05302786 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302787 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302788 }
2789}
2790
2791/*See the comments for mpi_ssp_completion */
2792static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
2793{
2794 struct sas_task *t;
2795 struct task_status_struct *ts;
2796 struct pm8001_ccb_info *ccb;
2797 struct pm8001_device *pm8001_dev;
2798 struct sata_event_resp *psataPayload =
2799 (struct sata_event_resp *)(piomb + 4);
2800 u32 event = le32_to_cpu(psataPayload->event);
2801 u32 tag = le32_to_cpu(psataPayload->tag);
2802 u32 port_id = le32_to_cpu(psataPayload->port_id);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302803 u32 dev_id = le32_to_cpu(psataPayload->device_id);
2804 unsigned long flags;
Sakthivel Kf5860992013-04-17 16:37:02 +05302805
2806 ccb = &pm8001_ha->ccb_info[tag];
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302807
2808 if (ccb) {
2809 t = ccb->task;
2810 pm8001_dev = ccb->device;
2811 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002812 pm8001_dbg(pm8001_ha, FAIL, "No CCB !!!. returning\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302813 return;
2814 }
Sakthivel Kf5860992013-04-17 16:37:02 +05302815 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002816 pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302817
2818 /* Check if this is NCQ error */
2819 if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2820 /* find device using device id */
2821 pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2822 /* send read log extension */
2823 if (pm8001_dev)
2824 pm80xx_send_read_log(pm8001_ha, pm8001_dev);
Sakthivel Kf5860992013-04-17 16:37:02 +05302825 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302826 }
2827
2828 if (unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002829 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302830 return;
2831 }
2832
Sakthivel Kf5860992013-04-17 16:37:02 +05302833 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002834 pm8001_dbg(pm8001_ha, IOERR, "port_id:0x%x, tag:0x%x, event:0x%x\n",
2835 port_id, tag, event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302836 switch (event) {
2837 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002838 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302839 ts->resp = SAS_TASK_COMPLETE;
2840 ts->stat = SAS_DATA_OVERRUN;
2841 ts->residual = 0;
2842 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302843 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05302844 break;
2845 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002846 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302847 ts->resp = SAS_TASK_COMPLETE;
2848 ts->stat = SAS_INTERRUPTED;
2849 break;
2850 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002851 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302852 ts->resp = SAS_TASK_COMPLETE;
2853 ts->stat = SAS_OPEN_REJECT;
2854 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2855 break;
2856 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002857 pm8001_dbg(pm8001_ha, IO,
2858 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302859 ts->resp = SAS_TASK_COMPLETE;
2860 ts->stat = SAS_OPEN_REJECT;
2861 ts->open_rej_reason = SAS_OREJ_EPROTO;
2862 break;
2863 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002864 pm8001_dbg(pm8001_ha, IO,
2865 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302866 ts->resp = SAS_TASK_COMPLETE;
2867 ts->stat = SAS_OPEN_REJECT;
2868 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2869 break;
2870 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002871 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302872 ts->resp = SAS_TASK_COMPLETE;
2873 ts->stat = SAS_OPEN_REJECT;
2874 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2875 break;
2876 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302877 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2878 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2879 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2880 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2881 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002882 pm8001_dbg(pm8001_ha, FAIL,
2883 "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302884 ts->resp = SAS_TASK_UNDELIVERED;
2885 ts->stat = SAS_DEV_NO_RESPONSE;
2886 if (!t->uldd_task) {
2887 pm8001_handle_event(pm8001_ha,
2888 pm8001_dev,
2889 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2890 ts->resp = SAS_TASK_COMPLETE;
2891 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302892 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05302893 return;
2894 }
2895 break;
2896 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002897 pm8001_dbg(pm8001_ha, IO,
2898 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302899 ts->resp = SAS_TASK_UNDELIVERED;
2900 ts->stat = SAS_OPEN_REJECT;
2901 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2902 break;
2903 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002904 pm8001_dbg(pm8001_ha, IO,
2905 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302906 ts->resp = SAS_TASK_COMPLETE;
2907 ts->stat = SAS_OPEN_REJECT;
2908 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2909 break;
2910 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002911 pm8001_dbg(pm8001_ha, IO,
2912 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302913 ts->resp = SAS_TASK_COMPLETE;
2914 ts->stat = SAS_OPEN_REJECT;
2915 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2916 break;
2917 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002918 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302919 ts->resp = SAS_TASK_COMPLETE;
2920 ts->stat = SAS_NAK_R_ERR;
2921 break;
2922 case IO_XFER_ERROR_PEER_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002923 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302924 ts->resp = SAS_TASK_COMPLETE;
2925 ts->stat = SAS_NAK_R_ERR;
2926 break;
2927 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002928 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302929 ts->resp = SAS_TASK_COMPLETE;
2930 ts->stat = SAS_DATA_UNDERRUN;
2931 break;
2932 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002933 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302934 ts->resp = SAS_TASK_COMPLETE;
2935 ts->stat = SAS_OPEN_TO;
2936 break;
2937 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002938 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302939 ts->resp = SAS_TASK_COMPLETE;
2940 ts->stat = SAS_OPEN_TO;
2941 break;
2942 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002943 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302944 ts->resp = SAS_TASK_COMPLETE;
2945 ts->stat = SAS_OPEN_TO;
2946 break;
2947 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002948 pm8001_dbg(pm8001_ha, IO,
2949 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302950 ts->resp = SAS_TASK_COMPLETE;
2951 ts->stat = SAS_OPEN_TO;
2952 break;
2953 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002954 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302955 ts->resp = SAS_TASK_COMPLETE;
2956 ts->stat = SAS_OPEN_TO;
2957 break;
2958 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002959 pm8001_dbg(pm8001_ha, IO,
2960 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302961 ts->resp = SAS_TASK_COMPLETE;
2962 ts->stat = SAS_OPEN_TO;
2963 break;
2964 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002965 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302966 break;
2967 case IO_XFER_PIO_SETUP_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002968 pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05302969 ts->resp = SAS_TASK_COMPLETE;
2970 ts->stat = SAS_OPEN_TO;
2971 break;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302972 case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002973 pm8001_dbg(pm8001_ha, FAIL,
2974 "IO_XFR_ERROR_INTERNAL_CRC_ERROR\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302975 /* TBC: used default set values */
2976 ts->resp = SAS_TASK_COMPLETE;
2977 ts->stat = SAS_OPEN_TO;
2978 break;
2979 case IO_XFER_DMA_ACTIVATE_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002980 pm8001_dbg(pm8001_ha, FAIL, "IO_XFR_DMA_ACTIVATE_TIMEOUT\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05302981 /* TBC: used default set values */
2982 ts->resp = SAS_TASK_COMPLETE;
2983 ts->stat = SAS_OPEN_TO;
2984 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05302985 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002986 pm8001_dbg(pm8001_ha, IO, "Unknown status 0x%x\n", event);
Sakthivel Kf5860992013-04-17 16:37:02 +05302987 /* not allowed case. Therefore, return failed status */
2988 ts->resp = SAS_TASK_COMPLETE;
2989 ts->stat = SAS_OPEN_TO;
2990 break;
2991 }
2992 spin_lock_irqsave(&t->task_state_lock, flags);
2993 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2994 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2995 t->task_state_flags |= SAS_TASK_STATE_DONE;
2996 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2997 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002998 pm8001_dbg(pm8001_ha, FAIL,
2999 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
3000 t, event, ts->resp, ts->stat);
Sakthivel Kf5860992013-04-17 16:37:02 +05303001 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05303002 } else {
Sakthivel Kf5860992013-04-17 16:37:02 +05303003 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05303004 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05303005 }
3006}
3007
3008/*See the comments for mpi_ssp_completion */
3009static void
3010mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
3011{
3012 u32 param, i;
3013 struct sas_task *t;
3014 struct pm8001_ccb_info *ccb;
3015 unsigned long flags;
3016 u32 status;
3017 u32 tag;
3018 struct smp_completion_resp *psmpPayload;
3019 struct task_status_struct *ts;
3020 struct pm8001_device *pm8001_dev;
3021 char *pdma_respaddr = NULL;
3022
3023 psmpPayload = (struct smp_completion_resp *)(piomb + 4);
3024 status = le32_to_cpu(psmpPayload->status);
3025 tag = le32_to_cpu(psmpPayload->tag);
3026
3027 ccb = &pm8001_ha->ccb_info[tag];
3028 param = le32_to_cpu(psmpPayload->param);
3029 t = ccb->task;
3030 ts = &t->task_status;
3031 pm8001_dev = ccb->device;
3032 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08003033 pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303034 if (unlikely(!t || !t->lldd_task || !t->dev))
3035 return;
3036
Joe Perches1b5d2792020-11-20 15:16:09 -08003037 pm8001_dbg(pm8001_ha, DEV, "tag::0x%x status::0x%x\n", tag, status);
peter chang73706722019-11-14 15:39:02 +05303038
Sakthivel Kf5860992013-04-17 16:37:02 +05303039 switch (status) {
3040
3041 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003042 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303043 ts->resp = SAS_TASK_COMPLETE;
3044 ts->stat = SAM_STAT_GOOD;
3045 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303046 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05303047 if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003048 pm8001_dbg(pm8001_ha, IO,
3049 "DIRECT RESPONSE Length:%d\n",
3050 param);
Sakthivel Kf5860992013-04-17 16:37:02 +05303051 pdma_respaddr = (char *)(phys_to_virt(cpu_to_le64
3052 ((u64)sg_dma_address
3053 (&t->smp_task.smp_resp))));
3054 for (i = 0; i < param; i++) {
3055 *(pdma_respaddr+i) = psmpPayload->_r_a[i];
Joe Perches1b5d2792020-11-20 15:16:09 -08003056 pm8001_dbg(pm8001_ha, IO,
3057 "SMP Byte%d DMA data 0x%x psmp 0x%x\n",
3058 i, *(pdma_respaddr + i),
3059 psmpPayload->_r_a[i]);
Sakthivel Kf5860992013-04-17 16:37:02 +05303060 }
3061 }
3062 break;
3063 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003064 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303065 ts->resp = SAS_TASK_COMPLETE;
3066 ts->stat = SAS_ABORTED_TASK;
3067 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303068 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05303069 break;
3070 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08003071 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303072 ts->resp = SAS_TASK_COMPLETE;
3073 ts->stat = SAS_DATA_OVERRUN;
3074 ts->residual = 0;
3075 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303076 atomic_dec(&pm8001_dev->running_req);
Sakthivel Kf5860992013-04-17 16:37:02 +05303077 break;
3078 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003079 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303080 ts->resp = SAS_TASK_COMPLETE;
3081 ts->stat = SAS_PHY_DOWN;
3082 break;
3083 case IO_ERROR_HW_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003084 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303085 ts->resp = SAS_TASK_COMPLETE;
3086 ts->stat = SAM_STAT_BUSY;
3087 break;
3088 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003089 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303090 ts->resp = SAS_TASK_COMPLETE;
3091 ts->stat = SAM_STAT_BUSY;
3092 break;
3093 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003094 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303095 ts->resp = SAS_TASK_COMPLETE;
3096 ts->stat = SAM_STAT_BUSY;
3097 break;
3098 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003099 pm8001_dbg(pm8001_ha, IO,
3100 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303101 ts->resp = SAS_TASK_COMPLETE;
3102 ts->stat = SAS_OPEN_REJECT;
3103 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3104 break;
3105 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003106 pm8001_dbg(pm8001_ha, IO,
3107 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303108 ts->resp = SAS_TASK_COMPLETE;
3109 ts->stat = SAS_OPEN_REJECT;
3110 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3111 break;
3112 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003113 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303114 ts->resp = SAS_TASK_COMPLETE;
3115 ts->stat = SAS_OPEN_REJECT;
3116 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
3117 break;
3118 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05303119 case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
3120 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
3121 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
3122 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
3123 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003124 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303125 ts->resp = SAS_TASK_COMPLETE;
3126 ts->stat = SAS_OPEN_REJECT;
3127 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3128 pm8001_handle_event(pm8001_ha,
3129 pm8001_dev,
3130 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
3131 break;
3132 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003133 pm8001_dbg(pm8001_ha, IO,
3134 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303135 ts->resp = SAS_TASK_COMPLETE;
3136 ts->stat = SAS_OPEN_REJECT;
3137 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
3138 break;
3139 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003140 pm8001_dbg(pm8001_ha, IO,
3141 "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303142 ts->resp = SAS_TASK_COMPLETE;
3143 ts->stat = SAS_OPEN_REJECT;
3144 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
3145 break;
3146 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003147 pm8001_dbg(pm8001_ha, IO,
3148 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303149 ts->resp = SAS_TASK_COMPLETE;
3150 ts->stat = SAS_OPEN_REJECT;
3151 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
3152 break;
3153 case IO_XFER_ERROR_RX_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08003154 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303155 ts->resp = SAS_TASK_COMPLETE;
3156 ts->stat = SAS_DEV_NO_RESPONSE;
3157 break;
3158 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003159 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303160 ts->resp = SAS_TASK_COMPLETE;
3161 ts->stat = SAS_OPEN_REJECT;
3162 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3163 break;
3164 case IO_ERROR_INTERNAL_SMP_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003165 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303166 ts->resp = SAS_TASK_COMPLETE;
3167 ts->stat = SAS_QUEUE_FULL;
3168 break;
3169 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003170 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303171 ts->resp = SAS_TASK_COMPLETE;
3172 ts->stat = SAS_OPEN_REJECT;
3173 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3174 break;
3175 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003176 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303177 ts->resp = SAS_TASK_COMPLETE;
3178 ts->stat = SAS_DEV_NO_RESPONSE;
3179 break;
3180 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003181 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303182 ts->resp = SAS_TASK_COMPLETE;
3183 ts->stat = SAS_OPEN_REJECT;
3184 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3185 break;
3186 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003187 pm8001_dbg(pm8001_ha, IO,
3188 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303189 ts->resp = SAS_TASK_COMPLETE;
3190 ts->stat = SAS_OPEN_REJECT;
3191 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3192 break;
3193 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003194 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303195 ts->resp = SAS_TASK_COMPLETE;
3196 ts->stat = SAS_DEV_NO_RESPONSE;
3197 /* not allowed case. Therefore, return failed status */
3198 break;
3199 }
3200 spin_lock_irqsave(&t->task_state_lock, flags);
3201 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3202 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3203 t->task_state_flags |= SAS_TASK_STATE_DONE;
3204 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3205 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08003206 pm8001_dbg(pm8001_ha, FAIL,
3207 "task 0x%p done with io_status 0x%x resp 0x%xstat 0x%x but aborted by upper layer!\n",
3208 t, status, ts->resp, ts->stat);
Sakthivel Kf5860992013-04-17 16:37:02 +05303209 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3210 } else {
3211 spin_unlock_irqrestore(&t->task_state_lock, flags);
3212 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3213 mb();/* in order to force CPU ordering */
3214 t->task_done(t);
3215 }
3216}
3217
3218/**
3219 * pm80xx_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
3220 * @pm8001_ha: our hba card information
3221 * @Qnum: the outbound queue message number.
3222 * @SEA: source of event to ack
3223 * @port_id: port id.
3224 * @phyId: phy id.
3225 * @param0: parameter 0.
3226 * @param1: parameter 1.
3227 */
3228static void pm80xx_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3229 u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3230{
3231 struct hw_event_ack_req payload;
3232 u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3233
3234 struct inbound_queue_table *circularQ;
3235
3236 memset((u8 *)&payload, 0, sizeof(payload));
3237 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
3238 payload.tag = cpu_to_le32(1);
3239 payload.phyid_sea_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3240 ((phyId & 0xFF) << 24) | (port_id & 0xFF));
3241 payload.param0 = cpu_to_le32(param0);
3242 payload.param1 = cpu_to_le32(param1);
peter chang91a43fa2019-11-14 15:39:05 +05303243 pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
3244 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303245}
3246
3247static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3248 u32 phyId, u32 phy_op);
3249
Viswas G8414cd82015-08-11 15:06:30 +05303250static void hw_event_port_recover(struct pm8001_hba_info *pm8001_ha,
3251 void *piomb)
3252{
3253 struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4);
3254 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3255 u8 phy_id = (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3256 u32 lr_status_evt_portid =
3257 le32_to_cpu(pPayload->lr_status_evt_portid);
3258 u8 deviceType = pPayload->sas_identify.dev_type;
3259 u8 link_rate = (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3260 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3261 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3262 struct pm8001_port *port = &pm8001_ha->port[port_id];
3263
3264 if (deviceType == SAS_END_DEVICE) {
3265 pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
3266 PHY_NOTIFY_ENABLE_SPINUP);
3267 }
3268
3269 port->wide_port_phymap |= (1U << phy_id);
3270 pm8001_get_lrate_mode(phy, link_rate);
3271 phy->sas_phy.oob_mode = SAS_OOB_MODE;
3272 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
3273 phy->phy_attached = 1;
3274}
3275
Sakthivel Kf5860992013-04-17 16:37:02 +05303276/**
3277 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
3278 * @pm8001_ha: our hba card information
3279 * @piomb: IO message buffer
3280 */
3281static void
3282hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3283{
3284 struct hw_event_resp *pPayload =
3285 (struct hw_event_resp *)(piomb + 4);
3286 u32 lr_status_evt_portid =
3287 le32_to_cpu(pPayload->lr_status_evt_portid);
3288 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3289
3290 u8 link_rate =
3291 (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3292 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3293 u8 phy_id =
3294 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3295 u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3296
3297 struct pm8001_port *port = &pm8001_ha->port[port_id];
3298 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3299 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3300 unsigned long flags;
3301 u8 deviceType = pPayload->sas_identify.dev_type;
3302 port->port_state = portstate;
Viswas G8414cd82015-08-11 15:06:30 +05303303 port->wide_port_phymap |= (1U << phy_id);
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303304 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
Joe Perches1b5d2792020-11-20 15:16:09 -08003305 pm8001_dbg(pm8001_ha, MSG,
3306 "portid:%d; phyid:%d; linkrate:%d; portstate:%x; devicetype:%x\n",
3307 port_id, phy_id, link_rate, portstate, deviceType);
Sakthivel Kf5860992013-04-17 16:37:02 +05303308
3309 switch (deviceType) {
3310 case SAS_PHY_UNUSED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003311 pm8001_dbg(pm8001_ha, MSG, "device type no device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303312 break;
3313 case SAS_END_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003314 pm8001_dbg(pm8001_ha, MSG, "end device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303315 pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
3316 PHY_NOTIFY_ENABLE_SPINUP);
3317 port->port_attached = 1;
3318 pm8001_get_lrate_mode(phy, link_rate);
3319 break;
3320 case SAS_EDGE_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003321 pm8001_dbg(pm8001_ha, MSG, "expander device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303322 port->port_attached = 1;
3323 pm8001_get_lrate_mode(phy, link_rate);
3324 break;
3325 case SAS_FANOUT_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003326 pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303327 port->port_attached = 1;
3328 pm8001_get_lrate_mode(phy, link_rate);
3329 break;
3330 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003331 pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n",
3332 deviceType);
Sakthivel Kf5860992013-04-17 16:37:02 +05303333 break;
3334 }
3335 phy->phy_type |= PORT_TYPE_SAS;
3336 phy->identify.device_type = deviceType;
3337 phy->phy_attached = 1;
3338 if (phy->identify.device_type == SAS_END_DEVICE)
3339 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
3340 else if (phy->identify.device_type != SAS_PHY_UNUSED)
3341 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3342 phy->sas_phy.oob_mode = SAS_OOB_MODE;
3343 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
3344 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3345 memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3346 sizeof(struct sas_identify_frame)-4);
3347 phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3348 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3349 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3350 if (pm8001_ha->flags == PM8001F_RUN_TIME)
Ahmed S. Darwish4ba9e512020-11-26 14:29:39 +01003351 mdelay(200); /* delay a moment to wait for disk to spin up */
Sakthivel Kf5860992013-04-17 16:37:02 +05303352 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3353}
3354
3355/**
3356 * hw_event_sata_phy_up -FW tells me a SATA phy up event.
3357 * @pm8001_ha: our hba card information
3358 * @piomb: IO message buffer
3359 */
3360static void
3361hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3362{
3363 struct hw_event_resp *pPayload =
3364 (struct hw_event_resp *)(piomb + 4);
3365 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3366 u32 lr_status_evt_portid =
3367 le32_to_cpu(pPayload->lr_status_evt_portid);
3368 u8 link_rate =
3369 (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3370 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3371 u8 phy_id =
3372 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3373
3374 u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3375
3376 struct pm8001_port *port = &pm8001_ha->port[port_id];
3377 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3378 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3379 unsigned long flags;
Joe Perches1b5d2792020-11-20 15:16:09 -08003380 pm8001_dbg(pm8001_ha, DEVIO,
3381 "port id %d, phy id %d link_rate %d portstate 0x%x\n",
3382 port_id, phy_id, link_rate, portstate);
Sakthivel Kf5860992013-04-17 16:37:02 +05303383
3384 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303385 phy->phy_state = PHY_STATE_LINK_UP_SPCV;
Sakthivel Kf5860992013-04-17 16:37:02 +05303386 port->port_attached = 1;
3387 pm8001_get_lrate_mode(phy, link_rate);
3388 phy->phy_type |= PORT_TYPE_SATA;
3389 phy->phy_attached = 1;
3390 phy->sas_phy.oob_mode = SATA_OOB_MODE;
3391 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
3392 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3393 memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3394 sizeof(struct dev_to_host_fis));
3395 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3396 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
James Bottomleyaa9f8322013-05-07 14:44:06 -07003397 phy->identify.device_type = SAS_SATA_DEV;
Sakthivel Kf5860992013-04-17 16:37:02 +05303398 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3399 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3400 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3401}
3402
3403/**
3404 * hw_event_phy_down -we should notify the libsas the phy is down.
3405 * @pm8001_ha: our hba card information
3406 * @piomb: IO message buffer
3407 */
3408static void
3409hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3410{
3411 struct hw_event_resp *pPayload =
3412 (struct hw_event_resp *)(piomb + 4);
3413
3414 u32 lr_status_evt_portid =
3415 le32_to_cpu(pPayload->lr_status_evt_portid);
3416 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3417 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3418 u8 phy_id =
3419 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3420 u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3421
3422 struct pm8001_port *port = &pm8001_ha->port[port_id];
3423 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
Viswas G869ddbd2017-10-18 11:39:13 +05303424 u32 port_sata = (phy->phy_type & PORT_TYPE_SATA);
Sakthivel Kf5860992013-04-17 16:37:02 +05303425 port->port_state = portstate;
Sakthivel Kf5860992013-04-17 16:37:02 +05303426 phy->identify.device_type = 0;
3427 phy->phy_attached = 0;
Sakthivel Kf5860992013-04-17 16:37:02 +05303428 switch (portstate) {
3429 case PORT_VALID:
3430 break;
3431 case PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003432 pm8001_dbg(pm8001_ha, MSG, " PortInvalid portID %d\n",
3433 port_id);
3434 pm8001_dbg(pm8001_ha, MSG,
3435 " Last phy Down and port invalid\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303436 if (port_sata) {
Viswas G8414cd82015-08-11 15:06:30 +05303437 phy->phy_type = 0;
3438 port->port_attached = 0;
3439 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3440 port_id, phy_id, 0, 0);
3441 }
3442 sas_phy_disconnected(&phy->sas_phy);
Sakthivel Kf5860992013-04-17 16:37:02 +05303443 break;
3444 case PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003445 pm8001_dbg(pm8001_ha, MSG, " Port In Reset portID %d\n",
3446 port_id);
Sakthivel Kf5860992013-04-17 16:37:02 +05303447 break;
3448 case PORT_NOT_ESTABLISHED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003449 pm8001_dbg(pm8001_ha, MSG,
3450 " Phy Down and PORT_NOT_ESTABLISHED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303451 port->port_attached = 0;
3452 break;
3453 case PORT_LOSTCOMM:
Joe Perches1b5d2792020-11-20 15:16:09 -08003454 pm8001_dbg(pm8001_ha, MSG, " Phy Down and PORT_LOSTCOMM\n");
3455 pm8001_dbg(pm8001_ha, MSG,
3456 " Last phy Down and port invalid\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303457 if (port_sata) {
Viswas G8414cd82015-08-11 15:06:30 +05303458 port->port_attached = 0;
3459 phy->phy_type = 0;
3460 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3461 port_id, phy_id, 0, 0);
3462 }
3463 sas_phy_disconnected(&phy->sas_phy);
Sakthivel Kf5860992013-04-17 16:37:02 +05303464 break;
3465 default:
3466 port->port_attached = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08003467 pm8001_dbg(pm8001_ha, DEVIO,
3468 " Phy Down and(default) = 0x%x\n",
3469 portstate);
Sakthivel Kf5860992013-04-17 16:37:02 +05303470 break;
3471
3472 }
Viswas G869ddbd2017-10-18 11:39:13 +05303473 if (port_sata && (portstate != PORT_IN_RESET)) {
3474 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3475
3476 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
3477 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303478}
3479
3480static int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3481{
3482 struct phy_start_resp *pPayload =
3483 (struct phy_start_resp *)(piomb + 4);
3484 u32 status =
3485 le32_to_cpu(pPayload->status);
3486 u32 phy_id =
3487 le32_to_cpu(pPayload->phyid);
3488 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3489
Joe Perches1b5d2792020-11-20 15:16:09 -08003490 pm8001_dbg(pm8001_ha, INIT,
3491 "phy start resp status:0x%x, phyid:0x%x\n",
3492 status, phy_id);
Sakthivel Kf5860992013-04-17 16:37:02 +05303493 if (status == 0) {
Deepak Ukeycd135752018-09-11 14:18:02 +05303494 phy->phy_state = PHY_LINK_DOWN;
3495 if (pm8001_ha->flags == PM8001F_RUN_TIME &&
peter change7039772019-11-14 15:38:59 +05303496 phy->enable_completion != NULL) {
Sakthivel Kf5860992013-04-17 16:37:02 +05303497 complete(phy->enable_completion);
peter change7039772019-11-14 15:38:59 +05303498 phy->enable_completion = NULL;
3499 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303500 }
3501 return 0;
3502
3503}
3504
3505/**
3506 * mpi_thermal_hw_event -The hw event has come.
3507 * @pm8001_ha: our hba card information
3508 * @piomb: IO message buffer
3509 */
3510static int mpi_thermal_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3511{
3512 struct thermal_hw_event *pPayload =
3513 (struct thermal_hw_event *)(piomb + 4);
3514
3515 u32 thermal_event = le32_to_cpu(pPayload->thermal_event);
3516 u32 rht_lht = le32_to_cpu(pPayload->rht_lht);
3517
3518 if (thermal_event & 0x40) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003519 pm8001_dbg(pm8001_ha, IO,
3520 "Thermal Event: Local high temperature violated!\n");
3521 pm8001_dbg(pm8001_ha, IO,
3522 "Thermal Event: Measured local high temperature %d\n",
3523 ((rht_lht & 0xFF00) >> 8));
Sakthivel Kf5860992013-04-17 16:37:02 +05303524 }
3525 if (thermal_event & 0x10) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003526 pm8001_dbg(pm8001_ha, IO,
3527 "Thermal Event: Remote high temperature violated!\n");
3528 pm8001_dbg(pm8001_ha, IO,
3529 "Thermal Event: Measured remote high temperature %d\n",
3530 ((rht_lht & 0xFF000000) >> 24));
Sakthivel Kf5860992013-04-17 16:37:02 +05303531 }
3532 return 0;
3533}
3534
3535/**
3536 * mpi_hw_event -The hw event has come.
3537 * @pm8001_ha: our hba card information
3538 * @piomb: IO message buffer
3539 */
3540static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3541{
Viswas G8414cd82015-08-11 15:06:30 +05303542 unsigned long flags, i;
Sakthivel Kf5860992013-04-17 16:37:02 +05303543 struct hw_event_resp *pPayload =
3544 (struct hw_event_resp *)(piomb + 4);
3545 u32 lr_status_evt_portid =
3546 le32_to_cpu(pPayload->lr_status_evt_portid);
3547 u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3548 u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3549 u8 phy_id =
3550 (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3551 u16 eventType =
3552 (u16)((lr_status_evt_portid & 0x00FFFF00) >> 8);
3553 u8 status =
3554 (u8)((lr_status_evt_portid & 0x0F000000) >> 24);
Sakthivel Kf5860992013-04-17 16:37:02 +05303555 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3556 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
Viswas G8414cd82015-08-11 15:06:30 +05303557 struct pm8001_port *port = &pm8001_ha->port[port_id];
Sakthivel Kf5860992013-04-17 16:37:02 +05303558 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
Joe Perches1b5d2792020-11-20 15:16:09 -08003559 pm8001_dbg(pm8001_ha, DEV,
3560 "portid:%d phyid:%d event:0x%x status:0x%x\n",
3561 port_id, phy_id, eventType, status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303562
3563 switch (eventType) {
3564
3565 case HW_EVENT_SAS_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003566 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303567 hw_event_sas_phy_up(pm8001_ha, piomb);
3568 break;
3569 case HW_EVENT_SATA_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003570 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_PHY_UP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303571 hw_event_sata_phy_up(pm8001_ha, piomb);
3572 break;
3573 case HW_EVENT_SATA_SPINUP_HOLD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003574 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_SPINUP_HOLD\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303575 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
3576 break;
3577 case HW_EVENT_PHY_DOWN:
Joe Perches1b5d2792020-11-20 15:16:09 -08003578 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_DOWN\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303579 hw_event_phy_down(pm8001_ha, piomb);
3580 if (pm8001_ha->reset_in_progress) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003581 pm8001_dbg(pm8001_ha, MSG, "Reset in progress\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303582 return 0;
3583 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303584 phy->phy_attached = 0;
Deepak Ukeycd135752018-09-11 14:18:02 +05303585 phy->phy_state = PHY_LINK_DISABLE;
Sakthivel Kf5860992013-04-17 16:37:02 +05303586 break;
3587 case HW_EVENT_PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003588 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_INVALID\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303589 sas_phy_disconnected(sas_phy);
3590 phy->phy_attached = 0;
3591 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3592 break;
3593 /* the broadcast change primitive received, tell the LIBSAS this event
3594 to revalidate the sas domain*/
3595 case HW_EVENT_BROADCAST_CHANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003596 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303597 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3598 port_id, phy_id, 1, 0);
3599 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3600 sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3601 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3602 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3603 break;
3604 case HW_EVENT_PHY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003605 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303606 sas_phy_disconnected(&phy->sas_phy);
3607 phy->phy_attached = 0;
3608 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
3609 break;
3610 case HW_EVENT_BROADCAST_EXP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003611 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303612 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3613 sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3614 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3615 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3616 break;
3617 case HW_EVENT_LINK_ERR_INVALID_DWORD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003618 pm8001_dbg(pm8001_ha, MSG,
3619 "HW_EVENT_LINK_ERR_INVALID_DWORD\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303620 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3621 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303622 break;
3623 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003624 pm8001_dbg(pm8001_ha, MSG,
3625 "HW_EVENT_LINK_ERR_DISPARITY_ERROR\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303626 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3627 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3628 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303629 break;
3630 case HW_EVENT_LINK_ERR_CODE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003631 pm8001_dbg(pm8001_ha, MSG,
3632 "HW_EVENT_LINK_ERR_CODE_VIOLATION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303633 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3634 HW_EVENT_LINK_ERR_CODE_VIOLATION,
3635 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303636 break;
3637 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08003638 pm8001_dbg(pm8001_ha, MSG,
3639 "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303640 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3641 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3642 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303643 break;
3644 case HW_EVENT_MALFUNCTION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003645 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_MALFUNCTION\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303646 break;
3647 case HW_EVENT_BROADCAST_SES:
Joe Perches1b5d2792020-11-20 15:16:09 -08003648 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303649 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3650 sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3651 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3652 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3653 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");
Sakthivel Kf5860992013-04-17 16:37:02 +05303662 sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
3663 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;
3668 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3669 break;
3670 case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003671 pm8001_dbg(pm8001_ha, MSG,
3672 "HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303673 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3674 HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3675 port_id, phy_id, 0, 0);
3676 sas_phy_disconnected(sas_phy);
3677 phy->phy_attached = 0;
3678 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3679 break;
3680 case HW_EVENT_PORT_RESET_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003681 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_TIMER_TMO\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303682 pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3683 port_id, phy_id, 0, 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05303684 sas_phy_disconnected(sas_phy);
3685 phy->phy_attached = 0;
3686 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
Viswas G869ddbd2017-10-18 11:39:13 +05303687 if (pm8001_ha->phy[phy_id].reset_completion) {
3688 pm8001_ha->phy[phy_id].port_reset_status =
3689 PORT_RESET_TMO;
3690 complete(pm8001_ha->phy[phy_id].reset_completion);
3691 pm8001_ha->phy[phy_id].reset_completion = NULL;
3692 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303693 break;
3694 case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003695 pm8001_dbg(pm8001_ha, MSG,
3696 "HW_EVENT_PORT_RECOVERY_TIMER_TMO\n");
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05303697 pm80xx_hw_event_ack_req(pm8001_ha, 0,
3698 HW_EVENT_PORT_RECOVERY_TIMER_TMO,
3699 port_id, phy_id, 0, 0);
Viswas G8414cd82015-08-11 15:06:30 +05303700 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
3701 if (port->wide_port_phymap & (1 << i)) {
3702 phy = &pm8001_ha->phy[i];
3703 sas_ha->notify_phy_event(&phy->sas_phy,
3704 PHYE_LOSS_OF_SIGNAL);
3705 port->wide_port_phymap &= ~(1 << i);
3706 }
3707 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303708 break;
3709 case HW_EVENT_PORT_RECOVER:
Joe Perches1b5d2792020-11-20 15:16:09 -08003710 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RECOVER\n");
Viswas G8414cd82015-08-11 15:06:30 +05303711 hw_event_port_recover(pm8001_ha, piomb);
Sakthivel Kf5860992013-04-17 16:37:02 +05303712 break;
3713 case HW_EVENT_PORT_RESET_COMPLETE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003714 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_COMPLETE\n");
Viswas G869ddbd2017-10-18 11:39:13 +05303715 if (pm8001_ha->phy[phy_id].reset_completion) {
3716 pm8001_ha->phy[phy_id].port_reset_status =
3717 PORT_RESET_SUCCESS;
3718 complete(pm8001_ha->phy[phy_id].reset_completion);
3719 pm8001_ha->phy[phy_id].reset_completion = NULL;
3720 }
Sakthivel Kf5860992013-04-17 16:37:02 +05303721 break;
3722 case EVENT_BROADCAST_ASYNCH_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003723 pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303724 break;
3725 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003726 pm8001_dbg(pm8001_ha, DEVIO, "Unknown event type 0x%x\n",
3727 eventType);
Sakthivel Kf5860992013-04-17 16:37:02 +05303728 break;
3729 }
3730 return 0;
3731}
3732
3733/**
3734 * mpi_phy_stop_resp - SPCv specific
3735 * @pm8001_ha: our hba card information
3736 * @piomb: IO message buffer
3737 */
3738static int mpi_phy_stop_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3739{
3740 struct phy_stop_resp *pPayload =
3741 (struct phy_stop_resp *)(piomb + 4);
3742 u32 status =
3743 le32_to_cpu(pPayload->status);
3744 u32 phyid =
Deepak Ukeycd135752018-09-11 14:18:02 +05303745 le32_to_cpu(pPayload->phyid) & 0xFF;
Sakthivel Kf5860992013-04-17 16:37:02 +05303746 struct pm8001_phy *phy = &pm8001_ha->phy[phyid];
Joe Perches1b5d2792020-11-20 15:16:09 -08003747 pm8001_dbg(pm8001_ha, MSG, "phy:0x%x status:0x%x\n",
3748 phyid, status);
Deepak Ukeycd135752018-09-11 14:18:02 +05303749 if (status == PHY_STOP_SUCCESS ||
3750 status == PHY_STOP_ERR_DEVICE_ATTACHED)
3751 phy->phy_state = PHY_LINK_DISABLE;
Sakthivel Kf5860992013-04-17 16:37:02 +05303752 return 0;
3753}
3754
3755/**
3756 * mpi_set_controller_config_resp - SPCv specific
3757 * @pm8001_ha: our hba card information
3758 * @piomb: IO message buffer
3759 */
3760static int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3761 void *piomb)
3762{
3763 struct set_ctrl_cfg_resp *pPayload =
3764 (struct set_ctrl_cfg_resp *)(piomb + 4);
3765 u32 status = le32_to_cpu(pPayload->status);
3766 u32 err_qlfr_pgcd = le32_to_cpu(pPayload->err_qlfr_pgcd);
3767
Joe Perches1b5d2792020-11-20 15:16:09 -08003768 pm8001_dbg(pm8001_ha, MSG,
3769 "SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
3770 status, err_qlfr_pgcd);
Sakthivel Kf5860992013-04-17 16:37:02 +05303771
3772 return 0;
3773}
3774
3775/**
3776 * mpi_get_controller_config_resp - SPCv specific
3777 * @pm8001_ha: our hba card information
3778 * @piomb: IO message buffer
3779 */
3780static int mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3781 void *piomb)
3782{
Joe Perches1b5d2792020-11-20 15:16:09 -08003783 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303784
3785 return 0;
3786}
3787
3788/**
3789 * mpi_get_phy_profile_resp - SPCv specific
3790 * @pm8001_ha: our hba card information
3791 * @piomb: IO message buffer
3792 */
3793static int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3794 void *piomb)
3795{
Joe Perches1b5d2792020-11-20 15:16:09 -08003796 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303797
3798 return 0;
3799}
3800
3801/**
3802 * mpi_flash_op_ext_resp - SPCv specific
3803 * @pm8001_ha: our hba card information
3804 * @piomb: IO message buffer
3805 */
3806static int mpi_flash_op_ext_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3807{
Joe Perches1b5d2792020-11-20 15:16:09 -08003808 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303809
3810 return 0;
3811}
3812
3813/**
3814 * mpi_set_phy_profile_resp - SPCv specific
3815 * @pm8001_ha: our hba card information
3816 * @piomb: IO message buffer
3817 */
3818static int mpi_set_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3819 void *piomb)
3820{
yuuzheng9d9c7c22020-03-16 13:19:03 +05303821 u32 tag;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303822 u8 page_code;
yuuzheng9d9c7c22020-03-16 13:19:03 +05303823 int rc = 0;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303824 struct set_phy_profile_resp *pPayload =
3825 (struct set_phy_profile_resp *)(piomb + 4);
3826 u32 ppc_phyid = le32_to_cpu(pPayload->ppc_phyid);
3827 u32 status = le32_to_cpu(pPayload->status);
Sakthivel Kf5860992013-04-17 16:37:02 +05303828
yuuzheng9d9c7c22020-03-16 13:19:03 +05303829 tag = le32_to_cpu(pPayload->tag);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303830 page_code = (u8)((ppc_phyid & 0xFF00) >> 8);
3831 if (status) {
3832 /* status is FAILED */
Joe Perches1b5d2792020-11-20 15:16:09 -08003833 pm8001_dbg(pm8001_ha, FAIL,
3834 "PhyProfile command failed with status 0x%08X\n",
3835 status);
yuuzheng9d9c7c22020-03-16 13:19:03 +05303836 rc = -1;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303837 } else {
3838 if (page_code != SAS_PHY_ANALOG_SETTINGS_PAGE) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003839 pm8001_dbg(pm8001_ha, FAIL, "Invalid page code 0x%X\n",
3840 page_code);
yuuzheng9d9c7c22020-03-16 13:19:03 +05303841 rc = -1;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05303842 }
3843 }
yuuzheng9d9c7c22020-03-16 13:19:03 +05303844 pm8001_tag_free(pm8001_ha, tag);
3845 return rc;
Sakthivel Kf5860992013-04-17 16:37:02 +05303846}
3847
3848/**
3849 * mpi_kek_management_resp - SPCv specific
3850 * @pm8001_ha: our hba card information
3851 * @piomb: IO message buffer
3852 */
3853static int mpi_kek_management_resp(struct pm8001_hba_info *pm8001_ha,
3854 void *piomb)
3855{
3856 struct kek_mgmt_resp *pPayload = (struct kek_mgmt_resp *)(piomb + 4);
3857
3858 u32 status = le32_to_cpu(pPayload->status);
3859 u32 kidx_new_curr_ksop = le32_to_cpu(pPayload->kidx_new_curr_ksop);
3860 u32 err_qlfr = le32_to_cpu(pPayload->err_qlfr);
3861
Joe Perches1b5d2792020-11-20 15:16:09 -08003862 pm8001_dbg(pm8001_ha, MSG,
3863 "KEK MGMT RESP. Status 0x%x idx_ksop 0x%x err_qlfr 0x%x\n",
3864 status, kidx_new_curr_ksop, err_qlfr);
Sakthivel Kf5860992013-04-17 16:37:02 +05303865
3866 return 0;
3867}
3868
3869/**
3870 * mpi_dek_management_resp - SPCv specific
3871 * @pm8001_ha: our hba card information
3872 * @piomb: IO message buffer
3873 */
3874static int mpi_dek_management_resp(struct pm8001_hba_info *pm8001_ha,
3875 void *piomb)
3876{
Joe Perches1b5d2792020-11-20 15:16:09 -08003877 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303878
3879 return 0;
3880}
3881
3882/**
3883 * ssp_coalesced_comp_resp - SPCv specific
3884 * @pm8001_ha: our hba card information
3885 * @piomb: IO message buffer
3886 */
3887static int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
3888 void *piomb)
3889{
Joe Perches1b5d2792020-11-20 15:16:09 -08003890 pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303891
3892 return 0;
3893}
3894
3895/**
3896 * process_one_iomb - process one outbound Queue memory block
3897 * @pm8001_ha: our hba card information
3898 * @piomb: IO message buffer
3899 */
3900static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3901{
3902 __le32 pHeader = *(__le32 *)piomb;
3903 u32 opc = (u32)((le32_to_cpu(pHeader)) & 0xFFF);
3904
3905 switch (opc) {
3906 case OPC_OUB_ECHO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003907 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303908 break;
3909 case OPC_OUB_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003910 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303911 mpi_hw_event(pm8001_ha, piomb);
3912 break;
3913 case OPC_OUB_THERM_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003914 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_THERMAL_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303915 mpi_thermal_hw_event(pm8001_ha, piomb);
3916 break;
3917 case OPC_OUB_SSP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003918 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303919 mpi_ssp_completion(pm8001_ha, piomb);
3920 break;
3921 case OPC_OUB_SMP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003922 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303923 mpi_smp_completion(pm8001_ha, piomb);
3924 break;
3925 case OPC_OUB_LOCAL_PHY_CNTRL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003926 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303927 pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
3928 break;
3929 case OPC_OUB_DEV_REGIST:
Joe Perches1b5d2792020-11-20 15:16:09 -08003930 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303931 pm8001_mpi_reg_resp(pm8001_ha, piomb);
3932 break;
3933 case OPC_OUB_DEREG_DEV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003934 pm8001_dbg(pm8001_ha, MSG, "unregister the device\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303935 pm8001_mpi_dereg_resp(pm8001_ha, piomb);
3936 break;
3937 case OPC_OUB_GET_DEV_HANDLE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003938 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303939 break;
3940 case OPC_OUB_SATA_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003941 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303942 mpi_sata_completion(pm8001_ha, piomb);
3943 break;
3944 case OPC_OUB_SATA_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003945 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303946 mpi_sata_event(pm8001_ha, piomb);
3947 break;
3948 case OPC_OUB_SSP_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003949 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303950 mpi_ssp_event(pm8001_ha, piomb);
3951 break;
3952 case OPC_OUB_DEV_HANDLE_ARRIV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003953 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303954 /*This is for target*/
3955 break;
3956 case OPC_OUB_SSP_RECV_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003957 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303958 /*This is for target*/
3959 break;
3960 case OPC_OUB_FW_FLASH_UPDATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003961 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303962 pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
3963 break;
3964 case OPC_OUB_GPIO_RESPONSE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003965 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303966 break;
3967 case OPC_OUB_GPIO_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003968 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303969 break;
3970 case OPC_OUB_GENERAL_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003971 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303972 pm8001_mpi_general_event(pm8001_ha, piomb);
3973 break;
3974 case OPC_OUB_SSP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003975 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303976 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3977 break;
3978 case OPC_OUB_SATA_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003979 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303980 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3981 break;
3982 case OPC_OUB_SAS_DIAG_MODE_START_END:
Joe Perches1b5d2792020-11-20 15:16:09 -08003983 pm8001_dbg(pm8001_ha, MSG,
3984 "OPC_OUB_SAS_DIAG_MODE_START_END\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303985 break;
3986 case OPC_OUB_SAS_DIAG_EXECUTE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003987 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303988 break;
3989 case OPC_OUB_GET_TIME_STAMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003990 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303991 break;
3992 case OPC_OUB_SAS_HW_EVENT_ACK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003993 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303994 break;
3995 case OPC_OUB_PORT_CONTROL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003996 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05303997 break;
3998 case OPC_OUB_SMP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003999 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304000 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
4001 break;
4002 case OPC_OUB_GET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004003 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304004 pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
4005 break;
4006 case OPC_OUB_SET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004007 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304008 pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
4009 break;
4010 case OPC_OUB_DEVICE_HANDLE_REMOVAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004011 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304012 break;
4013 case OPC_OUB_SET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004014 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304015 pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
4016 break;
4017 case OPC_OUB_GET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004018 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304019 break;
4020 case OPC_OUB_SET_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08004021 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304022 break;
4023 /* spcv specifc commands */
4024 case OPC_OUB_PHY_START_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004025 pm8001_dbg(pm8001_ha, MSG,
4026 "OPC_OUB_PHY_START_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304027 mpi_phy_start_resp(pm8001_ha, piomb);
4028 break;
4029 case OPC_OUB_PHY_STOP_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004030 pm8001_dbg(pm8001_ha, MSG,
4031 "OPC_OUB_PHY_STOP_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304032 mpi_phy_stop_resp(pm8001_ha, piomb);
4033 break;
4034 case OPC_OUB_SET_CONTROLLER_CONFIG:
Joe Perches1b5d2792020-11-20 15:16:09 -08004035 pm8001_dbg(pm8001_ha, MSG,
4036 "OPC_OUB_SET_CONTROLLER_CONFIG opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304037 mpi_set_controller_config_resp(pm8001_ha, piomb);
4038 break;
4039 case OPC_OUB_GET_CONTROLLER_CONFIG:
Joe Perches1b5d2792020-11-20 15:16:09 -08004040 pm8001_dbg(pm8001_ha, MSG,
4041 "OPC_OUB_GET_CONTROLLER_CONFIG opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304042 mpi_get_controller_config_resp(pm8001_ha, piomb);
4043 break;
4044 case OPC_OUB_GET_PHY_PROFILE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004045 pm8001_dbg(pm8001_ha, MSG,
4046 "OPC_OUB_GET_PHY_PROFILE opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304047 mpi_get_phy_profile_resp(pm8001_ha, piomb);
4048 break;
4049 case OPC_OUB_FLASH_OP_EXT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004050 pm8001_dbg(pm8001_ha, MSG,
4051 "OPC_OUB_FLASH_OP_EXT opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304052 mpi_flash_op_ext_resp(pm8001_ha, piomb);
4053 break;
4054 case OPC_OUB_SET_PHY_PROFILE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004055 pm8001_dbg(pm8001_ha, MSG,
4056 "OPC_OUB_SET_PHY_PROFILE opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304057 mpi_set_phy_profile_resp(pm8001_ha, piomb);
4058 break;
4059 case OPC_OUB_KEK_MANAGEMENT_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004060 pm8001_dbg(pm8001_ha, MSG,
4061 "OPC_OUB_KEK_MANAGEMENT_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304062 mpi_kek_management_resp(pm8001_ha, piomb);
4063 break;
4064 case OPC_OUB_DEK_MANAGEMENT_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004065 pm8001_dbg(pm8001_ha, MSG,
4066 "OPC_OUB_DEK_MANAGEMENT_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304067 mpi_dek_management_resp(pm8001_ha, piomb);
4068 break;
4069 case OPC_OUB_SSP_COALESCED_COMP_RESP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004070 pm8001_dbg(pm8001_ha, MSG,
4071 "OPC_OUB_SSP_COALESCED_COMP_RESP opcode:%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304072 ssp_coalesced_comp_resp(pm8001_ha, piomb);
4073 break;
4074 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08004075 pm8001_dbg(pm8001_ha, DEVIO,
4076 "Unknown outbound Queue IOMB OPC = 0x%x\n", opc);
Sakthivel Kf5860992013-04-17 16:37:02 +05304077 break;
4078 }
4079}
4080
Deepak Ukey72349b62018-09-11 14:18:04 +05304081static void print_scratchpad_registers(struct pm8001_hba_info *pm8001_ha)
4082{
Joe Perches1b5d2792020-11-20 15:16:09 -08004083 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_0: 0x%x\n",
4084 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0));
4085 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_1:0x%x\n",
4086 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1));
4087 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_2: 0x%x\n",
4088 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2));
4089 pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_3: 0x%x\n",
4090 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3));
4091 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_0: 0x%x\n",
4092 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0));
4093 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_1: 0x%x\n",
4094 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_1));
4095 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_2: 0x%x\n",
4096 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_2));
4097 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_3: 0x%x\n",
4098 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_3));
4099 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_4: 0x%x\n",
4100 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_4));
4101 pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_5: 0x%x\n",
4102 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_5));
4103 pm8001_dbg(pm8001_ha, FAIL, "MSGU_RSVD_SCRATCH_PAD_0: 0x%x\n",
4104 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_6));
4105 pm8001_dbg(pm8001_ha, FAIL, "MSGU_RSVD_SCRATCH_PAD_1: 0x%x\n",
4106 pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_7));
Deepak Ukey72349b62018-09-11 14:18:04 +05304107}
4108
Sakthivel Kf5860992013-04-17 16:37:02 +05304109static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
4110{
4111 struct outbound_queue_table *circularQ;
4112 void *pMsg1 = NULL;
Kees Cook3f649ab2020-06-03 13:09:38 -07004113 u8 bc;
Sakthivel Kf5860992013-04-17 16:37:02 +05304114 u32 ret = MPI_IO_STATUS_FAIL;
4115 unsigned long flags;
Deepak Ukey72349b62018-09-11 14:18:04 +05304116 u32 regval;
Sakthivel Kf5860992013-04-17 16:37:02 +05304117
Viswas G05c6c022020-10-05 20:20:08 +05304118 if (vec == (pm8001_ha->max_q_num - 1)) {
Deepak Ukey72349b62018-09-11 14:18:04 +05304119 regval = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
4120 if ((regval & SCRATCH_PAD_MIPSALL_READY) !=
4121 SCRATCH_PAD_MIPSALL_READY) {
4122 pm8001_ha->controller_fatal_error = true;
Joe Perches1b5d2792020-11-20 15:16:09 -08004123 pm8001_dbg(pm8001_ha, FAIL,
4124 "Firmware Fatal error! Regval:0x%x\n",
4125 regval);
Deepak Ukey72349b62018-09-11 14:18:04 +05304126 print_scratchpad_registers(pm8001_ha);
4127 return ret;
4128 }
4129 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304130 spin_lock_irqsave(&pm8001_ha->lock, flags);
4131 circularQ = &pm8001_ha->outbnd_q_tbl[vec];
4132 do {
Deepak Ukey72349b62018-09-11 14:18:04 +05304133 /* spurious interrupt during setup if kexec-ing and
4134 * driver doing a doorbell access w/ the pre-kexec oq
4135 * interrupt setup.
4136 */
4137 if (!circularQ->pi_virt)
4138 break;
Sakthivel Kf5860992013-04-17 16:37:02 +05304139 ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
4140 if (MPI_IO_STATUS_SUCCESS == ret) {
4141 /* process the outbound message */
4142 process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
4143 /* free the message from the outbound circular buffer */
4144 pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4145 circularQ, bc);
4146 }
4147 if (MPI_IO_STATUS_BUSY == ret) {
4148 /* Update the producer index from SPC */
4149 circularQ->producer_index =
4150 cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4151 if (le32_to_cpu(circularQ->producer_index) ==
4152 circularQ->consumer_idx)
4153 /* OQ is empty */
4154 break;
4155 }
4156 } while (1);
4157 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
4158 return ret;
4159}
4160
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004161/* DMA_... to our direction translation. */
Sakthivel Kf5860992013-04-17 16:37:02 +05304162static const u8 data_dir_flags[] = {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004163 [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
4164 [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
4165 [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */
4166 [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */
Sakthivel Kf5860992013-04-17 16:37:02 +05304167};
4168
4169static void build_smp_cmd(u32 deviceID, __le32 hTag,
4170 struct smp_req *psmp_cmd, int mode, int length)
4171{
4172 psmp_cmd->tag = hTag;
4173 psmp_cmd->device_id = cpu_to_le32(deviceID);
4174 if (mode == SMP_DIRECT) {
4175 length = length - 4; /* subtract crc */
4176 psmp_cmd->len_ip_ir = cpu_to_le32(length << 16);
4177 } else {
4178 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4179 }
4180}
4181
4182/**
4183 * pm8001_chip_smp_req - send a SMP task to FW
4184 * @pm8001_ha: our hba card information.
4185 * @ccb: the ccb information this request used.
4186 */
4187static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4188 struct pm8001_ccb_info *ccb)
4189{
4190 int elem, rc;
4191 struct sas_task *task = ccb->task;
4192 struct domain_device *dev = task->dev;
4193 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4194 struct scatterlist *sg_req, *sg_resp;
4195 u32 req_len, resp_len;
4196 struct smp_req smp_cmd;
4197 u32 opc;
4198 struct inbound_queue_table *circularQ;
4199 char *preq_dma_addr = NULL;
4200 __le64 tmp_addr;
4201 u32 i, length;
4202
4203 memset(&smp_cmd, 0, sizeof(smp_cmd));
4204 /*
4205 * DMA-map SMP request, response buffers
4206 */
4207 sg_req = &task->smp_task.smp_req;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004208 elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304209 if (!elem)
4210 return -ENOMEM;
4211 req_len = sg_dma_len(sg_req);
4212
4213 sg_resp = &task->smp_task.smp_resp;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004214 elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304215 if (!elem) {
4216 rc = -ENOMEM;
4217 goto err_out;
4218 }
4219 resp_len = sg_dma_len(sg_resp);
4220 /* must be in dwords */
4221 if ((req_len & 0x3) || (resp_len & 0x3)) {
4222 rc = -EINVAL;
4223 goto err_out_2;
4224 }
4225
4226 opc = OPC_INB_SMP_REQUEST;
4227 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4228 smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4229
4230 length = sg_req->length;
Joe Perches1b5d2792020-11-20 15:16:09 -08004231 pm8001_dbg(pm8001_ha, IO, "SMP Frame Length %d\n", sg_req->length);
Sakthivel Kf5860992013-04-17 16:37:02 +05304232 if (!(length - 8))
4233 pm8001_ha->smp_exp_mode = SMP_DIRECT;
4234 else
4235 pm8001_ha->smp_exp_mode = SMP_INDIRECT;
4236
Sakthivel Kf5860992013-04-17 16:37:02 +05304237
4238 tmp_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4239 preq_dma_addr = (char *)phys_to_virt(tmp_addr);
4240
4241 /* INDIRECT MODE command settings. Use DMA */
4242 if (pm8001_ha->smp_exp_mode == SMP_INDIRECT) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004243 pm8001_dbg(pm8001_ha, IO, "SMP REQUEST INDIRECT MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304244 /* for SPCv indirect mode. Place the top 4 bytes of
4245 * SMP Request header here. */
4246 for (i = 0; i < 4; i++)
4247 smp_cmd.smp_req16[i] = *(preq_dma_addr + i);
4248 /* exclude top 4 bytes for SMP req header */
4249 smp_cmd.long_smp_req.long_req_addr =
4250 cpu_to_le64((u64)sg_dma_address
Anand Kumar Santhanamcb993e52013-09-17 14:37:14 +05304251 (&task->smp_task.smp_req) + 4);
Sakthivel Kf5860992013-04-17 16:37:02 +05304252 /* exclude 4 bytes for SMP req header and CRC */
4253 smp_cmd.long_smp_req.long_req_size =
4254 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-8);
4255 smp_cmd.long_smp_req.long_resp_addr =
4256 cpu_to_le64((u64)sg_dma_address
4257 (&task->smp_task.smp_resp));
4258 smp_cmd.long_smp_req.long_resp_size =
4259 cpu_to_le32((u32)sg_dma_len
4260 (&task->smp_task.smp_resp)-4);
4261 } else { /* DIRECT MODE */
4262 smp_cmd.long_smp_req.long_req_addr =
4263 cpu_to_le64((u64)sg_dma_address
4264 (&task->smp_task.smp_req));
4265 smp_cmd.long_smp_req.long_req_size =
4266 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4267 smp_cmd.long_smp_req.long_resp_addr =
4268 cpu_to_le64((u64)sg_dma_address
4269 (&task->smp_task.smp_resp));
4270 smp_cmd.long_smp_req.long_resp_size =
4271 cpu_to_le32
4272 ((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4273 }
4274 if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004275 pm8001_dbg(pm8001_ha, IO, "SMP REQUEST DIRECT MODE\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304276 for (i = 0; i < length; i++)
4277 if (i < 16) {
4278 smp_cmd.smp_req16[i] = *(preq_dma_addr+i);
Joe Perches1b5d2792020-11-20 15:16:09 -08004279 pm8001_dbg(pm8001_ha, IO,
4280 "Byte[%d]:%x (DMA data:%x)\n",
4281 i, smp_cmd.smp_req16[i],
4282 *(preq_dma_addr));
Sakthivel Kf5860992013-04-17 16:37:02 +05304283 } else {
4284 smp_cmd.smp_req[i] = *(preq_dma_addr+i);
Joe Perches1b5d2792020-11-20 15:16:09 -08004285 pm8001_dbg(pm8001_ha, IO,
4286 "Byte[%d]:%x (DMA data:%x)\n",
4287 i, smp_cmd.smp_req[i],
4288 *(preq_dma_addr));
Sakthivel Kf5860992013-04-17 16:37:02 +05304289 }
4290 }
4291
4292 build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag,
4293 &smp_cmd, pm8001_ha->smp_exp_mode, length);
peter chang91a43fa2019-11-14 15:39:05 +05304294 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &smp_cmd,
4295 sizeof(smp_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304296 if (rc)
4297 goto err_out_2;
Sakthivel Kf5860992013-04-17 16:37:02 +05304298 return 0;
4299
4300err_out_2:
4301 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004302 DMA_FROM_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304303err_out:
4304 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004305 DMA_TO_DEVICE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304306 return rc;
4307}
4308
4309static int check_enc_sas_cmd(struct sas_task *task)
4310{
James Bottomleye73823f2013-05-07 15:38:18 -07004311 u8 cmd = task->ssp_task.cmd->cmnd[0];
4312
4313 if (cmd == READ_10 || cmd == WRITE_10 || cmd == WRITE_VERIFY)
Sakthivel Kf5860992013-04-17 16:37:02 +05304314 return 1;
4315 else
4316 return 0;
4317}
4318
4319static int check_enc_sat_cmd(struct sas_task *task)
4320{
4321 int ret = 0;
4322 switch (task->ata_task.fis.command) {
4323 case ATA_CMD_FPDMA_READ:
4324 case ATA_CMD_READ_EXT:
4325 case ATA_CMD_READ:
4326 case ATA_CMD_FPDMA_WRITE:
4327 case ATA_CMD_WRITE_EXT:
4328 case ATA_CMD_WRITE:
4329 case ATA_CMD_PIO_READ:
4330 case ATA_CMD_PIO_READ_EXT:
4331 case ATA_CMD_PIO_WRITE:
4332 case ATA_CMD_PIO_WRITE_EXT:
4333 ret = 1;
4334 break;
4335 default:
4336 ret = 0;
4337 break;
4338 }
4339 return ret;
4340}
4341
4342/**
4343 * pm80xx_chip_ssp_io_req - send a SSP task to FW
4344 * @pm8001_ha: our hba card information.
4345 * @ccb: the ccb information this request used.
4346 */
4347static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4348 struct pm8001_ccb_info *ccb)
4349{
4350 struct sas_task *task = ccb->task;
4351 struct domain_device *dev = task->dev;
4352 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4353 struct ssp_ini_io_start_req ssp_cmd;
4354 u32 tag = ccb->ccb_tag;
4355 int ret;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304356 u64 phys_addr, start_addr, end_addr;
4357 u32 end_addr_high, end_addr_low;
Sakthivel Kf5860992013-04-17 16:37:02 +05304358 struct inbound_queue_table *circularQ;
Viswas G05c6c022020-10-05 20:20:08 +05304359 u32 q_index, cpu_id;
Sakthivel Kf5860992013-04-17 16:37:02 +05304360 u32 opc = OPC_INB_SSPINIIOSTART;
4361 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4362 memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
4363 /* data address domain added for spcv; set to 0 by host,
4364 * used internally by controller
4365 * 0 for SAS 1.1 and SAS 2.0 compatible TLR
4366 */
4367 ssp_cmd.dad_dir_m_tlr =
4368 cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);
4369 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4370 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4371 ssp_cmd.tag = cpu_to_le32(tag);
4372 if (task->ssp_task.enable_first_burst)
4373 ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
4374 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
4375 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
James Bottomleye73823f2013-05-07 15:38:18 -07004376 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4377 task->ssp_task.cmd->cmd_len);
Viswas G05c6c022020-10-05 20:20:08 +05304378 cpu_id = smp_processor_id();
4379 q_index = (u32) (cpu_id) % (pm8001_ha->max_q_num);
Anand Kumar Santhanamf9cd6cb2013-09-18 11:12:59 +05304380 circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
Sakthivel Kf5860992013-04-17 16:37:02 +05304381
4382 /* Check if encryption is set */
4383 if (pm8001_ha->chip->encrypt &&
4384 !(pm8001_ha->encrypt_info.status) && check_enc_sas_cmd(task)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004385 pm8001_dbg(pm8001_ha, IO,
4386 "Encryption enabled.Sending Encrypt SAS command 0x%x\n",
4387 task->ssp_task.cmd->cmnd[0]);
Sakthivel Kf5860992013-04-17 16:37:02 +05304388 opc = OPC_INB_SSP_INI_DIF_ENC_IO;
4389 /* enable encryption. 0 for SAS 1.1 and SAS 2.0 compatible TLR*/
4390 ssp_cmd.dad_dir_m_tlr = cpu_to_le32
4391 ((data_dir_flags[task->data_dir] << 8) | 0x20 | 0x0);
4392
4393 /* fill in PRD (scatter/gather) table, if any */
4394 if (task->num_scatter > 1) {
4395 pm8001_chip_make_sg(task->scatter,
4396 ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304397 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304398 ssp_cmd.enc_addr_low =
4399 cpu_to_le32(lower_32_bits(phys_addr));
4400 ssp_cmd.enc_addr_high =
4401 cpu_to_le32(upper_32_bits(phys_addr));
4402 ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
4403 } else if (task->num_scatter == 1) {
4404 u64 dma_addr = sg_dma_address(task->scatter);
4405 ssp_cmd.enc_addr_low =
4406 cpu_to_le32(lower_32_bits(dma_addr));
4407 ssp_cmd.enc_addr_high =
4408 cpu_to_le32(upper_32_bits(dma_addr));
4409 ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4410 ssp_cmd.enc_esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304411 /* Check 4G Boundary */
4412 start_addr = cpu_to_le64(dma_addr);
4413 end_addr = (start_addr + ssp_cmd.enc_len) - 1;
4414 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4415 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4416 if (end_addr_high != ssp_cmd.enc_addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004417 pm8001_dbg(pm8001_ha, FAIL,
4418 "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",
4419 start_addr, ssp_cmd.enc_len,
4420 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304421 pm8001_chip_make_sg(task->scatter, 1,
4422 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304423 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304424 ssp_cmd.enc_addr_low =
4425 cpu_to_le32(lower_32_bits(phys_addr));
4426 ssp_cmd.enc_addr_high =
4427 cpu_to_le32(upper_32_bits(phys_addr));
4428 ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
4429 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304430 } else if (task->num_scatter == 0) {
4431 ssp_cmd.enc_addr_low = 0;
4432 ssp_cmd.enc_addr_high = 0;
4433 ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4434 ssp_cmd.enc_esgl = 0;
4435 }
4436 /* XTS mode. All other fields are 0 */
4437 ssp_cmd.key_cmode = 0x6 << 4;
4438 /* set tweak values. Should be the start lba */
James Bottomleye73823f2013-05-07 15:38:18 -07004439 ssp_cmd.twk_val0 = cpu_to_le32((task->ssp_task.cmd->cmnd[2] << 24) |
4440 (task->ssp_task.cmd->cmnd[3] << 16) |
4441 (task->ssp_task.cmd->cmnd[4] << 8) |
4442 (task->ssp_task.cmd->cmnd[5]));
Sakthivel Kf5860992013-04-17 16:37:02 +05304443 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08004444 pm8001_dbg(pm8001_ha, IO,
4445 "Sending Normal SAS command 0x%x inb q %x\n",
4446 task->ssp_task.cmd->cmnd[0], q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304447 /* fill in PRD (scatter/gather) table, if any */
4448 if (task->num_scatter > 1) {
4449 pm8001_chip_make_sg(task->scatter, ccb->n_elem,
4450 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304451 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304452 ssp_cmd.addr_low =
4453 cpu_to_le32(lower_32_bits(phys_addr));
4454 ssp_cmd.addr_high =
4455 cpu_to_le32(upper_32_bits(phys_addr));
4456 ssp_cmd.esgl = cpu_to_le32(1<<31);
4457 } else if (task->num_scatter == 1) {
4458 u64 dma_addr = sg_dma_address(task->scatter);
4459 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4460 ssp_cmd.addr_high =
4461 cpu_to_le32(upper_32_bits(dma_addr));
4462 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4463 ssp_cmd.esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304464 /* Check 4G Boundary */
4465 start_addr = cpu_to_le64(dma_addr);
4466 end_addr = (start_addr + ssp_cmd.len) - 1;
4467 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4468 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4469 if (end_addr_high != ssp_cmd.addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004470 pm8001_dbg(pm8001_ha, FAIL,
4471 "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",
4472 start_addr, ssp_cmd.len,
4473 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304474 pm8001_chip_make_sg(task->scatter, 1,
4475 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304476 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304477 ssp_cmd.addr_low =
4478 cpu_to_le32(lower_32_bits(phys_addr));
4479 ssp_cmd.addr_high =
4480 cpu_to_le32(upper_32_bits(phys_addr));
4481 ssp_cmd.esgl = cpu_to_le32(1<<31);
4482 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304483 } else if (task->num_scatter == 0) {
4484 ssp_cmd.addr_low = 0;
4485 ssp_cmd.addr_high = 0;
4486 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4487 ssp_cmd.esgl = 0;
4488 }
4489 }
Anand Kumar Santhanamf9cd6cb2013-09-18 11:12:59 +05304490 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304491 &ssp_cmd, sizeof(ssp_cmd), q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304492 return ret;
4493}
4494
4495static int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4496 struct pm8001_ccb_info *ccb)
4497{
4498 struct sas_task *task = ccb->task;
4499 struct domain_device *dev = task->dev;
4500 struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4501 u32 tag = ccb->ccb_tag;
4502 int ret;
Viswas G05c6c022020-10-05 20:20:08 +05304503 u32 q_index, cpu_id;
Sakthivel Kf5860992013-04-17 16:37:02 +05304504 struct sata_start_req sata_cmd;
4505 u32 hdr_tag, ncg_tag = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304506 u64 phys_addr, start_addr, end_addr;
4507 u32 end_addr_high, end_addr_low;
Sakthivel Kf5860992013-04-17 16:37:02 +05304508 u32 ATAP = 0x0;
4509 u32 dir;
4510 struct inbound_queue_table *circularQ;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304511 unsigned long flags;
Sakthivel Kf5860992013-04-17 16:37:02 +05304512 u32 opc = OPC_INB_SATA_HOST_OPSTART;
4513 memset(&sata_cmd, 0, sizeof(sata_cmd));
Viswas G05c6c022020-10-05 20:20:08 +05304514 cpu_id = smp_processor_id();
4515 q_index = (u32) (cpu_id) % (pm8001_ha->max_q_num);
Anand Kumar Santhanamf9cd6cb2013-09-18 11:12:59 +05304516 circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
Sakthivel Kf5860992013-04-17 16:37:02 +05304517
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004518 if (task->data_dir == DMA_NONE) {
Sakthivel Kf5860992013-04-17 16:37:02 +05304519 ATAP = 0x04; /* no data*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004520 pm8001_dbg(pm8001_ha, IO, "no data\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304521 } else if (likely(!task->ata_task.device_control_reg_update)) {
4522 if (task->ata_task.dma_xfer) {
4523 ATAP = 0x06; /* DMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004524 pm8001_dbg(pm8001_ha, IO, "DMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304525 } else {
4526 ATAP = 0x05; /* PIO*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004527 pm8001_dbg(pm8001_ha, IO, "PIO\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304528 }
4529 if (task->ata_task.use_ncq &&
Hannes Reinecke1cbd7722014-11-05 13:08:20 +01004530 dev->sata_dev.class != ATA_DEV_ATAPI) {
Sakthivel Kf5860992013-04-17 16:37:02 +05304531 ATAP = 0x07; /* FPDMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004532 pm8001_dbg(pm8001_ha, IO, "FPDMA\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05304533 }
4534 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304535 if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4536 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
Sakthivel Kf5860992013-04-17 16:37:02 +05304537 ncg_tag = hdr_tag;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304538 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304539 dir = data_dir_flags[task->data_dir] << 8;
4540 sata_cmd.tag = cpu_to_le32(tag);
4541 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4542 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4543
4544 sata_cmd.sata_fis = task->ata_task.fis;
4545 if (likely(!task->ata_task.device_control_reg_update))
4546 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4547 sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4548
4549 /* Check if encryption is set */
4550 if (pm8001_ha->chip->encrypt &&
4551 !(pm8001_ha->encrypt_info.status) && check_enc_sat_cmd(task)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004552 pm8001_dbg(pm8001_ha, IO,
4553 "Encryption enabled.Sending Encrypt SATA cmd 0x%x\n",
4554 sata_cmd.sata_fis.command);
Sakthivel Kf5860992013-04-17 16:37:02 +05304555 opc = OPC_INB_SATA_DIF_ENC_IO;
4556
4557 /* set encryption bit */
4558 sata_cmd.ncqtag_atap_dir_m_dad =
4559 cpu_to_le32(((ncg_tag & 0xff)<<16)|
4560 ((ATAP & 0x3f) << 10) | 0x20 | dir);
4561 /* dad (bit 0-1) is 0 */
4562 /* fill in PRD (scatter/gather) table, if any */
4563 if (task->num_scatter > 1) {
4564 pm8001_chip_make_sg(task->scatter,
4565 ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304566 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304567 sata_cmd.enc_addr_low = lower_32_bits(phys_addr);
4568 sata_cmd.enc_addr_high = upper_32_bits(phys_addr);
4569 sata_cmd.enc_esgl = cpu_to_le32(1 << 31);
4570 } else if (task->num_scatter == 1) {
4571 u64 dma_addr = sg_dma_address(task->scatter);
4572 sata_cmd.enc_addr_low = lower_32_bits(dma_addr);
4573 sata_cmd.enc_addr_high = upper_32_bits(dma_addr);
4574 sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4575 sata_cmd.enc_esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304576 /* Check 4G Boundary */
4577 start_addr = cpu_to_le64(dma_addr);
4578 end_addr = (start_addr + sata_cmd.enc_len) - 1;
4579 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4580 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4581 if (end_addr_high != sata_cmd.enc_addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004582 pm8001_dbg(pm8001_ha, FAIL,
4583 "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",
4584 start_addr, sata_cmd.enc_len,
4585 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304586 pm8001_chip_make_sg(task->scatter, 1,
4587 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304588 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304589 sata_cmd.enc_addr_low =
4590 lower_32_bits(phys_addr);
4591 sata_cmd.enc_addr_high =
4592 upper_32_bits(phys_addr);
4593 sata_cmd.enc_esgl =
4594 cpu_to_le32(1 << 31);
4595 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304596 } else if (task->num_scatter == 0) {
4597 sata_cmd.enc_addr_low = 0;
4598 sata_cmd.enc_addr_high = 0;
4599 sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4600 sata_cmd.enc_esgl = 0;
4601 }
4602 /* XTS mode. All other fields are 0 */
4603 sata_cmd.key_index_mode = 0x6 << 4;
4604 /* set tweak values. Should be the start lba */
4605 sata_cmd.twk_val0 =
4606 cpu_to_le32((sata_cmd.sata_fis.lbal_exp << 24) |
4607 (sata_cmd.sata_fis.lbah << 16) |
4608 (sata_cmd.sata_fis.lbam << 8) |
4609 (sata_cmd.sata_fis.lbal));
4610 sata_cmd.twk_val1 =
4611 cpu_to_le32((sata_cmd.sata_fis.lbah_exp << 8) |
4612 (sata_cmd.sata_fis.lbam_exp));
4613 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08004614 pm8001_dbg(pm8001_ha, IO,
4615 "Sending Normal SATA command 0x%x inb %x\n",
4616 sata_cmd.sata_fis.command, q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304617 /* dad (bit 0-1) is 0 */
4618 sata_cmd.ncqtag_atap_dir_m_dad =
4619 cpu_to_le32(((ncg_tag & 0xff)<<16) |
4620 ((ATAP & 0x3f) << 10) | dir);
4621
4622 /* fill in PRD (scatter/gather) table, if any */
4623 if (task->num_scatter > 1) {
4624 pm8001_chip_make_sg(task->scatter,
4625 ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304626 phys_addr = ccb->ccb_dma_handle;
Sakthivel Kf5860992013-04-17 16:37:02 +05304627 sata_cmd.addr_low = lower_32_bits(phys_addr);
4628 sata_cmd.addr_high = upper_32_bits(phys_addr);
4629 sata_cmd.esgl = cpu_to_le32(1 << 31);
4630 } else if (task->num_scatter == 1) {
4631 u64 dma_addr = sg_dma_address(task->scatter);
4632 sata_cmd.addr_low = lower_32_bits(dma_addr);
4633 sata_cmd.addr_high = upper_32_bits(dma_addr);
4634 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4635 sata_cmd.esgl = 0;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304636 /* Check 4G Boundary */
4637 start_addr = cpu_to_le64(dma_addr);
4638 end_addr = (start_addr + sata_cmd.len) - 1;
4639 end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
4640 end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
4641 if (end_addr_high != sata_cmd.addr_high) {
Joe Perches1b5d2792020-11-20 15:16:09 -08004642 pm8001_dbg(pm8001_ha, FAIL,
4643 "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",
4644 start_addr, sata_cmd.len,
4645 end_addr_high, end_addr_low);
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304646 pm8001_chip_make_sg(task->scatter, 1,
4647 ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304648 phys_addr = ccb->ccb_dma_handle;
Anand Kumar Santhanam0ecdf002013-09-18 11:14:54 +05304649 sata_cmd.addr_low =
4650 lower_32_bits(phys_addr);
4651 sata_cmd.addr_high =
4652 upper_32_bits(phys_addr);
4653 sata_cmd.esgl = cpu_to_le32(1 << 31);
4654 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304655 } else if (task->num_scatter == 0) {
4656 sata_cmd.addr_low = 0;
4657 sata_cmd.addr_high = 0;
4658 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4659 sata_cmd.esgl = 0;
4660 }
Colin Ian King9e2a07e2019-03-17 18:15:32 +00004661 /* scsi cdb */
4662 sata_cmd.atapi_scsi_cdb[0] =
4663 cpu_to_le32(((task->ata_task.atapi_packet[0]) |
4664 (task->ata_task.atapi_packet[1] << 8) |
4665 (task->ata_task.atapi_packet[2] << 16) |
4666 (task->ata_task.atapi_packet[3] << 24)));
4667 sata_cmd.atapi_scsi_cdb[1] =
4668 cpu_to_le32(((task->ata_task.atapi_packet[4]) |
4669 (task->ata_task.atapi_packet[5] << 8) |
4670 (task->ata_task.atapi_packet[6] << 16) |
4671 (task->ata_task.atapi_packet[7] << 24)));
4672 sata_cmd.atapi_scsi_cdb[2] =
4673 cpu_to_le32(((task->ata_task.atapi_packet[8]) |
4674 (task->ata_task.atapi_packet[9] << 8) |
4675 (task->ata_task.atapi_packet[10] << 16) |
4676 (task->ata_task.atapi_packet[11] << 24)));
4677 sata_cmd.atapi_scsi_cdb[3] =
4678 cpu_to_le32(((task->ata_task.atapi_packet[12]) |
4679 (task->ata_task.atapi_packet[13] << 8) |
4680 (task->ata_task.atapi_packet[14] << 16) |
4681 (task->ata_task.atapi_packet[15] << 24)));
Sakthivel Kf5860992013-04-17 16:37:02 +05304682 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304683
4684 /* Check for read log for failed drive and return */
4685 if (sata_cmd.sata_fis.command == 0x2f) {
4686 if (pm8001_ha_dev && ((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
4687 (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4688 (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4689 struct task_status_struct *ts;
4690
4691 pm8001_ha_dev->id &= 0xDFFFFFFF;
4692 ts = &task->task_status;
4693
4694 spin_lock_irqsave(&task->task_state_lock, flags);
4695 ts->resp = SAS_TASK_COMPLETE;
4696 ts->stat = SAM_STAT_GOOD;
4697 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4698 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4699 task->task_state_flags |= SAS_TASK_STATE_DONE;
4700 if (unlikely((task->task_state_flags &
4701 SAS_TASK_STATE_ABORTED))) {
4702 spin_unlock_irqrestore(&task->task_state_lock,
4703 flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08004704 pm8001_dbg(pm8001_ha, FAIL,
4705 "task 0x%p resp 0x%x stat 0x%x but aborted by upper layer\n",
4706 task, ts->resp,
4707 ts->stat);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304708 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
4709 return 0;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304710 } else {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304711 spin_unlock_irqrestore(&task->task_state_lock,
4712 flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304713 pm8001_ccb_task_free_done(pm8001_ha, task,
4714 ccb, tag);
Viswas G4a2efd42020-11-02 22:25:26 +05304715 atomic_dec(&pm8001_ha_dev->running_req);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304716 return 0;
4717 }
4718 }
4719 }
Sakthivel Kf5860992013-04-17 16:37:02 +05304720 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304721 &sata_cmd, sizeof(sata_cmd), q_index);
Sakthivel Kf5860992013-04-17 16:37:02 +05304722 return ret;
4723}
4724
4725/**
4726 * pm80xx_chip_phy_start_req - start phy via PHY_START COMMAND
4727 * @pm8001_ha: our hba card information.
Sakthivel Kf5860992013-04-17 16:37:02 +05304728 * @phy_id: the phy id which we wanted to start up.
4729 */
4730static int
4731pm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4732{
4733 struct phy_start_req payload;
4734 struct inbound_queue_table *circularQ;
4735 int ret;
4736 u32 tag = 0x01;
4737 u32 opcode = OPC_INB_PHYSTART;
4738 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4739 memset(&payload, 0, sizeof(payload));
4740 payload.tag = cpu_to_le32(tag);
4741
Joe Perches1b5d2792020-11-20 15:16:09 -08004742 pm8001_dbg(pm8001_ha, INIT, "PHY START REQ for phy_id %d\n", phy_id);
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05304743
peter chang3e253d92019-11-14 15:39:07 +05304744 payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4745 LINKMODE_AUTO | pm8001_ha->link_rate | phy_id);
Sakthivel Kf5860992013-04-17 16:37:02 +05304746 /* SSC Disable and SAS Analog ST configuration */
4747 /**
4748 payload.ase_sh_lm_slr_phyid =
4749 cpu_to_le32(SSC_DISABLE_30 | SAS_ASE | SPINHOLD_DISABLE |
4750 LINKMODE_AUTO | LINKRATE_15 | LINKRATE_30 | LINKRATE_60 |
4751 phy_id);
4752 Have to add "SAS PHY Analog Setup SPASTI 1 Byte" Based on need
4753 **/
4754
James Bottomleyaa9f8322013-05-07 14:44:06 -07004755 payload.sas_identify.dev_type = SAS_END_DEVICE;
Sakthivel Kf5860992013-04-17 16:37:02 +05304756 payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4757 memcpy(payload.sas_identify.sas_addr,
peter chang3e253d92019-11-14 15:39:07 +05304758 &pm8001_ha->sas_addr, SAS_ADDR_SIZE);
Sakthivel Kf5860992013-04-17 16:37:02 +05304759 payload.sas_identify.phy_id = phy_id;
peter chang91a43fa2019-11-14 15:39:05 +05304760 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4761 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05304762 return ret;
4763}
4764
4765/**
4766 * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4767 * @pm8001_ha: our hba card information.
Sakthivel Kf5860992013-04-17 16:37:02 +05304768 * @phy_id: the phy id which we wanted to start up.
4769 */
4770static int pm80xx_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4771 u8 phy_id)
4772{
4773 struct phy_stop_req payload;
4774 struct inbound_queue_table *circularQ;
4775 int ret;
4776 u32 tag = 0x01;
4777 u32 opcode = OPC_INB_PHYSTOP;
4778 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4779 memset(&payload, 0, sizeof(payload));
4780 payload.tag = cpu_to_le32(tag);
4781 payload.phy_id = cpu_to_le32(phy_id);
peter chang91a43fa2019-11-14 15:39:05 +05304782 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4783 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05304784 return ret;
4785}
4786
Lee Jones6ad4a512020-07-21 17:41:25 +01004787/*
Sakthivel Kf5860992013-04-17 16:37:02 +05304788 * see comments on pm8001_mpi_reg_resp.
4789 */
4790static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4791 struct pm8001_device *pm8001_dev, u32 flag)
4792{
4793 struct reg_dev_req payload;
4794 u32 opc;
4795 u32 stp_sspsmp_sata = 0x4;
4796 struct inbound_queue_table *circularQ;
4797 u32 linkrate, phy_id;
4798 int rc, tag = 0xdeadbeef;
4799 struct pm8001_ccb_info *ccb;
4800 u8 retryFlag = 0x1;
4801 u16 firstBurstSize = 0;
4802 u16 ITNT = 2000;
4803 struct domain_device *dev = pm8001_dev->sas_device;
4804 struct domain_device *parent_dev = dev->parent;
4805 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4806
4807 memset(&payload, 0, sizeof(payload));
4808 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4809 if (rc)
4810 return rc;
4811 ccb = &pm8001_ha->ccb_info[tag];
4812 ccb->device = pm8001_dev;
4813 ccb->ccb_tag = tag;
4814 payload.tag = cpu_to_le32(tag);
4815
4816 if (flag == 1) {
4817 stp_sspsmp_sata = 0x02; /*direct attached sata */
4818 } else {
James Bottomleyaa9f8322013-05-07 14:44:06 -07004819 if (pm8001_dev->dev_type == SAS_SATA_DEV)
Sakthivel Kf5860992013-04-17 16:37:02 +05304820 stp_sspsmp_sata = 0x00; /* stp*/
James Bottomleyaa9f8322013-05-07 14:44:06 -07004821 else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
4822 pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
4823 pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
Sakthivel Kf5860992013-04-17 16:37:02 +05304824 stp_sspsmp_sata = 0x01; /*ssp or smp*/
4825 }
John Garry924a3542019-06-10 20:41:41 +08004826 if (parent_dev && dev_is_expander(parent_dev->dev_type))
Sakthivel Kf5860992013-04-17 16:37:02 +05304827 phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4828 else
4829 phy_id = pm8001_dev->attached_phy;
4830
4831 opc = OPC_INB_REG_DEV;
4832
4833 linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4834 pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4835
4836 payload.phyid_portid =
4837 cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0xFF) |
4838 ((phy_id & 0xFF) << 8));
4839
4840 payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 0x01) |
4841 ((linkrate & 0x0F) << 24) |
4842 ((stp_sspsmp_sata & 0x03) << 28));
4843 payload.firstburstsize_ITNexustimeout =
4844 cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
4845
4846 memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
4847 SAS_ADDR_SIZE);
4848
peter chang91a43fa2019-11-14 15:39:05 +05304849 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4850 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304851 if (rc)
4852 pm8001_tag_free(pm8001_ha, tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05304853
4854 return rc;
4855}
4856
4857/**
4858 * pm80xx_chip_phy_ctl_req - support the local phy operation
4859 * @pm8001_ha: our hba card information.
Lee Jones6ad4a512020-07-21 17:41:25 +01004860 * @phyId: the phy id which we wanted to operate
4861 * @phy_op: phy operation to request
Sakthivel Kf5860992013-04-17 16:37:02 +05304862 */
4863static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4864 u32 phyId, u32 phy_op)
4865{
Viswas G25c6edb2017-10-18 11:39:10 +05304866 u32 tag;
4867 int rc;
Sakthivel Kf5860992013-04-17 16:37:02 +05304868 struct local_phy_ctl_req payload;
4869 struct inbound_queue_table *circularQ;
Sakthivel Kf5860992013-04-17 16:37:02 +05304870 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
4871 memset(&payload, 0, sizeof(payload));
Viswas G25c6edb2017-10-18 11:39:10 +05304872 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4873 if (rc)
4874 return rc;
Sakthivel Kf5860992013-04-17 16:37:02 +05304875 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Viswas G25c6edb2017-10-18 11:39:10 +05304876 payload.tag = cpu_to_le32(tag);
Sakthivel Kf5860992013-04-17 16:37:02 +05304877 payload.phyop_phyid =
4878 cpu_to_le32(((phy_op & 0xFF) << 8) | (phyId & 0xFF));
peter chang91a43fa2019-11-14 15:39:05 +05304879 return pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4880 sizeof(payload), 0);
Sakthivel Kf5860992013-04-17 16:37:02 +05304881}
4882
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004883static u32 pm80xx_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
Sakthivel Kf5860992013-04-17 16:37:02 +05304884{
Sakthivel Kf5860992013-04-17 16:37:02 +05304885#ifdef PM8001_USE_MSIX
4886 return 1;
Colin Ian King292c04c2019-03-28 23:43:28 +00004887#else
4888 u32 value;
4889
Sakthivel Kf5860992013-04-17 16:37:02 +05304890 value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4891 if (value)
4892 return 1;
4893 return 0;
Colin Ian King292c04c2019-03-28 23:43:28 +00004894#endif
Sakthivel Kf5860992013-04-17 16:37:02 +05304895}
4896
4897/**
4898 * pm8001_chip_isr - PM8001 isr handler.
4899 * @pm8001_ha: our hba card information.
Lee Jones6ad4a512020-07-21 17:41:25 +01004900 * @vec: irq number.
Sakthivel Kf5860992013-04-17 16:37:02 +05304901 */
4902static irqreturn_t
4903pm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
4904{
4905 pm80xx_chip_interrupt_disable(pm8001_ha, vec);
Joe Perches1b5d2792020-11-20 15:16:09 -08004906 pm8001_dbg(pm8001_ha, DEVIO,
4907 "irq vec %d, ODMR:0x%x\n",
4908 vec, pm8001_cr32(pm8001_ha, 0, 0x30));
Sakthivel Kf5860992013-04-17 16:37:02 +05304909 process_oq(pm8001_ha, vec);
4910 pm80xx_chip_interrupt_enable(pm8001_ha, vec);
4911 return IRQ_HANDLED;
4912}
4913
Lee Jonesea310f52020-07-21 17:41:33 +01004914static void mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
4915 u32 operation, u32 phyid,
4916 u32 length, u32 *buf)
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304917{
4918 u32 tag , i, j = 0;
4919 int rc;
4920 struct set_phy_profile_req payload;
4921 struct inbound_queue_table *circularQ;
4922 u32 opc = OPC_INB_SET_PHY_PROFILE;
4923
4924 memset(&payload, 0, sizeof(payload));
4925 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4926 if (rc)
Joe Perches1b5d2792020-11-20 15:16:09 -08004927 pm8001_dbg(pm8001_ha, FAIL, "Invalid tag\n");
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304928 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4929 payload.tag = cpu_to_le32(tag);
4930 payload.ppc_phyid = (((operation & 0xF) << 8) | (phyid & 0xFF));
Joe Perches1b5d2792020-11-20 15:16:09 -08004931 pm8001_dbg(pm8001_ha, INIT,
4932 " phy profile command for phy %x ,length is %d\n",
4933 payload.ppc_phyid, length);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304934 for (i = length; i < (length + PHY_DWORD_LENGTH - 1); i++) {
4935 payload.reserved[j] = cpu_to_le32(*((u32 *)buf + i));
4936 j++;
4937 }
peter chang91a43fa2019-11-14 15:39:05 +05304938 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4939 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304940 if (rc)
4941 pm8001_tag_free(pm8001_ha, tag);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304942}
4943
4944void pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha,
4945 u32 length, u8 *buf)
4946{
YueHaibingfdd0a662018-09-14 01:38:56 +00004947 u32 i;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304948
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304949 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
4950 mpi_set_phy_profile_req(pm8001_ha,
4951 SAS_PHY_ANALOG_SETTINGS_PAGE, i, length, (u32 *)buf);
4952 length = length + PHY_DWORD_LENGTH;
4953 }
Joe Perches1b5d2792020-11-20 15:16:09 -08004954 pm8001_dbg(pm8001_ha, INIT, "phy settings completed\n");
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304955}
Benjamin Roodc5614df2015-10-30 10:53:28 -04004956
4957void pm8001_set_phy_profile_single(struct pm8001_hba_info *pm8001_ha,
4958 u32 phy, u32 length, u32 *buf)
4959{
4960 u32 tag, opc;
4961 int rc, i;
4962 struct set_phy_profile_req payload;
4963 struct inbound_queue_table *circularQ;
4964
4965 memset(&payload, 0, sizeof(payload));
4966
4967 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4968 if (rc)
Joe Perches1b5d2792020-11-20 15:16:09 -08004969 pm8001_dbg(pm8001_ha, INIT, "Invalid tag\n");
Benjamin Roodc5614df2015-10-30 10:53:28 -04004970
4971 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4972 opc = OPC_INB_SET_PHY_PROFILE;
4973
4974 payload.tag = cpu_to_le32(tag);
4975 payload.ppc_phyid = (((SAS_PHY_ANALOG_SETTINGS_PAGE & 0xF) << 8)
4976 | (phy & 0xFF));
4977
4978 for (i = 0; i < length; i++)
4979 payload.reserved[i] = cpu_to_le32(*(buf + i));
4980
peter chang91a43fa2019-11-14 15:39:05 +05304981 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4982 sizeof(payload), 0);
Benjamin Roodc5614df2015-10-30 10:53:28 -04004983 if (rc)
4984 pm8001_tag_free(pm8001_ha, tag);
4985
Joe Perches1b5d2792020-11-20 15:16:09 -08004986 pm8001_dbg(pm8001_ha, INIT, "PHY %d settings applied\n", phy);
Benjamin Roodc5614df2015-10-30 10:53:28 -04004987}
Sakthivel Kf5860992013-04-17 16:37:02 +05304988const struct pm8001_dispatch pm8001_80xx_dispatch = {
4989 .name = "pmc80xx",
4990 .chip_init = pm80xx_chip_init,
4991 .chip_soft_rst = pm80xx_chip_soft_rst,
4992 .chip_rst = pm80xx_hw_chip_rst,
4993 .chip_iounmap = pm8001_chip_iounmap,
4994 .isr = pm80xx_chip_isr,
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004995 .is_our_interrupt = pm80xx_chip_is_our_interrupt,
Sakthivel Kf5860992013-04-17 16:37:02 +05304996 .isr_process_oq = process_oq,
4997 .interrupt_enable = pm80xx_chip_interrupt_enable,
4998 .interrupt_disable = pm80xx_chip_interrupt_disable,
4999 .make_prd = pm8001_chip_make_sg,
5000 .smp_req = pm80xx_chip_smp_req,
5001 .ssp_io_req = pm80xx_chip_ssp_io_req,
5002 .sata_req = pm80xx_chip_sata_req,
5003 .phy_start_req = pm80xx_chip_phy_start_req,
5004 .phy_stop_req = pm80xx_chip_phy_stop_req,
5005 .reg_dev_req = pm80xx_chip_reg_dev_req,
5006 .dereg_dev_req = pm8001_chip_dereg_dev_req,
5007 .phy_ctl_req = pm80xx_chip_phy_ctl_req,
5008 .task_abort = pm8001_chip_abort_task,
5009 .ssp_tm_req = pm8001_chip_ssp_tm_req,
5010 .get_nvmd_req = pm8001_chip_get_nvmd_req,
5011 .set_nvmd_req = pm8001_chip_set_nvmd_req,
5012 .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
5013 .set_dev_state_req = pm8001_chip_set_dev_state_req,
akshatzena961ea02021-01-09 18:08:43 +05305014 .fatal_errors = pm80xx_fatal_errors,
Sakthivel Kf5860992013-04-17 16:37:02 +05305015};