1f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/*
2f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * PMC-Sierra SPCv/ve 8088/8089 SAS/SATA based host adapters driver
3f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K *
4f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * Copyright (c) 2008-2009 PMC-Sierra, Inc.,
5f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * All rights reserved.
6f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K *
7f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * Redistribution and use in source and binary forms, with or without
8f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * modification, are permitted provided that the following conditions
9f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * are met:
10f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * 1. Redistributions of source code must retain the above copyright
11f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * notice, this list of conditions, and the following disclaimer,
12f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * without modification.
13f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * substantially similar to the "NO WARRANTY" disclaimer below
15f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * ("Disclaimer") and any redistribution must be conditioned upon
16f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * including a substantially similar Disclaimer requirement for further
17f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * binary redistribution.
18f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * 3. Neither the names of the above-listed copyright holders nor the names
19f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * of any contributors may be used to endorse or promote products derived
20f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * from this software without specific prior written permission.
21f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K *
22f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * Alternatively, this software may be distributed under the terms of the
23f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * GNU General Public License ("GPL") version 2 as published by the Free
24f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * Software Foundation.
25f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K *
26f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * NO WARRANTY
27f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * POSSIBILITY OF SUCH DAMAGES.
38f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K *
39f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
40f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K #include <linux/slab.h>
41f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K #include "pm8001_sas.h"
42f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K #include "pm80xx_hwi.h"
43f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K #include "pm8001_chips.h"
44f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K #include "pm8001_ctl.h"
45f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
46f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#define SMP_DIRECT 1
47f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#define SMP_INDIRECT 2
48d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
49d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
50d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanamint pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shift_value)
51d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam{
52d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	u32 reg_val;
53d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	unsigned long start;
54d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER, shift_value);
55d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	/* confirm the setting is written */
56d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	start = jiffies + HZ; /* 1 sec */
57d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	do {
58d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		reg_val = pm8001_cr32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER);
59d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	} while ((reg_val != shift_value) && time_before(jiffies, start));
60d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (reg_val != shift_value) {
61d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		PM8001_FAIL_DBG(pm8001_ha,
62d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_printk("TIMEOUT:MEMBASE_II_SHIFT_REGISTER"
63d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			" = 0x%x\n", reg_val));
64d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		return -1;
65d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
66d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	return 0;
67d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam}
68d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
69d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanamvoid pm80xx_pci_mem_copy(struct pm8001_hba_info  *pm8001_ha, u32 soffset,
70d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				const void *destination,
71d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				u32 dw_count, u32 bus_base_number)
72d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam{
73d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	u32 index, value, offset;
74d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	u32 *destination1;
75d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	destination1 = (u32 *)destination;
76d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
77d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	for (index = 0; index < dw_count; index += 4, destination1++) {
78d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		offset = (soffset + index / 4);
79d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		if (offset < (64 * 1024)) {
80d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			value = pm8001_cr32(pm8001_ha, bus_base_number, offset);
81d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			*destination1 =  cpu_to_le32(value);
82d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
83d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
84d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	return;
85d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam}
86d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
87d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanamssize_t pm80xx_get_fatal_dump(struct device *cdev,
88d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	struct device_attribute *attr, char *buf)
89d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam{
90d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	struct Scsi_Host *shost = class_to_shost(cdev);
91d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
92d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
93d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	void __iomem *fatal_table_address = pm8001_ha->fatal_tbl_addr;
94d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	u32 accum_len , reg_val, index, *temp;
95d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	unsigned long start;
96d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	u8 *direct_data;
97d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	char *fatal_error_data = buf;
98d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
99d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	pm8001_ha->forensic_info.data_buf.direct_data = buf;
100d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (pm8001_ha->chip_id == chip_8001) {
101d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.direct_data +=
102d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
103d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			"Not supported for SPC controller");
104d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
105d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			(char *)buf;
106d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
107d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (pm8001_ha->forensic_info.data_buf.direct_offset == 0) {
108d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		PM8001_IO_DBG(pm8001_ha,
109d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_printk("forensic_info TYPE_NON_FATAL..............\n"));
110d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		direct_data = (u8 *)fatal_error_data;
111d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_type = TYPE_NON_FATAL;
112d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.direct_len = SYSFS_OFFSET;
113d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.read_len = 0;
114d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
115d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.direct_data = direct_data;
116d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
117d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		/* start to get data */
118d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		/* Program the MEMBASE II Shifting Register with 0x00.*/
119d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
120d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				pm8001_ha->fatal_forensic_shift_offset);
121d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_last_offset = 0;
122d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_fatal_step = 0;
123d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->fatal_bar_loc = 0;
124d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
125cf370066ac5c7d5fdf384fef24b8ba48a481ffa5Viswas G
126d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	/* Read until accum_len is retrived */
127d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	accum_len = pm8001_mr32(fatal_table_address,
128d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
129d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	PM8001_IO_DBG(pm8001_ha, pm8001_printk("accum_len 0x%x\n",
130d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam						accum_len));
131d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (accum_len == 0xFFFFFFFF) {
132d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		PM8001_IO_DBG(pm8001_ha,
133d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_printk("Possible PCI issue 0x%x not expected\n",
134d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				accum_len));
135cf370066ac5c7d5fdf384fef24b8ba48a481ffa5Viswas G		return -EIO;
136d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
137d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (accum_len == 0 || accum_len >= 0x100000) {
138d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.direct_data +=
139d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
140d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				"%08x ", 0xFFFFFFFF);
141d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
142d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			(char *)buf;
143d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
144d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
145d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (pm8001_ha->forensic_fatal_step == 0) {
146d078b5117f18dce57b895df640d9bf2614864829Anand Kumar SanthanammoreData:
147d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		if (pm8001_ha->forensic_info.data_buf.direct_data) {
148d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			/* Data is in bar, copy to host memory */
149d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm80xx_pci_mem_copy(pm8001_ha, pm8001_ha->fatal_bar_loc,
150d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			 pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr,
151d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				pm8001_ha->forensic_info.data_buf.direct_len ,
152d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					1);
153d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
154d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->fatal_bar_loc +=
155d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_len;
156d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.direct_offset +=
157d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_len;
158d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_last_offset	+=
159d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_len;
160d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.read_len =
161d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_len;
162d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
163d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		if (pm8001_ha->forensic_last_offset  >= accum_len) {
164d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_data +=
165d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
166d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				"%08x ", 3);
167d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			for (index = 0; index < (SYSFS_OFFSET / 4); index++) {
168d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				pm8001_ha->forensic_info.data_buf.direct_data +=
169d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					sprintf(pm8001_ha->
170d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					 forensic_info.data_buf.direct_data,
171d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam						"%08x ", *(temp + index));
172d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			}
173d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
174d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->fatal_bar_loc = 0;
175d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_fatal_step = 1;
176d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->fatal_forensic_shift_offset = 0;
177d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_last_offset	= 0;
178d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			return (char *)pm8001_ha->
179d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				forensic_info.data_buf.direct_data -
180d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				(char *)buf;
181d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
182d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		if (pm8001_ha->fatal_bar_loc < (64 * 1024)) {
183d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_data +=
184d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				sprintf(pm8001_ha->
185d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					forensic_info.data_buf.direct_data,
186d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					"%08x ", 2);
187d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			for (index = 0; index < (SYSFS_OFFSET / 4); index++) {
188d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				pm8001_ha->forensic_info.data_buf.direct_data +=
189d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					sprintf(pm8001_ha->
190d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					forensic_info.data_buf.direct_data,
191d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					"%08x ", *(temp + index));
192d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			}
193d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			return (char *)pm8001_ha->
194d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				forensic_info.data_buf.direct_data -
195d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				(char *)buf;
196d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
197d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
198d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		/* Increment the MEMBASE II Shifting Register value by 0x100.*/
199d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_info.data_buf.direct_data +=
200d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
201d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				"%08x ", 2);
202d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		for (index = 0; index < 256; index++) {
203d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_data +=
204d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				sprintf(pm8001_ha->
205d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					forensic_info.data_buf.direct_data,
206d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam						"%08x ", *(temp + index));
207d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
208d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->fatal_forensic_shift_offset += 0x100;
209d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
210d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->fatal_forensic_shift_offset);
211d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->fatal_bar_loc = 0;
212d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
213d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			(char *)buf;
214d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
215d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	if (pm8001_ha->forensic_fatal_step == 1) {
216d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->fatal_forensic_shift_offset = 0;
217d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		/* Read 64K of the debug data. */
218d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
219d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->fatal_forensic_shift_offset);
220d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_mw32(fatal_table_address,
221d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			MPI_FATAL_EDUMP_TABLE_HANDSHAKE,
222d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				MPI_FATAL_EDUMP_HANDSHAKE_RDY);
223d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
224d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		/* Poll FDDHSHK  until clear  */
225d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		start = jiffies + (2 * HZ); /* 2 sec */
226d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
227d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		do {
228d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			reg_val = pm8001_mr32(fatal_table_address,
229d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					MPI_FATAL_EDUMP_TABLE_HANDSHAKE);
230d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		} while ((reg_val) && time_before(jiffies, start));
231d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
232d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		if (reg_val != 0) {
233d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			PM8001_FAIL_DBG(pm8001_ha,
234d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_printk("TIMEOUT:MEMBASE_II_SHIFT_REGISTER"
235d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			" = 0x%x\n", reg_val));
236cf370066ac5c7d5fdf384fef24b8ba48a481ffa5Viswas G			return -EIO;
237d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
238d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
239d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		/* Read the next 64K of the debug data. */
240d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		pm8001_ha->forensic_fatal_step = 0;
241d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		if (pm8001_mr32(fatal_table_address,
242d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			MPI_FATAL_EDUMP_TABLE_STATUS) !=
243d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) {
244d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_mw32(fatal_table_address,
245d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				MPI_FATAL_EDUMP_TABLE_HANDSHAKE, 0);
246d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			goto moreData;
247d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		} else {
248d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_data +=
249d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam				sprintf(pm8001_ha->
250d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					forensic_info.data_buf.direct_data,
251d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam						"%08x ", 4);
252d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.read_len = 0xFFFFFFFF;
253d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_len =  0;
254d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.direct_offset = 0;
255d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam			pm8001_ha->forensic_info.data_buf.read_len = 0;
256d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		}
257d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	}
258d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
259d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
260d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		(char *)buf;
261d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam}
262d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam
263f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
264f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * read_main_config_table - read the configure table and save it.
265f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
266f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
267f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
268f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
269f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
270f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
271f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature	=
272f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_SIGNATURE_OFFSET);
273f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev =
274f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_INTERFACE_REVISION);
275f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev	=
276f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_FW_REVISION);
277f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io	=
278f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_MAX_OUTSTANDING_IO_OFFSET);
279f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl	=
280f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_MAX_SGL_OFFSET);
281f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag =
282f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_CNTRL_CAP_OFFSET);
283f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset	=
284f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_GST_OFFSET);
285f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset =
286f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_IBQ_OFFSET);
287f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset =
288f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_OBQ_OFFSET);
289f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
290f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* read Error Dump Offset and Length */
291f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset0 =
292f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
293f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length0 =
294f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
295f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset1 =
296f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
297f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length1 =
298f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
299f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
300f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* read GPIO LED settings from the configuration table */
301f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping =
302f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET);
303f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
304f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* read analog Setting offset from the configuration table */
305f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.analog_setup_table_offset =
306f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
307f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
308f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset =
309f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_INT_VECTOR_TABLE_OFFSET);
310f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset =
311f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mr32(address, MAIN_SAS_PHY_ATTR_TABLE_OFFSET);
312f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
313f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
314f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
315f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * read_general_status_table - read the general status table and save it.
316f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
317f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
318f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
319f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
320f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->general_stat_tbl_addr;
321f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.gst_len_mpistate	=
322f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_GSTLEN_MPIS_OFFSET);
323f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state0	=
324f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_IQ_FREEZE_STATE0_OFFSET);
325f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state1	=
326f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_IQ_FREEZE_STATE1_OFFSET);
327f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.msgu_tcnt		=
328f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_MSGUTCNT_OFFSET);
329f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.iop_tcnt		=
330f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_IOPTCNT_OFFSET);
331f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.gpio_input_val	=
332f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_GPIO_INPUT_VAL);
333f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[0] =
334f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET0);
335f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[1] =
336f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET1);
337f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[2] =
338f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET2);
339f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[3] =
340f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET3);
341f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[4] =
342f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET4);
343f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[5] =
344f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET5);
345f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[6] =
346f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, GST_RERRINFO_OFFSET6);
347f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[7] =
348f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			 pm8001_mr32(address, GST_RERRINFO_OFFSET7);
349f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
350f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
351f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * read_phy_attr_table - read the phy attribute table and save it.
352f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
353f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
354f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void read_phy_attr_table(struct pm8001_hba_info *pm8001_ha)
355f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
356f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->pspa_q_tbl_addr;
357f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[0] =
358f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE0_OFFSET);
359f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[1] =
360f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE1_OFFSET);
361f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[2] =
362f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE2_OFFSET);
363f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[3] =
364f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE3_OFFSET);
365f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[4] =
366f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE4_OFFSET);
367f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[5] =
368f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE5_OFFSET);
369f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[6] =
370f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE6_OFFSET);
371f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[7] =
372f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE7_OFFSET);
373f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[8] =
374f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE8_OFFSET);
375f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[9] =
376f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE9_OFFSET);
377f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[10] =
378f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE10_OFFSET);
379f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[11] =
380f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE11_OFFSET);
381f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[12] =
382f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE12_OFFSET);
383f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[13] =
384f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE13_OFFSET);
385f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[14] =
386f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE14_OFFSET);
387f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.phystart1_16[15] =
388f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_PHYSTATE15_OFFSET);
389f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
390f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[0] =
391f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID0_OFFSET);
392f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[1] =
393f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID1_OFFSET);
394f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[2] =
395f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID2_OFFSET);
396f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[3] =
397f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID3_OFFSET);
398f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[4] =
399f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID4_OFFSET);
400f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[5] =
401f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID5_OFFSET);
402f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[6] =
403f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID6_OFFSET);
404f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[7] =
405f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID7_OFFSET);
406f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[8] =
407f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID8_OFFSET);
408f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[9] =
409f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID9_OFFSET);
410f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[10] =
411f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID10_OFFSET);
412f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[11] =
413f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID11_OFFSET);
414f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[12] =
415f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID12_OFFSET);
416f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[13] =
417f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID13_OFFSET);
418f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[14] =
419f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID14_OFFSET);
420f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[15] =
421f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, PSPA_OB_HW_EVENT_PID15_OFFSET);
422f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
423f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
424f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
425f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
426f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * read_inbnd_queue_table - read the inbound queue table and save it.
427f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
428f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
429f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
430f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
431f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int i;
432f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
433f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
434f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		u32 offset = i * 0x20;
435f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
436f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			get_pci_bar_index(pm8001_mr32(address,
437f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(offset + IB_PIPCI_BAR)));
438f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].pi_offset =
439f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, (offset + IB_PIPCI_BAR_OFFSET));
440f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
441f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
442f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
443f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
444f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * read_outbnd_queue_table - read the outbound queue table and save it.
445f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
446f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
447f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
448f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
449f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int i;
450f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
451f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
452f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		u32 offset = i * 0x24;
453f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
454f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			get_pci_bar_index(pm8001_mr32(address,
455f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(offset + OB_CIPCI_BAR)));
456f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].ci_offset =
457f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(address, (offset + OB_CIPCI_BAR_OFFSET));
458f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
459f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
460f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
461f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
462f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * init_default_table_values - init the default table.
463f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
464f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
465f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
466f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
467f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int i;
468f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 offsetib, offsetob;
469f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
470f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
471f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
472f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr		=
473f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
474f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr		=
475f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
476f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size		=
477f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K							PM8001_EVENT_LOG_SIZE;
478f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity		= 0x01;
479f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr	=
480f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
481f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr	=
482f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
483f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size		=
484f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K							PM8001_EVENT_LOG_SIZE;
485f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity	= 0x01;
486f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt		= 0x01;
487f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
488c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	/* Disable end to end CRC checking */
489c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump = (0x1 << 16);
490c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
491f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
492f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt	=
4939504a923924d663e1953f872f0a828e6454a6cfcHans Verkuil			PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
494f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].upper_base_addr	=
495f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[IB + i].phys_addr_hi;
496f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].lower_base_addr	=
497f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->memoryMap.region[IB + i].phys_addr_lo;
498f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].base_virt		=
499f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(u8 *)pm8001_ha->memoryMap.region[IB + i].virt_ptr;
500f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].total_length		=
501f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[IB + i].total_len;
502f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr	=
503f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[CI + i].phys_addr_hi;
504f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr	=
505f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[CI + i].phys_addr_lo;
506f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].ci_virt		=
507f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[CI + i].virt_ptr;
508f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		offsetib = i * 0x20;
509f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].pi_pci_bar		=
510f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			get_pci_bar_index(pm8001_mr32(addressib,
511f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(offsetib + 0x14)));
512f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].pi_offset		=
513f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(addressib, (offsetib + 0x18));
514f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].producer_idx		= 0;
515f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[i].consumer_index	= 0;
516f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
517f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
518f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].element_size_cnt	=
5199504a923924d663e1953f872f0a828e6454a6cfcHans Verkuil			PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
520f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].upper_base_addr	=
521f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[OB + i].phys_addr_hi;
522f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].lower_base_addr	=
523f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[OB + i].phys_addr_lo;
524f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].base_virt		=
525f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(u8 *)pm8001_ha->memoryMap.region[OB + i].virt_ptr;
526f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].total_length		=
527f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[OB + i].total_len;
528f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr	=
529f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[PI + i].phys_addr_hi;
530f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr	=
531f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[PI + i].phys_addr_lo;
532f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* interrupt vector based on oq */
533f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = (i << 24);
534f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].pi_virt		=
535f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->memoryMap.region[PI + i].virt_ptr;
536f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		offsetob = i * 0x24;
537f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].ci_pci_bar		=
538f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			get_pci_bar_index(pm8001_mr32(addressob,
539f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			offsetob + 0x14));
540f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].ci_offset		=
541f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(addressob, (offsetob + 0x18));
542f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].consumer_idx		= 0;
543f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[i].producer_index	= 0;
544f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
545f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
546f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
547f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
548f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * update_main_config_table - update the main default table to the HBA.
549f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
550f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
551f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
552f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
553f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
554f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_IQNPPD_HPPD_OFFSET,
555f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_q_nppd_hppd);
556f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_HI,
557f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr);
558f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_LO,
559f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr);
560f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_EVENT_LOG_BUFF_SIZE,
561f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
562f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_EVENT_LOG_OPTION,
563f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity);
564f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_HI,
565f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr);
566f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_LO,
567f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr);
568f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_BUFF_SIZE,
569f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size);
570f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_PCS_EVENT_LOG_OPTION,
571f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity);
572f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_FATAL_ERROR_INTERRUPT,
573f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt);
574c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	pm8001_mw32(address, MAIN_EVENT_CRC_CHECK,
575c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump);
576f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
577f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* SPCv specific */
578f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping &= 0xCFFFFFFF;
579f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Set GPIOLED to 0x2 for LED indicator */
580f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping |= 0x20000000;
581f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_GPIO_LED_FLAGS_OFFSET,
582f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping);
583f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
584f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
585f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
586f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, MAIN_INT_REASSERTION_DELAY,
587f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->main_cfg_tbl.pm80xx_tbl.interrupt_reassertion_delay);
588f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
589f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
590f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
591f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * update_inbnd_queue_table - update the inbound queue table to the HBA.
592f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
593f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
594f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
595f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					 int number)
596f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
597f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
598f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u16 offset = number * 0x20;
599f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + IB_PROPERITY_OFFSET,
600f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
601f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + IB_BASE_ADDR_HI_OFFSET,
602f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
603f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + IB_BASE_ADDR_LO_OFFSET,
604f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
605f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + IB_CI_BASE_ADDR_HI_OFFSET,
606f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
607f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + IB_CI_BASE_ADDR_LO_OFFSET,
608f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
609f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
610f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
611f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
612f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * update_outbnd_queue_table - update the outbound queue table to the HBA.
613f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
614f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
615f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
616f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						 int number)
617f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
618f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
619f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u16 offset = number * 0x24;
620f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + OB_PROPERITY_OFFSET,
621f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
622f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + OB_BASE_ADDR_HI_OFFSET,
623f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
624f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + OB_BASE_ADDR_LO_OFFSET,
625f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
626f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + OB_PI_BASE_ADDR_HI_OFFSET,
627f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
628f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + OB_PI_BASE_ADDR_LO_OFFSET,
629f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
630f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mw32(address, offset + OB_INTERRUPT_COALES_OFFSET,
631f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
632f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
633f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
634f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
635f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_init_check - check firmware initialization status.
636f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
637f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
638f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
639f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
640f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 max_wait_count;
641f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 value;
642f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 gst_len_mpistate;
643f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
644f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
645f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	table is updated */
646f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_UPDATE);
647f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* wait until Inbound DoorBell Clear Register toggled */
648a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	if (IS_SPCV_12G(pm8001_ha->pdev)) {
649a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam		max_wait_count = 4 * 1000 * 1000;/* 4 sec */
650a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	} else {
651a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam		max_wait_count = 2 * 1000 * 1000;/* 2 sec */
652a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	}
653f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
654f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
655f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
656f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value &= SPCv_MSGU_CFG_TABLE_UPDATE;
657f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while ((value != 0) && (--max_wait_count));
658f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
659f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count)
660f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
661f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check the MPI-State for initialization upto 100ms*/
662f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	max_wait_count = 100 * 1000;/* 100 msec */
663f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
664f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
665f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		gst_len_mpistate =
666f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
667f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					GST_GSTLEN_MPIS_OFFSET);
668f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while ((GST_MPI_STATE_INIT !=
669f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(gst_len_mpistate & GST_MPI_STATE_MASK)) && (--max_wait_count));
670f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count)
671f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
672f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
673f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check MPI Initialization error */
674f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	gst_len_mpistate = gst_len_mpistate >> 16;
675f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (0x0000 != gst_len_mpistate)
676f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
677f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
678f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
679f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
680f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
681f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
682f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
683f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
684f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
685f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
686f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
687f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 value;
688f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 max_wait_count;
689f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 max_wait_time;
690f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret = 0;
691f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
692f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* reset / PCIe ready */
693f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	max_wait_time = max_wait_count = 100 * 1000;	/* 100 milli sec */
694f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
695f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
696f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
697f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while ((value == 0xFFFFFFFF) && (--max_wait_count));
698f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
699f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check ila status */
700f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	max_wait_time = max_wait_count = 1000 * 1000;	/* 1000 milli sec */
701f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
702f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
703f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
704f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while (((value & SCRATCH_PAD_ILA_READY) !=
705f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			SCRATCH_PAD_ILA_READY) && (--max_wait_count));
706f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count)
707f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = -1;
708f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else {
709f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
710f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" ila ready status in %d millisec\n",
711f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(max_wait_time - max_wait_count)));
712f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
713f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
714f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check RAAE status */
715f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	max_wait_time = max_wait_count = 1800 * 1000;	/* 1800 milli sec */
716f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
717f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
718f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
719f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while (((value & SCRATCH_PAD_RAAE_READY) !=
720f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				SCRATCH_PAD_RAAE_READY) && (--max_wait_count));
721f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count)
722f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = -1;
723f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else {
724f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
725f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" raae ready status in %d millisec\n",
726f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(max_wait_time - max_wait_count)));
727f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
728f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
729f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check iop0 status */
730f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	max_wait_time = max_wait_count = 600 * 1000;	/* 600 milli sec */
731f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
732f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
733f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
734f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while (((value & SCRATCH_PAD_IOP0_READY) != SCRATCH_PAD_IOP0_READY) &&
735f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(--max_wait_count));
736f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count)
737f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = -1;
738f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else {
739f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
740f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" iop0 ready status in %d millisec\n",
741f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(max_wait_time - max_wait_count)));
742f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
743f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
744f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check iop1 status only for 16 port controllers */
745f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if ((pm8001_ha->chip_id != chip_8008) &&
746f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(pm8001_ha->chip_id != chip_8009)) {
747f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* 200 milli sec */
748f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		max_wait_time = max_wait_count = 200 * 1000;
749f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		do {
750f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			udelay(1);
751f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
752f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} while (((value & SCRATCH_PAD_IOP1_READY) !=
753f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				SCRATCH_PAD_IOP1_READY) && (--max_wait_count));
754f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!max_wait_count)
755f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ret = -1;
756f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		else {
757f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
758f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				"iop1 ready status in %d millisec\n",
759f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(max_wait_time - max_wait_count)));
760f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
761f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
762f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
763f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
764f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
765f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
766f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
767f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
768f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void __iomem *base_addr;
769f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32	value;
770f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32	offset;
771f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32	pcibar;
772f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32	pcilogic;
773f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
774f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
775f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	offset = value & 0x03FFFFFF; /* scratch pad 0 TBL address */
776f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
777f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
778f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("Scratchpad 0 Offset: 0x%x value 0x%x\n",
779f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				offset, value));
780f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pcilogic = (value & 0xFC000000) >> 26;
781f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pcibar = get_pci_bar_index(pcilogic);
782f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
783f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar));
784f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->main_cfg_tbl_addr = base_addr =
785f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
786f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->general_stat_tbl_addr =
787f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x18) &
788f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					0xFFFFFF);
789f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->inbnd_q_tbl_addr =
790f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C) &
791f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					0xFFFFFF);
792f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->outbnd_q_tbl_addr =
793f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x20) &
794f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					0xFFFFFF);
795f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->ivt_tbl_addr =
796f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C) &
797f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					0xFFFFFF);
798f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_ha->pspa_q_tbl_addr =
799f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x90) &
800f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					0xFFFFFF);
801d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam	pm8001_ha->fatal_tbl_addr =
802d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam		base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0xA0) &
803d078b5117f18dce57b895df640d9bf2614864829Anand Kumar Santhanam					0xFFFFFF);
804f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
805f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
806f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("GST OFFSET 0x%x\n",
807f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_cr32(pm8001_ha, pcibar, offset + 0x18)));
808f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
809f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("INBND OFFSET 0x%x\n",
810f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C)));
811f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
812f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OBND OFFSET 0x%x\n",
813f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_cr32(pm8001_ha, pcibar, offset + 0x20)));
814f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
815f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IVT OFFSET 0x%x\n",
816f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C)));
817f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
818f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("PSPA OFFSET 0x%x\n",
819f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_cr32(pm8001_ha, pcibar, offset + 0x90)));
820f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
821f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("addr - main cfg %p general status %p\n",
822f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->main_cfg_tbl_addr,
823f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->general_stat_tbl_addr));
824f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
825f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("addr - inbnd %p obnd %p\n",
826f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->inbnd_q_tbl_addr,
827f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->outbnd_q_tbl_addr));
828f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
829f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("addr - pspa %p ivt %p\n",
830f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->pspa_q_tbl_addr,
831f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->ivt_tbl_addr));
832f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
833f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
834f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
835f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_set_thermal_config - support the thermal configuration
836f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
837f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
838a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel Kint
839f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha)
840f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
841f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct set_ctrl_cfg_req payload;
842f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
843f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int rc;
844f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag;
845f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
846f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
847f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
848f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	rc = pm8001_tag_alloc(pm8001_ha, &tag);
849f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (rc)
850f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
851f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
852f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
853f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(tag);
854f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.cfg_pg[0] = (THERMAL_LOG_ENABLE << 9) |
855f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(THERMAL_ENABLE << 8) | THERMAL_OP_CODE;
856f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.cfg_pg[1] = (LTEMPHIL << 24) | (RTEMPHIL << 8);
857f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
858f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
8595533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (rc)
8605533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, tag);
861f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return rc;
862f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
863f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
864f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
865f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
866a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K* pm80xx_set_sas_protocol_timer_config - support the SAS Protocol
867a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K* Timer configuration page
868a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K* @pm8001_ha: our hba card information.
869a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K*/
870a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel Kstatic int
871a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel Kpm80xx_set_sas_protocol_timer_config(struct pm8001_hba_info *pm8001_ha)
872a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K{
873a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	struct set_ctrl_cfg_req payload;
874a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	struct inbound_queue_table *circularQ;
875a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASProtocolTimerConfig_t SASConfigPage;
876a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	int rc;
877a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	u32 tag;
878a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
879a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
880a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
881a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	memset(&SASConfigPage, 0, sizeof(SASProtocolTimerConfig_t));
882a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
883a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	rc = pm8001_tag_alloc(pm8001_ha, &tag);
884a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
885a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	if (rc)
886a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		return -1;
887a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
888a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
889a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	payload.tag = cpu_to_le32(tag);
890a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
891a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.pageCode        =  SAS_PROTOCOL_TIMER_CONFIG_PAGE;
892a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.MST_MSI         =  3 << 15;
893a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.STP_SSP_MCT_TMO =  (STP_MCT_TMO << 16) | SSP_MCT_TMO;
894a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.STP_FRM_TMO     = (SAS_MAX_OPEN_TIME << 24) |
895a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K				(SMP_MAX_CONN_TIMER << 16) | STP_FRM_TIMER;
896a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.STP_IDLE_TMO    =  STP_IDLE_TIME;
897a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
898a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	if (SASConfigPage.STP_IDLE_TMO > 0x3FFFFFF)
899a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		SASConfigPage.STP_IDLE_TMO = 0x3FFFFFF;
900a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
901a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
902a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.OPNRJT_RTRY_INTVL =         (SAS_MFD << 16) |
903a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K						SAS_OPNRJT_RTRY_INTVL;
904a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO =  (SAS_DOPNRJT_RTRY_TMO << 16)
905a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K						| SAS_COPNRJT_RTRY_TMO;
906a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR =  (SAS_DOPNRJT_RTRY_THR << 16)
907a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K						| SAS_COPNRJT_RTRY_THR;
908a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	SASConfigPage.MAX_AIP =  SAS_MAX_AIP;
909a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
910a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
911a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.pageCode "
912a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			"0x%08x\n", SASConfigPage.pageCode));
913a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
914a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.MST_MSI "
915a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.MST_MSI));
916a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
917a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.STP_SSP_MCT_TMO "
918a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.STP_SSP_MCT_TMO));
919a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
920a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.STP_FRM_TMO "
921a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.STP_FRM_TMO));
922a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
923a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.STP_IDLE_TMO "
924a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.STP_IDLE_TMO));
925a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
926a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.OPNRJT_RTRY_INTVL "
927a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.OPNRJT_RTRY_INTVL));
928a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
929a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO "
930a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO));
931a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha,
932a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR "
933a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR));
934a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	PM8001_INIT_DBG(pm8001_ha, pm8001_printk("SASConfigPage.MAX_AIP "
935a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			" 0x%08x\n", SASConfigPage.MAX_AIP));
936a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
937a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	memcpy(&payload.cfg_pg, &SASConfigPage,
938a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			 sizeof(SASProtocolTimerConfig_t));
939a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
940a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
9415533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (rc)
9425533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, tag);
943a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
944a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	return rc;
945a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K}
946a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K
947a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K/**
948f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_get_encrypt_info - Check for encryption
949f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
950f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
951f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int
952f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_get_encrypt_info(struct pm8001_hba_info *pm8001_ha)
953f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
954f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 scratch3_value;
955da225498d97565b6f25ed28ebdf0fecdf3a5ca5cRickard Strandqvist	int ret = -1;
956f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
957f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Read encryption status from SCRATCH PAD 3 */
958f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	scratch3_value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
959f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
960f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
961f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_ENC_READY) {
962f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
963f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
964f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
965f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						SCRATCH_PAD3_SMF_ENABLED)
966f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
967f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
968f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						SCRATCH_PAD3_SMA_ENABLED)
969f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
970f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
971f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						SCRATCH_PAD3_SMB_ENABLED)
972f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
973f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->encrypt_info.status = 0;
974f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
975f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Encryption: SCRATCH_PAD3_ENC_READY 0x%08X."
976f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Cipher mode 0x%x Sec mode 0x%x status 0x%x\n",
977f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			scratch3_value, pm8001_ha->encrypt_info.cipher_mode,
978f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode,
979f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.status));
980f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = 0;
981f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else if ((scratch3_value & SCRATCH_PAD3_ENC_READY) ==
982f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_ENC_DISABLED) {
983f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
984f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Encryption: SCRATCH_PAD3_ENC_DISABLED 0x%08X\n",
985f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			scratch3_value));
986f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->encrypt_info.status = 0xFFFFFFFF;
987f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->encrypt_info.cipher_mode = 0;
988f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->encrypt_info.sec_mode = 0;
989da225498d97565b6f25ed28ebdf0fecdf3a5ca5cRickard Strandqvist		ret = 0;
990f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
991f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				SCRATCH_PAD3_ENC_DIS_ERR) {
992f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->encrypt_info.status =
993f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
994f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
995f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
996f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
997f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_SMF_ENABLED)
998f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
999f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1000f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_SMA_ENABLED)
1001f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1002f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1003f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_SMB_ENABLED)
1004f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1005f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
1006f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Encryption: SCRATCH_PAD3_DIS_ERR 0x%08X."
1007f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
1008f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			scratch3_value, pm8001_ha->encrypt_info.cipher_mode,
1009f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode,
1010f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.status));
1011f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
1012f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				 SCRATCH_PAD3_ENC_ENA_ERR) {
1013f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1014f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->encrypt_info.status =
1015f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
1016f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
1017f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
1018f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1019f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_SMF_ENABLED)
1020f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
1021f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1022f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_SMA_ENABLED)
1023f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
1024f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
1025f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD3_SMB_ENABLED)
1026f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
1027f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1028f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
1029f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Encryption: SCRATCH_PAD3_ENA_ERR 0x%08X."
1030f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
1031f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			scratch3_value, pm8001_ha->encrypt_info.cipher_mode,
1032f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.sec_mode,
1033f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_ha->encrypt_info.status));
1034f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1035f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
1036f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1037f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1038f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1039f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_encrypt_update - update flash with encryption informtion
1040f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
1041f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1042f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_encrypt_update(struct pm8001_hba_info *pm8001_ha)
1043f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1044f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct kek_mgmt_req payload;
1045f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
1046f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int rc;
1047f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag;
1048f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = OPC_INB_KEK_MANAGEMENT;
1049f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1050f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&payload, 0, sizeof(struct kek_mgmt_req));
1051f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	rc = pm8001_tag_alloc(pm8001_ha, &tag);
1052f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (rc)
1053f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
1054f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1055f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
1056f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(tag);
1057f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Currently only one key is used. New KEK index is 1.
1058f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 * Current KEK index is 1. Store KEK to NVRAM is 1.
1059f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 */
1060f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.new_curidx_ksop = ((1 << 24) | (1 << 16) | (1 << 8) |
1061f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					KEK_MGMT_SUBOP_KEYCARDUPDATE);
1062f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1063f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
10645533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (rc)
10655533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, tag);
1066f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1067f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return rc;
1068f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1069f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1070f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1071f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
1072f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1073f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1074f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_init(struct pm8001_hba_info *pm8001_ha)
1075f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1076f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret;
1077f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 i = 0;
1078f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1079f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check the firmware status */
1080f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (-1 == check_fw_ready(pm8001_ha)) {
1081f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1082f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Firmware is not ready!\n"));
1083f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -EBUSY;
1084f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1085f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1086f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Initialize pci space address eg: mpi offset */
1087f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	init_pci_device_addresses(pm8001_ha);
1088f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	init_default_table_values(pm8001_ha);
1089f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	read_main_config_table(pm8001_ha);
1090f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	read_general_status_table(pm8001_ha);
1091f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	read_inbnd_queue_table(pm8001_ha);
1092f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	read_outbnd_queue_table(pm8001_ha);
1093f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	read_phy_attr_table(pm8001_ha);
1094f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1095f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* update main config table ,inbound table and outbound table */
1096f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	update_main_config_table(pm8001_ha);
1097f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++)
1098f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		update_inbnd_queue_table(pm8001_ha, i);
1099f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++)
1100f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		update_outbnd_queue_table(pm8001_ha, i);
1101f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1102f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* notify firmware update finished and check initialization status */
1103f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (0 == mpi_init_check(pm8001_ha)) {
1104f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_INIT_DBG(pm8001_ha,
1105f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("MPI initialize successful!\n"));
1106f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else
1107f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -EBUSY;
1108f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1109a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	/* send SAS protocol timer configuration page to FW */
1110a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	ret = pm80xx_set_sas_protocol_timer_config(pm8001_ha);
1111f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1112f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Check for encryption */
1113f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (pm8001_ha->chip->encrypt) {
1114f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_INIT_DBG(pm8001_ha,
1115f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Checking for encryption\n"));
1116f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = pm80xx_get_encrypt_info(pm8001_ha);
1117f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (ret == -1) {
1118f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_INIT_DBG(pm8001_ha,
1119f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_printk("Encryption error !!\n"));
1120f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			if (pm8001_ha->encrypt_info.status == 0x81) {
1121f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
1122f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					"Encryption enabled with error."
1123f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					"Saving encryption key to flash\n"));
1124f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm80xx_encrypt_update(pm8001_ha);
1125f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			}
1126f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
1127f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1128f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
1129f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1130f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1131f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
1132f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1133f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 max_wait_count;
1134f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 value;
1135f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 gst_len_mpistate;
1136f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	init_pci_device_addresses(pm8001_ha);
1137f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
1138f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	table is stop */
1139f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_RESET);
1140f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1141f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* wait until Inbound DoorBell Clear Register toggled */
1142a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	if (IS_SPCV_12G(pm8001_ha->pdev)) {
1143a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam		max_wait_count = 4 * 1000 * 1000;/* 4 sec */
1144a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	} else {
1145a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam		max_wait_count = 2 * 1000 * 1000;/* 2 sec */
1146a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	}
1147f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
1148f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
1149f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
1150f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		value &= SPCv_MSGU_CFG_TABLE_RESET;
1151f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while ((value != 0) && (--max_wait_count));
1152f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1153f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count) {
1154f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1155f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("TIMEOUT:IBDB value/=%x\n", value));
1156f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
1157f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1158f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1159f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check the MPI-State for termination in progress */
1160f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* wait until Inbound DoorBell Clear Register toggled */
1161f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	max_wait_count = 2 * 1000 * 1000;	/* 2 sec for spcv/ve */
1162f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
1163f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		udelay(1);
1164f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		gst_len_mpistate =
1165f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
1166f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			GST_GSTLEN_MPIS_OFFSET);
1167f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (GST_MPI_STATE_UNINIT ==
1168f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(gst_len_mpistate & GST_MPI_STATE_MASK))
1169f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			break;
1170f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while (--max_wait_count);
1171f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!max_wait_count) {
1172f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1173f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" TIME OUT MPI State = 0x%x\n",
1174f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				gst_len_mpistate & GST_MPI_STATE_MASK));
1175f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
1176f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1177f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1178f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
1179f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1180f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1181f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1182f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
1183f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * the FW register status to the originated status.
1184f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1185f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1186f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1187f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int
1188f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
1189f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1190f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 regval;
1191f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 bootloader_state;
119206f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam	u32 ibutton0, ibutton1;
1193f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1194f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Check if MPI is in ready state to reset */
1195f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (mpi_uninit_check(pm8001_ha) != 0) {
1196f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1197f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("MPI state is not ready\n"));
1198f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -1;
1199f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1200f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1201f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* checked for reset register normal state; 0x0 */
1202f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
1203f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
1204f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("reset register before write : 0x%x\n", regval));
1205f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1206f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, SPCv_NORMAL_RESET_VALUE);
1207f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	mdelay(500);
1208f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1209f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
1210f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
1211f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_printk("reset register after write 0x%x\n", regval));
1212f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1213f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if ((regval & SPCv_SOFT_RESET_READ_MASK) ==
1214f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			SPCv_SOFT_RESET_NORMAL_RESET_OCCURED) {
1215f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
1216f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" soft reset successful [regval: 0x%x]\n",
1217f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					regval));
1218f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
1219f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
1220f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" soft reset failed [regval: 0x%x]\n",
1221f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					regval));
1222f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1223f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* check bootloader is successfully executed or in HDA mode */
1224f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		bootloader_state =
1225f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1226f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			SCRATCH_PAD1_BOOTSTATE_MASK;
1227f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1228f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (bootloader_state == SCRATCH_PAD1_BOOTSTATE_HDA_SEEPROM) {
1229f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
1230f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				"Bootloader state - HDA mode SEEPROM\n"));
1231f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (bootloader_state ==
1232f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				SCRATCH_PAD1_BOOTSTATE_HDA_BOOTSTRAP) {
1233f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
1234f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				"Bootloader state - HDA mode Bootstrap Pin\n"));
1235f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (bootloader_state ==
1236f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				SCRATCH_PAD1_BOOTSTATE_HDA_SOFTRESET) {
1237f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
1238f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				"Bootloader state - HDA mode soft reset\n"));
1239f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (bootloader_state ==
1240f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					SCRATCH_PAD1_BOOTSTATE_CRIT_ERROR) {
1241f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
1242f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				"Bootloader state-HDA mode critical error\n"));
1243f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
1244f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -EBUSY;
1245f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1246f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1247f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* check the firmware status after reset */
1248f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (-1 == check_fw_ready(pm8001_ha)) {
1249f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1250f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Firmware is not ready!\n"));
125106f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam		/* check iButton feature support for motherboard controller */
125206f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam		if (pm8001_ha->pdev->subsystem_vendor !=
125306f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			PCI_VENDOR_ID_ADAPTEC2 &&
125406f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			pm8001_ha->pdev->subsystem_vendor != 0) {
125506f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			ibutton0 = pm8001_cr32(pm8001_ha, 0,
125606f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam					MSGU_HOST_SCRATCH_PAD_6);
125706f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			ibutton1 = pm8001_cr32(pm8001_ha, 0,
125806f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam					MSGU_HOST_SCRATCH_PAD_7);
125906f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			if (!ibutton0 && !ibutton1) {
126006f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam				PM8001_FAIL_DBG(pm8001_ha,
126106f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam					pm8001_printk("iButton Feature is"
126206f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam					" not Available!!!\n"));
126306f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam				return -EBUSY;
126406f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			}
126506f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			if (ibutton0 == 0xdeadbeef && ibutton1 == 0xdeadbeef) {
126606f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam				PM8001_FAIL_DBG(pm8001_ha,
126706f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam					pm8001_printk("CRC Check for iButton"
126806f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam					" Feature Failed!!!\n"));
126906f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam				return -EBUSY;
127006f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam			}
127106f12f22cefdc2737b54fc986d9b82ec358cdbb8Anand Kumar Santhanam		}
1272f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1273f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
1274f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("SPCv soft reset Complete\n"));
1275f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
1276f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1277f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1278f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void pm80xx_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1279f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1280f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 u32 i;
1281f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1282f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
1283f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("chip reset start\n"));
1284f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1285f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* do SPCv chip reset. */
1286f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, 0x11);
1287f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
1288f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("SPC soft reset Complete\n"));
1289f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1290f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Check this ..whether delay is required or no */
1291f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* delay 10 usec */
1292f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	udelay(10);
1293f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1294f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* wait for 20 msec until the firmware gets reloaded */
1295f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	i = 20;
1296f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
1297f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mdelay(1);
1298f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while ((--i) != 0);
1299f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1300f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
1301f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("chip reset finished\n"));
1302f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1303f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1304f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1305f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1306f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1307f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1308f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
1309f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1310f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1311f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1312f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1313f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1314f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1315f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1316f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
1317f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1318f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1319f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
1320f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1321f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1322f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, ODMR_MASK_ALL);
1323f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1324f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1325f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1326f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1327f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1328f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1329f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
1330f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1331f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1332f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#ifdef PM8001_USE_MSIX
1333f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 mask;
1334f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	mask = (u32)(1 << vec);
1335f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1336f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, (u32)(mask & 0xFFFFFFFF));
1337f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return;
1338f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#endif
1339f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm80xx_chip_intx_interrupt_enable(pm8001_ha);
1340f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1341f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1342f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1343f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1344f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_interrupt_disable- disable PM8001 chip interrupt
1345f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1346f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1347f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
1348f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
1349f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1350f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#ifdef PM8001_USE_MSIX
1351f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 mask;
1352f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (vec == 0xFF)
1353f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mask = 0xFFFFFFFF;
1354f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else
1355f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mask = (u32)(1 << vec);
1356f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, (u32)(mask & 0xFFFFFFFF));
1357f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return;
1358f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#endif
1359f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm80xx_chip_intx_interrupt_disable(pm8001_ha);
1360f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1361f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1362c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel Kstatic void pm80xx_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1363c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		struct pm8001_device *pm8001_ha_dev)
1364c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K{
1365c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	int res;
1366c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	u32 ccb_tag;
1367c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct pm8001_ccb_info *ccb;
1368c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct sas_task *task = NULL;
1369c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct task_abort_req task_abort;
1370c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct inbound_queue_table *circularQ;
1371c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	u32 opc = OPC_INB_SATA_ABORT;
1372c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	int ret;
1373c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1374c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (!pm8001_ha_dev) {
1375c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("dev is null\n"));
1376c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1377c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1378c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1379c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task = sas_alloc_slow_task(GFP_ATOMIC);
1380c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1381c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (!task) {
1382c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("cannot "
1383c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K						"allocate task\n"));
1384c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1385c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1386c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1387c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task->task_done = pm8001_task_done;
1388c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1389c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
13905533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (res) {
13915533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		sas_free_task(task);
1392c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
13935533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	}
1394c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1395c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb = &pm8001_ha->ccb_info[ccb_tag];
1396c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb->device = pm8001_ha_dev;
1397c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb->ccb_tag = ccb_tag;
1398c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb->task = task;
1399c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1400c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
1401c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1402c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	memset(&task_abort, 0, sizeof(task_abort));
1403c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task_abort.abort_all = cpu_to_le32(1);
1404c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1405c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task_abort.tag = cpu_to_le32(ccb_tag);
1406c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1407c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort, 0);
14085533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (ret) {
14095533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		sas_free_task(task);
14105533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, ccb_tag);
14115533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	}
1412c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K}
1413c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1414c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel Kstatic void pm80xx_send_read_log(struct pm8001_hba_info *pm8001_ha,
1415c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		struct pm8001_device *pm8001_ha_dev)
1416c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K{
1417c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct sata_start_req sata_cmd;
1418c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	int res;
1419c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	u32 ccb_tag;
1420c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct pm8001_ccb_info *ccb;
1421c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct sas_task *task = NULL;
1422c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct host_to_dev_fis fis;
1423c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct domain_device *dev;
1424c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	struct inbound_queue_table *circularQ;
1425c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	u32 opc = OPC_INB_SATA_HOST_OPSTART;
1426c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1427c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task = sas_alloc_slow_task(GFP_ATOMIC);
1428c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1429c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (!task) {
1430c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1431c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("cannot allocate task !!!\n"));
1432c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1433c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1434c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	task->task_done = pm8001_task_done;
1435c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1436c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1437c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (res) {
14385533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		sas_free_task(task);
1439c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1440c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("cannot allocate tag !!!\n"));
1441c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1442c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1443c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1444c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	/* allocate domain device by ourselves as libsas
1445c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	 * is not going to provide any
1446c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	*/
1447c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1448c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (!dev) {
14495533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		sas_free_task(task);
14505533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, ccb_tag);
1451c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1452c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("Domain device cannot be allocated\n"));
1453c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1454c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1455c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
14565533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	task->dev = dev;
14575533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	task->dev->lldd_dev = pm8001_ha_dev;
14585533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl
1459c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb = &pm8001_ha->ccb_info[ccb_tag];
1460c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb->device = pm8001_ha_dev;
1461c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb->ccb_tag = ccb_tag;
1462c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	ccb->task = task;
1463c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1464c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1465c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1466c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	memset(&sata_cmd, 0, sizeof(sata_cmd));
1467c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
1468c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1469c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	/* construct read log FIS */
1470c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	memset(&fis, 0, sizeof(struct host_to_dev_fis));
1471c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	fis.fis_type = 0x27;
1472c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	fis.flags = 0x80;
1473c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	fis.command = ATA_CMD_READ_LOG_EXT;
1474c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	fis.lbal = 0x10;
1475c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	fis.sector_count = 0x1;
1476c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1477c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	sata_cmd.tag = cpu_to_le32(ccb_tag);
1478c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1479c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	sata_cmd.ncqtag_atap_dir_m_dad |= ((0x1 << 7) | (0x5 << 9));
1480c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1481c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1482c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd, 0);
14835533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (res) {
14845533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		sas_free_task(task);
14855533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, ccb_tag);
14865533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		kfree(dev);
14875533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	}
1488c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K}
1489c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1490f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
1491f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_ssp_completion- process the event that FW response to the SSP request.
1492f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
1493f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: the message contents of this outbound message.
1494f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K *
1495f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * When FW has completed a ssp request for example a IO request, after it has
1496f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * filled the SG data with the data, it will trigger this event represent
1497f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * that he has finished the job,please check the coresponding buffer.
1498f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * So we will tell the caller who maybe waiting the result to tell upper layer
1499f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * that the task has been finished.
1500f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
1501f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
1502f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kmpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
1503f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1504f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *t;
1505f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb;
1506f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
1507f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status;
1508f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 param;
1509f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag;
1510f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct ssp_completion_resp *psspPayload;
1511f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct task_status_struct *ts;
1512f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct ssp_response_iu *iu;
1513f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev;
1514f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1515f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	status = le32_to_cpu(psspPayload->status);
1516f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	tag = le32_to_cpu(psspPayload->tag);
1517f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb = &pm8001_ha->ccb_info[tag];
1518f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if ((status == IO_ABORTED) && ccb->open_retry) {
1519f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* Being completed by another */
1520f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ccb->open_retry = 0;
1521f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
1522f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1523f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_dev = ccb->device;
1524f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	param = le32_to_cpu(psspPayload->param);
1525f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t = ccb->task;
1526f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1527f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (status && status != IO_UNDERFLOW)
1528f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1529f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("sas IO status 0x%x\n", status));
1530f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely(!t || !t->lldd_task || !t->dev))
1531f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
1532f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ts = &t->task_status;
1533cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	/* Print sas address of IO failed device */
1534cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1535cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam		(status != IO_UNDERFLOW))
1536cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam		PM8001_FAIL_DBG(pm8001_ha,
1537cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			pm8001_printk("SAS Address of IO Failure Drive"
1538cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			":%016llx", SAS_ADDR(t->dev->sas_addr)));
1539cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam
1540f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (status) {
1541f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_SUCCESS:
1542f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1543f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_SUCCESS ,param = 0x%x\n",
1544f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				param));
1545f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (param == 0) {
1546f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_COMPLETE;
1547f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAM_STAT_GOOD;
1548f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else {
1549f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_COMPLETE;
1550f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_PROTO_RESPONSE;
1551f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->residual = param;
1552f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			iu = &psspPayload->ssp_resp_iu;
1553f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sas_ssp_task_response(pm8001_ha->dev, t, iu);
1554f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
1555f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
1556f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
1557f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1558f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_ABORTED:
1559f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1560f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_ABORTED IOMB Tag\n"));
1561f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1562f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_ABORTED_TASK;
1563f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1564f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_UNDERFLOW:
1565f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* SSP Completion with error */
1566f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1567f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_UNDERFLOW ,param = 0x%x\n",
1568f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				param));
1569f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1570f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_UNDERRUN;
1571f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->residual = param;
1572f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
1573f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
1574f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1575f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_NO_DEVICE:
1576f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1577f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_NO_DEVICE\n"));
1578f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
1579f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_PHY_DOWN;
1580f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1581f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_BREAK:
1582f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1583f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_BREAK\n"));
1584f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1585f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1586f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* Force the midlayer to retry */
1587f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1588f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1589f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_PHY_NOT_READY:
1590f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1591f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
1592f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1593f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1594f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1595f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1596f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
1597f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1598f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
1599f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1600f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1601f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_EPROTO;
1602f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1603f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
1604f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1605f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
1606f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1607f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1608f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1609f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1610f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BREAK:
1611f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1612f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
1613f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1614f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1615f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1616f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1617f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
1618a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
1619a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
1620a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
1621a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
1622a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
1623f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1624f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
1625f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1626f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1627f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1628f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task)
1629f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
1630f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
1631f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
1632f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1633f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
1634f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1635f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
1636f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1637f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1638f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
1639f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1640f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
1641f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
1642f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
1643f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1644f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1645f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
1646f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1647f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
1648f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1649f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
1650f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
1651f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1652f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
1653f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1654f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_NAK_RECEIVED:
1655f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1656f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
1657f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1658f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1659f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1660f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1661f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
1662f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1663f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
1664f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1665f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_NAK_R_ERR;
1666f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1667f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_DMA:
1668f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1669f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("IO_XFER_ERROR_DMA\n"));
1670f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1671f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1672f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1673f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_OPEN_RETRY_TIMEOUT:
1674f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1675f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1676f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1677f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1678f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1679f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1680f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_OFFSET_MISMATCH:
1681f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1682f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
1683f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1684f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1685f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1686f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_PORT_IN_RESET:
1687f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1688f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_PORT_IN_RESET\n"));
1689f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1690f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1691f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1692f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_NON_OPERATIONAL:
1693f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1694f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
1695f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1696f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1697f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task)
1698f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
1699f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
1700f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_DS_NON_OPERATIONAL);
1701f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1702f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_IN_RECOVERY:
1703f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1704f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_IN_RECOVERY\n"));
1705f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1706f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1707f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1708f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_TM_TAG_NOT_FOUND:
1709f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1710f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_TM_TAG_NOT_FOUND\n"));
1711f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1712f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1713f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1714f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
1715f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1716f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_SSP_EXT_IU_ZERO_LEN_ERROR\n"));
1717f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1718f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1719f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1720f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
1721f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1722f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
1723f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1724f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1725f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1726f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1727f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
1728f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1729f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Unknown status 0x%x\n", status));
1730f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* not allowed case. Therefore, return failed status */
1731f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1732f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1733f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1734f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1735f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_IO_DBG(pm8001_ha,
1736f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("scsi_status = 0x%x\n ",
1737f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		psspPayload->ssp_resp_iu.status));
1738f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&t->task_state_lock, flags);
1739f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
1740f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
1741f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags |= SAS_TASK_STATE_DONE;
1742f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
1743f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
1744f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
1745f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"task 0x%p done with io_status 0x%x resp 0x%x "
1746f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"stat 0x%x but aborted by upper layer!\n",
1747f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			t, status, ts->resp, ts->stat));
1748f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1749f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
1750f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
1751f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1752f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mb();/* in order to force CPU ordering */
1753f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		t->task_done(t);
1754f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1755f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1756f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1757f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/*See the comments for mpi_ssp_completion */
1758f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
1759f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1760f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *t;
1761f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
1762f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct task_status_struct *ts;
1763f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb;
1764f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev;
1765f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct ssp_event_resp *psspPayload =
1766f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct ssp_event_resp *)(piomb + 4);
1767f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 event = le32_to_cpu(psspPayload->event);
1768f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag = le32_to_cpu(psspPayload->tag);
1769f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 port_id = le32_to_cpu(psspPayload->port_id);
1770f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1771f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb = &pm8001_ha->ccb_info[tag];
1772f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t = ccb->task;
1773f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_dev = ccb->device;
1774f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (event)
1775f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1776f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("sas IO status 0x%x\n", event));
1777f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely(!t || !t->lldd_task || !t->dev))
1778f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
1779f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ts = &t->task_status;
1780f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_IO_DBG(pm8001_ha,
1781f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("port_id:0x%x, tag:0x%x, event:0x%x\n",
1782f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				port_id, tag, event));
1783f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (event) {
1784f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OVERFLOW:
1785f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n");)
1786f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1787f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1788f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->residual = 0;
1789f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
1790f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
1791f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1792f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_BREAK:
1793f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1794f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_BREAK\n"));
1795f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
1796f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
1797f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_PHY_NOT_READY:
1798f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1799f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
1800f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1801f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1802f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1803f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1804f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
1805f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
1806f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
1807f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1808f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1809f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_EPROTO;
1810f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1811f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
1812f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1813f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
1814f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1815f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1816f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1817f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1818f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BREAK:
1819f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1820f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
1821f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1822f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1823f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1824f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1825f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
1826a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
1827a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
1828a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
1829a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
1830a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
1831f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1832f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
1833f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1834f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1835f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1836f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task)
1837f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
1838f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
1839f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
1840f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1841f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
1842f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1843f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
1844f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1845f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1846f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
1847f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1848f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
1849f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
1850f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
1851f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1852f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1853f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
1854f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1855f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
1856f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1857f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
1858f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1859f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1860f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
1861f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1862f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_NAK_RECEIVED:
1863f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1864f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
1865f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1866f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
1867f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1868f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1869f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
1870f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1871f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
1872f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1873f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_NAK_R_ERR;
1874f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1875f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_OPEN_RETRY_TIMEOUT:
1876f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1877f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1878f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
1879f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
1880f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_UNEXPECTED_PHASE:
1881f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1882f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
1883f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1884f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1885f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1886f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_XFER_RDY_OVERRUN:
1887f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1888f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
1889f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1890f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1891f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1892f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
1893f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1894f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
1895f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1896f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1897f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1898f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
1899f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1900f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n"));
1901f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1902f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1903f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1904f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_OFFSET_MISMATCH:
1905f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1906f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
1907f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1908f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1909f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1910f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
1911f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1912f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
1913f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1914f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1915f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1916a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
1917a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		PM8001_IO_DBG(pm8001_ha,
1918a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("IO_XFR_ERROR_INTERNAL_CRC_ERROR\n"));
1919a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		/* TBC: used default set values */
1920a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1921a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1922a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		break;
1923f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_CMD_FRAME_ISSUED:
1924f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1925f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
1926f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
1927f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
1928f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
1929f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Unknown status 0x%x\n", event));
1930f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* not allowed case. Therefore, return failed status */
1931f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
1932f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
1933f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
1934f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1935f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&t->task_state_lock, flags);
1936f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
1937f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
1938f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags |= SAS_TASK_STATE_DONE;
1939f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
1940f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
1941f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
1942f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"task 0x%p done with event 0x%x resp 0x%x "
1943f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"stat 0x%x but aborted by upper layer!\n",
1944f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			t, event, ts->resp, ts->stat));
1945f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1946f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
1947f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
1948f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1949f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mb();/* in order to force CPU ordering */
1950f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		t->task_done(t);
1951f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
1952f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
1953f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1954f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/*See the comments for mpi_ssp_completion */
1955f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
1956f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kmpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
1957f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
1958f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *t;
1959f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb;
1960f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 param;
1961f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status;
1962f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag;
1963cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	int i, j;
1964cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	u8 sata_addr_low[4];
1965cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	u32 temp_sata_addr_low, temp_sata_addr_hi;
1966cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	u8 sata_addr_hi[4];
1967f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sata_completion_resp *psataPayload;
1968f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct task_status_struct *ts;
1969f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct ata_task_resp *resp ;
1970f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 *sata_resp;
1971f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev;
1972c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	unsigned long flags;
1973f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1974f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	psataPayload = (struct sata_completion_resp *)(piomb + 4);
1975f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	status = le32_to_cpu(psataPayload->status);
1976f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	tag = le32_to_cpu(psataPayload->tag);
1977f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
1978c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (!tag) {
1979c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1980c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("tag null\n"));
1981c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1982c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1983f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb = &pm8001_ha->ccb_info[tag];
1984f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	param = le32_to_cpu(psataPayload->param);
1985c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (ccb) {
1986c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		t = ccb->task;
1987c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		pm8001_dev = ccb->device;
1988c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	} else {
1989c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1990c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("ccb null\n"));
1991c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
1992c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
1993c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
1994c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (t) {
1995c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		if (t->dev && (t->dev->lldd_dev))
1996c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_dev = t->dev->lldd_dev;
1997c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	} else {
1998c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
1999c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("task null\n"));
2000c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
2001c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
2002c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
2003c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2004c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		&& unlikely(!t || !t->lldd_task || !t->dev)) {
2005c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2006c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("task or dev null\n"));
2007c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
2008c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
2009c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
2010f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ts = &t->task_status;
2011c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (!ts) {
2012f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2013c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("ts null\n"));
2014f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
2015c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
2016cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	/* Print sas address of IO failed device */
2017cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2018cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam		(status != IO_UNDERFLOW)) {
2019cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam		if (!((t->dev->parent) &&
2020cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			(DEV_IS_EXPANDER(t->dev->parent->dev_type)))) {
2021cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			for (i = 0 , j = 4; i <= 3 && j <= 7; i++ , j++)
2022cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				sata_addr_low[i] = pm8001_ha->sas_addr[j];
2023cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			for (i = 0 , j = 0; i <= 3 && j <= 3; i++ , j++)
2024cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2025cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			memcpy(&temp_sata_addr_low, sata_addr_low,
2026cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				sizeof(sata_addr_low));
2027cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			memcpy(&temp_sata_addr_hi, sata_addr_hi,
2028cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				sizeof(sata_addr_hi));
2029cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2030cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						|((temp_sata_addr_hi << 8) &
2031cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						0xff0000) |
2032cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						((temp_sata_addr_hi >> 8)
2033cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						& 0xff00) |
2034cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						((temp_sata_addr_hi << 24) &
2035cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						0xff000000));
2036cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2037cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						& 0xff) |
2038cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						((temp_sata_addr_low << 8)
2039cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						& 0xff0000) |
2040cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						((temp_sata_addr_low >> 8)
2041cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						& 0xff00) |
2042cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						((temp_sata_addr_low << 24)
2043cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						& 0xff000000)) +
2044cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						pm8001_dev->attached_phy +
2045cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam						0x10);
2046cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			PM8001_FAIL_DBG(pm8001_ha,
2047cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				pm8001_printk("SAS Address of IO Failure Drive:"
2048cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				"%08x%08x", temp_sata_addr_hi,
2049cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam					temp_sata_addr_low));
2050f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2051cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam		} else {
2052cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam			PM8001_FAIL_DBG(pm8001_ha,
2053cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				pm8001_printk("SAS Address of IO Failure Drive:"
2054cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam				"%016llx", SAS_ADDR(t->dev->sas_addr)));
2055cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam		}
2056cb269c26ed027bea67f5961619ae43f480a4dd3dAnand Kumar Santhanam	}
2057f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (status) {
2058f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_SUCCESS:
2059f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
2060f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (param == 0) {
2061f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_COMPLETE;
2062f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAM_STAT_GOOD;
2063c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			/* check if response is for SEND READ LOG */
2064c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			if (pm8001_dev &&
2065c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				(pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2066c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				/* set new bit for abort_all */
2067c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2068c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				/* clear bit for read log */
2069c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2070c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				pm80xx_send_abort_all(pm8001_ha, pm8001_dev);
2071c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				/* Free the tag */
2072c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				pm8001_tag_free(pm8001_ha, tag);
2073c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				sas_free_task(t);
2074c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				return;
2075c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			}
2076f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else {
2077f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			u8 len;
2078f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_COMPLETE;
2079f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_PROTO_RESPONSE;
2080f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->residual = param;
2081f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_IO_DBG(pm8001_ha,
2082f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_printk("SAS_PROTO_RESPONSE len = %d\n",
2083f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				param));
2084f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_resp = &psataPayload->sata_resp[0];
2085f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			resp = (struct ata_task_resp *)ts->buf;
2086f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			if (t->ata_task.dma_xfer == 0 &&
2087f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			t->data_dir == PCI_DMA_FROMDEVICE) {
2088f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				len = sizeof(struct pio_setup_fis);
2089f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha,
2090f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_printk("PIO read len = %d\n", len));
2091f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			} else if (t->ata_task.use_ncq) {
2092f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				len = sizeof(struct set_dev_bits_fis);
2093f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha,
2094f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					pm8001_printk("FPDMA len = %d\n", len));
2095f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			} else {
2096f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				len = sizeof(struct dev_to_host_fis);
2097f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha,
2098f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_printk("other len = %d\n", len));
2099f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			}
2100f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2101f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				resp->frame_len = len;
2102f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				memcpy(&resp->ending_fis[0], sata_resp, len);
2103f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				ts->buf_valid_size = sizeof(*resp);
2104f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			} else
2105f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha,
2106f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					pm8001_printk("response to large\n"));
2107f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2108f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2109f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2110f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2111f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_ABORTED:
2112f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2113f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_ABORTED IOMB Tag\n"));
2114f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2115f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_ABORTED_TASK;
2116f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2117f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2118f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2119f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* following cases are to do cases */
2120f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_UNDERFLOW:
2121f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* SATA Completion with error */
2122f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2123f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_UNDERFLOW param = %d\n", param));
2124f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2125f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_UNDERRUN;
2126f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->residual = param;
2127f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2128f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2129f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2130f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_NO_DEVICE:
2131f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2132f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_NO_DEVICE\n"));
2133f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
2134f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_PHY_DOWN;
2135f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2136f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_BREAK:
2137f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2138f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_BREAK\n"));
2139f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2140f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_INTERRUPTED;
2141f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2142f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_PHY_NOT_READY:
2143f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2144f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
2145f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2146f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2147f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2148f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2149f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
2150f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
2151f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
2152f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2153f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2154f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_EPROTO;
2155f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2156f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
2157f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2158f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
2159f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2160f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2161f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2162f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2163f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BREAK:
2164f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2165f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2166f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2167f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2168f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2169f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2170f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2171a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2172a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2173a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2174a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2175a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
2176f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2177f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2178f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2179f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2180f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task) {
2181f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
2182f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
2183f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2184f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_UNDELIVERED;
2185f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_QUEUE_FULL;
21862b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2187f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			return;
2188f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2189f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2190f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2191f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2192f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2193f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
2194f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2195f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2196f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task) {
2197f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
2198f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
2199f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2200f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_UNDELIVERED;
2201f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_QUEUE_FULL;
22022b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2203f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			return;
2204f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2205f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2206f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2207f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
2208f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
2209f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2210f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2211f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2212f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2213f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
2214f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
2215f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n"));
2216f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2217f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2218f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task) {
2219f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
2220f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
2221f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2222f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_UNDELIVERED;
2223f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_QUEUE_FULL;
22242b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2225f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			return;
2226f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2227f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2228f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2229f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2230f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2231f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2232f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2233f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2234f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2235f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_NAK_RECEIVED:
2236f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2237f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
2238f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2239f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_NAK_R_ERR;
2240f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2241f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
2242f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2243f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
2244f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2245f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_NAK_R_ERR;
2246f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2247f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_DMA:
2248f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2249f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_DMA\n"));
2250f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2251f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_ABORTED_TASK;
2252f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2253f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
2254f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2255f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n"));
2256f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
2257f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2258f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2259f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_REJECTED_NCQ_MODE:
2260f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2261f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
2262f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2263f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_UNDERRUN;
2264f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2265f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_OPEN_RETRY_TIMEOUT:
2266f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2267f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
2268f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2269f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2270f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2271f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_PORT_IN_RESET:
2272f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2273f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_PORT_IN_RESET\n"));
2274f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2275f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2276f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2277f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_NON_OPERATIONAL:
2278f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2279f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
2280f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2281f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2282f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task) {
2283f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha, pm8001_dev,
2284f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					IO_DS_NON_OPERATIONAL);
2285f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_UNDELIVERED;
2286f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_QUEUE_FULL;
22872b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2288f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			return;
2289f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2290f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2291f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_IN_RECOVERY:
2292f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2293f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_IN_RECOVERY\n"));
2294f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2295f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2296f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2297f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_IN_ERROR:
2298f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2299f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_IN_ERROR\n"));
2300f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2301f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2302f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task) {
2303f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha, pm8001_dev,
2304f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					IO_DS_IN_ERROR);
2305f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_UNDELIVERED;
2306f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_QUEUE_FULL;
23072b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2308f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			return;
2309f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2310f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2311f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
2312f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2313f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
2314f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2315f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2316f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2317f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
2318f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2319f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Unknown status 0x%x\n", status));
2320f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* not allowed case. Therefore, return failed status */
2321f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2322f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2323f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2324f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2325f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&t->task_state_lock, flags);
2326f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2327f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2328f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags |= SAS_TASK_STATE_DONE;
2329f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2330f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
2331f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2332f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("task 0x%p done with io_status 0x%x"
2333f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			" resp 0x%x stat 0x%x but aborted by upper layer!\n",
2334f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			t, status, ts->resp, ts->stat));
2335f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
23362b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan	} else {
2337f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
23382b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan		pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2339f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2340f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
2341f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2342f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/*See the comments for mpi_ssp_completion */
2343f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
2344f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
2345f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *t;
2346f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct task_status_struct *ts;
2347f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb;
2348f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev;
2349f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sata_event_resp *psataPayload =
2350f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct sata_event_resp *)(piomb + 4);
2351f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 event = le32_to_cpu(psataPayload->event);
2352f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag = le32_to_cpu(psataPayload->tag);
2353f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 port_id = le32_to_cpu(psataPayload->port_id);
2354c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	u32 dev_id = le32_to_cpu(psataPayload->device_id);
2355c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	unsigned long flags;
2356f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2357f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb = &pm8001_ha->ccb_info[tag];
2358c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
2359c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (ccb) {
2360c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		t = ccb->task;
2361c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		pm8001_dev = ccb->device;
2362c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	} else {
2363c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2364c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("No CCB !!!. returning\n"));
2365c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
2366c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
2367f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (event)
2368f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2369c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("SATA EVENT 0x%x\n", event));
2370c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
2371c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	/* Check if this is NCQ error */
2372c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2373c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		/* find device using device id */
2374c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2375c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		/* send read log extension */
2376c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		if (pm8001_dev)
2377c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm80xx_send_read_log(pm8001_ha, pm8001_dev);
2378c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		return;
2379c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
2380c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
2381c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (unlikely(!t || !t->lldd_task || !t->dev)) {
2382c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2383c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_printk("task or dev null\n"));
2384f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
2385c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
2386c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
2387f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ts = &t->task_status;
2388f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_IO_DBG(pm8001_ha,
2389f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("port_id:0x%x, tag:0x%x, event:0x%x\n",
2390f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				port_id, tag, event));
2391f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (event) {
2392f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OVERFLOW:
2393f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
2394f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2395f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
2396f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->residual = 0;
2397f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2398f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2399f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2400f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_BREAK:
2401f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2402f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_BREAK\n"));
2403f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2404f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_INTERRUPTED;
2405f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2406f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_PHY_NOT_READY:
2407f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2408f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
2409f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2410f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2411f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2412f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2413f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
2414f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
2415f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
2416f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2417f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2418f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_EPROTO;
2419f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2420f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
2421f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2422f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
2423f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2424f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2425f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2426f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2427f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BREAK:
2428f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2429f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2430f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2431f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2432f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2433f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2434f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2435a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2436a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2437a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2438a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2439a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
2440a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2441f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2442f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
2443f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2444f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (!t->uldd_task) {
2445f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_handle_event(pm8001_ha,
2446f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
2447f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2448f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->resp = SAS_TASK_COMPLETE;
2449f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ts->stat = SAS_QUEUE_FULL;
24502b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2451f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			return;
2452f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2453f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2454f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2455f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2456f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2457f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_UNDELIVERED;
2458f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2459f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2460f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2461f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2462f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
2463f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
2464f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2465f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2466f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2467f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2468f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2469f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2470f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2471f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2472f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2473f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2474f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2475f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_NAK_RECEIVED:
2476f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2477f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
2478f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2479f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_NAK_R_ERR;
2480f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2481f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_PEER_ABORTED:
2482f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2483f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_PEER_ABORTED\n"));
2484f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2485f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_NAK_R_ERR;
2486f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2487f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_REJECTED_NCQ_MODE:
2488f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2489f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
2490f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2491f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_UNDERRUN;
2492f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2493f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_OPEN_RETRY_TIMEOUT:
2494f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2495f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
2496f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2497f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2498f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2499f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_UNEXPECTED_PHASE:
2500f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2501f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
2502f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2503f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2504f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2505f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_XFER_RDY_OVERRUN:
2506f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2507f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
2508f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2509f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2510f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2511f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
2512f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2513f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
2514f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2515f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2516f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2517f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_OFFSET_MISMATCH:
2518f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2519f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
2520f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2521f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2522f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2523f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
2524f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2525f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
2526f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2527f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2528f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2529f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_CMD_FRAME_ISSUED:
2530f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2531f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
2532f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2533f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_PIO_SETUP_ERROR:
2534f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2535f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_PIO_SETUP_ERROR\n"));
2536f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2537f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2538f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2539a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
2540a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2541a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("IO_XFR_ERROR_INTERNAL_CRC_ERROR\n"));
2542a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		/* TBC: used default set values */
2543a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2544a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		ts->stat = SAS_OPEN_TO;
2545a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		break;
2546a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_DMA_ACTIVATE_TIMEOUT:
2547a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2548a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			pm8001_printk("IO_XFR_DMA_ACTIVATE_TIMEOUT\n"));
2549a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		/* TBC: used default set values */
2550a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2551a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		ts->stat = SAS_OPEN_TO;
2552a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		break;
2553f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
2554f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2555f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Unknown status 0x%x\n", event));
2556f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* not allowed case. Therefore, return failed status */
2557f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2558f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_TO;
2559f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2560f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2561f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&t->task_state_lock, flags);
2562f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2563f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2564f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags |= SAS_TASK_STATE_DONE;
2565f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2566f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
2567f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2568f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("task 0x%p done with io_status 0x%x"
2569f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			" resp 0x%x stat 0x%x but aborted by upper layer!\n",
2570f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			t, event, ts->resp, ts->stat));
2571f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
25722b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan	} else {
2573f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
25742b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan		pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
2575f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2576f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
2577f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2578f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/*See the comments for mpi_ssp_completion */
2579f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
2580f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kmpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2581f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
2582f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 param, i;
2583f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *t;
2584f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb;
2585f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
2586f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status;
2587f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag;
2588f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct smp_completion_resp *psmpPayload;
2589f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct task_status_struct *ts;
2590f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev;
2591f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	char *pdma_respaddr = NULL;
2592f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2593f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	psmpPayload = (struct smp_completion_resp *)(piomb + 4);
2594f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	status = le32_to_cpu(psmpPayload->status);
2595f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	tag = le32_to_cpu(psmpPayload->tag);
2596f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2597f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb = &pm8001_ha->ccb_info[tag];
2598f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	param = le32_to_cpu(psmpPayload->param);
2599f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t = ccb->task;
2600f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ts = &t->task_status;
2601f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_dev = ccb->device;
2602f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (status)
2603f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha,
2604f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("smp IO status 0x%x\n", status));
2605f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely(!t || !t->lldd_task || !t->dev))
2606f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return;
2607f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2608f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (status) {
2609f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2610f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_SUCCESS:
2611f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
2612f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2613f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAM_STAT_GOOD;
2614f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2615f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2616f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
2617f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_IO_DBG(pm8001_ha,
2618f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_printk("DIRECT RESPONSE Length:%d\n",
2619f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						param));
2620f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pdma_respaddr = (char *)(phys_to_virt(cpu_to_le64
2621f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						((u64)sg_dma_address
2622f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						(&t->smp_task.smp_resp))));
2623f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			for (i = 0; i < param; i++) {
2624f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				*(pdma_respaddr+i) = psmpPayload->_r_a[i];
2625f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha, pm8001_printk(
2626f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					"SMP Byte%d DMA data 0x%x psmp 0x%x\n",
2627f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					i, *(pdma_respaddr+i),
2628f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					psmpPayload->_r_a[i]));
2629f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			}
2630f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
2631f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2632f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_ABORTED:
2633f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2634f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_ABORTED IOMB\n"));
2635f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2636f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_ABORTED_TASK;
2637f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2638f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2639f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2640f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OVERFLOW:
2641f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
2642f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2643f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DATA_OVERRUN;
2644f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->residual = 0;
2645f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_dev)
2646f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->running_req--;
2647f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2648f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_NO_DEVICE:
2649f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n"));
2650f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2651f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_PHY_DOWN;
2652f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2653f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_ERROR_HW_TIMEOUT:
2654f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2655f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_ERROR_HW_TIMEOUT\n"));
2656f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2657f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAM_STAT_BUSY;
2658f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2659f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_BREAK:
2660f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2661f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_BREAK\n"));
2662f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2663f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAM_STAT_BUSY;
2664f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2665f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_PHY_NOT_READY:
2666f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2667f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
2668f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2669f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAM_STAT_BUSY;
2670f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2671f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
2672f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2673f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
2674f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2675f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2676f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2677f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2678f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
2679f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2680f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
2681f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2682f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2683f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2684f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2685f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BREAK:
2686f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2687f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2688f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2689f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2690f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2691f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2692f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2693a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
2694a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
2695a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
2696a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
2697a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K	case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
2698f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2699f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2700f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2701f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2702f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2703f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_handle_event(pm8001_ha,
2704f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				pm8001_dev,
2705f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2706f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2707f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2708f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2709f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2710f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2711f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2712f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2713f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2714f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2715f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(\
2716f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
2717f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2718f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2719f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2720f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2721f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2722f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2723f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2724f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2725f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2726f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2727f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2728f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_ERROR_RX_FRAME:
2729f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2730f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_ERROR_RX_FRAME\n"));
2731f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2732f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2733f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2734f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_XFER_OPEN_RETRY_TIMEOUT:
2735f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2736f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
2737f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2738f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2739f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2740f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2741f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_ERROR_INTERNAL_SMP_RESOURCE:
2742f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2743f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_ERROR_INTERNAL_SMP_RESOURCE\n"));
2744f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2745f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_QUEUE_FULL;
2746f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2747f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_PORT_IN_RESET:
2748f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2749f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_PORT_IN_RESET\n"));
2750f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2751f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2752f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2753f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2754f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_NON_OPERATIONAL:
2755f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2756f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
2757f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2758f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2759f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2760f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_DS_IN_RECOVERY:
2761f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2762f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_DS_IN_RECOVERY\n"));
2763f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2764f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2765f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2766f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2767f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
2768f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2769f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
2770f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2771f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_OPEN_REJECT;
2772f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2773f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2774f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
2775f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
2776f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Unknown status 0x%x\n", status));
2777f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->resp = SAS_TASK_COMPLETE;
2778f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ts->stat = SAS_DEV_NO_RESPONSE;
2779f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* not allowed case. Therefore, return failed status */
2780f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2781f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2782f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&t->task_state_lock, flags);
2783f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2784f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2785f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	t->task_state_flags |= SAS_TASK_STATE_DONE;
2786f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2787f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
2788f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
2789f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"task 0x%p done with io_status 0x%x resp 0x%x"
2790f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"stat 0x%x but aborted by upper layer!\n",
2791f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			t, status, ts->resp, ts->stat));
2792f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2793f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
2794f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&t->task_state_lock, flags);
2795f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2796f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mb();/* in order to force CPU ordering */
2797f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		t->task_done(t);
2798f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2799f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
2800f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2801f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
2802f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
2803f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
2804f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @Qnum: the outbound queue message number.
2805f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @SEA: source of event to ack
2806f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @port_id: port id.
2807f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @phyId: phy id.
2808f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @param0: parameter 0.
2809f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @param1: parameter 1.
2810f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
2811f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void pm80xx_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
2812f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
2813f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
2814f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct hw_event_ack_req	 payload;
2815f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
2816f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2817f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
2818f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2819f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset((u8 *)&payload, 0, sizeof(payload));
2820f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
2821f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(1);
2822f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.phyid_sea_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
2823f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		((phyId & 0xFF) << 24) | (port_id & 0xFF));
2824f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.param0 = cpu_to_le32(param0);
2825f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.param1 = cpu_to_le32(param1);
2826f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
2827f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
2828f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2829f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
2830f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyId, u32 phy_op);
2831f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2832f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
2833f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * hw_event_sas_phy_up -FW tells me a SAS phy up event.
2834f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
2835f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
2836f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
2837f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
2838f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Khw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
2839f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
2840f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct hw_event_resp *pPayload =
2841f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct hw_event_resp *)(piomb + 4);
2842f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 lr_status_evt_portid =
2843f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->lr_status_evt_portid);
2844f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
2845f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2846f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 link_rate =
2847f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((lr_status_evt_portid & 0xF0000000) >> 28);
2848f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
2849f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 phy_id =
2850f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
2851f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
2852f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2853f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_port *port = &pm8001_ha->port[port_id];
2854f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_ha_struct *sas_ha = pm8001_ha->sas;
2855f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
2856f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
2857f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 deviceType = pPayload->sas_identify.dev_type;
2858f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	port->port_state = portstate;
28597d029005484a6125a91a075518b9cfde830bc709Nikith Ganigarakoppal	phy->phy_state = PHY_STATE_LINK_UP_SPCV;
2860f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
2861f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		"portid:%d; phyid:%d; linkrate:%d; "
2862f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		"portstate:%x; devicetype:%x\n",
2863f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port_id, phy_id, link_rate, portstate, deviceType));
2864f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2865f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (deviceType) {
2866f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case SAS_PHY_UNUSED:
2867f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
2868f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("device type no device.\n"));
2869f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2870f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case SAS_END_DEVICE:
2871f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
2872f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
2873f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PHY_NOTIFY_ENABLE_SPINUP);
2874f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 1;
2875f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_get_lrate_mode(phy, link_rate);
2876f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2877f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case SAS_EDGE_EXPANDER_DEVICE:
2878f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
2879f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("expander device.\n"));
2880f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 1;
2881f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_get_lrate_mode(phy, link_rate);
2882f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2883f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case SAS_FANOUT_EXPANDER_DEVICE:
2884f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
2885f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("fanout expander device.\n"));
2886f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 1;
2887f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_get_lrate_mode(phy, link_rate);
2888f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2889f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
2890f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
2891f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("unknown device type(%x)\n", deviceType));
2892f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2893f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
2894f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->phy_type |= PORT_TYPE_SAS;
2895f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->identify.device_type = deviceType;
2896f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->phy_attached = 1;
2897f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (phy->identify.device_type == SAS_END_DEVICE)
2898f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
2899f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else if (phy->identify.device_type != SAS_PHY_UNUSED)
2900f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
2901f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->sas_phy.oob_mode = SAS_OOB_MODE;
2902f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
2903f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
2904f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memcpy(phy->frame_rcvd, &pPayload->sas_identify,
2905f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sizeof(struct sas_identify_frame)-4);
2906f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
2907f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
2908f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
2909f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (pm8001_ha->flags == PM8001F_RUN_TIME)
2910f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mdelay(200);/*delay a moment to wait disk to spinup*/
2911f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_bytes_dmaed(pm8001_ha, phy_id);
2912f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
2913f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2914f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
2915f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * hw_event_sata_phy_up -FW tells me a SATA phy up event.
2916f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
2917f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
2918f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
2919f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
2920f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Khw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
2921f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
2922f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct hw_event_resp *pPayload =
2923f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct hw_event_resp *)(piomb + 4);
2924f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
2925f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 lr_status_evt_portid =
2926f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->lr_status_evt_portid);
2927f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 link_rate =
2928f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((lr_status_evt_portid & 0xF0000000) >> 28);
2929f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
2930f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 phy_id =
2931f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
2932f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2933f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
2934f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2935f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_port *port = &pm8001_ha->port[port_id];
2936f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_ha_struct *sas_ha = pm8001_ha->sas;
2937f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
2938f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
2939f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
2940f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		"port id %d, phy id %d link_rate %d portstate 0x%x\n",
2941f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				port_id, phy_id, link_rate, portstate));
2942f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2943f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	port->port_state = portstate;
29447d029005484a6125a91a075518b9cfde830bc709Nikith Ganigarakoppal	phy->phy_state = PHY_STATE_LINK_UP_SPCV;
2945f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	port->port_attached = 1;
2946f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_get_lrate_mode(phy, link_rate);
2947f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->phy_type |= PORT_TYPE_SATA;
2948f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->phy_attached = 1;
2949f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->sas_phy.oob_mode = SATA_OOB_MODE;
2950f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
2951f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
2952f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
2953f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sizeof(struct dev_to_host_fis));
2954f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
2955f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
2956aa9f8328fc51460e15da129caf622b6560fa8c99James Bottomley	phy->identify.device_type = SAS_SATA_DEV;
2957f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
2958f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
2959f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm8001_bytes_dmaed(pm8001_ha, phy_id);
2960f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
2961f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2962f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
2963f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * hw_event_phy_down -we should notify the libsas the phy is down.
2964f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
2965f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
2966f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
2967f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void
2968f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Khw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
2969f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
2970f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct hw_event_resp *pPayload =
2971f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct hw_event_resp *)(piomb + 4);
2972f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2973f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 lr_status_evt_portid =
2974f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->lr_status_evt_portid);
2975f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
2976f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
2977f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 phy_id =
2978f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
2979f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
2980f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
2981f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_port *port = &pm8001_ha->port[port_id];
2982f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
2983f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	port->port_state = portstate;
2984f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->phy_type = 0;
2985f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->identify.device_type = 0;
2986f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	phy->phy_attached = 0;
2987f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
2988f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (portstate) {
2989f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case PORT_VALID:
2990f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
2991f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case PORT_INVALID:
2992f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
2993f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" PortInvalid portID %d\n", port_id));
2994f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
2995f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" Last phy Down and port invalid\n"));
2996f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 0;
2997f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
2998f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
2999f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3000f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case PORT_IN_RESET:
3001f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3002f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" Port In Reset portID %d\n", port_id));
3003f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3004f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case PORT_NOT_ESTABLISHED:
3005f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3006f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n"));
3007f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 0;
3008f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3009f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case PORT_LOSTCOMM:
3010f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3011f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" phy Down and PORT_LOSTCOMM\n"));
3012f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3013f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" Last phy Down and port invalid\n"));
3014f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 0;
3015f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3016f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
3017f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3018f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
3019f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		port->port_attached = 0;
3020f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3021f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" phy Down and(default) = 0x%x\n",
3022f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			portstate));
3023f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3024f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3025f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3026f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3027f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3028f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3029f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3030f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct phy_start_resp *pPayload =
3031f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct phy_start_resp *)(piomb + 4);
3032f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status =
3033f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->status);
3034f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phy_id =
3035f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->phyid);
3036f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3037f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3038f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
3039f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("phy start resp status:0x%x, phyid:0x%x\n",
3040f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				status, phy_id));
3041f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (status == 0) {
3042f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_state = 1;
3043f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (pm8001_ha->flags == PM8001F_RUN_TIME)
3044f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			complete(phy->enable_completion);
3045f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3046f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3047f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3048f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3049f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3050f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3051f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_thermal_hw_event -The hw event has come.
3052f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3053f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3054f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3055f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_thermal_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3056f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3057f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct thermal_hw_event *pPayload =
3058f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct thermal_hw_event *)(piomb + 4);
3059f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3060f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 thermal_event = le32_to_cpu(pPayload->thermal_event);
3061f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 rht_lht = le32_to_cpu(pPayload->rht_lht);
3062f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3063f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (thermal_event & 0x40) {
3064f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3065f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Thermal Event: Local high temperature violated!\n"));
3066f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3067f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Thermal Event: Measured local high temperature %d\n",
3068f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				((rht_lht & 0xFF00) >> 8)));
3069f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3070f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (thermal_event & 0x10) {
3071f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3072f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Thermal Event: Remote high temperature violated!\n"));
3073f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3074f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Thermal Event: Measured remote high temperature %d\n",
3075f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				((rht_lht & 0xFF000000) >> 24)));
3076f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3077f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3078f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3079f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3080f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3081f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_hw_event -The hw event has come.
3082f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3083f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3084f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3085f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
3086f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3087f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
3088f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct hw_event_resp *pPayload =
3089f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct hw_event_resp *)(piomb + 4);
3090f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 lr_status_evt_portid =
3091f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->lr_status_evt_portid);
3092f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
3093f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
3094f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 phy_id =
3095f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((phyid_npip_portstate & 0xFF0000) >> 16);
3096f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u16 eventType =
3097f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u16)((lr_status_evt_portid & 0x00FFFF00) >> 8);
3098f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 status =
3099f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(u8)((lr_status_evt_portid & 0x0F000000) >> 24);
3100f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3101f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3102f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3103f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
3104f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3105f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("portid:%d phyid:%d event:0x%x status:0x%x\n",
3106f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				port_id, phy_id, eventType, status));
3107f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3108f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (eventType) {
3109f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3110f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_SAS_PHY_UP:
3111f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3112f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PHY_START_STATUS\n"));
3113f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		hw_event_sas_phy_up(pm8001_ha, piomb);
3114f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3115f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_SATA_PHY_UP:
3116f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3117f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_SATA_PHY_UP\n"));
3118f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		hw_event_sata_phy_up(pm8001_ha, piomb);
3119f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3120f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_SATA_SPINUP_HOLD:
3121f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3122f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
3123f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
3124f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3125f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PHY_DOWN:
3126f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3127f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PHY_DOWN\n"));
3128f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
3129f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3130f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_state = 0;
3131f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		hw_event_phy_down(pm8001_ha, piomb);
3132f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3133f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PORT_INVALID:
3134f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3135f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PORT_INVALID\n"));
3136f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3137f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3138f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3139f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3140f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* the broadcast change primitive received, tell the LIBSAS this event
3141f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	to revalidate the sas domain*/
3142f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_BROADCAST_CHANGE:
3143f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3144f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_BROADCAST_CHANGE\n"));
3145f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3146f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 1, 0);
3147f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3148f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3149f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3150f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3151f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3152f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PHY_ERROR:
3153f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3154f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PHY_ERROR\n"));
3155f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(&phy->sas_phy);
3156f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3157f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
3158f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3159f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_BROADCAST_EXP:
3160f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3161f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_BROADCAST_EXP\n"));
3162f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3163f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3164f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3165f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3166f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3167f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_LINK_ERR_INVALID_DWORD:
3168f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3169f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n"));
3170f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3171f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3172f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3173f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3174f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3175f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3176f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
3177f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3178f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_LINK_ERR_DISPARITY_ERROR\n"));
3179f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3180f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3181f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
3182f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3183f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3184f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3185f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3186f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_LINK_ERR_CODE_VIOLATION:
3187f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3188f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_LINK_ERR_CODE_VIOLATION\n"));
3189f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3190f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			HW_EVENT_LINK_ERR_CODE_VIOLATION,
3191f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
3192f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3193f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3194f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3195f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3196f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
3197f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3198f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				"HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n"));
3199f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3200f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3201f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
3202f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3203f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3204f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3205f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3206f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_MALFUNCTION:
3207f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3208f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_MALFUNCTION\n"));
3209f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3210f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_BROADCAST_SES:
3211f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3212f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_BROADCAST_SES\n"));
3213f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3214f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3215f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3216f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3217f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3218f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_INBOUND_CRC_ERROR:
3219f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3220f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_INBOUND_CRC_ERROR\n"));
3221f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3222f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			HW_EVENT_INBOUND_CRC_ERROR,
3223f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
3224f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3225f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_HARD_RESET_RECEIVED:
3226f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3227f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_HARD_RESET_RECEIVED\n"));
3228f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
3229f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3230f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_ID_FRAME_TIMEOUT:
3231f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3232f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_ID_FRAME_TIMEOUT\n"));
3233f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3234f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3235f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3236f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3237f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
3238f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3239f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n"));
3240f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3241f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3242f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			port_id, phy_id, 0, 0);
3243f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3244f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3245f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3246f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3247f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PORT_RESET_TIMER_TMO:
3248f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3249f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n"));
3250f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3251f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3252f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3253f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3254f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
3255f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3256f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"));
3257a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K		pm80xx_hw_event_ack_req(pm8001_ha, 0,
3258a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			HW_EVENT_PORT_RECOVERY_TIMER_TMO,
3259a6cb3d012b983b350ae3892cff2e692665df0e1eSakthivel K			port_id, phy_id, 0, 0);
3260f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_phy_disconnected(sas_phy);
3261f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_attached = 0;
3262f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3263f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3264f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PORT_RECOVER:
3265f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3266f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PORT_RECOVER\n"));
3267f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3268f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case HW_EVENT_PORT_RESET_COMPLETE:
3269f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3270f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n"));
3271f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3272f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case EVENT_BROADCAST_ASYNCH_EVENT:
3273f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3274f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("EVENT_BROADCAST_ASYNCH_EVENT\n"));
3275f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3276f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
3277f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3278f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("Unknown event type 0x%x\n", eventType));
3279f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3280f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3281f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3282f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3283f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3284f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3285f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_phy_stop_resp - SPCv specific
3286f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3287f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3288f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3289f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_phy_stop_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3290f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3291f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct phy_stop_resp *pPayload =
3292f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		(struct phy_stop_resp *)(piomb + 4);
3293f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status =
3294f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->status);
3295f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyid =
3296f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		le32_to_cpu(pPayload->phyid);
3297f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_phy *phy = &pm8001_ha->phy[phyid];
3298f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3299f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("phy:0x%x status:0x%x\n",
3300f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					phyid, status));
3301f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (status == 0)
3302f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy->phy_state = 0;
3303f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3304f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3305f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3306f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3307f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_set_controller_config_resp - SPCv specific
3308f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3309f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3310f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3311f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3312f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3313f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3314f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct set_ctrl_cfg_resp *pPayload =
3315f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			(struct set_ctrl_cfg_resp *)(piomb + 4);
3316f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status = le32_to_cpu(pPayload->status);
3317f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 err_qlfr_pgcd = le32_to_cpu(pPayload->err_qlfr_pgcd);
3318f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3319f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3320f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
3321f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			status, err_qlfr_pgcd));
3322f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3323f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3324f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3325f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3326f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3327f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_get_controller_config_resp - SPCv specific
3328f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3329f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3330f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3331f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
3332f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3333f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3334f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3335f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" pm80xx_addition_functionality\n"));
3336f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3337f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3338f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3339f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3340f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3341f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_get_phy_profile_resp - SPCv specific
3342f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3343f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3344f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3345f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3346f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3347f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3348f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3349f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" pm80xx_addition_functionality\n"));
3350f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3351f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3352f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3353f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3354f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3355f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_flash_op_ext_resp - SPCv specific
3356f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3357f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3358f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3359f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_flash_op_ext_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
3360f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3361f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3362f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" pm80xx_addition_functionality\n"));
3363f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3364f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3365f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3366f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3367f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3368f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_set_phy_profile_resp - SPCv specific
3369f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3370f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3371f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3372f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_set_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
3373f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3374f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3375279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u8 page_code;
3376279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	struct set_phy_profile_resp *pPayload =
3377279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		(struct set_phy_profile_resp *)(piomb + 4);
3378279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 ppc_phyid = le32_to_cpu(pPayload->ppc_phyid);
3379279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 status = le32_to_cpu(pPayload->status);
3380f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3381279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	page_code = (u8)((ppc_phyid & 0xFF00) >> 8);
3382279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	if (status) {
3383279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		/* status is FAILED */
3384279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		PM8001_FAIL_DBG(pm8001_ha,
3385279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam			pm8001_printk("PhyProfile command failed  with status "
3386279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam			"0x%08X \n", status));
3387279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		return -1;
3388279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	} else {
3389279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		if (page_code != SAS_PHY_ANALOG_SETTINGS_PAGE) {
3390279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam			PM8001_FAIL_DBG(pm8001_ha,
3391279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam				pm8001_printk("Invalid page code 0x%X\n",
3392279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam					page_code));
3393279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam			return -1;
3394279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		}
3395279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	}
3396f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3397f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3398f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3399f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3400f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_kek_management_resp - SPCv specific
3401f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3402f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3403f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3404f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_kek_management_resp(struct pm8001_hba_info *pm8001_ha,
3405f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3406f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3407f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct kek_mgmt_resp *pPayload = (struct kek_mgmt_resp *)(piomb + 4);
3408f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3409f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 status = le32_to_cpu(pPayload->status);
3410f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 kidx_new_curr_ksop = le32_to_cpu(pPayload->kidx_new_curr_ksop);
3411f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 err_qlfr = le32_to_cpu(pPayload->err_qlfr);
3412f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3413f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3414f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		"KEK MGMT RESP. Status 0x%x idx_ksop 0x%x err_qlfr 0x%x\n",
3415f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		status, kidx_new_curr_ksop, err_qlfr));
3416f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3417f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3418f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3419f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3420f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3421f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * mpi_dek_management_resp - SPCv specific
3422f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3423f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3424f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3425f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int mpi_dek_management_resp(struct pm8001_hba_info *pm8001_ha,
3426f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3427f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3428f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3429f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" pm80xx_addition_functionality\n"));
3430f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3431f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3432f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3433f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3434f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3435f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * ssp_coalesced_comp_resp - SPCv specific
3436f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3437f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3438f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3439f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
3440f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			void *piomb)
3441f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3442f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_MSG_DBG(pm8001_ha,
3443f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk(" pm80xx_addition_functionality\n"));
3444f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3445f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3446f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3447f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3448f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3449f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * process_one_iomb - process one outbound Queue memory block
3450f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information
3451f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @piomb: IO message buffer
3452f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3453f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3454f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3455f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	__le32 pHeader = *(__le32 *)piomb;
3456f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = (u32)((le32_to_cpu(pHeader)) & 0xFFF);
3457f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3458f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (opc) {
3459f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_ECHO:
3460f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n"));
3461f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3462f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_HW_EVENT:
3463f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3464f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_HW_EVENT\n"));
3465f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_hw_event(pm8001_ha, piomb);
3466f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3467f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_THERM_HW_EVENT:
3468f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3469f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_THERMAL_EVENT\n"));
3470f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_thermal_hw_event(pm8001_ha, piomb);
3471f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3472f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SSP_COMP:
3473f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3474f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SSP_COMP\n"));
3475f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_ssp_completion(pm8001_ha, piomb);
3476f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3477f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SMP_COMP:
3478f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3479f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SMP_COMP\n"));
3480f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_smp_completion(pm8001_ha, piomb);
3481f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3482f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_LOCAL_PHY_CNTRL:
3483f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3484f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_LOCAL_PHY_CNTRL\n"));
3485f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
3486f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3487f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_DEV_REGIST:
3488f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3489f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("OPC_OUB_DEV_REGIST\n"));
3490f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_reg_resp(pm8001_ha, piomb);
3491f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3492f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_DEREG_DEV:
3493f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
34948b513d0cf603c0a9ccf86a92cb22931f05a7bc86Masanari Iida			pm8001_printk("unregister the device\n"));
3495f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_dereg_resp(pm8001_ha, piomb);
3496f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3497f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GET_DEV_HANDLE:
3498f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3499f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n"));
3500f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3501f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SATA_COMP:
3502f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3503f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SATA_COMP\n"));
3504f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_sata_completion(pm8001_ha, piomb);
3505f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3506f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SATA_EVENT:
3507f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3508f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SATA_EVENT\n"));
3509f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_sata_event(pm8001_ha, piomb);
3510f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3511f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SSP_EVENT:
3512f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3513f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SSP_EVENT\n"));
3514f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_ssp_event(pm8001_ha, piomb);
3515f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3516f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_DEV_HANDLE_ARRIV:
3517f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3518f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_DEV_HANDLE_ARRIV\n"));
3519f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/*This is for target*/
3520f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3521f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SSP_RECV_EVENT:
3522f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3523f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SSP_RECV_EVENT\n"));
3524f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/*This is for target*/
3525f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3526f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_FW_FLASH_UPDATE:
3527f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3528f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_FW_FLASH_UPDATE\n"));
3529f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
3530f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3531f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GPIO_RESPONSE:
3532f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3533f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GPIO_RESPONSE\n"));
3534f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3535f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GPIO_EVENT:
3536f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3537f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GPIO_EVENT\n"));
3538f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3539f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GENERAL_EVENT:
3540f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3541f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GENERAL_EVENT\n"));
3542f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_general_event(pm8001_ha, piomb);
3543f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3544f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SSP_ABORT_RSP:
3545f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3546f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n"));
3547f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3548f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3549f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SATA_ABORT_RSP:
3550f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3551f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n"));
3552f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3553f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3554f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SAS_DIAG_MODE_START_END:
3555f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3556f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SAS_DIAG_MODE_START_END\n"));
3557f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3558f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SAS_DIAG_EXECUTE:
3559f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3560f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SAS_DIAG_EXECUTE\n"));
3561f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3562f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GET_TIME_STAMP:
3563f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3564f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GET_TIME_STAMP\n"));
3565f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3566f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SAS_HW_EVENT_ACK:
3567f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3568f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SAS_HW_EVENT_ACK\n"));
3569f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3570f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_PORT_CONTROL:
3571f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3572f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_PORT_CONTROL\n"));
3573f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3574f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SMP_ABORT_RSP:
3575f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3576f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SMP_ABORT_RSP\n"));
3577f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
3578f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3579f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GET_NVMD_DATA:
3580f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3581f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GET_NVMD_DATA\n"));
3582f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
3583f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3584f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SET_NVMD_DATA:
3585f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3586f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SET_NVMD_DATA\n"));
3587f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
3588f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3589f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_DEVICE_HANDLE_REMOVAL:
3590f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3591f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_DEVICE_HANDLE_REMOVAL\n"));
3592f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3593f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SET_DEVICE_STATE:
3594f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3595f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SET_DEVICE_STATE\n"));
3596f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
3597f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3598f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GET_DEVICE_STATE:
3599f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3600f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_GET_DEVICE_STATE\n"));
3601f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3602f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SET_DEV_INFO:
3603f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha,
3604f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("OPC_OUB_SET_DEV_INFO\n"));
3605f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3606f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* spcv specifc commands */
3607f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_PHY_START_RESP:
3608f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3609f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_PHY_START_RESP opcode:%x\n", opc));
3610f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_phy_start_resp(pm8001_ha, piomb);
3611f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3612f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_PHY_STOP_RESP:
3613f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3614f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_PHY_STOP_RESP opcode:%x\n", opc));
3615f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_phy_stop_resp(pm8001_ha, piomb);
3616f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3617f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SET_CONTROLLER_CONFIG:
3618f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3619f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_SET_CONTROLLER_CONFIG opcode:%x\n", opc));
3620f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_set_controller_config_resp(pm8001_ha, piomb);
3621f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3622f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GET_CONTROLLER_CONFIG:
3623f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3624f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_GET_CONTROLLER_CONFIG opcode:%x\n", opc));
3625f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_get_controller_config_resp(pm8001_ha, piomb);
3626f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3627f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_GET_PHY_PROFILE:
3628f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3629f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_GET_PHY_PROFILE opcode:%x\n", opc));
3630f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_get_phy_profile_resp(pm8001_ha, piomb);
3631f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3632f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_FLASH_OP_EXT:
3633f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3634f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_FLASH_OP_EXT opcode:%x\n", opc));
3635f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_flash_op_ext_resp(pm8001_ha, piomb);
3636f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3637f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SET_PHY_PROFILE:
3638f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3639f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_SET_PHY_PROFILE opcode:%x\n", opc));
3640f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_set_phy_profile_resp(pm8001_ha, piomb);
3641f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3642f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_KEK_MANAGEMENT_RESP:
3643f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3644f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_KEK_MANAGEMENT_RESP opcode:%x\n", opc));
3645f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_kek_management_resp(pm8001_ha, piomb);
3646f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3647f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_DEK_MANAGEMENT_RESP:
3648f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3649f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_DEK_MANAGEMENT_RESP opcode:%x\n", opc));
3650f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		mpi_dek_management_resp(pm8001_ha, piomb);
3651f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3652f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case OPC_OUB_SSP_COALESCED_COMP_RESP:
3653f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3654f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"OPC_OUB_SSP_COALESCED_COMP_RESP opcode:%x\n", opc));
3655f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ssp_coalesced_comp_resp(pm8001_ha, piomb);
3656f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3657f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
3658f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
3659f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Unknown outbound Queue IOMB OPC = 0x%x\n", opc));
3660f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3661f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3662f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3663f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3664f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
3665f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3666f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct outbound_queue_table *circularQ;
3667f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	void *pMsg1 = NULL;
3668f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 uninitialized_var(bc);
3669f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 ret = MPI_IO_STATUS_FAIL;
3670f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	unsigned long flags;
3671f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3672f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_lock_irqsave(&pm8001_ha->lock, flags);
3673f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->outbnd_q_tbl[vec];
3674f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	do {
3675f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
3676f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (MPI_IO_STATUS_SUCCESS == ret) {
3677f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			/* process the outbound message */
3678f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
3679f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			/* free the message from the outbound circular buffer */
3680f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
3681f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K							circularQ, bc);
3682f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
3683f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (MPI_IO_STATUS_BUSY == ret) {
3684f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			/* Update the producer index from SPC */
3685f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			circularQ->producer_index =
3686f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
3687f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			if (le32_to_cpu(circularQ->producer_index) ==
3688f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				circularQ->consumer_idx)
3689f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				/* OQ is empty */
3690f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				break;
3691f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
3692f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} while (1);
3693f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	spin_unlock_irqrestore(&pm8001_ha->lock, flags);
3694f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
3695f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3696f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3697f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/* PCI_DMA_... to our direction translation. */
3698f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic const u8 data_dir_flags[] = {
3699f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	[PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT,/* UNSPECIFIED */
3700f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	[PCI_DMA_TODEVICE]	= DATA_DIR_OUT,/* OUTBOUND */
3701f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	[PCI_DMA_FROMDEVICE]	= DATA_DIR_IN,/* INBOUND */
3702f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	[PCI_DMA_NONE]		= DATA_DIR_NONE,/* NO TRANSFER */
3703f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K};
3704f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3705f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic void build_smp_cmd(u32 deviceID, __le32 hTag,
3706f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			struct smp_req *psmp_cmd, int mode, int length)
3707f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3708f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	psmp_cmd->tag = hTag;
3709f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	psmp_cmd->device_id = cpu_to_le32(deviceID);
3710f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (mode == SMP_DIRECT) {
3711f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		length = length - 4; /* subtract crc */
3712f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		psmp_cmd->len_ip_ir = cpu_to_le32(length << 16);
3713f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
3714f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
3715f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3716f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3717f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3718f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3719f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_smp_req - send a SMP task to FW
3720f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
3721f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @ccb: the ccb information this request used.
3722f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3723f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
3724f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb)
3725f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3726f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int elem, rc;
3727f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *task = ccb->task;
3728f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct domain_device *dev = task->dev;
3729f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev = dev->lldd_dev;
3730f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct scatterlist *sg_req, *sg_resp;
3731f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 req_len, resp_len;
3732f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct smp_req smp_cmd;
3733f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc;
3734f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
3735f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	char *preq_dma_addr = NULL;
3736f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	__le64 tmp_addr;
3737f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 i, length;
3738f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3739f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&smp_cmd, 0, sizeof(smp_cmd));
3740f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/*
3741f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 * DMA-map SMP request, response buffers
3742f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 */
3743f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sg_req = &task->smp_task.smp_req;
3744f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, PCI_DMA_TODEVICE);
3745f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!elem)
3746f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return -ENOMEM;
3747f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	req_len = sg_dma_len(sg_req);
3748f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3749f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sg_resp = &task->smp_task.smp_resp;
3750f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
3751f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!elem) {
3752f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		rc = -ENOMEM;
3753f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		goto err_out;
3754f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3755f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	resp_len = sg_dma_len(sg_resp);
3756f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* must be in dwords */
3757f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if ((req_len & 0x3) || (resp_len & 0x3)) {
3758f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		rc = -EINVAL;
3759f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		goto err_out_2;
3760f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3761f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3762f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	opc = OPC_INB_SMP_REQUEST;
3763f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
3764f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
3765f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3766f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	length = sg_req->length;
3767f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_IO_DBG(pm8001_ha,
3768f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("SMP Frame Length %d\n", sg_req->length));
3769f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (!(length - 8))
3770f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->smp_exp_mode = SMP_DIRECT;
3771f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else
3772f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->smp_exp_mode = SMP_INDIRECT;
3773f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3774f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3775f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	tmp_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
3776f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	preq_dma_addr = (char *)phys_to_virt(tmp_addr);
3777f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3778f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* INDIRECT MODE command settings. Use DMA */
3779f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (pm8001_ha->smp_exp_mode == SMP_INDIRECT) {
3780f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
3781f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("SMP REQUEST INDIRECT MODE\n"));
3782f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* for SPCv indirect mode. Place the top 4 bytes of
3783f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		 * SMP Request header here. */
3784f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		for (i = 0; i < 4; i++)
3785f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			smp_cmd.smp_req16[i] = *(preq_dma_addr + i);
3786f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* exclude top 4 bytes for SMP req header */
3787f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_req_addr =
3788f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le64((u64)sg_dma_address
3789cb993e5d50dd82e3d675225e2eff3c77951682b0Anand Kumar Santhanam				(&task->smp_task.smp_req) + 4);
3790f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* exclude 4 bytes for SMP req header and CRC */
3791f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_req_size =
3792f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-8);
3793f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_resp_addr =
3794f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le64((u64)sg_dma_address
3795f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(&task->smp_task.smp_resp));
3796f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_resp_size =
3797f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32((u32)sg_dma_len
3798f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(&task->smp_task.smp_resp)-4);
3799f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else { /* DIRECT MODE */
3800f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_req_addr =
3801f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le64((u64)sg_dma_address
3802f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(&task->smp_task.smp_req));
3803f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_req_size =
3804f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
3805f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_resp_addr =
3806f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le64((u64)sg_dma_address
3807f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(&task->smp_task.smp_resp));
3808f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		smp_cmd.long_smp_req.long_resp_size =
3809f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32
3810f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
3811f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3812f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
3813f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha,
3814f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_printk("SMP REQUEST DIRECT MODE\n"));
3815f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		for (i = 0; i < length; i++)
3816f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			if (i < 16) {
3817f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				smp_cmd.smp_req16[i] = *(preq_dma_addr+i);
3818f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3819f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					"Byte[%d]:%x (DMA data:%x)\n",
3820f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					i, smp_cmd.smp_req16[i],
3821f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					*(preq_dma_addr)));
3822f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			} else {
3823f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				smp_cmd.smp_req[i] = *(preq_dma_addr+i);
3824f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3825f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					"Byte[%d]:%x (DMA data:%x)\n",
3826f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					i, smp_cmd.smp_req[i],
3827f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					*(preq_dma_addr)));
3828f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			}
3829f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3830f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3831f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag,
3832f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				&smp_cmd, pm8001_ha->smp_exp_mode, length);
38335533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
38345533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl					(u32 *)&smp_cmd, 0);
38355533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (rc)
38365533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		goto err_out_2;
3837f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
3838f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3839f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kerr_out_2:
3840f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
3841f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PCI_DMA_FROMDEVICE);
3842f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kerr_out:
3843f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
3844f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PCI_DMA_TODEVICE);
3845f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return rc;
3846f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3847f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3848f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int check_enc_sas_cmd(struct sas_task *task)
3849f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3850e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley	u8 cmd = task->ssp_task.cmd->cmnd[0];
3851e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley
3852e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley	if (cmd == READ_10 || cmd == WRITE_10 || cmd == WRITE_VERIFY)
3853f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return 1;
3854f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else
3855f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return 0;
3856f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3857f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3858f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int check_enc_sat_cmd(struct sas_task *task)
3859f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3860f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret = 0;
3861f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	switch (task->ata_task.fis.command) {
3862f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_FPDMA_READ:
3863f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_READ_EXT:
3864f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_READ:
3865f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_FPDMA_WRITE:
3866f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_WRITE_EXT:
3867f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_WRITE:
3868f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_PIO_READ:
3869f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_PIO_READ_EXT:
3870f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_PIO_WRITE:
3871f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	case ATA_CMD_PIO_WRITE_EXT:
3872f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = 1;
3873f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3874f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	default:
3875f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ret = 0;
3876f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		break;
3877f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
3878f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
3879f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
3880f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3881f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
3882f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_chip_ssp_io_req - send a SSP task to FW
3883f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
3884f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @ccb: the ccb information this request used.
3885f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
3886f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
3887f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb)
3888f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
3889f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *task = ccb->task;
3890f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct domain_device *dev = task->dev;
3891f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev = dev->lldd_dev;
3892f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct ssp_ini_io_start_req ssp_cmd;
3893f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag = ccb->ccb_tag;
3894f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret;
38950ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam	u64 phys_addr, start_addr, end_addr;
38960ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam	u32 end_addr_high, end_addr_low;
3897f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
3898f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	u32 q_index;
3899f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = OPC_INB_SSPINIIOSTART;
3900f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&ssp_cmd, 0, sizeof(ssp_cmd));
3901f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
3902f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* data address domain added for spcv; set to 0 by host,
3903f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 * used internally by controller
3904f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 * 0 for SAS 1.1 and SAS 2.0 compatible TLR
3905f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 */
3906f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ssp_cmd.dad_dir_m_tlr =
3907f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);
3908f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
3909f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
3910f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ssp_cmd.tag = cpu_to_le32(tag);
3911f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (task->ssp_task.enable_first_burst)
3912f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
3913f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
3914f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
3915e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley	memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
3916e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley		       task->ssp_task.cmd->cmd_len);
3917f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	q_index = (u32) (pm8001_dev->id & 0x00ffffff) % PM8001_MAX_INB_NUM;
3918f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
3919f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3920f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Check if encryption is set */
3921f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (pm8001_ha->chip->encrypt &&
3922f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		!(pm8001_ha->encrypt_info.status) && check_enc_sas_cmd(task)) {
3923f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3924f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Encryption enabled.Sending Encrypt SAS command 0x%x\n",
3925e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley			task->ssp_task.cmd->cmnd[0]));
3926f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		opc = OPC_INB_SSP_INI_DIF_ENC_IO;
3927f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* enable encryption. 0 for SAS 1.1 and SAS 2.0 compatible TLR*/
3928f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ssp_cmd.dad_dir_m_tlr =	cpu_to_le32
3929f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			((data_dir_flags[task->data_dir] << 8) | 0x20 | 0x0);
3930f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
3931f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* fill in PRD (scatter/gather) table, if any */
3932f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (task->num_scatter > 1) {
3933f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_chip_make_sg(task->scatter,
3934f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						ccb->n_elem, ccb->buf_prd);
3935f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			phys_addr = ccb->ccb_dma_handle +
3936f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				offsetof(struct pm8001_ccb_info, buf_prd[0]);
3937f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_addr_low =
3938f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(lower_32_bits(phys_addr));
3939f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_addr_high =
3940f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(upper_32_bits(phys_addr));
3941f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
3942f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 1) {
3943f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			u64 dma_addr = sg_dma_address(task->scatter);
3944f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_addr_low =
3945f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(lower_32_bits(dma_addr));
3946f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_addr_high =
3947f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(upper_32_bits(dma_addr));
3948f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
3949f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_esgl = 0;
39500ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			/* Check 4G Boundary */
39510ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			start_addr = cpu_to_le64(dma_addr);
39520ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr = (start_addr + ssp_cmd.enc_len) - 1;
39530ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
39540ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
39550ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			if (end_addr_high != ssp_cmd.enc_addr_high) {
39560ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				PM8001_FAIL_DBG(pm8001_ha,
39570ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					pm8001_printk("The sg list address "
39580ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"start_addr=0x%016llx data_len=0x%x "
39590ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"end_addr_high=0x%08x end_addr_low="
39600ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"0x%08x has crossed 4G boundary\n",
39610ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						start_addr, ssp_cmd.enc_len,
39620ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						end_addr_high, end_addr_low));
39630ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				pm8001_chip_make_sg(task->scatter, 1,
39640ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					ccb->buf_prd);
39650ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				phys_addr = ccb->ccb_dma_handle +
39660ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					offsetof(struct pm8001_ccb_info,
39670ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						buf_prd[0]);
39680ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				ssp_cmd.enc_addr_low =
39690ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					cpu_to_le32(lower_32_bits(phys_addr));
39700ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				ssp_cmd.enc_addr_high =
39710ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					cpu_to_le32(upper_32_bits(phys_addr));
39720ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
39730ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			}
3974f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 0) {
3975f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_addr_low = 0;
3976f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_addr_high = 0;
3977f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
3978f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.enc_esgl = 0;
3979f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
3980f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* XTS mode. All other fields are 0 */
3981f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ssp_cmd.key_cmode = 0x6 << 4;
3982f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* set tweak values. Should be the start lba */
3983e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley		ssp_cmd.twk_val0 = cpu_to_le32((task->ssp_task.cmd->cmnd[2] << 24) |
3984e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley						(task->ssp_task.cmd->cmnd[3] << 16) |
3985e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley						(task->ssp_task.cmd->cmnd[4] << 8) |
3986e73823f7a2c921dcf068d34ea03bd682498d9e42James Bottomley						(task->ssp_task.cmd->cmnd[5]));
3987f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
3988f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
3989f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Sending Normal SAS command 0x%x inb q %x\n",
3990f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam			task->ssp_task.cmd->cmnd[0], q_index));
3991f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* fill in PRD (scatter/gather) table, if any */
3992f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (task->num_scatter > 1) {
3993f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_chip_make_sg(task->scatter, ccb->n_elem,
3994f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					ccb->buf_prd);
3995f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			phys_addr = ccb->ccb_dma_handle +
3996f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				offsetof(struct pm8001_ccb_info, buf_prd[0]);
3997f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.addr_low =
3998f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(lower_32_bits(phys_addr));
3999f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.addr_high =
4000f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(upper_32_bits(phys_addr));
4001f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.esgl = cpu_to_le32(1<<31);
4002f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 1) {
4003f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			u64 dma_addr = sg_dma_address(task->scatter);
4004f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4005f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.addr_high =
4006f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(upper_32_bits(dma_addr));
4007f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4008f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.esgl = 0;
40090ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			/* Check 4G Boundary */
40100ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			start_addr = cpu_to_le64(dma_addr);
40110ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr = (start_addr + ssp_cmd.len) - 1;
40120ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
40130ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
40140ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			if (end_addr_high != ssp_cmd.addr_high) {
40150ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				PM8001_FAIL_DBG(pm8001_ha,
40160ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					pm8001_printk("The sg list address "
40170ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"start_addr=0x%016llx data_len=0x%x "
40180ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"end_addr_high=0x%08x end_addr_low="
40190ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"0x%08x has crossed 4G boundary\n",
40200ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						 start_addr, ssp_cmd.len,
40210ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						 end_addr_high, end_addr_low));
40220ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				pm8001_chip_make_sg(task->scatter, 1,
40230ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					ccb->buf_prd);
40240ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				phys_addr = ccb->ccb_dma_handle +
40250ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					offsetof(struct pm8001_ccb_info,
40260ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						 buf_prd[0]);
40270ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				ssp_cmd.addr_low =
40280ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					cpu_to_le32(lower_32_bits(phys_addr));
40290ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				ssp_cmd.addr_high =
40300ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					cpu_to_le32(upper_32_bits(phys_addr));
40310ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				ssp_cmd.esgl = cpu_to_le32(1<<31);
40320ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			}
4033f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 0) {
4034f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.addr_low = 0;
4035f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.addr_high = 0;
4036f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4037f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ssp_cmd.esgl = 0;
4038f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
4039f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
4040f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	q_index = (u32) (pm8001_dev->id & 0x00ffffff) % PM8001_MAX_OUTB_NUM;
4041f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
4042f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam						&ssp_cmd, q_index);
4043f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
4044f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4045f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4046f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4047f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb)
4048f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4049f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sas_task *task = ccb->task;
4050f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct domain_device *dev = task->dev;
4051f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4052f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag = ccb->ccb_tag;
4053f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret;
4054f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	u32 q_index;
4055f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct sata_start_req sata_cmd;
4056f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 hdr_tag, ncg_tag = 0;
40570ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam	u64 phys_addr, start_addr, end_addr;
40580ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam	u32 end_addr_high, end_addr_low;
4059f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 ATAP = 0x0;
4060f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 dir;
4061f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
4062c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	unsigned long flags;
4063f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = OPC_INB_SATA_HOST_OPSTART;
4064f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&sata_cmd, 0, sizeof(sata_cmd));
4065f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	q_index = (u32) (pm8001_ha_dev->id & 0x00ffffff) % PM8001_MAX_INB_NUM;
4066f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
4067f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4068f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (task->data_dir == PCI_DMA_NONE) {
4069f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ATAP = 0x04; /* no data*/
4070f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n"));
4071f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else if (likely(!task->ata_task.device_control_reg_update)) {
4072f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (task->ata_task.dma_xfer) {
4073f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ATAP = 0x06; /* DMA */
4074f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n"));
4075f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else {
4076f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ATAP = 0x05; /* PIO*/
4077f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n"));
4078f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
4079f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (task->ata_task.use_ncq &&
4080f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			dev->sata_dev.command_set != ATAPI_COMMAND_SET) {
4081f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			ATAP = 0x07; /* FPDMA */
4082f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n"));
4083f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
4084f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
4085c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4086c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
4087f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		ncg_tag = hdr_tag;
4088c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
4089f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	dir = data_dir_flags[task->data_dir] << 8;
4090f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sata_cmd.tag = cpu_to_le32(tag);
4091f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4092f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4093f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4094f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sata_cmd.sata_fis = task->ata_task.fis;
4095f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (likely(!task->ata_task.device_control_reg_update))
4096f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4097f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4098f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4099f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* Check if encryption is set */
4100f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (pm8001_ha->chip->encrypt &&
4101f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		!(pm8001_ha->encrypt_info.status) && check_enc_sat_cmd(task)) {
4102f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
4103f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Encryption enabled.Sending Encrypt SATA cmd 0x%x\n",
4104f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.sata_fis.command));
4105f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		opc = OPC_INB_SATA_DIF_ENC_IO;
4106f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4107f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* set encryption bit */
4108f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sata_cmd.ncqtag_atap_dir_m_dad =
4109f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32(((ncg_tag & 0xff)<<16)|
4110f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				((ATAP & 0x3f) << 10) | 0x20 | dir);
4111f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K							/* dad (bit 0-1) is 0 */
4112f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* fill in PRD (scatter/gather) table, if any */
4113f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (task->num_scatter > 1) {
4114f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_chip_make_sg(task->scatter,
4115f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K						ccb->n_elem, ccb->buf_prd);
4116f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			phys_addr = ccb->ccb_dma_handle +
4117f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				offsetof(struct pm8001_ccb_info, buf_prd[0]);
4118f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_addr_low = lower_32_bits(phys_addr);
4119f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_addr_high = upper_32_bits(phys_addr);
4120f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_esgl = cpu_to_le32(1 << 31);
4121f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 1) {
4122f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			u64 dma_addr = sg_dma_address(task->scatter);
4123f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_addr_low = lower_32_bits(dma_addr);
4124f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_addr_high = upper_32_bits(dma_addr);
4125f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4126f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_esgl = 0;
41270ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			/* Check 4G Boundary */
41280ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			start_addr = cpu_to_le64(dma_addr);
41290ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr = (start_addr + sata_cmd.enc_len) - 1;
41300ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
41310ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
41320ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			if (end_addr_high != sata_cmd.enc_addr_high) {
41330ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				PM8001_FAIL_DBG(pm8001_ha,
41340ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					pm8001_printk("The sg list address "
41350ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"start_addr=0x%016llx data_len=0x%x "
41360ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"end_addr_high=0x%08x end_addr_low"
41370ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"=0x%08x has crossed 4G boundary\n",
41380ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						start_addr, sata_cmd.enc_len,
41390ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						end_addr_high, end_addr_low));
41400ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				pm8001_chip_make_sg(task->scatter, 1,
41410ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					ccb->buf_prd);
41420ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				phys_addr = ccb->ccb_dma_handle +
41430ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						offsetof(struct pm8001_ccb_info,
41440ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						buf_prd[0]);
41450ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				sata_cmd.enc_addr_low =
41460ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					lower_32_bits(phys_addr);
41470ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				sata_cmd.enc_addr_high =
41480ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					upper_32_bits(phys_addr);
41490ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				sata_cmd.enc_esgl =
41500ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					cpu_to_le32(1 << 31);
41510ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			}
4152f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 0) {
4153f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_addr_low = 0;
4154f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_addr_high = 0;
4155f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
4156f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.enc_esgl = 0;
4157f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
4158f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* XTS mode. All other fields are 0 */
4159f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sata_cmd.key_index_mode = 0x6 << 4;
4160f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* set tweak values. Should be the start lba */
4161f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sata_cmd.twk_val0 =
4162f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32((sata_cmd.sata_fis.lbal_exp << 24) |
4163f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(sata_cmd.sata_fis.lbah << 16) |
4164f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(sata_cmd.sata_fis.lbam << 8) |
4165f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					(sata_cmd.sata_fis.lbal));
4166f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sata_cmd.twk_val1 =
4167f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32((sata_cmd.sata_fis.lbah_exp << 8) |
4168f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					 (sata_cmd.sata_fis.lbam_exp));
4169f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
4170f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		PM8001_IO_DBG(pm8001_ha, pm8001_printk(
4171f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			"Sending Normal SATA command 0x%x inb %x\n",
4172f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam			sata_cmd.sata_fis.command, q_index));
4173f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* dad (bit 0-1) is 0 */
4174f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		sata_cmd.ncqtag_atap_dir_m_dad =
4175f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			cpu_to_le32(((ncg_tag & 0xff)<<16) |
4176f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					((ATAP & 0x3f) << 10) | dir);
4177f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4178f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		/* fill in PRD (scatter/gather) table, if any */
4179f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		if (task->num_scatter > 1) {
4180f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_chip_make_sg(task->scatter,
4181f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K					ccb->n_elem, ccb->buf_prd);
4182f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			phys_addr = ccb->ccb_dma_handle +
4183f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				offsetof(struct pm8001_ccb_info, buf_prd[0]);
4184f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.addr_low = lower_32_bits(phys_addr);
4185f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.addr_high = upper_32_bits(phys_addr);
4186f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.esgl = cpu_to_le32(1 << 31);
4187f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 1) {
4188f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			u64 dma_addr = sg_dma_address(task->scatter);
4189f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.addr_low = lower_32_bits(dma_addr);
4190f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.addr_high = upper_32_bits(dma_addr);
4191f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4192f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.esgl = 0;
41930ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			/* Check 4G Boundary */
41940ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			start_addr = cpu_to_le64(dma_addr);
41950ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr = (start_addr + sata_cmd.len) - 1;
41960ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
41970ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
41980ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			if (end_addr_high != sata_cmd.addr_high) {
41990ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				PM8001_FAIL_DBG(pm8001_ha,
42000ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					pm8001_printk("The sg list address "
42010ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"start_addr=0x%016llx data_len=0x%x"
42020ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"end_addr_high=0x%08x end_addr_low="
42030ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					"0x%08x has crossed 4G boundary\n",
42040ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						start_addr, sata_cmd.len,
42050ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam						end_addr_high, end_addr_low));
42060ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				pm8001_chip_make_sg(task->scatter, 1,
42070ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					ccb->buf_prd);
42080ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				phys_addr = ccb->ccb_dma_handle +
42090ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					offsetof(struct pm8001_ccb_info,
42100ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					buf_prd[0]);
42110ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				sata_cmd.addr_low =
42120ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					lower_32_bits(phys_addr);
42130ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				sata_cmd.addr_high =
42140ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam					upper_32_bits(phys_addr);
42150ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam				sata_cmd.esgl = cpu_to_le32(1 << 31);
42160ecdf00ba6e50eaa452356d0d4e79657dab702a4Anand Kumar Santhanam			}
4217f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		} else if (task->num_scatter == 0) {
4218f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.addr_low = 0;
4219f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.addr_high = 0;
4220f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4221f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.esgl = 0;
4222f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		}
4223f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			/* scsi cdb */
4224f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.atapi_scsi_cdb[0] =
4225f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(((task->ata_task.atapi_packet[0]) |
4226f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[1] << 8) |
4227f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[2] << 16) |
4228f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[3] << 24)));
4229f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.atapi_scsi_cdb[1] =
4230f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(((task->ata_task.atapi_packet[4]) |
4231f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[5] << 8) |
4232f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[6] << 16) |
4233f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[7] << 24)));
4234f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.atapi_scsi_cdb[2] =
4235f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(((task->ata_task.atapi_packet[8]) |
4236f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[9] << 8) |
4237f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[10] << 16) |
4238f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[11] << 24)));
4239f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			sata_cmd.atapi_scsi_cdb[3] =
4240f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				cpu_to_le32(((task->ata_task.atapi_packet[12]) |
4241f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[13] << 8) |
4242f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[14] << 16) |
4243f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K				(task->ata_task.atapi_packet[15] << 24)));
4244f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
4245c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
4246c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	/* Check for read log for failed drive and return */
4247c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	if (sata_cmd.sata_fis.command == 0x2f) {
4248c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		if (pm8001_ha_dev && ((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
4249c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			(pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4250c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			(pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4251c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			struct task_status_struct *ts;
4252c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
4253c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			pm8001_ha_dev->id &= 0xDFFFFFFF;
4254c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			ts = &task->task_status;
4255c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K
4256c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			spin_lock_irqsave(&task->task_state_lock, flags);
4257c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			ts->resp = SAS_TASK_COMPLETE;
4258c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			ts->stat = SAM_STAT_GOOD;
4259c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4260c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4261c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			task->task_state_flags |= SAS_TASK_STATE_DONE;
4262c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			if (unlikely((task->task_state_flags &
4263c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K					SAS_TASK_STATE_ABORTED))) {
4264c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				spin_unlock_irqrestore(&task->task_state_lock,
4265c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K							flags);
4266c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				PM8001_FAIL_DBG(pm8001_ha,
4267c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K					pm8001_printk("task 0x%p resp 0x%x "
4268c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K					" stat 0x%x but aborted by upper layer "
4269c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K					"\n", task, ts->resp, ts->stat));
4270c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
4271c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				return 0;
42722b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan			} else {
4273c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				spin_unlock_irqrestore(&task->task_state_lock,
4274c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K							flags);
42752b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan				pm8001_ccb_task_free_done(pm8001_ha, task,
42762b01d816f5f884d5ea16ab2498736b1221bc027cSuresh Thiagarajan								ccb, tag);
4277c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K				return 0;
4278c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K			}
4279c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K		}
4280c6b9ef5779c3e1edfa9de949d2a51252bc347663Sakthivel K	}
4281f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam	q_index = (u32) (pm8001_ha_dev->id & 0x00ffffff) % PM8001_MAX_OUTB_NUM;
4282f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
4283f9cd6cbd80d1d5963ffd0eab3970235cd4205984Anand Kumar Santhanam						&sata_cmd, q_index);
4284f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
4285f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4286f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4287f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
4288f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_chip_phy_start_req - start phy via PHY_START COMMAND
4289f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
4290f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @num: the inbound queue number
4291f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @phy_id: the phy id which we wanted to start up.
4292f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
4293f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int
4294f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4295f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4296f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct phy_start_req payload;
4297f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
4298f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret;
4299f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag = 0x01;
4300f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opcode = OPC_INB_PHYSTART;
4301f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
4302f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&payload, 0, sizeof(payload));
4303f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(tag);
4304f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4305f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	PM8001_INIT_DBG(pm8001_ha,
4306f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_printk("PHY START REQ for phy_id %d\n", phy_id));
4307f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/*
4308f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 ** [0:7]	PHY Identifier
4309f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 ** [8:11]	link rate 1.5G, 3G, 6G
4310f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b Auto mode
4311f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 ** [14]	0b disable spin up hold; 1b enable spin up hold
4312f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 ** [15] ob no change in current PHY analig setup 1b enable using SPAST
4313f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	 */
4314a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	if (!IS_SPCV_12G(pm8001_ha->pdev))
4315a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam		payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4316a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam				LINKMODE_AUTO | LINKRATE_15 |
4317a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam				LINKRATE_30 | LINKRATE_60 | phy_id);
4318a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam	else
4319a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam		payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4320a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam				LINKMODE_AUTO | LINKRATE_15 |
4321a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam				LINKRATE_30 | LINKRATE_60 | LINKRATE_120 |
4322a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam				phy_id);
4323a9a923e55ede94ddbf5b870b0f057da8b7cee1b9Anand Kumar Santhanam
4324f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/* SSC Disable and SAS Analog ST configuration */
4325f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	/**
4326f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.ase_sh_lm_slr_phyid =
4327f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		cpu_to_le32(SSC_DISABLE_30 | SAS_ASE | SPINHOLD_DISABLE |
4328f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		LINKMODE_AUTO | LINKRATE_15 | LINKRATE_30 | LINKRATE_60 |
4329f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy_id);
4330f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	Have to add "SAS PHY Analog Setup SPASTI 1 Byte" Based on need
4331f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	**/
4332f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4333aa9f8328fc51460e15da129caf622b6560fa8c99James Bottomley	payload.sas_identify.dev_type = SAS_END_DEVICE;
4334f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4335f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memcpy(payload.sas_identify.sas_addr,
4336f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		pm8001_ha->sas_addr, SAS_ADDR_SIZE);
4337f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.sas_identify.phy_id = phy_id;
4338f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, 0);
4339f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
4340f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4341f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4342f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
4343f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4344f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
4345f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @num: the inbound queue number
4346f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @phy_id: the phy id which we wanted to start up.
4347f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
4348f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4349f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 phy_id)
4350f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4351f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct phy_stop_req payload;
4352f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
4353f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret;
4354f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 tag = 0x01;
4355f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opcode = OPC_INB_PHYSTOP;
4356f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
4357f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&payload, 0, sizeof(payload));
4358f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(tag);
4359f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.phy_id = cpu_to_le32(phy_id);
4360f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, 0);
4361f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
4362f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4363f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4364f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
4365f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * see comments on pm8001_mpi_reg_resp.
4366f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
4367f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4368f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_device *pm8001_dev, u32 flag)
4369f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4370f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct reg_dev_req payload;
4371f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32	opc;
4372f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 stp_sspsmp_sata = 0x4;
4373f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
4374f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 linkrate, phy_id;
4375f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int rc, tag = 0xdeadbeef;
4376f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct pm8001_ccb_info *ccb;
4377f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u8 retryFlag = 0x1;
4378f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u16 firstBurstSize = 0;
4379f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u16 ITNT = 2000;
4380f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct domain_device *dev = pm8001_dev->sas_device;
4381f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct domain_device *parent_dev = dev->parent;
4382f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
4383f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4384f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&payload, 0, sizeof(payload));
4385f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	rc = pm8001_tag_alloc(pm8001_ha, &tag);
4386f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (rc)
4387f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return rc;
4388f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb = &pm8001_ha->ccb_info[tag];
4389f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb->device = pm8001_dev;
4390f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ccb->ccb_tag = tag;
4391f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(tag);
4392f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4393f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (flag == 1) {
4394f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		stp_sspsmp_sata = 0x02; /*direct attached sata */
4395f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	} else {
4396aa9f8328fc51460e15da129caf622b6560fa8c99James Bottomley		if (pm8001_dev->dev_type == SAS_SATA_DEV)
4397f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			stp_sspsmp_sata = 0x00; /* stp*/
4398aa9f8328fc51460e15da129caf622b6560fa8c99James Bottomley		else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
4399aa9f8328fc51460e15da129caf622b6560fa8c99James Bottomley			pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
4400aa9f8328fc51460e15da129caf622b6560fa8c99James Bottomley			pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
4401f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			stp_sspsmp_sata = 0x01; /*ssp or smp*/
4402f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	}
4403f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
4404f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4405f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	else
4406f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		phy_id = pm8001_dev->attached_phy;
4407f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4408f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	opc = OPC_INB_REG_DEV;
4409f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4410f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4411f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K			pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4412f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4413f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.phyid_portid =
4414f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0xFF) |
4415f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		((phy_id & 0xFF) << 8));
4416f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4417f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 0x01) |
4418f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		((linkrate & 0x0F) << 24) |
4419f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		((stp_sspsmp_sata & 0x03) << 28));
4420f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.firstburstsize_ITNexustimeout =
4421f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
4422f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4423f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
4424f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		SAS_ADDR_SIZE);
4425f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4426f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
44275533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (rc)
44285533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, tag);
4429f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4430f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return rc;
4431f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4432f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4433f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
4434f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm80xx_chip_phy_ctl_req - support the local phy operation
4435f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
4436f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @num: the inbound queue number
4437f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @phy_id: the phy id which we wanted to operate
4438f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @phy_op:
4439f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
4440f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4441f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 phyId, u32 phy_op)
4442f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4443f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct local_phy_ctl_req payload;
4444f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	struct inbound_queue_table *circularQ;
4445f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	int ret;
4446f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
4447f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	memset(&payload, 0, sizeof(payload));
4448f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	circularQ = &pm8001_ha->inbnd_q_tbl[0];
4449f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.tag = cpu_to_le32(1);
4450f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	payload.phyop_phyid =
4451f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		cpu_to_le32(((phy_op & 0xFF) << 8) | (phyId & 0xFF));
4452f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
4453f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return ret;
4454f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4455f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4456f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic u32 pm80xx_chip_is_our_interupt(struct pm8001_hba_info *pm8001_ha)
4457f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4458f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	u32 value;
4459f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#ifdef PM8001_USE_MSIX
4460f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 1;
4461f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K#endif
4462f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4463f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	if (value)
4464f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K		return 1;
4465f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return 0;
4466f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4467f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4468f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4469f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K/**
4470f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * pm8001_chip_isr - PM8001 isr handler.
4471f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @pm8001_ha: our hba card information.
4472f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @irq: irq number.
4473f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K * @stat: stat.
4474f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K */
4475f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kstatic irqreturn_t
4476f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kpm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
4477f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K{
4478f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm80xx_chip_interrupt_disable(pm8001_ha, vec);
4479f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	process_oq(pm8001_ha, vec);
4480f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	pm80xx_chip_interrupt_enable(pm8001_ha, vec);
4481f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	return IRQ_HANDLED;
4482f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K}
4483f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K
4484279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanamvoid mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
4485279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 operation, u32 phyid, u32 length, u32 *buf)
4486279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam{
4487279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 tag , i, j = 0;
4488279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	int rc;
4489279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	struct set_phy_profile_req payload;
4490279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	struct inbound_queue_table *circularQ;
4491279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 opc = OPC_INB_SET_PHY_PROFILE;
4492279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam
4493279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	memset(&payload, 0, sizeof(payload));
4494279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	rc = pm8001_tag_alloc(pm8001_ha, &tag);
4495279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	if (rc)
4496279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Invalid tag\n"));
4497279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	circularQ = &pm8001_ha->inbnd_q_tbl[0];
4498279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	payload.tag = cpu_to_le32(tag);
4499279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	payload.ppc_phyid = (((operation & 0xF) << 8) | (phyid  & 0xFF));
4500279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	PM8001_INIT_DBG(pm8001_ha,
4501279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		pm8001_printk(" phy profile command for phy %x ,length is %d\n",
4502279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam			payload.ppc_phyid, length));
4503279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	for (i = length; i < (length + PHY_DWORD_LENGTH - 1); i++) {
4504279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		payload.reserved[j] =  cpu_to_le32(*((u32 *)buf + i));
4505279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		j++;
4506279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	}
45075533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
45085533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl	if (rc)
45095533abca06e07121697ed1d30863ce03e7c518e5Tomas Henzl		pm8001_tag_free(pm8001_ha, tag);
4510279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam}
4511279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam
4512279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanamvoid pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha,
4513279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 length, u8 *buf)
4514279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam{
4515279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	u32 page_code, i;
4516279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam
4517279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	page_code = SAS_PHY_ANALOG_SETTINGS_PAGE;
4518279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
4519279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		mpi_set_phy_profile_req(pm8001_ha,
4520279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam			SAS_PHY_ANALOG_SETTINGS_PAGE, i, length, (u32 *)buf);
4521279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam		length = length + PHY_DWORD_LENGTH;
4522279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	}
4523279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam	PM8001_INIT_DBG(pm8001_ha, pm8001_printk("phy settings completed\n"));
4524279094079a442c19ff7e7c0fd9511d9404cb2518Anand Kumar Santhanam}
4525f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel Kconst struct pm8001_dispatch pm8001_80xx_dispatch = {
4526f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.name			= "pmc80xx",
4527f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.chip_init		= pm80xx_chip_init,
4528f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.chip_soft_rst		= pm80xx_chip_soft_rst,
4529f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.chip_rst		= pm80xx_hw_chip_rst,
4530f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.chip_iounmap		= pm8001_chip_iounmap,
4531f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.isr			= pm80xx_chip_isr,
4532f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.is_our_interupt	= pm80xx_chip_is_our_interupt,
4533f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.isr_process_oq		= process_oq,
4534f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.interrupt_enable	= pm80xx_chip_interrupt_enable,
4535f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.interrupt_disable	= pm80xx_chip_interrupt_disable,
4536f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.make_prd		= pm8001_chip_make_sg,
4537f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.smp_req		= pm80xx_chip_smp_req,
4538f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.ssp_io_req		= pm80xx_chip_ssp_io_req,
4539f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.sata_req		= pm80xx_chip_sata_req,
4540f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.phy_start_req		= pm80xx_chip_phy_start_req,
4541f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.phy_stop_req		= pm80xx_chip_phy_stop_req,
4542f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.reg_dev_req		= pm80xx_chip_reg_dev_req,
4543f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.dereg_dev_req		= pm8001_chip_dereg_dev_req,
4544f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.phy_ctl_req		= pm80xx_chip_phy_ctl_req,
4545f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.task_abort		= pm8001_chip_abort_task,
4546f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.ssp_tm_req		= pm8001_chip_ssp_tm_req,
4547f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.get_nvmd_req		= pm8001_chip_get_nvmd_req,
4548f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.set_nvmd_req		= pm8001_chip_set_nvmd_req,
4549f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.fw_flash_update_req	= pm8001_chip_fw_flash_update_req,
4550f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K	.set_dev_state_req	= pm8001_chip_set_dev_state_req,
4551f5860992db55c9e36b0f120dff73f0c34abe510dSakthivel K};
4552