xref: /openbmc/linux/drivers/scsi/pm8001/pm80xx_hwi.c (revision c13e7331)
1f5860992SSakthivel K /*
2f5860992SSakthivel K  * PMC-Sierra SPCv/ve 8088/8089 SAS/SATA based host adapters driver
3f5860992SSakthivel K  *
4f5860992SSakthivel K  * Copyright (c) 2008-2009 PMC-Sierra, Inc.,
5f5860992SSakthivel K  * All rights reserved.
6f5860992SSakthivel K  *
7f5860992SSakthivel K  * Redistribution and use in source and binary forms, with or without
8f5860992SSakthivel K  * modification, are permitted provided that the following conditions
9f5860992SSakthivel K  * are met:
10f5860992SSakthivel K  * 1. Redistributions of source code must retain the above copyright
11f5860992SSakthivel K  * notice, this list of conditions, and the following disclaimer,
12f5860992SSakthivel K  * without modification.
13f5860992SSakthivel K  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14f5860992SSakthivel K  * substantially similar to the "NO WARRANTY" disclaimer below
15f5860992SSakthivel K  * ("Disclaimer") and any redistribution must be conditioned upon
16f5860992SSakthivel K  * including a substantially similar Disclaimer requirement for further
17f5860992SSakthivel K  * binary redistribution.
18f5860992SSakthivel K  * 3. Neither the names of the above-listed copyright holders nor the names
19f5860992SSakthivel K  * of any contributors may be used to endorse or promote products derived
20f5860992SSakthivel K  * from this software without specific prior written permission.
21f5860992SSakthivel K  *
22f5860992SSakthivel K  * Alternatively, this software may be distributed under the terms of the
23f5860992SSakthivel K  * GNU General Public License ("GPL") version 2 as published by the Free
24f5860992SSakthivel K  * Software Foundation.
25f5860992SSakthivel K  *
26f5860992SSakthivel K  * NO WARRANTY
27f5860992SSakthivel K  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28f5860992SSakthivel K  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29f5860992SSakthivel K  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30f5860992SSakthivel K  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31f5860992SSakthivel K  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32f5860992SSakthivel K  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33f5860992SSakthivel K  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34f5860992SSakthivel K  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35f5860992SSakthivel K  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36f5860992SSakthivel K  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37f5860992SSakthivel K  * POSSIBILITY OF SUCH DAMAGES.
38f5860992SSakthivel K  *
39f5860992SSakthivel K  */
40f5860992SSakthivel K  #include <linux/slab.h>
41f5860992SSakthivel K  #include "pm8001_sas.h"
42f5860992SSakthivel K  #include "pm80xx_hwi.h"
43f5860992SSakthivel K  #include "pm8001_chips.h"
44f5860992SSakthivel K  #include "pm8001_ctl.h"
458ceddda3SChangyuan Lyu #include "pm80xx_tracepoints.h"
46f5860992SSakthivel K 
47f5860992SSakthivel K #define SMP_DIRECT 1
48f5860992SSakthivel K #define SMP_INDIRECT 2
49d078b511SAnand Kumar Santhanam 
50d078b511SAnand Kumar Santhanam 
pm80xx_bar4_shift(struct pm8001_hba_info * pm8001_ha,u32 shift_value)51d078b511SAnand Kumar Santhanam int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shift_value)
52d078b511SAnand Kumar Santhanam {
53d078b511SAnand Kumar Santhanam 	u32 reg_val;
54d078b511SAnand Kumar Santhanam 	unsigned long start;
55d078b511SAnand Kumar Santhanam 	pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER, shift_value);
56d078b511SAnand Kumar Santhanam 	/* confirm the setting is written */
57d078b511SAnand Kumar Santhanam 	start = jiffies + HZ; /* 1 sec */
58d078b511SAnand Kumar Santhanam 	do {
59d078b511SAnand Kumar Santhanam 		reg_val = pm8001_cr32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER);
60d078b511SAnand Kumar Santhanam 	} while ((reg_val != shift_value) && time_before(jiffies, start));
61d078b511SAnand Kumar Santhanam 	if (reg_val != shift_value) {
621b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:MEMBASE_II_SHIFT_REGISTER = 0x%x\n",
631b5d2793SJoe Perches 			   reg_val);
64d078b511SAnand Kumar Santhanam 		return -1;
65d078b511SAnand Kumar Santhanam 	}
66d078b511SAnand Kumar Santhanam 	return 0;
67d078b511SAnand Kumar Santhanam }
68d078b511SAnand Kumar Santhanam 
pm80xx_pci_mem_copy(struct pm8001_hba_info * pm8001_ha,u32 soffset,__le32 * destination,u32 dw_count,u32 bus_base_number)69ea310f57SLee Jones static void pm80xx_pci_mem_copy(struct pm8001_hba_info  *pm8001_ha, u32 soffset,
703762d8f6SDamien Le Moal 				__le32 *destination,
71d078b511SAnand Kumar Santhanam 				u32 dw_count, u32 bus_base_number)
72d078b511SAnand Kumar Santhanam {
73d078b511SAnand Kumar Santhanam 	u32 index, value, offset;
74d078b511SAnand Kumar Santhanam 
753762d8f6SDamien Le Moal 	for (index = 0; index < dw_count; index += 4, destination++) {
76044f59deSDeepak Ukey 		offset = (soffset + index);
77d078b511SAnand Kumar Santhanam 		if (offset < (64 * 1024)) {
78d078b511SAnand Kumar Santhanam 			value = pm8001_cr32(pm8001_ha, bus_base_number, offset);
793762d8f6SDamien Le Moal 			*destination = cpu_to_le32(value);
80d078b511SAnand Kumar Santhanam 		}
81d078b511SAnand Kumar Santhanam 	}
82d078b511SAnand Kumar Santhanam 	return;
83d078b511SAnand Kumar Santhanam }
84d078b511SAnand Kumar Santhanam 
pm80xx_get_fatal_dump(struct device * cdev,struct device_attribute * attr,char * buf)85d078b511SAnand Kumar Santhanam ssize_t pm80xx_get_fatal_dump(struct device *cdev,
86d078b511SAnand Kumar Santhanam 	struct device_attribute *attr, char *buf)
87d078b511SAnand Kumar Santhanam {
88d078b511SAnand Kumar Santhanam 	struct Scsi_Host *shost = class_to_shost(cdev);
89d078b511SAnand Kumar Santhanam 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
90d078b511SAnand Kumar Santhanam 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
91d078b511SAnand Kumar Santhanam 	void __iomem *fatal_table_address = pm8001_ha->fatal_tbl_addr;
92d078b511SAnand Kumar Santhanam 	u32 accum_len, reg_val, index, *temp;
93044f59deSDeepak Ukey 	u32 status = 1;
94d078b511SAnand Kumar Santhanam 	unsigned long start;
95d078b511SAnand Kumar Santhanam 	u8 *direct_data;
96d078b511SAnand Kumar Santhanam 	char *fatal_error_data = buf;
97044f59deSDeepak Ukey 	u32 length_to_read;
98044f59deSDeepak Ukey 	u32 offset;
99d078b511SAnand Kumar Santhanam 
100d078b511SAnand Kumar Santhanam 	pm8001_ha->forensic_info.data_buf.direct_data = buf;
101d078b511SAnand Kumar Santhanam 	if (pm8001_ha->chip_id == chip_8001) {
102d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.direct_data +=
103d078b511SAnand Kumar Santhanam 			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
104d078b511SAnand Kumar Santhanam 			"Not supported for SPC controller");
105d078b511SAnand Kumar Santhanam 		return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
106d078b511SAnand Kumar Santhanam 			(char *)buf;
107d078b511SAnand Kumar Santhanam 	}
108044f59deSDeepak Ukey 	/* initialize variables for very first call from host application */
109d078b511SAnand Kumar Santhanam 	if (pm8001_ha->forensic_info.data_buf.direct_offset == 0) {
1101b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
1111b5d2793SJoe Perches 			   "forensic_info TYPE_NON_FATAL..............\n");
112d078b511SAnand Kumar Santhanam 		direct_data = (u8 *)fatal_error_data;
113d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_type = TYPE_NON_FATAL;
114d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.direct_len = SYSFS_OFFSET;
115044f59deSDeepak Ukey 		pm8001_ha->forensic_info.data_buf.direct_offset = 0;
116d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.read_len = 0;
117044f59deSDeepak Ukey 		pm8001_ha->forensic_preserved_accumulated_transfer = 0;
118044f59deSDeepak Ukey 
119044f59deSDeepak Ukey 		/* Write signature to fatal dump table */
120044f59deSDeepak Ukey 		pm8001_mw32(fatal_table_address,
121044f59deSDeepak Ukey 				MPI_FATAL_EDUMP_TABLE_SIGNATURE, 0x1234abcd);
122d078b511SAnand Kumar Santhanam 
123d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.direct_data = direct_data;
1241b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "ossaHwCB: status1 %d\n", status);
1251b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "ossaHwCB: read_len 0x%x\n",
1261b5d2793SJoe Perches 			   pm8001_ha->forensic_info.data_buf.read_len);
1271b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "ossaHwCB: direct_len 0x%x\n",
1281b5d2793SJoe Perches 			   pm8001_ha->forensic_info.data_buf.direct_len);
1291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "ossaHwCB: direct_offset 0x%x\n",
1301b5d2793SJoe Perches 			   pm8001_ha->forensic_info.data_buf.direct_offset);
131044f59deSDeepak Ukey 	}
132044f59deSDeepak Ukey 	if (pm8001_ha->forensic_info.data_buf.direct_offset == 0) {
133d078b511SAnand Kumar Santhanam 		/* start to get data */
134d078b511SAnand Kumar Santhanam 		/* Program the MEMBASE II Shifting Register with 0x00.*/
135d078b511SAnand Kumar Santhanam 		pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
136d078b511SAnand Kumar Santhanam 				pm8001_ha->fatal_forensic_shift_offset);
137d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_last_offset = 0;
138d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_fatal_step = 0;
139d078b511SAnand Kumar Santhanam 		pm8001_ha->fatal_bar_loc = 0;
140d078b511SAnand Kumar Santhanam 	}
141cf370066SViswas G 
142bb6beabfSRandy Dunlap 	/* Read until accum_len is retrieved */
143d078b511SAnand Kumar Santhanam 	accum_len = pm8001_mr32(fatal_table_address,
144d078b511SAnand Kumar Santhanam 				MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
145044f59deSDeepak Ukey 	/* Determine length of data between previously stored transfer length
146044f59deSDeepak Ukey 	 * and current accumulated transfer length
147044f59deSDeepak Ukey 	 */
148044f59deSDeepak Ukey 	length_to_read =
149044f59deSDeepak Ukey 		accum_len - pm8001_ha->forensic_preserved_accumulated_transfer;
1501b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: accum_len 0x%x\n",
1511b5d2793SJoe Perches 		   accum_len);
1521b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: length_to_read 0x%x\n",
1531b5d2793SJoe Perches 		   length_to_read);
1541b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: last_offset 0x%x\n",
1551b5d2793SJoe Perches 		   pm8001_ha->forensic_last_offset);
1561b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: read_len 0x%x\n",
1571b5d2793SJoe Perches 		   pm8001_ha->forensic_info.data_buf.read_len);
1581b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv:: direct_len 0x%x\n",
1591b5d2793SJoe Perches 		   pm8001_ha->forensic_info.data_buf.direct_len);
1601b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv:: direct_offset 0x%x\n",
1611b5d2793SJoe Perches 		   pm8001_ha->forensic_info.data_buf.direct_offset);
162044f59deSDeepak Ukey 
163044f59deSDeepak Ukey 	/* If accumulated length failed to read correctly fail the attempt.*/
164d078b511SAnand Kumar Santhanam 	if (accum_len == 0xFFFFFFFF) {
1651b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
1661b5d2793SJoe Perches 			   "Possible PCI issue 0x%x not expected\n",
1671b5d2793SJoe Perches 			   accum_len);
168044f59deSDeepak Ukey 		return status;
169d078b511SAnand Kumar Santhanam 	}
170044f59deSDeepak Ukey 	/* If accumulated length is zero fail the attempt */
171044f59deSDeepak Ukey 	if (accum_len == 0) {
172d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.direct_data +=
173d078b511SAnand Kumar Santhanam 			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
174d078b511SAnand Kumar Santhanam 			"%08x ", 0xFFFFFFFF);
175d078b511SAnand Kumar Santhanam 		return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
176d078b511SAnand Kumar Santhanam 			(char *)buf;
177d078b511SAnand Kumar Santhanam 	}
178044f59deSDeepak Ukey 	/* Accumulated length is good so start capturing the first data */
179d078b511SAnand Kumar Santhanam 	temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
180d078b511SAnand Kumar Santhanam 	if (pm8001_ha->forensic_fatal_step == 0) {
181d078b511SAnand Kumar Santhanam moreData:
182044f59deSDeepak Ukey 		/* If data to read is less than SYSFS_OFFSET then reduce the
183044f59deSDeepak Ukey 		 * length of dataLen
184044f59deSDeepak Ukey 		 */
185044f59deSDeepak Ukey 		if (pm8001_ha->forensic_last_offset + SYSFS_OFFSET
186044f59deSDeepak Ukey 				> length_to_read) {
187044f59deSDeepak Ukey 			pm8001_ha->forensic_info.data_buf.direct_len =
188044f59deSDeepak Ukey 				length_to_read -
189044f59deSDeepak Ukey 				pm8001_ha->forensic_last_offset;
190044f59deSDeepak Ukey 		} else {
191044f59deSDeepak Ukey 			pm8001_ha->forensic_info.data_buf.direct_len =
192044f59deSDeepak Ukey 				SYSFS_OFFSET;
193044f59deSDeepak Ukey 		}
194d078b511SAnand Kumar Santhanam 		if (pm8001_ha->forensic_info.data_buf.direct_data) {
195d078b511SAnand Kumar Santhanam 			/* Data is in bar, copy to host memory */
196044f59deSDeepak Ukey 			pm80xx_pci_mem_copy(pm8001_ha,
197044f59deSDeepak Ukey 			pm8001_ha->fatal_bar_loc,
198d078b511SAnand Kumar Santhanam 			pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr,
199044f59deSDeepak Ukey 			pm8001_ha->forensic_info.data_buf.direct_len, 1);
200d078b511SAnand Kumar Santhanam 		}
201d078b511SAnand Kumar Santhanam 		pm8001_ha->fatal_bar_loc +=
202d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_len;
203d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.direct_offset +=
204d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_len;
205d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_last_offset	+=
206d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_len;
207d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.read_len =
208d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_len;
209d078b511SAnand Kumar Santhanam 
210044f59deSDeepak Ukey 		if (pm8001_ha->forensic_last_offset  >= length_to_read) {
211d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_data +=
212d078b511SAnand Kumar Santhanam 			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
213d078b511SAnand Kumar Santhanam 				"%08x ", 3);
214044f59deSDeepak Ukey 			for (index = 0; index <
215044f59deSDeepak Ukey 				(pm8001_ha->forensic_info.data_buf.direct_len
216044f59deSDeepak Ukey 				 / 4); index++) {
217d078b511SAnand Kumar Santhanam 				pm8001_ha->forensic_info.data_buf.direct_data +=
218044f59deSDeepak Ukey 				sprintf(
219044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data,
220d078b511SAnand Kumar Santhanam 				"%08x ", *(temp + index));
221d078b511SAnand Kumar Santhanam 			}
222d078b511SAnand Kumar Santhanam 
223d078b511SAnand Kumar Santhanam 			pm8001_ha->fatal_bar_loc = 0;
224d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_fatal_step = 1;
225d078b511SAnand Kumar Santhanam 			pm8001_ha->fatal_forensic_shift_offset = 0;
226d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_last_offset	= 0;
227044f59deSDeepak Ukey 			status = 0;
228044f59deSDeepak Ukey 			offset = (int)
229044f59deSDeepak Ukey 			((char *)pm8001_ha->forensic_info.data_buf.direct_data
230044f59deSDeepak Ukey 			- (char *)buf);
2311b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, IO,
2321b5d2793SJoe Perches 				   "get_fatal_spcv:return1 0x%x\n", offset);
233d078b511SAnand Kumar Santhanam 			return (char *)pm8001_ha->
234d078b511SAnand Kumar Santhanam 				forensic_info.data_buf.direct_data -
235d078b511SAnand Kumar Santhanam 				(char *)buf;
236d078b511SAnand Kumar Santhanam 		}
237d078b511SAnand Kumar Santhanam 		if (pm8001_ha->fatal_bar_loc < (64 * 1024)) {
238d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_data +=
239d078b511SAnand Kumar Santhanam 				sprintf(pm8001_ha->
240d078b511SAnand Kumar Santhanam 					forensic_info.data_buf.direct_data,
241d078b511SAnand Kumar Santhanam 					"%08x ", 2);
242044f59deSDeepak Ukey 			for (index = 0; index <
243044f59deSDeepak Ukey 				(pm8001_ha->forensic_info.data_buf.direct_len
244044f59deSDeepak Ukey 				 / 4); index++) {
245044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data
246044f59deSDeepak Ukey 					+= sprintf(pm8001_ha->
247d078b511SAnand Kumar Santhanam 					forensic_info.data_buf.direct_data,
248d078b511SAnand Kumar Santhanam 					"%08x ", *(temp + index));
249d078b511SAnand Kumar Santhanam 			}
250044f59deSDeepak Ukey 			status = 0;
251044f59deSDeepak Ukey 			offset = (int)
252044f59deSDeepak Ukey 			((char *)pm8001_ha->forensic_info.data_buf.direct_data
253044f59deSDeepak Ukey 			- (char *)buf);
2541b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, IO,
2551b5d2793SJoe Perches 				   "get_fatal_spcv:return2 0x%x\n", offset);
256d078b511SAnand Kumar Santhanam 			return (char *)pm8001_ha->
257d078b511SAnand Kumar Santhanam 				forensic_info.data_buf.direct_data -
258d078b511SAnand Kumar Santhanam 				(char *)buf;
259d078b511SAnand Kumar Santhanam 		}
260d078b511SAnand Kumar Santhanam 
261d078b511SAnand Kumar Santhanam 		/* Increment the MEMBASE II Shifting Register value by 0x100.*/
262d078b511SAnand Kumar Santhanam 		pm8001_ha->forensic_info.data_buf.direct_data +=
263d078b511SAnand Kumar Santhanam 			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
264d078b511SAnand Kumar Santhanam 				"%08x ", 2);
265044f59deSDeepak Ukey 		for (index = 0; index <
266044f59deSDeepak Ukey 			(pm8001_ha->forensic_info.data_buf.direct_len
267044f59deSDeepak Ukey 			 / 4) ; index++) {
268d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_data +=
269d078b511SAnand Kumar Santhanam 				sprintf(pm8001_ha->
270d078b511SAnand Kumar Santhanam 				forensic_info.data_buf.direct_data,
271d078b511SAnand Kumar Santhanam 				"%08x ", *(temp + index));
272d078b511SAnand Kumar Santhanam 		}
273d078b511SAnand Kumar Santhanam 		pm8001_ha->fatal_forensic_shift_offset += 0x100;
274d078b511SAnand Kumar Santhanam 		pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
275d078b511SAnand Kumar Santhanam 			pm8001_ha->fatal_forensic_shift_offset);
276d078b511SAnand Kumar Santhanam 		pm8001_ha->fatal_bar_loc = 0;
277044f59deSDeepak Ukey 		status = 0;
278044f59deSDeepak Ukey 		offset = (int)
279044f59deSDeepak Ukey 			((char *)pm8001_ha->forensic_info.data_buf.direct_data
280044f59deSDeepak Ukey 			- (char *)buf);
2811b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: return3 0x%x\n",
2821b5d2793SJoe Perches 			   offset);
283d078b511SAnand Kumar Santhanam 		return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
284d078b511SAnand Kumar Santhanam 			(char *)buf;
285d078b511SAnand Kumar Santhanam 	}
286d078b511SAnand Kumar Santhanam 	if (pm8001_ha->forensic_fatal_step == 1) {
287044f59deSDeepak Ukey 		/* store previous accumulated length before triggering next
288044f59deSDeepak Ukey 		 * accumulated length update
289044f59deSDeepak Ukey 		 */
290044f59deSDeepak Ukey 		pm8001_ha->forensic_preserved_accumulated_transfer =
291044f59deSDeepak Ukey 			pm8001_mr32(fatal_table_address,
292044f59deSDeepak Ukey 			MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
293044f59deSDeepak Ukey 
294044f59deSDeepak Ukey 		/* continue capturing the fatal log until Dump status is 0x3 */
295044f59deSDeepak Ukey 		if (pm8001_mr32(fatal_table_address,
296044f59deSDeepak Ukey 			MPI_FATAL_EDUMP_TABLE_STATUS) <
297044f59deSDeepak Ukey 			MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) {
298044f59deSDeepak Ukey 
299044f59deSDeepak Ukey 			/* reset fddstat bit by writing to zero*/
300044f59deSDeepak Ukey 			pm8001_mw32(fatal_table_address,
301044f59deSDeepak Ukey 					MPI_FATAL_EDUMP_TABLE_STATUS, 0x0);
302044f59deSDeepak Ukey 
303044f59deSDeepak Ukey 			/* set dump control value to '1' so that new data will
304044f59deSDeepak Ukey 			 * be transferred to shared memory
305044f59deSDeepak Ukey 			 */
306d078b511SAnand Kumar Santhanam 			pm8001_mw32(fatal_table_address,
307d078b511SAnand Kumar Santhanam 				MPI_FATAL_EDUMP_TABLE_HANDSHAKE,
308d078b511SAnand Kumar Santhanam 				MPI_FATAL_EDUMP_HANDSHAKE_RDY);
309d078b511SAnand Kumar Santhanam 
310d078b511SAnand Kumar Santhanam 			/*Poll FDDHSHK  until clear */
311d078b511SAnand Kumar Santhanam 			start = jiffies + (2 * HZ); /* 2 sec */
312d078b511SAnand Kumar Santhanam 
313d078b511SAnand Kumar Santhanam 			do {
314d078b511SAnand Kumar Santhanam 				reg_val = pm8001_mr32(fatal_table_address,
315d078b511SAnand Kumar Santhanam 					MPI_FATAL_EDUMP_TABLE_HANDSHAKE);
316d078b511SAnand Kumar Santhanam 			} while ((reg_val) && time_before(jiffies, start));
317d078b511SAnand Kumar Santhanam 
318d078b511SAnand Kumar Santhanam 			if (reg_val != 0) {
3191b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
320044f59deSDeepak Ukey 					   "TIMEOUT:MPI_FATAL_EDUMP_TABLE_HDSHAKE 0x%x\n",
3211b5d2793SJoe Perches 					   reg_val);
322044f59deSDeepak Ukey 			       /* Fail the dump if a timeout occurs */
323044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data +=
324044f59deSDeepak Ukey 				sprintf(
325044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data,
326044f59deSDeepak Ukey 				"%08x ", 0xFFFFFFFF);
327044f59deSDeepak Ukey 				return((char *)
328044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data
329044f59deSDeepak Ukey 				- (char *)buf);
330d078b511SAnand Kumar Santhanam 			}
331044f59deSDeepak Ukey 			/* Poll status register until set to 2 or
332044f59deSDeepak Ukey 			 * 3 for up to 2 seconds
333044f59deSDeepak Ukey 			 */
334044f59deSDeepak Ukey 			start = jiffies + (2 * HZ); /* 2 sec */
335d078b511SAnand Kumar Santhanam 
336044f59deSDeepak Ukey 			do {
337044f59deSDeepak Ukey 				reg_val = pm8001_mr32(fatal_table_address,
338044f59deSDeepak Ukey 					MPI_FATAL_EDUMP_TABLE_STATUS);
3390e7c353eSColin Ian King 			} while (((reg_val != 2) && (reg_val != 3)) &&
340044f59deSDeepak Ukey 					time_before(jiffies, start));
341044f59deSDeepak Ukey 
342044f59deSDeepak Ukey 			if (reg_val < 2) {
3431b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
344044f59deSDeepak Ukey 					   "TIMEOUT:MPI_FATAL_EDUMP_TABLE_STATUS = 0x%x\n",
3451b5d2793SJoe Perches 					   reg_val);
346044f59deSDeepak Ukey 				/* Fail the dump if a timeout occurs */
347044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data +=
348044f59deSDeepak Ukey 				sprintf(
349044f59deSDeepak Ukey 				pm8001_ha->forensic_info.data_buf.direct_data,
350044f59deSDeepak Ukey 				"%08x ", 0xFFFFFFFF);
351ec2e7e1aSViswas G 				return((char *)pm8001_ha->forensic_info.data_buf.direct_data -
352ec2e7e1aSViswas G 						(char *)buf);
353ec2e7e1aSViswas G 			}
354ec2e7e1aSViswas G 	/* reset fatal_forensic_shift_offset back to zero and reset MEMBASE 2 register to zero */
355ec2e7e1aSViswas G 			pm8001_ha->fatal_forensic_shift_offset = 0; /* location in 64k region */
356044f59deSDeepak Ukey 			pm8001_cw32(pm8001_ha, 0,
357044f59deSDeepak Ukey 					MEMBASE_II_SHIFT_REGISTER,
358044f59deSDeepak Ukey 					pm8001_ha->fatal_forensic_shift_offset);
359044f59deSDeepak Ukey 		}
360044f59deSDeepak Ukey 		/* Read the next block of the debug data.*/
361044f59deSDeepak Ukey 		length_to_read = pm8001_mr32(fatal_table_address,
362044f59deSDeepak Ukey 		MPI_FATAL_EDUMP_TABLE_ACCUM_LEN) -
363044f59deSDeepak Ukey 		pm8001_ha->forensic_preserved_accumulated_transfer;
364044f59deSDeepak Ukey 		if (length_to_read != 0x0) {
365d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_fatal_step = 0;
366d078b511SAnand Kumar Santhanam 			goto moreData;
367d078b511SAnand Kumar Santhanam 		} else {
368d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.direct_data +=
3697b382122SColin Ian King 			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
370d078b511SAnand Kumar Santhanam 				"%08x ", 4);
3717b382122SColin Ian King 			pm8001_ha->forensic_info.data_buf.read_len = 0xFFFFFFFF;
3727b382122SColin Ian King 			pm8001_ha->forensic_info.data_buf.direct_len =  0;
3737b382122SColin Ian King 			pm8001_ha->forensic_info.data_buf.direct_offset = 0;
374d078b511SAnand Kumar Santhanam 			pm8001_ha->forensic_info.data_buf.read_len = 0;
375d078b511SAnand Kumar Santhanam 		}
376d078b511SAnand Kumar Santhanam 	}
377044f59deSDeepak Ukey 	offset = (int)((char *)pm8001_ha->forensic_info.data_buf.direct_data
378044f59deSDeepak Ukey 			- (char *)buf);
3791b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "get_fatal_spcv: return4 0x%x\n", offset);
380ec2e7e1aSViswas G 	return ((char *)pm8001_ha->forensic_info.data_buf.direct_data -
381ec2e7e1aSViswas G 		(char *)buf);
382d078b511SAnand Kumar Santhanam }
383d078b511SAnand Kumar Santhanam 
384dba2cc03SDeepak Ukey /* pm80xx_get_non_fatal_dump - dump the nonfatal data from the dma
385dba2cc03SDeepak Ukey  * location by the firmware.
386dba2cc03SDeepak Ukey  */
pm80xx_get_non_fatal_dump(struct device * cdev,struct device_attribute * attr,char * buf)387dba2cc03SDeepak Ukey ssize_t pm80xx_get_non_fatal_dump(struct device *cdev,
388dba2cc03SDeepak Ukey 	struct device_attribute *attr, char *buf)
389dba2cc03SDeepak Ukey {
390dba2cc03SDeepak Ukey 	struct Scsi_Host *shost = class_to_shost(cdev);
391dba2cc03SDeepak Ukey 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
392dba2cc03SDeepak Ukey 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
393dba2cc03SDeepak Ukey 	void __iomem *nonfatal_table_address = pm8001_ha->fatal_tbl_addr;
394dba2cc03SDeepak Ukey 	u32 accum_len = 0;
395dba2cc03SDeepak Ukey 	u32 total_len = 0;
396dba2cc03SDeepak Ukey 	u32 reg_val = 0;
397dba2cc03SDeepak Ukey 	u32 *temp = NULL;
398dba2cc03SDeepak Ukey 	u32 index = 0;
399dba2cc03SDeepak Ukey 	u32 output_length;
400dba2cc03SDeepak Ukey 	unsigned long start = 0;
401dba2cc03SDeepak Ukey 	char *buf_copy = buf;
402dba2cc03SDeepak Ukey 
403dba2cc03SDeepak Ukey 	temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
404dba2cc03SDeepak Ukey 	if (++pm8001_ha->non_fatal_count == 1) {
405dba2cc03SDeepak Ukey 		if (pm8001_ha->chip_id == chip_8001) {
406dba2cc03SDeepak Ukey 			snprintf(pm8001_ha->forensic_info.data_buf.direct_data,
407dba2cc03SDeepak Ukey 				PAGE_SIZE, "Not supported for SPC controller");
408dba2cc03SDeepak Ukey 			return 0;
409dba2cc03SDeepak Ukey 		}
4101b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "forensic_info TYPE_NON_FATAL...\n");
411dba2cc03SDeepak Ukey 		/*
412dba2cc03SDeepak Ukey 		 * Step 1: Write the host buffer parameters in the MPI Fatal and
413dba2cc03SDeepak Ukey 		 * Non-Fatal Error Dump Capture Table.This is the buffer
414dba2cc03SDeepak Ukey 		 * where debug data will be DMAed to.
415dba2cc03SDeepak Ukey 		 */
416dba2cc03SDeepak Ukey 		pm8001_mw32(nonfatal_table_address,
417dba2cc03SDeepak Ukey 		MPI_FATAL_EDUMP_TABLE_LO_OFFSET,
418dba2cc03SDeepak Ukey 		pm8001_ha->memoryMap.region[FORENSIC_MEM].phys_addr_lo);
419dba2cc03SDeepak Ukey 
420dba2cc03SDeepak Ukey 		pm8001_mw32(nonfatal_table_address,
421dba2cc03SDeepak Ukey 		MPI_FATAL_EDUMP_TABLE_HI_OFFSET,
422dba2cc03SDeepak Ukey 		pm8001_ha->memoryMap.region[FORENSIC_MEM].phys_addr_hi);
423dba2cc03SDeepak Ukey 
424dba2cc03SDeepak Ukey 		pm8001_mw32(nonfatal_table_address,
425dba2cc03SDeepak Ukey 		MPI_FATAL_EDUMP_TABLE_LENGTH, SYSFS_OFFSET);
426dba2cc03SDeepak Ukey 
427dba2cc03SDeepak Ukey 		/* Optionally, set the DUMPCTRL bit to 1 if the host
428dba2cc03SDeepak Ukey 		 * keeps sending active I/Os while capturing the non-fatal
429dba2cc03SDeepak Ukey 		 * debug data. Otherwise, leave this bit set to zero
430dba2cc03SDeepak Ukey 		 */
431dba2cc03SDeepak Ukey 		pm8001_mw32(nonfatal_table_address,
432dba2cc03SDeepak Ukey 		MPI_FATAL_EDUMP_TABLE_HANDSHAKE, MPI_FATAL_EDUMP_HANDSHAKE_RDY);
433dba2cc03SDeepak Ukey 
434dba2cc03SDeepak Ukey 		/*
435dba2cc03SDeepak Ukey 		 * Step 2: Clear Accumulative Length of Debug Data Transferred
436dba2cc03SDeepak Ukey 		 * [ACCDDLEN] field in the MPI Fatal and Non-Fatal Error Dump
437dba2cc03SDeepak Ukey 		 * Capture Table to zero.
438dba2cc03SDeepak Ukey 		 */
439dba2cc03SDeepak Ukey 		pm8001_mw32(nonfatal_table_address,
440dba2cc03SDeepak Ukey 				MPI_FATAL_EDUMP_TABLE_ACCUM_LEN, 0);
441dba2cc03SDeepak Ukey 
442dba2cc03SDeepak Ukey 		/* initiallize previous accumulated length to 0 */
443dba2cc03SDeepak Ukey 		pm8001_ha->forensic_preserved_accumulated_transfer = 0;
444dba2cc03SDeepak Ukey 		pm8001_ha->non_fatal_read_length = 0;
445dba2cc03SDeepak Ukey 	}
446dba2cc03SDeepak Ukey 
447dba2cc03SDeepak Ukey 	total_len = pm8001_mr32(nonfatal_table_address,
448dba2cc03SDeepak Ukey 			MPI_FATAL_EDUMP_TABLE_TOTAL_LEN);
449dba2cc03SDeepak Ukey 	/*
450dba2cc03SDeepak Ukey 	 * Step 3:Clear Fatal/Non-Fatal Debug Data Transfer Status [FDDTSTAT]
451dba2cc03SDeepak Ukey 	 * field and then request that the SPCv controller transfer the debug
452dba2cc03SDeepak Ukey 	 * data by setting bit 7 of the Inbound Doorbell Set Register.
453dba2cc03SDeepak Ukey 	 */
454dba2cc03SDeepak Ukey 	pm8001_mw32(nonfatal_table_address, MPI_FATAL_EDUMP_TABLE_STATUS, 0);
455dba2cc03SDeepak Ukey 	pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET,
456dba2cc03SDeepak Ukey 			SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP);
457dba2cc03SDeepak Ukey 
458dba2cc03SDeepak Ukey 	/*
459dba2cc03SDeepak Ukey 	 * Step 4.1: Read back the Inbound Doorbell Set Register (by polling for
460dba2cc03SDeepak Ukey 	 * 2 seconds) until register bit 7 is cleared.
461dba2cc03SDeepak Ukey 	 * This step only indicates the request is accepted by the controller.
462dba2cc03SDeepak Ukey 	 */
463dba2cc03SDeepak Ukey 	start = jiffies + (2 * HZ); /* 2 sec */
464dba2cc03SDeepak Ukey 	do {
465dba2cc03SDeepak Ukey 		reg_val = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET) &
466dba2cc03SDeepak Ukey 			SPCv_MSGU_CFG_TABLE_NONFATAL_DUMP;
467dba2cc03SDeepak Ukey 	} while ((reg_val != 0) && time_before(jiffies, start));
468dba2cc03SDeepak Ukey 
469dba2cc03SDeepak Ukey 	/* Step 4.2: To check the completion of the transfer, poll the Fatal/Non
470dba2cc03SDeepak Ukey 	 * Fatal Debug Data Transfer Status [FDDTSTAT] field for 2 seconds in
471dba2cc03SDeepak Ukey 	 * the MPI Fatal and Non-Fatal Error Dump Capture Table.
472dba2cc03SDeepak Ukey 	 */
473dba2cc03SDeepak Ukey 	start = jiffies + (2 * HZ); /* 2 sec */
474dba2cc03SDeepak Ukey 	do {
475dba2cc03SDeepak Ukey 		reg_val = pm8001_mr32(nonfatal_table_address,
476dba2cc03SDeepak Ukey 				MPI_FATAL_EDUMP_TABLE_STATUS);
477dba2cc03SDeepak Ukey 	} while ((!reg_val) && time_before(jiffies, start));
478dba2cc03SDeepak Ukey 
479dba2cc03SDeepak Ukey 	if ((reg_val == 0x00) ||
480dba2cc03SDeepak Ukey 		(reg_val == MPI_FATAL_EDUMP_TABLE_STAT_DMA_FAILED) ||
481dba2cc03SDeepak Ukey 		(reg_val > MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE)) {
482dba2cc03SDeepak Ukey 		pm8001_ha->non_fatal_read_length = 0;
483dba2cc03SDeepak Ukey 		buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 0xFFFFFFFF);
484dba2cc03SDeepak Ukey 		pm8001_ha->non_fatal_count = 0;
485dba2cc03SDeepak Ukey 		return (buf_copy - buf);
486dba2cc03SDeepak Ukey 	} else if (reg_val ==
487dba2cc03SDeepak Ukey 			MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_MORE_DATA) {
488dba2cc03SDeepak Ukey 		buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 2);
489dba2cc03SDeepak Ukey 	} else if ((reg_val == MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) ||
490dba2cc03SDeepak Ukey 		(pm8001_ha->non_fatal_read_length >= total_len)) {
491dba2cc03SDeepak Ukey 		pm8001_ha->non_fatal_read_length = 0;
492dba2cc03SDeepak Ukey 		buf_copy += snprintf(buf_copy, PAGE_SIZE, "%08x ", 4);
493dba2cc03SDeepak Ukey 		pm8001_ha->non_fatal_count = 0;
494dba2cc03SDeepak Ukey 	}
495dba2cc03SDeepak Ukey 	accum_len = pm8001_mr32(nonfatal_table_address,
496dba2cc03SDeepak Ukey 			MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
497dba2cc03SDeepak Ukey 	output_length = accum_len -
498dba2cc03SDeepak Ukey 		pm8001_ha->forensic_preserved_accumulated_transfer;
499dba2cc03SDeepak Ukey 
500dba2cc03SDeepak Ukey 	for (index = 0; index < output_length/4; index++)
501dba2cc03SDeepak Ukey 		buf_copy += snprintf(buf_copy, PAGE_SIZE,
502dba2cc03SDeepak Ukey 				"%08x ", *(temp+index));
503dba2cc03SDeepak Ukey 
504dba2cc03SDeepak Ukey 	pm8001_ha->non_fatal_read_length += output_length;
505dba2cc03SDeepak Ukey 
506dba2cc03SDeepak Ukey 	/* store current accumulated length to use in next iteration as
507dba2cc03SDeepak Ukey 	 * the previous accumulated length
508dba2cc03SDeepak Ukey 	 */
509dba2cc03SDeepak Ukey 	pm8001_ha->forensic_preserved_accumulated_transfer = accum_len;
510dba2cc03SDeepak Ukey 	return (buf_copy - buf);
511dba2cc03SDeepak Ukey }
512dba2cc03SDeepak Ukey 
513f5860992SSakthivel K /**
514f5860992SSakthivel K  * read_main_config_table - read the configure table and save it.
515f5860992SSakthivel K  * @pm8001_ha: our hba card information
516f5860992SSakthivel K  */
read_main_config_table(struct pm8001_hba_info * pm8001_ha)517f5860992SSakthivel K static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
518f5860992SSakthivel K {
519f5860992SSakthivel K 	void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
520f5860992SSakthivel K 
521f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature	=
522f5860992SSakthivel K 		pm8001_mr32(address, MAIN_SIGNATURE_OFFSET);
523f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev =
524f5860992SSakthivel K 		pm8001_mr32(address, MAIN_INTERFACE_REVISION);
525f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev	=
526f5860992SSakthivel K 		pm8001_mr32(address, MAIN_FW_REVISION);
527f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io	=
528f5860992SSakthivel K 		pm8001_mr32(address, MAIN_MAX_OUTSTANDING_IO_OFFSET);
529f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl	=
530f5860992SSakthivel K 		pm8001_mr32(address, MAIN_MAX_SGL_OFFSET);
531f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag =
532f5860992SSakthivel K 		pm8001_mr32(address, MAIN_CNTRL_CAP_OFFSET);
533f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset	=
534f5860992SSakthivel K 		pm8001_mr32(address, MAIN_GST_OFFSET);
535f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset =
536f5860992SSakthivel K 		pm8001_mr32(address, MAIN_IBQ_OFFSET);
537f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset =
538f5860992SSakthivel K 		pm8001_mr32(address, MAIN_OBQ_OFFSET);
539f5860992SSakthivel K 
540f5860992SSakthivel K 	/* read Error Dump Offset and Length */
541f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset0 =
542f5860992SSakthivel K 		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
543f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length0 =
544f5860992SSakthivel K 		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
545f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset1 =
546f5860992SSakthivel K 		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
547f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length1 =
548f5860992SSakthivel K 		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
549f5860992SSakthivel K 
550f5860992SSakthivel K 	/* read GPIO LED settings from the configuration table */
551f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping =
552f5860992SSakthivel K 		pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET);
553f5860992SSakthivel K 
554f5860992SSakthivel K 	/* read analog Setting offset from the configuration table */
555f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.analog_setup_table_offset =
556f5860992SSakthivel K 		pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
557f5860992SSakthivel K 
558f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset =
559f5860992SSakthivel K 		pm8001_mr32(address, MAIN_INT_VECTOR_TABLE_OFFSET);
560f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset =
561f5860992SSakthivel K 		pm8001_mr32(address, MAIN_SAS_PHY_ATTR_TABLE_OFFSET);
5628414cd80SViswas G 	/* read port recover and reset timeout */
5638414cd80SViswas G 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer =
5648414cd80SViswas G 		pm8001_mr32(address, MAIN_PORT_RECOVERY_TIMER);
56524fff017SViswas G 	/* read ILA and inactive firmware version */
56624fff017SViswas G 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version =
56724fff017SViswas G 		pm8001_mr32(address, MAIN_MPI_ILA_RELEASE_TYPE);
56824fff017SViswas G 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version =
56924fff017SViswas G 		pm8001_mr32(address, MAIN_MPI_INACTIVE_FW_VERSION);
5707370672dSpeter chang 
5711b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
5727370672dSpeter chang 		   "Main cfg table: sign:%x interface rev:%x fw_rev:%x\n",
5737370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature,
5747370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev,
5751b5d2793SJoe Perches 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev);
5767370672dSpeter chang 
5771b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
5787370672dSpeter chang 		   "table offset: gst:%x iq:%x oq:%x int vec:%x phy attr:%x\n",
5797370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset,
5807370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset,
5817370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset,
5827370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset,
5831b5d2793SJoe Perches 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset);
5847370672dSpeter chang 
5851b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
5867370672dSpeter chang 		   "Main cfg table; ila rev:%x Inactive fw rev:%x\n",
5877370672dSpeter chang 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version,
5881b5d2793SJoe Perches 		   pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version);
589f5860992SSakthivel K }
590f5860992SSakthivel K 
591f5860992SSakthivel K /**
592f5860992SSakthivel K  * read_general_status_table - read the general status table and save it.
593f5860992SSakthivel K  * @pm8001_ha: our hba card information
594f5860992SSakthivel K  */
read_general_status_table(struct pm8001_hba_info * pm8001_ha)595f5860992SSakthivel K static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
596f5860992SSakthivel K {
597f5860992SSakthivel K 	void __iomem *address = pm8001_ha->general_stat_tbl_addr;
598f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.gst_len_mpistate	=
599f5860992SSakthivel K 			pm8001_mr32(address, GST_GSTLEN_MPIS_OFFSET);
600f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state0	=
601f5860992SSakthivel K 			pm8001_mr32(address, GST_IQ_FREEZE_STATE0_OFFSET);
602f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state1	=
603f5860992SSakthivel K 			pm8001_mr32(address, GST_IQ_FREEZE_STATE1_OFFSET);
604f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.msgu_tcnt		=
605f5860992SSakthivel K 			pm8001_mr32(address, GST_MSGUTCNT_OFFSET);
606f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.iop_tcnt		=
607f5860992SSakthivel K 			pm8001_mr32(address, GST_IOPTCNT_OFFSET);
608f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.gpio_input_val	=
609f5860992SSakthivel K 			pm8001_mr32(address, GST_GPIO_INPUT_VAL);
610f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[0] =
611f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET0);
612f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[1] =
613f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET1);
614f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[2] =
615f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET2);
616f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[3] =
617f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET3);
618f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[4] =
619f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET4);
620f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[5] =
621f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET5);
622f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[6] =
623f5860992SSakthivel K 			pm8001_mr32(address, GST_RERRINFO_OFFSET6);
624f5860992SSakthivel K 	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[7] =
625f5860992SSakthivel K 			 pm8001_mr32(address, GST_RERRINFO_OFFSET7);
626f5860992SSakthivel K }
627f5860992SSakthivel K /**
628f5860992SSakthivel K  * read_phy_attr_table - read the phy attribute table and save it.
629f5860992SSakthivel K  * @pm8001_ha: our hba card information
630f5860992SSakthivel K  */
read_phy_attr_table(struct pm8001_hba_info * pm8001_ha)631f5860992SSakthivel K static void read_phy_attr_table(struct pm8001_hba_info *pm8001_ha)
632f5860992SSakthivel K {
633f5860992SSakthivel K 	void __iomem *address = pm8001_ha->pspa_q_tbl_addr;
634f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[0] =
635f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE0_OFFSET);
636f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[1] =
637f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE1_OFFSET);
638f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[2] =
639f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE2_OFFSET);
640f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[3] =
641f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE3_OFFSET);
642f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[4] =
643f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE4_OFFSET);
644f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[5] =
645f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE5_OFFSET);
646f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[6] =
647f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE6_OFFSET);
648f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[7] =
649f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE7_OFFSET);
650f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[8] =
651f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE8_OFFSET);
652f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[9] =
653f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE9_OFFSET);
654f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[10] =
655f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE10_OFFSET);
656f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[11] =
657f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE11_OFFSET);
658f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[12] =
659f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE12_OFFSET);
660f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[13] =
661f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE13_OFFSET);
662f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[14] =
663f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE14_OFFSET);
664f5860992SSakthivel K 	pm8001_ha->phy_attr_table.phystart1_16[15] =
665f5860992SSakthivel K 			pm8001_mr32(address, PSPA_PHYSTATE15_OFFSET);
666f5860992SSakthivel K 
667f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[0] =
668f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID0_OFFSET);
669f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[1] =
670f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID1_OFFSET);
671f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[2] =
672f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID2_OFFSET);
673f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[3] =
674f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID3_OFFSET);
675f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[4] =
676f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID4_OFFSET);
677f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[5] =
678f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID5_OFFSET);
679f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[6] =
680f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID6_OFFSET);
681f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[7] =
682f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID7_OFFSET);
683f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[8] =
684f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID8_OFFSET);
685f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[9] =
686f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID9_OFFSET);
687f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[10] =
688f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID10_OFFSET);
689f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[11] =
690f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID11_OFFSET);
691f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[12] =
692f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID12_OFFSET);
693f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[13] =
694f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID13_OFFSET);
695f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[14] =
696f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID14_OFFSET);
697f5860992SSakthivel K 	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[15] =
698f5860992SSakthivel K 			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID15_OFFSET);
699f5860992SSakthivel K 
700f5860992SSakthivel K }
701f5860992SSakthivel K 
702f5860992SSakthivel K /**
703f5860992SSakthivel K  * read_inbnd_queue_table - read the inbound queue table and save it.
704f5860992SSakthivel K  * @pm8001_ha: our hba card information
705f5860992SSakthivel K  */
read_inbnd_queue_table(struct pm8001_hba_info * pm8001_ha)706f5860992SSakthivel K static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
707f5860992SSakthivel K {
708f5860992SSakthivel K 	int i;
709f5860992SSakthivel K 	void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
71005c6c029SViswas G 	for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
711f5860992SSakthivel K 		u32 offset = i * 0x20;
712f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
713f5860992SSakthivel K 			get_pci_bar_index(pm8001_mr32(address,
714f5860992SSakthivel K 				(offset + IB_PIPCI_BAR)));
715f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].pi_offset =
716f5860992SSakthivel K 			pm8001_mr32(address, (offset + IB_PIPCI_BAR_OFFSET));
717f5860992SSakthivel K 	}
718f5860992SSakthivel K }
719f5860992SSakthivel K 
720f5860992SSakthivel K /**
721f5860992SSakthivel K  * read_outbnd_queue_table - read the outbound queue table and save it.
722f5860992SSakthivel K  * @pm8001_ha: our hba card information
723f5860992SSakthivel K  */
read_outbnd_queue_table(struct pm8001_hba_info * pm8001_ha)724f5860992SSakthivel K static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
725f5860992SSakthivel K {
726f5860992SSakthivel K 	int i;
727f5860992SSakthivel K 	void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
72805c6c029SViswas G 	for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
729f5860992SSakthivel K 		u32 offset = i * 0x24;
730f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
731f5860992SSakthivel K 			get_pci_bar_index(pm8001_mr32(address,
732f5860992SSakthivel K 				(offset + OB_CIPCI_BAR)));
733f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].ci_offset =
734f5860992SSakthivel K 			pm8001_mr32(address, (offset + OB_CIPCI_BAR_OFFSET));
735f5860992SSakthivel K 	}
736f5860992SSakthivel K }
737f5860992SSakthivel K 
738f5860992SSakthivel K /**
739f5860992SSakthivel K  * init_default_table_values - init the default table.
740f5860992SSakthivel K  * @pm8001_ha: our hba card information
741f5860992SSakthivel K  */
init_default_table_values(struct pm8001_hba_info * pm8001_ha)742f5860992SSakthivel K static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
743f5860992SSakthivel K {
744f5860992SSakthivel K 	int i;
745f5860992SSakthivel K 	u32 offsetib, offsetob;
746f5860992SSakthivel K 	void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
747f5860992SSakthivel K 	void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
74805c6c029SViswas G 	u32 ib_offset = pm8001_ha->ib_offset;
74905c6c029SViswas G 	u32 ob_offset = pm8001_ha->ob_offset;
75005c6c029SViswas G 	u32 ci_offset = pm8001_ha->ci_offset;
75105c6c029SViswas G 	u32 pi_offset = pm8001_ha->pi_offset;
752f5860992SSakthivel K 
753f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr		=
754f5860992SSakthivel K 		pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
755f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr		=
756f5860992SSakthivel K 		pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
757f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size		=
758f5860992SSakthivel K 							PM8001_EVENT_LOG_SIZE;
759f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity		= 0x01;
760f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr	=
761f5860992SSakthivel K 		pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
762f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr	=
763f5860992SSakthivel K 		pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
764f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size		=
765f5860992SSakthivel K 							PM8001_EVENT_LOG_SIZE;
766f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity	= 0x01;
767f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt		= 0x01;
768f5860992SSakthivel K 
769bcd8a452SAjish Koshy 	/* Enable higher IQs and OQs, 32 to 63, bit 16 */
770bcd8a452SAjish Koshy 	if (pm8001_ha->max_q_num > 32)
771bcd8a452SAjish Koshy 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt |=
772bcd8a452SAjish Koshy 							1 << 16;
773c6b9ef57SSakthivel K 	/* Disable end to end CRC checking */
774c6b9ef57SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump = (0x1 << 16);
775c6b9ef57SSakthivel K 
77605c6c029SViswas G 	for (i = 0; i < pm8001_ha->max_q_num; i++) {
777f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt	=
7789504a923SHans Verkuil 			PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
779f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].upper_base_addr	=
78005c6c029SViswas G 			pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi;
781f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].lower_base_addr	=
78205c6c029SViswas G 		pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo;
783f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].base_virt		=
78405c6c029SViswas G 		  (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr;
785f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].total_length		=
78605c6c029SViswas G 			pm8001_ha->memoryMap.region[ib_offset + i].total_len;
787f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr	=
78805c6c029SViswas G 			pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi;
789f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr	=
79005c6c029SViswas G 			pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo;
791f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].ci_virt		=
79205c6c029SViswas G 			pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr;
793b431472bSViswas G 		pm8001_write_32(pm8001_ha->inbnd_q_tbl[i].ci_virt, 0, 0);
794f5860992SSakthivel K 		offsetib = i * 0x20;
795f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].pi_pci_bar		=
796f5860992SSakthivel K 			get_pci_bar_index(pm8001_mr32(addressib,
797f5860992SSakthivel K 				(offsetib + 0x14)));
798f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].pi_offset		=
799f5860992SSakthivel K 			pm8001_mr32(addressib, (offsetib + 0x18));
800f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].producer_idx		= 0;
801f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[i].consumer_index	= 0;
8027370672dSpeter chang 
8031b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEV,
8047370672dSpeter chang 			   "IQ %d pi_bar 0x%x pi_offset 0x%x\n", i,
8057370672dSpeter chang 			   pm8001_ha->inbnd_q_tbl[i].pi_pci_bar,
8061b5d2793SJoe Perches 			   pm8001_ha->inbnd_q_tbl[i].pi_offset);
807f5860992SSakthivel K 	}
80805c6c029SViswas G 	for (i = 0; i < pm8001_ha->max_q_num; i++) {
809f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].element_size_cnt	=
8109504a923SHans Verkuil 			PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
811f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].upper_base_addr	=
81205c6c029SViswas G 			pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
813f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].lower_base_addr	=
81405c6c029SViswas G 			pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
815f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].base_virt		=
81605c6c029SViswas G 		  (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
817f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].total_length		=
81805c6c029SViswas G 			pm8001_ha->memoryMap.region[ob_offset + i].total_len;
819f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr	=
82005c6c029SViswas G 			pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
821f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr	=
82205c6c029SViswas G 			pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
823f5860992SSakthivel K 		/* interrupt vector based on oq */
824f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = (i << 24);
825f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].pi_virt		=
82605c6c029SViswas G 			pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
827b431472bSViswas G 		pm8001_write_32(pm8001_ha->outbnd_q_tbl[i].pi_virt, 0, 0);
828f5860992SSakthivel K 		offsetob = i * 0x24;
829f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].ci_pci_bar		=
830f5860992SSakthivel K 			get_pci_bar_index(pm8001_mr32(addressob,
831f5860992SSakthivel K 			offsetob + 0x14));
832f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].ci_offset		=
833f5860992SSakthivel K 			pm8001_mr32(addressob, (offsetob + 0x18));
834f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].consumer_idx		= 0;
835f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[i].producer_index	= 0;
8367370672dSpeter chang 
8371b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEV,
8387370672dSpeter chang 			   "OQ %d ci_bar 0x%x ci_offset 0x%x\n", i,
8397370672dSpeter chang 			   pm8001_ha->outbnd_q_tbl[i].ci_pci_bar,
8401b5d2793SJoe Perches 			   pm8001_ha->outbnd_q_tbl[i].ci_offset);
841f5860992SSakthivel K 	}
842f5860992SSakthivel K }
843f5860992SSakthivel K 
844f5860992SSakthivel K /**
845f5860992SSakthivel K  * update_main_config_table - update the main default table to the HBA.
846f5860992SSakthivel K  * @pm8001_ha: our hba card information
847f5860992SSakthivel K  */
update_main_config_table(struct pm8001_hba_info * pm8001_ha)848f5860992SSakthivel K static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
849f5860992SSakthivel K {
850f5860992SSakthivel K 	void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
851f5860992SSakthivel K 	pm8001_mw32(address, MAIN_IQNPPD_HPPD_OFFSET,
852f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_q_nppd_hppd);
853f5860992SSakthivel K 	pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_HI,
854f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr);
855f5860992SSakthivel K 	pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_LO,
856f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr);
857f5860992SSakthivel K 	pm8001_mw32(address, MAIN_EVENT_LOG_BUFF_SIZE,
858f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
859f5860992SSakthivel K 	pm8001_mw32(address, MAIN_EVENT_LOG_OPTION,
860f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity);
861f5860992SSakthivel K 	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_HI,
862f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr);
863f5860992SSakthivel K 	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_LO,
864f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr);
865f5860992SSakthivel K 	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_BUFF_SIZE,
866f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size);
867f5860992SSakthivel K 	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_OPTION,
868f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity);
86972349b62SDeepak Ukey 	/* Update Fatal error interrupt vector */
87072349b62SDeepak Ukey 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt |=
87105c6c029SViswas G 					((pm8001_ha->max_q_num - 1) << 8);
872f5860992SSakthivel K 	pm8001_mw32(address, MAIN_FATAL_ERROR_INTERRUPT,
873f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt);
8741b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
8757370672dSpeter chang 		   "Updated Fatal error interrupt vector 0x%x\n",
8761b5d2793SJoe Perches 		   pm8001_mr32(address, MAIN_FATAL_ERROR_INTERRUPT));
8777370672dSpeter chang 
878c6b9ef57SSakthivel K 	pm8001_mw32(address, MAIN_EVENT_CRC_CHECK,
879c6b9ef57SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump);
880f5860992SSakthivel K 
881f5860992SSakthivel K 	/* SPCv specific */
882f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping &= 0xCFFFFFFF;
883f5860992SSakthivel K 	/* Set GPIOLED to 0x2 for LED indicator */
884f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping |= 0x20000000;
885f5860992SSakthivel K 	pm8001_mw32(address, MAIN_GPIO_LED_FLAGS_OFFSET,
886f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping);
8871b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
8887370672dSpeter chang 		   "Programming DW 0x21 in main cfg table with 0x%x\n",
8891b5d2793SJoe Perches 		   pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET));
890f5860992SSakthivel K 
891f5860992SSakthivel K 	pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
892f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
893f5860992SSakthivel K 	pm8001_mw32(address, MAIN_INT_REASSERTION_DELAY,
894f5860992SSakthivel K 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.interrupt_reassertion_delay);
8958414cd80SViswas G 
8968414cd80SViswas G 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &= 0xffff0000;
8978414cd80SViswas G 	pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
8988414cd80SViswas G 							PORT_RECOVERY_TIMEOUT;
89961daffdeSViswas G 	if (pm8001_ha->chip_id == chip_8006) {
90061daffdeSViswas G 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &=
90161daffdeSViswas G 					0x0000ffff;
90261daffdeSViswas G 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
903196ba662SDeepak Ukey 					CHIP_8006_PORT_RECOVERY_TIMEOUT;
90461daffdeSViswas G 	}
9058414cd80SViswas G 	pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
9068414cd80SViswas G 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
907f5860992SSakthivel K }
908f5860992SSakthivel K 
909f5860992SSakthivel K /**
910f5860992SSakthivel K  * update_inbnd_queue_table - update the inbound queue table to the HBA.
911f5860992SSakthivel K  * @pm8001_ha: our hba card information
9126ad4a517SLee Jones  * @number: entry in the queue
913f5860992SSakthivel K  */
update_inbnd_queue_table(struct pm8001_hba_info * pm8001_ha,int number)914f5860992SSakthivel K static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
915f5860992SSakthivel K 					 int number)
916f5860992SSakthivel K {
917f5860992SSakthivel K 	void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
918f5860992SSakthivel K 	u16 offset = number * 0x20;
919f5860992SSakthivel K 	pm8001_mw32(address, offset + IB_PROPERITY_OFFSET,
920f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
921f5860992SSakthivel K 	pm8001_mw32(address, offset + IB_BASE_ADDR_HI_OFFSET,
922f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
923f5860992SSakthivel K 	pm8001_mw32(address, offset + IB_BASE_ADDR_LO_OFFSET,
924f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
925f5860992SSakthivel K 	pm8001_mw32(address, offset + IB_CI_BASE_ADDR_HI_OFFSET,
926f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
927f5860992SSakthivel K 	pm8001_mw32(address, offset + IB_CI_BASE_ADDR_LO_OFFSET,
928f5860992SSakthivel K 		pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
9297370672dSpeter chang 
9301b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
9317370672dSpeter chang 		   "IQ %d: Element pri size 0x%x\n",
9327370672dSpeter chang 		   number,
9331b5d2793SJoe Perches 		   pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
9347370672dSpeter chang 
9351b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
9367370672dSpeter chang 		   "IQ upr base addr 0x%x IQ lwr base addr 0x%x\n",
9377370672dSpeter chang 		   pm8001_ha->inbnd_q_tbl[number].upper_base_addr,
9381b5d2793SJoe Perches 		   pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
9397370672dSpeter chang 
9401b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
9417370672dSpeter chang 		   "CI upper base addr 0x%x CI lower base addr 0x%x\n",
9427370672dSpeter chang 		   pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr,
9431b5d2793SJoe Perches 		   pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
944f5860992SSakthivel K }
945f5860992SSakthivel K 
946f5860992SSakthivel K /**
947f5860992SSakthivel K  * update_outbnd_queue_table - update the outbound queue table to the HBA.
948f5860992SSakthivel K  * @pm8001_ha: our hba card information
9496ad4a517SLee Jones  * @number: entry in the queue
950f5860992SSakthivel K  */
update_outbnd_queue_table(struct pm8001_hba_info * pm8001_ha,int number)951f5860992SSakthivel K static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
952f5860992SSakthivel K 						 int number)
953f5860992SSakthivel K {
954f5860992SSakthivel K 	void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
955f5860992SSakthivel K 	u16 offset = number * 0x24;
956f5860992SSakthivel K 	pm8001_mw32(address, offset + OB_PROPERITY_OFFSET,
957f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
958f5860992SSakthivel K 	pm8001_mw32(address, offset + OB_BASE_ADDR_HI_OFFSET,
959f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
960f5860992SSakthivel K 	pm8001_mw32(address, offset + OB_BASE_ADDR_LO_OFFSET,
961f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
962f5860992SSakthivel K 	pm8001_mw32(address, offset + OB_PI_BASE_ADDR_HI_OFFSET,
963f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
964f5860992SSakthivel K 	pm8001_mw32(address, offset + OB_PI_BASE_ADDR_LO_OFFSET,
965f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
966f5860992SSakthivel K 	pm8001_mw32(address, offset + OB_INTERRUPT_COALES_OFFSET,
967f5860992SSakthivel K 		pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
9687370672dSpeter chang 
9691b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
9707370672dSpeter chang 		   "OQ %d: Element pri size 0x%x\n",
9717370672dSpeter chang 		   number,
9721b5d2793SJoe Perches 		   pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
9737370672dSpeter chang 
9741b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
9757370672dSpeter chang 		   "OQ upr base addr 0x%x OQ lwr base addr 0x%x\n",
9767370672dSpeter chang 		   pm8001_ha->outbnd_q_tbl[number].upper_base_addr,
9771b5d2793SJoe Perches 		   pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
9787370672dSpeter chang 
9791b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
9807370672dSpeter chang 		   "PI upper base addr 0x%x PI lower base addr 0x%x\n",
9817370672dSpeter chang 		   pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr,
9821b5d2793SJoe Perches 		   pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
983f5860992SSakthivel K }
984f5860992SSakthivel K 
985f5860992SSakthivel K /**
986f5860992SSakthivel K  * mpi_init_check - check firmware initialization status.
987f5860992SSakthivel K  * @pm8001_ha: our hba card information
988f5860992SSakthivel K  */
mpi_init_check(struct pm8001_hba_info * pm8001_ha)989f5860992SSakthivel K static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
990f5860992SSakthivel K {
991f5860992SSakthivel K 	u32 max_wait_count;
992f5860992SSakthivel K 	u32 value;
993f5860992SSakthivel K 	u32 gst_len_mpistate;
994f5860992SSakthivel K 
995f5860992SSakthivel K 	/* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
996f5860992SSakthivel K 	table is updated */
997f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_UPDATE);
998f5860992SSakthivel K 	/* wait until Inbound DoorBell Clear Register toggled */
999a9a923e5SAnand Kumar Santhanam 	if (IS_SPCV_12G(pm8001_ha->pdev)) {
1000e90e2362Sianyar 		max_wait_count = SPCV_DOORBELL_CLEAR_TIMEOUT;
1001a9a923e5SAnand Kumar Santhanam 	} else {
1002e90e2362Sianyar 		max_wait_count = SPC_DOORBELL_CLEAR_TIMEOUT;
1003a9a923e5SAnand Kumar Santhanam 	}
1004f5860992SSakthivel K 	do {
1005d71023afSakshatzen 		msleep(FW_READY_INTERVAL);
1006f5860992SSakthivel K 		value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1007f5860992SSakthivel K 		value &= SPCv_MSGU_CFG_TABLE_UPDATE;
1008f5860992SSakthivel K 	} while ((value != 0) && (--max_wait_count));
1009f5860992SSakthivel K 
101005c6c029SViswas G 	if (!max_wait_count) {
101105c6c029SViswas G 		/* additional check */
10121b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
10131b5d2793SJoe Perches 			   "Inb doorbell clear not toggled[value:%x]\n",
10141b5d2793SJoe Perches 			   value);
101505c6c029SViswas G 		return -EBUSY;
101605c6c029SViswas G 	}
1017f5860992SSakthivel K 	/* check the MPI-State for initialization up to 100ms*/
1018d71023afSakshatzen 	max_wait_count = 5;/* 100 msec */
1019f5860992SSakthivel K 	do {
1020d71023afSakshatzen 		msleep(FW_READY_INTERVAL);
1021f5860992SSakthivel K 		gst_len_mpistate =
1022f5860992SSakthivel K 			pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1023f5860992SSakthivel K 					GST_GSTLEN_MPIS_OFFSET);
1024f5860992SSakthivel K 	} while ((GST_MPI_STATE_INIT !=
1025f5860992SSakthivel K 		(gst_len_mpistate & GST_MPI_STATE_MASK)) && (--max_wait_count));
1026f5860992SSakthivel K 	if (!max_wait_count)
102705c6c029SViswas G 		return -EBUSY;
1028f5860992SSakthivel K 
1029f5860992SSakthivel K 	/* check MPI Initialization error */
1030f5860992SSakthivel K 	gst_len_mpistate = gst_len_mpistate >> 16;
1031f5860992SSakthivel K 	if (0x0000 != gst_len_mpistate)
103205c6c029SViswas G 		return -EBUSY;
1033f5860992SSakthivel K 
1034bcd8a452SAjish Koshy 	/*
1035bcd8a452SAjish Koshy 	 *  As per controller datasheet, after successful MPI
1036bcd8a452SAjish Koshy 	 *  initialization minimum 500ms delay is required before
1037bcd8a452SAjish Koshy 	 *  issuing commands.
1038bcd8a452SAjish Koshy 	 */
1039bcd8a452SAjish Koshy 	msleep(500);
1040bcd8a452SAjish Koshy 
1041f5860992SSakthivel K 	return 0;
1042f5860992SSakthivel K }
1043f5860992SSakthivel K 
1044f5860992SSakthivel K /**
1045f5860992SSakthivel K  * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
104648cd6b38Sakshatzen  * This function sleeps hence it must not be used in atomic context.
1047f5860992SSakthivel K  * @pm8001_ha: our hba card information
1048f5860992SSakthivel K  */
check_fw_ready(struct pm8001_hba_info * pm8001_ha)1049f5860992SSakthivel K static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
1050f5860992SSakthivel K {
1051f5860992SSakthivel K 	u32 value;
1052f5860992SSakthivel K 	u32 max_wait_count;
1053f5860992SSakthivel K 	u32 max_wait_time;
10546b2f2d05SBhavesh Jashnani 	u32 expected_mask;
1055f5860992SSakthivel K 	int ret = 0;
1056f5860992SSakthivel K 
1057f5860992SSakthivel K 	/* reset / PCIe ready */
105848cd6b38Sakshatzen 	max_wait_time = max_wait_count = 5;	/* 100 milli sec */
1059f5860992SSakthivel K 	do {
106048cd6b38Sakshatzen 		msleep(FW_READY_INTERVAL);
1061f5860992SSakthivel K 		value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1062f5860992SSakthivel K 	} while ((value == 0xFFFFFFFF) && (--max_wait_count));
1063f5860992SSakthivel K 
10646b2f2d05SBhavesh Jashnani 	/* check ila, RAAE and iops status */
1065f5860992SSakthivel K 	if ((pm8001_ha->chip_id != chip_8008) &&
1066f5860992SSakthivel K 			(pm8001_ha->chip_id != chip_8009)) {
10676b2f2d05SBhavesh Jashnani 		max_wait_time = max_wait_count = 180;   /* 3600 milli sec */
10686b2f2d05SBhavesh Jashnani 		expected_mask = SCRATCH_PAD_ILA_READY |
10696b2f2d05SBhavesh Jashnani 			SCRATCH_PAD_RAAE_READY |
10706b2f2d05SBhavesh Jashnani 			SCRATCH_PAD_IOP0_READY |
10716b2f2d05SBhavesh Jashnani 			SCRATCH_PAD_IOP1_READY;
10726b2f2d05SBhavesh Jashnani 	} else {
10736b2f2d05SBhavesh Jashnani 		max_wait_time = max_wait_count = 170;   /* 3400 milli sec */
10746b2f2d05SBhavesh Jashnani 		expected_mask = SCRATCH_PAD_ILA_READY |
10756b2f2d05SBhavesh Jashnani 			SCRATCH_PAD_RAAE_READY |
10766b2f2d05SBhavesh Jashnani 			SCRATCH_PAD_IOP0_READY;
10776b2f2d05SBhavesh Jashnani 	}
1078f5860992SSakthivel K 	do {
107948cd6b38Sakshatzen 		msleep(FW_READY_INTERVAL);
1080f5860992SSakthivel K 		value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
10816b2f2d05SBhavesh Jashnani 	} while (((value & expected_mask) !=
10826b2f2d05SBhavesh Jashnani 				 expected_mask) && (--max_wait_count));
10836b2f2d05SBhavesh Jashnani 	if (!max_wait_count) {
10846b2f2d05SBhavesh Jashnani 		pm8001_dbg(pm8001_ha, INIT,
10856b2f2d05SBhavesh Jashnani 		"At least one FW component failed to load within %d millisec: Scratchpad1: 0x%x\n",
10866b2f2d05SBhavesh Jashnani 			max_wait_time * FW_READY_INTERVAL, value);
1087f5860992SSakthivel K 		ret = -1;
10886b2f2d05SBhavesh Jashnani 	} else {
10891b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
10906b2f2d05SBhavesh Jashnani 			"All FW components ready by %d ms\n",
10916b2f2d05SBhavesh Jashnani 			(max_wait_time - max_wait_count) * FW_READY_INTERVAL);
1092f5860992SSakthivel K 	}
1093f5860992SSakthivel K 	return ret;
1094f5860992SSakthivel K }
1095f5860992SSakthivel K 
init_pci_device_addresses(struct pm8001_hba_info * pm8001_ha)109695652f98Sakshatzen static int init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
1097f5860992SSakthivel K {
1098f5860992SSakthivel K 	void __iomem *base_addr;
1099f5860992SSakthivel K 	u32	value;
1100f5860992SSakthivel K 	u32	offset;
1101f5860992SSakthivel K 	u32	pcibar;
1102f5860992SSakthivel K 	u32	pcilogic;
1103f5860992SSakthivel K 
1104f5860992SSakthivel K 	value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
110595652f98Sakshatzen 
1106bb6beabfSRandy Dunlap 	/*
110795652f98Sakshatzen 	 * lower 26 bits of SCRATCHPAD0 register describes offset within the
110895652f98Sakshatzen 	 * PCIe BAR where the MPI configuration table is present
110995652f98Sakshatzen 	 */
1110f5860992SSakthivel K 	offset = value & 0x03FFFFFF; /* scratch pad 0 TBL address */
1111f5860992SSakthivel K 
11121b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV, "Scratchpad 0 Offset: 0x%x value 0x%x\n",
11131b5d2793SJoe Perches 		   offset, value);
1114bb6beabfSRandy Dunlap 	/*
111595652f98Sakshatzen 	 * Upper 6 bits describe the offset within PCI config space where BAR
111695652f98Sakshatzen 	 * is located.
111795652f98Sakshatzen 	 */
1118f5860992SSakthivel K 	pcilogic = (value & 0xFC000000) >> 26;
1119f5860992SSakthivel K 	pcibar = get_pci_bar_index(pcilogic);
11201b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar);
112195652f98Sakshatzen 
1122bb6beabfSRandy Dunlap 	/*
112395652f98Sakshatzen 	 * Make sure the offset falls inside the ioremapped PCI BAR
112495652f98Sakshatzen 	 */
112595652f98Sakshatzen 	if (offset > pm8001_ha->io_mem[pcibar].memsize) {
112695652f98Sakshatzen 		pm8001_dbg(pm8001_ha, FAIL,
112795652f98Sakshatzen 			"Main cfg tbl offset outside %u > %u\n",
112895652f98Sakshatzen 				offset, pm8001_ha->io_mem[pcibar].memsize);
112995652f98Sakshatzen 		return -EBUSY;
113095652f98Sakshatzen 	}
1131f5860992SSakthivel K 	pm8001_ha->main_cfg_tbl_addr = base_addr =
1132f5860992SSakthivel K 		pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
113395652f98Sakshatzen 
1134bb6beabfSRandy Dunlap 	/*
113595652f98Sakshatzen 	 * Validate main configuration table address: first DWord should read
113695652f98Sakshatzen 	 * "PMCS"
113795652f98Sakshatzen 	 */
113895652f98Sakshatzen 	value = pm8001_mr32(pm8001_ha->main_cfg_tbl_addr, 0);
113995652f98Sakshatzen 	if (memcmp(&value, "PMCS", 4) != 0) {
114095652f98Sakshatzen 		pm8001_dbg(pm8001_ha, FAIL,
114195652f98Sakshatzen 			"BAD main config signature 0x%x\n",
114295652f98Sakshatzen 				value);
114395652f98Sakshatzen 		return -EBUSY;
114495652f98Sakshatzen 	}
114595652f98Sakshatzen 	pm8001_dbg(pm8001_ha, INIT,
114695652f98Sakshatzen 			"VALID main config signature 0x%x\n", value);
1147f5860992SSakthivel K 	pm8001_ha->general_stat_tbl_addr =
1148f5860992SSakthivel K 		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x18) &
1149f5860992SSakthivel K 					0xFFFFFF);
1150f5860992SSakthivel K 	pm8001_ha->inbnd_q_tbl_addr =
1151f5860992SSakthivel K 		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C) &
1152f5860992SSakthivel K 					0xFFFFFF);
1153f5860992SSakthivel K 	pm8001_ha->outbnd_q_tbl_addr =
1154f5860992SSakthivel K 		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x20) &
1155f5860992SSakthivel K 					0xFFFFFF);
1156f5860992SSakthivel K 	pm8001_ha->ivt_tbl_addr =
1157f5860992SSakthivel K 		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C) &
1158f5860992SSakthivel K 					0xFFFFFF);
1159f5860992SSakthivel K 	pm8001_ha->pspa_q_tbl_addr =
1160f5860992SSakthivel K 		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x90) &
1161f5860992SSakthivel K 					0xFFFFFF);
1162d078b511SAnand Kumar Santhanam 	pm8001_ha->fatal_tbl_addr =
1163d078b511SAnand Kumar Santhanam 		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0xA0) &
1164d078b511SAnand Kumar Santhanam 					0xFFFFFF);
1165f5860992SSakthivel K 
11661b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "GST OFFSET 0x%x\n",
11671b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, pcibar, offset + 0x18));
11681b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "INBND OFFSET 0x%x\n",
11691b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C));
11701b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "OBND OFFSET 0x%x\n",
11711b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, pcibar, offset + 0x20));
11721b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "IVT OFFSET 0x%x\n",
11731b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C));
11741b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "PSPA OFFSET 0x%x\n",
11751b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, pcibar, offset + 0x90));
11761b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "addr - main cfg %p general status %p\n",
1177f5860992SSakthivel K 		   pm8001_ha->main_cfg_tbl_addr,
11781b5d2793SJoe Perches 		   pm8001_ha->general_stat_tbl_addr);
11791b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "addr - inbnd %p obnd %p\n",
1180f5860992SSakthivel K 		   pm8001_ha->inbnd_q_tbl_addr,
11811b5d2793SJoe Perches 		   pm8001_ha->outbnd_q_tbl_addr);
11821b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "addr - pspa %p ivt %p\n",
1183f5860992SSakthivel K 		   pm8001_ha->pspa_q_tbl_addr,
11841b5d2793SJoe Perches 		   pm8001_ha->ivt_tbl_addr);
118595652f98Sakshatzen 	return 0;
1186f5860992SSakthivel K }
1187f5860992SSakthivel K 
1188f5860992SSakthivel K /**
1189f5860992SSakthivel K  * pm80xx_set_thermal_config - support the thermal configuration
1190f5860992SSakthivel K  * @pm8001_ha: our hba card information.
1191f5860992SSakthivel K  */
1192a6cb3d01SSakthivel K int
pm80xx_set_thermal_config(struct pm8001_hba_info * pm8001_ha)1193f5860992SSakthivel K pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha)
1194f5860992SSakthivel K {
1195f5860992SSakthivel K 	struct set_ctrl_cfg_req payload;
1196f5860992SSakthivel K 	int rc;
1197f5860992SSakthivel K 	u32 tag;
1198f5860992SSakthivel K 	u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
1199842784e0SViswas G 	u32 page_code;
1200f5860992SSakthivel K 
1201f5860992SSakthivel K 	memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
1202f5860992SSakthivel K 	rc = pm8001_tag_alloc(pm8001_ha, &tag);
1203f5860992SSakthivel K 	if (rc)
1204f17c599aSDamien Le Moal 		return rc;
1205f5860992SSakthivel K 
1206f5860992SSakthivel K 	payload.tag = cpu_to_le32(tag);
1207842784e0SViswas G 
1208842784e0SViswas G 	if (IS_SPCV_12G(pm8001_ha->pdev))
1209842784e0SViswas G 		page_code = THERMAL_PAGE_CODE_7H;
1210842784e0SViswas G 	else
1211842784e0SViswas G 		page_code = THERMAL_PAGE_CODE_8H;
1212842784e0SViswas G 
1213bb225b12SDamien Le Moal 	payload.cfg_pg[0] =
1214bb225b12SDamien Le Moal 		cpu_to_le32((THERMAL_LOG_ENABLE << 9) |
1215bb225b12SDamien Le Moal 			    (THERMAL_ENABLE << 8) | page_code);
1216bb225b12SDamien Le Moal 	payload.cfg_pg[1] =
1217bb225b12SDamien Le Moal 		cpu_to_le32((LTEMPHIL << 24) | (RTEMPHIL << 8));
1218f5860992SSakthivel K 
12191b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
12207370672dSpeter chang 		   "Setting up thermal config. cfg_pg 0 0x%x cfg_pg 1 0x%x\n",
12211b5d2793SJoe Perches 		   payload.cfg_pg[0], payload.cfg_pg[1]);
12227370672dSpeter chang 
1223f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
122491a43fa6Speter chang 			sizeof(payload), 0);
12255533abcaSTomas Henzl 	if (rc)
12265533abcaSTomas Henzl 		pm8001_tag_free(pm8001_ha, tag);
1227f5860992SSakthivel K 	return rc;
1228f5860992SSakthivel K 
1229f5860992SSakthivel K }
1230f5860992SSakthivel K 
1231f5860992SSakthivel K /**
1232a6cb3d01SSakthivel K * pm80xx_set_sas_protocol_timer_config - support the SAS Protocol
1233a6cb3d01SSakthivel K * Timer configuration page
1234a6cb3d01SSakthivel K * @pm8001_ha: our hba card information.
1235a6cb3d01SSakthivel K */
1236a6cb3d01SSakthivel K static int
pm80xx_set_sas_protocol_timer_config(struct pm8001_hba_info * pm8001_ha)1237a6cb3d01SSakthivel K pm80xx_set_sas_protocol_timer_config(struct pm8001_hba_info *pm8001_ha)
1238a6cb3d01SSakthivel K {
1239a6cb3d01SSakthivel K 	struct set_ctrl_cfg_req payload;
1240a6cb3d01SSakthivel K 	SASProtocolTimerConfig_t SASConfigPage;
1241a6cb3d01SSakthivel K 	int rc;
1242a6cb3d01SSakthivel K 	u32 tag;
1243a6cb3d01SSakthivel K 	u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
1244a6cb3d01SSakthivel K 
1245a6cb3d01SSakthivel K 	memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
1246a6cb3d01SSakthivel K 	memset(&SASConfigPage, 0, sizeof(SASProtocolTimerConfig_t));
1247a6cb3d01SSakthivel K 
1248a6cb3d01SSakthivel K 	rc = pm8001_tag_alloc(pm8001_ha, &tag);
1249a6cb3d01SSakthivel K 	if (rc)
1250f17c599aSDamien Le Moal 		return rc;
1251a6cb3d01SSakthivel K 
1252a6cb3d01SSakthivel K 	payload.tag = cpu_to_le32(tag);
1253a6cb3d01SSakthivel K 
1254ca374f5dSDamien Le Moal 	SASConfigPage.pageCode = cpu_to_le32(SAS_PROTOCOL_TIMER_CONFIG_PAGE);
1255ca374f5dSDamien Le Moal 	SASConfigPage.MST_MSI = cpu_to_le32(3 << 15);
1256ca374f5dSDamien Le Moal 	SASConfigPage.STP_SSP_MCT_TMO =
1257ca374f5dSDamien Le Moal 		cpu_to_le32((STP_MCT_TMO << 16) | SSP_MCT_TMO);
1258ca374f5dSDamien Le Moal 	SASConfigPage.STP_FRM_TMO =
1259ca374f5dSDamien Le Moal 		cpu_to_le32((SAS_MAX_OPEN_TIME << 24) |
1260ca374f5dSDamien Le Moal 			    (SMP_MAX_CONN_TIMER << 16) | STP_FRM_TIMER);
1261ca374f5dSDamien Le Moal 	SASConfigPage.STP_IDLE_TMO = cpu_to_le32(STP_IDLE_TIME);
1262a6cb3d01SSakthivel K 
1263ca374f5dSDamien Le Moal 	SASConfigPage.OPNRJT_RTRY_INTVL =
1264ca374f5dSDamien Le Moal 		cpu_to_le32((SAS_MFD << 16) | SAS_OPNRJT_RTRY_INTVL);
1265ca374f5dSDamien Le Moal 	SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO =
1266ca374f5dSDamien Le Moal 		cpu_to_le32((SAS_DOPNRJT_RTRY_TMO << 16) | SAS_COPNRJT_RTRY_TMO);
1267ca374f5dSDamien Le Moal 	SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR =
1268ca374f5dSDamien Le Moal 		cpu_to_le32((SAS_DOPNRJT_RTRY_THR << 16) | SAS_COPNRJT_RTRY_THR);
1269ca374f5dSDamien Le Moal 	SASConfigPage.MAX_AIP = cpu_to_le32(SAS_MAX_AIP);
1270a6cb3d01SSakthivel K 
12711b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.pageCode 0x%08x\n",
1272ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.pageCode));
12731b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.MST_MSI  0x%08x\n",
1274ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.MST_MSI));
12751b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_SSP_MCT_TMO  0x%08x\n",
1276ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.STP_SSP_MCT_TMO));
12771b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_FRM_TMO  0x%08x\n",
1278ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.STP_FRM_TMO));
12791b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.STP_IDLE_TMO  0x%08x\n",
1280ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.STP_IDLE_TMO));
12811b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.OPNRJT_RTRY_INTVL  0x%08x\n",
1282ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.OPNRJT_RTRY_INTVL));
12831b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO  0x%08x\n",
1284ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO));
12851b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR  0x%08x\n",
1286ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR));
12871b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SASConfigPage.MAX_AIP  0x%08x\n",
1288ca374f5dSDamien Le Moal 		   le32_to_cpu(SASConfigPage.MAX_AIP));
1289a6cb3d01SSakthivel K 
1290a6cb3d01SSakthivel K 	memcpy(&payload.cfg_pg, &SASConfigPage,
1291a6cb3d01SSakthivel K 			 sizeof(SASProtocolTimerConfig_t));
1292a6cb3d01SSakthivel K 
1293f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
129491a43fa6Speter chang 			sizeof(payload), 0);
12955533abcaSTomas Henzl 	if (rc)
12965533abcaSTomas Henzl 		pm8001_tag_free(pm8001_ha, tag);
1297a6cb3d01SSakthivel K 
1298a6cb3d01SSakthivel K 	return rc;
1299a6cb3d01SSakthivel K }
1300a6cb3d01SSakthivel K 
1301a6cb3d01SSakthivel K /**
1302f5860992SSakthivel K  * pm80xx_get_encrypt_info - Check for encryption
1303f5860992SSakthivel K  * @pm8001_ha: our hba card information.
1304f5860992SSakthivel K  */
1305f5860992SSakthivel K static int
pm80xx_get_encrypt_info(struct pm8001_hba_info * pm8001_ha)1306f5860992SSakthivel K pm80xx_get_encrypt_info(struct pm8001_hba_info *pm8001_ha)
1307f5860992SSakthivel K {
1308f5860992SSakthivel K 	u32 scratch3_value;
1309da225498SRickard Strandqvist 	int ret = -1;
1310f5860992SSakthivel K 
1311f5860992SSakthivel K 	/* Read encryption status from SCRATCH PAD 3 */
1312f5860992SSakthivel K 	scratch3_value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
1313f5860992SSakthivel K 
1314f5860992SSakthivel K 	if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1315f5860992SSakthivel K 					SCRATCH_PAD3_ENC_READY) {
1316f5860992SSakthivel K 		if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1317f5860992SSakthivel K 			pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1318f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1319f5860992SSakthivel K 						SCRATCH_PAD3_SMF_ENABLED)
1320f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1321f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1322f5860992SSakthivel K 						SCRATCH_PAD3_SMA_ENABLED)
1323f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1324f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1325f5860992SSakthivel K 						SCRATCH_PAD3_SMB_ENABLED)
1326f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1327f5860992SSakthivel K 		pm8001_ha->encrypt_info.status = 0;
13281b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT,
13291b5d2793SJoe Perches 			   "Encryption: SCRATCH_PAD3_ENC_READY 0x%08X.Cipher mode 0x%x Sec mode 0x%x status 0x%x\n",
13301b5d2793SJoe Perches 			   scratch3_value,
13311b5d2793SJoe Perches 			   pm8001_ha->encrypt_info.cipher_mode,
1332f5860992SSakthivel K 			   pm8001_ha->encrypt_info.sec_mode,
13331b5d2793SJoe Perches 			   pm8001_ha->encrypt_info.status);
1334f5860992SSakthivel K 		ret = 0;
1335f5860992SSakthivel K 	} else if ((scratch3_value & SCRATCH_PAD3_ENC_READY) ==
1336f5860992SSakthivel K 					SCRATCH_PAD3_ENC_DISABLED) {
13371b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT,
1338f5860992SSakthivel K 			   "Encryption: SCRATCH_PAD3_ENC_DISABLED 0x%08X\n",
13391b5d2793SJoe Perches 			   scratch3_value);
1340f5860992SSakthivel K 		pm8001_ha->encrypt_info.status = 0xFFFFFFFF;
1341f5860992SSakthivel K 		pm8001_ha->encrypt_info.cipher_mode = 0;
1342f5860992SSakthivel K 		pm8001_ha->encrypt_info.sec_mode = 0;
1343da225498SRickard Strandqvist 		ret = 0;
1344f5860992SSakthivel K 	} else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1345f5860992SSakthivel K 				SCRATCH_PAD3_ENC_DIS_ERR) {
1346f5860992SSakthivel K 		pm8001_ha->encrypt_info.status =
1347f5860992SSakthivel K 			(scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1348f5860992SSakthivel K 		if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1349f5860992SSakthivel K 			pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1350f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1351f5860992SSakthivel K 					SCRATCH_PAD3_SMF_ENABLED)
1352f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1353f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1354f5860992SSakthivel K 					SCRATCH_PAD3_SMA_ENABLED)
1355f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1356f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1357f5860992SSakthivel K 					SCRATCH_PAD3_SMB_ENABLED)
1358f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
13591b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT,
13601b5d2793SJoe Perches 			   "Encryption: SCRATCH_PAD3_DIS_ERR 0x%08X.Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
13611b5d2793SJoe Perches 			   scratch3_value,
13621b5d2793SJoe Perches 			   pm8001_ha->encrypt_info.cipher_mode,
1363f5860992SSakthivel K 			   pm8001_ha->encrypt_info.sec_mode,
13641b5d2793SJoe Perches 			   pm8001_ha->encrypt_info.status);
1365f5860992SSakthivel K 	} else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1366f5860992SSakthivel K 				 SCRATCH_PAD3_ENC_ENA_ERR) {
1367f5860992SSakthivel K 
1368f5860992SSakthivel K 		pm8001_ha->encrypt_info.status =
1369f5860992SSakthivel K 			(scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1370f5860992SSakthivel K 		if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1371f5860992SSakthivel K 			pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1372f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1373f5860992SSakthivel K 					SCRATCH_PAD3_SMF_ENABLED)
1374f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1375f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1376f5860992SSakthivel K 					SCRATCH_PAD3_SMA_ENABLED)
1377f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1378f5860992SSakthivel K 		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1379f5860992SSakthivel K 					SCRATCH_PAD3_SMB_ENABLED)
1380f5860992SSakthivel K 			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1381f5860992SSakthivel K 
13821b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT,
13831b5d2793SJoe Perches 			   "Encryption: SCRATCH_PAD3_ENA_ERR 0x%08X.Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
13841b5d2793SJoe Perches 			   scratch3_value,
13851b5d2793SJoe Perches 			   pm8001_ha->encrypt_info.cipher_mode,
1386f5860992SSakthivel K 			   pm8001_ha->encrypt_info.sec_mode,
13871b5d2793SJoe Perches 			   pm8001_ha->encrypt_info.status);
1388f5860992SSakthivel K 	}
1389f5860992SSakthivel K 	return ret;
1390f5860992SSakthivel K }
1391f5860992SSakthivel K 
1392f5860992SSakthivel K /**
1393bb6beabfSRandy Dunlap  * pm80xx_encrypt_update - update flash with encryption information
1394f5860992SSakthivel K  * @pm8001_ha: our hba card information.
1395f5860992SSakthivel K  */
pm80xx_encrypt_update(struct pm8001_hba_info * pm8001_ha)1396f5860992SSakthivel K static int pm80xx_encrypt_update(struct pm8001_hba_info *pm8001_ha)
1397f5860992SSakthivel K {
1398f5860992SSakthivel K 	struct kek_mgmt_req payload;
1399f5860992SSakthivel K 	int rc;
1400f5860992SSakthivel K 	u32 tag;
1401f5860992SSakthivel K 	u32 opc = OPC_INB_KEK_MANAGEMENT;
1402f5860992SSakthivel K 
1403f5860992SSakthivel K 	memset(&payload, 0, sizeof(struct kek_mgmt_req));
1404f5860992SSakthivel K 	rc = pm8001_tag_alloc(pm8001_ha, &tag);
1405f5860992SSakthivel K 	if (rc)
1406f17c599aSDamien Le Moal 		return rc;
1407f5860992SSakthivel K 
1408f5860992SSakthivel K 	payload.tag = cpu_to_le32(tag);
1409f5860992SSakthivel K 	/* Currently only one key is used. New KEK index is 1.
1410f5860992SSakthivel K 	 * Current KEK index is 1. Store KEK to NVRAM is 1.
1411f5860992SSakthivel K 	 */
1412f8b12dfbSDamien Le Moal 	payload.new_curidx_ksop =
1413f8b12dfbSDamien Le Moal 		cpu_to_le32(((1 << 24) | (1 << 16) | (1 << 8) |
1414f8b12dfbSDamien Le Moal 			     KEK_MGMT_SUBOP_KEYCARDUPDATE));
1415f5860992SSakthivel K 
14161b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
14177370672dSpeter chang 		   "Saving Encryption info to flash. payload 0x%x\n",
1418f8b12dfbSDamien Le Moal 		   le32_to_cpu(payload.new_curidx_ksop));
14197370672dSpeter chang 
1420f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
142191a43fa6Speter chang 			sizeof(payload), 0);
14225533abcaSTomas Henzl 	if (rc)
14235533abcaSTomas Henzl 		pm8001_tag_free(pm8001_ha, tag);
1424f5860992SSakthivel K 
1425f5860992SSakthivel K 	return rc;
1426f5860992SSakthivel K }
1427f5860992SSakthivel K 
1428f5860992SSakthivel K /**
1429bb6beabfSRandy Dunlap  * pm80xx_chip_init - the main init function that initializes whole PM8001 chip.
1430f5860992SSakthivel K  * @pm8001_ha: our hba card information
1431f5860992SSakthivel K  */
pm80xx_chip_init(struct pm8001_hba_info * pm8001_ha)1432f5860992SSakthivel K static int pm80xx_chip_init(struct pm8001_hba_info *pm8001_ha)
1433f5860992SSakthivel K {
1434f5860992SSakthivel K 	int ret;
1435f5860992SSakthivel K 	u8 i = 0;
1436f5860992SSakthivel K 
1437f5860992SSakthivel K 	/* check the firmware status */
1438f5860992SSakthivel K 	if (-1 == check_fw_ready(pm8001_ha)) {
14391b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
1440f5860992SSakthivel K 		return -EBUSY;
1441f5860992SSakthivel K 	}
1442f5860992SSakthivel K 
144372349b62SDeepak Ukey 	/* Initialize the controller fatal error flag */
144472349b62SDeepak Ukey 	pm8001_ha->controller_fatal_error = false;
144572349b62SDeepak Ukey 
1446f5860992SSakthivel K 	/* Initialize pci space address eg: mpi offset */
144795652f98Sakshatzen 	ret = init_pci_device_addresses(pm8001_ha);
144895652f98Sakshatzen 	if (ret) {
144995652f98Sakshatzen 		pm8001_dbg(pm8001_ha, FAIL,
145095652f98Sakshatzen 			"Failed to init pci addresses");
145195652f98Sakshatzen 		return ret;
145295652f98Sakshatzen 	}
1453f5860992SSakthivel K 	init_default_table_values(pm8001_ha);
1454f5860992SSakthivel K 	read_main_config_table(pm8001_ha);
1455f5860992SSakthivel K 	read_general_status_table(pm8001_ha);
1456f5860992SSakthivel K 	read_inbnd_queue_table(pm8001_ha);
1457f5860992SSakthivel K 	read_outbnd_queue_table(pm8001_ha);
1458f5860992SSakthivel K 	read_phy_attr_table(pm8001_ha);
1459f5860992SSakthivel K 
1460f5860992SSakthivel K 	/* update main config table ,inbound table and outbound table */
1461f5860992SSakthivel K 	update_main_config_table(pm8001_ha);
146205c6c029SViswas G 	for (i = 0; i < pm8001_ha->max_q_num; i++) {
1463f5860992SSakthivel K 		update_inbnd_queue_table(pm8001_ha, i);
1464f5860992SSakthivel K 		update_outbnd_queue_table(pm8001_ha, i);
146505c6c029SViswas G 	}
1466f5860992SSakthivel K 	/* notify firmware update finished and check initialization status */
1467f5860992SSakthivel K 	if (0 == mpi_init_check(pm8001_ha)) {
14681b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n");
1469f5860992SSakthivel K 	} else
1470f5860992SSakthivel K 		return -EBUSY;
1471f5860992SSakthivel K 
147298132d84SJohn Garry 	return 0;
147398132d84SJohn Garry }
147498132d84SJohn Garry 
pm80xx_chip_post_init(struct pm8001_hba_info * pm8001_ha)147598132d84SJohn Garry static void pm80xx_chip_post_init(struct pm8001_hba_info *pm8001_ha)
147698132d84SJohn Garry {
1477a6cb3d01SSakthivel K 	/* send SAS protocol timer configuration page to FW */
147898132d84SJohn Garry 	pm80xx_set_sas_protocol_timer_config(pm8001_ha);
1479f5860992SSakthivel K 
1480f5860992SSakthivel K 	/* Check for encryption */
1481f5860992SSakthivel K 	if (pm8001_ha->chip->encrypt) {
148298132d84SJohn Garry 		int ret;
148398132d84SJohn Garry 
14841b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT, "Checking for encryption\n");
1485f5860992SSakthivel K 		ret = pm80xx_get_encrypt_info(pm8001_ha);
1486f5860992SSakthivel K 		if (ret == -1) {
14871b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, INIT, "Encryption error !!\n");
1488f5860992SSakthivel K 			if (pm8001_ha->encrypt_info.status == 0x81) {
14891b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, INIT,
14901b5d2793SJoe Perches 					   "Encryption enabled with error.Saving encryption key to flash\n");
1491f5860992SSakthivel K 				pm80xx_encrypt_update(pm8001_ha);
1492f5860992SSakthivel K 			}
1493f5860992SSakthivel K 		}
1494f5860992SSakthivel K 	}
1495f5860992SSakthivel K }
1496f5860992SSakthivel K 
mpi_uninit_check(struct pm8001_hba_info * pm8001_ha)1497f5860992SSakthivel K static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
1498f5860992SSakthivel K {
1499f5860992SSakthivel K 	u32 max_wait_count;
1500f5860992SSakthivel K 	u32 value;
1501f5860992SSakthivel K 	u32 gst_len_mpistate;
150295652f98Sakshatzen 	int ret;
150395652f98Sakshatzen 
150495652f98Sakshatzen 	ret = init_pci_device_addresses(pm8001_ha);
150595652f98Sakshatzen 	if (ret) {
150695652f98Sakshatzen 		pm8001_dbg(pm8001_ha, FAIL,
150795652f98Sakshatzen 			"Failed to init pci addresses");
150895652f98Sakshatzen 		return ret;
150995652f98Sakshatzen 	}
151095652f98Sakshatzen 
1511f5860992SSakthivel K 	/* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
1512f5860992SSakthivel K 	table is stop */
1513f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_RESET);
1514f5860992SSakthivel K 
1515f5860992SSakthivel K 	/* wait until Inbound DoorBell Clear Register toggled */
1516a9a923e5SAnand Kumar Santhanam 	if (IS_SPCV_12G(pm8001_ha->pdev)) {
15176f305bf6SIgor Pylypiv 		max_wait_count = SPCV_DOORBELL_CLEAR_TIMEOUT;
1518a9a923e5SAnand Kumar Santhanam 	} else {
15196f305bf6SIgor Pylypiv 		max_wait_count = SPC_DOORBELL_CLEAR_TIMEOUT;
1520a9a923e5SAnand Kumar Santhanam 	}
1521f5860992SSakthivel K 	do {
15226f305bf6SIgor Pylypiv 		msleep(FW_READY_INTERVAL);
1523f5860992SSakthivel K 		value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1524f5860992SSakthivel K 		value &= SPCv_MSGU_CFG_TABLE_RESET;
1525f5860992SSakthivel K 	} while ((value != 0) && (--max_wait_count));
1526f5860992SSakthivel K 
1527f5860992SSakthivel K 	if (!max_wait_count) {
15281b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=%x\n", value);
1529f5860992SSakthivel K 		return -1;
1530f5860992SSakthivel K 	}
1531f5860992SSakthivel K 
1532f5860992SSakthivel K 	/* check the MPI-State for termination in progress */
1533f5860992SSakthivel K 	/* wait until Inbound DoorBell Clear Register toggled */
15346f305bf6SIgor Pylypiv 	max_wait_count = 100; /* 2 sec for spcv/ve */
1535f5860992SSakthivel K 	do {
15366f305bf6SIgor Pylypiv 		msleep(FW_READY_INTERVAL);
1537f5860992SSakthivel K 		gst_len_mpistate =
1538f5860992SSakthivel K 			pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1539f5860992SSakthivel K 			GST_GSTLEN_MPIS_OFFSET);
1540f5860992SSakthivel K 		if (GST_MPI_STATE_UNINIT ==
1541f5860992SSakthivel K 			(gst_len_mpistate & GST_MPI_STATE_MASK))
1542f5860992SSakthivel K 			break;
1543f5860992SSakthivel K 	} while (--max_wait_count);
1544f5860992SSakthivel K 	if (!max_wait_count) {
15451b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n",
15461b5d2793SJoe Perches 			   gst_len_mpistate & GST_MPI_STATE_MASK);
1547f5860992SSakthivel K 		return -1;
1548f5860992SSakthivel K 	}
1549f5860992SSakthivel K 
1550f5860992SSakthivel K 	return 0;
1551f5860992SSakthivel K }
1552f5860992SSakthivel K 
1553f5860992SSakthivel K /**
1554bb6beabfSRandy Dunlap  * pm80xx_fatal_errors - returns non-zero *ONLY* when fatal errors
1555a961ea0aSakshatzen  * @pm8001_ha: our hba card information
1556a961ea0aSakshatzen  *
1557a961ea0aSakshatzen  * Fatal errors are recoverable only after a host reboot.
1558a961ea0aSakshatzen  */
1559a961ea0aSakshatzen int
pm80xx_fatal_errors(struct pm8001_hba_info * pm8001_ha)1560a961ea0aSakshatzen pm80xx_fatal_errors(struct pm8001_hba_info *pm8001_ha)
1561a961ea0aSakshatzen {
1562a961ea0aSakshatzen 	int ret = 0;
1563a961ea0aSakshatzen 	u32 scratch_pad_rsvd0 = pm8001_cr32(pm8001_ha, 0,
156480cac47bSAjish Koshy 					    MSGU_SCRATCH_PAD_RSVD_0);
1565a961ea0aSakshatzen 	u32 scratch_pad_rsvd1 = pm8001_cr32(pm8001_ha, 0,
156680cac47bSAjish Koshy 					    MSGU_SCRATCH_PAD_RSVD_1);
1567a961ea0aSakshatzen 	u32 scratch_pad1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1568a961ea0aSakshatzen 	u32 scratch_pad2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1569a961ea0aSakshatzen 	u32 scratch_pad3 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
1570a961ea0aSakshatzen 
1571a961ea0aSakshatzen 	if (pm8001_ha->chip_id != chip_8006 &&
1572a961ea0aSakshatzen 			pm8001_ha->chip_id != chip_8074 &&
1573a961ea0aSakshatzen 			pm8001_ha->chip_id != chip_8076) {
1574a961ea0aSakshatzen 		return 0;
1575a961ea0aSakshatzen 	}
1576a961ea0aSakshatzen 
1577a961ea0aSakshatzen 	if (MSGU_SCRATCHPAD1_STATE_FATAL_ERROR(scratch_pad1)) {
1578a961ea0aSakshatzen 		pm8001_dbg(pm8001_ha, FAIL,
1579a961ea0aSakshatzen 			"Fatal error SCRATCHPAD1 = 0x%x SCRATCHPAD2 = 0x%x SCRATCHPAD3 = 0x%x SCRATCHPAD_RSVD0 = 0x%x SCRATCHPAD_RSVD1 = 0x%x\n",
1580a961ea0aSakshatzen 				scratch_pad1, scratch_pad2, scratch_pad3,
1581a961ea0aSakshatzen 				scratch_pad_rsvd0, scratch_pad_rsvd1);
1582a961ea0aSakshatzen 		ret = 1;
1583a961ea0aSakshatzen 	}
1584a961ea0aSakshatzen 
1585a961ea0aSakshatzen 	return ret;
1586a961ea0aSakshatzen }
1587a961ea0aSakshatzen 
1588a961ea0aSakshatzen /**
1589bb6beabfSRandy Dunlap  * pm80xx_chip_soft_rst - soft reset the PM8001 chip, so that all
1590bb6beabfSRandy Dunlap  * FW register status are reset to the originated status.
1591f5860992SSakthivel K  * @pm8001_ha: our hba card information
1592f5860992SSakthivel K  */
1593f5860992SSakthivel K 
1594f5860992SSakthivel K static int
pm80xx_chip_soft_rst(struct pm8001_hba_info * pm8001_ha)1595f5860992SSakthivel K pm80xx_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
1596f5860992SSakthivel K {
1597f5860992SSakthivel K 	u32 regval;
1598f5860992SSakthivel K 	u32 bootloader_state;
159906f12f22SAnand Kumar Santhanam 	u32 ibutton0, ibutton1;
1600f5860992SSakthivel K 
160172349b62SDeepak Ukey 	/* Process MPI table uninitialization only if FW is ready */
160272349b62SDeepak Ukey 	if (!pm8001_ha->controller_fatal_error) {
1603f5860992SSakthivel K 		/* Check if MPI is in ready state to reset */
1604f5860992SSakthivel K 		if (mpi_uninit_check(pm8001_ha) != 0) {
1605d384be6eSVikram Auradkar 			u32 r0 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
1606d384be6eSVikram Auradkar 			u32 r1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1607d384be6eSVikram Auradkar 			u32 r2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1608d384be6eSVikram Auradkar 			u32 r3 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
16091b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, FAIL,
1610d384be6eSVikram Auradkar 				   "MPI state is not ready scratch: %x:%x:%x:%x\n",
16111b5d2793SJoe Perches 				   r0, r1, r2, r3);
1612d384be6eSVikram Auradkar 			/* if things aren't ready but the bootloader is ok then
1613d384be6eSVikram Auradkar 			 * try the reset anyway.
1614d384be6eSVikram Auradkar 			 */
1615d384be6eSVikram Auradkar 			if (r1 & SCRATCH_PAD1_BOOTSTATE_MASK)
1616f5860992SSakthivel K 				return -1;
1617f5860992SSakthivel K 		}
161872349b62SDeepak Ukey 	}
1619f5860992SSakthivel K 	/* checked for reset register normal state; 0x0 */
1620f5860992SSakthivel K 	regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
16211b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "reset register before write : 0x%x\n",
16221b5d2793SJoe Perches 		   regval);
1623f5860992SSakthivel K 
1624f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, SPCv_NORMAL_RESET_VALUE);
16254daf1ef3SVikram Auradkar 	msleep(500);
1626f5860992SSakthivel K 
1627f5860992SSakthivel K 	regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
16281b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "reset register after write 0x%x\n",
16291b5d2793SJoe Perches 		   regval);
1630f5860992SSakthivel K 
1631f5860992SSakthivel K 	if ((regval & SPCv_SOFT_RESET_READ_MASK) ==
1632f5860992SSakthivel K 			SPCv_SOFT_RESET_NORMAL_RESET_OCCURED) {
16331b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
16341b5d2793SJoe Perches 			   " soft reset successful [regval: 0x%x]\n",
16351b5d2793SJoe Perches 			   regval);
1636f5860992SSakthivel K 	} else {
16371b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
16381b5d2793SJoe Perches 			   " soft reset failed [regval: 0x%x]\n",
16391b5d2793SJoe Perches 			   regval);
1640f5860992SSakthivel K 
1641f5860992SSakthivel K 		/* check bootloader is successfully executed or in HDA mode */
1642f5860992SSakthivel K 		bootloader_state =
1643f5860992SSakthivel K 			pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1644f5860992SSakthivel K 			SCRATCH_PAD1_BOOTSTATE_MASK;
1645f5860992SSakthivel K 
1646f5860992SSakthivel K 		if (bootloader_state == SCRATCH_PAD1_BOOTSTATE_HDA_SEEPROM) {
16471b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, MSG,
16481b5d2793SJoe Perches 				   "Bootloader state - HDA mode SEEPROM\n");
1649f5860992SSakthivel K 		} else if (bootloader_state ==
1650f5860992SSakthivel K 				SCRATCH_PAD1_BOOTSTATE_HDA_BOOTSTRAP) {
16511b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, MSG,
16521b5d2793SJoe Perches 				   "Bootloader state - HDA mode Bootstrap Pin\n");
1653f5860992SSakthivel K 		} else if (bootloader_state ==
1654f5860992SSakthivel K 				SCRATCH_PAD1_BOOTSTATE_HDA_SOFTRESET) {
16551b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, MSG,
16561b5d2793SJoe Perches 				   "Bootloader state - HDA mode soft reset\n");
1657f5860992SSakthivel K 		} else if (bootloader_state ==
1658f5860992SSakthivel K 					SCRATCH_PAD1_BOOTSTATE_CRIT_ERROR) {
16591b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, MSG,
16601b5d2793SJoe Perches 				   "Bootloader state-HDA mode critical error\n");
1661f5860992SSakthivel K 		}
1662f5860992SSakthivel K 		return -EBUSY;
1663f5860992SSakthivel K 	}
1664f5860992SSakthivel K 
1665f5860992SSakthivel K 	/* check the firmware status after reset */
1666f5860992SSakthivel K 	if (-1 == check_fw_ready(pm8001_ha)) {
16671b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
166806f12f22SAnand Kumar Santhanam 		/* check iButton feature support for motherboard controller */
166906f12f22SAnand Kumar Santhanam 		if (pm8001_ha->pdev->subsystem_vendor !=
167006f12f22SAnand Kumar Santhanam 			PCI_VENDOR_ID_ADAPTEC2 &&
1671faf321b0SBenjamin Rood 			pm8001_ha->pdev->subsystem_vendor !=
1672faf321b0SBenjamin Rood 			PCI_VENDOR_ID_ATTO &&
167306f12f22SAnand Kumar Santhanam 			pm8001_ha->pdev->subsystem_vendor != 0) {
167406f12f22SAnand Kumar Santhanam 			ibutton0 = pm8001_cr32(pm8001_ha, 0,
167580cac47bSAjish Koshy 					       MSGU_SCRATCH_PAD_RSVD_0);
167606f12f22SAnand Kumar Santhanam 			ibutton1 = pm8001_cr32(pm8001_ha, 0,
167780cac47bSAjish Koshy 					       MSGU_SCRATCH_PAD_RSVD_1);
167806f12f22SAnand Kumar Santhanam 			if (!ibutton0 && !ibutton1) {
16791b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
16801b5d2793SJoe Perches 					   "iButton Feature is not Available!!!\n");
1681f5860992SSakthivel K 				return -EBUSY;
1682f5860992SSakthivel K 			}
168306f12f22SAnand Kumar Santhanam 			if (ibutton0 == 0xdeadbeef && ibutton1 == 0xdeadbeef) {
16841b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
16851b5d2793SJoe Perches 					   "CRC Check for iButton Feature Failed!!!\n");
168606f12f22SAnand Kumar Santhanam 				return -EBUSY;
168706f12f22SAnand Kumar Santhanam 			}
168806f12f22SAnand Kumar Santhanam 		}
168906f12f22SAnand Kumar Santhanam 	}
16901b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SPCv soft reset Complete\n");
1691f5860992SSakthivel K 	return 0;
1692f5860992SSakthivel K }
1693f5860992SSakthivel K 
pm80xx_hw_chip_rst(struct pm8001_hba_info * pm8001_ha)1694f5860992SSakthivel K static void pm80xx_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1695f5860992SSakthivel K {
1696f5860992SSakthivel K 	u32 i;
1697f5860992SSakthivel K 
16981b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "chip reset start\n");
1699f5860992SSakthivel K 
1700f5860992SSakthivel K 	/* do SPCv chip reset. */
1701f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, 0x11);
17021b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n");
1703f5860992SSakthivel K 
1704f5860992SSakthivel K 	/* Check this ..whether delay is required or no */
1705f5860992SSakthivel K 	/* delay 10 usec */
1706f5860992SSakthivel K 	udelay(10);
1707f5860992SSakthivel K 
1708f5860992SSakthivel K 	/* wait for 20 msec until the firmware gets reloaded */
1709f5860992SSakthivel K 	i = 20;
1710f5860992SSakthivel K 	do {
1711f5860992SSakthivel K 		mdelay(1);
1712f5860992SSakthivel K 	} while ((--i) != 0);
1713f5860992SSakthivel K 
17141b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n");
1715f5860992SSakthivel K }
1716f5860992SSakthivel K 
1717f5860992SSakthivel K /**
17187cdaf12eSLee Jones  * pm80xx_chip_intx_interrupt_enable - enable PM8001 chip interrupt
1719f5860992SSakthivel K  * @pm8001_ha: our hba card information
1720f5860992SSakthivel K  */
1721f5860992SSakthivel K static void
pm80xx_chip_intx_interrupt_enable(struct pm8001_hba_info * pm8001_ha)1722f5860992SSakthivel K pm80xx_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1723f5860992SSakthivel K {
1724f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1725f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1726f5860992SSakthivel K }
1727f5860992SSakthivel K 
1728f5860992SSakthivel K /**
17297cdaf12eSLee Jones  * pm80xx_chip_intx_interrupt_disable - disable PM8001 chip interrupt
1730f5860992SSakthivel K  * @pm8001_ha: our hba card information
1731f5860992SSakthivel K  */
1732f5860992SSakthivel K static void
pm80xx_chip_intx_interrupt_disable(struct pm8001_hba_info * pm8001_ha)1733f5860992SSakthivel K pm80xx_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1734f5860992SSakthivel K {
1735f5860992SSakthivel K 	pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, ODMR_MASK_ALL);
1736f5860992SSakthivel K }
1737f5860992SSakthivel K 
1738f5860992SSakthivel K /**
17397cdaf12eSLee Jones  * pm80xx_chip_interrupt_enable - enable PM8001 chip interrupt
1740f5860992SSakthivel K  * @pm8001_ha: our hba card information
17416ad4a517SLee Jones  * @vec: interrupt number to enable
1742f5860992SSakthivel K  */
1743f5860992SSakthivel K static void
pm80xx_chip_interrupt_enable(struct pm8001_hba_info * pm8001_ha,u8 vec)1744f5860992SSakthivel K pm80xx_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1745f5860992SSakthivel K {
1746f5860992SSakthivel K #ifdef PM8001_USE_MSIX
1747294080eaSAjish Koshy 	if (vec < 32)
1748294080eaSAjish Koshy 		pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, 1U << vec);
1749294080eaSAjish Koshy 	else
1750294080eaSAjish Koshy 		pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR_U,
1751294080eaSAjish Koshy 			    1U << (vec - 32));
1752f5860992SSakthivel K 	return;
1753f5860992SSakthivel K #endif
1754f5860992SSakthivel K 	pm80xx_chip_intx_interrupt_enable(pm8001_ha);
1755f5860992SSakthivel K 
1756f5860992SSakthivel K }
1757f5860992SSakthivel K 
1758f5860992SSakthivel K /**
17597cdaf12eSLee Jones  * pm80xx_chip_interrupt_disable - disable PM8001 chip interrupt
1760f5860992SSakthivel K  * @pm8001_ha: our hba card information
17616ad4a517SLee Jones  * @vec: interrupt number to disable
1762f5860992SSakthivel K  */
1763f5860992SSakthivel K static void
pm80xx_chip_interrupt_disable(struct pm8001_hba_info * pm8001_ha,u8 vec)1764f5860992SSakthivel K pm80xx_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1765f5860992SSakthivel K {
1766f5860992SSakthivel K #ifdef PM8001_USE_MSIX
1767294080eaSAjish Koshy 	if (vec == 0xFF) {
1768294080eaSAjish Koshy 		/* disable all vectors 0-31, 32-63 */
1769294080eaSAjish Koshy 		pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, 0xFFFFFFFF);
1770294080eaSAjish Koshy 		pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_U, 0xFFFFFFFF);
1771294080eaSAjish Koshy 	} else if (vec < 32)
1772294080eaSAjish Koshy 		pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, 1U << vec);
1773f5860992SSakthivel K 	else
1774294080eaSAjish Koshy 		pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_U,
1775294080eaSAjish Koshy 			    1U << (vec - 32));
1776f5860992SSakthivel K 	return;
1777f5860992SSakthivel K #endif
1778f5860992SSakthivel K 	pm80xx_chip_intx_interrupt_disable(pm8001_ha);
1779f5860992SSakthivel K }
1780f5860992SSakthivel K 
1781f5860992SSakthivel K /**
1782f5860992SSakthivel K  * mpi_ssp_completion - process the event that FW response to the SSP request.
1783f5860992SSakthivel K  * @pm8001_ha: our hba card information
1784f5860992SSakthivel K  * @piomb: the message contents of this outbound message.
1785f5860992SSakthivel K  *
1786f5860992SSakthivel K  * When FW has completed a ssp request for example a IO request, after it has
1787bb6beabfSRandy Dunlap  * filled the SG data with the data, it will trigger this event representing
1788bb6beabfSRandy Dunlap  * that he has finished the job; please check the corresponding buffer.
1789f5860992SSakthivel K  * So we will tell the caller who maybe waiting the result to tell upper layer
1790f5860992SSakthivel K  * that the task has been finished.
1791f5860992SSakthivel K  */
1792f5860992SSakthivel K static void
mpi_ssp_completion(struct pm8001_hba_info * pm8001_ha,void * piomb)1793f5860992SSakthivel K mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
1794f5860992SSakthivel K {
1795f5860992SSakthivel K 	struct sas_task *t;
1796f5860992SSakthivel K 	struct pm8001_ccb_info *ccb;
1797f5860992SSakthivel K 	unsigned long flags;
1798f5860992SSakthivel K 	u32 status;
1799f5860992SSakthivel K 	u32 param;
1800f5860992SSakthivel K 	u32 tag;
1801f5860992SSakthivel K 	struct ssp_completion_resp *psspPayload;
1802f5860992SSakthivel K 	struct task_status_struct *ts;
1803f5860992SSakthivel K 	struct ssp_response_iu *iu;
1804f5860992SSakthivel K 	struct pm8001_device *pm8001_dev;
1805f5860992SSakthivel K 	psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1806f5860992SSakthivel K 	status = le32_to_cpu(psspPayload->status);
1807f5860992SSakthivel K 	tag = le32_to_cpu(psspPayload->tag);
1808f5860992SSakthivel K 	ccb = &pm8001_ha->ccb_info[tag];
1809f5860992SSakthivel K 	if ((status == IO_ABORTED) && ccb->open_retry) {
1810f5860992SSakthivel K 		/* Being completed by another */
1811f5860992SSakthivel K 		ccb->open_retry = 0;
1812f5860992SSakthivel K 		return;
1813f5860992SSakthivel K 	}
1814f5860992SSakthivel K 	pm8001_dev = ccb->device;
1815f5860992SSakthivel K 	param = le32_to_cpu(psspPayload->param);
1816f5860992SSakthivel K 	t = ccb->task;
1817f5860992SSakthivel K 
1818f5860992SSakthivel K 	if (status && status != IO_UNDERFLOW)
18191b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status);
1820f5860992SSakthivel K 	if (unlikely(!t || !t->lldd_task || !t->dev))
1821f5860992SSakthivel K 		return;
1822f5860992SSakthivel K 	ts = &t->task_status;
18237370672dSpeter chang 
18241b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
18251b5d2793SJoe Perches 		   "tag::0x%x, status::0x%x task::0x%p\n", tag, status, t);
18267370672dSpeter chang 
1827cb269c26SAnand Kumar Santhanam 	/* Print sas address of IO failed device */
1828cb269c26SAnand Kumar Santhanam 	if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1829cb269c26SAnand Kumar Santhanam 		(status != IO_UNDERFLOW))
18301b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n",
18311b5d2793SJoe Perches 			   SAS_ADDR(t->dev->sas_addr));
1832cb269c26SAnand Kumar Santhanam 
1833f5860992SSakthivel K 	switch (status) {
1834f5860992SSakthivel K 	case IO_SUCCESS:
18351b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS ,param = 0x%x\n",
18361b5d2793SJoe Perches 			   param);
1837f5860992SSakthivel K 		if (param == 0) {
1838f5860992SSakthivel K 			ts->resp = SAS_TASK_COMPLETE;
1839d377f415SBart Van Assche 			ts->stat = SAS_SAM_STAT_GOOD;
1840f5860992SSakthivel K 		} else {
1841f5860992SSakthivel K 			ts->resp = SAS_TASK_COMPLETE;
1842f5860992SSakthivel K 			ts->stat = SAS_PROTO_RESPONSE;
1843f5860992SSakthivel K 			ts->residual = param;
1844f5860992SSakthivel K 			iu = &psspPayload->ssp_resp_iu;
1845f5860992SSakthivel K 			sas_ssp_task_response(pm8001_ha->dev, t, iu);
1846f5860992SSakthivel K 		}
1847f5860992SSakthivel K 		if (pm8001_dev)
18484a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1849f5860992SSakthivel K 		break;
1850f5860992SSakthivel K 	case IO_ABORTED:
18511b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
1852f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1853f5860992SSakthivel K 		ts->stat = SAS_ABORTED_TASK;
18544a2efd4bSViswas G 		if (pm8001_dev)
18554a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1856f5860992SSakthivel K 		break;
1857f5860992SSakthivel K 	case IO_UNDERFLOW:
1858f5860992SSakthivel K 		/* SSP Completion with error */
18591b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW ,param = 0x%x\n",
18601b5d2793SJoe Perches 			   param);
1861f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1862f5860992SSakthivel K 		ts->stat = SAS_DATA_UNDERRUN;
1863f5860992SSakthivel K 		ts->residual = param;
1864f5860992SSakthivel K 		if (pm8001_dev)
18654a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1866f5860992SSakthivel K 		break;
1867f5860992SSakthivel K 	case IO_NO_DEVICE:
18681b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
1869f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
1870f5860992SSakthivel K 		ts->stat = SAS_PHY_DOWN;
18714a2efd4bSViswas G 		if (pm8001_dev)
18724a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1873f5860992SSakthivel K 		break;
1874f5860992SSakthivel K 	case IO_XFER_ERROR_BREAK:
18751b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
1876f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1877f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1878f5860992SSakthivel K 		/* Force the midlayer to retry */
1879f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
18804a2efd4bSViswas G 		if (pm8001_dev)
18814a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1882f5860992SSakthivel K 		break;
1883f5860992SSakthivel K 	case IO_XFER_ERROR_PHY_NOT_READY:
18841b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
1885f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1886f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1887f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
18884a2efd4bSViswas G 		if (pm8001_dev)
18894a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1890f5860992SSakthivel K 		break;
189127ecfa5eSViswas G 	case IO_XFER_ERROR_INVALID_SSP_RSP_FRAME:
18921b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
18931b5d2793SJoe Perches 			   "IO_XFER_ERROR_INVALID_SSP_RSP_FRAME\n");
189427ecfa5eSViswas G 		ts->resp = SAS_TASK_COMPLETE;
189527ecfa5eSViswas G 		ts->stat = SAS_OPEN_REJECT;
189627ecfa5eSViswas G 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
18974a2efd4bSViswas G 		if (pm8001_dev)
18984a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
189927ecfa5eSViswas G 		break;
1900f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
19011b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
19021b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
1903f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1904f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1905f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_EPROTO;
19064a2efd4bSViswas G 		if (pm8001_dev)
19074a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1908f5860992SSakthivel K 		break;
1909f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
19101b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
19111b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
1912f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1913f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1914f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
19154a2efd4bSViswas G 		if (pm8001_dev)
19164a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1917f5860992SSakthivel K 		break;
1918f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BREAK:
19191b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
1920f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1921f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1922f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
19234a2efd4bSViswas G 		if (pm8001_dev)
19244a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1925f5860992SSakthivel K 		break;
1926f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
1927a6cb3d01SSakthivel K 	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
1928a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
1929a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
1930a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
1931a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
19321b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
1933f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1934f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1935f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1936f5860992SSakthivel K 		if (!t->uldd_task)
1937f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
1938f5860992SSakthivel K 				pm8001_dev,
1939f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
1940f5860992SSakthivel K 		break;
1941f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
19421b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
19431b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
1944f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1945f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1946f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
19474a2efd4bSViswas G 		if (pm8001_dev)
19484a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1949f5860992SSakthivel K 		break;
1950f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
19511b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
19521b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
1953f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1954f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1955f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
19564a2efd4bSViswas G 		if (pm8001_dev)
19574a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1958f5860992SSakthivel K 		break;
1959f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
19601b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
19611b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
1962f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
1963f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1964f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
19654a2efd4bSViswas G 		if (pm8001_dev)
19664a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1967f5860992SSakthivel K 		break;
1968f5860992SSakthivel K 	case IO_XFER_ERROR_NAK_RECEIVED:
19691b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
1970f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1971f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1972f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
19734a2efd4bSViswas G 		if (pm8001_dev)
19744a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1975f5860992SSakthivel K 		break;
1976f5860992SSakthivel K 	case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
19771b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
1978f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1979f5860992SSakthivel K 		ts->stat = SAS_NAK_R_ERR;
19804a2efd4bSViswas G 		if (pm8001_dev)
19814a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1982f5860992SSakthivel K 		break;
1983f5860992SSakthivel K 	case IO_XFER_ERROR_DMA:
19841b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
1985f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1986f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
19874a2efd4bSViswas G 		if (pm8001_dev)
19884a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1989f5860992SSakthivel K 		break;
1990f5860992SSakthivel K 	case IO_XFER_OPEN_RETRY_TIMEOUT:
19911b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
1992f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
1993f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
1994f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
19954a2efd4bSViswas G 		if (pm8001_dev)
19964a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
1997f5860992SSakthivel K 		break;
1998f5860992SSakthivel K 	case IO_XFER_ERROR_OFFSET_MISMATCH:
19991b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
2000f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2001f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
20024a2efd4bSViswas G 		if (pm8001_dev)
20034a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2004f5860992SSakthivel K 		break;
2005f5860992SSakthivel K 	case IO_PORT_IN_RESET:
20061b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
2007f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2008f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
20094a2efd4bSViswas G 		if (pm8001_dev)
20104a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2011f5860992SSakthivel K 		break;
2012f5860992SSakthivel K 	case IO_DS_NON_OPERATIONAL:
20131b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
2014f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2015f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2016f5860992SSakthivel K 		if (!t->uldd_task)
2017f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
2018f5860992SSakthivel K 				pm8001_dev,
2019f5860992SSakthivel K 				IO_DS_NON_OPERATIONAL);
2020f5860992SSakthivel K 		break;
2021f5860992SSakthivel K 	case IO_DS_IN_RECOVERY:
20221b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
2023f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2024f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
20254a2efd4bSViswas G 		if (pm8001_dev)
20264a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2027f5860992SSakthivel K 		break;
2028f5860992SSakthivel K 	case IO_TM_TAG_NOT_FOUND:
20291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n");
2030f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2031f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
20324a2efd4bSViswas G 		if (pm8001_dev)
20334a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2034f5860992SSakthivel K 		break;
2035f5860992SSakthivel K 	case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
20361b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n");
2037f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2038f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
20394a2efd4bSViswas G 		if (pm8001_dev)
20404a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2041f5860992SSakthivel K 		break;
2042f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
20431b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
20441b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
2045f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2046f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2047f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
20484a2efd4bSViswas G 		if (pm8001_dev)
20494a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2050f5860992SSakthivel K 		break;
2051f5860992SSakthivel K 	default:
20521b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
2053f5860992SSakthivel K 		/* not allowed case. Therefore, return failed status */
2054f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2055f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
20564a2efd4bSViswas G 		if (pm8001_dev)
20574a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2058f5860992SSakthivel K 		break;
2059f5860992SSakthivel K 	}
20601b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "scsi_status = 0x%x\n ",
20611b5d2793SJoe Perches 		   psspPayload->ssp_resp_iu.status);
2062f5860992SSakthivel K 	spin_lock_irqsave(&t->task_state_lock, flags);
2063f5860992SSakthivel K 	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2064f5860992SSakthivel K 	t->task_state_flags |= SAS_TASK_STATE_DONE;
2065f5860992SSakthivel K 	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2066f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
20671b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
20681b5d2793SJoe Perches 			   "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
20691b5d2793SJoe Perches 			   t, status, ts->resp, ts->stat);
2070304fe11bSDamien Le Moal 		pm8001_ccb_task_free(pm8001_ha, ccb);
2071869ddbdcSViswas G 		if (t->slow_task)
2072869ddbdcSViswas G 			complete(&t->slow_task->completion);
2073f5860992SSakthivel K 	} else {
2074f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
2075304fe11bSDamien Le Moal 		pm8001_ccb_task_free_done(pm8001_ha, ccb);
2076f5860992SSakthivel K 	}
2077f5860992SSakthivel K }
2078f5860992SSakthivel K 
2079f5860992SSakthivel K /*See the comments for mpi_ssp_completion */
mpi_ssp_event(struct pm8001_hba_info * pm8001_ha,void * piomb)2080f5860992SSakthivel K static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
2081f5860992SSakthivel K {
2082f5860992SSakthivel K 	struct sas_task *t;
2083f5860992SSakthivel K 	unsigned long flags;
2084f5860992SSakthivel K 	struct task_status_struct *ts;
2085f5860992SSakthivel K 	struct pm8001_ccb_info *ccb;
2086f5860992SSakthivel K 	struct pm8001_device *pm8001_dev;
2087f5860992SSakthivel K 	struct ssp_event_resp *psspPayload =
2088f5860992SSakthivel K 		(struct ssp_event_resp *)(piomb + 4);
2089f5860992SSakthivel K 	u32 event = le32_to_cpu(psspPayload->event);
2090f5860992SSakthivel K 	u32 tag = le32_to_cpu(psspPayload->tag);
2091f5860992SSakthivel K 	u32 port_id = le32_to_cpu(psspPayload->port_id);
2092f5860992SSakthivel K 
2093f5860992SSakthivel K 	ccb = &pm8001_ha->ccb_info[tag];
2094f5860992SSakthivel K 	t = ccb->task;
2095f5860992SSakthivel K 	pm8001_dev = ccb->device;
2096f5860992SSakthivel K 	if (event)
20971b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event);
2098f5860992SSakthivel K 	if (unlikely(!t || !t->lldd_task || !t->dev))
2099f5860992SSakthivel K 		return;
2100f5860992SSakthivel K 	ts = &t->task_status;
21011b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IOERR, "port_id:0x%x, tag:0x%x, event:0x%x\n",
21021b5d2793SJoe Perches 		   port_id, tag, event);
2103f5860992SSakthivel K 	switch (event) {
2104f5860992SSakthivel K 	case IO_OVERFLOW:
21051b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
2106f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2107f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2108f5860992SSakthivel K 		ts->residual = 0;
2109f5860992SSakthivel K 		if (pm8001_dev)
21104a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2111f5860992SSakthivel K 		break;
2112f5860992SSakthivel K 	case IO_XFER_ERROR_BREAK:
21131b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
2114f5860992SSakthivel K 		pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2115f5860992SSakthivel K 		return;
2116f5860992SSakthivel K 	case IO_XFER_ERROR_PHY_NOT_READY:
21171b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
2118f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2119f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2120f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2121f5860992SSakthivel K 		break;
2122f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
21231b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
21241b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
2125f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2126f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2127f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_EPROTO;
2128f5860992SSakthivel K 		break;
2129f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
21301b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
21311b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
2132f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2133f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2134f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2135f5860992SSakthivel K 		break;
2136f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BREAK:
21371b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
2138f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2139f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2140f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2141f5860992SSakthivel K 		break;
2142f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2143a6cb3d01SSakthivel K 	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2144a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2145a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2146a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2147a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
21481b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
2149f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2150f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2151f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2152f5860992SSakthivel K 		if (!t->uldd_task)
2153f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
2154f5860992SSakthivel K 				pm8001_dev,
2155f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2156f5860992SSakthivel K 		break;
2157f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
21581b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
21591b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
2160f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2161f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2162f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2163f5860992SSakthivel K 		break;
2164f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
21651b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
21661b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
2167f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2168f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2169f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2170f5860992SSakthivel K 		break;
2171f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
21721b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
21731b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
2174f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2175f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2176f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2177f5860992SSakthivel K 		break;
2178f5860992SSakthivel K 	case IO_XFER_ERROR_NAK_RECEIVED:
21791b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
2180f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2181f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2182f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2183f5860992SSakthivel K 		break;
2184f5860992SSakthivel K 	case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
21851b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
2186f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2187f5860992SSakthivel K 		ts->stat = SAS_NAK_R_ERR;
2188f5860992SSakthivel K 		break;
2189f5860992SSakthivel K 	case IO_XFER_OPEN_RETRY_TIMEOUT:
21901b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
2191f5860992SSakthivel K 		pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2192f5860992SSakthivel K 		return;
2193f5860992SSakthivel K 	case IO_XFER_ERROR_UNEXPECTED_PHASE:
21941b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
2195f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2196f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2197f5860992SSakthivel K 		break;
2198f5860992SSakthivel K 	case IO_XFER_ERROR_XFER_RDY_OVERRUN:
21991b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
2200f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2201f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2202f5860992SSakthivel K 		break;
2203f5860992SSakthivel K 	case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
22041b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
22051b5d2793SJoe Perches 			   "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
2206f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2207f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2208f5860992SSakthivel K 		break;
2209f5860992SSakthivel K 	case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
22101b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
22111b5d2793SJoe Perches 			   "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n");
2212f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2213f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2214f5860992SSakthivel K 		break;
2215f5860992SSakthivel K 	case IO_XFER_ERROR_OFFSET_MISMATCH:
22161b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
2217f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2218f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2219f5860992SSakthivel K 		break;
2220f5860992SSakthivel K 	case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
22211b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
22221b5d2793SJoe Perches 			   "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
2223f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2224f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2225f5860992SSakthivel K 		break;
2226a6cb3d01SSakthivel K 	case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
22271b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IOERR,
22281b5d2793SJoe Perches 			   "IO_XFR_ERROR_INTERNAL_CRC_ERROR\n");
2229a6cb3d01SSakthivel K 		/* TBC: used default set values */
2230a6cb3d01SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2231a6cb3d01SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2232a6cb3d01SSakthivel K 		break;
2233f5860992SSakthivel K 	case IO_XFER_CMD_FRAME_ISSUED:
22341b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
2235f5860992SSakthivel K 		return;
2236f5860992SSakthivel K 	default:
22371b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
2238f5860992SSakthivel K 		/* not allowed case. Therefore, return failed status */
2239f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2240f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2241f5860992SSakthivel K 		break;
2242f5860992SSakthivel K 	}
2243f5860992SSakthivel K 	spin_lock_irqsave(&t->task_state_lock, flags);
2244f5860992SSakthivel K 	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2245f5860992SSakthivel K 	t->task_state_flags |= SAS_TASK_STATE_DONE;
2246f5860992SSakthivel K 	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2247f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
22481b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
22491b5d2793SJoe Perches 			   "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
22501b5d2793SJoe Perches 			   t, event, ts->resp, ts->stat);
2251304fe11bSDamien Le Moal 		pm8001_ccb_task_free(pm8001_ha, ccb);
2252f5860992SSakthivel K 	} else {
2253f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
2254304fe11bSDamien Le Moal 		pm8001_ccb_task_free_done(pm8001_ha, ccb);
2255f5860992SSakthivel K 	}
2256f5860992SSakthivel K }
2257f5860992SSakthivel K 
2258f5860992SSakthivel K /*See the comments for mpi_ssp_completion */
2259f5860992SSakthivel K static void
mpi_sata_completion(struct pm8001_hba_info * pm8001_ha,struct outbound_queue_table * circularQ,void * piomb)2260b27a4053SAjish Koshy mpi_sata_completion(struct pm8001_hba_info *pm8001_ha,
2261b27a4053SAjish Koshy 		struct outbound_queue_table *circularQ, void *piomb)
2262f5860992SSakthivel K {
2263f5860992SSakthivel K 	struct sas_task *t;
2264f5860992SSakthivel K 	struct pm8001_ccb_info *ccb;
2265f5860992SSakthivel K 	u32 param;
2266f5860992SSakthivel K 	u32 status;
2267f5860992SSakthivel K 	u32 tag;
2268cb269c26SAnand Kumar Santhanam 	int i, j;
2269cb269c26SAnand Kumar Santhanam 	u8 sata_addr_low[4];
2270cb269c26SAnand Kumar Santhanam 	u32 temp_sata_addr_low, temp_sata_addr_hi;
2271cb269c26SAnand Kumar Santhanam 	u8 sata_addr_hi[4];
2272f5860992SSakthivel K 	struct sata_completion_resp *psataPayload;
2273f5860992SSakthivel K 	struct task_status_struct *ts;
2274f5860992SSakthivel K 	struct ata_task_resp *resp ;
2275f5860992SSakthivel K 	u32 *sata_resp;
2276f5860992SSakthivel K 	struct pm8001_device *pm8001_dev;
2277c6b9ef57SSakthivel K 	unsigned long flags;
2278f5860992SSakthivel K 
2279f5860992SSakthivel K 	psataPayload = (struct sata_completion_resp *)(piomb + 4);
2280f5860992SSakthivel K 	status = le32_to_cpu(psataPayload->status);
228160de1a67SIgor Pylypiv 	param = le32_to_cpu(psataPayload->param);
2282f5860992SSakthivel K 	tag = le32_to_cpu(psataPayload->tag);
2283f5860992SSakthivel K 
2284f5860992SSakthivel K 	ccb = &pm8001_ha->ccb_info[tag];
2285f5860992SSakthivel K 	t = ccb->task;
2286f5860992SSakthivel K 	pm8001_dev = ccb->device;
2287c6b9ef57SSakthivel K 
2288c6b9ef57SSakthivel K 	if (t) {
2289c6b9ef57SSakthivel K 		if (t->dev && (t->dev->lldd_dev))
2290c6b9ef57SSakthivel K 			pm8001_dev = t->dev->lldd_dev;
2291c6b9ef57SSakthivel K 	} else {
22920b639decSJohn Garry 		pm8001_dbg(pm8001_ha, FAIL, "task null, freeing CCB tag %d\n",
22930b639decSJohn Garry 			   ccb->ccb_tag);
22940b639decSJohn Garry 		pm8001_ccb_free(pm8001_ha, ccb);
2295c6b9ef57SSakthivel K 		return;
2296c6b9ef57SSakthivel K 	}
2297c6b9ef57SSakthivel K 
2298811be570SJohn Garry 
2299811be570SJohn Garry 	if (pm8001_dev && unlikely(!t->lldd_task || !t->dev))
2300c6b9ef57SSakthivel K 		return;
2301c6b9ef57SSakthivel K 
2302c6b9ef57SSakthivel K 	ts = &t->task_status;
23037370672dSpeter chang 
23044f608fbcSVishakha Channapattan 	if (status != IO_SUCCESS) {
23054f608fbcSVishakha Channapattan 		pm8001_dbg(pm8001_ha, FAIL,
23064f608fbcSVishakha Channapattan 			"IO failed device_id %u status 0x%x tag %d\n",
23074f608fbcSVishakha Channapattan 			pm8001_dev->device_id, status, tag);
23084f608fbcSVishakha Channapattan 	}
23097370672dSpeter chang 
2310cb269c26SAnand Kumar Santhanam 	/* Print sas address of IO failed device */
2311cb269c26SAnand Kumar Santhanam 	if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2312cb269c26SAnand Kumar Santhanam 		(status != IO_UNDERFLOW)) {
2313cb269c26SAnand Kumar Santhanam 		if (!((t->dev->parent) &&
2314924a3541SJohn Garry 			(dev_is_expander(t->dev->parent->dev_type)))) {
2315cb269c26SAnand Kumar Santhanam 			for (i = 0, j = 4; i <= 3 && j <= 7; i++, j++)
2316cb269c26SAnand Kumar Santhanam 				sata_addr_low[i] = pm8001_ha->sas_addr[j];
2317cb269c26SAnand Kumar Santhanam 			for (i = 0, j = 0; i <= 3 && j <= 3; i++, j++)
2318cb269c26SAnand Kumar Santhanam 				sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2319cb269c26SAnand Kumar Santhanam 			memcpy(&temp_sata_addr_low, sata_addr_low,
2320cb269c26SAnand Kumar Santhanam 				sizeof(sata_addr_low));
2321cb269c26SAnand Kumar Santhanam 			memcpy(&temp_sata_addr_hi, sata_addr_hi,
2322cb269c26SAnand Kumar Santhanam 				sizeof(sata_addr_hi));
2323cb269c26SAnand Kumar Santhanam 			temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2324cb269c26SAnand Kumar Santhanam 						|((temp_sata_addr_hi << 8) &
2325cb269c26SAnand Kumar Santhanam 						0xff0000) |
2326cb269c26SAnand Kumar Santhanam 						((temp_sata_addr_hi >> 8)
2327cb269c26SAnand Kumar Santhanam 						& 0xff00) |
2328cb269c26SAnand Kumar Santhanam 						((temp_sata_addr_hi << 24) &
2329cb269c26SAnand Kumar Santhanam 						0xff000000));
2330cb269c26SAnand Kumar Santhanam 			temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2331cb269c26SAnand Kumar Santhanam 						& 0xff) |
2332cb269c26SAnand Kumar Santhanam 						((temp_sata_addr_low << 8)
2333cb269c26SAnand Kumar Santhanam 						& 0xff0000) |
2334cb269c26SAnand Kumar Santhanam 						((temp_sata_addr_low >> 8)
2335cb269c26SAnand Kumar Santhanam 						& 0xff00) |
2336cb269c26SAnand Kumar Santhanam 						((temp_sata_addr_low << 24)
2337cb269c26SAnand Kumar Santhanam 						& 0xff000000)) +
2338cb269c26SAnand Kumar Santhanam 						pm8001_dev->attached_phy +
2339cb269c26SAnand Kumar Santhanam 						0x10);
23401b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, FAIL,
23411b5d2793SJoe Perches 				   "SAS Address of IO Failure Drive:%08x%08x\n",
23421b5d2793SJoe Perches 				   temp_sata_addr_hi,
23431b5d2793SJoe Perches 				   temp_sata_addr_low);
2344f5860992SSakthivel K 
2345cb269c26SAnand Kumar Santhanam 		} else {
23461b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, FAIL,
23471b5d2793SJoe Perches 				   "SAS Address of IO Failure Drive:%016llx\n",
23481b5d2793SJoe Perches 				   SAS_ADDR(t->dev->sas_addr));
2349cb269c26SAnand Kumar Santhanam 		}
2350cb269c26SAnand Kumar Santhanam 	}
2351f5860992SSakthivel K 	switch (status) {
2352f5860992SSakthivel K 	case IO_SUCCESS:
23531b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
2354f5860992SSakthivel K 		if (param == 0) {
2355f5860992SSakthivel K 			ts->resp = SAS_TASK_COMPLETE;
2356d377f415SBart Van Assche 			ts->stat = SAS_SAM_STAT_GOOD;
2357f5860992SSakthivel K 		} else {
2358f5860992SSakthivel K 			u8 len;
2359f5860992SSakthivel K 			ts->resp = SAS_TASK_COMPLETE;
2360f5860992SSakthivel K 			ts->stat = SAS_PROTO_RESPONSE;
2361f5860992SSakthivel K 			ts->residual = param;
23621b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, IO,
23631b5d2793SJoe Perches 				   "SAS_PROTO_RESPONSE len = %d\n",
23641b5d2793SJoe Perches 				   param);
2365f5860992SSakthivel K 			sata_resp = &psataPayload->sata_resp[0];
2366f5860992SSakthivel K 			resp = (struct ata_task_resp *)ts->buf;
2367f5860992SSakthivel K 			if (t->ata_task.dma_xfer == 0 &&
2368f73bdebdSChristoph Hellwig 			    t->data_dir == DMA_FROM_DEVICE) {
2369f5860992SSakthivel K 				len = sizeof(struct pio_setup_fis);
23701b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO,
23711b5d2793SJoe Perches 					   "PIO read len = %d\n", len);
23721d6736c3SDamien Le Moal 			} else if (t->ata_task.use_ncq &&
23731d6736c3SDamien Le Moal 				   t->data_dir != DMA_NONE) {
2374f5860992SSakthivel K 				len = sizeof(struct set_dev_bits_fis);
23751b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n",
23761b5d2793SJoe Perches 					   len);
2377f5860992SSakthivel K 			} else {
2378f5860992SSakthivel K 				len = sizeof(struct dev_to_host_fis);
23791b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO, "other len = %d\n",
23801b5d2793SJoe Perches 					   len);
2381f5860992SSakthivel K 			}
2382f5860992SSakthivel K 			if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2383f5860992SSakthivel K 				resp->frame_len = len;
2384f5860992SSakthivel K 				memcpy(&resp->ending_fis[0], sata_resp, len);
2385f5860992SSakthivel K 				ts->buf_valid_size = sizeof(*resp);
2386f5860992SSakthivel K 			} else
23871b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO,
23881b5d2793SJoe Perches 					   "response too large\n");
2389f5860992SSakthivel K 		}
2390f5860992SSakthivel K 		if (pm8001_dev)
23914a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2392f5860992SSakthivel K 		break;
2393f5860992SSakthivel K 	case IO_ABORTED:
23941b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
2395f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2396f5860992SSakthivel K 		ts->stat = SAS_ABORTED_TASK;
2397f5860992SSakthivel K 		if (pm8001_dev)
23984a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2399f5860992SSakthivel K 		break;
2400f5860992SSakthivel K 		/* following cases are to do cases */
2401f5860992SSakthivel K 	case IO_UNDERFLOW:
2402f5860992SSakthivel K 		/* SATA Completion with error */
24031b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param);
2404f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2405f5860992SSakthivel K 		ts->stat = SAS_DATA_UNDERRUN;
2406f5860992SSakthivel K 		ts->residual = param;
2407f5860992SSakthivel K 		if (pm8001_dev)
24084a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2409f5860992SSakthivel K 		break;
2410f5860992SSakthivel K 	case IO_NO_DEVICE:
24111b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
2412f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
2413f5860992SSakthivel K 		ts->stat = SAS_PHY_DOWN;
24144a2efd4bSViswas G 		if (pm8001_dev)
24154a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2416f5860992SSakthivel K 		break;
2417f5860992SSakthivel K 	case IO_XFER_ERROR_BREAK:
24181b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
2419f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2420f5860992SSakthivel K 		ts->stat = SAS_INTERRUPTED;
24214a2efd4bSViswas G 		if (pm8001_dev)
24224a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2423f5860992SSakthivel K 		break;
2424f5860992SSakthivel K 	case IO_XFER_ERROR_PHY_NOT_READY:
24251b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
2426f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2427f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2428f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
24294a2efd4bSViswas G 		if (pm8001_dev)
24304a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2431f5860992SSakthivel K 		break;
2432f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
24331b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
24341b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
2435f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2436f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2437f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_EPROTO;
24384a2efd4bSViswas G 		if (pm8001_dev)
24394a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2440f5860992SSakthivel K 		break;
2441f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
24421b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
24431b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
2444f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2445f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2446f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
24474a2efd4bSViswas G 		if (pm8001_dev)
24484a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2449f5860992SSakthivel K 		break;
2450f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BREAK:
24511b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
2452f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2453f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2454f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
24554a2efd4bSViswas G 		if (pm8001_dev)
24564a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2457f5860992SSakthivel K 		break;
2458f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2459a6cb3d01SSakthivel K 	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2460a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2461a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2462a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2463a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
24641b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
2465f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2466f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
2467f5860992SSakthivel K 		if (!t->uldd_task) {
2468f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
2469f5860992SSakthivel K 				pm8001_dev,
2470f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2471f5860992SSakthivel K 			ts->resp = SAS_TASK_UNDELIVERED;
2472f5860992SSakthivel K 			ts->stat = SAS_QUEUE_FULL;
2473b27a4053SAjish Koshy 			spin_unlock_irqrestore(&circularQ->oq_lock,
2474b27a4053SAjish Koshy 					circularQ->lock_flags);
2475304fe11bSDamien Le Moal 			pm8001_ccb_task_free_done(pm8001_ha, ccb);
2476b27a4053SAjish Koshy 			spin_lock_irqsave(&circularQ->oq_lock,
2477b27a4053SAjish Koshy 					circularQ->lock_flags);
2478f5860992SSakthivel K 			return;
2479f5860992SSakthivel K 		}
2480f5860992SSakthivel K 		break;
2481f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
24821b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
24831b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
2484f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
2485f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2486f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2487f5860992SSakthivel K 		if (!t->uldd_task) {
2488f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
2489f5860992SSakthivel K 				pm8001_dev,
2490f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2491f5860992SSakthivel K 			ts->resp = SAS_TASK_UNDELIVERED;
2492f5860992SSakthivel K 			ts->stat = SAS_QUEUE_FULL;
2493b27a4053SAjish Koshy 			spin_unlock_irqrestore(&circularQ->oq_lock,
2494b27a4053SAjish Koshy 					circularQ->lock_flags);
2495304fe11bSDamien Le Moal 			pm8001_ccb_task_free_done(pm8001_ha, ccb);
2496b27a4053SAjish Koshy 			spin_lock_irqsave(&circularQ->oq_lock,
2497b27a4053SAjish Koshy 					circularQ->lock_flags);
2498f5860992SSakthivel K 			return;
2499f5860992SSakthivel K 		}
2500f5860992SSakthivel K 		break;
2501f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
25021b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
25031b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
2504f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2505f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2506f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
25074a2efd4bSViswas G 		if (pm8001_dev)
25084a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2509f5860992SSakthivel K 		break;
2510f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
25111b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
25121b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n");
2513f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2514f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
2515f5860992SSakthivel K 		if (!t->uldd_task) {
2516f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
2517f5860992SSakthivel K 				pm8001_dev,
2518f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2519f5860992SSakthivel K 			ts->resp = SAS_TASK_UNDELIVERED;
2520f5860992SSakthivel K 			ts->stat = SAS_QUEUE_FULL;
2521b27a4053SAjish Koshy 			spin_unlock_irqrestore(&circularQ->oq_lock,
2522b27a4053SAjish Koshy 					circularQ->lock_flags);
2523304fe11bSDamien Le Moal 			pm8001_ccb_task_free_done(pm8001_ha, ccb);
2524b27a4053SAjish Koshy 			spin_lock_irqsave(&circularQ->oq_lock,
2525b27a4053SAjish Koshy 					circularQ->lock_flags);
2526f5860992SSakthivel K 			return;
2527f5860992SSakthivel K 		}
2528f5860992SSakthivel K 		break;
2529f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
25301b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
25311b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
2532f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2533f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2534f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
25354a2efd4bSViswas G 		if (pm8001_dev)
25364a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2537f5860992SSakthivel K 		break;
2538f5860992SSakthivel K 	case IO_XFER_ERROR_NAK_RECEIVED:
25391b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
2540f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2541f5860992SSakthivel K 		ts->stat = SAS_NAK_R_ERR;
25424a2efd4bSViswas G 		if (pm8001_dev)
25434a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2544f5860992SSakthivel K 		break;
2545f5860992SSakthivel K 	case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
25461b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
2547f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2548f5860992SSakthivel K 		ts->stat = SAS_NAK_R_ERR;
25494a2efd4bSViswas G 		if (pm8001_dev)
25504a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2551f5860992SSakthivel K 		break;
2552f5860992SSakthivel K 	case IO_XFER_ERROR_DMA:
25531b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
2554f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2555f5860992SSakthivel K 		ts->stat = SAS_ABORTED_TASK;
25564a2efd4bSViswas G 		if (pm8001_dev)
25574a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2558f5860992SSakthivel K 		break;
2559f5860992SSakthivel K 	case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
25601b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n");
2561f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
2562f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
25634a2efd4bSViswas G 		if (pm8001_dev)
25644a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2565f5860992SSakthivel K 		break;
2566f5860992SSakthivel K 	case IO_XFER_ERROR_REJECTED_NCQ_MODE:
25671b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
2568f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2569f5860992SSakthivel K 		ts->stat = SAS_DATA_UNDERRUN;
25704a2efd4bSViswas G 		if (pm8001_dev)
25714a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2572f5860992SSakthivel K 		break;
2573f5860992SSakthivel K 	case IO_XFER_OPEN_RETRY_TIMEOUT:
25741b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
2575f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2576f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
25774a2efd4bSViswas G 		if (pm8001_dev)
25784a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2579f5860992SSakthivel K 		break;
2580f5860992SSakthivel K 	case IO_PORT_IN_RESET:
25811b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
2582f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2583f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
25844a2efd4bSViswas G 		if (pm8001_dev)
25854a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2586f5860992SSakthivel K 		break;
2587f5860992SSakthivel K 	case IO_DS_NON_OPERATIONAL:
25881b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
2589f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2590f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
2591f5860992SSakthivel K 		if (!t->uldd_task) {
2592f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha, pm8001_dev,
2593f5860992SSakthivel K 					IO_DS_NON_OPERATIONAL);
2594f5860992SSakthivel K 			ts->resp = SAS_TASK_UNDELIVERED;
2595f5860992SSakthivel K 			ts->stat = SAS_QUEUE_FULL;
2596b27a4053SAjish Koshy 			spin_unlock_irqrestore(&circularQ->oq_lock,
2597b27a4053SAjish Koshy 					circularQ->lock_flags);
2598304fe11bSDamien Le Moal 			pm8001_ccb_task_free_done(pm8001_ha, ccb);
2599b27a4053SAjish Koshy 			spin_lock_irqsave(&circularQ->oq_lock,
2600b27a4053SAjish Koshy 					circularQ->lock_flags);
2601f5860992SSakthivel K 			return;
2602f5860992SSakthivel K 		}
2603f5860992SSakthivel K 		break;
2604f5860992SSakthivel K 	case IO_DS_IN_RECOVERY:
26051b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
2606f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2607f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
26084a2efd4bSViswas G 		if (pm8001_dev)
26094a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2610f5860992SSakthivel K 		break;
2611f5860992SSakthivel K 	case IO_DS_IN_ERROR:
26121b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n");
2613f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2614f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
2615f5860992SSakthivel K 		if (!t->uldd_task) {
2616f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha, pm8001_dev,
2617f5860992SSakthivel K 					IO_DS_IN_ERROR);
2618f5860992SSakthivel K 			ts->resp = SAS_TASK_UNDELIVERED;
2619f5860992SSakthivel K 			ts->stat = SAS_QUEUE_FULL;
2620b27a4053SAjish Koshy 			spin_unlock_irqrestore(&circularQ->oq_lock,
2621b27a4053SAjish Koshy 					circularQ->lock_flags);
2622304fe11bSDamien Le Moal 			pm8001_ccb_task_free_done(pm8001_ha, ccb);
2623b27a4053SAjish Koshy 			spin_lock_irqsave(&circularQ->oq_lock,
2624b27a4053SAjish Koshy 					circularQ->lock_flags);
2625f5860992SSakthivel K 			return;
2626f5860992SSakthivel K 		}
2627f5860992SSakthivel K 		break;
2628f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
26291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
26301b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
2631f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2632f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2633f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
26344a2efd4bSViswas G 		if (pm8001_dev)
26354a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
263650acde8eSJohannes Thumshirn 		break;
2637f5860992SSakthivel K 	default:
26384f608fbcSVishakha Channapattan 		pm8001_dbg(pm8001_ha, DEVIO,
26394f608fbcSVishakha Channapattan 				"Unknown status device_id %u status 0x%x tag %d\n",
26404f608fbcSVishakha Channapattan 			pm8001_dev->device_id, status, tag);
2641f5860992SSakthivel K 		/* not allowed case. Therefore, return failed status */
2642f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2643f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
26444a2efd4bSViswas G 		if (pm8001_dev)
26454a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2646f5860992SSakthivel K 		break;
2647f5860992SSakthivel K 	}
2648f5860992SSakthivel K 	spin_lock_irqsave(&t->task_state_lock, flags);
2649f5860992SSakthivel K 	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2650f5860992SSakthivel K 	t->task_state_flags |= SAS_TASK_STATE_DONE;
2651f5860992SSakthivel K 	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2652f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
26531b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
26541b5d2793SJoe Perches 			   "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
26551b5d2793SJoe Perches 			   t, status, ts->resp, ts->stat);
2656304fe11bSDamien Le Moal 		pm8001_ccb_task_free(pm8001_ha, ccb);
2657ce21c63eSpeter chang 		if (t->slow_task)
2658ce21c63eSpeter chang 			complete(&t->slow_task->completion);
26592b01d816SSuresh Thiagarajan 	} else {
2660f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
2661b27a4053SAjish Koshy 		spin_unlock_irqrestore(&circularQ->oq_lock,
2662b27a4053SAjish Koshy 				circularQ->lock_flags);
2663304fe11bSDamien Le Moal 		pm8001_ccb_task_free_done(pm8001_ha, ccb);
2664b27a4053SAjish Koshy 		spin_lock_irqsave(&circularQ->oq_lock,
2665b27a4053SAjish Koshy 				circularQ->lock_flags);
2666f5860992SSakthivel K 	}
2667f5860992SSakthivel K }
2668f5860992SSakthivel K 
2669f5860992SSakthivel K /*See the comments for mpi_ssp_completion */
mpi_sata_event(struct pm8001_hba_info * pm8001_ha,struct outbound_queue_table * circularQ,void * piomb)2670b27a4053SAjish Koshy static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha,
2671b27a4053SAjish Koshy 		struct outbound_queue_table *circularQ, void *piomb)
2672f5860992SSakthivel K {
2673f5860992SSakthivel K 	struct sas_task *t;
2674f5860992SSakthivel K 	struct task_status_struct *ts;
2675f5860992SSakthivel K 	struct pm8001_ccb_info *ccb;
2676f5860992SSakthivel K 	struct pm8001_device *pm8001_dev;
2677f5860992SSakthivel K 	struct sata_event_resp *psataPayload =
2678f5860992SSakthivel K 		(struct sata_event_resp *)(piomb + 4);
2679f5860992SSakthivel K 	u32 event = le32_to_cpu(psataPayload->event);
2680f5860992SSakthivel K 	u32 tag = le32_to_cpu(psataPayload->tag);
2681f5860992SSakthivel K 	u32 port_id = le32_to_cpu(psataPayload->port_id);
2682c6b9ef57SSakthivel K 	u32 dev_id = le32_to_cpu(psataPayload->device_id);
2683f5860992SSakthivel K 
2684f5860992SSakthivel K 	if (event)
26851b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
2686c6b9ef57SSakthivel K 
2687c6b9ef57SSakthivel K 	/* Check if this is NCQ error */
2688c6b9ef57SSakthivel K 	if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2689c6b9ef57SSakthivel K 		/* find device using device id */
2690c6b9ef57SSakthivel K 		pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2691811be570SJohn Garry 		/* send read log extension by aborting the link - libata does what we want */
2692c6b9ef57SSakthivel K 		if (pm8001_dev)
2693811be570SJohn Garry 			pm8001_handle_event(pm8001_ha,
2694811be570SJohn Garry 				pm8001_dev,
2695811be570SJohn Garry 				IO_XFER_ERROR_ABORTED_NCQ_MODE);
2696f5860992SSakthivel K 		return;
2697c6b9ef57SSakthivel K 	}
2698c6b9ef57SSakthivel K 
269960de1a67SIgor Pylypiv 	ccb = &pm8001_ha->ccb_info[tag];
270060de1a67SIgor Pylypiv 	t = ccb->task;
270160de1a67SIgor Pylypiv 	pm8001_dev = ccb->device;
27020b639decSJohn Garry 	if (unlikely(!t)) {
27030b639decSJohn Garry 		pm8001_dbg(pm8001_ha, FAIL, "task null, freeing CCB tag %d\n",
27040b639decSJohn Garry 			   ccb->ccb_tag);
27050b639decSJohn Garry 		pm8001_ccb_free(pm8001_ha, ccb);
2706c6b9ef57SSakthivel K 		return;
2707c6b9ef57SSakthivel K 	}
2708c6b9ef57SSakthivel K 
27090b639decSJohn Garry 	if (unlikely(!t->lldd_task || !t->dev))
27100b639decSJohn Garry 		return;
27110b639decSJohn Garry 
2712f5860992SSakthivel K 	ts = &t->task_status;
27131b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IOERR, "port_id:0x%x, tag:0x%x, event:0x%x\n",
27141b5d2793SJoe Perches 		   port_id, tag, event);
2715f5860992SSakthivel K 	switch (event) {
2716f5860992SSakthivel K 	case IO_OVERFLOW:
27171b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
2718f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2719f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2720f5860992SSakthivel K 		ts->residual = 0;
2721f5860992SSakthivel K 		break;
2722f5860992SSakthivel K 	case IO_XFER_ERROR_BREAK:
27231b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
2724f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2725f5860992SSakthivel K 		ts->stat = SAS_INTERRUPTED;
2726f5860992SSakthivel K 		break;
2727f5860992SSakthivel K 	case IO_XFER_ERROR_PHY_NOT_READY:
27281b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
2729f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2730f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2731f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2732f5860992SSakthivel K 		break;
2733f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
27341b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
27351b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
2736f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2737f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2738f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_EPROTO;
2739f5860992SSakthivel K 		break;
2740f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
27411b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
27421b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
2743f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2744f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2745f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2746f5860992SSakthivel K 		break;
2747f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BREAK:
27481b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
2749f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2750f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2751f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2752f5860992SSakthivel K 		break;
2753f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2754a6cb3d01SSakthivel K 	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2755a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2756a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2757a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2758a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
27591b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
27601b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
2761f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
2762f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
2763f5860992SSakthivel K 		if (!t->uldd_task) {
2764f5860992SSakthivel K 			pm8001_handle_event(pm8001_ha,
2765f5860992SSakthivel K 				pm8001_dev,
2766f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2767f5860992SSakthivel K 			ts->resp = SAS_TASK_COMPLETE;
2768f5860992SSakthivel K 			ts->stat = SAS_QUEUE_FULL;
2769f5860992SSakthivel K 			return;
2770f5860992SSakthivel K 		}
2771f5860992SSakthivel K 		break;
2772f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
27731b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
27741b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
2775f5860992SSakthivel K 		ts->resp = SAS_TASK_UNDELIVERED;
2776f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2777f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2778f5860992SSakthivel K 		break;
2779f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
27801b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
27811b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
2782f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2783f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2784f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2785f5860992SSakthivel K 		break;
2786f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
27871b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
27881b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
2789f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2790f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2791f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2792f5860992SSakthivel K 		break;
2793f5860992SSakthivel K 	case IO_XFER_ERROR_NAK_RECEIVED:
27941b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
2795f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2796f5860992SSakthivel K 		ts->stat = SAS_NAK_R_ERR;
2797f5860992SSakthivel K 		break;
2798f5860992SSakthivel K 	case IO_XFER_ERROR_PEER_ABORTED:
27991b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n");
2800f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2801f5860992SSakthivel K 		ts->stat = SAS_NAK_R_ERR;
2802f5860992SSakthivel K 		break;
2803f5860992SSakthivel K 	case IO_XFER_ERROR_REJECTED_NCQ_MODE:
28041b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
2805f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2806f5860992SSakthivel K 		ts->stat = SAS_DATA_UNDERRUN;
2807f5860992SSakthivel K 		break;
2808f5860992SSakthivel K 	case IO_XFER_OPEN_RETRY_TIMEOUT:
28091b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
2810f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2811f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2812f5860992SSakthivel K 		break;
2813f5860992SSakthivel K 	case IO_XFER_ERROR_UNEXPECTED_PHASE:
28141b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
2815f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2816f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2817f5860992SSakthivel K 		break;
2818f5860992SSakthivel K 	case IO_XFER_ERROR_XFER_RDY_OVERRUN:
28191b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
2820f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2821f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2822f5860992SSakthivel K 		break;
2823f5860992SSakthivel K 	case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
28241b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
28251b5d2793SJoe Perches 			   "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
2826f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2827f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2828f5860992SSakthivel K 		break;
2829f5860992SSakthivel K 	case IO_XFER_ERROR_OFFSET_MISMATCH:
28301b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
2831f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2832f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2833f5860992SSakthivel K 		break;
2834f5860992SSakthivel K 	case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
28351b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
28361b5d2793SJoe Perches 			   "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
2837f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2838f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2839f5860992SSakthivel K 		break;
2840f5860992SSakthivel K 	case IO_XFER_CMD_FRAME_ISSUED:
28411b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
2842f5860992SSakthivel K 		break;
2843f5860992SSakthivel K 	case IO_XFER_PIO_SETUP_ERROR:
28441b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n");
2845f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2846f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2847f5860992SSakthivel K 		break;
2848a6cb3d01SSakthivel K 	case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
28491b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
28501b5d2793SJoe Perches 			   "IO_XFR_ERROR_INTERNAL_CRC_ERROR\n");
2851a6cb3d01SSakthivel K 		/* TBC: used default set values */
2852a6cb3d01SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2853a6cb3d01SSakthivel K 		ts->stat = SAS_OPEN_TO;
2854a6cb3d01SSakthivel K 		break;
2855a6cb3d01SSakthivel K 	case IO_XFER_DMA_ACTIVATE_TIMEOUT:
28561b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "IO_XFR_DMA_ACTIVATE_TIMEOUT\n");
2857a6cb3d01SSakthivel K 		/* TBC: used default set values */
2858a6cb3d01SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2859a6cb3d01SSakthivel K 		ts->stat = SAS_OPEN_TO;
2860a6cb3d01SSakthivel K 		break;
2861f5860992SSakthivel K 	default:
28621b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "Unknown status 0x%x\n", event);
2863f5860992SSakthivel K 		/* not allowed case. Therefore, return failed status */
2864f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2865f5860992SSakthivel K 		ts->stat = SAS_OPEN_TO;
2866f5860992SSakthivel K 		break;
2867f5860992SSakthivel K 	}
2868f5860992SSakthivel K }
2869f5860992SSakthivel K 
2870f5860992SSakthivel K /*See the comments for mpi_ssp_completion */
2871f5860992SSakthivel K static void
mpi_smp_completion(struct pm8001_hba_info * pm8001_ha,void * piomb)2872f5860992SSakthivel K mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2873f5860992SSakthivel K {
2874f5860992SSakthivel K 	u32 param, i;
2875f5860992SSakthivel K 	struct sas_task *t;
2876f5860992SSakthivel K 	struct pm8001_ccb_info *ccb;
2877f5860992SSakthivel K 	unsigned long flags;
2878f5860992SSakthivel K 	u32 status;
2879f5860992SSakthivel K 	u32 tag;
2880f5860992SSakthivel K 	struct smp_completion_resp *psmpPayload;
2881f5860992SSakthivel K 	struct task_status_struct *ts;
2882f5860992SSakthivel K 	struct pm8001_device *pm8001_dev;
2883f5860992SSakthivel K 
2884f5860992SSakthivel K 	psmpPayload = (struct smp_completion_resp *)(piomb + 4);
2885f5860992SSakthivel K 	status = le32_to_cpu(psmpPayload->status);
2886f5860992SSakthivel K 	tag = le32_to_cpu(psmpPayload->tag);
2887f5860992SSakthivel K 
2888f5860992SSakthivel K 	ccb = &pm8001_ha->ccb_info[tag];
2889f5860992SSakthivel K 	param = le32_to_cpu(psmpPayload->param);
2890f5860992SSakthivel K 	t = ccb->task;
2891f5860992SSakthivel K 	ts = &t->task_status;
2892f5860992SSakthivel K 	pm8001_dev = ccb->device;
2893f5860992SSakthivel K 	if (status)
28941b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status);
2895f5860992SSakthivel K 	if (unlikely(!t || !t->lldd_task || !t->dev))
2896f5860992SSakthivel K 		return;
2897f5860992SSakthivel K 
28981b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV, "tag::0x%x status::0x%x\n", tag, status);
28997370672dSpeter chang 
2900f5860992SSakthivel K 	switch (status) {
2901f5860992SSakthivel K 
2902f5860992SSakthivel K 	case IO_SUCCESS:
29031b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
2904f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2905d377f415SBart Van Assche 		ts->stat = SAS_SAM_STAT_GOOD;
2906f5860992SSakthivel K 		if (pm8001_dev)
29074a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2908f5860992SSakthivel K 		if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
29092fe24343SJohn Garry 			struct scatterlist *sg_resp = &t->smp_task.smp_resp;
29102fe24343SJohn Garry 			u8 *payload;
29112fe24343SJohn Garry 			void *to;
29122fe24343SJohn Garry 
29131b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, IO,
29141b5d2793SJoe Perches 				   "DIRECT RESPONSE Length:%d\n",
29151b5d2793SJoe Perches 				   param);
29162fe24343SJohn Garry 			to = kmap_atomic(sg_page(sg_resp));
29172fe24343SJohn Garry 			payload = to + sg_resp->offset;
2918f5860992SSakthivel K 			for (i = 0; i < param; i++) {
29192fe24343SJohn Garry 				*(payload + i) = psmpPayload->_r_a[i];
29201b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO,
2921f5860992SSakthivel K 					   "SMP Byte%d DMA data 0x%x psmp 0x%x\n",
29222fe24343SJohn Garry 					   i, *(payload + i),
29231b5d2793SJoe Perches 					   psmpPayload->_r_a[i]);
2924f5860992SSakthivel K 			}
29252fe24343SJohn Garry 			kunmap_atomic(to);
2926f5860992SSakthivel K 		}
2927f5860992SSakthivel K 		break;
2928f5860992SSakthivel K 	case IO_ABORTED:
29291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n");
2930f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2931f5860992SSakthivel K 		ts->stat = SAS_ABORTED_TASK;
2932f5860992SSakthivel K 		if (pm8001_dev)
29334a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2934f5860992SSakthivel K 		break;
2935f5860992SSakthivel K 	case IO_OVERFLOW:
29361b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
2937f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2938f5860992SSakthivel K 		ts->stat = SAS_DATA_OVERRUN;
2939f5860992SSakthivel K 		ts->residual = 0;
2940f5860992SSakthivel K 		if (pm8001_dev)
29414a2efd4bSViswas G 			atomic_dec(&pm8001_dev->running_req);
2942f5860992SSakthivel K 		break;
2943f5860992SSakthivel K 	case IO_NO_DEVICE:
29441b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
2945f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2946f5860992SSakthivel K 		ts->stat = SAS_PHY_DOWN;
2947f5860992SSakthivel K 		break;
2948f5860992SSakthivel K 	case IO_ERROR_HW_TIMEOUT:
29491b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\n");
2950f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2951d377f415SBart Van Assche 		ts->stat = SAS_SAM_STAT_BUSY;
2952f5860992SSakthivel K 		break;
2953f5860992SSakthivel K 	case IO_XFER_ERROR_BREAK:
29541b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
2955f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2956d377f415SBart Van Assche 		ts->stat = SAS_SAM_STAT_BUSY;
2957f5860992SSakthivel K 		break;
2958f5860992SSakthivel K 	case IO_XFER_ERROR_PHY_NOT_READY:
29591b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
2960f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2961d377f415SBart Van Assche 		ts->stat = SAS_SAM_STAT_BUSY;
2962f5860992SSakthivel K 		break;
2963f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
29641b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
29651b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
2966f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2967f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2968f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2969f5860992SSakthivel K 		break;
2970f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
29711b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
29721b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
2973f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2974f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2975f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2976f5860992SSakthivel K 		break;
2977f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BREAK:
29781b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
2979f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2980f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2981f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2982f5860992SSakthivel K 		break;
2983f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2984a6cb3d01SSakthivel K 	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2985a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2986a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2987a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2988a6cb3d01SSakthivel K 	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
29891b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
2990f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
2991f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
2992f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2993f5860992SSakthivel K 		pm8001_handle_event(pm8001_ha,
2994f5860992SSakthivel K 				pm8001_dev,
2995f5860992SSakthivel K 				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2996f5860992SSakthivel K 		break;
2997f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
29981b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
29991b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
3000f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3001f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3002f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
3003f5860992SSakthivel K 		break;
3004f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
30051b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
30061b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
3007f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3008f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3009f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
3010f5860992SSakthivel K 		break;
3011f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
30121b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
30131b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
3014f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3015f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3016f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
3017f5860992SSakthivel K 		break;
3018f5860992SSakthivel K 	case IO_XFER_ERROR_RX_FRAME:
30191b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n");
3020f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3021f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
3022f5860992SSakthivel K 		break;
3023f5860992SSakthivel K 	case IO_XFER_OPEN_RETRY_TIMEOUT:
30241b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
3025f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3026f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3027f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3028f5860992SSakthivel K 		break;
3029f5860992SSakthivel K 	case IO_ERROR_INTERNAL_SMP_RESOURCE:
30301b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n");
3031f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3032f5860992SSakthivel K 		ts->stat = SAS_QUEUE_FULL;
3033f5860992SSakthivel K 		break;
3034f5860992SSakthivel K 	case IO_PORT_IN_RESET:
30351b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
3036f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3037f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3038f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3039f5860992SSakthivel K 		break;
3040f5860992SSakthivel K 	case IO_DS_NON_OPERATIONAL:
30411b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
3042f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3043f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
3044f5860992SSakthivel K 		break;
3045f5860992SSakthivel K 	case IO_DS_IN_RECOVERY:
30461b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
3047f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3048f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3049f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3050f5860992SSakthivel K 		break;
3051f5860992SSakthivel K 	case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
30521b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
30531b5d2793SJoe Perches 			   "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
3054f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3055f5860992SSakthivel K 		ts->stat = SAS_OPEN_REJECT;
3056f5860992SSakthivel K 		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3057f5860992SSakthivel K 		break;
3058f5860992SSakthivel K 	default:
30591b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
3060f5860992SSakthivel K 		ts->resp = SAS_TASK_COMPLETE;
3061f5860992SSakthivel K 		ts->stat = SAS_DEV_NO_RESPONSE;
3062f5860992SSakthivel K 		/* not allowed case. Therefore, return failed status */
3063f5860992SSakthivel K 		break;
3064f5860992SSakthivel K 	}
3065f5860992SSakthivel K 	spin_lock_irqsave(&t->task_state_lock, flags);
3066f5860992SSakthivel K 	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3067f5860992SSakthivel K 	t->task_state_flags |= SAS_TASK_STATE_DONE;
3068f5860992SSakthivel K 	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3069f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
30701b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
30711b5d2793SJoe Perches 			   "task 0x%p done with io_status 0x%x resp 0x%xstat 0x%x but aborted by upper layer!\n",
30721b5d2793SJoe Perches 			   t, status, ts->resp, ts->stat);
3073304fe11bSDamien Le Moal 		pm8001_ccb_task_free(pm8001_ha, ccb);
3074f5860992SSakthivel K 	} else {
3075f5860992SSakthivel K 		spin_unlock_irqrestore(&t->task_state_lock, flags);
3076304fe11bSDamien Le Moal 		pm8001_ccb_task_free(pm8001_ha, ccb);
3077f5860992SSakthivel K 		mb();/* in order to force CPU ordering */
3078f5860992SSakthivel K 		t->task_done(t);
3079f5860992SSakthivel K 	}
3080f5860992SSakthivel K }
3081f5860992SSakthivel K 
3082f5860992SSakthivel K /**
3083bb6beabfSRandy Dunlap  * pm80xx_hw_event_ack_req- For PM8001, some events need to acknowledge to FW.
3084f5860992SSakthivel K  * @pm8001_ha: our hba card information
3085f5860992SSakthivel K  * @Qnum: the outbound queue message number.
3086f5860992SSakthivel K  * @SEA: source of event to ack
3087f5860992SSakthivel K  * @port_id: port id.
3088f5860992SSakthivel K  * @phyId: phy id.
3089f5860992SSakthivel K  * @param0: parameter 0.
3090f5860992SSakthivel K  * @param1: parameter 1.
3091f5860992SSakthivel K  */
pm80xx_hw_event_ack_req(struct pm8001_hba_info * pm8001_ha,u32 Qnum,u32 SEA,u32 port_id,u32 phyId,u32 param0,u32 param1)3092f5860992SSakthivel K static void pm80xx_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3093f5860992SSakthivel K 	u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3094f5860992SSakthivel K {
3095f5860992SSakthivel K 	struct hw_event_ack_req	 payload;
3096f5860992SSakthivel K 	u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3097f5860992SSakthivel K 
3098f5860992SSakthivel K 	memset((u8 *)&payload, 0, sizeof(payload));
3099f5860992SSakthivel K 	payload.tag = cpu_to_le32(1);
3100f5860992SSakthivel K 	payload.phyid_sea_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3101f5860992SSakthivel K 		((phyId & 0xFF) << 24) | (port_id & 0xFF));
3102f5860992SSakthivel K 	payload.param0 = cpu_to_le32(param0);
3103f5860992SSakthivel K 	payload.param1 = cpu_to_le32(param1);
3104f91767a3SDamien Le Moal 
3105f91767a3SDamien Le Moal 	pm8001_mpi_build_cmd(pm8001_ha, Qnum, opc, &payload,
310691a43fa6Speter chang 			     sizeof(payload), 0);
3107f5860992SSakthivel K }
3108f5860992SSakthivel K 
3109f5860992SSakthivel K static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3110f5860992SSakthivel K 	u32 phyId, u32 phy_op);
3111f5860992SSakthivel K 
hw_event_port_recover(struct pm8001_hba_info * pm8001_ha,void * piomb)31128414cd80SViswas G static void hw_event_port_recover(struct pm8001_hba_info *pm8001_ha,
31138414cd80SViswas G 					void *piomb)
31148414cd80SViswas G {
31158414cd80SViswas G 	struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4);
31168414cd80SViswas G 	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
31178414cd80SViswas G 	u8 phy_id = (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
31188414cd80SViswas G 	u32 lr_status_evt_portid =
31198414cd80SViswas G 		le32_to_cpu(pPayload->lr_status_evt_portid);
31208414cd80SViswas G 	u8 deviceType = pPayload->sas_identify.dev_type;
31218414cd80SViswas G 	u8 link_rate = (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
31228414cd80SViswas G 	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
31238414cd80SViswas G 	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
31248414cd80SViswas G 	struct pm8001_port *port = &pm8001_ha->port[port_id];
31258414cd80SViswas G 
31268414cd80SViswas G 	if (deviceType == SAS_END_DEVICE) {
31278414cd80SViswas G 		pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
31288414cd80SViswas G 					PHY_NOTIFY_ENABLE_SPINUP);
31298414cd80SViswas G 	}
31308414cd80SViswas G 
31318414cd80SViswas G 	port->wide_port_phymap |= (1U << phy_id);
31328414cd80SViswas G 	pm8001_get_lrate_mode(phy, link_rate);
31338414cd80SViswas G 	phy->sas_phy.oob_mode = SAS_OOB_MODE;
31348414cd80SViswas G 	phy->phy_state = PHY_STATE_LINK_UP_SPCV;
31358414cd80SViswas G 	phy->phy_attached = 1;
31368414cd80SViswas G }
31378414cd80SViswas G 
3138f5860992SSakthivel K /**
3139f5860992SSakthivel K  * hw_event_sas_phy_up - FW tells me a SAS phy up event.
3140f5860992SSakthivel K  * @pm8001_ha: our hba card information
3141f5860992SSakthivel K  * @piomb: IO message buffer
3142f5860992SSakthivel K  */
3143f5860992SSakthivel K static void
hw_event_sas_phy_up(struct pm8001_hba_info * pm8001_ha,void * piomb)3144f5860992SSakthivel K hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3145f5860992SSakthivel K {
3146f5860992SSakthivel K 	struct hw_event_resp *pPayload =
3147f5860992SSakthivel K 		(struct hw_event_resp *)(piomb + 4);
3148f5860992SSakthivel K 	u32 lr_status_evt_portid =
3149f5860992SSakthivel K 		le32_to_cpu(pPayload->lr_status_evt_portid);
3150f5860992SSakthivel K 	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3151f5860992SSakthivel K 
3152f5860992SSakthivel K 	u8 link_rate =
3153f5860992SSakthivel K 		(u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3154f5860992SSakthivel K 	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3155f5860992SSakthivel K 	u8 phy_id =
3156f5860992SSakthivel K 		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3157f5860992SSakthivel K 	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3158f5860992SSakthivel K 
3159f5860992SSakthivel K 	struct pm8001_port *port = &pm8001_ha->port[port_id];
3160f5860992SSakthivel K 	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3161f5860992SSakthivel K 	unsigned long flags;
3162f5860992SSakthivel K 	u8 deviceType = pPayload->sas_identify.dev_type;
316308d0a992SAjish Koshy 	phy->port = port;
316408d0a992SAjish Koshy 	port->port_id = port_id;
3165f5860992SSakthivel K 	port->port_state = portstate;
31668414cd80SViswas G 	port->wide_port_phymap |= (1U << phy_id);
31677d029005SNikith Ganigarakoppal 	phy->phy_state = PHY_STATE_LINK_UP_SPCV;
31681b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG,
31691b5d2793SJoe Perches 		   "portid:%d; phyid:%d; linkrate:%d; portstate:%x; devicetype:%x\n",
31701b5d2793SJoe Perches 		   port_id, phy_id, link_rate, portstate, deviceType);
3171f5860992SSakthivel K 
3172f5860992SSakthivel K 	switch (deviceType) {
3173f5860992SSakthivel K 	case SAS_PHY_UNUSED:
31741b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "device type no device.\n");
3175f5860992SSakthivel K 		break;
3176f5860992SSakthivel K 	case SAS_END_DEVICE:
31771b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "end device.\n");
3178f5860992SSakthivel K 		pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
3179f5860992SSakthivel K 			PHY_NOTIFY_ENABLE_SPINUP);
3180f5860992SSakthivel K 		port->port_attached = 1;
3181f5860992SSakthivel K 		pm8001_get_lrate_mode(phy, link_rate);
3182f5860992SSakthivel K 		break;
3183f5860992SSakthivel K 	case SAS_EDGE_EXPANDER_DEVICE:
31841b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "expander device.\n");
3185f5860992SSakthivel K 		port->port_attached = 1;
3186f5860992SSakthivel K 		pm8001_get_lrate_mode(phy, link_rate);
3187f5860992SSakthivel K 		break;
3188f5860992SSakthivel K 	case SAS_FANOUT_EXPANDER_DEVICE:
31891b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n");
3190f5860992SSakthivel K 		port->port_attached = 1;
3191f5860992SSakthivel K 		pm8001_get_lrate_mode(phy, link_rate);
3192f5860992SSakthivel K 		break;
3193f5860992SSakthivel K 	default:
31941b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n",
31951b5d2793SJoe Perches 			   deviceType);
3196f5860992SSakthivel K 		break;
3197f5860992SSakthivel K 	}
3198f5860992SSakthivel K 	phy->phy_type |= PORT_TYPE_SAS;
3199f5860992SSakthivel K 	phy->identify.device_type = deviceType;
3200f5860992SSakthivel K 	phy->phy_attached = 1;
3201f5860992SSakthivel K 	if (phy->identify.device_type == SAS_END_DEVICE)
3202f5860992SSakthivel K 		phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
3203f5860992SSakthivel K 	else if (phy->identify.device_type != SAS_PHY_UNUSED)
3204f5860992SSakthivel K 		phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3205f5860992SSakthivel K 	phy->sas_phy.oob_mode = SAS_OOB_MODE;
3206de6d7547SAhmed S. Darwish 	sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
3207f5860992SSakthivel K 	spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3208f5860992SSakthivel K 	memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3209f5860992SSakthivel K 		sizeof(struct sas_identify_frame)-4);
3210f5860992SSakthivel K 	phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3211f5860992SSakthivel K 	pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3212f5860992SSakthivel K 	spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3213f5860992SSakthivel K 	if (pm8001_ha->flags == PM8001F_RUN_TIME)
32144ba9e516SAhmed S. Darwish 		mdelay(200); /* delay a moment to wait for disk to spin up */
3215f5860992SSakthivel K 	pm8001_bytes_dmaed(pm8001_ha, phy_id);
3216f5860992SSakthivel K }
3217f5860992SSakthivel K 
3218f5860992SSakthivel K /**
3219f5860992SSakthivel K  * hw_event_sata_phy_up - FW tells me a SATA phy up event.
3220f5860992SSakthivel K  * @pm8001_ha: our hba card information
3221f5860992SSakthivel K  * @piomb: IO message buffer
3222f5860992SSakthivel K  */
3223f5860992SSakthivel K static void
hw_event_sata_phy_up(struct pm8001_hba_info * pm8001_ha,void * piomb)3224f5860992SSakthivel K hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3225f5860992SSakthivel K {
3226f5860992SSakthivel K 	struct hw_event_resp *pPayload =
3227f5860992SSakthivel K 		(struct hw_event_resp *)(piomb + 4);
3228f5860992SSakthivel K 	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3229f5860992SSakthivel K 	u32 lr_status_evt_portid =
3230f5860992SSakthivel K 		le32_to_cpu(pPayload->lr_status_evt_portid);
3231f5860992SSakthivel K 	u8 link_rate =
3232f5860992SSakthivel K 		(u8)((lr_status_evt_portid & 0xF0000000) >> 28);
3233f5860992SSakthivel K 	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3234f5860992SSakthivel K 	u8 phy_id =
3235f5860992SSakthivel K 		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3236f5860992SSakthivel K 
3237f5860992SSakthivel K 	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3238f5860992SSakthivel K 
3239f5860992SSakthivel K 	struct pm8001_port *port = &pm8001_ha->port[port_id];
3240f5860992SSakthivel K 	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3241f5860992SSakthivel K 	unsigned long flags;
3242d309422dSAkshat Jain 	pm8001_dbg(pm8001_ha, EVENT,
3243d309422dSAkshat Jain 		   "HW_EVENT_SATA_PHY_UP phyid:%#x port_id:%#x link_rate:%d portstate:%#x\n",
3244d309422dSAkshat Jain 		   phy_id, port_id, link_rate, portstate);
3245f5860992SSakthivel K 
324608d0a992SAjish Koshy 	phy->port = port;
324708d0a992SAjish Koshy 	port->port_id = port_id;
3248f5860992SSakthivel K 	port->port_state = portstate;
32497d029005SNikith Ganigarakoppal 	phy->phy_state = PHY_STATE_LINK_UP_SPCV;
3250f5860992SSakthivel K 	port->port_attached = 1;
3251f5860992SSakthivel K 	pm8001_get_lrate_mode(phy, link_rate);
3252f5860992SSakthivel K 	phy->phy_type |= PORT_TYPE_SATA;
3253f5860992SSakthivel K 	phy->phy_attached = 1;
3254f5860992SSakthivel K 	phy->sas_phy.oob_mode = SATA_OOB_MODE;
3255de6d7547SAhmed S. Darwish 	sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
3256f5860992SSakthivel K 	spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3257f5860992SSakthivel K 	memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3258f5860992SSakthivel K 		sizeof(struct dev_to_host_fis));
3259f5860992SSakthivel K 	phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3260f5860992SSakthivel K 	phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
3261aa9f8328SJames Bottomley 	phy->identify.device_type = SAS_SATA_DEV;
3262f5860992SSakthivel K 	pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3263f5860992SSakthivel K 	spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3264f5860992SSakthivel K 	pm8001_bytes_dmaed(pm8001_ha, phy_id);
3265f5860992SSakthivel K }
3266f5860992SSakthivel K 
3267f5860992SSakthivel K /**
3268f5860992SSakthivel K  * hw_event_phy_down - we should notify the libsas the phy is down.
3269f5860992SSakthivel K  * @pm8001_ha: our hba card information
3270f5860992SSakthivel K  * @piomb: IO message buffer
3271f5860992SSakthivel K  */
3272f5860992SSakthivel K static void
hw_event_phy_down(struct pm8001_hba_info * pm8001_ha,void * piomb)3273f5860992SSakthivel K hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3274f5860992SSakthivel K {
3275f5860992SSakthivel K 	struct hw_event_resp *pPayload =
3276f5860992SSakthivel K 		(struct hw_event_resp *)(piomb + 4);
3277f5860992SSakthivel K 
3278f5860992SSakthivel K 	u32 lr_status_evt_portid =
3279f5860992SSakthivel K 		le32_to_cpu(pPayload->lr_status_evt_portid);
3280f5860992SSakthivel K 	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3281f5860992SSakthivel K 	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3282f5860992SSakthivel K 	u8 phy_id =
3283f5860992SSakthivel K 		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3284f5860992SSakthivel K 	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3285f5860992SSakthivel K 
3286f5860992SSakthivel K 	struct pm8001_port *port = &pm8001_ha->port[port_id];
3287f5860992SSakthivel K 	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3288869ddbdcSViswas G 	u32 port_sata = (phy->phy_type & PORT_TYPE_SATA);
3289f5860992SSakthivel K 	port->port_state = portstate;
3290f5860992SSakthivel K 	phy->identify.device_type = 0;
3291f5860992SSakthivel K 	phy->phy_attached = 0;
3292f5860992SSakthivel K 	switch (portstate) {
3293f5860992SSakthivel K 	case PORT_VALID:
3294d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3295d309422dSAkshat Jain 			"HW_EVENT_PHY_DOWN phyid:%#x port_id:%#x portstate: PORT_VALID\n",
3296d309422dSAkshat Jain 			phy_id, port_id);
3297f5860992SSakthivel K 		break;
3298f5860992SSakthivel K 	case PORT_INVALID:
3299d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3300d309422dSAkshat Jain 			"HW_EVENT_PHY_DOWN phyid:%#x port_id:%#x portstate: PORT_INVALID\n",
3301d309422dSAkshat Jain 			phy_id, port_id);
33021b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
33031b5d2793SJoe Perches 			   " Last phy Down and port invalid\n");
3304869ddbdcSViswas G 		if (port_sata) {
33058414cd80SViswas G 			phy->phy_type = 0;
3306f5860992SSakthivel K 			port->port_attached = 0;
3307f5860992SSakthivel K 			pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3308f5860992SSakthivel K 					port_id, phy_id, 0, 0);
33098414cd80SViswas G 		}
33108414cd80SViswas G 		sas_phy_disconnected(&phy->sas_phy);
3311f5860992SSakthivel K 		break;
3312f5860992SSakthivel K 	case PORT_IN_RESET:
3313d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3314d309422dSAkshat Jain 			"HW_EVENT_PHY_DOWN phyid:%#x port_id:%#x portstate: PORT_IN_RESET\n",
3315d309422dSAkshat Jain 			phy_id, port_id);
3316f5860992SSakthivel K 		break;
3317f5860992SSakthivel K 	case PORT_NOT_ESTABLISHED:
3318d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3319d309422dSAkshat Jain 			"HW_EVENT_PHY_DOWN phyid:%#x port_id:%#x portstate: PORT_NOT_ESTABLISHED\n",
3320d309422dSAkshat Jain 			phy_id, port_id);
3321f5860992SSakthivel K 		port->port_attached = 0;
3322f5860992SSakthivel K 		break;
3323f5860992SSakthivel K 	case PORT_LOSTCOMM:
3324d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3325d309422dSAkshat Jain 			"HW_EVENT_PHY_DOWN phyid:%#x port_id:%#x portstate: PORT_LOSTCOMM\n",
3326d309422dSAkshat Jain 			phy_id, port_id);
3327d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, MSG, " Last phy Down and port invalid\n");
3328869ddbdcSViswas G 		if (port_sata) {
3329f5860992SSakthivel K 			port->port_attached = 0;
33308414cd80SViswas G 			phy->phy_type = 0;
3331f5860992SSakthivel K 			pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3332f5860992SSakthivel K 					port_id, phy_id, 0, 0);
33338414cd80SViswas G 		}
33348414cd80SViswas G 		sas_phy_disconnected(&phy->sas_phy);
3335f5860992SSakthivel K 		break;
3336f5860992SSakthivel K 	default:
3337f5860992SSakthivel K 		port->port_attached = 0;
3338d309422dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3339d309422dSAkshat Jain 			"HW_EVENT_PHY_DOWN phyid:%#x port_id:%#x portstate:%#x\n",
3340d309422dSAkshat Jain 			phy_id, port_id, portstate);
3341f5860992SSakthivel K 		break;
3342f5860992SSakthivel K 
3343f5860992SSakthivel K 	}
3344121181f3SJohn Garry 	if (port_sata && (portstate != PORT_IN_RESET))
3345de6d7547SAhmed S. Darwish 		sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL,
3346cd4e8176SAhmed S. Darwish 				GFP_ATOMIC);
3347f5860992SSakthivel K }
3348f5860992SSakthivel K 
mpi_phy_start_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3349f5860992SSakthivel K static int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3350f5860992SSakthivel K {
3351f5860992SSakthivel K 	struct phy_start_resp *pPayload =
3352f5860992SSakthivel K 		(struct phy_start_resp *)(piomb + 4);
3353f5860992SSakthivel K 	u32 status =
3354f5860992SSakthivel K 		le32_to_cpu(pPayload->status);
3355f5860992SSakthivel K 	u32 phy_id =
3356744798fcSIgor Pylypiv 		le32_to_cpu(pPayload->phyid) & 0xFF;
3357f5860992SSakthivel K 	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3358f5860992SSakthivel K 
33591b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT,
33601b5d2793SJoe Perches 		   "phy start resp status:0x%x, phyid:0x%x\n",
33611b5d2793SJoe Perches 		   status, phy_id);
3362d1acd81bSAjish Koshy 	if (status == 0)
3363cd135754SDeepak Ukey 		phy->phy_state = PHY_LINK_DOWN;
3364d1acd81bSAjish Koshy 
3365cd135754SDeepak Ukey 	if (pm8001_ha->flags == PM8001F_RUN_TIME &&
3366e703977bSpeter chang 			phy->enable_completion != NULL) {
3367f5860992SSakthivel K 		complete(phy->enable_completion);
3368e703977bSpeter chang 		phy->enable_completion = NULL;
3369e703977bSpeter chang 	}
3370f5860992SSakthivel K 	return 0;
3371f5860992SSakthivel K 
3372f5860992SSakthivel K }
3373f5860992SSakthivel K 
3374f5860992SSakthivel K /**
3375bb6beabfSRandy Dunlap  * mpi_thermal_hw_event - a thermal hw event has come.
3376f5860992SSakthivel K  * @pm8001_ha: our hba card information
3377f5860992SSakthivel K  * @piomb: IO message buffer
3378f5860992SSakthivel K  */
mpi_thermal_hw_event(struct pm8001_hba_info * pm8001_ha,void * piomb)3379f5860992SSakthivel K static int mpi_thermal_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3380f5860992SSakthivel K {
3381f5860992SSakthivel K 	struct thermal_hw_event *pPayload =
3382f5860992SSakthivel K 		(struct thermal_hw_event *)(piomb + 4);
3383f5860992SSakthivel K 
3384f5860992SSakthivel K 	u32 thermal_event = le32_to_cpu(pPayload->thermal_event);
3385f5860992SSakthivel K 	u32 rht_lht = le32_to_cpu(pPayload->rht_lht);
3386f5860992SSakthivel K 
3387f5860992SSakthivel K 	if (thermal_event & 0x40) {
33881b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
33891b5d2793SJoe Perches 			   "Thermal Event: Local high temperature violated!\n");
33901b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
3391f5860992SSakthivel K 			   "Thermal Event: Measured local high temperature %d\n",
33921b5d2793SJoe Perches 			   ((rht_lht & 0xFF00) >> 8));
3393f5860992SSakthivel K 	}
3394f5860992SSakthivel K 	if (thermal_event & 0x10) {
33951b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
33961b5d2793SJoe Perches 			   "Thermal Event: Remote high temperature violated!\n");
33971b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
3398f5860992SSakthivel K 			   "Thermal Event: Measured remote high temperature %d\n",
33991b5d2793SJoe Perches 			   ((rht_lht & 0xFF000000) >> 24));
3400f5860992SSakthivel K 	}
3401f5860992SSakthivel K 	return 0;
3402f5860992SSakthivel K }
3403f5860992SSakthivel K 
3404f5860992SSakthivel K /**
3405f5860992SSakthivel K  * mpi_hw_event - The hw event has come.
3406f5860992SSakthivel K  * @pm8001_ha: our hba card information
3407f5860992SSakthivel K  * @piomb: IO message buffer
3408f5860992SSakthivel K  */
mpi_hw_event(struct pm8001_hba_info * pm8001_ha,void * piomb)3409f5860992SSakthivel K static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3410f5860992SSakthivel K {
34118414cd80SViswas G 	unsigned long flags, i;
3412f5860992SSakthivel K 	struct hw_event_resp *pPayload =
3413f5860992SSakthivel K 		(struct hw_event_resp *)(piomb + 4);
3414f5860992SSakthivel K 	u32 lr_status_evt_portid =
3415f5860992SSakthivel K 		le32_to_cpu(pPayload->lr_status_evt_portid);
3416f5860992SSakthivel K 	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3417f5860992SSakthivel K 	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3418f5860992SSakthivel K 	u8 phy_id =
3419f5860992SSakthivel K 		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
34203aa65f7eSChangyuan Lyu 	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
3421f5860992SSakthivel K 	u16 eventType =
3422f5860992SSakthivel K 		(u16)((lr_status_evt_portid & 0x00FFFF00) >> 8);
3423f5860992SSakthivel K 	u8 status =
3424f5860992SSakthivel K 		(u8)((lr_status_evt_portid & 0x0F000000) >> 24);
3425f5860992SSakthivel K 	struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3426f5860992SSakthivel K 	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
34278414cd80SViswas G 	struct pm8001_port *port = &pm8001_ha->port[port_id];
3428f5860992SSakthivel K 	struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
34291b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEV,
34301b5d2793SJoe Perches 		   "portid:%d phyid:%d event:0x%x status:0x%x\n",
34311b5d2793SJoe Perches 		   port_id, phy_id, eventType, status);
3432f5860992SSakthivel K 
3433f5860992SSakthivel K 	switch (eventType) {
3434f5860992SSakthivel K 
3435f5860992SSakthivel K 	case HW_EVENT_SAS_PHY_UP:
3436b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3437a6cf6b8bSAkshat Jain 			   "HW_EVENT_SAS_PHY_UP phyid:%#x port_id:%#x\n",
3438a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3439f5860992SSakthivel K 		hw_event_sas_phy_up(pm8001_ha, piomb);
3440f5860992SSakthivel K 		break;
3441f5860992SSakthivel K 	case HW_EVENT_SATA_PHY_UP:
3442f5860992SSakthivel K 		hw_event_sata_phy_up(pm8001_ha, piomb);
3443f5860992SSakthivel K 		break;
3444f5860992SSakthivel K 	case HW_EVENT_SATA_SPINUP_HOLD:
3445b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3446a6cf6b8bSAkshat Jain 			   "HW_EVENT_SATA_SPINUP_HOLD phyid:%#x port_id:%#x\n",
3447a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3448de6d7547SAhmed S. Darwish 		sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD,
3449cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3450f5860992SSakthivel K 		break;
3451f5860992SSakthivel K 	case HW_EVENT_PHY_DOWN:
3452869ddbdcSViswas G 		hw_event_phy_down(pm8001_ha, piomb);
3453cd135754SDeepak Ukey 		phy->phy_state = PHY_LINK_DISABLE;
3454f5860992SSakthivel K 		break;
3455f5860992SSakthivel K 	case HW_EVENT_PORT_INVALID:
3456b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3457a6cf6b8bSAkshat Jain 			   "HW_EVENT_PORT_INVALID phyid:%#x port_id:%#x\n",
3458a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3459f5860992SSakthivel K 		sas_phy_disconnected(sas_phy);
3460f5860992SSakthivel K 		phy->phy_attached = 0;
3461de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
3462cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3463f5860992SSakthivel K 		break;
3464f5860992SSakthivel K 	/* the broadcast change primitive received, tell the LIBSAS this event
3465f5860992SSakthivel K 	to revalidate the sas domain*/
3466f5860992SSakthivel K 	case HW_EVENT_BROADCAST_CHANGE:
34671b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n");
3468f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3469f5860992SSakthivel K 			port_id, phy_id, 1, 0);
3470f5860992SSakthivel K 		spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3471f5860992SSakthivel K 		sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3472f5860992SSakthivel K 		spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3473de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
3474cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3475f5860992SSakthivel K 		break;
3476f5860992SSakthivel K 	case HW_EVENT_PHY_ERROR:
3477a6cf6b8bSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3478a6cf6b8bSAkshat Jain 			   "HW_EVENT_PHY_ERROR phyid:%#x port_id:%#x\n",
3479a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3480f5860992SSakthivel K 		sas_phy_disconnected(&phy->sas_phy);
3481f5860992SSakthivel K 		phy->phy_attached = 0;
3482de6d7547SAhmed S. Darwish 		sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR, GFP_ATOMIC);
3483f5860992SSakthivel K 		break;
3484f5860992SSakthivel K 	case HW_EVENT_BROADCAST_EXP:
34851b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n");
3486f5860992SSakthivel K 		spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3487f5860992SSakthivel K 		sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3488f5860992SSakthivel K 		spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3489de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
3490cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3491f5860992SSakthivel K 		break;
3492f5860992SSakthivel K 	case HW_EVENT_LINK_ERR_INVALID_DWORD:
3493b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3494a6cf6b8bSAkshat Jain 			   "HW_EVENT_LINK_ERR_INVALID_DWORD phyid:%#x port_id:%#x\n",
3495a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3496f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3497f5860992SSakthivel K 			HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3498f5860992SSakthivel K 		break;
3499f5860992SSakthivel K 	case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
3500b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3501a6cf6b8bSAkshat Jain 			   "HW_EVENT_LINK_ERR_DISPARITY_ERROR phyid:%#x port_id:%#x\n",
3502a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3503f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3504f5860992SSakthivel K 			HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3505f5860992SSakthivel K 			port_id, phy_id, 0, 0);
3506f5860992SSakthivel K 		break;
3507f5860992SSakthivel K 	case HW_EVENT_LINK_ERR_CODE_VIOLATION:
3508b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3509a6cf6b8bSAkshat Jain 			   "HW_EVENT_LINK_ERR_CODE_VIOLATION phyid:%#x port_id:%#x\n",
3510a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3511f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3512f5860992SSakthivel K 			HW_EVENT_LINK_ERR_CODE_VIOLATION,
3513f5860992SSakthivel K 			port_id, phy_id, 0, 0);
3514f5860992SSakthivel K 		break;
3515f5860992SSakthivel K 	case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
3516b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3517a6cf6b8bSAkshat Jain 			   "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH phyid:%#x port_id:%#x\n",
3518a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3519f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3520f5860992SSakthivel K 			HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3521f5860992SSakthivel K 			port_id, phy_id, 0, 0);
3522f5860992SSakthivel K 		break;
3523f5860992SSakthivel K 	case HW_EVENT_MALFUNCTION:
3524b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3525b7d26c1dSAkshat Jain 			   "HW_EVENT_MALFUNCTION phyid:%#x\n", phy_id);
3526f5860992SSakthivel K 		break;
3527f5860992SSakthivel K 	case HW_EVENT_BROADCAST_SES:
35281b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n");
3529f5860992SSakthivel K 		spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3530f5860992SSakthivel K 		sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3531f5860992SSakthivel K 		spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3532de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
3533cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3534f5860992SSakthivel K 		break;
3535f5860992SSakthivel K 	case HW_EVENT_INBOUND_CRC_ERROR:
3536b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3537a6cf6b8bSAkshat Jain 			   "HW_EVENT_INBOUND_CRC_ERROR phyid:%#x port_id:%#x\n",
3538a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3539f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3540f5860992SSakthivel K 			HW_EVENT_INBOUND_CRC_ERROR,
3541f5860992SSakthivel K 			port_id, phy_id, 0, 0);
3542f5860992SSakthivel K 		break;
3543f5860992SSakthivel K 	case HW_EVENT_HARD_RESET_RECEIVED:
3544b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3545b7d26c1dSAkshat Jain 			   "HW_EVENT_HARD_RESET_RECEIVED phyid:%#x\n", phy_id);
3546de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_HARD_RESET, GFP_ATOMIC);
3547f5860992SSakthivel K 		break;
3548f5860992SSakthivel K 	case HW_EVENT_ID_FRAME_TIMEOUT:
3549b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3550b7d26c1dSAkshat Jain 			   "HW_EVENT_ID_FRAME_TIMEOUT phyid:%#x\n", phy_id);
3551f5860992SSakthivel K 		sas_phy_disconnected(sas_phy);
3552f5860992SSakthivel K 		phy->phy_attached = 0;
3553de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
3554cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3555f5860992SSakthivel K 		break;
3556f5860992SSakthivel K 	case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
3557b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3558a6cf6b8bSAkshat Jain 			   "HW_EVENT_LINK_ERR_PHY_RESET_FAILED phyid:%#x port_id:%#x\n",
3559a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3560f5860992SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3561f5860992SSakthivel K 			HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3562f5860992SSakthivel K 			port_id, phy_id, 0, 0);
3563f5860992SSakthivel K 		sas_phy_disconnected(sas_phy);
3564f5860992SSakthivel K 		phy->phy_attached = 0;
3565de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
3566cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3567f5860992SSakthivel K 		break;
3568f5860992SSakthivel K 	case HW_EVENT_PORT_RESET_TIMER_TMO:
3569b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
35703aa65f7eSChangyuan Lyu 			   "HW_EVENT_PORT_RESET_TIMER_TMO phyid:%#x port_id:%#x portstate:%#x\n",
35713aa65f7eSChangyuan Lyu 			   phy_id, port_id, portstate);
3572ee05cb71SAjish Koshy 		if (!pm8001_ha->phy[phy_id].reset_completion) {
3573869ddbdcSViswas G 			pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3574869ddbdcSViswas G 				port_id, phy_id, 0, 0);
3575ee05cb71SAjish Koshy 		}
3576f5860992SSakthivel K 		sas_phy_disconnected(sas_phy);
3577f5860992SSakthivel K 		phy->phy_attached = 0;
35783aa65f7eSChangyuan Lyu 		port->port_state = portstate;
3579de6d7547SAhmed S. Darwish 		sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
3580cd4e8176SAhmed S. Darwish 			GFP_ATOMIC);
3581869ddbdcSViswas G 		if (pm8001_ha->phy[phy_id].reset_completion) {
3582869ddbdcSViswas G 			pm8001_ha->phy[phy_id].port_reset_status =
3583869ddbdcSViswas G 					PORT_RESET_TMO;
3584869ddbdcSViswas G 			complete(pm8001_ha->phy[phy_id].reset_completion);
3585869ddbdcSViswas G 			pm8001_ha->phy[phy_id].reset_completion = NULL;
3586869ddbdcSViswas G 		}
3587f5860992SSakthivel K 		break;
3588f5860992SSakthivel K 	case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
3589b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3590a6cf6b8bSAkshat Jain 			   "HW_EVENT_PORT_RECOVERY_TIMER_TMO phyid:%#x port_id:%#x\n",
3591a6cf6b8bSAkshat Jain 			   phy_id, port_id);
3592a6cb3d01SSakthivel K 		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3593a6cb3d01SSakthivel K 			HW_EVENT_PORT_RECOVERY_TIMER_TMO,
3594a6cb3d01SSakthivel K 			port_id, phy_id, 0, 0);
35958414cd80SViswas G 		for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
35968414cd80SViswas G 			if (port->wide_port_phymap & (1 << i)) {
35978414cd80SViswas G 				phy = &pm8001_ha->phy[i];
3598de6d7547SAhmed S. Darwish 				sas_notify_phy_event(&phy->sas_phy,
3599cd4e8176SAhmed S. Darwish 					PHYE_LOSS_OF_SIGNAL, GFP_ATOMIC);
36008414cd80SViswas G 				port->wide_port_phymap &= ~(1 << i);
36018414cd80SViswas G 			}
36028414cd80SViswas G 		}
3603f5860992SSakthivel K 		break;
3604f5860992SSakthivel K 	case HW_EVENT_PORT_RECOVER:
3605b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
3606b7d26c1dSAkshat Jain 			   "HW_EVENT_PORT_RECOVER phyid:%#x port_id:%#x\n",
3607b7d26c1dSAkshat Jain 			   phy_id, port_id);
36088414cd80SViswas G 		hw_event_port_recover(pm8001_ha, piomb);
3609f5860992SSakthivel K 		break;
3610f5860992SSakthivel K 	case HW_EVENT_PORT_RESET_COMPLETE:
3611b7d26c1dSAkshat Jain 		pm8001_dbg(pm8001_ha, EVENT,
36123aa65f7eSChangyuan Lyu 			   "HW_EVENT_PORT_RESET_COMPLETE phyid:%#x port_id:%#x portstate:%#x\n",
36133aa65f7eSChangyuan Lyu 			   phy_id, port_id, portstate);
3614869ddbdcSViswas G 		if (pm8001_ha->phy[phy_id].reset_completion) {
3615869ddbdcSViswas G 			pm8001_ha->phy[phy_id].port_reset_status =
3616869ddbdcSViswas G 					PORT_RESET_SUCCESS;
3617869ddbdcSViswas G 			complete(pm8001_ha->phy[phy_id].reset_completion);
3618869ddbdcSViswas G 			pm8001_ha->phy[phy_id].reset_completion = NULL;
3619869ddbdcSViswas G 		}
36203aa65f7eSChangyuan Lyu 		phy->phy_attached = 1;
36213aa65f7eSChangyuan Lyu 		phy->phy_state = PHY_STATE_LINK_UP_SPCV;
36223aa65f7eSChangyuan Lyu 		port->port_state = portstate;
3623f5860992SSakthivel K 		break;
3624f5860992SSakthivel K 	case EVENT_BROADCAST_ASYNCH_EVENT:
36251b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n");
3626f5860992SSakthivel K 		break;
3627f5860992SSakthivel K 	default:
3628a6cf6b8bSAkshat Jain 		pm8001_dbg(pm8001_ha, DEVIO,
3629a6cf6b8bSAkshat Jain 			   "Unknown event portid:%d phyid:%d event:0x%x status:0x%x\n",
3630a6cf6b8bSAkshat Jain 			   port_id, phy_id, eventType, status);
3631f5860992SSakthivel K 		break;
3632f5860992SSakthivel K 	}
3633f5860992SSakthivel K 	return 0;
3634f5860992SSakthivel K }
3635f5860992SSakthivel K 
3636f5860992SSakthivel K /**
3637f5860992SSakthivel K  * mpi_phy_stop_resp - SPCv specific
3638f5860992SSakthivel K  * @pm8001_ha: our hba card information
3639f5860992SSakthivel K  * @piomb: IO message buffer
3640f5860992SSakthivel K  */
mpi_phy_stop_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3641f5860992SSakthivel K static int mpi_phy_stop_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3642f5860992SSakthivel K {
3643f5860992SSakthivel K 	struct phy_stop_resp *pPayload =
3644f5860992SSakthivel K 		(struct phy_stop_resp *)(piomb + 4);
3645f5860992SSakthivel K 	u32 status =
3646f5860992SSakthivel K 		le32_to_cpu(pPayload->status);
3647f5860992SSakthivel K 	u32 phyid =
3648cd135754SDeepak Ukey 		le32_to_cpu(pPayload->phyid) & 0xFF;
3649f5860992SSakthivel K 	struct pm8001_phy *phy = &pm8001_ha->phy[phyid];
36501b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG, "phy:0x%x status:0x%x\n",
36511b5d2793SJoe Perches 		   phyid, status);
3652cd135754SDeepak Ukey 	if (status == PHY_STOP_SUCCESS ||
3653355bf2e0SChangyuan Lyu 		status == PHY_STOP_ERR_DEVICE_ATTACHED) {
3654cd135754SDeepak Ukey 		phy->phy_state = PHY_LINK_DISABLE;
3655355bf2e0SChangyuan Lyu 		phy->sas_phy.phy->negotiated_linkrate = SAS_PHY_DISABLED;
3656355bf2e0SChangyuan Lyu 		phy->sas_phy.linkrate = SAS_PHY_DISABLED;
3657355bf2e0SChangyuan Lyu 	}
3658355bf2e0SChangyuan Lyu 
3659f5860992SSakthivel K 	return 0;
3660f5860992SSakthivel K }
3661f5860992SSakthivel K 
3662f5860992SSakthivel K /**
3663f5860992SSakthivel K  * mpi_set_controller_config_resp - SPCv specific
3664f5860992SSakthivel K  * @pm8001_ha: our hba card information
3665f5860992SSakthivel K  * @piomb: IO message buffer
3666f5860992SSakthivel K  */
mpi_set_controller_config_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3667f5860992SSakthivel K static int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3668f5860992SSakthivel K 			void *piomb)
3669f5860992SSakthivel K {
3670f5860992SSakthivel K 	struct set_ctrl_cfg_resp *pPayload =
3671f5860992SSakthivel K 			(struct set_ctrl_cfg_resp *)(piomb + 4);
3672f5860992SSakthivel K 	u32 status = le32_to_cpu(pPayload->status);
3673f5860992SSakthivel K 	u32 err_qlfr_pgcd = le32_to_cpu(pPayload->err_qlfr_pgcd);
3674*c13e7331SMichal Grzedzicki 	u32 tag = le32_to_cpu(pPayload->tag);
3675f5860992SSakthivel K 
36761b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG,
3677f5860992SSakthivel K 		   "SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
36781b5d2793SJoe Perches 		   status, err_qlfr_pgcd);
3679*c13e7331SMichal Grzedzicki 	pm8001_tag_free(pm8001_ha, tag);
3680f5860992SSakthivel K 
3681f5860992SSakthivel K 	return 0;
3682f5860992SSakthivel K }
3683f5860992SSakthivel K 
3684f5860992SSakthivel K /**
3685f5860992SSakthivel K  * mpi_get_controller_config_resp - SPCv specific
3686f5860992SSakthivel K  * @pm8001_ha: our hba card information
3687f5860992SSakthivel K  * @piomb: IO message buffer
3688f5860992SSakthivel K  */
mpi_get_controller_config_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3689f5860992SSakthivel K static int mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3690f5860992SSakthivel K 			void *piomb)
3691f5860992SSakthivel K {
36921b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
3693f5860992SSakthivel K 
3694f5860992SSakthivel K 	return 0;
3695f5860992SSakthivel K }
3696f5860992SSakthivel K 
3697f5860992SSakthivel K /**
3698f5860992SSakthivel K  * mpi_get_phy_profile_resp - SPCv specific
3699f5860992SSakthivel K  * @pm8001_ha: our hba card information
3700f5860992SSakthivel K  * @piomb: IO message buffer
3701f5860992SSakthivel K  */
mpi_get_phy_profile_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3702f5860992SSakthivel K static int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3703f5860992SSakthivel K 			void *piomb)
3704f5860992SSakthivel K {
37051b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
3706f5860992SSakthivel K 
3707f5860992SSakthivel K 	return 0;
3708f5860992SSakthivel K }
3709f5860992SSakthivel K 
3710f5860992SSakthivel K /**
3711f5860992SSakthivel K  * mpi_flash_op_ext_resp - SPCv specific
3712f5860992SSakthivel K  * @pm8001_ha: our hba card information
3713f5860992SSakthivel K  * @piomb: IO message buffer
3714f5860992SSakthivel K  */
mpi_flash_op_ext_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3715f5860992SSakthivel K static int mpi_flash_op_ext_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3716f5860992SSakthivel K {
37171b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
3718f5860992SSakthivel K 
3719f5860992SSakthivel K 	return 0;
3720f5860992SSakthivel K }
3721f5860992SSakthivel K 
3722f5860992SSakthivel K /**
3723f5860992SSakthivel K  * mpi_set_phy_profile_resp - SPCv specific
3724f5860992SSakthivel K  * @pm8001_ha: our hba card information
3725f5860992SSakthivel K  * @piomb: IO message buffer
3726f5860992SSakthivel K  */
mpi_set_phy_profile_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3727f5860992SSakthivel K static int mpi_set_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3728f5860992SSakthivel K 			void *piomb)
3729f5860992SSakthivel K {
37309d9c7c20Syuuzheng 	u32 tag;
373127909407SAnand Kumar Santhanam 	u8 page_code;
37329d9c7c20Syuuzheng 	int rc = 0;
373327909407SAnand Kumar Santhanam 	struct set_phy_profile_resp *pPayload =
373427909407SAnand Kumar Santhanam 		(struct set_phy_profile_resp *)(piomb + 4);
373527909407SAnand Kumar Santhanam 	u32 ppc_phyid = le32_to_cpu(pPayload->ppc_phyid);
373627909407SAnand Kumar Santhanam 	u32 status = le32_to_cpu(pPayload->status);
3737f5860992SSakthivel K 
37389d9c7c20Syuuzheng 	tag = le32_to_cpu(pPayload->tag);
373927909407SAnand Kumar Santhanam 	page_code = (u8)((ppc_phyid & 0xFF00) >> 8);
374027909407SAnand Kumar Santhanam 	if (status) {
374127909407SAnand Kumar Santhanam 		/* status is FAILED */
37421b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
37431b5d2793SJoe Perches 			   "PhyProfile command failed  with status 0x%08X\n",
37441b5d2793SJoe Perches 			   status);
37459d9c7c20Syuuzheng 		rc = -1;
374627909407SAnand Kumar Santhanam 	} else {
374727909407SAnand Kumar Santhanam 		if (page_code != SAS_PHY_ANALOG_SETTINGS_PAGE) {
37481b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, FAIL, "Invalid page code 0x%X\n",
37491b5d2793SJoe Perches 				   page_code);
37509d9c7c20Syuuzheng 			rc = -1;
375127909407SAnand Kumar Santhanam 		}
375227909407SAnand Kumar Santhanam 	}
37539d9c7c20Syuuzheng 	pm8001_tag_free(pm8001_ha, tag);
37549d9c7c20Syuuzheng 	return rc;
3755f5860992SSakthivel K }
3756f5860992SSakthivel K 
3757f5860992SSakthivel K /**
3758f5860992SSakthivel K  * mpi_kek_management_resp - SPCv specific
3759f5860992SSakthivel K  * @pm8001_ha: our hba card information
3760f5860992SSakthivel K  * @piomb: IO message buffer
3761f5860992SSakthivel K  */
mpi_kek_management_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3762f5860992SSakthivel K static int mpi_kek_management_resp(struct pm8001_hba_info *pm8001_ha,
3763f5860992SSakthivel K 			void *piomb)
3764f5860992SSakthivel K {
3765f5860992SSakthivel K 	struct kek_mgmt_resp *pPayload = (struct kek_mgmt_resp *)(piomb + 4);
3766f5860992SSakthivel K 
3767f5860992SSakthivel K 	u32 status = le32_to_cpu(pPayload->status);
3768f5860992SSakthivel K 	u32 kidx_new_curr_ksop = le32_to_cpu(pPayload->kidx_new_curr_ksop);
3769f5860992SSakthivel K 	u32 err_qlfr = le32_to_cpu(pPayload->err_qlfr);
3770f5860992SSakthivel K 
37711b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG,
3772f5860992SSakthivel K 		   "KEK MGMT RESP. Status 0x%x idx_ksop 0x%x err_qlfr 0x%x\n",
37731b5d2793SJoe Perches 		   status, kidx_new_curr_ksop, err_qlfr);
3774f5860992SSakthivel K 
3775f5860992SSakthivel K 	return 0;
3776f5860992SSakthivel K }
3777f5860992SSakthivel K 
3778f5860992SSakthivel K /**
3779f5860992SSakthivel K  * mpi_dek_management_resp - SPCv specific
3780f5860992SSakthivel K  * @pm8001_ha: our hba card information
3781f5860992SSakthivel K  * @piomb: IO message buffer
3782f5860992SSakthivel K  */
mpi_dek_management_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3783f5860992SSakthivel K static int mpi_dek_management_resp(struct pm8001_hba_info *pm8001_ha,
3784f5860992SSakthivel K 			void *piomb)
3785f5860992SSakthivel K {
37861b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
3787f5860992SSakthivel K 
3788f5860992SSakthivel K 	return 0;
3789f5860992SSakthivel K }
3790f5860992SSakthivel K 
3791f5860992SSakthivel K /**
3792f5860992SSakthivel K  * ssp_coalesced_comp_resp - SPCv specific
3793f5860992SSakthivel K  * @pm8001_ha: our hba card information
3794f5860992SSakthivel K  * @piomb: IO message buffer
3795f5860992SSakthivel K  */
ssp_coalesced_comp_resp(struct pm8001_hba_info * pm8001_ha,void * piomb)3796f5860992SSakthivel K static int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
3797f5860992SSakthivel K 			void *piomb)
3798f5860992SSakthivel K {
37991b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, MSG, " pm80xx_addition_functionality\n");
3800f5860992SSakthivel K 
3801f5860992SSakthivel K 	return 0;
3802f5860992SSakthivel K }
3803f5860992SSakthivel K 
3804f5860992SSakthivel K /**
3805f5860992SSakthivel K  * process_one_iomb - process one outbound Queue memory block
3806f5860992SSakthivel K  * @pm8001_ha: our hba card information
38070aed75fdSJohn Garry  * @circularQ: outbound circular queue
3808f5860992SSakthivel K  * @piomb: IO message buffer
3809f5860992SSakthivel K  */
process_one_iomb(struct pm8001_hba_info * pm8001_ha,struct outbound_queue_table * circularQ,void * piomb)3810b27a4053SAjish Koshy static void process_one_iomb(struct pm8001_hba_info *pm8001_ha,
3811b27a4053SAjish Koshy 		struct outbound_queue_table *circularQ, void *piomb)
3812f5860992SSakthivel K {
3813f5860992SSakthivel K 	__le32 pHeader = *(__le32 *)piomb;
3814f5860992SSakthivel K 	u32 opc = (u32)((le32_to_cpu(pHeader)) & 0xFFF);
3815f5860992SSakthivel K 
3816f5860992SSakthivel K 	switch (opc) {
3817f5860992SSakthivel K 	case OPC_OUB_ECHO:
38181b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n");
3819f5860992SSakthivel K 		break;
3820f5860992SSakthivel K 	case OPC_OUB_HW_EVENT:
38211b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n");
3822f5860992SSakthivel K 		mpi_hw_event(pm8001_ha, piomb);
3823f5860992SSakthivel K 		break;
3824f5860992SSakthivel K 	case OPC_OUB_THERM_HW_EVENT:
38251b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_THERMAL_EVENT\n");
3826f5860992SSakthivel K 		mpi_thermal_hw_event(pm8001_ha, piomb);
3827f5860992SSakthivel K 		break;
3828f5860992SSakthivel K 	case OPC_OUB_SSP_COMP:
38291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n");
3830f5860992SSakthivel K 		mpi_ssp_completion(pm8001_ha, piomb);
3831f5860992SSakthivel K 		break;
3832f5860992SSakthivel K 	case OPC_OUB_SMP_COMP:
38331b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n");
3834f5860992SSakthivel K 		mpi_smp_completion(pm8001_ha, piomb);
3835f5860992SSakthivel K 		break;
3836f5860992SSakthivel K 	case OPC_OUB_LOCAL_PHY_CNTRL:
38371b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n");
3838f5860992SSakthivel K 		pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
3839f5860992SSakthivel K 		break;
3840f5860992SSakthivel K 	case OPC_OUB_DEV_REGIST:
38411b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n");
3842f5860992SSakthivel K 		pm8001_mpi_reg_resp(pm8001_ha, piomb);
3843f5860992SSakthivel K 		break;
3844f5860992SSakthivel K 	case OPC_OUB_DEREG_DEV:
38451b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "unregister the device\n");
3846f5860992SSakthivel K 		pm8001_mpi_dereg_resp(pm8001_ha, piomb);
3847f5860992SSakthivel K 		break;
3848f5860992SSakthivel K 	case OPC_OUB_GET_DEV_HANDLE:
38491b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n");
3850f5860992SSakthivel K 		break;
3851f5860992SSakthivel K 	case OPC_OUB_SATA_COMP:
38521b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n");
3853b27a4053SAjish Koshy 		mpi_sata_completion(pm8001_ha, circularQ, piomb);
3854f5860992SSakthivel K 		break;
3855f5860992SSakthivel K 	case OPC_OUB_SATA_EVENT:
38561b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n");
3857b27a4053SAjish Koshy 		mpi_sata_event(pm8001_ha, circularQ, piomb);
3858f5860992SSakthivel K 		break;
3859f5860992SSakthivel K 	case OPC_OUB_SSP_EVENT:
38601b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n");
3861f5860992SSakthivel K 		mpi_ssp_event(pm8001_ha, piomb);
3862f5860992SSakthivel K 		break;
3863f5860992SSakthivel K 	case OPC_OUB_DEV_HANDLE_ARRIV:
38641b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n");
3865f5860992SSakthivel K 		/*This is for target*/
3866f5860992SSakthivel K 		break;
3867f5860992SSakthivel K 	case OPC_OUB_SSP_RECV_EVENT:
38681b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n");
3869f5860992SSakthivel K 		/*This is for target*/
3870f5860992SSakthivel K 		break;
3871f5860992SSakthivel K 	case OPC_OUB_FW_FLASH_UPDATE:
38721b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n");
3873f5860992SSakthivel K 		pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
3874f5860992SSakthivel K 		break;
3875f5860992SSakthivel K 	case OPC_OUB_GPIO_RESPONSE:
38761b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n");
3877f5860992SSakthivel K 		break;
3878f5860992SSakthivel K 	case OPC_OUB_GPIO_EVENT:
38791b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n");
3880f5860992SSakthivel K 		break;
3881f5860992SSakthivel K 	case OPC_OUB_GENERAL_EVENT:
38821b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n");
3883f5860992SSakthivel K 		pm8001_mpi_general_event(pm8001_ha, piomb);
3884f5860992SSakthivel K 		break;
3885f5860992SSakthivel K 	case OPC_OUB_SSP_ABORT_RSP:
38861b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n");
3887f5860992SSakthivel K 		pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3888f5860992SSakthivel K 		break;
3889f5860992SSakthivel K 	case OPC_OUB_SATA_ABORT_RSP:
38901b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n");
3891f5860992SSakthivel K 		pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3892f5860992SSakthivel K 		break;
3893f5860992SSakthivel K 	case OPC_OUB_SAS_DIAG_MODE_START_END:
38941b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
38951b5d2793SJoe Perches 			   "OPC_OUB_SAS_DIAG_MODE_START_END\n");
3896f5860992SSakthivel K 		break;
3897f5860992SSakthivel K 	case OPC_OUB_SAS_DIAG_EXECUTE:
38981b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n");
3899f5860992SSakthivel K 		break;
3900f5860992SSakthivel K 	case OPC_OUB_GET_TIME_STAMP:
39011b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n");
3902f5860992SSakthivel K 		break;
3903f5860992SSakthivel K 	case OPC_OUB_SAS_HW_EVENT_ACK:
39041b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n");
3905f5860992SSakthivel K 		break;
3906f5860992SSakthivel K 	case OPC_OUB_PORT_CONTROL:
39071b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n");
3908f5860992SSakthivel K 		break;
3909f5860992SSakthivel K 	case OPC_OUB_SMP_ABORT_RSP:
39101b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n");
3911f5860992SSakthivel K 		pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3912f5860992SSakthivel K 		break;
3913f5860992SSakthivel K 	case OPC_OUB_GET_NVMD_DATA:
39141b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n");
3915f5860992SSakthivel K 		pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
3916f5860992SSakthivel K 		break;
3917f5860992SSakthivel K 	case OPC_OUB_SET_NVMD_DATA:
39181b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n");
3919f5860992SSakthivel K 		pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
3920f5860992SSakthivel K 		break;
3921f5860992SSakthivel K 	case OPC_OUB_DEVICE_HANDLE_REMOVAL:
39221b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n");
3923f5860992SSakthivel K 		break;
3924f5860992SSakthivel K 	case OPC_OUB_SET_DEVICE_STATE:
39251b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n");
3926f5860992SSakthivel K 		pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
3927f5860992SSakthivel K 		break;
3928f5860992SSakthivel K 	case OPC_OUB_GET_DEVICE_STATE:
39291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n");
3930f5860992SSakthivel K 		break;
3931f5860992SSakthivel K 	case OPC_OUB_SET_DEV_INFO:
39321b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n");
3933f5860992SSakthivel K 		break;
3934bb6beabfSRandy Dunlap 	/* spcv specific commands */
3935f5860992SSakthivel K 	case OPC_OUB_PHY_START_RESP:
39361b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39371b5d2793SJoe Perches 			   "OPC_OUB_PHY_START_RESP opcode:%x\n", opc);
3938f5860992SSakthivel K 		mpi_phy_start_resp(pm8001_ha, piomb);
3939f5860992SSakthivel K 		break;
3940f5860992SSakthivel K 	case OPC_OUB_PHY_STOP_RESP:
39411b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39421b5d2793SJoe Perches 			   "OPC_OUB_PHY_STOP_RESP opcode:%x\n", opc);
3943f5860992SSakthivel K 		mpi_phy_stop_resp(pm8001_ha, piomb);
3944f5860992SSakthivel K 		break;
3945f5860992SSakthivel K 	case OPC_OUB_SET_CONTROLLER_CONFIG:
39461b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39471b5d2793SJoe Perches 			   "OPC_OUB_SET_CONTROLLER_CONFIG opcode:%x\n", opc);
3948f5860992SSakthivel K 		mpi_set_controller_config_resp(pm8001_ha, piomb);
3949f5860992SSakthivel K 		break;
3950f5860992SSakthivel K 	case OPC_OUB_GET_CONTROLLER_CONFIG:
39511b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39521b5d2793SJoe Perches 			   "OPC_OUB_GET_CONTROLLER_CONFIG opcode:%x\n", opc);
3953f5860992SSakthivel K 		mpi_get_controller_config_resp(pm8001_ha, piomb);
3954f5860992SSakthivel K 		break;
3955f5860992SSakthivel K 	case OPC_OUB_GET_PHY_PROFILE:
39561b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39571b5d2793SJoe Perches 			   "OPC_OUB_GET_PHY_PROFILE opcode:%x\n", opc);
3958f5860992SSakthivel K 		mpi_get_phy_profile_resp(pm8001_ha, piomb);
3959f5860992SSakthivel K 		break;
3960f5860992SSakthivel K 	case OPC_OUB_FLASH_OP_EXT:
39611b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39621b5d2793SJoe Perches 			   "OPC_OUB_FLASH_OP_EXT opcode:%x\n", opc);
3963f5860992SSakthivel K 		mpi_flash_op_ext_resp(pm8001_ha, piomb);
3964f5860992SSakthivel K 		break;
3965f5860992SSakthivel K 	case OPC_OUB_SET_PHY_PROFILE:
39661b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39671b5d2793SJoe Perches 			   "OPC_OUB_SET_PHY_PROFILE opcode:%x\n", opc);
3968f5860992SSakthivel K 		mpi_set_phy_profile_resp(pm8001_ha, piomb);
3969f5860992SSakthivel K 		break;
3970f5860992SSakthivel K 	case OPC_OUB_KEK_MANAGEMENT_RESP:
39711b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39721b5d2793SJoe Perches 			   "OPC_OUB_KEK_MANAGEMENT_RESP opcode:%x\n", opc);
3973f5860992SSakthivel K 		mpi_kek_management_resp(pm8001_ha, piomb);
3974f5860992SSakthivel K 		break;
3975f5860992SSakthivel K 	case OPC_OUB_DEK_MANAGEMENT_RESP:
39761b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39771b5d2793SJoe Perches 			   "OPC_OUB_DEK_MANAGEMENT_RESP opcode:%x\n", opc);
3978f5860992SSakthivel K 		mpi_dek_management_resp(pm8001_ha, piomb);
3979f5860992SSakthivel K 		break;
3980f5860992SSakthivel K 	case OPC_OUB_SSP_COALESCED_COMP_RESP:
39811b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, MSG,
39821b5d2793SJoe Perches 			   "OPC_OUB_SSP_COALESCED_COMP_RESP opcode:%x\n", opc);
3983f5860992SSakthivel K 		ssp_coalesced_comp_resp(pm8001_ha, piomb);
3984f5860992SSakthivel K 		break;
3985f5860992SSakthivel K 	default:
39861b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, DEVIO,
39871b5d2793SJoe Perches 			   "Unknown outbound Queue IOMB OPC = 0x%x\n", opc);
3988f5860992SSakthivel K 		break;
3989f5860992SSakthivel K 	}
3990f5860992SSakthivel K }
3991f5860992SSakthivel K 
print_scratchpad_registers(struct pm8001_hba_info * pm8001_ha)399272349b62SDeepak Ukey static void print_scratchpad_registers(struct pm8001_hba_info *pm8001_ha)
399372349b62SDeepak Ukey {
39941b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_0: 0x%x\n",
39951b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0));
39961b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_1:0x%x\n",
39971b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1));
39981b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_2: 0x%x\n",
39991b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2));
40001b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_SCRATCH_PAD_3: 0x%x\n",
40011b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3));
40021b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_0: 0x%x\n",
40031b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0));
40041b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_1: 0x%x\n",
40051b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_1));
40061b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_2: 0x%x\n",
40071b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_2));
40081b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_3: 0x%x\n",
40091b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_3));
40101b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_4: 0x%x\n",
40111b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_4));
40121b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_HOST_SCRATCH_PAD_5: 0x%x\n",
40131b5d2793SJoe Perches 		   pm8001_cr32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_5));
40141b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_RSVD_SCRATCH_PAD_0: 0x%x\n",
401580cac47bSAjish Koshy 		   pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_RSVD_0));
40161b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, FAIL, "MSGU_RSVD_SCRATCH_PAD_1: 0x%x\n",
401780cac47bSAjish Koshy 		   pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_RSVD_1));
401872349b62SDeepak Ukey }
401972349b62SDeepak Ukey 
process_oq(struct pm8001_hba_info * pm8001_ha,u8 vec)4020f5860992SSakthivel K static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
4021f5860992SSakthivel K {
4022f5860992SSakthivel K 	struct outbound_queue_table *circularQ;
4023f5860992SSakthivel K 	void *pMsg1 = NULL;
40243f649ab7SKees Cook 	u8 bc;
4025f5860992SSakthivel K 	u32 ret = MPI_IO_STATUS_FAIL;
402672349b62SDeepak Ukey 	u32 regval;
4027f5860992SSakthivel K 
402862afb379SJohn Garry 	/*
402962afb379SJohn Garry 	 * Fatal errors are programmed to be signalled in irq vector
403062afb379SJohn Garry 	 * pm8001_ha->max_q_num - 1 through pm8001_ha->main_cfg_tbl.pm80xx_tbl.
403162afb379SJohn Garry 	 * fatal_err_interrupt
403262afb379SJohn Garry 	 */
403305c6c029SViswas G 	if (vec == (pm8001_ha->max_q_num - 1)) {
403462afb379SJohn Garry 		u32 mipsall_ready;
403562afb379SJohn Garry 
403662afb379SJohn Garry 		if (pm8001_ha->chip_id == chip_8008 ||
403762afb379SJohn Garry 		    pm8001_ha->chip_id == chip_8009)
403862afb379SJohn Garry 			mipsall_ready = SCRATCH_PAD_MIPSALL_READY_8PORT;
403962afb379SJohn Garry 		else
404062afb379SJohn Garry 			mipsall_ready = SCRATCH_PAD_MIPSALL_READY_16PORT;
404162afb379SJohn Garry 
404272349b62SDeepak Ukey 		regval = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
404362afb379SJohn Garry 		if ((regval & mipsall_ready) != mipsall_ready) {
404472349b62SDeepak Ukey 			pm8001_ha->controller_fatal_error = true;
40451b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, FAIL,
40461b5d2793SJoe Perches 				   "Firmware Fatal error! Regval:0x%x\n",
40471b5d2793SJoe Perches 				   regval);
40484f5deeb4SRuksar Devadi 			pm8001_handle_event(pm8001_ha, NULL, IO_FATAL_ERROR);
404972349b62SDeepak Ukey 			print_scratchpad_registers(pm8001_ha);
405072349b62SDeepak Ukey 			return ret;
405180cac47bSAjish Koshy 		} else {
405280cac47bSAjish Koshy 			/*read scratchpad rsvd 0 register*/
405380cac47bSAjish Koshy 			regval = pm8001_cr32(pm8001_ha, 0,
405480cac47bSAjish Koshy 					     MSGU_SCRATCH_PAD_RSVD_0);
405580cac47bSAjish Koshy 			switch (regval) {
405680cac47bSAjish Koshy 			case NON_FATAL_SPBC_LBUS_ECC_ERR:
405780cac47bSAjish Koshy 			case NON_FATAL_BDMA_ERR:
405880cac47bSAjish Koshy 			case NON_FATAL_THERM_OVERTEMP_ERR:
405980cac47bSAjish Koshy 				/*Clear the register*/
406080cac47bSAjish Koshy 				pm8001_cw32(pm8001_ha, 0,
406180cac47bSAjish Koshy 					    MSGU_SCRATCH_PAD_RSVD_0,
406280cac47bSAjish Koshy 					    0x00000000);
406380cac47bSAjish Koshy 				break;
406480cac47bSAjish Koshy 			default:
406580cac47bSAjish Koshy 				break;
406680cac47bSAjish Koshy 			}
406772349b62SDeepak Ukey 		}
406872349b62SDeepak Ukey 	}
4069f5860992SSakthivel K 	circularQ = &pm8001_ha->outbnd_q_tbl[vec];
4070b27a4053SAjish Koshy 	spin_lock_irqsave(&circularQ->oq_lock, circularQ->lock_flags);
4071f5860992SSakthivel K 	do {
407272349b62SDeepak Ukey 		/* spurious interrupt during setup if kexec-ing and
407372349b62SDeepak Ukey 		 * driver doing a doorbell access w/ the pre-kexec oq
407472349b62SDeepak Ukey 		 * interrupt setup.
407572349b62SDeepak Ukey 		 */
407672349b62SDeepak Ukey 		if (!circularQ->pi_virt)
407772349b62SDeepak Ukey 			break;
4078f5860992SSakthivel K 		ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
4079f5860992SSakthivel K 		if (MPI_IO_STATUS_SUCCESS == ret) {
4080f5860992SSakthivel K 			/* process the outbound message */
4081b27a4053SAjish Koshy 			process_one_iomb(pm8001_ha, circularQ,
4082b27a4053SAjish Koshy 						(void *)(pMsg1 - 4));
4083f5860992SSakthivel K 			/* free the message from the outbound circular buffer */
4084f5860992SSakthivel K 			pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4085f5860992SSakthivel K 							circularQ, bc);
4086f5860992SSakthivel K 		}
4087f5860992SSakthivel K 		if (MPI_IO_STATUS_BUSY == ret) {
4088f5860992SSakthivel K 			/* Update the producer index from SPC */
4089f5860992SSakthivel K 			circularQ->producer_index =
4090f5860992SSakthivel K 				cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4091f5860992SSakthivel K 			if (le32_to_cpu(circularQ->producer_index) ==
4092f5860992SSakthivel K 				circularQ->consumer_idx)
4093f5860992SSakthivel K 				/* OQ is empty */
4094f5860992SSakthivel K 				break;
4095f5860992SSakthivel K 		}
4096f5860992SSakthivel K 	} while (1);
4097b27a4053SAjish Koshy 	spin_unlock_irqrestore(&circularQ->oq_lock, circularQ->lock_flags);
4098f5860992SSakthivel K 	return ret;
4099f5860992SSakthivel K }
4100f5860992SSakthivel K 
4101f73bdebdSChristoph Hellwig /* DMA_... to our direction translation. */
4102f5860992SSakthivel K static const u8 data_dir_flags[] = {
4103f73bdebdSChristoph Hellwig 	[DMA_BIDIRECTIONAL]	= DATA_DIR_BYRECIPIENT,	/* UNSPECIFIED */
4104f73bdebdSChristoph Hellwig 	[DMA_TO_DEVICE]		= DATA_DIR_OUT,		/* OUTBOUND */
4105f73bdebdSChristoph Hellwig 	[DMA_FROM_DEVICE]	= DATA_DIR_IN,		/* INBOUND */
4106f73bdebdSChristoph Hellwig 	[DMA_NONE]		= DATA_DIR_NONE,	/* NO TRANSFER */
4107f5860992SSakthivel K };
4108f5860992SSakthivel K 
build_smp_cmd(u32 deviceID,__le32 hTag,struct smp_req * psmp_cmd,int mode,int length)4109f5860992SSakthivel K static void build_smp_cmd(u32 deviceID, __le32 hTag,
4110f5860992SSakthivel K 			struct smp_req *psmp_cmd, int mode, int length)
4111f5860992SSakthivel K {
4112f5860992SSakthivel K 	psmp_cmd->tag = hTag;
4113f5860992SSakthivel K 	psmp_cmd->device_id = cpu_to_le32(deviceID);
4114f5860992SSakthivel K 	if (mode == SMP_DIRECT) {
4115f5860992SSakthivel K 		length = length - 4; /* subtract crc */
4116f5860992SSakthivel K 		psmp_cmd->len_ip_ir = cpu_to_le32(length << 16);
4117f5860992SSakthivel K 	} else {
4118f5860992SSakthivel K 		psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4119f5860992SSakthivel K 	}
4120f5860992SSakthivel K }
4121f5860992SSakthivel K 
4122f5860992SSakthivel K /**
4123bb6beabfSRandy Dunlap  * pm80xx_chip_smp_req - send an SMP task to FW
4124f5860992SSakthivel K  * @pm8001_ha: our hba card information.
4125f5860992SSakthivel K  * @ccb: the ccb information this request used.
4126f5860992SSakthivel K  */
pm80xx_chip_smp_req(struct pm8001_hba_info * pm8001_ha,struct pm8001_ccb_info * ccb)4127f5860992SSakthivel K static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4128f5860992SSakthivel K 	struct pm8001_ccb_info *ccb)
4129f5860992SSakthivel K {
4130f5860992SSakthivel K 	int elem, rc;
4131f5860992SSakthivel K 	struct sas_task *task = ccb->task;
4132f5860992SSakthivel K 	struct domain_device *dev = task->dev;
4133f5860992SSakthivel K 	struct pm8001_device *pm8001_dev = dev->lldd_dev;
41342fe24343SJohn Garry 	struct scatterlist *sg_req, *sg_resp, *smp_req;
4135f5860992SSakthivel K 	u32 req_len, resp_len;
4136f5860992SSakthivel K 	struct smp_req smp_cmd;
4137f5860992SSakthivel K 	u32 opc;
4138f5860992SSakthivel K 	u32 i, length;
41392fe24343SJohn Garry 	u8 *payload;
41402fe24343SJohn Garry 	u8 *to;
4141f5860992SSakthivel K 
4142f5860992SSakthivel K 	memset(&smp_cmd, 0, sizeof(smp_cmd));
4143f5860992SSakthivel K 	/*
4144f5860992SSakthivel K 	 * DMA-map SMP request, response buffers
4145f5860992SSakthivel K 	 */
4146f5860992SSakthivel K 	sg_req = &task->smp_task.smp_req;
4147f73bdebdSChristoph Hellwig 	elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
4148f5860992SSakthivel K 	if (!elem)
4149f5860992SSakthivel K 		return -ENOMEM;
4150f5860992SSakthivel K 	req_len = sg_dma_len(sg_req);
4151f5860992SSakthivel K 
4152f5860992SSakthivel K 	sg_resp = &task->smp_task.smp_resp;
4153f73bdebdSChristoph Hellwig 	elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
4154f5860992SSakthivel K 	if (!elem) {
4155f5860992SSakthivel K 		rc = -ENOMEM;
4156f5860992SSakthivel K 		goto err_out;
4157f5860992SSakthivel K 	}
4158f5860992SSakthivel K 	resp_len = sg_dma_len(sg_resp);
4159f5860992SSakthivel K 	/* must be in dwords */
4160f5860992SSakthivel K 	if ((req_len & 0x3) || (resp_len & 0x3)) {
4161f5860992SSakthivel K 		rc = -EINVAL;
4162f5860992SSakthivel K 		goto err_out_2;
4163f5860992SSakthivel K 	}
4164f5860992SSakthivel K 
4165f5860992SSakthivel K 	opc = OPC_INB_SMP_REQUEST;
4166f5860992SSakthivel K 	smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4167f5860992SSakthivel K 
4168f5860992SSakthivel K 	length = sg_req->length;
41691b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, IO, "SMP Frame Length %d\n", sg_req->length);
4170f5860992SSakthivel K 	if (!(length - 8))
4171f5860992SSakthivel K 		pm8001_ha->smp_exp_mode = SMP_DIRECT;
4172f5860992SSakthivel K 	else
4173f5860992SSakthivel K 		pm8001_ha->smp_exp_mode = SMP_INDIRECT;
4174f5860992SSakthivel K 
4175f5860992SSakthivel K 
41762fe24343SJohn Garry 	smp_req = &task->smp_task.smp_req;
41772fe24343SJohn Garry 	to = kmap_atomic(sg_page(smp_req));
41782fe24343SJohn Garry 	payload = to + smp_req->offset;
4179f5860992SSakthivel K 
4180f5860992SSakthivel K 	/* INDIRECT MODE command settings. Use DMA */
4181f5860992SSakthivel K 	if (pm8001_ha->smp_exp_mode == SMP_INDIRECT) {
41821b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "SMP REQUEST INDIRECT MODE\n");
4183f5860992SSakthivel K 		/* for SPCv indirect mode. Place the top 4 bytes of
4184f5860992SSakthivel K 		 * SMP Request header here. */
4185f5860992SSakthivel K 		for (i = 0; i < 4; i++)
41862fe24343SJohn Garry 			smp_cmd.smp_req16[i] = *(payload + i);
4187f5860992SSakthivel K 		/* exclude top 4 bytes for SMP req header */
4188f5860992SSakthivel K 		smp_cmd.long_smp_req.long_req_addr =
4189f5860992SSakthivel K 			cpu_to_le64((u64)sg_dma_address
4190cb993e5dSAnand Kumar Santhanam 				(&task->smp_task.smp_req) + 4);
4191f5860992SSakthivel K 		/* exclude 4 bytes for SMP req header and CRC */
4192f5860992SSakthivel K 		smp_cmd.long_smp_req.long_req_size =
4193f5860992SSakthivel K 			cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-8);
4194f5860992SSakthivel K 		smp_cmd.long_smp_req.long_resp_addr =
4195f5860992SSakthivel K 				cpu_to_le64((u64)sg_dma_address
4196f5860992SSakthivel K 					(&task->smp_task.smp_resp));
4197f5860992SSakthivel K 		smp_cmd.long_smp_req.long_resp_size =
4198f5860992SSakthivel K 				cpu_to_le32((u32)sg_dma_len
4199f5860992SSakthivel K 					(&task->smp_task.smp_resp)-4);
4200f5860992SSakthivel K 	} else { /* DIRECT MODE */
4201f5860992SSakthivel K 		smp_cmd.long_smp_req.long_req_addr =
4202f5860992SSakthivel K 			cpu_to_le64((u64)sg_dma_address
4203f5860992SSakthivel K 					(&task->smp_task.smp_req));
4204f5860992SSakthivel K 		smp_cmd.long_smp_req.long_req_size =
4205f5860992SSakthivel K 			cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4206f5860992SSakthivel K 		smp_cmd.long_smp_req.long_resp_addr =
4207f5860992SSakthivel K 			cpu_to_le64((u64)sg_dma_address
4208f5860992SSakthivel K 				(&task->smp_task.smp_resp));
4209f5860992SSakthivel K 		smp_cmd.long_smp_req.long_resp_size =
4210f5860992SSakthivel K 			cpu_to_le32
4211f5860992SSakthivel K 			((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4212f5860992SSakthivel K 	}
4213f5860992SSakthivel K 	if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
42141b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "SMP REQUEST DIRECT MODE\n");
4215f5860992SSakthivel K 		for (i = 0; i < length; i++)
4216f5860992SSakthivel K 			if (i < 16) {
42172fe24343SJohn Garry 				smp_cmd.smp_req16[i] = *(payload + i);
42181b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO,
4219f5860992SSakthivel K 					   "Byte[%d]:%x (DMA data:%x)\n",
4220f5860992SSakthivel K 					   i, smp_cmd.smp_req16[i],
42212fe24343SJohn Garry 					   *(payload));
4222f5860992SSakthivel K 			} else {
42232fe24343SJohn Garry 				smp_cmd.smp_req[i] = *(payload + i);
42241b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, IO,
4225f5860992SSakthivel K 					   "Byte[%d]:%x (DMA data:%x)\n",
4226f5860992SSakthivel K 					   i, smp_cmd.smp_req[i],
42272fe24343SJohn Garry 					   *(payload));
4228f5860992SSakthivel K 			}
4229f5860992SSakthivel K 	}
42302fe24343SJohn Garry 	kunmap_atomic(to);
4231f5860992SSakthivel K 	build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag,
4232f5860992SSakthivel K 				&smp_cmd, pm8001_ha->smp_exp_mode, length);
4233f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &smp_cmd,
423491a43fa6Speter chang 				  sizeof(smp_cmd), 0);
42355533abcaSTomas Henzl 	if (rc)
42365533abcaSTomas Henzl 		goto err_out_2;
4237f5860992SSakthivel K 	return 0;
4238f5860992SSakthivel K 
4239f5860992SSakthivel K err_out_2:
4240f5860992SSakthivel K 	dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
4241f73bdebdSChristoph Hellwig 			DMA_FROM_DEVICE);
4242f5860992SSakthivel K err_out:
4243f5860992SSakthivel K 	dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
4244f73bdebdSChristoph Hellwig 			DMA_TO_DEVICE);
4245f5860992SSakthivel K 	return rc;
4246f5860992SSakthivel K }
4247f5860992SSakthivel K 
check_enc_sas_cmd(struct sas_task * task)4248f5860992SSakthivel K static int check_enc_sas_cmd(struct sas_task *task)
4249f5860992SSakthivel K {
4250e73823f7SJames Bottomley 	u8 cmd = task->ssp_task.cmd->cmnd[0];
4251e73823f7SJames Bottomley 
4252e73823f7SJames Bottomley 	if (cmd == READ_10 || cmd == WRITE_10 || cmd == WRITE_VERIFY)
4253f5860992SSakthivel K 		return 1;
4254f5860992SSakthivel K 	else
4255f5860992SSakthivel K 		return 0;
4256f5860992SSakthivel K }
4257f5860992SSakthivel K 
check_enc_sat_cmd(struct sas_task * task)4258f5860992SSakthivel K static int check_enc_sat_cmd(struct sas_task *task)
4259f5860992SSakthivel K {
4260f5860992SSakthivel K 	int ret = 0;
4261f5860992SSakthivel K 	switch (task->ata_task.fis.command) {
4262f5860992SSakthivel K 	case ATA_CMD_FPDMA_READ:
4263f5860992SSakthivel K 	case ATA_CMD_READ_EXT:
4264f5860992SSakthivel K 	case ATA_CMD_READ:
4265f5860992SSakthivel K 	case ATA_CMD_FPDMA_WRITE:
4266f5860992SSakthivel K 	case ATA_CMD_WRITE_EXT:
4267f5860992SSakthivel K 	case ATA_CMD_WRITE:
4268f5860992SSakthivel K 	case ATA_CMD_PIO_READ:
4269f5860992SSakthivel K 	case ATA_CMD_PIO_READ_EXT:
4270f5860992SSakthivel K 	case ATA_CMD_PIO_WRITE:
4271f5860992SSakthivel K 	case ATA_CMD_PIO_WRITE_EXT:
4272f5860992SSakthivel K 		ret = 1;
4273f5860992SSakthivel K 		break;
4274f5860992SSakthivel K 	default:
4275f5860992SSakthivel K 		ret = 0;
4276f5860992SSakthivel K 		break;
4277f5860992SSakthivel K 	}
4278f5860992SSakthivel K 	return ret;
4279f5860992SSakthivel K }
4280f5860992SSakthivel K 
pm80xx_chip_get_q_index(struct sas_task * task)428142f22fe3SJohn Garry static u32 pm80xx_chip_get_q_index(struct sas_task *task)
428242f22fe3SJohn Garry {
42836472cfb4SJohn Garry 	struct request *rq = sas_task_find_rq(task);
428442f22fe3SJohn Garry 
42856472cfb4SJohn Garry 	if (!rq)
428642f22fe3SJohn Garry 		return 0;
428742f22fe3SJohn Garry 
42886472cfb4SJohn Garry 	return blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(rq));
428942f22fe3SJohn Garry }
429042f22fe3SJohn Garry 
4291f5860992SSakthivel K /**
4292bb6beabfSRandy Dunlap  * pm80xx_chip_ssp_io_req - send an SSP task to FW
4293f5860992SSakthivel K  * @pm8001_ha: our hba card information.
4294f5860992SSakthivel K  * @ccb: the ccb information this request used.
4295f5860992SSakthivel K  */
pm80xx_chip_ssp_io_req(struct pm8001_hba_info * pm8001_ha,struct pm8001_ccb_info * ccb)4296f5860992SSakthivel K static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4297f5860992SSakthivel K 	struct pm8001_ccb_info *ccb)
4298f5860992SSakthivel K {
4299f5860992SSakthivel K 	struct sas_task *task = ccb->task;
4300f5860992SSakthivel K 	struct domain_device *dev = task->dev;
4301f5860992SSakthivel K 	struct pm8001_device *pm8001_dev = dev->lldd_dev;
4302f5860992SSakthivel K 	struct ssp_ini_io_start_req ssp_cmd;
4303f5860992SSakthivel K 	u32 tag = ccb->ccb_tag;
4304970404ccSDamien Le Moal 	u64 phys_addr, end_addr;
43050ecdf00bSAnand Kumar Santhanam 	u32 end_addr_high, end_addr_low;
430642f22fe3SJohn Garry 	u32 q_index;
4307f5860992SSakthivel K 	u32 opc = OPC_INB_SSPINIIOSTART;
4308970404ccSDamien Le Moal 
4309f5860992SSakthivel K 	memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4310f5860992SSakthivel K 	memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
4311970404ccSDamien Le Moal 
4312f5860992SSakthivel K 	/* data address domain added for spcv; set to 0 by host,
4313f5860992SSakthivel K 	 * used internally by controller
4314f5860992SSakthivel K 	 * 0 for SAS 1.1 and SAS 2.0 compatible TLR
4315f5860992SSakthivel K 	 */
4316f5860992SSakthivel K 	ssp_cmd.dad_dir_m_tlr =
4317f5860992SSakthivel K 		cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);
4318f5860992SSakthivel K 	ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4319f5860992SSakthivel K 	ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4320f5860992SSakthivel K 	ssp_cmd.tag = cpu_to_le32(tag);
4321f5860992SSakthivel K 	ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
4322e73823f7SJames Bottomley 	memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4323e73823f7SJames Bottomley 		       task->ssp_task.cmd->cmd_len);
432442f22fe3SJohn Garry 	q_index = pm80xx_chip_get_q_index(task);
4325f5860992SSakthivel K 
4326f5860992SSakthivel K 	/* Check if encryption is set */
4327f5860992SSakthivel K 	if (pm8001_ha->chip->encrypt &&
4328f5860992SSakthivel K 		!(pm8001_ha->encrypt_info.status) && check_enc_sas_cmd(task)) {
43291b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
4330f5860992SSakthivel K 			   "Encryption enabled.Sending Encrypt SAS command 0x%x\n",
43311b5d2793SJoe Perches 			   task->ssp_task.cmd->cmnd[0]);
4332f5860992SSakthivel K 		opc = OPC_INB_SSP_INI_DIF_ENC_IO;
4333f5860992SSakthivel K 		/* enable encryption. 0 for SAS 1.1 and SAS 2.0 compatible TLR*/
4334f5860992SSakthivel K 		ssp_cmd.dad_dir_m_tlr =	cpu_to_le32
4335f5860992SSakthivel K 			((data_dir_flags[task->data_dir] << 8) | 0x20 | 0x0);
4336f5860992SSakthivel K 
4337f5860992SSakthivel K 		/* fill in PRD (scatter/gather) table, if any */
4338f5860992SSakthivel K 		if (task->num_scatter > 1) {
4339f5860992SSakthivel K 			pm8001_chip_make_sg(task->scatter,
4340f5860992SSakthivel K 						ccb->n_elem, ccb->buf_prd);
43415a141315SViswas G 			phys_addr = ccb->ccb_dma_handle;
4342f5860992SSakthivel K 			ssp_cmd.enc_addr_low =
4343f5860992SSakthivel K 				cpu_to_le32(lower_32_bits(phys_addr));
4344f5860992SSakthivel K 			ssp_cmd.enc_addr_high =
4345f5860992SSakthivel K 				cpu_to_le32(upper_32_bits(phys_addr));
4346f5860992SSakthivel K 			ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
4347f5860992SSakthivel K 		} else if (task->num_scatter == 1) {
4348f5860992SSakthivel K 			u64 dma_addr = sg_dma_address(task->scatter);
4349970404ccSDamien Le Moal 
4350f5860992SSakthivel K 			ssp_cmd.enc_addr_low =
4351f5860992SSakthivel K 				cpu_to_le32(lower_32_bits(dma_addr));
4352f5860992SSakthivel K 			ssp_cmd.enc_addr_high =
4353f5860992SSakthivel K 				cpu_to_le32(upper_32_bits(dma_addr));
4354f5860992SSakthivel K 			ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4355f5860992SSakthivel K 			ssp_cmd.enc_esgl = 0;
4356970404ccSDamien Le Moal 
43570ecdf00bSAnand Kumar Santhanam 			/* Check 4G Boundary */
4358970404ccSDamien Le Moal 			end_addr = dma_addr + le32_to_cpu(ssp_cmd.enc_len) - 1;
4359970404ccSDamien Le Moal 			end_addr_low = lower_32_bits(end_addr);
4360970404ccSDamien Le Moal 			end_addr_high = upper_32_bits(end_addr);
4361970404ccSDamien Le Moal 
4362970404ccSDamien Le Moal 			if (end_addr_high != le32_to_cpu(ssp_cmd.enc_addr_high)) {
43631b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
43641b5d2793SJoe Perches 					   "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",
4365970404ccSDamien Le Moal 					   dma_addr,
4366970404ccSDamien Le Moal 					   le32_to_cpu(ssp_cmd.enc_len),
43671b5d2793SJoe Perches 					   end_addr_high, end_addr_low);
43680ecdf00bSAnand Kumar Santhanam 				pm8001_chip_make_sg(task->scatter, 1,
43690ecdf00bSAnand Kumar Santhanam 					ccb->buf_prd);
43705a141315SViswas G 				phys_addr = ccb->ccb_dma_handle;
43710ecdf00bSAnand Kumar Santhanam 				ssp_cmd.enc_addr_low =
43720ecdf00bSAnand Kumar Santhanam 					cpu_to_le32(lower_32_bits(phys_addr));
43730ecdf00bSAnand Kumar Santhanam 				ssp_cmd.enc_addr_high =
43740ecdf00bSAnand Kumar Santhanam 					cpu_to_le32(upper_32_bits(phys_addr));
4375970404ccSDamien Le Moal 				ssp_cmd.enc_esgl = cpu_to_le32(1U<<31);
43760ecdf00bSAnand Kumar Santhanam 			}
4377f5860992SSakthivel K 		} else if (task->num_scatter == 0) {
4378f5860992SSakthivel K 			ssp_cmd.enc_addr_low = 0;
4379f5860992SSakthivel K 			ssp_cmd.enc_addr_high = 0;
4380f5860992SSakthivel K 			ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4381f5860992SSakthivel K 			ssp_cmd.enc_esgl = 0;
4382f5860992SSakthivel K 		}
4383970404ccSDamien Le Moal 
4384f5860992SSakthivel K 		/* XTS mode. All other fields are 0 */
4385970404ccSDamien Le Moal 		ssp_cmd.key_cmode = cpu_to_le32(0x6 << 4);
4386970404ccSDamien Le Moal 
4387f5860992SSakthivel K 		/* set tweak values. Should be the start lba */
4388e73823f7SJames Bottomley 		ssp_cmd.twk_val0 = cpu_to_le32((task->ssp_task.cmd->cmnd[2] << 24) |
4389e73823f7SJames Bottomley 						(task->ssp_task.cmd->cmnd[3] << 16) |
4390e73823f7SJames Bottomley 						(task->ssp_task.cmd->cmnd[4] << 8) |
4391e73823f7SJames Bottomley 						(task->ssp_task.cmd->cmnd[5]));
4392f5860992SSakthivel K 	} else {
43931b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
4394f5860992SSakthivel K 			   "Sending Normal SAS command 0x%x inb q %x\n",
43951b5d2793SJoe Perches 			   task->ssp_task.cmd->cmnd[0], q_index);
4396f5860992SSakthivel K 		/* fill in PRD (scatter/gather) table, if any */
4397f5860992SSakthivel K 		if (task->num_scatter > 1) {
4398f5860992SSakthivel K 			pm8001_chip_make_sg(task->scatter, ccb->n_elem,
4399f5860992SSakthivel K 					ccb->buf_prd);
44005a141315SViswas G 			phys_addr = ccb->ccb_dma_handle;
4401f5860992SSakthivel K 			ssp_cmd.addr_low =
4402f5860992SSakthivel K 				cpu_to_le32(lower_32_bits(phys_addr));
4403f5860992SSakthivel K 			ssp_cmd.addr_high =
4404f5860992SSakthivel K 				cpu_to_le32(upper_32_bits(phys_addr));
4405f5860992SSakthivel K 			ssp_cmd.esgl = cpu_to_le32(1<<31);
4406f5860992SSakthivel K 		} else if (task->num_scatter == 1) {
4407f5860992SSakthivel K 			u64 dma_addr = sg_dma_address(task->scatter);
4408970404ccSDamien Le Moal 
4409f5860992SSakthivel K 			ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4410f5860992SSakthivel K 			ssp_cmd.addr_high =
4411f5860992SSakthivel K 				cpu_to_le32(upper_32_bits(dma_addr));
4412f5860992SSakthivel K 			ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4413f5860992SSakthivel K 			ssp_cmd.esgl = 0;
4414970404ccSDamien Le Moal 
44150ecdf00bSAnand Kumar Santhanam 			/* Check 4G Boundary */
4416970404ccSDamien Le Moal 			end_addr = dma_addr + le32_to_cpu(ssp_cmd.len) - 1;
4417970404ccSDamien Le Moal 			end_addr_low = lower_32_bits(end_addr);
4418970404ccSDamien Le Moal 			end_addr_high = upper_32_bits(end_addr);
4419970404ccSDamien Le Moal 			if (end_addr_high != le32_to_cpu(ssp_cmd.addr_high)) {
44201b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
44211b5d2793SJoe Perches 					   "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",
4422970404ccSDamien Le Moal 					   dma_addr,
4423970404ccSDamien Le Moal 					   le32_to_cpu(ssp_cmd.len),
44241b5d2793SJoe Perches 					   end_addr_high, end_addr_low);
44250ecdf00bSAnand Kumar Santhanam 				pm8001_chip_make_sg(task->scatter, 1,
44260ecdf00bSAnand Kumar Santhanam 					ccb->buf_prd);
44275a141315SViswas G 				phys_addr = ccb->ccb_dma_handle;
44280ecdf00bSAnand Kumar Santhanam 				ssp_cmd.addr_low =
44290ecdf00bSAnand Kumar Santhanam 					cpu_to_le32(lower_32_bits(phys_addr));
44300ecdf00bSAnand Kumar Santhanam 				ssp_cmd.addr_high =
44310ecdf00bSAnand Kumar Santhanam 					cpu_to_le32(upper_32_bits(phys_addr));
44320ecdf00bSAnand Kumar Santhanam 				ssp_cmd.esgl = cpu_to_le32(1<<31);
44330ecdf00bSAnand Kumar Santhanam 			}
4434f5860992SSakthivel K 		} else if (task->num_scatter == 0) {
4435f5860992SSakthivel K 			ssp_cmd.addr_low = 0;
4436f5860992SSakthivel K 			ssp_cmd.addr_high = 0;
4437f5860992SSakthivel K 			ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4438f5860992SSakthivel K 			ssp_cmd.esgl = 0;
4439f5860992SSakthivel K 		}
4440f5860992SSakthivel K 	}
4441f91767a3SDamien Le Moal 
4442f91767a3SDamien Le Moal 	return pm8001_mpi_build_cmd(pm8001_ha, q_index, opc, &ssp_cmd,
4443f91767a3SDamien Le Moal 				    sizeof(ssp_cmd), q_index);
4444f5860992SSakthivel K }
4445f5860992SSakthivel K 
pm80xx_chip_sata_req(struct pm8001_hba_info * pm8001_ha,struct pm8001_ccb_info * ccb)4446f5860992SSakthivel K static int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4447f5860992SSakthivel K 	struct pm8001_ccb_info *ccb)
4448f5860992SSakthivel K {
4449f5860992SSakthivel K 	struct sas_task *task = ccb->task;
4450f5860992SSakthivel K 	struct domain_device *dev = task->dev;
4451f5860992SSakthivel K 	struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
44528ceddda3SChangyuan Lyu 	struct ata_queued_cmd *qc = task->uldd_task;
445342f22fe3SJohn Garry 	u32 tag = ccb->ccb_tag, q_index;
4454f5860992SSakthivel K 	struct sata_start_req sata_cmd;
4455f5860992SSakthivel K 	u32 hdr_tag, ncg_tag = 0;
4456fd6d0e37SDamien Le Moal 	u64 phys_addr, end_addr;
44570ecdf00bSAnand Kumar Santhanam 	u32 end_addr_high, end_addr_low;
4458f5860992SSakthivel K 	u32 ATAP = 0x0;
445954543295SIgor Pylypiv 	u32 dir, retfis = 0;
4460f5860992SSakthivel K 	u32 opc = OPC_INB_SATA_HOST_OPSTART;
4461f5860992SSakthivel K 	memset(&sata_cmd, 0, sizeof(sata_cmd));
446242f22fe3SJohn Garry 
446342f22fe3SJohn Garry 	q_index = pm80xx_chip_get_q_index(task);
4464f5860992SSakthivel K 
4465aa028141SDamien Le Moal 	if (task->data_dir == DMA_NONE && !task->ata_task.use_ncq) {
4466f5860992SSakthivel K 		ATAP = 0x04; /* no data*/
44671b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO, "no data\n");
4468f5860992SSakthivel K 	} else if (likely(!task->ata_task.device_control_reg_update)) {
4469aa028141SDamien Le Moal 		if (task->ata_task.use_ncq &&
4470aa028141SDamien Le Moal 		    dev->sata_dev.class != ATA_DEV_ATAPI) {
4471aa028141SDamien Le Moal 			ATAP = 0x07; /* FPDMA */
4472aa028141SDamien Le Moal 			pm8001_dbg(pm8001_ha, IO, "FPDMA\n");
4473aa028141SDamien Le Moal 		} else if (task->ata_task.dma_xfer) {
4474f5860992SSakthivel K 			ATAP = 0x06; /* DMA */
44751b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, IO, "DMA\n");
4476f5860992SSakthivel K 		} else {
4477f5860992SSakthivel K 			ATAP = 0x05; /* PIO*/
44781b5d2793SJoe Perches 			pm8001_dbg(pm8001_ha, IO, "PIO\n");
4479f5860992SSakthivel K 		}
4480f5860992SSakthivel K 	}
4481c6b9ef57SSakthivel K 	if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4482c6b9ef57SSakthivel K 		task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
4483f5860992SSakthivel K 		ncg_tag = hdr_tag;
4484c6b9ef57SSakthivel K 	}
4485f5860992SSakthivel K 	dir = data_dir_flags[task->data_dir] << 8;
4486f5860992SSakthivel K 	sata_cmd.tag = cpu_to_le32(tag);
4487f5860992SSakthivel K 	sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4488f5860992SSakthivel K 	sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
448954543295SIgor Pylypiv 	if (task->ata_task.return_fis_on_success)
449054543295SIgor Pylypiv 		retfis = 1;
4491f5860992SSakthivel K 	sata_cmd.sata_fis = task->ata_task.fis;
4492f5860992SSakthivel K 	if (likely(!task->ata_task.device_control_reg_update))
4493f5860992SSakthivel K 		sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4494f5860992SSakthivel K 	sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4495f5860992SSakthivel K 
4496f5860992SSakthivel K 	/* Check if encryption is set */
4497f5860992SSakthivel K 	if (pm8001_ha->chip->encrypt &&
4498f5860992SSakthivel K 		!(pm8001_ha->encrypt_info.status) && check_enc_sat_cmd(task)) {
44991b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
4500f5860992SSakthivel K 			   "Encryption enabled.Sending Encrypt SATA cmd 0x%x\n",
45011b5d2793SJoe Perches 			   sata_cmd.sata_fis.command);
4502f5860992SSakthivel K 		opc = OPC_INB_SATA_DIF_ENC_IO;
450354543295SIgor Pylypiv 		/* set encryption bit; dad (bits 0-1) is 0 */
450454543295SIgor Pylypiv 		sata_cmd.retfis_ncqtag_atap_dir_m_dad =
450554543295SIgor Pylypiv 			cpu_to_le32((retfis << 24) | ((ncg_tag & 0xff) << 16) |
4506f5860992SSakthivel K 				    ((ATAP & 0x3f) << 10) | 0x20 | dir);
4507f5860992SSakthivel K 		/* fill in PRD (scatter/gather) table, if any */
4508f5860992SSakthivel K 		if (task->num_scatter > 1) {
4509f5860992SSakthivel K 			pm8001_chip_make_sg(task->scatter,
4510f5860992SSakthivel K 						ccb->n_elem, ccb->buf_prd);
45115a141315SViswas G 			phys_addr = ccb->ccb_dma_handle;
4512fd6d0e37SDamien Le Moal 			sata_cmd.enc_addr_low =
4513fd6d0e37SDamien Le Moal 				cpu_to_le32(lower_32_bits(phys_addr));
4514fd6d0e37SDamien Le Moal 			sata_cmd.enc_addr_high =
4515fd6d0e37SDamien Le Moal 				cpu_to_le32(upper_32_bits(phys_addr));
4516f5860992SSakthivel K 			sata_cmd.enc_esgl = cpu_to_le32(1 << 31);
4517f5860992SSakthivel K 		} else if (task->num_scatter == 1) {
4518f5860992SSakthivel K 			u64 dma_addr = sg_dma_address(task->scatter);
4519fd6d0e37SDamien Le Moal 
4520fd6d0e37SDamien Le Moal 			sata_cmd.enc_addr_low =
4521fd6d0e37SDamien Le Moal 				cpu_to_le32(lower_32_bits(dma_addr));
4522fd6d0e37SDamien Le Moal 			sata_cmd.enc_addr_high =
4523fd6d0e37SDamien Le Moal 				cpu_to_le32(upper_32_bits(dma_addr));
4524f5860992SSakthivel K 			sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4525f5860992SSakthivel K 			sata_cmd.enc_esgl = 0;
4526fd6d0e37SDamien Le Moal 
45270ecdf00bSAnand Kumar Santhanam 			/* Check 4G Boundary */
4528fd6d0e37SDamien Le Moal 			end_addr = dma_addr + le32_to_cpu(sata_cmd.enc_len) - 1;
4529fd6d0e37SDamien Le Moal 			end_addr_low = lower_32_bits(end_addr);
4530fd6d0e37SDamien Le Moal 			end_addr_high = upper_32_bits(end_addr);
4531fd6d0e37SDamien Le Moal 			if (end_addr_high != le32_to_cpu(sata_cmd.enc_addr_high)) {
45321b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
45331b5d2793SJoe Perches 					   "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",
4534fd6d0e37SDamien Le Moal 					   dma_addr,
4535fd6d0e37SDamien Le Moal 					   le32_to_cpu(sata_cmd.enc_len),
45361b5d2793SJoe Perches 					   end_addr_high, end_addr_low);
45370ecdf00bSAnand Kumar Santhanam 				pm8001_chip_make_sg(task->scatter, 1,
45380ecdf00bSAnand Kumar Santhanam 					ccb->buf_prd);
45395a141315SViswas G 				phys_addr = ccb->ccb_dma_handle;
45400ecdf00bSAnand Kumar Santhanam 				sata_cmd.enc_addr_low =
4541fd6d0e37SDamien Le Moal 					cpu_to_le32(lower_32_bits(phys_addr));
45420ecdf00bSAnand Kumar Santhanam 				sata_cmd.enc_addr_high =
4543fd6d0e37SDamien Le Moal 					cpu_to_le32(upper_32_bits(phys_addr));
45440ecdf00bSAnand Kumar Santhanam 				sata_cmd.enc_esgl =
45450ecdf00bSAnand Kumar Santhanam 					cpu_to_le32(1 << 31);
45460ecdf00bSAnand Kumar Santhanam 			}
4547f5860992SSakthivel K 		} else if (task->num_scatter == 0) {
4548f5860992SSakthivel K 			sata_cmd.enc_addr_low = 0;
4549f5860992SSakthivel K 			sata_cmd.enc_addr_high = 0;
4550f5860992SSakthivel K 			sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4551f5860992SSakthivel K 			sata_cmd.enc_esgl = 0;
4552f5860992SSakthivel K 		}
4553f5860992SSakthivel K 		/* XTS mode. All other fields are 0 */
4554fd6d0e37SDamien Le Moal 		sata_cmd.key_index_mode = cpu_to_le32(0x6 << 4);
4555fd6d0e37SDamien Le Moal 
4556f5860992SSakthivel K 		/* set tweak values. Should be the start lba */
4557f5860992SSakthivel K 		sata_cmd.twk_val0 =
4558f5860992SSakthivel K 			cpu_to_le32((sata_cmd.sata_fis.lbal_exp << 24) |
4559f5860992SSakthivel K 					(sata_cmd.sata_fis.lbah << 16) |
4560f5860992SSakthivel K 					(sata_cmd.sata_fis.lbam << 8) |
4561f5860992SSakthivel K 					(sata_cmd.sata_fis.lbal));
4562f5860992SSakthivel K 		sata_cmd.twk_val1 =
4563f5860992SSakthivel K 			cpu_to_le32((sata_cmd.sata_fis.lbah_exp << 8) |
4564f5860992SSakthivel K 					 (sata_cmd.sata_fis.lbam_exp));
4565f5860992SSakthivel K 	} else {
45661b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, IO,
4567f5860992SSakthivel K 			   "Sending Normal SATA command 0x%x inb %x\n",
45681b5d2793SJoe Perches 			   sata_cmd.sata_fis.command, q_index);
456954543295SIgor Pylypiv 		/* dad (bits 0-1) is 0 */
457054543295SIgor Pylypiv 		sata_cmd.retfis_ncqtag_atap_dir_m_dad =
457154543295SIgor Pylypiv 			cpu_to_le32((retfis << 24) | ((ncg_tag & 0xff) << 16) |
4572f5860992SSakthivel K 				    ((ATAP & 0x3f) << 10) | dir);
4573f5860992SSakthivel K 		/* fill in PRD (scatter/gather) table, if any */
4574f5860992SSakthivel K 		if (task->num_scatter > 1) {
4575f5860992SSakthivel K 			pm8001_chip_make_sg(task->scatter,
4576f5860992SSakthivel K 					ccb->n_elem, ccb->buf_prd);
45775a141315SViswas G 			phys_addr = ccb->ccb_dma_handle;
4578f5860992SSakthivel K 			sata_cmd.addr_low = lower_32_bits(phys_addr);
4579f5860992SSakthivel K 			sata_cmd.addr_high = upper_32_bits(phys_addr);
4580fd6d0e37SDamien Le Moal 			sata_cmd.esgl = cpu_to_le32(1U << 31);
4581f5860992SSakthivel K 		} else if (task->num_scatter == 1) {
4582f5860992SSakthivel K 			u64 dma_addr = sg_dma_address(task->scatter);
4583fd6d0e37SDamien Le Moal 
4584f5860992SSakthivel K 			sata_cmd.addr_low = lower_32_bits(dma_addr);
4585f5860992SSakthivel K 			sata_cmd.addr_high = upper_32_bits(dma_addr);
4586f5860992SSakthivel K 			sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4587f5860992SSakthivel K 			sata_cmd.esgl = 0;
4588fd6d0e37SDamien Le Moal 
45890ecdf00bSAnand Kumar Santhanam 			/* Check 4G Boundary */
4590fd6d0e37SDamien Le Moal 			end_addr = dma_addr + le32_to_cpu(sata_cmd.len) - 1;
4591fd6d0e37SDamien Le Moal 			end_addr_low = lower_32_bits(end_addr);
4592fd6d0e37SDamien Le Moal 			end_addr_high = upper_32_bits(end_addr);
45930ecdf00bSAnand Kumar Santhanam 			if (end_addr_high != sata_cmd.addr_high) {
45941b5d2793SJoe Perches 				pm8001_dbg(pm8001_ha, FAIL,
45951b5d2793SJoe Perches 					   "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",
4596fd6d0e37SDamien Le Moal 					   dma_addr,
4597fd6d0e37SDamien Le Moal 					   le32_to_cpu(sata_cmd.len),
45981b5d2793SJoe Perches 					   end_addr_high, end_addr_low);
45990ecdf00bSAnand Kumar Santhanam 				pm8001_chip_make_sg(task->scatter, 1,
46000ecdf00bSAnand Kumar Santhanam 					ccb->buf_prd);
46015a141315SViswas G 				phys_addr = ccb->ccb_dma_handle;
4602fd6d0e37SDamien Le Moal 				sata_cmd.addr_low = lower_32_bits(phys_addr);
4603fd6d0e37SDamien Le Moal 				sata_cmd.addr_high = upper_32_bits(phys_addr);
4604fd6d0e37SDamien Le Moal 				sata_cmd.esgl = cpu_to_le32(1U << 31);
46050ecdf00bSAnand Kumar Santhanam 			}
4606f5860992SSakthivel K 		} else if (task->num_scatter == 0) {
4607f5860992SSakthivel K 			sata_cmd.addr_low = 0;
4608f5860992SSakthivel K 			sata_cmd.addr_high = 0;
4609f5860992SSakthivel K 			sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4610f5860992SSakthivel K 			sata_cmd.esgl = 0;
4611f5860992SSakthivel K 		}
4612fd6d0e37SDamien Le Moal 
4613f5860992SSakthivel K 		/* scsi cdb */
4614f5860992SSakthivel K 		sata_cmd.atapi_scsi_cdb[0] =
4615f5860992SSakthivel K 			cpu_to_le32(((task->ata_task.atapi_packet[0]) |
4616f5860992SSakthivel K 				     (task->ata_task.atapi_packet[1] << 8) |
4617f5860992SSakthivel K 				     (task->ata_task.atapi_packet[2] << 16) |
4618f5860992SSakthivel K 				     (task->ata_task.atapi_packet[3] << 24)));
4619f5860992SSakthivel K 		sata_cmd.atapi_scsi_cdb[1] =
4620f5860992SSakthivel K 			cpu_to_le32(((task->ata_task.atapi_packet[4]) |
4621f5860992SSakthivel K 				     (task->ata_task.atapi_packet[5] << 8) |
4622f5860992SSakthivel K 				     (task->ata_task.atapi_packet[6] << 16) |
4623f5860992SSakthivel K 				     (task->ata_task.atapi_packet[7] << 24)));
4624f5860992SSakthivel K 		sata_cmd.atapi_scsi_cdb[2] =
4625f5860992SSakthivel K 			cpu_to_le32(((task->ata_task.atapi_packet[8]) |
4626f5860992SSakthivel K 				     (task->ata_task.atapi_packet[9] << 8) |
4627f5860992SSakthivel K 				     (task->ata_task.atapi_packet[10] << 16) |
4628f5860992SSakthivel K 				     (task->ata_task.atapi_packet[11] << 24)));
4629f5860992SSakthivel K 		sata_cmd.atapi_scsi_cdb[3] =
4630f5860992SSakthivel K 			cpu_to_le32(((task->ata_task.atapi_packet[12]) |
4631f5860992SSakthivel K 				     (task->ata_task.atapi_packet[13] << 8) |
4632f5860992SSakthivel K 				     (task->ata_task.atapi_packet[14] << 16) |
4633f5860992SSakthivel K 				     (task->ata_task.atapi_packet[15] << 24)));
4634f5860992SSakthivel K 	}
4635c6b9ef57SSakthivel K 
46368ceddda3SChangyuan Lyu 	trace_pm80xx_request_issue(pm8001_ha->id,
46378ceddda3SChangyuan Lyu 				ccb->device ? ccb->device->attached_phy : PM8001_MAX_PHYS,
46388ceddda3SChangyuan Lyu 				ccb->ccb_tag, opc,
46398ceddda3SChangyuan Lyu 				qc ? qc->tf.command : 0, // ata opcode
46408ceddda3SChangyuan Lyu 				ccb->device ? atomic_read(&ccb->device->running_req) : 0);
4641f91767a3SDamien Le Moal 	return pm8001_mpi_build_cmd(pm8001_ha, q_index, opc, &sata_cmd,
4642f91767a3SDamien Le Moal 				    sizeof(sata_cmd), q_index);
4643f5860992SSakthivel K }
4644f5860992SSakthivel K 
4645f5860992SSakthivel K /**
4646f5860992SSakthivel K  * pm80xx_chip_phy_start_req - start phy via PHY_START COMMAND
4647f5860992SSakthivel K  * @pm8001_ha: our hba card information.
4648f5860992SSakthivel K  * @phy_id: the phy id which we wanted to start up.
4649f5860992SSakthivel K  */
4650f5860992SSakthivel K static int
pm80xx_chip_phy_start_req(struct pm8001_hba_info * pm8001_ha,u8 phy_id)4651f5860992SSakthivel K pm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4652f5860992SSakthivel K {
4653f5860992SSakthivel K 	struct phy_start_req payload;
4654f5860992SSakthivel K 	u32 tag = 0x01;
4655f5860992SSakthivel K 	u32 opcode = OPC_INB_PHYSTART;
4656f91767a3SDamien Le Moal 
4657f5860992SSakthivel K 	memset(&payload, 0, sizeof(payload));
4658f5860992SSakthivel K 	payload.tag = cpu_to_le32(tag);
4659f5860992SSakthivel K 
46601b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "PHY START REQ for phy_id %d\n", phy_id);
4661a9a923e5SAnand Kumar Santhanam 
46623e253d96Speter chang 	payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
46633e253d96Speter chang 			LINKMODE_AUTO | pm8001_ha->link_rate | phy_id);
4664f5860992SSakthivel K 	/* SSC Disable and SAS Analog ST configuration */
4665bb6beabfSRandy Dunlap 	/*
4666f5860992SSakthivel K 	payload.ase_sh_lm_slr_phyid =
4667f5860992SSakthivel K 		cpu_to_le32(SSC_DISABLE_30 | SAS_ASE | SPINHOLD_DISABLE |
4668f5860992SSakthivel K 		LINKMODE_AUTO | LINKRATE_15 | LINKRATE_30 | LINKRATE_60 |
4669f5860992SSakthivel K 		phy_id);
4670f5860992SSakthivel K 	Have to add "SAS PHY Analog Setup SPASTI 1 Byte" Based on need
4671bb6beabfSRandy Dunlap 	*/
4672f5860992SSakthivel K 
4673aa9f8328SJames Bottomley 	payload.sas_identify.dev_type = SAS_END_DEVICE;
4674f5860992SSakthivel K 	payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4675f5860992SSakthivel K 	memcpy(payload.sas_identify.sas_addr,
467671996bb8SMichal Grzedzicki 		&pm8001_ha->phy[phy_id].dev_sas_addr, SAS_ADDR_SIZE);
4677f5860992SSakthivel K 	payload.sas_identify.phy_id = phy_id;
4678f91767a3SDamien Le Moal 
4679f91767a3SDamien Le Moal 	return pm8001_mpi_build_cmd(pm8001_ha, 0, opcode, &payload,
468091a43fa6Speter chang 				    sizeof(payload), 0);
4681f5860992SSakthivel K }
4682f5860992SSakthivel K 
4683f5860992SSakthivel K /**
46847cdaf12eSLee Jones  * pm80xx_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4685f5860992SSakthivel K  * @pm8001_ha: our hba card information.
4686f5860992SSakthivel K  * @phy_id: the phy id which we wanted to start up.
4687f5860992SSakthivel K  */
pm80xx_chip_phy_stop_req(struct pm8001_hba_info * pm8001_ha,u8 phy_id)4688f5860992SSakthivel K static int pm80xx_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4689f5860992SSakthivel K 	u8 phy_id)
4690f5860992SSakthivel K {
4691f5860992SSakthivel K 	struct phy_stop_req payload;
4692f5860992SSakthivel K 	u32 tag = 0x01;
4693f5860992SSakthivel K 	u32 opcode = OPC_INB_PHYSTOP;
4694f91767a3SDamien Le Moal 
4695f5860992SSakthivel K 	memset(&payload, 0, sizeof(payload));
4696f5860992SSakthivel K 	payload.tag = cpu_to_le32(tag);
4697f5860992SSakthivel K 	payload.phy_id = cpu_to_le32(phy_id);
4698f91767a3SDamien Le Moal 
4699f91767a3SDamien Le Moal 	return pm8001_mpi_build_cmd(pm8001_ha, 0, opcode, &payload,
470091a43fa6Speter chang 				    sizeof(payload), 0);
4701f5860992SSakthivel K }
4702f5860992SSakthivel K 
47036ad4a517SLee Jones /*
4704f5860992SSakthivel K  * see comments on pm8001_mpi_reg_resp.
4705f5860992SSakthivel K  */
pm80xx_chip_reg_dev_req(struct pm8001_hba_info * pm8001_ha,struct pm8001_device * pm8001_dev,u32 flag)4706f5860992SSakthivel K static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4707f5860992SSakthivel K 	struct pm8001_device *pm8001_dev, u32 flag)
4708f5860992SSakthivel K {
4709f5860992SSakthivel K 	struct reg_dev_req payload;
4710f5860992SSakthivel K 	u32	opc;
4711f5860992SSakthivel K 	u32 stp_sspsmp_sata = 0x4;
4712f5860992SSakthivel K 	u32 linkrate, phy_id;
471399df0edbSDamien Le Moal 	int rc;
4714f5860992SSakthivel K 	struct pm8001_ccb_info *ccb;
4715f5860992SSakthivel K 	u8 retryFlag = 0x1;
4716f5860992SSakthivel K 	u16 firstBurstSize = 0;
4717f5860992SSakthivel K 	u16 ITNT = 2000;
4718f5860992SSakthivel K 	struct domain_device *dev = pm8001_dev->sas_device;
4719f5860992SSakthivel K 	struct domain_device *parent_dev = dev->parent;
472008d0a992SAjish Koshy 	struct pm8001_port *port = dev->port->lldd_port;
4721f5860992SSakthivel K 
4722f5860992SSakthivel K 	memset(&payload, 0, sizeof(payload));
472399df0edbSDamien Le Moal 	ccb = pm8001_ccb_alloc(pm8001_ha, pm8001_dev, NULL);
472499df0edbSDamien Le Moal 	if (!ccb)
472599df0edbSDamien Le Moal 		return -SAS_QUEUE_FULL;
472699df0edbSDamien Le Moal 
472799df0edbSDamien Le Moal 	payload.tag = cpu_to_le32(ccb->ccb_tag);
4728f5860992SSakthivel K 
4729f5860992SSakthivel K 	if (flag == 1) {
4730f5860992SSakthivel K 		stp_sspsmp_sata = 0x02; /*direct attached sata */
4731f5860992SSakthivel K 	} else {
4732aa9f8328SJames Bottomley 		if (pm8001_dev->dev_type == SAS_SATA_DEV)
4733f5860992SSakthivel K 			stp_sspsmp_sata = 0x00; /* stp*/
4734aa9f8328SJames Bottomley 		else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
47354f632918SIgor Pylypiv 			dev_is_expander(pm8001_dev->dev_type))
4736f5860992SSakthivel K 			stp_sspsmp_sata = 0x01; /*ssp or smp*/
4737f5860992SSakthivel K 	}
4738924a3541SJohn Garry 	if (parent_dev && dev_is_expander(parent_dev->dev_type))
4739f5860992SSakthivel K 		phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4740f5860992SSakthivel K 	else
4741f5860992SSakthivel K 		phy_id = pm8001_dev->attached_phy;
4742f5860992SSakthivel K 
4743f5860992SSakthivel K 	opc = OPC_INB_REG_DEV;
4744f5860992SSakthivel K 
4745f5860992SSakthivel K 	linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4746f5860992SSakthivel K 			pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4747f5860992SSakthivel K 
4748f5860992SSakthivel K 	payload.phyid_portid =
474908d0a992SAjish Koshy 		cpu_to_le32(((port->port_id) & 0xFF) |
4750f5860992SSakthivel K 		((phy_id & 0xFF) << 8));
4751f5860992SSakthivel K 
4752f5860992SSakthivel K 	payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 0x01) |
4753f5860992SSakthivel K 		((linkrate & 0x0F) << 24) |
4754f5860992SSakthivel K 		((stp_sspsmp_sata & 0x03) << 28));
4755f5860992SSakthivel K 	payload.firstburstsize_ITNexustimeout =
4756f5860992SSakthivel K 		cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
4757f5860992SSakthivel K 
4758f5860992SSakthivel K 	memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
4759f5860992SSakthivel K 		SAS_ADDR_SIZE);
4760f5860992SSakthivel K 
47615f797120SAkshat Jain 	pm8001_dbg(pm8001_ha, INIT,
47625f797120SAkshat Jain 		   "register device req phy_id 0x%x port_id 0x%x\n", phy_id,
47635f797120SAkshat Jain 		   (port->port_id & 0xFF));
4764f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
476591a43fa6Speter chang 			sizeof(payload), 0);
47665533abcaSTomas Henzl 	if (rc)
476799df0edbSDamien Le Moal 		pm8001_ccb_free(pm8001_ha, ccb);
4768f5860992SSakthivel K 
4769f5860992SSakthivel K 	return rc;
4770f5860992SSakthivel K }
4771f5860992SSakthivel K 
4772f5860992SSakthivel K /**
4773f5860992SSakthivel K  * pm80xx_chip_phy_ctl_req - support the local phy operation
4774f5860992SSakthivel K  * @pm8001_ha: our hba card information.
47756ad4a517SLee Jones  * @phyId: the phy id which we wanted to operate
47766ad4a517SLee Jones  * @phy_op: phy operation to request
4777f5860992SSakthivel K  */
pm80xx_chip_phy_ctl_req(struct pm8001_hba_info * pm8001_ha,u32 phyId,u32 phy_op)4778f5860992SSakthivel K static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4779f5860992SSakthivel K 	u32 phyId, u32 phy_op)
4780f5860992SSakthivel K {
478125c6edbdSViswas G 	u32 tag;
478225c6edbdSViswas G 	int rc;
4783f5860992SSakthivel K 	struct local_phy_ctl_req payload;
4784f5860992SSakthivel K 	u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
4785f91767a3SDamien Le Moal 
4786f5860992SSakthivel K 	memset(&payload, 0, sizeof(payload));
478725c6edbdSViswas G 	rc = pm8001_tag_alloc(pm8001_ha, &tag);
478825c6edbdSViswas G 	if (rc)
478925c6edbdSViswas G 		return rc;
4790f91767a3SDamien Le Moal 
479125c6edbdSViswas G 	payload.tag = cpu_to_le32(tag);
4792f5860992SSakthivel K 	payload.phyop_phyid =
4793f5860992SSakthivel K 		cpu_to_le32(((phy_op & 0xFF) << 8) | (phyId & 0xFF));
47944c8f04b1SDamien Le Moal 
4795f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
479691a43fa6Speter chang 				  sizeof(payload), 0);
47974c8f04b1SDamien Le Moal 	if (rc)
47984c8f04b1SDamien Le Moal 		pm8001_tag_free(pm8001_ha, tag);
47994c8f04b1SDamien Le Moal 
48004c8f04b1SDamien Le Moal 	return rc;
4801f5860992SSakthivel K }
4802f5860992SSakthivel K 
pm80xx_chip_is_our_interrupt(struct pm8001_hba_info * pm8001_ha)4803f310a4eaSColin Ian King static u32 pm80xx_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
4804f5860992SSakthivel K {
4805f5860992SSakthivel K #ifdef PM8001_USE_MSIX
4806f5860992SSakthivel K 	return 1;
4807292c04ccSColin Ian King #else
4808292c04ccSColin Ian King 	u32 value;
4809292c04ccSColin Ian King 
4810f5860992SSakthivel K 	value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4811f5860992SSakthivel K 	if (value)
4812f5860992SSakthivel K 		return 1;
4813f5860992SSakthivel K 	return 0;
4814292c04ccSColin Ian King #endif
4815f5860992SSakthivel K }
4816f5860992SSakthivel K 
4817f5860992SSakthivel K /**
48187cdaf12eSLee Jones  * pm80xx_chip_isr - PM8001 isr handler.
4819f5860992SSakthivel K  * @pm8001_ha: our hba card information.
48206ad4a517SLee Jones  * @vec: irq number.
4821f5860992SSakthivel K  */
4822f5860992SSakthivel K static irqreturn_t
pm80xx_chip_isr(struct pm8001_hba_info * pm8001_ha,u8 vec)4823f5860992SSakthivel K pm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
4824f5860992SSakthivel K {
4825f5860992SSakthivel K 	pm80xx_chip_interrupt_disable(pm8001_ha, vec);
48261b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, DEVIO,
48277370672dSpeter chang 		   "irq vec %d, ODMR:0x%x\n",
48281b5d2793SJoe Perches 		   vec, pm8001_cr32(pm8001_ha, 0, 0x30));
4829f5860992SSakthivel K 	process_oq(pm8001_ha, vec);
4830f5860992SSakthivel K 	pm80xx_chip_interrupt_enable(pm8001_ha, vec);
4831f5860992SSakthivel K 	return IRQ_HANDLED;
4832f5860992SSakthivel K }
4833f5860992SSakthivel K 
mpi_set_phy_profile_req(struct pm8001_hba_info * pm8001_ha,u32 operation,u32 phyid,u32 length,u32 * buf)4834ea310f57SLee Jones static void mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
4835ea310f57SLee Jones 				    u32 operation, u32 phyid,
4836ea310f57SLee Jones 				    u32 length, u32 *buf)
483727909407SAnand Kumar Santhanam {
483827909407SAnand Kumar Santhanam 	u32 tag, i, j = 0;
483927909407SAnand Kumar Santhanam 	int rc;
484027909407SAnand Kumar Santhanam 	struct set_phy_profile_req payload;
484127909407SAnand Kumar Santhanam 	u32 opc = OPC_INB_SET_PHY_PROFILE;
484227909407SAnand Kumar Santhanam 
484327909407SAnand Kumar Santhanam 	memset(&payload, 0, sizeof(payload));
484427909407SAnand Kumar Santhanam 	rc = pm8001_tag_alloc(pm8001_ha, &tag);
4845f17c599aSDamien Le Moal 	if (rc) {
48461b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL, "Invalid tag\n");
4847f17c599aSDamien Le Moal 		return;
4848f17c599aSDamien Le Moal 	}
4849f17c599aSDamien Le Moal 
485027909407SAnand Kumar Santhanam 	payload.tag = cpu_to_le32(tag);
4851e5039a92SDamien Le Moal 	payload.ppc_phyid =
4852e5039a92SDamien Le Moal 		cpu_to_le32(((operation & 0xF) << 8) | (phyid  & 0xFF));
48536a516506SAkshat Jain 	pm8001_dbg(pm8001_ha, DISC,
48541b5d2793SJoe Perches 		   " phy profile command for phy %x ,length is %d\n",
4855e5039a92SDamien Le Moal 		   le32_to_cpu(payload.ppc_phyid), length);
485627909407SAnand Kumar Santhanam 	for (i = length; i < (length + PHY_DWORD_LENGTH - 1); i++) {
485727909407SAnand Kumar Santhanam 		payload.reserved[j] = cpu_to_le32(*((u32 *)buf + i));
485827909407SAnand Kumar Santhanam 		j++;
485927909407SAnand Kumar Santhanam 	}
4860f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
486191a43fa6Speter chang 				  sizeof(payload), 0);
48625533abcaSTomas Henzl 	if (rc)
48635533abcaSTomas Henzl 		pm8001_tag_free(pm8001_ha, tag);
486427909407SAnand Kumar Santhanam }
486527909407SAnand Kumar Santhanam 
pm8001_set_phy_profile(struct pm8001_hba_info * pm8001_ha,u32 length,u8 * buf)486627909407SAnand Kumar Santhanam void pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha,
486727909407SAnand Kumar Santhanam 	u32 length, u8 *buf)
486827909407SAnand Kumar Santhanam {
4869fdd0a66bSYueHaibing 	u32 i;
487027909407SAnand Kumar Santhanam 
487127909407SAnand Kumar Santhanam 	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
487227909407SAnand Kumar Santhanam 		mpi_set_phy_profile_req(pm8001_ha,
487327909407SAnand Kumar Santhanam 			SAS_PHY_ANALOG_SETTINGS_PAGE, i, length, (u32 *)buf);
487427909407SAnand Kumar Santhanam 		length = length + PHY_DWORD_LENGTH;
487527909407SAnand Kumar Santhanam 	}
48761b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "phy settings completed\n");
487727909407SAnand Kumar Santhanam }
4878c5614df7SBenjamin Rood 
pm8001_set_phy_profile_single(struct pm8001_hba_info * pm8001_ha,u32 phy,u32 length,u32 * buf)4879c5614df7SBenjamin Rood void pm8001_set_phy_profile_single(struct pm8001_hba_info *pm8001_ha,
4880c5614df7SBenjamin Rood 		u32 phy, u32 length, u32 *buf)
4881c5614df7SBenjamin Rood {
4882c5614df7SBenjamin Rood 	u32 tag, opc;
4883c5614df7SBenjamin Rood 	int rc, i;
4884c5614df7SBenjamin Rood 	struct set_phy_profile_req payload;
4885c5614df7SBenjamin Rood 
4886c5614df7SBenjamin Rood 	memset(&payload, 0, sizeof(payload));
4887c5614df7SBenjamin Rood 
4888c5614df7SBenjamin Rood 	rc = pm8001_tag_alloc(pm8001_ha, &tag);
4889f17c599aSDamien Le Moal 	if (rc) {
48901b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, INIT, "Invalid tag\n");
4891f17c599aSDamien Le Moal 		return;
4892f17c599aSDamien Le Moal 	}
4893c5614df7SBenjamin Rood 
4894c5614df7SBenjamin Rood 	opc = OPC_INB_SET_PHY_PROFILE;
4895c5614df7SBenjamin Rood 
4896c5614df7SBenjamin Rood 	payload.tag = cpu_to_le32(tag);
4897e5039a92SDamien Le Moal 	payload.ppc_phyid =
4898e5039a92SDamien Le Moal 		cpu_to_le32(((SAS_PHY_ANALOG_SETTINGS_PAGE & 0xF) << 8)
4899c5614df7SBenjamin Rood 			    | (phy & 0xFF));
4900c5614df7SBenjamin Rood 
4901c5614df7SBenjamin Rood 	for (i = 0; i < length; i++)
4902c5614df7SBenjamin Rood 		payload.reserved[i] = cpu_to_le32(*(buf + i));
4903c5614df7SBenjamin Rood 
4904f91767a3SDamien Le Moal 	rc = pm8001_mpi_build_cmd(pm8001_ha, 0, opc, &payload,
490591a43fa6Speter chang 			sizeof(payload), 0);
4906c5614df7SBenjamin Rood 	if (rc)
4907c5614df7SBenjamin Rood 		pm8001_tag_free(pm8001_ha, tag);
4908c5614df7SBenjamin Rood 
49091b5d2793SJoe Perches 	pm8001_dbg(pm8001_ha, INIT, "PHY %d settings applied\n", phy);
4910c5614df7SBenjamin Rood }
4911f5860992SSakthivel K const struct pm8001_dispatch pm8001_80xx_dispatch = {
4912f5860992SSakthivel K 	.name			= "pmc80xx",
4913f5860992SSakthivel K 	.chip_init		= pm80xx_chip_init,
491498132d84SJohn Garry 	.chip_post_init		= pm80xx_chip_post_init,
4915f5860992SSakthivel K 	.chip_soft_rst		= pm80xx_chip_soft_rst,
4916f5860992SSakthivel K 	.chip_rst		= pm80xx_hw_chip_rst,
4917f5860992SSakthivel K 	.chip_iounmap		= pm8001_chip_iounmap,
4918f5860992SSakthivel K 	.isr			= pm80xx_chip_isr,
4919f310a4eaSColin Ian King 	.is_our_interrupt	= pm80xx_chip_is_our_interrupt,
4920f5860992SSakthivel K 	.isr_process_oq		= process_oq,
4921f5860992SSakthivel K 	.interrupt_enable	= pm80xx_chip_interrupt_enable,
4922f5860992SSakthivel K 	.interrupt_disable	= pm80xx_chip_interrupt_disable,
4923f5860992SSakthivel K 	.make_prd		= pm8001_chip_make_sg,
4924f5860992SSakthivel K 	.smp_req		= pm80xx_chip_smp_req,
4925f5860992SSakthivel K 	.ssp_io_req		= pm80xx_chip_ssp_io_req,
4926f5860992SSakthivel K 	.sata_req		= pm80xx_chip_sata_req,
4927f5860992SSakthivel K 	.phy_start_req		= pm80xx_chip_phy_start_req,
4928f5860992SSakthivel K 	.phy_stop_req		= pm80xx_chip_phy_stop_req,
4929f5860992SSakthivel K 	.reg_dev_req		= pm80xx_chip_reg_dev_req,
4930f5860992SSakthivel K 	.dereg_dev_req		= pm8001_chip_dereg_dev_req,
4931f5860992SSakthivel K 	.phy_ctl_req		= pm80xx_chip_phy_ctl_req,
4932f5860992SSakthivel K 	.task_abort		= pm8001_chip_abort_task,
4933f5860992SSakthivel K 	.ssp_tm_req		= pm8001_chip_ssp_tm_req,
4934f5860992SSakthivel K 	.get_nvmd_req		= pm8001_chip_get_nvmd_req,
4935f5860992SSakthivel K 	.set_nvmd_req		= pm8001_chip_set_nvmd_req,
4936f5860992SSakthivel K 	.fw_flash_update_req	= pm8001_chip_fw_flash_update_req,
4937f5860992SSakthivel K 	.set_dev_state_req	= pm8001_chip_set_dev_state_req,
4938a961ea0aSakshatzen 	.fatal_errors		= pm80xx_fatal_errors,
4939ee05cb71SAjish Koshy 	.hw_event_ack_req	= pm80xx_hw_event_ack_req,
4940f5860992SSakthivel K };
4941