blob: d048455f49413520fe65f5e9b9336de2f536ec24 [file] [log] [blame]
jack wangdbf9bfe2009-10-14 16:19:21 +08001/*
2 * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
3 *
4 * Copyright (c) 2008-2009 USI Co., Ltd.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * substantially similar to the "NO WARRANTY" disclaimer below
15 * ("Disclaimer") and any redistribution must be conditioned upon
16 * including a substantially similar Disclaimer requirement for further
17 * binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * Alternatively, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2 as published by the Free
24 * Software Foundation.
25 *
26 * NO WARRANTY
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
38 *
39 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040 #include <linux/slab.h>
jack wangdbf9bfe2009-10-14 16:19:21 +080041 #include "pm8001_sas.h"
42 #include "pm8001_hwi.h"
43 #include "pm8001_chips.h"
44 #include "pm8001_ctl.h"
45
46/**
47 * read_main_config_table - read the configure table and save it.
48 * @pm8001_ha: our hba card information
49 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080050static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +080051{
52 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
Sakthivel Ke5742102013-04-17 16:26:36 +053053 pm8001_ha->main_cfg_tbl.pm8001_tbl.signature =
54 pm8001_mr32(address, 0x00);
55 pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev =
56 pm8001_mr32(address, 0x04);
57 pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev =
58 pm8001_mr32(address, 0x08);
59 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io =
60 pm8001_mr32(address, 0x0C);
61 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl =
62 pm8001_mr32(address, 0x10);
63 pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag =
64 pm8001_mr32(address, 0x14);
65 pm8001_ha->main_cfg_tbl.pm8001_tbl.gst_offset =
66 pm8001_mr32(address, 0x18);
67 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_queue_offset =
jack_wangd0b68042009-11-05 22:32:31 +080068 pm8001_mr32(address, MAIN_IBQ_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053069 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_queue_offset =
jack_wangd0b68042009-11-05 22:32:31 +080070 pm8001_mr32(address, MAIN_OBQ_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053071 pm8001_ha->main_cfg_tbl.pm8001_tbl.hda_mode_flag =
jack wangdbf9bfe2009-10-14 16:19:21 +080072 pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET);
73
74 /* read analog Setting offset from the configuration table */
Sakthivel Ke5742102013-04-17 16:26:36 +053075 pm8001_ha->main_cfg_tbl.pm8001_tbl.anolog_setup_table_offset =
jack wangdbf9bfe2009-10-14 16:19:21 +080076 pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
77
78 /* read Error Dump Offset and Length */
Sakthivel Ke5742102013-04-17 16:26:36 +053079 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset0 =
jack wangdbf9bfe2009-10-14 16:19:21 +080080 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053081 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length0 =
jack wangdbf9bfe2009-10-14 16:19:21 +080082 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
Sakthivel Ke5742102013-04-17 16:26:36 +053083 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset1 =
jack wangdbf9bfe2009-10-14 16:19:21 +080084 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053085 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length1 =
jack wangdbf9bfe2009-10-14 16:19:21 +080086 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
87}
88
89/**
90 * read_general_status_table - read the general status table and save it.
91 * @pm8001_ha: our hba card information
92 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080093static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +080094{
95 void __iomem *address = pm8001_ha->general_stat_tbl_addr;
Sakthivel Ke5742102013-04-17 16:26:36 +053096 pm8001_ha->gs_tbl.pm8001_tbl.gst_len_mpistate =
97 pm8001_mr32(address, 0x00);
98 pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state0 =
99 pm8001_mr32(address, 0x04);
100 pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state1 =
101 pm8001_mr32(address, 0x08);
102 pm8001_ha->gs_tbl.pm8001_tbl.msgu_tcnt =
103 pm8001_mr32(address, 0x0C);
104 pm8001_ha->gs_tbl.pm8001_tbl.iop_tcnt =
105 pm8001_mr32(address, 0x10);
106 pm8001_ha->gs_tbl.pm8001_tbl.rsvd =
107 pm8001_mr32(address, 0x14);
108 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[0] =
109 pm8001_mr32(address, 0x18);
110 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[1] =
111 pm8001_mr32(address, 0x1C);
112 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[2] =
113 pm8001_mr32(address, 0x20);
114 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[3] =
115 pm8001_mr32(address, 0x24);
116 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[4] =
117 pm8001_mr32(address, 0x28);
118 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[5] =
119 pm8001_mr32(address, 0x2C);
120 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[6] =
121 pm8001_mr32(address, 0x30);
122 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[7] =
123 pm8001_mr32(address, 0x34);
124 pm8001_ha->gs_tbl.pm8001_tbl.gpio_input_val =
125 pm8001_mr32(address, 0x38);
126 pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[0] =
127 pm8001_mr32(address, 0x3C);
128 pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[1] =
129 pm8001_mr32(address, 0x40);
130 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[0] =
131 pm8001_mr32(address, 0x44);
132 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[1] =
133 pm8001_mr32(address, 0x48);
134 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[2] =
135 pm8001_mr32(address, 0x4C);
136 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[3] =
137 pm8001_mr32(address, 0x50);
138 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[4] =
139 pm8001_mr32(address, 0x54);
140 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[5] =
141 pm8001_mr32(address, 0x58);
142 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[6] =
143 pm8001_mr32(address, 0x5C);
144 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[7] =
145 pm8001_mr32(address, 0x60);
jack wangdbf9bfe2009-10-14 16:19:21 +0800146}
147
148/**
149 * read_inbnd_queue_table - read the inbound queue table and save it.
150 * @pm8001_ha: our hba card information
151 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800152static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800153{
jack wangdbf9bfe2009-10-14 16:19:21 +0800154 int i;
155 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530156 for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
jack_wangd0b68042009-11-05 22:32:31 +0800157 u32 offset = i * 0x20;
jack wangdbf9bfe2009-10-14 16:19:21 +0800158 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
159 get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
160 pm8001_ha->inbnd_q_tbl[i].pi_offset =
161 pm8001_mr32(address, (offset + 0x18));
162 }
163}
164
165/**
166 * read_outbnd_queue_table - read the outbound queue table and save it.
167 * @pm8001_ha: our hba card information
168 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800169static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800170{
jack wangdbf9bfe2009-10-14 16:19:21 +0800171 int i;
172 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530173 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800174 u32 offset = i * 0x24;
175 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
176 get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
177 pm8001_ha->outbnd_q_tbl[i].ci_offset =
178 pm8001_mr32(address, (offset + 0x18));
179 }
180}
181
182/**
183 * init_default_table_values - init the default table.
184 * @pm8001_ha: our hba card information
185 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800186static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800187{
jack wangdbf9bfe2009-10-14 16:19:21 +0800188 int i;
189 u32 offsetib, offsetob;
190 void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
191 void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530192 u32 ib_offset = pm8001_ha->ib_offset;
193 u32 ob_offset = pm8001_ha->ob_offset;
194 u32 ci_offset = pm8001_ha->ci_offset;
195 u32 pi_offset = pm8001_ha->pi_offset;
jack wangdbf9bfe2009-10-14 16:19:21 +0800196
Sakthivel Ke5742102013-04-17 16:26:36 +0530197 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd = 0;
198 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3 = 0;
199 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7 = 0;
200 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3 = 0;
201 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7 = 0;
202 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid0_3 =
203 0;
204 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid4_7 =
205 0;
206 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid0_3 = 0;
207 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid4_7 = 0;
208 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid0_3 = 0;
209 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid4_7 = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +0800210
Sakthivel Ke5742102013-04-17 16:26:36 +0530211 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800212 pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
Sakthivel Ke5742102013-04-17 16:26:36 +0530213 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800214 pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
Sakthivel Ke5742102013-04-17 16:26:36 +0530215 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size =
216 PM8001_EVENT_LOG_SIZE;
217 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option = 0x01;
218 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800219 pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
Sakthivel Ke5742102013-04-17 16:26:36 +0530220 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800221 pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
Sakthivel Ke5742102013-04-17 16:26:36 +0530222 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size =
223 PM8001_EVENT_LOG_SIZE;
224 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option = 0x01;
225 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt = 0x01;
Viswas G65df7d12021-04-02 11:12:12 +0530226 for (i = 0; i < pm8001_ha->max_q_num; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800227 pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200228 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800229 pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530230 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800231 pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530232 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800233 pm8001_ha->inbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530234 (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800235 pm8001_ha->inbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530236 pm8001_ha->memoryMap.region[ib_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800237 pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530238 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800239 pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530240 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800241 pm8001_ha->inbnd_q_tbl[i].ci_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530242 pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800243 offsetib = i * 0x20;
244 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
245 get_pci_bar_index(pm8001_mr32(addressib,
246 (offsetib + 0x14)));
247 pm8001_ha->inbnd_q_tbl[i].pi_offset =
248 pm8001_mr32(addressib, (offsetib + 0x18));
249 pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
250 pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
251 }
Viswas G65df7d12021-04-02 11:12:12 +0530252 for (i = 0; i < pm8001_ha->max_q_num; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800253 pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200254 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800255 pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530256 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800257 pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530258 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800259 pm8001_ha->outbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530260 (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800261 pm8001_ha->outbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530262 pm8001_ha->memoryMap.region[ob_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800263 pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530264 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800265 pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530266 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800267 pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530268 0 | (10 << 16) | (i << 24);
jack wangdbf9bfe2009-10-14 16:19:21 +0800269 pm8001_ha->outbnd_q_tbl[i].pi_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530270 pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800271 offsetob = i * 0x24;
272 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
273 get_pci_bar_index(pm8001_mr32(addressob,
274 offsetob + 0x14));
275 pm8001_ha->outbnd_q_tbl[i].ci_offset =
276 pm8001_mr32(addressob, (offsetob + 0x18));
277 pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
278 pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
279 }
280}
281
282/**
283 * update_main_config_table - update the main default table to the HBA.
284 * @pm8001_ha: our hba card information
285 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800286static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800287{
288 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
289 pm8001_mw32(address, 0x24,
Sakthivel Ke5742102013-04-17 16:26:36 +0530290 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd);
jack wangdbf9bfe2009-10-14 16:19:21 +0800291 pm8001_mw32(address, 0x28,
Sakthivel Ke5742102013-04-17 16:26:36 +0530292 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800293 pm8001_mw32(address, 0x2C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530294 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800295 pm8001_mw32(address, 0x30,
Sakthivel Ke5742102013-04-17 16:26:36 +0530296 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800297 pm8001_mw32(address, 0x34,
Sakthivel Ke5742102013-04-17 16:26:36 +0530298 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800299 pm8001_mw32(address, 0x38,
Sakthivel Ke5742102013-04-17 16:26:36 +0530300 pm8001_ha->main_cfg_tbl.pm8001_tbl.
301 outbound_tgt_ITNexus_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800302 pm8001_mw32(address, 0x3C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530303 pm8001_ha->main_cfg_tbl.pm8001_tbl.
304 outbound_tgt_ITNexus_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800305 pm8001_mw32(address, 0x40,
Sakthivel Ke5742102013-04-17 16:26:36 +0530306 pm8001_ha->main_cfg_tbl.pm8001_tbl.
307 outbound_tgt_ssp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800308 pm8001_mw32(address, 0x44,
Sakthivel Ke5742102013-04-17 16:26:36 +0530309 pm8001_ha->main_cfg_tbl.pm8001_tbl.
310 outbound_tgt_ssp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800311 pm8001_mw32(address, 0x48,
Sakthivel Ke5742102013-04-17 16:26:36 +0530312 pm8001_ha->main_cfg_tbl.pm8001_tbl.
313 outbound_tgt_smp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800314 pm8001_mw32(address, 0x4C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530315 pm8001_ha->main_cfg_tbl.pm8001_tbl.
316 outbound_tgt_smp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800317 pm8001_mw32(address, 0x50,
Sakthivel Ke5742102013-04-17 16:26:36 +0530318 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800319 pm8001_mw32(address, 0x54,
Sakthivel Ke5742102013-04-17 16:26:36 +0530320 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr);
321 pm8001_mw32(address, 0x58,
322 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size);
323 pm8001_mw32(address, 0x5C,
324 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800325 pm8001_mw32(address, 0x60,
Sakthivel Ke5742102013-04-17 16:26:36 +0530326 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800327 pm8001_mw32(address, 0x64,
Sakthivel Ke5742102013-04-17 16:26:36 +0530328 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr);
329 pm8001_mw32(address, 0x68,
330 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size);
jack wangdbf9bfe2009-10-14 16:19:21 +0800331 pm8001_mw32(address, 0x6C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530332 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800333 pm8001_mw32(address, 0x70,
Sakthivel Ke5742102013-04-17 16:26:36 +0530334 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt);
jack wangdbf9bfe2009-10-14 16:19:21 +0800335}
336
337/**
338 * update_inbnd_queue_table - update the inbound queue table to the HBA.
339 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100340 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800341 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800342static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
343 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800344{
345 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
346 u16 offset = number * 0x20;
347 pm8001_mw32(address, offset + 0x00,
348 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
349 pm8001_mw32(address, offset + 0x04,
350 pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
351 pm8001_mw32(address, offset + 0x08,
352 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
353 pm8001_mw32(address, offset + 0x0C,
354 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
355 pm8001_mw32(address, offset + 0x10,
356 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
357}
358
359/**
360 * update_outbnd_queue_table - update the outbound queue table to the HBA.
361 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100362 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800363 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800364static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
365 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800366{
367 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
368 u16 offset = number * 0x24;
369 pm8001_mw32(address, offset + 0x00,
370 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
371 pm8001_mw32(address, offset + 0x04,
372 pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
373 pm8001_mw32(address, offset + 0x08,
374 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
375 pm8001_mw32(address, offset + 0x0C,
376 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
377 pm8001_mw32(address, offset + 0x10,
378 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
379 pm8001_mw32(address, offset + 0x1C,
380 pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
381}
382
383/**
Mark Salyzynd95d0002012-01-17 09:18:57 -0500384 * pm8001_bar4_shift - function is called to shift BAR base address
385 * @pm8001_ha : our hba card infomation
jack wangdbf9bfe2009-10-14 16:19:21 +0800386 * @shiftValue : shifting value in memory bar.
387 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500388int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue)
jack wangdbf9bfe2009-10-14 16:19:21 +0800389{
390 u32 regVal;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500391 unsigned long start;
jack wangdbf9bfe2009-10-14 16:19:21 +0800392
393 /* program the inbound AXI translation Lower Address */
394 pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue);
395
396 /* confirm the setting is written */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500397 start = jiffies + HZ; /* 1 sec */
jack wangdbf9bfe2009-10-14 16:19:21 +0800398 do {
jack wangdbf9bfe2009-10-14 16:19:21 +0800399 regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW);
Mark Salyzynd95d0002012-01-17 09:18:57 -0500400 } while ((regVal != shiftValue) && time_before(jiffies, start));
jack wangdbf9bfe2009-10-14 16:19:21 +0800401
Mark Salyzynd95d0002012-01-17 09:18:57 -0500402 if (regVal != shiftValue) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800403 pm8001_dbg(pm8001_ha, INIT,
404 "TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW = 0x%x\n",
405 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800406 return -1;
407 }
408 return 0;
409}
410
411/**
412 * mpi_set_phys_g3_with_ssc
413 * @pm8001_ha: our hba card information
414 * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc.
415 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800416static void mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha,
417 u32 SSCbit)
jack wangdbf9bfe2009-10-14 16:19:21 +0800418{
Lee Jonesa364a3e2020-11-16 10:41:19 +0000419 u32 offset, i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500420 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800421
422#define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000
423#define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000
424#define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074
425#define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074
jack_wangd0b68042009-11-05 22:32:31 +0800426#define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12
427#define PHY_G3_WITH_SSC_BIT_SHIFT 13
428#define SNW3_PHY_CAPABILITIES_PARITY 31
jack wangdbf9bfe2009-10-14 16:19:21 +0800429
430 /*
431 * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3)
432 * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7)
433 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500434 spin_lock_irqsave(&pm8001_ha->lock, flags);
435 if (-1 == pm8001_bar4_shift(pm8001_ha,
436 SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) {
437 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800438 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500439 }
jack wang0330dba2009-12-07 17:46:22 +0800440
jack wangdbf9bfe2009-10-14 16:19:21 +0800441 for (i = 0; i < 4; i++) {
442 offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i;
jack wang0330dba2009-12-07 17:46:22 +0800443 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800444 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800445 /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500446 if (-1 == pm8001_bar4_shift(pm8001_ha,
447 SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) {
448 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800449 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500450 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800451 for (i = 4; i < 8; i++) {
452 offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
jack wang0330dba2009-12-07 17:46:22 +0800453 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800454 }
jack wang0330dba2009-12-07 17:46:22 +0800455 /*************************************************************
456 Change the SSC upspreading value to 0x0 so that upspreading is disabled.
457 Device MABC SMOD0 Controls
458 Address: (via MEMBASE-III):
459 Using shifted destination address 0x0_0000: with Offset 0xD8
460
461 31:28 R/W Reserved Do not change
462 27:24 R/W SAS_SMOD_SPRDUP 0000
463 23:20 R/W SAS_SMOD_SPRDDN 0000
464 19:0 R/W Reserved Do not change
465 Upon power-up this register will read as 0x8990c016,
466 and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000
467 so that the written value will be 0x8090c016.
468 This will ensure only down-spreading SSC is enabled on the SPC.
469 *************************************************************/
Lee Jonesa364a3e2020-11-16 10:41:19 +0000470 pm8001_cr32(pm8001_ha, 2, 0xd8);
jack wang0330dba2009-12-07 17:46:22 +0800471 pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016);
jack wangdbf9bfe2009-10-14 16:19:21 +0800472
473 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500474 pm8001_bar4_shift(pm8001_ha, 0x0);
475 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800476 return;
477}
478
479/**
480 * mpi_set_open_retry_interval_reg
481 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100482 * @interval: interval time for each OPEN_REJECT (RETRY). The units are in 1us.
jack wangdbf9bfe2009-10-14 16:19:21 +0800483 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800484static void mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha,
485 u32 interval)
jack wangdbf9bfe2009-10-14 16:19:21 +0800486{
487 u32 offset;
488 u32 value;
489 u32 i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500490 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800491
492#define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000
493#define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000
494#define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4
495#define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4
496#define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF
497
498 value = interval & OPEN_RETRY_INTERVAL_REG_MASK;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500499 spin_lock_irqsave(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800500 /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/
Mark Salyzynd95d0002012-01-17 09:18:57 -0500501 if (-1 == pm8001_bar4_shift(pm8001_ha,
502 OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) {
503 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800504 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500505 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800506 for (i = 0; i < 4; i++) {
507 offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i;
508 pm8001_cw32(pm8001_ha, 2, offset, value);
509 }
510
Mark Salyzynd95d0002012-01-17 09:18:57 -0500511 if (-1 == pm8001_bar4_shift(pm8001_ha,
512 OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) {
513 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800514 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500515 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800516 for (i = 4; i < 8; i++) {
517 offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
518 pm8001_cw32(pm8001_ha, 2, offset, value);
519 }
520 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500521 pm8001_bar4_shift(pm8001_ha, 0x0);
522 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800523 return;
524}
525
526/**
527 * mpi_init_check - check firmware initialization status.
528 * @pm8001_ha: our hba card information
529 */
530static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
531{
532 u32 max_wait_count;
533 u32 value;
534 u32 gst_len_mpistate;
535 /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
536 table is updated */
537 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE);
538 /* wait until Inbound DoorBell Clear Register toggled */
539 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
540 do {
541 udelay(1);
542 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
543 value &= SPC_MSGU_CFG_TABLE_UPDATE;
544 } while ((value != 0) && (--max_wait_count));
545
546 if (!max_wait_count)
547 return -1;
548 /* check the MPI-State for initialization */
549 gst_len_mpistate =
550 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
551 GST_GSTLEN_MPIS_OFFSET);
552 if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK))
553 return -1;
554 /* check MPI Initialization error */
555 gst_len_mpistate = gst_len_mpistate >> 16;
556 if (0x0000 != gst_len_mpistate)
557 return -1;
558 return 0;
559}
560
561/**
562 * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
563 * @pm8001_ha: our hba card information
564 */
565static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
566{
567 u32 value, value1;
568 u32 max_wait_count;
569 /* check error state */
570 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
571 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
572 /* check AAP error */
573 if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) {
574 /* error state */
575 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
576 return -1;
577 }
578
579 /* check IOP error */
580 if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) {
581 /* error state */
582 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
583 return -1;
584 }
585
586 /* bit 4-31 of scratch pad1 should be zeros if it is not
587 in error state*/
588 if (value & SCRATCH_PAD1_STATE_MASK) {
589 /* error case */
590 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
591 return -1;
592 }
593
594 /* bit 2, 4-31 of scratch pad2 should be zeros if it is not
595 in error state */
596 if (value1 & SCRATCH_PAD2_STATE_MASK) {
597 /* error case */
598 return -1;
599 }
600
601 max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */
602
603 /* wait until scratch pad 1 and 2 registers in ready state */
604 do {
605 udelay(1);
606 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
607 & SCRATCH_PAD1_RDY;
608 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
609 & SCRATCH_PAD2_RDY;
610 if ((--max_wait_count) == 0)
611 return -1;
612 } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY));
613 return 0;
614}
615
616static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
617{
618 void __iomem *base_addr;
619 u32 value;
620 u32 offset;
621 u32 pcibar;
622 u32 pcilogic;
623
624 value = pm8001_cr32(pm8001_ha, 0, 0x44);
625 offset = value & 0x03FFFFFF;
Joe Perches1b5d2792020-11-20 15:16:09 -0800626 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 Offset: %x\n", offset);
jack wangdbf9bfe2009-10-14 16:19:21 +0800627 pcilogic = (value & 0xFC000000) >> 26;
628 pcibar = get_pci_bar_index(pcilogic);
Joe Perches1b5d2792020-11-20 15:16:09 -0800629 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar);
jack wangdbf9bfe2009-10-14 16:19:21 +0800630 pm8001_ha->main_cfg_tbl_addr = base_addr =
631 pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
632 pm8001_ha->general_stat_tbl_addr =
633 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18);
634 pm8001_ha->inbnd_q_tbl_addr =
635 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C);
636 pm8001_ha->outbnd_q_tbl_addr =
637 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20);
638}
639
640/**
641 * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
642 * @pm8001_ha: our hba card information
643 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800644static int pm8001_chip_init(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800645{
Sakthivel Ke590adf2013-02-27 20:25:25 +0530646 u8 i = 0;
Sakthivel K54792dc2013-03-19 18:05:55 +0530647 u16 deviceid;
648 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
649 /* 8081 controllers need BAR shift to access MPI space
650 * as this is shared with BIOS data */
Bradley Grove81b86d42013-12-19 10:50:57 -0500651 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530652 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800653 pm8001_dbg(pm8001_ha, FAIL,
654 "Shift Bar4 to 0x%x failed\n",
655 GSM_SM_BASE);
Sakthivel K54792dc2013-03-19 18:05:55 +0530656 return -1;
657 }
658 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800659 /* check the firmware status */
660 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800661 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800662 return -EBUSY;
663 }
664
665 /* Initialize pci space address eg: mpi offset */
666 init_pci_device_addresses(pm8001_ha);
667 init_default_table_values(pm8001_ha);
668 read_main_config_table(pm8001_ha);
669 read_general_status_table(pm8001_ha);
670 read_inbnd_queue_table(pm8001_ha);
671 read_outbnd_queue_table(pm8001_ha);
672 /* update main config table ,inbound table and outbound table */
673 update_main_config_table(pm8001_ha);
Viswas G65df7d12021-04-02 11:12:12 +0530674 for (i = 0; i < pm8001_ha->max_q_num; i++)
Sakthivel Ke590adf2013-02-27 20:25:25 +0530675 update_inbnd_queue_table(pm8001_ha, i);
Viswas G65df7d12021-04-02 11:12:12 +0530676 for (i = 0; i < pm8001_ha->max_q_num; i++)
Sakthivel Ke590adf2013-02-27 20:25:25 +0530677 update_outbnd_queue_table(pm8001_ha, i);
Sakthivel K54792dc2013-03-19 18:05:55 +0530678 /* 8081 controller donot require these operations */
Bradley Grove81b86d42013-12-19 10:50:57 -0500679 if (deviceid != 0x8081 && deviceid != 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530680 mpi_set_phys_g3_with_ssc(pm8001_ha, 0);
681 /* 7->130ms, 34->500ms, 119->1.5s */
682 mpi_set_open_retry_interval_reg(pm8001_ha, 119);
683 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800684 /* notify firmware update finished and check initialization status */
685 if (0 == mpi_init_check(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800686 pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800687 } else
688 return -EBUSY;
689 /*This register is a 16-bit timer with a resolution of 1us. This is the
690 timer used for interrupt delay/coalescing in the PCIe Application Layer.
691 Zero is not a valid value. A value of 1 in the register will cause the
692 interrupts to be normal. A value greater than 1 will cause coalescing
693 delays.*/
694 pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1);
695 pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0);
696 return 0;
697}
698
699static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
700{
701 u32 max_wait_count;
702 u32 value;
703 u32 gst_len_mpistate;
Sakthivel K54792dc2013-03-19 18:05:55 +0530704 u16 deviceid;
705 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
Bradley Grove81b86d42013-12-19 10:50:57 -0500706 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530707 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800708 pm8001_dbg(pm8001_ha, FAIL,
709 "Shift Bar4 to 0x%x failed\n",
710 GSM_SM_BASE);
Sakthivel K54792dc2013-03-19 18:05:55 +0530711 return -1;
712 }
713 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800714 init_pci_device_addresses(pm8001_ha);
715 /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
716 table is stop */
717 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET);
718
719 /* wait until Inbound DoorBell Clear Register toggled */
720 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
721 do {
722 udelay(1);
723 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
724 value &= SPC_MSGU_CFG_TABLE_RESET;
725 } while ((value != 0) && (--max_wait_count));
726
727 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800728 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=0x%x\n",
729 value);
jack wangdbf9bfe2009-10-14 16:19:21 +0800730 return -1;
731 }
732
733 /* check the MPI-State for termination in progress */
734 /* wait until Inbound DoorBell Clear Register toggled */
735 max_wait_count = 1 * 1000 * 1000; /* 1 sec */
736 do {
737 udelay(1);
738 gst_len_mpistate =
739 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
740 GST_GSTLEN_MPIS_OFFSET);
741 if (GST_MPI_STATE_UNINIT ==
742 (gst_len_mpistate & GST_MPI_STATE_MASK))
743 break;
744 } while (--max_wait_count);
745 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800746 pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n",
747 gst_len_mpistate & GST_MPI_STATE_MASK);
jack wangdbf9bfe2009-10-14 16:19:21 +0800748 return -1;
749 }
750 return 0;
751}
752
753/**
754 * soft_reset_ready_check - Function to check FW is ready for soft reset.
755 * @pm8001_ha: our hba card information
756 */
757static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha)
758{
759 u32 regVal, regVal1, regVal2;
760 if (mpi_uninit_check(pm8001_ha) != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800761 pm8001_dbg(pm8001_ha, FAIL, "MPI state is not ready\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800762 return -1;
763 }
764 /* read the scratch pad 2 register bit 2 */
765 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
766 & SCRATCH_PAD2_FWRDY_RST;
767 if (regVal == SCRATCH_PAD2_FWRDY_RST) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800768 pm8001_dbg(pm8001_ha, INIT, "Firmware is ready for reset.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800769 } else {
Mark Salyzynd95d0002012-01-17 09:18:57 -0500770 unsigned long flags;
771 /* Trigger NMI twice via RB6 */
772 spin_lock_irqsave(&pm8001_ha->lock, flags);
773 if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) {
774 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800775 pm8001_dbg(pm8001_ha, FAIL,
776 "Shift Bar4 to 0x%x failed\n",
777 RB6_ACCESS_REG);
jack wangdbf9bfe2009-10-14 16:19:21 +0800778 return -1;
779 }
780 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET,
781 RB6_MAGIC_NUMBER_RST);
782 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST);
783 /* wait for 100 ms */
784 mdelay(100);
785 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) &
786 SCRATCH_PAD2_FWRDY_RST;
787 if (regVal != SCRATCH_PAD2_FWRDY_RST) {
788 regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
789 regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
Joe Perches1b5d2792020-11-20 15:16:09 -0800790 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:MSGU_SCRATCH_PAD1=0x%x, MSGU_SCRATCH_PAD2=0x%x\n",
791 regVal1, regVal2);
792 pm8001_dbg(pm8001_ha, FAIL,
793 "SCRATCH_PAD0 value = 0x%x\n",
794 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0));
795 pm8001_dbg(pm8001_ha, FAIL,
796 "SCRATCH_PAD3 value = 0x%x\n",
797 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -0500798 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800799 return -1;
800 }
Mark Salyzynd95d0002012-01-17 09:18:57 -0500801 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800802 }
803 return 0;
804}
805
806/**
807 * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
808 * the FW register status to the originated status.
809 * @pm8001_ha: our hba card information
jack wangdbf9bfe2009-10-14 16:19:21 +0800810 */
811static int
Sakthivel Kf5860992013-04-17 16:37:02 +0530812pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800813{
814 u32 regVal, toggleVal;
815 u32 max_wait_count;
816 u32 regVal1, regVal2, regVal3;
Sakthivel Kf5860992013-04-17 16:37:02 +0530817 u32 signature = 0x252acbcd; /* for host scratch pad0 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500818 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800819
820 /* step1: Check FW is ready for soft reset */
821 if (soft_reset_ready_check(pm8001_ha) != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800822 pm8001_dbg(pm8001_ha, FAIL, "FW is not ready\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800823 return -1;
824 }
825
826 /* step 2: clear NMI status register on AAP1 and IOP, write the same
827 value to clear */
828 /* map 0x60000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500829 spin_lock_irqsave(&pm8001_ha->lock, flags);
830 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) {
831 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800832 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
833 MBIC_AAP1_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800834 return -1;
835 }
836 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP);
Joe Perches1b5d2792020-11-20 15:16:09 -0800837 pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (IOP)= 0x%x\n",
838 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800839 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0);
840 /* map 0x70000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500841 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) {
842 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800843 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
844 MBIC_IOP_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800845 return -1;
846 }
847 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1);
Joe Perches1b5d2792020-11-20 15:16:09 -0800848 pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n",
849 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800850 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0);
851
852 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800853 pm8001_dbg(pm8001_ha, INIT, "PCIE -Event Interrupt Enable = 0x%x\n",
854 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800855 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0);
856
857 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT);
Joe Perches1b5d2792020-11-20 15:16:09 -0800858 pm8001_dbg(pm8001_ha, INIT, "PCIE - Event Interrupt = 0x%x\n",
859 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800860 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal);
861
862 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800863 pm8001_dbg(pm8001_ha, INIT, "PCIE -Error Interrupt Enable = 0x%x\n",
864 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800865 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0);
866
867 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT);
Joe Perches1b5d2792020-11-20 15:16:09 -0800868 pm8001_dbg(pm8001_ha, INIT, "PCIE - Error Interrupt = 0x%x\n", regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800869 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal);
870
871 /* read the scratch pad 1 register bit 2 */
872 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
873 & SCRATCH_PAD1_RST;
874 toggleVal = regVal ^ SCRATCH_PAD1_RST;
875
876 /* set signature in host scratch pad0 register to tell SPC that the
877 host performs the soft reset */
878 pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature);
879
880 /* read required registers for confirmming */
881 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500882 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
883 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800884 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
885 GSM_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800886 return -1;
887 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800888 pm8001_dbg(pm8001_ha, INIT,
889 "GSM 0x0(0x00007b88)-GSM Configuration and Reset = 0x%x\n",
890 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +0800891
892 /* step 3: host read GSM Configuration and Reset register */
893 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
894 /* Put those bits to low */
895 /* GSM XCBI offset = 0x70 0000
896 0x00 Bit 13 COM_SLV_SW_RSTB 1
897 0x00 Bit 12 QSSP_SW_RSTB 1
898 0x00 Bit 11 RAAE_SW_RSTB 1
899 0x00 Bit 9 RB_1_SW_RSTB 1
900 0x00 Bit 8 SM_SW_RSTB 1
901 */
902 regVal &= ~(0x00003b00);
903 /* host write GSM Configuration and Reset register */
904 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
Joe Perches1b5d2792020-11-20 15:16:09 -0800905 pm8001_dbg(pm8001_ha, INIT,
906 "GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM Configuration and Reset is set to = 0x%x\n",
907 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +0800908
909 /* step 4: */
910 /* disable GSM - Read Address Parity Check */
911 regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800912 pm8001_dbg(pm8001_ha, INIT,
913 "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n",
914 regVal1);
jack wangdbf9bfe2009-10-14 16:19:21 +0800915 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800916 pm8001_dbg(pm8001_ha, INIT,
917 "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n",
918 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800919
920 /* disable GSM - Write Address Parity Check */
921 regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800922 pm8001_dbg(pm8001_ha, INIT,
923 "GSM 0x700040 - Write Address Parity Check Enable = 0x%x\n",
924 regVal2);
jack wangdbf9bfe2009-10-14 16:19:21 +0800925 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800926 pm8001_dbg(pm8001_ha, INIT,
927 "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n",
928 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800929
930 /* disable GSM - Write Data Parity Check */
931 regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800932 pm8001_dbg(pm8001_ha, INIT, "GSM 0x300048 - Write Data Parity Check Enable = 0x%x\n",
933 regVal3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800934 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800935 pm8001_dbg(pm8001_ha, INIT,
936 "GSM 0x300048 - Write Data Parity Check Enable is set to = 0x%x\n",
937 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800938
939 /* step 5: delay 10 usec */
940 udelay(10);
941 /* step 5-b: set GPIO-0 output control to tristate anyway */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500942 if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) {
943 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800944 pm8001_dbg(pm8001_ha, INIT, "Shift Bar4 to 0x%x failed\n",
945 GPIO_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800946 return -1;
947 }
948 regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800949 pm8001_dbg(pm8001_ha, INIT, "GPIO Output Control Register: = 0x%x\n",
950 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800951 /* set GPIO-0 output control to tri-state */
952 regVal &= 0xFFFFFFFC;
953 pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal);
954
955 /* Step 6: Reset the IOP and AAP1 */
956 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500957 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
958 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800959 pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n",
960 SPC_TOP_LEVEL_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800961 return -1;
962 }
963 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800964 pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting IOP/AAP1:= 0x%x\n",
965 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800966 regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
967 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
968
969 /* step 7: Reset the BDMA/OSSP */
970 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800971 pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting BDMA/OSSP: = 0x%x\n",
972 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800973 regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
974 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
975
976 /* step 8: delay 10 usec */
977 udelay(10);
978
979 /* step 9: bring the BDMA and OSSP out of reset */
980 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800981 pm8001_dbg(pm8001_ha, INIT,
982 "Top Register before bringing up BDMA/OSSP:= 0x%x\n",
983 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800984 regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
985 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
986
987 /* step 10: delay 10 usec */
988 udelay(10);
989
990 /* step 11: reads and sets the GSM Configuration and Reset Register */
991 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500992 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
993 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800994 pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n",
995 GSM_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800996 return -1;
997 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800998 pm8001_dbg(pm8001_ha, INIT,
999 "GSM 0x0 (0x00007b88)-GSM Configuration and Reset = 0x%x\n",
1000 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +08001001 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
1002 /* Put those bits to high */
1003 /* GSM XCBI offset = 0x70 0000
1004 0x00 Bit 13 COM_SLV_SW_RSTB 1
1005 0x00 Bit 12 QSSP_SW_RSTB 1
1006 0x00 Bit 11 RAAE_SW_RSTB 1
1007 0x00 Bit 9 RB_1_SW_RSTB 1
1008 0x00 Bit 8 SM_SW_RSTB 1
1009 */
1010 regVal |= (GSM_CONFIG_RESET_VALUE);
1011 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
Joe Perches1b5d2792020-11-20 15:16:09 -08001012 pm8001_dbg(pm8001_ha, INIT, "GSM (0x00004088 ==> 0x00007b88) - GSM Configuration and Reset is set to = 0x%x\n",
1013 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +08001014
1015 /* step 12: Restore GSM - Read Address Parity Check */
1016 regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
1017 /* just for debugging */
Joe Perches1b5d2792020-11-20 15:16:09 -08001018 pm8001_dbg(pm8001_ha, INIT,
1019 "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n",
1020 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +08001021 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001022 pm8001_dbg(pm8001_ha, INIT, "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n",
1023 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001024 /* Restore GSM - Write Address Parity Check */
1025 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
1026 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2);
Joe Perches1b5d2792020-11-20 15:16:09 -08001027 pm8001_dbg(pm8001_ha, INIT,
1028 "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n",
1029 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001030 /* Restore GSM - Write Data Parity Check */
1031 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
1032 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3);
Joe Perches1b5d2792020-11-20 15:16:09 -08001033 pm8001_dbg(pm8001_ha, INIT,
Colin Ian Kingc6131852020-11-24 09:38:28 +00001034 "GSM 0x700048 - Write Data Parity Check Enable is set to = 0x%x\n",
Joe Perches1b5d2792020-11-20 15:16:09 -08001035 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001036
1037 /* step 13: bring the IOP and AAP1 out of reset */
1038 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -05001039 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
1040 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08001041 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
1042 SPC_TOP_LEVEL_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001043 return -1;
1044 }
1045 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
1046 regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
1047 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
1048
1049 /* step 14: delay 10 usec - Normal Mode */
1050 udelay(10);
1051 /* check Soft Reset Normal mode or Soft Reset HDA mode */
1052 if (signature == SPC_SOFT_RESET_SIGNATURE) {
1053 /* step 15 (Normal Mode): wait until scratch pad1 register
1054 bit 2 toggled */
1055 max_wait_count = 2 * 1000 * 1000;/* 2 sec */
1056 do {
1057 udelay(1);
1058 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1059 SCRATCH_PAD1_RST;
1060 } while ((regVal != toggleVal) && (--max_wait_count));
1061
1062 if (!max_wait_count) {
1063 regVal = pm8001_cr32(pm8001_ha, 0,
1064 MSGU_SCRATCH_PAD_1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001065 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT : ToggleVal 0x%x,MSGU_SCRATCH_PAD1 = 0x%x\n",
1066 toggleVal, regVal);
1067 pm8001_dbg(pm8001_ha, FAIL,
1068 "SCRATCH_PAD0 value = 0x%x\n",
1069 pm8001_cr32(pm8001_ha, 0,
1070 MSGU_SCRATCH_PAD_0));
1071 pm8001_dbg(pm8001_ha, FAIL,
1072 "SCRATCH_PAD2 value = 0x%x\n",
1073 pm8001_cr32(pm8001_ha, 0,
1074 MSGU_SCRATCH_PAD_2));
1075 pm8001_dbg(pm8001_ha, FAIL,
1076 "SCRATCH_PAD3 value = 0x%x\n",
1077 pm8001_cr32(pm8001_ha, 0,
1078 MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001079 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001080 return -1;
1081 }
1082
1083 /* step 16 (Normal) - Clear ODMR and ODCR */
1084 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1085 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1086
1087 /* step 17 (Normal Mode): wait for the FW and IOP to get
1088 ready - 1 sec timeout */
1089 /* Wait for the SPC Configuration Table to be ready */
1090 if (check_fw_ready(pm8001_ha) == -1) {
1091 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1092 /* return error if MPI Configuration Table not ready */
Joe Perches1b5d2792020-11-20 15:16:09 -08001093 pm8001_dbg(pm8001_ha, INIT,
1094 "FW not ready SCRATCH_PAD1 = 0x%x\n",
1095 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +08001096 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1097 /* return error if MPI Configuration Table not ready */
Joe Perches1b5d2792020-11-20 15:16:09 -08001098 pm8001_dbg(pm8001_ha, INIT,
1099 "FW not ready SCRATCH_PAD2 = 0x%x\n",
1100 regVal);
1101 pm8001_dbg(pm8001_ha, INIT,
1102 "SCRATCH_PAD0 value = 0x%x\n",
1103 pm8001_cr32(pm8001_ha, 0,
1104 MSGU_SCRATCH_PAD_0));
1105 pm8001_dbg(pm8001_ha, INIT,
1106 "SCRATCH_PAD3 value = 0x%x\n",
1107 pm8001_cr32(pm8001_ha, 0,
1108 MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001109 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001110 return -1;
1111 }
1112 }
Mark Salyzynd95d0002012-01-17 09:18:57 -05001113 pm8001_bar4_shift(pm8001_ha, 0);
1114 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001115
Joe Perches1b5d2792020-11-20 15:16:09 -08001116 pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001117 return 0;
1118}
1119
1120static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1121{
1122 u32 i;
1123 u32 regVal;
Joe Perches1b5d2792020-11-20 15:16:09 -08001124 pm8001_dbg(pm8001_ha, INIT, "chip reset start\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001125
1126 /* do SPC chip reset. */
1127 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1128 regVal &= ~(SPC_REG_RESET_DEVICE);
1129 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1130
1131 /* delay 10 usec */
1132 udelay(10);
1133
1134 /* bring chip reset out of reset */
1135 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1136 regVal |= SPC_REG_RESET_DEVICE;
1137 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1138
1139 /* delay 10 usec */
1140 udelay(10);
1141
1142 /* wait for 20 msec until the firmware gets reloaded */
1143 i = 20;
1144 do {
1145 mdelay(1);
1146 } while ((--i) != 0);
1147
Joe Perches1b5d2792020-11-20 15:16:09 -08001148 pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001149}
1150
1151/**
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02001152 * pm8001_chip_iounmap - which maped when initialized.
jack wangdbf9bfe2009-10-14 16:19:21 +08001153 * @pm8001_ha: our hba card information
1154 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301155void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08001156{
1157 s8 bar, logical = 0;
Denis Efremovc9c13ba2019-09-28 02:43:08 +03001158 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001159 /*
1160 ** logical BARs for SPC:
1161 ** bar 0 and 1 - logical BAR0
1162 ** bar 2 and 3 - logical BAR1
1163 ** bar4 - logical BAR2
1164 ** bar5 - logical BAR3
1165 ** Skip the appropriate assignments:
1166 */
1167 if ((bar == 1) || (bar == 3))
1168 continue;
1169 if (pm8001_ha->io_mem[logical].memvirtaddr) {
1170 iounmap(pm8001_ha->io_mem[logical].memvirtaddr);
1171 logical++;
1172 }
1173 }
1174}
1175
Colin Ian King292c04c2019-03-28 23:43:28 +00001176#ifndef PM8001_USE_MSIX
jack wangdbf9bfe2009-10-14 16:19:21 +08001177/**
Lee Jones6b87e432021-03-03 14:46:19 +00001178 * pm8001_chip_intx_interrupt_enable - enable PM8001 chip interrupt
jack wangdbf9bfe2009-10-14 16:19:21 +08001179 * @pm8001_ha: our hba card information
1180 */
1181static void
1182pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1183{
1184 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1185 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1186}
1187
1188 /**
1189 * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
1190 * @pm8001_ha: our hba card information
1191 */
1192static void
1193pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1194{
1195 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL);
1196}
1197
Colin Ian King292c04c2019-03-28 23:43:28 +00001198#else
1199
jack wangdbf9bfe2009-10-14 16:19:21 +08001200/**
1201 * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt
1202 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001203 * @int_vec_idx: interrupt number to enable
jack wangdbf9bfe2009-10-14 16:19:21 +08001204 */
1205static void
1206pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha,
1207 u32 int_vec_idx)
1208{
1209 u32 msi_index;
1210 u32 value;
1211 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1212 msi_index += MSIX_TABLE_BASE;
1213 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE);
1214 value = (1 << int_vec_idx);
1215 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value);
1216
1217}
1218
1219/**
1220 * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt
1221 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001222 * @int_vec_idx: interrupt number to disable
jack wangdbf9bfe2009-10-14 16:19:21 +08001223 */
1224static void
1225pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha,
1226 u32 int_vec_idx)
1227{
1228 u32 msi_index;
1229 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1230 msi_index += MSIX_TABLE_BASE;
1231 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001232}
Colin Ian King292c04c2019-03-28 23:43:28 +00001233#endif
Mark Salyzynd95d0002012-01-17 09:18:57 -05001234
jack wangdbf9bfe2009-10-14 16:19:21 +08001235/**
1236 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1237 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001238 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001239 */
1240static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301241pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001242{
1243#ifdef PM8001_USE_MSIX
1244 pm8001_chip_msix_interrupt_enable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001245#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001246 pm8001_chip_intx_interrupt_enable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001247#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001248}
1249
1250/**
Lee Jones6b87e432021-03-03 14:46:19 +00001251 * pm8001_chip_interrupt_disable - disable PM8001 chip interrupt
jack wangdbf9bfe2009-10-14 16:19:21 +08001252 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001253 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001254 */
1255static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301256pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001257{
1258#ifdef PM8001_USE_MSIX
1259 pm8001_chip_msix_interrupt_disable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001260#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001261 pm8001_chip_intx_interrupt_disable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001262#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001263}
1264
1265/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301266 * pm8001_mpi_msg_free_get - get the free message buffer for transfer
1267 * inbound queue.
jack wangdbf9bfe2009-10-14 16:19:21 +08001268 * @circularQ: the inbound queue we want to transfer to HBA.
1269 * @messageSize: the message size of this transfer, normally it is 64 bytes
1270 * @messagePtr: the pointer to message.
1271 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301272int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ,
jack wangdbf9bfe2009-10-14 16:19:21 +08001273 u16 messageSize, void **messagePtr)
1274{
1275 u32 offset, consumer_index;
1276 struct mpi_msg_hdr *msgHeader;
1277 u8 bcCount = 1; /* only support single buffer */
1278
1279 /* Checks is the requested message size can be allocated in this queue*/
Sakthivel Kf74cf272013-02-27 20:27:43 +05301280 if (messageSize > IOMB_SIZE_SPCV) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001281 *messagePtr = NULL;
1282 return -1;
1283 }
1284
1285 /* Stores the new consumer index */
1286 consumer_index = pm8001_read_32(circularQ->ci_virt);
1287 circularQ->consumer_index = cpu_to_le32(consumer_index);
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001288 if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) ==
Santosh Nayak8270ee22012-02-26 20:14:46 +05301289 le32_to_cpu(circularQ->consumer_index)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001290 *messagePtr = NULL;
1291 return -1;
1292 }
1293 /* get memory IOMB buffer address */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301294 offset = circularQ->producer_idx * messageSize;
jack wangdbf9bfe2009-10-14 16:19:21 +08001295 /* increment to next bcCount element */
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001296 circularQ->producer_idx = (circularQ->producer_idx + bcCount)
1297 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001298 /* Adds that distance to the base of the region virtual address plus
1299 the message header size*/
1300 msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset);
1301 *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr);
1302 return 0;
1303}
1304
1305/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301306 * pm8001_mpi_build_cmd- build the message queue for transfer, update the PI to
1307 * FW to tell the fw to get this message from IOMB.
jack wangdbf9bfe2009-10-14 16:19:21 +08001308 * @pm8001_ha: our hba card information
1309 * @circularQ: the inbound queue we want to transfer to HBA.
1310 * @opCode: the operation code represents commands which LLDD and fw recognized.
1311 * @payload: the command payload of each operation command.
peter chang91a43fa2019-11-14 15:39:05 +05301312 * @nb: size in bytes of the command payload
1313 * @responseQueue: queue to interrupt on w/ command response (if any)
jack wangdbf9bfe2009-10-14 16:19:21 +08001314 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301315int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001316 struct inbound_queue_table *circularQ,
peter chang91a43fa2019-11-14 15:39:05 +05301317 u32 opCode, void *payload, size_t nb,
1318 u32 responseQueue)
jack wangdbf9bfe2009-10-14 16:19:21 +08001319{
1320 u32 Header = 0, hpriority = 0, bc = 1, category = 0x02;
jack wangdbf9bfe2009-10-14 16:19:21 +08001321 void *pMessage;
peter chang7640e1e2020-11-02 22:25:25 +05301322 unsigned long flags;
1323 int q_index = circularQ - pm8001_ha->inbnd_q_tbl;
1324 int rv = -1;
jack wangdbf9bfe2009-10-14 16:19:21 +08001325
peter chang7640e1e2020-11-02 22:25:25 +05301326 WARN_ON(q_index >= PM8001_MAX_INB_NUM);
1327 spin_lock_irqsave(&circularQ->iq_lock, flags);
1328 rv = pm8001_mpi_msg_free_get(circularQ, pm8001_ha->iomb_size,
1329 &pMessage);
1330 if (rv < 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001331 pm8001_dbg(pm8001_ha, IO, "No free mpi buffer\n");
peter chang7640e1e2020-11-02 22:25:25 +05301332 rv = -ENOMEM;
1333 goto done;
jack wangdbf9bfe2009-10-14 16:19:21 +08001334 }
peter chang91a43fa2019-11-14 15:39:05 +05301335
1336 if (nb > (pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr)))
1337 nb = pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr);
1338 memcpy(pMessage, payload, nb);
1339 if (nb + sizeof(struct mpi_msg_hdr) < pm8001_ha->iomb_size)
1340 memset(pMessage + nb, 0, pm8001_ha->iomb_size -
1341 (nb + sizeof(struct mpi_msg_hdr)));
jack wangdbf9bfe2009-10-14 16:19:21 +08001342
1343 /*Build the header*/
1344 Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24)
1345 | ((responseQueue & 0x3F) << 16)
1346 | ((category & 0xF) << 12) | (opCode & 0xFFF));
1347
1348 pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header));
1349 /*Update the PI to the firmware*/
1350 pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
1351 circularQ->pi_offset, circularQ->producer_idx);
Joe Perches1b5d2792020-11-20 15:16:09 -08001352 pm8001_dbg(pm8001_ha, DEVIO,
1353 "INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n",
1354 responseQueue, opCode, circularQ->producer_idx,
1355 circularQ->consumer_index);
peter chang7640e1e2020-11-02 22:25:25 +05301356done:
1357 spin_unlock_irqrestore(&circularQ->iq_lock, flags);
1358 return rv;
jack wangdbf9bfe2009-10-14 16:19:21 +08001359}
1360
Sakthivel Kf74cf272013-02-27 20:27:43 +05301361u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
jack wangdbf9bfe2009-10-14 16:19:21 +08001362 struct outbound_queue_table *circularQ, u8 bc)
1363{
1364 u32 producer_index;
jack_wang72d0baa2009-11-05 22:33:35 +08001365 struct mpi_msg_hdr *msgHeader;
1366 struct mpi_msg_hdr *pOutBoundMsgHeader;
1367
1368 msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr));
1369 pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301370 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack_wang72d0baa2009-11-05 22:33:35 +08001371 if (pOutBoundMsgHeader != msgHeader) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001372 pm8001_dbg(pm8001_ha, FAIL,
1373 "consumer_idx = %d msgHeader = %p\n",
1374 circularQ->consumer_idx, msgHeader);
jack_wang72d0baa2009-11-05 22:33:35 +08001375
1376 /* Update the producer index from SPC */
1377 producer_index = pm8001_read_32(circularQ->pi_virt);
1378 circularQ->producer_index = cpu_to_le32(producer_index);
Joe Perches1b5d2792020-11-20 15:16:09 -08001379 pm8001_dbg(pm8001_ha, FAIL,
1380 "consumer_idx = %d producer_index = %dmsgHeader = %p\n",
1381 circularQ->consumer_idx,
1382 circularQ->producer_index, msgHeader);
jack_wang72d0baa2009-11-05 22:33:35 +08001383 return 0;
1384 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001385 /* free the circular queue buffer elements associated with the message*/
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001386 circularQ->consumer_idx = (circularQ->consumer_idx + bc)
1387 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001388 /* update the CI of outbound queue */
1389 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset,
1390 circularQ->consumer_idx);
1391 /* Update the producer index from SPC*/
1392 producer_index = pm8001_read_32(circularQ->pi_virt);
1393 circularQ->producer_index = cpu_to_le32(producer_index);
Joe Perches1b5d2792020-11-20 15:16:09 -08001394 pm8001_dbg(pm8001_ha, IO, " CI=%d PI=%d\n",
1395 circularQ->consumer_idx, circularQ->producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001396 return 0;
1397}
1398
1399/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301400 * pm8001_mpi_msg_consume- get the MPI message from outbound queue
1401 * message table.
jack wangdbf9bfe2009-10-14 16:19:21 +08001402 * @pm8001_ha: our hba card information
1403 * @circularQ: the outbound queue table.
1404 * @messagePtr1: the message contents of this outbound message.
1405 * @pBC: the message size.
1406 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301407u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001408 struct outbound_queue_table *circularQ,
1409 void **messagePtr1, u8 *pBC)
1410{
1411 struct mpi_msg_hdr *msgHeader;
1412 __le32 msgHeader_tmp;
1413 u32 header_tmp;
1414 do {
1415 /* If there are not-yet-delivered messages ... */
Santosh Nayak8270ee22012-02-26 20:14:46 +05301416 if (le32_to_cpu(circularQ->producer_index)
1417 != circularQ->consumer_idx) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001418 /*Get the pointer to the circular queue buffer element*/
1419 msgHeader = (struct mpi_msg_hdr *)
1420 (circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301421 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack wangdbf9bfe2009-10-14 16:19:21 +08001422 /* read header */
1423 header_tmp = pm8001_read_32(msgHeader);
1424 msgHeader_tmp = cpu_to_le32(header_tmp);
Joe Perches1b5d2792020-11-20 15:16:09 -08001425 pm8001_dbg(pm8001_ha, DEVIO,
1426 "outbound opcode msgheader:%x ci=%d pi=%d\n",
1427 msgHeader_tmp, circularQ->consumer_idx,
1428 circularQ->producer_index);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301429 if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001430 if (OPC_OUB_SKIP_ENTRY !=
Santosh Nayak8270ee22012-02-26 20:14:46 +05301431 (le32_to_cpu(msgHeader_tmp) & 0xfff)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001432 *messagePtr1 =
1433 ((u8 *)msgHeader) +
1434 sizeof(struct mpi_msg_hdr);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301435 *pBC = (u8)((le32_to_cpu(msgHeader_tmp)
1436 >> 24) & 0x1f);
Joe Perches1b5d2792020-11-20 15:16:09 -08001437 pm8001_dbg(pm8001_ha, IO,
1438 ": CI=%d PI=%d msgHeader=%x\n",
1439 circularQ->consumer_idx,
1440 circularQ->producer_index,
1441 msgHeader_tmp);
jack wangdbf9bfe2009-10-14 16:19:21 +08001442 return MPI_IO_STATUS_SUCCESS;
1443 } else {
jack wangdbf9bfe2009-10-14 16:19:21 +08001444 circularQ->consumer_idx =
1445 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301446 ((le32_to_cpu(msgHeader_tmp)
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001447 >> 24) & 0x1f))
1448 % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001449 msgHeader_tmp = 0;
1450 pm8001_write_32(msgHeader, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08001451 /* update the CI of outbound queue */
1452 pm8001_cw32(pm8001_ha,
1453 circularQ->ci_pci_bar,
1454 circularQ->ci_offset,
1455 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001456 }
jack_wang72d0baa2009-11-05 22:33:35 +08001457 } else {
1458 circularQ->consumer_idx =
1459 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301460 ((le32_to_cpu(msgHeader_tmp) >> 24) &
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001461 0x1f)) % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001462 msgHeader_tmp = 0;
1463 pm8001_write_32(msgHeader, 0, 0);
1464 /* update the CI of outbound queue */
1465 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar,
1466 circularQ->ci_offset,
1467 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001468 return MPI_IO_STATUS_FAIL;
jack_wang72d0baa2009-11-05 22:33:35 +08001469 }
1470 } else {
1471 u32 producer_index;
1472 void *pi_virt = circularQ->pi_virt;
Deepak Ukey72349b62018-09-11 14:18:04 +05301473 /* spurious interrupt during setup if
1474 * kexec-ing and driver doing a doorbell access
1475 * with the pre-kexec oq interrupt setup
1476 */
1477 if (!pi_virt)
1478 break;
jack_wang72d0baa2009-11-05 22:33:35 +08001479 /* Update the producer index from SPC */
1480 producer_index = pm8001_read_32(pi_virt);
1481 circularQ->producer_index = cpu_to_le32(producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001482 }
Santosh Nayak8270ee22012-02-26 20:14:46 +05301483 } while (le32_to_cpu(circularQ->producer_index) !=
1484 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001485 /* while we don't have any more not-yet-delivered message */
1486 /* report empty */
1487 return MPI_IO_STATUS_BUSY;
1488}
1489
Sakthivel Kf74cf272013-02-27 20:27:43 +05301490void pm8001_work_fn(struct work_struct *work)
jack wangdbf9bfe2009-10-14 16:19:21 +08001491{
Tejun Heo429305e2011-01-24 14:57:29 +01001492 struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001493 struct pm8001_device *pm8001_dev;
Tejun Heo429305e2011-01-24 14:57:29 +01001494 struct domain_device *dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08001495
Mark Salyzyn5954d732012-01-17 11:52:24 -05001496 /*
1497 * So far, all users of this stash an associated structure here.
1498 * If we get here, and this pointer is null, then the action
1499 * was cancelled. This nullification happens when the device
1500 * goes away.
1501 */
1502 pm8001_dev = pw->data; /* Most stash device structure */
1503 if ((pm8001_dev == NULL)
1504 || ((pw->handler != IO_XFER_ERROR_BREAK)
James Bottomleyaa9f8322013-05-07 14:44:06 -07001505 && (pm8001_dev->dev_type == SAS_PHY_UNUSED))) {
Mark Salyzyn5954d732012-01-17 11:52:24 -05001506 kfree(pw);
1507 return;
1508 }
1509
Tejun Heo429305e2011-01-24 14:57:29 +01001510 switch (pw->handler) {
Mark Salyzyn5954d732012-01-17 11:52:24 -05001511 case IO_XFER_ERROR_BREAK:
1512 { /* This one stashes the sas_task instead */
1513 struct sas_task *t = (struct sas_task *)pm8001_dev;
1514 u32 tag;
1515 struct pm8001_ccb_info *ccb;
1516 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1517 unsigned long flags, flags1;
1518 struct task_status_struct *ts;
1519 int i;
1520
1521 if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC)
1522 break; /* Task still on lu */
1523 spin_lock_irqsave(&pm8001_ha->lock, flags);
1524
1525 spin_lock_irqsave(&t->task_state_lock, flags1);
1526 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1527 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1528 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1529 break; /* Task got completed by another */
1530 }
1531 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1532
1533 /* Search for a possible ccb that matches the task */
1534 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1535 ccb = &pm8001_ha->ccb_info[i];
1536 tag = ccb->ccb_tag;
1537 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1538 break;
1539 }
1540 if (!ccb) {
1541 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1542 break; /* Task got freed by another */
1543 }
1544 ts = &t->task_status;
1545 ts->resp = SAS_TASK_COMPLETE;
1546 /* Force the midlayer to retry */
1547 ts->stat = SAS_QUEUE_FULL;
1548 pm8001_dev = ccb->device;
1549 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301550 atomic_dec(&pm8001_dev->running_req);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001551 spin_lock_irqsave(&t->task_state_lock, flags1);
1552 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
1553 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
1554 t->task_state_flags |= SAS_TASK_STATE_DONE;
1555 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
1556 spin_unlock_irqrestore(&t->task_state_lock, flags1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001557 pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
1558 t, pw->handler, ts->resp, ts->stat);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001559 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1560 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1561 } else {
1562 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1563 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1564 mb();/* in order to force CPU ordering */
1565 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1566 t->task_done(t);
1567 }
1568 } break;
1569 case IO_XFER_OPEN_RETRY_TIMEOUT:
1570 { /* This one stashes the sas_task instead */
1571 struct sas_task *t = (struct sas_task *)pm8001_dev;
1572 u32 tag;
1573 struct pm8001_ccb_info *ccb;
1574 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1575 unsigned long flags, flags1;
1576 int i, ret = 0;
1577
Joe Perches1b5d2792020-11-20 15:16:09 -08001578 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001579
1580 ret = pm8001_query_task(t);
1581
Joe Perches1b5d2792020-11-20 15:16:09 -08001582 if (ret == TMF_RESP_FUNC_SUCC)
1583 pm8001_dbg(pm8001_ha, IO, "...Task on lu\n");
1584 else if (ret == TMF_RESP_FUNC_COMPLETE)
1585 pm8001_dbg(pm8001_ha, IO, "...Task NOT on lu\n");
1586 else
1587 pm8001_dbg(pm8001_ha, DEVIO, "...query task failed!!!\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001588
1589 spin_lock_irqsave(&pm8001_ha->lock, flags);
1590
1591 spin_lock_irqsave(&t->task_state_lock, flags1);
1592
1593 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1594 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1595 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1596 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1597 (void)pm8001_abort_task(t);
1598 break; /* Task got completed by another */
1599 }
1600
1601 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1602
1603 /* Search for a possible ccb that matches the task */
1604 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1605 ccb = &pm8001_ha->ccb_info[i];
1606 tag = ccb->ccb_tag;
1607 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1608 break;
1609 }
1610 if (!ccb) {
1611 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1612 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1613 (void)pm8001_abort_task(t);
1614 break; /* Task got freed by another */
1615 }
1616
1617 pm8001_dev = ccb->device;
1618 dev = pm8001_dev->sas_device;
1619
1620 switch (ret) {
1621 case TMF_RESP_FUNC_SUCC: /* task on lu */
1622 ccb->open_retry = 1; /* Snub completion */
1623 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1624 ret = pm8001_abort_task(t);
1625 ccb->open_retry = 0;
1626 switch (ret) {
1627 case TMF_RESP_FUNC_SUCC:
1628 case TMF_RESP_FUNC_COMPLETE:
1629 break;
1630 default: /* device misbehavior */
1631 ret = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08001632 pm8001_dbg(pm8001_ha, IO, "...Reset phy\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001633 pm8001_I_T_nexus_reset(dev);
1634 break;
1635 }
1636 break;
1637
1638 case TMF_RESP_FUNC_COMPLETE: /* task not on lu */
1639 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1640 /* Do we need to abort the task locally? */
1641 break;
1642
1643 default: /* device misbehavior */
1644 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1645 ret = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08001646 pm8001_dbg(pm8001_ha, IO, "...Reset phy\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001647 pm8001_I_T_nexus_reset(dev);
1648 }
1649
1650 if (ret == TMF_RESP_FUNC_FAILED)
1651 t = NULL;
1652 pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev);
Joe Perches1b5d2792020-11-20 15:16:09 -08001653 pm8001_dbg(pm8001_ha, IO, "...Complete\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001654 } break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001655 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
jack wangdbf9bfe2009-10-14 16:19:21 +08001656 dev = pm8001_dev->sas_device;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301657 pm8001_I_T_nexus_event_handler(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001658 break;
1659 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
jack wangdbf9bfe2009-10-14 16:19:21 +08001660 dev = pm8001_dev->sas_device;
1661 pm8001_I_T_nexus_reset(dev);
1662 break;
1663 case IO_DS_IN_ERROR:
jack wangdbf9bfe2009-10-14 16:19:21 +08001664 dev = pm8001_dev->sas_device;
1665 pm8001_I_T_nexus_reset(dev);
1666 break;
1667 case IO_DS_NON_OPERATIONAL:
jack wangdbf9bfe2009-10-14 16:19:21 +08001668 dev = pm8001_dev->sas_device;
1669 pm8001_I_T_nexus_reset(dev);
1670 break;
1671 }
Tejun Heo429305e2011-01-24 14:57:29 +01001672 kfree(pw);
jack wangdbf9bfe2009-10-14 16:19:21 +08001673}
1674
Sakthivel Kf74cf272013-02-27 20:27:43 +05301675int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
jack wangdbf9bfe2009-10-14 16:19:21 +08001676 int handler)
1677{
Tejun Heo429305e2011-01-24 14:57:29 +01001678 struct pm8001_work *pw;
jack wangdbf9bfe2009-10-14 16:19:21 +08001679 int ret = 0;
1680
Tejun Heo429305e2011-01-24 14:57:29 +01001681 pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
1682 if (pw) {
1683 pw->pm8001_ha = pm8001_ha;
1684 pw->data = data;
1685 pw->handler = handler;
1686 INIT_WORK(&pw->work, pm8001_work_fn);
1687 queue_work(pm8001_wq, &pw->work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001688 } else
1689 ret = -ENOMEM;
1690
1691 return ret;
1692}
1693
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301694static void pm8001_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1695 struct pm8001_device *pm8001_ha_dev)
1696{
1697 int res;
1698 u32 ccb_tag;
1699 struct pm8001_ccb_info *ccb;
1700 struct sas_task *task = NULL;
1701 struct task_abort_req task_abort;
1702 struct inbound_queue_table *circularQ;
1703 u32 opc = OPC_INB_SATA_ABORT;
1704 int ret;
1705
1706 if (!pm8001_ha_dev) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001707 pm8001_dbg(pm8001_ha, FAIL, "dev is null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301708 return;
1709 }
1710
1711 task = sas_alloc_slow_task(GFP_ATOMIC);
1712
1713 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001714 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301715 return;
1716 }
1717
1718 task->task_done = pm8001_task_done;
1719
1720 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1721 if (res)
1722 return;
1723
1724 ccb = &pm8001_ha->ccb_info[ccb_tag];
1725 ccb->device = pm8001_ha_dev;
1726 ccb->ccb_tag = ccb_tag;
1727 ccb->task = task;
1728
1729 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1730
1731 memset(&task_abort, 0, sizeof(task_abort));
1732 task_abort.abort_all = cpu_to_le32(1);
1733 task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1734 task_abort.tag = cpu_to_le32(ccb_tag);
1735
peter chang91a43fa2019-11-14 15:39:05 +05301736 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
1737 sizeof(task_abort), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301738 if (ret)
1739 pm8001_tag_free(pm8001_ha, ccb_tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301740
1741}
1742
1743static void pm8001_send_read_log(struct pm8001_hba_info *pm8001_ha,
1744 struct pm8001_device *pm8001_ha_dev)
1745{
1746 struct sata_start_req sata_cmd;
1747 int res;
1748 u32 ccb_tag;
1749 struct pm8001_ccb_info *ccb;
1750 struct sas_task *task = NULL;
1751 struct host_to_dev_fis fis;
1752 struct domain_device *dev;
1753 struct inbound_queue_table *circularQ;
1754 u32 opc = OPC_INB_SATA_HOST_OPSTART;
1755
1756 task = sas_alloc_slow_task(GFP_ATOMIC);
1757
1758 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001759 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301760 return;
1761 }
1762 task->task_done = pm8001_task_done;
1763
1764 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1765 if (res) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301766 sas_free_task(task);
Joe Perches1b5d2792020-11-20 15:16:09 -08001767 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate tag !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301768 return;
1769 }
1770
1771 /* allocate domain device by ourselves as libsas
1772 * is not going to provide any
1773 */
1774 dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1775 if (!dev) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301776 sas_free_task(task);
1777 pm8001_tag_free(pm8001_ha, ccb_tag);
Joe Perches1b5d2792020-11-20 15:16:09 -08001778 pm8001_dbg(pm8001_ha, FAIL,
1779 "Domain device cannot be allocated\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301780 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301781 }
Tomas Henzl5533abc2014-07-09 17:20:49 +05301782 task->dev = dev;
1783 task->dev->lldd_dev = pm8001_ha_dev;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301784
1785 ccb = &pm8001_ha->ccb_info[ccb_tag];
1786 ccb->device = pm8001_ha_dev;
1787 ccb->ccb_tag = ccb_tag;
1788 ccb->task = task;
1789 pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1790 pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1791
1792 memset(&sata_cmd, 0, sizeof(sata_cmd));
1793 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1794
1795 /* construct read log FIS */
1796 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1797 fis.fis_type = 0x27;
1798 fis.flags = 0x80;
1799 fis.command = ATA_CMD_READ_LOG_EXT;
1800 fis.lbal = 0x10;
1801 fis.sector_count = 0x1;
1802
1803 sata_cmd.tag = cpu_to_le32(ccb_tag);
1804 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1805 sata_cmd.ncqtag_atap_dir_m |= ((0x1 << 7) | (0x5 << 9));
1806 memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1807
peter chang91a43fa2019-11-14 15:39:05 +05301808 res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
1809 sizeof(sata_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301810 if (res) {
1811 sas_free_task(task);
1812 pm8001_tag_free(pm8001_ha, ccb_tag);
1813 kfree(dev);
1814 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301815}
1816
jack wangdbf9bfe2009-10-14 16:19:21 +08001817/**
1818 * mpi_ssp_completion- process the event that FW response to the SSP request.
1819 * @pm8001_ha: our hba card information
1820 * @piomb: the message contents of this outbound message.
1821 *
1822 * When FW has completed a ssp request for example a IO request, after it has
1823 * filled the SG data with the data, it will trigger this event represent
1824 * that he has finished the job,please check the coresponding buffer.
1825 * So we will tell the caller who maybe waiting the result to tell upper layer
1826 * that the task has been finished.
1827 */
jack_wang72d0baa2009-11-05 22:33:35 +08001828static void
jack wangdbf9bfe2009-10-14 16:19:21 +08001829mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
1830{
1831 struct sas_task *t;
1832 struct pm8001_ccb_info *ccb;
1833 unsigned long flags;
1834 u32 status;
1835 u32 param;
1836 u32 tag;
1837 struct ssp_completion_resp *psspPayload;
1838 struct task_status_struct *ts;
1839 struct ssp_response_iu *iu;
1840 struct pm8001_device *pm8001_dev;
1841 psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1842 status = le32_to_cpu(psspPayload->status);
1843 tag = le32_to_cpu(psspPayload->tag);
1844 ccb = &pm8001_ha->ccb_info[tag];
Mark Salyzyn5954d732012-01-17 11:52:24 -05001845 if ((status == IO_ABORTED) && ccb->open_retry) {
1846 /* Being completed by another */
1847 ccb->open_retry = 0;
1848 return;
1849 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001850 pm8001_dev = ccb->device;
1851 param = le32_to_cpu(psspPayload->param);
1852
jack wangdbf9bfe2009-10-14 16:19:21 +08001853 t = ccb->task;
1854
jack_wang72d0baa2009-11-05 22:33:35 +08001855 if (status && status != IO_UNDERFLOW)
Joe Perches1b5d2792020-11-20 15:16:09 -08001856 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08001857 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08001858 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08001859 ts = &t->task_status;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301860 /* Print sas address of IO failed device */
1861 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1862 (status != IO_UNDERFLOW))
Joe Perches1b5d2792020-11-20 15:16:09 -08001863 pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n",
1864 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301865
peter chang73706722019-11-14 15:39:02 +05301866 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08001867 pm8001_dbg(pm8001_ha, IOERR,
1868 "status:0x%x, tag:0x%x, task:0x%p\n",
1869 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05301870
jack wangdbf9bfe2009-10-14 16:19:21 +08001871 switch (status) {
1872 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001873 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS,param = %d\n",
1874 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08001875 if (param == 0) {
1876 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05001877 ts->stat = SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08001878 } else {
1879 ts->resp = SAS_TASK_COMPLETE;
1880 ts->stat = SAS_PROTO_RESPONSE;
1881 ts->residual = param;
1882 iu = &psspPayload->ssp_resp_iu;
1883 sas_ssp_task_response(pm8001_ha->dev, t, iu);
1884 }
1885 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301886 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001887 break;
1888 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001889 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001890 ts->resp = SAS_TASK_COMPLETE;
1891 ts->stat = SAS_ABORTED_TASK;
1892 break;
1893 case IO_UNDERFLOW:
1894 /* SSP Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08001895 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW,param = %d\n",
1896 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08001897 ts->resp = SAS_TASK_COMPLETE;
1898 ts->stat = SAS_DATA_UNDERRUN;
1899 ts->residual = param;
1900 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301901 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001902 break;
1903 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08001904 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001905 ts->resp = SAS_TASK_UNDELIVERED;
1906 ts->stat = SAS_PHY_DOWN;
1907 break;
1908 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001909 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001910 ts->resp = SAS_TASK_COMPLETE;
1911 ts->stat = SAS_OPEN_REJECT;
Mark Salyzyn5954d732012-01-17 11:52:24 -05001912 /* Force the midlayer to retry */
1913 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001914 break;
1915 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08001916 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001917 ts->resp = SAS_TASK_COMPLETE;
1918 ts->stat = SAS_OPEN_REJECT;
1919 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1920 break;
1921 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001922 pm8001_dbg(pm8001_ha, IO,
1923 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001924 ts->resp = SAS_TASK_COMPLETE;
1925 ts->stat = SAS_OPEN_REJECT;
1926 ts->open_rej_reason = SAS_OREJ_EPROTO;
1927 break;
1928 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08001929 pm8001_dbg(pm8001_ha, IO,
1930 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001931 ts->resp = SAS_TASK_COMPLETE;
1932 ts->stat = SAS_OPEN_REJECT;
1933 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1934 break;
1935 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001936 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001937 ts->resp = SAS_TASK_COMPLETE;
1938 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08001939 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001940 break;
1941 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001942 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001943 ts->resp = SAS_TASK_COMPLETE;
1944 ts->stat = SAS_OPEN_REJECT;
1945 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1946 if (!t->uldd_task)
1947 pm8001_handle_event(pm8001_ha,
1948 pm8001_dev,
1949 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
1950 break;
1951 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08001952 pm8001_dbg(pm8001_ha, IO,
1953 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001954 ts->resp = SAS_TASK_COMPLETE;
1955 ts->stat = SAS_OPEN_REJECT;
1956 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
1957 break;
1958 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001959 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001960 ts->resp = SAS_TASK_COMPLETE;
1961 ts->stat = SAS_OPEN_REJECT;
1962 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
1963 break;
1964 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08001965 pm8001_dbg(pm8001_ha, IO,
1966 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001967 ts->resp = SAS_TASK_UNDELIVERED;
1968 ts->stat = SAS_OPEN_REJECT;
1969 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
1970 break;
1971 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001972 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001973 ts->resp = SAS_TASK_COMPLETE;
1974 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08001975 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001976 break;
1977 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08001978 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001979 ts->resp = SAS_TASK_COMPLETE;
1980 ts->stat = SAS_NAK_R_ERR;
1981 break;
1982 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08001983 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001984 ts->resp = SAS_TASK_COMPLETE;
1985 ts->stat = SAS_OPEN_REJECT;
1986 break;
1987 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08001988 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001989 ts->resp = SAS_TASK_COMPLETE;
1990 ts->stat = SAS_OPEN_REJECT;
1991 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1992 break;
1993 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08001994 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001995 ts->resp = SAS_TASK_COMPLETE;
1996 ts->stat = SAS_OPEN_REJECT;
1997 break;
1998 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08001999 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002000 ts->resp = SAS_TASK_COMPLETE;
2001 ts->stat = SAS_OPEN_REJECT;
2002 break;
2003 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002004 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002005 ts->resp = SAS_TASK_COMPLETE;
2006 ts->stat = SAS_OPEN_REJECT;
2007 if (!t->uldd_task)
2008 pm8001_handle_event(pm8001_ha,
2009 pm8001_dev,
2010 IO_DS_NON_OPERATIONAL);
2011 break;
2012 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002013 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002014 ts->resp = SAS_TASK_COMPLETE;
2015 ts->stat = SAS_OPEN_REJECT;
2016 break;
2017 case IO_TM_TAG_NOT_FOUND:
Joe Perches1b5d2792020-11-20 15:16:09 -08002018 pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002019 ts->resp = SAS_TASK_COMPLETE;
2020 ts->stat = SAS_OPEN_REJECT;
2021 break;
2022 case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002023 pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002024 ts->resp = SAS_TASK_COMPLETE;
2025 ts->stat = SAS_OPEN_REJECT;
2026 break;
2027 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002028 pm8001_dbg(pm8001_ha, IO,
2029 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002030 ts->resp = SAS_TASK_COMPLETE;
2031 ts->stat = SAS_OPEN_REJECT;
2032 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07002033 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002034 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002035 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002036 /* not allowed case. Therefore, return failed status */
2037 ts->resp = SAS_TASK_COMPLETE;
2038 ts->stat = SAS_OPEN_REJECT;
2039 break;
2040 }
Joe Perches1b5d2792020-11-20 15:16:09 -08002041 pm8001_dbg(pm8001_ha, IO, "scsi_status = %x\n",
2042 psspPayload->ssp_resp_iu.status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002043 spin_lock_irqsave(&t->task_state_lock, flags);
2044 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2045 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2046 t->task_state_flags |= SAS_TASK_STATE_DONE;
2047 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2048 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002049 pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2050 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002051 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2052 } else {
2053 spin_unlock_irqrestore(&t->task_state_lock, flags);
2054 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2055 mb();/* in order to force CPU ordering */
2056 t->task_done(t);
2057 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002058}
2059
2060/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002061static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002062{
2063 struct sas_task *t;
2064 unsigned long flags;
2065 struct task_status_struct *ts;
2066 struct pm8001_ccb_info *ccb;
2067 struct pm8001_device *pm8001_dev;
2068 struct ssp_event_resp *psspPayload =
2069 (struct ssp_event_resp *)(piomb + 4);
2070 u32 event = le32_to_cpu(psspPayload->event);
2071 u32 tag = le32_to_cpu(psspPayload->tag);
2072 u32 port_id = le32_to_cpu(psspPayload->port_id);
2073 u32 dev_id = le32_to_cpu(psspPayload->device_id);
2074
2075 ccb = &pm8001_ha->ccb_info[tag];
2076 t = ccb->task;
2077 pm8001_dev = ccb->device;
2078 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002079 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002080 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002081 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002082 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002083 pm8001_dbg(pm8001_ha, DEVIO, "port_id = %x,device_id = %x\n",
2084 port_id, dev_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08002085 switch (event) {
2086 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002087 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002088 ts->resp = SAS_TASK_COMPLETE;
2089 ts->stat = SAS_DATA_OVERRUN;
2090 ts->residual = 0;
2091 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302092 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002093 break;
2094 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002095 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05002096 pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2097 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002098 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002099 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002100 ts->resp = SAS_TASK_COMPLETE;
2101 ts->stat = SAS_OPEN_REJECT;
2102 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2103 break;
2104 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002105 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002106 ts->resp = SAS_TASK_COMPLETE;
2107 ts->stat = SAS_OPEN_REJECT;
2108 ts->open_rej_reason = SAS_OREJ_EPROTO;
2109 break;
2110 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002111 pm8001_dbg(pm8001_ha, IO,
2112 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002113 ts->resp = SAS_TASK_COMPLETE;
2114 ts->stat = SAS_OPEN_REJECT;
2115 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2116 break;
2117 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002118 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002119 ts->resp = SAS_TASK_COMPLETE;
2120 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002121 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002122 break;
2123 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002124 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002125 ts->resp = SAS_TASK_COMPLETE;
2126 ts->stat = SAS_OPEN_REJECT;
2127 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2128 if (!t->uldd_task)
2129 pm8001_handle_event(pm8001_ha,
2130 pm8001_dev,
2131 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2132 break;
2133 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002134 pm8001_dbg(pm8001_ha, IO,
2135 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002136 ts->resp = SAS_TASK_COMPLETE;
2137 ts->stat = SAS_OPEN_REJECT;
2138 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2139 break;
2140 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002141 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002142 ts->resp = SAS_TASK_COMPLETE;
2143 ts->stat = SAS_OPEN_REJECT;
2144 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2145 break;
2146 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002147 pm8001_dbg(pm8001_ha, IO,
2148 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002149 ts->resp = SAS_TASK_COMPLETE;
2150 ts->stat = SAS_OPEN_REJECT;
2151 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2152 break;
2153 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002154 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002155 ts->resp = SAS_TASK_COMPLETE;
2156 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002157 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002158 break;
2159 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002160 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002161 ts->resp = SAS_TASK_COMPLETE;
2162 ts->stat = SAS_NAK_R_ERR;
2163 break;
2164 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002165 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05002166 pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2167 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002168 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002169 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002170 ts->resp = SAS_TASK_COMPLETE;
2171 ts->stat = SAS_DATA_OVERRUN;
2172 break;
2173 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002174 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002175 ts->resp = SAS_TASK_COMPLETE;
2176 ts->stat = SAS_DATA_OVERRUN;
2177 break;
2178 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002179 pm8001_dbg(pm8001_ha, IO,
2180 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002181 ts->resp = SAS_TASK_COMPLETE;
2182 ts->stat = SAS_DATA_OVERRUN;
2183 break;
2184 case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002185 pm8001_dbg(pm8001_ha, IO,
2186 "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002187 ts->resp = SAS_TASK_COMPLETE;
2188 ts->stat = SAS_DATA_OVERRUN;
2189 break;
2190 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002191 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002192 ts->resp = SAS_TASK_COMPLETE;
2193 ts->stat = SAS_DATA_OVERRUN;
2194 break;
2195 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002196 pm8001_dbg(pm8001_ha, IO,
2197 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002198 ts->resp = SAS_TASK_COMPLETE;
2199 ts->stat = SAS_DATA_OVERRUN;
2200 break;
2201 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002202 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
jack_wang72d0baa2009-11-05 22:33:35 +08002203 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002204 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002205 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002206 /* not allowed case. Therefore, return failed status */
2207 ts->resp = SAS_TASK_COMPLETE;
2208 ts->stat = SAS_DATA_OVERRUN;
2209 break;
2210 }
2211 spin_lock_irqsave(&t->task_state_lock, flags);
2212 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2213 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2214 t->task_state_flags |= SAS_TASK_STATE_DONE;
2215 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2216 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002217 pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2218 t, event, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002219 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2220 } else {
2221 spin_unlock_irqrestore(&t->task_state_lock, flags);
2222 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2223 mb();/* in order to force CPU ordering */
2224 t->task_done(t);
2225 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002226}
2227
2228/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002229static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002230mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2231{
2232 struct sas_task *t;
2233 struct pm8001_ccb_info *ccb;
jack wangdbf9bfe2009-10-14 16:19:21 +08002234 u32 param;
2235 u32 status;
2236 u32 tag;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302237 int i, j;
2238 u8 sata_addr_low[4];
2239 u32 temp_sata_addr_low;
2240 u8 sata_addr_hi[4];
2241 u32 temp_sata_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +08002242 struct sata_completion_resp *psataPayload;
2243 struct task_status_struct *ts;
2244 struct ata_task_resp *resp ;
2245 u32 *sata_resp;
2246 struct pm8001_device *pm8001_dev;
Santosh Nayakb08c1852012-03-09 13:43:38 +05302247 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002248
2249 psataPayload = (struct sata_completion_resp *)(piomb + 4);
2250 status = le32_to_cpu(psataPayload->status);
2251 tag = le32_to_cpu(psataPayload->tag);
2252
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302253 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002254 pm8001_dbg(pm8001_ha, FAIL, "tag null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302255 return;
2256 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002257 ccb = &pm8001_ha->ccb_info[tag];
2258 param = le32_to_cpu(psataPayload->param);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302259 if (ccb) {
2260 t = ccb->task;
2261 pm8001_dev = ccb->device;
2262 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002263 pm8001_dbg(pm8001_ha, FAIL, "ccb null\n");
jack_wang72d0baa2009-11-05 22:33:35 +08002264 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302265 }
2266
2267 if (t) {
2268 if (t->dev && (t->dev->lldd_dev))
2269 pm8001_dev = t->dev->lldd_dev;
2270 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002271 pm8001_dbg(pm8001_ha, FAIL, "task null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302272 return;
2273 }
2274
2275 if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2276 && unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002277 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302278 return;
2279 }
2280
2281 ts = &t->task_status;
2282 if (!ts) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002283 pm8001_dbg(pm8001_ha, FAIL, "ts null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302284 return;
2285 }
peter chang73706722019-11-14 15:39:02 +05302286
2287 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08002288 pm8001_dbg(pm8001_ha, IOERR,
2289 "status:0x%x, tag:0x%x, task::0x%p\n",
2290 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302291
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302292 /* Print sas address of IO failed device */
2293 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2294 (status != IO_UNDERFLOW)) {
2295 if (!((t->dev->parent) &&
John Garry924a3542019-06-10 20:41:41 +08002296 (dev_is_expander(t->dev->parent->dev_type)))) {
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302297 for (i = 0 , j = 4; j <= 7 && i <= 3; i++ , j++)
2298 sata_addr_low[i] = pm8001_ha->sas_addr[j];
2299 for (i = 0 , j = 0; j <= 3 && i <= 3; i++ , j++)
2300 sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2301 memcpy(&temp_sata_addr_low, sata_addr_low,
2302 sizeof(sata_addr_low));
2303 memcpy(&temp_sata_addr_hi, sata_addr_hi,
2304 sizeof(sata_addr_hi));
2305 temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2306 |((temp_sata_addr_hi << 8) &
2307 0xff0000) |
2308 ((temp_sata_addr_hi >> 8)
2309 & 0xff00) |
2310 ((temp_sata_addr_hi << 24) &
2311 0xff000000));
2312 temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2313 & 0xff) |
2314 ((temp_sata_addr_low << 8)
2315 & 0xff0000) |
2316 ((temp_sata_addr_low >> 8)
2317 & 0xff00) |
2318 ((temp_sata_addr_low << 24)
2319 & 0xff000000)) +
2320 pm8001_dev->attached_phy +
2321 0x10);
Joe Perches1b5d2792020-11-20 15:16:09 -08002322 pm8001_dbg(pm8001_ha, FAIL,
2323 "SAS Address of IO Failure Drive:%08x%08x\n",
2324 temp_sata_addr_hi,
2325 temp_sata_addr_low);
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302326 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002327 pm8001_dbg(pm8001_ha, FAIL,
2328 "SAS Address of IO Failure Drive:%016llx\n",
2329 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302330 }
2331 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002332 switch (status) {
2333 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002334 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002335 if (param == 0) {
2336 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05002337 ts->stat = SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302338 /* check if response is for SEND READ LOG */
2339 if (pm8001_dev &&
2340 (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2341 /* set new bit for abort_all */
2342 pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2343 /* clear bit for read log */
2344 pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2345 pm8001_send_abort_all(pm8001_ha, pm8001_dev);
2346 /* Free the tag */
2347 pm8001_tag_free(pm8001_ha, tag);
2348 sas_free_task(t);
2349 return;
2350 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002351 } else {
2352 u8 len;
2353 ts->resp = SAS_TASK_COMPLETE;
2354 ts->stat = SAS_PROTO_RESPONSE;
2355 ts->residual = param;
Joe Perches1b5d2792020-11-20 15:16:09 -08002356 pm8001_dbg(pm8001_ha, IO,
2357 "SAS_PROTO_RESPONSE len = %d\n",
2358 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002359 sata_resp = &psataPayload->sata_resp[0];
2360 resp = (struct ata_task_resp *)ts->buf;
2361 if (t->ata_task.dma_xfer == 0 &&
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02002362 t->data_dir == DMA_FROM_DEVICE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08002363 len = sizeof(struct pio_setup_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002364 pm8001_dbg(pm8001_ha, IO,
2365 "PIO read len = %d\n", len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002366 } else if (t->ata_task.use_ncq) {
2367 len = sizeof(struct set_dev_bits_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002368 pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n",
2369 len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002370 } else {
2371 len = sizeof(struct dev_to_host_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002372 pm8001_dbg(pm8001_ha, IO, "other len = %d\n",
2373 len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002374 }
2375 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2376 resp->frame_len = len;
2377 memcpy(&resp->ending_fis[0], sata_resp, len);
2378 ts->buf_valid_size = sizeof(*resp);
2379 } else
Joe Perches1b5d2792020-11-20 15:16:09 -08002380 pm8001_dbg(pm8001_ha, IO,
2381 "response too large\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002382 }
2383 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302384 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002385 break;
2386 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002387 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002388 ts->resp = SAS_TASK_COMPLETE;
2389 ts->stat = SAS_ABORTED_TASK;
2390 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302391 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002392 break;
2393 /* following cases are to do cases */
2394 case IO_UNDERFLOW:
2395 /* SATA Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08002396 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002397 ts->resp = SAS_TASK_COMPLETE;
2398 ts->stat = SAS_DATA_UNDERRUN;
2399 ts->residual = param;
2400 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302401 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002402 break;
2403 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002404 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002405 ts->resp = SAS_TASK_UNDELIVERED;
2406 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302407 if (pm8001_dev)
2408 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002409 break;
2410 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002411 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002412 ts->resp = SAS_TASK_COMPLETE;
2413 ts->stat = SAS_INTERRUPTED;
Viswas G4a2efd42020-11-02 22:25:26 +05302414 if (pm8001_dev)
2415 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002416 break;
2417 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002418 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002419 ts->resp = SAS_TASK_COMPLETE;
2420 ts->stat = SAS_OPEN_REJECT;
2421 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302422 if (pm8001_dev)
2423 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002424 break;
2425 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002426 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002427 ts->resp = SAS_TASK_COMPLETE;
2428 ts->stat = SAS_OPEN_REJECT;
2429 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302430 if (pm8001_dev)
2431 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002432 break;
2433 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002434 pm8001_dbg(pm8001_ha, IO,
2435 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002436 ts->resp = SAS_TASK_COMPLETE;
2437 ts->stat = SAS_OPEN_REJECT;
2438 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302439 if (pm8001_dev)
2440 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002441 break;
2442 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002443 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002444 ts->resp = SAS_TASK_COMPLETE;
2445 ts->stat = SAS_OPEN_REJECT;
2446 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
Viswas G4a2efd42020-11-02 22:25:26 +05302447 if (pm8001_dev)
2448 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002449 break;
2450 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002451 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002452 ts->resp = SAS_TASK_COMPLETE;
2453 ts->stat = SAS_DEV_NO_RESPONSE;
2454 if (!t->uldd_task) {
2455 pm8001_handle_event(pm8001_ha,
2456 pm8001_dev,
2457 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2458 ts->resp = SAS_TASK_UNDELIVERED;
2459 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302460 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002461 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002462 }
2463 break;
2464 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002465 pm8001_dbg(pm8001_ha, IO,
2466 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002467 ts->resp = SAS_TASK_UNDELIVERED;
2468 ts->stat = SAS_OPEN_REJECT;
2469 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2470 if (!t->uldd_task) {
2471 pm8001_handle_event(pm8001_ha,
2472 pm8001_dev,
2473 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2474 ts->resp = SAS_TASK_UNDELIVERED;
2475 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302476 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002477 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002478 }
2479 break;
2480 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002481 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002482 ts->resp = SAS_TASK_COMPLETE;
2483 ts->stat = SAS_OPEN_REJECT;
2484 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302485 if (pm8001_dev)
2486 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002487 break;
2488 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002489 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002490 ts->resp = SAS_TASK_COMPLETE;
2491 ts->stat = SAS_DEV_NO_RESPONSE;
2492 if (!t->uldd_task) {
2493 pm8001_handle_event(pm8001_ha,
2494 pm8001_dev,
2495 IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2496 ts->resp = SAS_TASK_UNDELIVERED;
2497 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302498 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002499 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002500 }
2501 break;
2502 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002503 pm8001_dbg(pm8001_ha, IO,
2504 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002505 ts->resp = SAS_TASK_COMPLETE;
2506 ts->stat = SAS_OPEN_REJECT;
2507 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302508 if (pm8001_dev)
2509 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002510 break;
2511 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002512 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002513 ts->resp = SAS_TASK_COMPLETE;
2514 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302515 if (pm8001_dev)
2516 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002517 break;
2518 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002519 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002520 ts->resp = SAS_TASK_COMPLETE;
2521 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302522 if (pm8001_dev)
2523 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002524 break;
2525 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002526 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002527 ts->resp = SAS_TASK_COMPLETE;
2528 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05302529 if (pm8001_dev)
2530 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002531 break;
2532 case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002533 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002534 ts->resp = SAS_TASK_UNDELIVERED;
2535 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302536 if (pm8001_dev)
2537 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002538 break;
2539 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002540 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002541 ts->resp = SAS_TASK_COMPLETE;
2542 ts->stat = SAS_DATA_UNDERRUN;
Viswas G4a2efd42020-11-02 22:25:26 +05302543 if (pm8001_dev)
2544 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002545 break;
2546 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002547 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002548 ts->resp = SAS_TASK_COMPLETE;
2549 ts->stat = SAS_OPEN_TO;
Viswas G4a2efd42020-11-02 22:25:26 +05302550 if (pm8001_dev)
2551 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002552 break;
2553 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002554 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002555 ts->resp = SAS_TASK_COMPLETE;
2556 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302557 if (pm8001_dev)
2558 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002559 break;
2560 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002561 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002562 ts->resp = SAS_TASK_COMPLETE;
2563 ts->stat = SAS_DEV_NO_RESPONSE;
2564 if (!t->uldd_task) {
2565 pm8001_handle_event(pm8001_ha, pm8001_dev,
2566 IO_DS_NON_OPERATIONAL);
2567 ts->resp = SAS_TASK_UNDELIVERED;
2568 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302569 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002570 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002571 }
2572 break;
2573 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002574 pm8001_dbg(pm8001_ha, IO, " IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002575 ts->resp = SAS_TASK_COMPLETE;
2576 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302577 if (pm8001_dev)
2578 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002579 break;
2580 case IO_DS_IN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002581 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002582 ts->resp = SAS_TASK_COMPLETE;
2583 ts->stat = SAS_DEV_NO_RESPONSE;
2584 if (!t->uldd_task) {
2585 pm8001_handle_event(pm8001_ha, pm8001_dev,
2586 IO_DS_IN_ERROR);
2587 ts->resp = SAS_TASK_UNDELIVERED;
2588 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302589 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002590 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002591 }
2592 break;
2593 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002594 pm8001_dbg(pm8001_ha, IO,
2595 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002596 ts->resp = SAS_TASK_COMPLETE;
2597 ts->stat = SAS_OPEN_REJECT;
2598 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302599 if (pm8001_dev)
2600 atomic_dec(&pm8001_dev->running_req);
Johannes Thumshirn50acde82015-08-17 15:52:32 +02002601 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002602 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002603 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002604 /* not allowed case. Therefore, return failed status */
2605 ts->resp = SAS_TASK_COMPLETE;
2606 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302607 if (pm8001_dev)
2608 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002609 break;
2610 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302611 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002612 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2613 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2614 t->task_state_flags |= SAS_TASK_STATE_DONE;
2615 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302616 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002617 pm8001_dbg(pm8001_ha, FAIL,
2618 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2619 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002620 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302621 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302622 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302623 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002624 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002625}
2626
2627/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002628static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002629{
2630 struct sas_task *t;
jack wangdbf9bfe2009-10-14 16:19:21 +08002631 struct task_status_struct *ts;
2632 struct pm8001_ccb_info *ccb;
2633 struct pm8001_device *pm8001_dev;
2634 struct sata_event_resp *psataPayload =
2635 (struct sata_event_resp *)(piomb + 4);
2636 u32 event = le32_to_cpu(psataPayload->event);
2637 u32 tag = le32_to_cpu(psataPayload->tag);
2638 u32 port_id = le32_to_cpu(psataPayload->port_id);
2639 u32 dev_id = le32_to_cpu(psataPayload->device_id);
Santosh Nayakb08c1852012-03-09 13:43:38 +05302640 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002641
2642 ccb = &pm8001_ha->ccb_info[tag];
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302643
2644 if (ccb) {
2645 t = ccb->task;
2646 pm8001_dev = ccb->device;
2647 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002648 pm8001_dbg(pm8001_ha, FAIL, "No CCB !!!. returning\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302649 }
2650 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002651 pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302652
2653 /* Check if this is NCQ error */
2654 if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2655 /* find device using device id */
2656 pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2657 /* send read log extension */
2658 if (pm8001_dev)
2659 pm8001_send_read_log(pm8001_ha, pm8001_dev);
2660 return;
2661 }
2662
2663 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002664 t = ccb->task;
2665 pm8001_dev = ccb->device;
2666 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002667 pm8001_dbg(pm8001_ha, FAIL, "sata IO status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002668 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002669 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002670 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002671 pm8001_dbg(pm8001_ha, DEVIO,
2672 "port_id:0x%x, device_id:0x%x, tag:0x%x, event:0x%x\n",
2673 port_id, dev_id, tag, event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002674 switch (event) {
2675 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002676 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002677 ts->resp = SAS_TASK_COMPLETE;
2678 ts->stat = SAS_DATA_OVERRUN;
2679 ts->residual = 0;
2680 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302681 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002682 break;
2683 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002684 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002685 ts->resp = SAS_TASK_COMPLETE;
2686 ts->stat = SAS_INTERRUPTED;
2687 break;
2688 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002689 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002690 ts->resp = SAS_TASK_COMPLETE;
2691 ts->stat = SAS_OPEN_REJECT;
2692 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2693 break;
2694 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002695 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002696 ts->resp = SAS_TASK_COMPLETE;
2697 ts->stat = SAS_OPEN_REJECT;
2698 ts->open_rej_reason = SAS_OREJ_EPROTO;
2699 break;
2700 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002701 pm8001_dbg(pm8001_ha, IO,
2702 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002703 ts->resp = SAS_TASK_COMPLETE;
2704 ts->stat = SAS_OPEN_REJECT;
2705 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2706 break;
2707 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002708 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002709 ts->resp = SAS_TASK_COMPLETE;
2710 ts->stat = SAS_OPEN_REJECT;
2711 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2712 break;
2713 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002714 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002715 ts->resp = SAS_TASK_UNDELIVERED;
2716 ts->stat = SAS_DEV_NO_RESPONSE;
2717 if (!t->uldd_task) {
2718 pm8001_handle_event(pm8001_ha,
2719 pm8001_dev,
2720 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2721 ts->resp = SAS_TASK_COMPLETE;
2722 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302723 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002724 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002725 }
2726 break;
2727 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002728 pm8001_dbg(pm8001_ha, IO,
2729 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002730 ts->resp = SAS_TASK_UNDELIVERED;
2731 ts->stat = SAS_OPEN_REJECT;
2732 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2733 break;
2734 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002735 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002736 ts->resp = SAS_TASK_COMPLETE;
2737 ts->stat = SAS_OPEN_REJECT;
2738 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2739 break;
2740 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002741 pm8001_dbg(pm8001_ha, IO,
2742 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002743 ts->resp = SAS_TASK_COMPLETE;
2744 ts->stat = SAS_OPEN_REJECT;
2745 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2746 break;
2747 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002748 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002749 ts->resp = SAS_TASK_COMPLETE;
2750 ts->stat = SAS_NAK_R_ERR;
2751 break;
2752 case IO_XFER_ERROR_PEER_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002753 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002754 ts->resp = SAS_TASK_COMPLETE;
2755 ts->stat = SAS_NAK_R_ERR;
2756 break;
2757 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002758 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002759 ts->resp = SAS_TASK_COMPLETE;
2760 ts->stat = SAS_DATA_UNDERRUN;
2761 break;
2762 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002763 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002764 ts->resp = SAS_TASK_COMPLETE;
2765 ts->stat = SAS_OPEN_TO;
2766 break;
2767 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002768 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002769 ts->resp = SAS_TASK_COMPLETE;
2770 ts->stat = SAS_OPEN_TO;
2771 break;
2772 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002773 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002774 ts->resp = SAS_TASK_COMPLETE;
2775 ts->stat = SAS_OPEN_TO;
2776 break;
2777 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002778 pm8001_dbg(pm8001_ha, IO,
2779 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002780 ts->resp = SAS_TASK_COMPLETE;
2781 ts->stat = SAS_OPEN_TO;
2782 break;
2783 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002784 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002785 ts->resp = SAS_TASK_COMPLETE;
2786 ts->stat = SAS_OPEN_TO;
2787 break;
2788 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002789 pm8001_dbg(pm8001_ha, IO,
2790 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002791 ts->resp = SAS_TASK_COMPLETE;
2792 ts->stat = SAS_OPEN_TO;
2793 break;
2794 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002795 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002796 break;
2797 case IO_XFER_PIO_SETUP_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002798 pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002799 ts->resp = SAS_TASK_COMPLETE;
2800 ts->stat = SAS_OPEN_TO;
2801 break;
2802 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002803 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002804 /* not allowed case. Therefore, return failed status */
2805 ts->resp = SAS_TASK_COMPLETE;
2806 ts->stat = SAS_OPEN_TO;
2807 break;
2808 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302809 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002810 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2811 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2812 t->task_state_flags |= SAS_TASK_STATE_DONE;
2813 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302814 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002815 pm8001_dbg(pm8001_ha, FAIL,
2816 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2817 t, event, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002818 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302819 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302820 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302821 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002822 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002823}
2824
2825/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002826static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002827mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2828{
jack wangdbf9bfe2009-10-14 16:19:21 +08002829 struct sas_task *t;
2830 struct pm8001_ccb_info *ccb;
2831 unsigned long flags;
2832 u32 status;
2833 u32 tag;
2834 struct smp_completion_resp *psmpPayload;
2835 struct task_status_struct *ts;
2836 struct pm8001_device *pm8001_dev;
2837
2838 psmpPayload = (struct smp_completion_resp *)(piomb + 4);
2839 status = le32_to_cpu(psmpPayload->status);
2840 tag = le32_to_cpu(psmpPayload->tag);
2841
2842 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002843 t = ccb->task;
2844 ts = &t->task_status;
2845 pm8001_dev = ccb->device;
peter chang73706722019-11-14 15:39:02 +05302846 if (status) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002847 pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status);
2848 pm8001_dbg(pm8001_ha, IOERR,
2849 "status:0x%x, tag:0x%x, task:0x%p\n",
2850 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302851 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002852 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002853 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002854
2855 switch (status) {
2856 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002857 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002858 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05002859 ts->stat = SAM_STAT_GOOD;
Colin Ian King9e2a07e2019-03-17 18:15:32 +00002860 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302861 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002862 break;
2863 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002864 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002865 ts->resp = SAS_TASK_COMPLETE;
2866 ts->stat = SAS_ABORTED_TASK;
2867 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302868 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002869 break;
2870 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002871 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002872 ts->resp = SAS_TASK_COMPLETE;
2873 ts->stat = SAS_DATA_OVERRUN;
2874 ts->residual = 0;
2875 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302876 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002877 break;
2878 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002879 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002880 ts->resp = SAS_TASK_COMPLETE;
2881 ts->stat = SAS_PHY_DOWN;
2882 break;
2883 case IO_ERROR_HW_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002884 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002885 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05002886 ts->stat = SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002887 break;
2888 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002889 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002890 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05002891 ts->stat = SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002892 break;
2893 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002894 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002895 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05002896 ts->stat = SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002897 break;
2898 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002899 pm8001_dbg(pm8001_ha, IO,
2900 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002901 ts->resp = SAS_TASK_COMPLETE;
2902 ts->stat = SAS_OPEN_REJECT;
2903 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2904 break;
2905 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002906 pm8001_dbg(pm8001_ha, IO,
2907 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002908 ts->resp = SAS_TASK_COMPLETE;
2909 ts->stat = SAS_OPEN_REJECT;
2910 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2911 break;
2912 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002913 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002914 ts->resp = SAS_TASK_COMPLETE;
2915 ts->stat = SAS_OPEN_REJECT;
2916 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2917 break;
2918 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002919 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002920 ts->resp = SAS_TASK_COMPLETE;
2921 ts->stat = SAS_OPEN_REJECT;
2922 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2923 pm8001_handle_event(pm8001_ha,
2924 pm8001_dev,
2925 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2926 break;
2927 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002928 pm8001_dbg(pm8001_ha, IO,
2929 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002930 ts->resp = SAS_TASK_COMPLETE;
2931 ts->stat = SAS_OPEN_REJECT;
2932 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2933 break;
2934 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002935 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002936 ts->resp = SAS_TASK_COMPLETE;
2937 ts->stat = SAS_OPEN_REJECT;
2938 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2939 break;
2940 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002941 pm8001_dbg(pm8001_ha, IO,
2942 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002943 ts->resp = SAS_TASK_COMPLETE;
2944 ts->stat = SAS_OPEN_REJECT;
2945 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2946 break;
2947 case IO_XFER_ERROR_RX_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08002948 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002949 ts->resp = SAS_TASK_COMPLETE;
2950 ts->stat = SAS_DEV_NO_RESPONSE;
2951 break;
2952 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002953 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002954 ts->resp = SAS_TASK_COMPLETE;
2955 ts->stat = SAS_OPEN_REJECT;
2956 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2957 break;
2958 case IO_ERROR_INTERNAL_SMP_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002959 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002960 ts->resp = SAS_TASK_COMPLETE;
2961 ts->stat = SAS_QUEUE_FULL;
2962 break;
2963 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002964 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002965 ts->resp = SAS_TASK_COMPLETE;
2966 ts->stat = SAS_OPEN_REJECT;
2967 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2968 break;
2969 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002970 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002971 ts->resp = SAS_TASK_COMPLETE;
2972 ts->stat = SAS_DEV_NO_RESPONSE;
2973 break;
2974 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002975 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002976 ts->resp = SAS_TASK_COMPLETE;
2977 ts->stat = SAS_OPEN_REJECT;
2978 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2979 break;
2980 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002981 pm8001_dbg(pm8001_ha, IO,
2982 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002983 ts->resp = SAS_TASK_COMPLETE;
2984 ts->stat = SAS_OPEN_REJECT;
2985 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2986 break;
2987 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002988 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002989 ts->resp = SAS_TASK_COMPLETE;
2990 ts->stat = SAS_DEV_NO_RESPONSE;
2991 /* not allowed case. Therefore, return failed status */
2992 break;
2993 }
2994 spin_lock_irqsave(&t->task_state_lock, flags);
2995 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2996 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2997 t->task_state_flags |= SAS_TASK_STATE_DONE;
2998 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2999 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08003000 pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
3001 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08003002 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3003 } else {
3004 spin_unlock_irqrestore(&t->task_state_lock, flags);
3005 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3006 mb();/* in order to force CPU ordering */
3007 t->task_done(t);
3008 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003009}
3010
Sakthivel Kf74cf272013-02-27 20:27:43 +05303011void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha,
3012 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003013{
3014 struct set_dev_state_resp *pPayload =
3015 (struct set_dev_state_resp *)(piomb + 4);
3016 u32 tag = le32_to_cpu(pPayload->tag);
3017 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3018 struct pm8001_device *pm8001_dev = ccb->device;
3019 u32 status = le32_to_cpu(pPayload->status);
3020 u32 device_id = le32_to_cpu(pPayload->device_id);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05303021 u8 pds = le32_to_cpu(pPayload->pds_nds) & PDS_BITS;
3022 u8 nds = le32_to_cpu(pPayload->pds_nds) & NDS_BITS;
Joe Perches1b5d2792020-11-20 15:16:09 -08003023 pm8001_dbg(pm8001_ha, MSG, "Set device id = 0x%x state from 0x%x to 0x%x status = 0x%x!\n",
3024 device_id, pds, nds, status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003025 complete(pm8001_dev->setds_completion);
3026 ccb->task = NULL;
3027 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303028 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003029}
3030
Sakthivel Kf74cf272013-02-27 20:27:43 +05303031void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003032{
3033 struct get_nvm_data_resp *pPayload =
3034 (struct get_nvm_data_resp *)(piomb + 4);
3035 u32 tag = le32_to_cpu(pPayload->tag);
3036 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3037 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3038 complete(pm8001_ha->nvmd_completion);
Joe Perches1b5d2792020-11-20 15:16:09 -08003039 pm8001_dbg(pm8001_ha, MSG, "Set nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003040 if ((dlen_status & NVMD_STAT) != 0) {
akshatzen5d280262021-01-09 18:08:45 +05303041 pm8001_dbg(pm8001_ha, FAIL, "Set nvm data error %x\n",
3042 dlen_status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003043 }
3044 ccb->task = NULL;
3045 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303046 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003047}
3048
Sakthivel Kf74cf272013-02-27 20:27:43 +05303049void
3050pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003051{
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303052 struct fw_control_ex *fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003053 struct get_nvm_data_resp *pPayload =
3054 (struct get_nvm_data_resp *)(piomb + 4);
3055 u32 tag = le32_to_cpu(pPayload->tag);
3056 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3057 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3058 u32 ir_tds_bn_dps_das_nvm =
3059 le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm);
3060 void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303061 fw_control_context = ccb->fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003062
Joe Perches1b5d2792020-11-20 15:16:09 -08003063 pm8001_dbg(pm8001_ha, MSG, "Get nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003064 if ((dlen_status & NVMD_STAT) != 0) {
akshatzen5d280262021-01-09 18:08:45 +05303065 pm8001_dbg(pm8001_ha, FAIL, "Get nvm data error %x\n",
3066 dlen_status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003067 complete(pm8001_ha->nvmd_completion);
akshatzen5d280262021-01-09 18:08:45 +05303068 /* We should free tag during failure also, the tag is not being
3069 * freed by requesting path anywhere.
3070 */
3071 ccb->task = NULL;
3072 ccb->ccb_tag = 0xFFFFFFFF;
3073 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003074 return;
3075 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003076 if (ir_tds_bn_dps_das_nvm & IPMode) {
3077 /* indirect mode - IR bit set */
Joe Perches1b5d2792020-11-20 15:16:09 -08003078 pm8001_dbg(pm8001_ha, MSG, "Get NVMD success, IR=1\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003079 if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) {
3080 if (ir_tds_bn_dps_das_nvm == 0x80a80200) {
3081 memcpy(pm8001_ha->sas_addr,
3082 ((u8 *)virt_addr + 4),
3083 SAS_ADDR_SIZE);
Joe Perches1b5d2792020-11-20 15:16:09 -08003084 pm8001_dbg(pm8001_ha, MSG, "Get SAS address from VPD successfully!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003085 }
3086 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM)
3087 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) ||
3088 ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) {
3089 ;
3090 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP)
3091 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) {
3092 ;
3093 } else {
3094 /* Should not be happened*/
Joe Perches1b5d2792020-11-20 15:16:09 -08003095 pm8001_dbg(pm8001_ha, MSG,
3096 "(IR=1)Wrong Device type 0x%x\n",
3097 ir_tds_bn_dps_das_nvm);
jack wangdbf9bfe2009-10-14 16:19:21 +08003098 }
3099 } else /* direct mode */{
Joe Perches1b5d2792020-11-20 15:16:09 -08003100 pm8001_dbg(pm8001_ha, MSG,
3101 "Get NVMD success, IR=0, dataLen=%d\n",
3102 (dlen_status & NVMD_LEN) >> 24);
jack wangdbf9bfe2009-10-14 16:19:21 +08003103 }
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303104 /* Though fw_control_context is freed below, usrAddr still needs
3105 * to be updated as this holds the response to the request function
3106 */
3107 memcpy(fw_control_context->usrAddr,
3108 pm8001_ha->memoryMap.region[NVMD].virt_ptr,
3109 fw_control_context->len);
Tomas Henzlf3a06552014-07-07 17:19:58 +02003110 kfree(ccb->fw_control_context);
yuuzheng1f889b52020-11-02 22:25:28 +05303111 /* To avoid race condition, complete should be
3112 * called after the message is copied to
3113 * fw_control_context->usrAddr
3114 */
3115 complete(pm8001_ha->nvmd_completion);
Joe Perches1b5d2792020-11-20 15:16:09 -08003116 pm8001_dbg(pm8001_ha, MSG, "Set nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003117 ccb->task = NULL;
3118 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303119 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003120}
3121
Sakthivel Kf74cf272013-02-27 20:27:43 +05303122int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003123{
Viswas G25c6edb2017-10-18 11:39:10 +05303124 u32 tag;
jack wangdbf9bfe2009-10-14 16:19:21 +08003125 struct local_phy_ctl_resp *pPayload =
3126 (struct local_phy_ctl_resp *)(piomb + 4);
3127 u32 status = le32_to_cpu(pPayload->status);
3128 u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
3129 u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
Viswas G25c6edb2017-10-18 11:39:10 +05303130 tag = le32_to_cpu(pPayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003131 if (status != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003132 pm8001_dbg(pm8001_ha, MSG,
3133 "%x phy execute %x phy op failed!\n",
3134 phy_id, phy_op);
Viswas G869ddbd2017-10-18 11:39:13 +05303135 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08003136 pm8001_dbg(pm8001_ha, MSG,
3137 "%x phy execute %x phy op success!\n",
3138 phy_id, phy_op);
Viswas G869ddbd2017-10-18 11:39:13 +05303139 pm8001_ha->phy[phy_id].reset_success = true;
3140 }
3141 if (pm8001_ha->phy[phy_id].enable_completion) {
3142 complete(pm8001_ha->phy[phy_id].enable_completion);
3143 pm8001_ha->phy[phy_id].enable_completion = NULL;
3144 }
Viswas G25c6edb2017-10-18 11:39:10 +05303145 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003146 return 0;
3147}
3148
3149/**
3150 * pm8001_bytes_dmaed - one of the interface function communication with libsas
3151 * @pm8001_ha: our hba card information
3152 * @i: which phy that received the event.
3153 *
3154 * when HBA driver received the identify done event or initiate FIS received
3155 * event(for SATA), it will invoke this function to notify the sas layer that
3156 * the sas toplogy has formed, please discover the the whole sas domain,
3157 * while receive a broadcast(change) primitive just tell the sas
3158 * layer to discover the changed domain rather than the whole domain.
3159 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303160void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i)
jack wangdbf9bfe2009-10-14 16:19:21 +08003161{
3162 struct pm8001_phy *phy = &pm8001_ha->phy[i];
3163 struct asd_sas_phy *sas_phy = &phy->sas_phy;
jack wangdbf9bfe2009-10-14 16:19:21 +08003164 if (!phy->phy_attached)
3165 return;
3166
jack wangdbf9bfe2009-10-14 16:19:21 +08003167 if (sas_phy->phy) {
3168 struct sas_phy *sphy = sas_phy->phy;
3169 sphy->negotiated_linkrate = sas_phy->linkrate;
3170 sphy->minimum_linkrate = phy->minimum_linkrate;
3171 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3172 sphy->maximum_linkrate = phy->maximum_linkrate;
3173 sphy->maximum_linkrate_hw = phy->maximum_linkrate;
3174 }
3175
3176 if (phy->phy_type & PORT_TYPE_SAS) {
3177 struct sas_identify_frame *id;
3178 id = (struct sas_identify_frame *)phy->frame_rcvd;
3179 id->dev_type = phy->identify.device_type;
3180 id->initiator_bits = SAS_PROTOCOL_ALL;
3181 id->target_bits = phy->identify.target_port_protocols;
3182 } else if (phy->phy_type & PORT_TYPE_SATA) {
3183 /*Nothing*/
3184 }
Joe Perches1b5d2792020-11-20 15:16:09 -08003185 pm8001_dbg(pm8001_ha, MSG, "phy %d byte dmaded.\n", i);
jack wangdbf9bfe2009-10-14 16:19:21 +08003186
3187 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003188 sas_notify_port_event(sas_phy, PORTE_BYTES_DMAED, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003189}
3190
3191/* Get the link rate speed */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303192void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate)
jack wangdbf9bfe2009-10-14 16:19:21 +08003193{
3194 struct sas_phy *sas_phy = phy->sas_phy.phy;
3195
3196 switch (link_rate) {
Viswas Gb093d592015-08-11 15:06:25 +05303197 case PHY_SPEED_120:
3198 phy->sas_phy.linkrate = SAS_LINK_RATE_12_0_GBPS;
3199 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_12_0_GBPS;
3200 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08003201 case PHY_SPEED_60:
3202 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
3203 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3204 break;
3205 case PHY_SPEED_30:
3206 phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
3207 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3208 break;
3209 case PHY_SPEED_15:
3210 phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
3211 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
3212 break;
3213 }
3214 sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
3215 sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS;
3216 sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3217 sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
3218 sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3219}
3220
3221/**
Lee Jones6b87e432021-03-03 14:46:19 +00003222 * pm8001_get_attached_sas_addr - extract/generate attached SAS address
jack wangdbf9bfe2009-10-14 16:19:21 +08003223 * @phy: pointer to asd_phy
3224 * @sas_addr: pointer to buffer where the SAS address is to be written
3225 *
3226 * This function extracts the SAS address from an IDENTIFY frame
3227 * received. If OOB is SATA, then a SAS address is generated from the
3228 * HA tables.
3229 *
3230 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
3231 * buffer.
3232 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303233void pm8001_get_attached_sas_addr(struct pm8001_phy *phy,
jack wangdbf9bfe2009-10-14 16:19:21 +08003234 u8 *sas_addr)
3235{
3236 if (phy->sas_phy.frame_rcvd[0] == 0x34
3237 && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
3238 struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha;
3239 /* FIS device-to-host */
3240 u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr);
3241 addr += phy->sas_phy.id;
3242 *(__be64 *)sas_addr = cpu_to_be64(addr);
3243 } else {
3244 struct sas_identify_frame *idframe =
3245 (void *) phy->sas_phy.frame_rcvd;
3246 memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
3247 }
3248}
3249
3250/**
3251 * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
3252 * @pm8001_ha: our hba card information
3253 * @Qnum: the outbound queue message number.
3254 * @SEA: source of event to ack
3255 * @port_id: port id.
3256 * @phyId: phy id.
3257 * @param0: parameter 0.
3258 * @param1: parameter 1.
3259 */
3260static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3261 u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3262{
3263 struct hw_event_ack_req payload;
3264 u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3265
3266 struct inbound_queue_table *circularQ;
3267
3268 memset((u8 *)&payload, 0, sizeof(payload));
3269 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
Santosh Nayak8270ee22012-02-26 20:14:46 +05303270 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08003271 payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3272 ((phyId & 0x0F) << 4) | (port_id & 0x0F));
3273 payload.param0 = cpu_to_le32(param0);
3274 payload.param1 = cpu_to_le32(param1);
peter chang91a43fa2019-11-14 15:39:05 +05303275 pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
3276 sizeof(payload), 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08003277}
3278
3279static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3280 u32 phyId, u32 phy_op);
3281
3282/**
3283 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
3284 * @pm8001_ha: our hba card information
3285 * @piomb: IO message buffer
3286 */
3287static void
3288hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3289{
3290 struct hw_event_resp *pPayload =
3291 (struct hw_event_resp *)(piomb + 4);
3292 u32 lr_evt_status_phyid_portid =
3293 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3294 u8 link_rate =
3295 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003296 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003297 u8 phy_id =
3298 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003299 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3300 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3301 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003302 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3303 unsigned long flags;
3304 u8 deviceType = pPayload->sas_identify.dev_type;
jack wang1cc943a2009-12-07 17:22:42 +08003305 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303306 phy->phy_state = PHY_STATE_LINK_UP_SPC;
Joe Perches1b5d2792020-11-20 15:16:09 -08003307 pm8001_dbg(pm8001_ha, MSG,
3308 "HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n",
3309 port_id, phy_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003310
3311 switch (deviceType) {
3312 case SAS_PHY_UNUSED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003313 pm8001_dbg(pm8001_ha, MSG, "device type no device.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003314 break;
3315 case SAS_END_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003316 pm8001_dbg(pm8001_ha, MSG, "end device.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003317 pm8001_chip_phy_ctl_req(pm8001_ha, phy_id,
3318 PHY_NOTIFY_ENABLE_SPINUP);
jack wang1cc943a2009-12-07 17:22:42 +08003319 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303320 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003321 break;
3322 case SAS_EDGE_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003323 pm8001_dbg(pm8001_ha, MSG, "expander device.\n");
jack wang1cc943a2009-12-07 17:22:42 +08003324 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303325 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003326 break;
3327 case SAS_FANOUT_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003328 pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n");
jack wang1cc943a2009-12-07 17:22:42 +08003329 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303330 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003331 break;
3332 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003333 pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n",
3334 deviceType);
jack wangdbf9bfe2009-10-14 16:19:21 +08003335 break;
3336 }
3337 phy->phy_type |= PORT_TYPE_SAS;
3338 phy->identify.device_type = deviceType;
3339 phy->phy_attached = 1;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303340 if (phy->identify.device_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08003341 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303342 else if (phy->identify.device_type != SAS_PHY_UNUSED)
jack wangdbf9bfe2009-10-14 16:19:21 +08003343 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3344 phy->sas_phy.oob_mode = SAS_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003345 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003346 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3347 memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3348 sizeof(struct sas_identify_frame)-4);
3349 phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3350 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3351 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3352 if (pm8001_ha->flags == PM8001F_RUN_TIME)
3353 mdelay(200);/*delay a moment to wait disk to spinup*/
3354 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3355}
3356
3357/**
3358 * hw_event_sata_phy_up -FW tells me a SATA phy up event.
3359 * @pm8001_ha: our hba card information
3360 * @piomb: IO message buffer
3361 */
3362static void
3363hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3364{
3365 struct hw_event_resp *pPayload =
3366 (struct hw_event_resp *)(piomb + 4);
3367 u32 lr_evt_status_phyid_portid =
3368 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3369 u8 link_rate =
3370 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003371 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003372 u8 phy_id =
3373 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003374 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3375 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3376 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003377 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3378 unsigned long flags;
Joe Perches1b5d2792020-11-20 15:16:09 -08003379 pm8001_dbg(pm8001_ha, DEVIO, "HW_EVENT_SATA_PHY_UP port id = %d, phy id = %d\n",
3380 port_id, phy_id);
jack wang1cc943a2009-12-07 17:22:42 +08003381 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303382 phy->phy_state = PHY_STATE_LINK_UP_SPC;
jack wang1cc943a2009-12-07 17:22:42 +08003383 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303384 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003385 phy->phy_type |= PORT_TYPE_SATA;
3386 phy->phy_attached = 1;
3387 phy->sas_phy.oob_mode = SATA_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003388 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003389 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3390 memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3391 sizeof(struct dev_to_host_fis));
3392 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3393 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
James Bottomleyaa9f8322013-05-07 14:44:06 -07003394 phy->identify.device_type = SAS_SATA_DEV;
jack wangdbf9bfe2009-10-14 16:19:21 +08003395 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3396 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3397 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3398}
3399
3400/**
3401 * hw_event_phy_down -we should notify the libsas the phy is down.
3402 * @pm8001_ha: our hba card information
3403 * @piomb: IO message buffer
3404 */
3405static void
3406hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3407{
3408 struct hw_event_resp *pPayload =
3409 (struct hw_event_resp *)(piomb + 4);
3410 u32 lr_evt_status_phyid_portid =
3411 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3412 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3413 u8 phy_id =
3414 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3415 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3416 u8 portstate = (u8)(npip_portstate & 0x0000000F);
jack wang1cc943a2009-12-07 17:22:42 +08003417 struct pm8001_port *port = &pm8001_ha->port[port_id];
3418 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3419 port->port_state = portstate;
3420 phy->phy_type = 0;
3421 phy->identify.device_type = 0;
3422 phy->phy_attached = 0;
3423 memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
jack wangdbf9bfe2009-10-14 16:19:21 +08003424 switch (portstate) {
3425 case PORT_VALID:
3426 break;
3427 case PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003428 pm8001_dbg(pm8001_ha, MSG, " PortInvalid portID %d\n",
3429 port_id);
3430 pm8001_dbg(pm8001_ha, MSG,
3431 " Last phy Down and port invalid\n");
jack wang1cc943a2009-12-07 17:22:42 +08003432 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003433 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3434 port_id, phy_id, 0, 0);
3435 break;
3436 case PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003437 pm8001_dbg(pm8001_ha, MSG, " Port In Reset portID %d\n",
3438 port_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003439 break;
3440 case PORT_NOT_ESTABLISHED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003441 pm8001_dbg(pm8001_ha, MSG,
3442 " phy Down and PORT_NOT_ESTABLISHED\n");
jack wang1cc943a2009-12-07 17:22:42 +08003443 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003444 break;
3445 case PORT_LOSTCOMM:
Joe Perches1b5d2792020-11-20 15:16:09 -08003446 pm8001_dbg(pm8001_ha, MSG, " phy Down and PORT_LOSTCOMM\n");
3447 pm8001_dbg(pm8001_ha, MSG,
3448 " Last phy Down and port invalid\n");
jack wang1cc943a2009-12-07 17:22:42 +08003449 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003450 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3451 port_id, phy_id, 0, 0);
3452 break;
3453 default:
jack wang1cc943a2009-12-07 17:22:42 +08003454 port->port_attached = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08003455 pm8001_dbg(pm8001_ha, DEVIO, " phy Down and(default) = %x\n",
3456 portstate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003457 break;
3458
3459 }
3460}
3461
3462/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05303463 * pm8001_mpi_reg_resp -process register device ID response.
jack wangdbf9bfe2009-10-14 16:19:21 +08003464 * @pm8001_ha: our hba card information
3465 * @piomb: IO message buffer
3466 *
3467 * when sas layer find a device it will notify LLDD, then the driver register
3468 * the domain device to FW, this event is the return device ID which the FW
3469 * has assigned, from now,inter-communication with FW is no longer using the
3470 * SAS address, use device ID which FW assigned.
3471 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303472int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003473{
3474 u32 status;
3475 u32 device_id;
3476 u32 htag;
3477 struct pm8001_ccb_info *ccb;
3478 struct pm8001_device *pm8001_dev;
3479 struct dev_reg_resp *registerRespPayload =
3480 (struct dev_reg_resp *)(piomb + 4);
3481
3482 htag = le32_to_cpu(registerRespPayload->tag);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303483 ccb = &pm8001_ha->ccb_info[htag];
jack wangdbf9bfe2009-10-14 16:19:21 +08003484 pm8001_dev = ccb->device;
3485 status = le32_to_cpu(registerRespPayload->status);
3486 device_id = le32_to_cpu(registerRespPayload->device_id);
Joe Perches1b5d2792020-11-20 15:16:09 -08003487 pm8001_dbg(pm8001_ha, MSG, " register device is status = %d\n",
3488 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003489 switch (status) {
3490 case DEVREG_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003491 pm8001_dbg(pm8001_ha, MSG, "DEVREG_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003492 pm8001_dev->device_id = device_id;
3493 break;
3494 case DEVREG_FAILURE_OUT_OF_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003495 pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_OUT_OF_RESOURCE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003496 break;
3497 case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003498 pm8001_dbg(pm8001_ha, MSG,
3499 "DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003500 break;
3501 case DEVREG_FAILURE_INVALID_PHY_ID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003502 pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_INVALID_PHY_ID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003503 break;
3504 case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003505 pm8001_dbg(pm8001_ha, MSG,
3506 "DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003507 break;
3508 case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003509 pm8001_dbg(pm8001_ha, MSG,
3510 "DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003511 break;
3512 case DEVREG_FAILURE_PORT_NOT_VALID_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003513 pm8001_dbg(pm8001_ha, MSG,
3514 "DEVREG_FAILURE_PORT_NOT_VALID_STATE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003515 break;
3516 case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003517 pm8001_dbg(pm8001_ha, MSG,
3518 "DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003519 break;
3520 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003521 pm8001_dbg(pm8001_ha, MSG,
3522 "DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003523 break;
3524 }
3525 complete(pm8001_dev->dcompletion);
3526 ccb->task = NULL;
3527 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303528 pm8001_tag_free(pm8001_ha, htag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003529 return 0;
3530}
3531
Sakthivel Kf74cf272013-02-27 20:27:43 +05303532int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003533{
3534 u32 status;
3535 u32 device_id;
3536 struct dev_reg_resp *registerRespPayload =
3537 (struct dev_reg_resp *)(piomb + 4);
3538
3539 status = le32_to_cpu(registerRespPayload->status);
3540 device_id = le32_to_cpu(registerRespPayload->device_id);
3541 if (status != 0)
Joe Perches1b5d2792020-11-20 15:16:09 -08003542 pm8001_dbg(pm8001_ha, MSG,
3543 " deregister device failed ,status = %x, device_id = %x\n",
3544 status, device_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003545 return 0;
3546}
3547
Sakthivel Kf74cf272013-02-27 20:27:43 +05303548/**
Lee Jones6b87e432021-03-03 14:46:19 +00003549 * pm8001_mpi_fw_flash_update_resp - Response from FW for flash update command.
Sakthivel Kf74cf272013-02-27 20:27:43 +05303550 * @pm8001_ha: our hba card information
3551 * @piomb: IO message buffer
3552 */
3553int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha,
3554 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003555{
3556 u32 status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003557 struct fw_flash_Update_resp *ppayload =
3558 (struct fw_flash_Update_resp *)(piomb + 4);
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303559 u32 tag = le32_to_cpu(ppayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003560 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3561 status = le32_to_cpu(ppayload->status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003562 switch (status) {
3563 case FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003564 pm8001_dbg(pm8001_ha, MSG,
3565 ": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003566 break;
3567 case FLASH_UPDATE_IN_PROGRESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003568 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_IN_PROGRESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003569 break;
3570 case FLASH_UPDATE_HDR_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003571 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HDR_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003572 break;
3573 case FLASH_UPDATE_OFFSET_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003574 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_OFFSET_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003575 break;
3576 case FLASH_UPDATE_CRC_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003577 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_CRC_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003578 break;
3579 case FLASH_UPDATE_LENGTH_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003580 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_LENGTH_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003581 break;
3582 case FLASH_UPDATE_HW_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003583 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HW_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003584 break;
3585 case FLASH_UPDATE_DNLD_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003586 pm8001_dbg(pm8001_ha, MSG,
3587 ": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003588 break;
3589 case FLASH_UPDATE_DISABLED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003590 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_DISABLED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003591 break;
3592 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003593 pm8001_dbg(pm8001_ha, DEVIO, "No matched status = %d\n",
3594 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003595 break;
3596 }
Tomas Henzl9422e862014-07-07 17:20:00 +02003597 kfree(ccb->fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08003598 ccb->task = NULL;
3599 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303600 pm8001_tag_free(pm8001_ha, tag);
Tomas Henzl9422e862014-07-07 17:20:00 +02003601 complete(pm8001_ha->nvmd_completion);
jack wangdbf9bfe2009-10-14 16:19:21 +08003602 return 0;
3603}
3604
Sakthivel Kf74cf272013-02-27 20:27:43 +05303605int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003606{
3607 u32 status;
3608 int i;
3609 struct general_event_resp *pPayload =
3610 (struct general_event_resp *)(piomb + 4);
3611 status = le32_to_cpu(pPayload->status);
Joe Perches1b5d2792020-11-20 15:16:09 -08003612 pm8001_dbg(pm8001_ha, MSG, " status = 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003613 for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
Joe Perches1b5d2792020-11-20 15:16:09 -08003614 pm8001_dbg(pm8001_ha, MSG, "inb_IOMB_payload[0x%x] 0x%x,\n",
3615 i,
3616 pPayload->inb_IOMB_payload[i]);
jack wangdbf9bfe2009-10-14 16:19:21 +08003617 return 0;
3618}
3619
Sakthivel Kf74cf272013-02-27 20:27:43 +05303620int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003621{
3622 struct sas_task *t;
3623 struct pm8001_ccb_info *ccb;
3624 unsigned long flags;
3625 u32 status ;
3626 u32 tag, scp;
3627 struct task_status_struct *ts;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303628 struct pm8001_device *pm8001_dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08003629
3630 struct task_abort_resp *pPayload =
3631 (struct task_abort_resp *)(piomb + 4);
jack wangdbf9bfe2009-10-14 16:19:21 +08003632
3633 status = le32_to_cpu(pPayload->status);
3634 tag = le32_to_cpu(pPayload->tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303635 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003636 pm8001_dbg(pm8001_ha, FAIL, " TAG NULL. RETURNING !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303637 return -1;
3638 }
3639
jack wangdbf9bfe2009-10-14 16:19:21 +08003640 scp = le32_to_cpu(pPayload->scp);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303641 ccb = &pm8001_ha->ccb_info[tag];
3642 t = ccb->task;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303643 pm8001_dev = ccb->device; /* retrieve device */
3644
3645 if (!t) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003646 pm8001_dbg(pm8001_ha, FAIL, " TASK NULL. RETURNING !!!\n");
jack_wang72d0baa2009-11-05 22:33:35 +08003647 return -1;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303648 }
jack_wang72d0baa2009-11-05 22:33:35 +08003649 ts = &t->task_status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003650 if (status != 0)
Joe Perches1b5d2792020-11-20 15:16:09 -08003651 pm8001_dbg(pm8001_ha, FAIL, "task abort failed status 0x%x ,tag = 0x%x, scp= 0x%x\n",
3652 status, tag, scp);
jack wangdbf9bfe2009-10-14 16:19:21 +08003653 switch (status) {
3654 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003655 pm8001_dbg(pm8001_ha, EH, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003656 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05003657 ts->stat = SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08003658 break;
3659 case IO_NOT_VALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003660 pm8001_dbg(pm8001_ha, EH, "IO_NOT_VALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003661 ts->resp = TMF_RESP_FUNC_FAILED;
3662 break;
3663 }
3664 spin_lock_irqsave(&t->task_state_lock, flags);
3665 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3666 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3667 t->task_state_flags |= SAS_TASK_STATE_DONE;
3668 spin_unlock_irqrestore(&t->task_state_lock, flags);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303669 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003670 mb();
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303671
Dan Carpenter808cbb62013-05-09 15:48:13 +03003672 if (pm8001_dev->id & NCQ_ABORT_ALL_FLAG) {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303673 pm8001_tag_free(pm8001_ha, tag);
3674 sas_free_task(t);
3675 /* clear the flag */
3676 pm8001_dev->id &= 0xBFFFFFFF;
3677 } else
3678 t->task_done(t);
3679
jack wangdbf9bfe2009-10-14 16:19:21 +08003680 return 0;
3681}
3682
3683/**
3684 * mpi_hw_event -The hw event has come.
3685 * @pm8001_ha: our hba card information
3686 * @piomb: IO message buffer
3687 */
3688static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
3689{
3690 unsigned long flags;
3691 struct hw_event_resp *pPayload =
3692 (struct hw_event_resp *)(piomb + 4);
3693 u32 lr_evt_status_phyid_portid =
3694 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3695 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3696 u8 phy_id =
3697 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3698 u16 eventType =
3699 (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8);
3700 u8 status =
3701 (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24);
3702 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3703 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3704 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
Joe Perches1b5d2792020-11-20 15:16:09 -08003705 pm8001_dbg(pm8001_ha, DEVIO,
3706 "SPC HW event for portid:%d, phyid:%d, event:%x, status:%x\n",
3707 port_id, phy_id, eventType, status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003708 switch (eventType) {
3709 case HW_EVENT_PHY_START_STATUS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003710 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS status = %x\n",
3711 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003712 if (status == 0) {
3713 phy->phy_state = 1;
Deepak Ukeycd135752018-09-11 14:18:02 +05303714 if (pm8001_ha->flags == PM8001F_RUN_TIME &&
3715 phy->enable_completion != NULL)
jack wangdbf9bfe2009-10-14 16:19:21 +08003716 complete(phy->enable_completion);
3717 }
3718 break;
3719 case HW_EVENT_SAS_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003720 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003721 hw_event_sas_phy_up(pm8001_ha, piomb);
3722 break;
3723 case HW_EVENT_SATA_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003724 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_PHY_UP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003725 hw_event_sata_phy_up(pm8001_ha, piomb);
3726 break;
3727 case HW_EVENT_PHY_STOP_STATUS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003728 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_STOP_STATUS status = %x\n",
3729 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003730 if (status == 0)
3731 phy->phy_state = 0;
3732 break;
3733 case HW_EVENT_SATA_SPINUP_HOLD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003734 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_SPINUP_HOLD\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003735 sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003736 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003737 break;
3738 case HW_EVENT_PHY_DOWN:
Joe Perches1b5d2792020-11-20 15:16:09 -08003739 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_DOWN\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003740 sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003741 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003742 phy->phy_attached = 0;
3743 phy->phy_state = 0;
3744 hw_event_phy_down(pm8001_ha, piomb);
3745 break;
3746 case HW_EVENT_PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003747 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_INVALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003748 sas_phy_disconnected(sas_phy);
3749 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003750 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003751 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003752 break;
3753 /* the broadcast change primitive received, tell the LIBSAS this event
3754 to revalidate the sas domain*/
3755 case HW_EVENT_BROADCAST_CHANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003756 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003757 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3758 port_id, phy_id, 1, 0);
3759 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3760 sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3761 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003762 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003763 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003764 break;
3765 case HW_EVENT_PHY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003766 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003767 sas_phy_disconnected(&phy->sas_phy);
3768 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003769 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003770 break;
3771 case HW_EVENT_BROADCAST_EXP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003772 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003773 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3774 sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3775 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003776 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003777 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003778 break;
3779 case HW_EVENT_LINK_ERR_INVALID_DWORD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003780 pm8001_dbg(pm8001_ha, MSG,
3781 "HW_EVENT_LINK_ERR_INVALID_DWORD\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003782 pm8001_hw_event_ack_req(pm8001_ha, 0,
3783 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3784 sas_phy_disconnected(sas_phy);
3785 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003786 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003787 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003788 break;
3789 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003790 pm8001_dbg(pm8001_ha, MSG,
3791 "HW_EVENT_LINK_ERR_DISPARITY_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003792 pm8001_hw_event_ack_req(pm8001_ha, 0,
3793 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3794 port_id, phy_id, 0, 0);
3795 sas_phy_disconnected(sas_phy);
3796 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003797 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003798 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003799 break;
3800 case HW_EVENT_LINK_ERR_CODE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003801 pm8001_dbg(pm8001_ha, MSG,
3802 "HW_EVENT_LINK_ERR_CODE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003803 pm8001_hw_event_ack_req(pm8001_ha, 0,
3804 HW_EVENT_LINK_ERR_CODE_VIOLATION,
3805 port_id, phy_id, 0, 0);
3806 sas_phy_disconnected(sas_phy);
3807 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003808 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003809 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003810 break;
3811 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08003812 pm8001_dbg(pm8001_ha, MSG,
3813 "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003814 pm8001_hw_event_ack_req(pm8001_ha, 0,
3815 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3816 port_id, phy_id, 0, 0);
3817 sas_phy_disconnected(sas_phy);
3818 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003819 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003820 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003821 break;
3822 case HW_EVENT_MALFUNCTION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003823 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_MALFUNCTION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003824 break;
3825 case HW_EVENT_BROADCAST_SES:
Joe Perches1b5d2792020-11-20 15:16:09 -08003826 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003827 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3828 sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3829 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003830 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003831 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003832 break;
3833 case HW_EVENT_INBOUND_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003834 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_INBOUND_CRC_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003835 pm8001_hw_event_ack_req(pm8001_ha, 0,
3836 HW_EVENT_INBOUND_CRC_ERROR,
3837 port_id, phy_id, 0, 0);
3838 break;
3839 case HW_EVENT_HARD_RESET_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003840 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_HARD_RESET_RECEIVED\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003841 sas_notify_port_event(sas_phy, PORTE_HARD_RESET, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003842 break;
3843 case HW_EVENT_ID_FRAME_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003844 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_ID_FRAME_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003845 sas_phy_disconnected(sas_phy);
3846 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003847 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003848 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003849 break;
3850 case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003851 pm8001_dbg(pm8001_ha, MSG,
3852 "HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003853 pm8001_hw_event_ack_req(pm8001_ha, 0,
3854 HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3855 port_id, phy_id, 0, 0);
3856 sas_phy_disconnected(sas_phy);
3857 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003858 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003859 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003860 break;
3861 case HW_EVENT_PORT_RESET_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003862 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_TIMER_TMO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003863 sas_phy_disconnected(sas_phy);
3864 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003865 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003866 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003867 break;
3868 case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003869 pm8001_dbg(pm8001_ha, MSG,
3870 "HW_EVENT_PORT_RECOVERY_TIMER_TMO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003871 sas_phy_disconnected(sas_phy);
3872 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003873 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003874 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003875 break;
3876 case HW_EVENT_PORT_RECOVER:
Joe Perches1b5d2792020-11-20 15:16:09 -08003877 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RECOVER\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003878 break;
3879 case HW_EVENT_PORT_RESET_COMPLETE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003880 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_COMPLETE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003881 break;
3882 case EVENT_BROADCAST_ASYNCH_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003883 pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003884 break;
3885 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003886 pm8001_dbg(pm8001_ha, DEVIO, "Unknown event type = %x\n",
3887 eventType);
jack wangdbf9bfe2009-10-14 16:19:21 +08003888 break;
3889 }
3890 return 0;
3891}
3892
3893/**
3894 * process_one_iomb - process one outbound Queue memory block
3895 * @pm8001_ha: our hba card information
3896 * @piomb: IO message buffer
3897 */
3898static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3899{
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303900 __le32 pHeader = *(__le32 *)piomb;
3901 u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF);
jack wangdbf9bfe2009-10-14 16:19:21 +08003902
Joe Perches1b5d2792020-11-20 15:16:09 -08003903 pm8001_dbg(pm8001_ha, MSG, "process_one_iomb:\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003904
3905 switch (opc) {
3906 case OPC_OUB_ECHO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003907 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003908 break;
3909 case OPC_OUB_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003910 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003911 mpi_hw_event(pm8001_ha, piomb);
3912 break;
3913 case OPC_OUB_SSP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003914 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003915 mpi_ssp_completion(pm8001_ha, piomb);
3916 break;
3917 case OPC_OUB_SMP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003918 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003919 mpi_smp_completion(pm8001_ha, piomb);
3920 break;
3921 case OPC_OUB_LOCAL_PHY_CNTRL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003922 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303923 pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003924 break;
3925 case OPC_OUB_DEV_REGIST:
Joe Perches1b5d2792020-11-20 15:16:09 -08003926 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303927 pm8001_mpi_reg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003928 break;
3929 case OPC_OUB_DEREG_DEV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003930 pm8001_dbg(pm8001_ha, MSG, "unregister the device\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303931 pm8001_mpi_dereg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003932 break;
3933 case OPC_OUB_GET_DEV_HANDLE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003934 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003935 break;
3936 case OPC_OUB_SATA_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003937 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003938 mpi_sata_completion(pm8001_ha, piomb);
3939 break;
3940 case OPC_OUB_SATA_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003941 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003942 mpi_sata_event(pm8001_ha, piomb);
3943 break;
3944 case OPC_OUB_SSP_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003945 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003946 mpi_ssp_event(pm8001_ha, piomb);
3947 break;
3948 case OPC_OUB_DEV_HANDLE_ARRIV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003949 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003950 /*This is for target*/
3951 break;
3952 case OPC_OUB_SSP_RECV_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003953 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003954 /*This is for target*/
3955 break;
3956 case OPC_OUB_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003957 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_INFO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003958 break;
3959 case OPC_OUB_FW_FLASH_UPDATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003960 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303961 pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003962 break;
3963 case OPC_OUB_GPIO_RESPONSE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003964 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003965 break;
3966 case OPC_OUB_GPIO_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003967 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003968 break;
3969 case OPC_OUB_GENERAL_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003970 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303971 pm8001_mpi_general_event(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003972 break;
3973 case OPC_OUB_SSP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003974 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303975 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003976 break;
3977 case OPC_OUB_SATA_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003978 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303979 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003980 break;
3981 case OPC_OUB_SAS_DIAG_MODE_START_END:
Joe Perches1b5d2792020-11-20 15:16:09 -08003982 pm8001_dbg(pm8001_ha, MSG,
3983 "OPC_OUB_SAS_DIAG_MODE_START_END\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003984 break;
3985 case OPC_OUB_SAS_DIAG_EXECUTE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003986 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003987 break;
3988 case OPC_OUB_GET_TIME_STAMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003989 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003990 break;
3991 case OPC_OUB_SAS_HW_EVENT_ACK:
Joe Perches1b5d2792020-11-20 15:16:09 -08003992 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003993 break;
3994 case OPC_OUB_PORT_CONTROL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003995 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003996 break;
3997 case OPC_OUB_SMP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003998 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303999 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004000 break;
4001 case OPC_OUB_GET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004002 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304003 pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004004 break;
4005 case OPC_OUB_SET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004006 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304007 pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004008 break;
4009 case OPC_OUB_DEVICE_HANDLE_REMOVAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004010 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004011 break;
4012 case OPC_OUB_SET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004013 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304014 pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004015 break;
4016 case OPC_OUB_GET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004017 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004018 break;
4019 case OPC_OUB_SET_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08004020 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004021 break;
4022 case OPC_OUB_SAS_RE_INITIALIZE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004023 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_RE_INITIALIZE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004024 break;
4025 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08004026 pm8001_dbg(pm8001_ha, DEVIO,
4027 "Unknown outbound Queue IOMB OPC = %x\n",
4028 opc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004029 break;
4030 }
4031}
4032
Sakthivel Kf74cf272013-02-27 20:27:43 +05304033static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004034{
4035 struct outbound_queue_table *circularQ;
4036 void *pMsg1 = NULL;
Kees Cook3f649ab2020-06-03 13:09:38 -07004037 u8 bc;
jack_wang72d0baa2009-11-05 22:33:35 +08004038 u32 ret = MPI_IO_STATUS_FAIL;
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304039 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004040
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304041 spin_lock_irqsave(&pm8001_ha->lock, flags);
Sakthivel Kf74cf272013-02-27 20:27:43 +05304042 circularQ = &pm8001_ha->outbnd_q_tbl[vec];
jack wangdbf9bfe2009-10-14 16:19:21 +08004043 do {
Sakthivel Kf74cf272013-02-27 20:27:43 +05304044 ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004045 if (MPI_IO_STATUS_SUCCESS == ret) {
4046 /* process the outbound message */
jack_wang72d0baa2009-11-05 22:33:35 +08004047 process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
jack wangdbf9bfe2009-10-14 16:19:21 +08004048 /* free the message from the outbound circular buffer */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304049 pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4050 circularQ, bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004051 }
4052 if (MPI_IO_STATUS_BUSY == ret) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004053 /* Update the producer index from SPC */
Santosh Nayak8270ee22012-02-26 20:14:46 +05304054 circularQ->producer_index =
4055 cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4056 if (le32_to_cpu(circularQ->producer_index) ==
jack wangdbf9bfe2009-10-14 16:19:21 +08004057 circularQ->consumer_idx)
4058 /* OQ is empty */
4059 break;
4060 }
jack_wang72d0baa2009-11-05 22:33:35 +08004061 } while (1);
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304062 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08004063 return ret;
4064}
4065
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004066/* DMA_... to our direction translation. */
jack wangdbf9bfe2009-10-14 16:19:21 +08004067static const u8 data_dir_flags[] = {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004068 [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
4069 [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
4070 [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */
4071 [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */
jack wangdbf9bfe2009-10-14 16:19:21 +08004072};
Sakthivel Kf74cf272013-02-27 20:27:43 +05304073void
jack wangdbf9bfe2009-10-14 16:19:21 +08004074pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
4075{
4076 int i;
4077 struct scatterlist *sg;
4078 struct pm8001_prd *buf_prd = prd;
4079
4080 for_each_sg(scatter, sg, nr, i) {
4081 buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
4082 buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
4083 buf_prd->im_len.e = 0;
4084 buf_prd++;
4085 }
4086}
4087
Santosh Nayak8270ee22012-02-26 20:14:46 +05304088static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd)
jack wangdbf9bfe2009-10-14 16:19:21 +08004089{
Santosh Nayak8270ee22012-02-26 20:14:46 +05304090 psmp_cmd->tag = hTag;
jack wangdbf9bfe2009-10-14 16:19:21 +08004091 psmp_cmd->device_id = cpu_to_le32(deviceID);
4092 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4093}
4094
4095/**
4096 * pm8001_chip_smp_req - send a SMP task to FW
4097 * @pm8001_ha: our hba card information.
4098 * @ccb: the ccb information this request used.
4099 */
4100static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4101 struct pm8001_ccb_info *ccb)
4102{
4103 int elem, rc;
4104 struct sas_task *task = ccb->task;
4105 struct domain_device *dev = task->dev;
4106 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4107 struct scatterlist *sg_req, *sg_resp;
4108 u32 req_len, resp_len;
4109 struct smp_req smp_cmd;
4110 u32 opc;
4111 struct inbound_queue_table *circularQ;
4112
4113 memset(&smp_cmd, 0, sizeof(smp_cmd));
4114 /*
4115 * DMA-map SMP request, response buffers
4116 */
4117 sg_req = &task->smp_task.smp_req;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004118 elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004119 if (!elem)
4120 return -ENOMEM;
4121 req_len = sg_dma_len(sg_req);
4122
4123 sg_resp = &task->smp_task.smp_resp;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004124 elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004125 if (!elem) {
4126 rc = -ENOMEM;
4127 goto err_out;
4128 }
4129 resp_len = sg_dma_len(sg_resp);
4130 /* must be in dwords */
4131 if ((req_len & 0x3) || (resp_len & 0x3)) {
4132 rc = -EINVAL;
4133 goto err_out_2;
4134 }
4135
4136 opc = OPC_INB_SMP_REQUEST;
4137 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4138 smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4139 smp_cmd.long_smp_req.long_req_addr =
4140 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4141 smp_cmd.long_smp_req.long_req_size =
4142 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4143 smp_cmd.long_smp_req.long_resp_addr =
4144 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp));
4145 smp_cmd.long_smp_req.long_resp_size =
4146 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4147 build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304148 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304149 &smp_cmd, sizeof(smp_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304150 if (rc)
4151 goto err_out_2;
4152
jack wangdbf9bfe2009-10-14 16:19:21 +08004153 return 0;
4154
4155err_out_2:
4156 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004157 DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004158err_out:
4159 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004160 DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004161 return rc;
4162}
4163
4164/**
4165 * pm8001_chip_ssp_io_req - send a SSP task to FW
4166 * @pm8001_ha: our hba card information.
4167 * @ccb: the ccb information this request used.
4168 */
4169static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4170 struct pm8001_ccb_info *ccb)
4171{
4172 struct sas_task *task = ccb->task;
4173 struct domain_device *dev = task->dev;
4174 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4175 struct ssp_ini_io_start_req ssp_cmd;
4176 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004177 int ret;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304178 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004179 struct inbound_queue_table *circularQ;
4180 u32 opc = OPC_INB_SSPINIIOSTART;
4181 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4182 memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
jack wangafc5ca92009-12-07 17:22:47 +08004183 ssp_cmd.dir_m_tlr =
4184 cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for
jack wangdbf9bfe2009-10-14 16:19:21 +08004185 SAS 1.1 compatible TLR*/
4186 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4187 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4188 ssp_cmd.tag = cpu_to_le32(tag);
4189 if (task->ssp_task.enable_first_burst)
4190 ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
4191 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
4192 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
James Bottomleye73823f2013-05-07 15:38:18 -07004193 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4194 task->ssp_task.cmd->cmd_len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004195 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4196
4197 /* fill in PRD (scatter/gather) table, if any */
4198 if (task->num_scatter > 1) {
4199 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304200 phys_addr = ccb->ccb_dma_handle;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304201 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr));
4202 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004203 ssp_cmd.esgl = cpu_to_le32(1<<31);
4204 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304205 u64 dma_addr = sg_dma_address(task->scatter);
4206 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4207 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004208 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4209 ssp_cmd.esgl = 0;
4210 } else if (task->num_scatter == 0) {
4211 ssp_cmd.addr_low = 0;
4212 ssp_cmd.addr_high = 0;
4213 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4214 ssp_cmd.esgl = 0;
4215 }
peter chang91a43fa2019-11-14 15:39:05 +05304216 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd,
4217 sizeof(ssp_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004218 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004219}
4220
4221static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4222 struct pm8001_ccb_info *ccb)
4223{
4224 struct sas_task *task = ccb->task;
4225 struct domain_device *dev = task->dev;
4226 struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4227 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004228 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004229 struct sata_start_req sata_cmd;
4230 u32 hdr_tag, ncg_tag = 0;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304231 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004232 u32 ATAP = 0x0;
4233 u32 dir;
4234 struct inbound_queue_table *circularQ;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304235 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004236 u32 opc = OPC_INB_SATA_HOST_OPSTART;
4237 memset(&sata_cmd, 0, sizeof(sata_cmd));
4238 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004239 if (task->data_dir == DMA_NONE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004240 ATAP = 0x04; /* no data*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004241 pm8001_dbg(pm8001_ha, IO, "no data\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004242 } else if (likely(!task->ata_task.device_control_reg_update)) {
4243 if (task->ata_task.dma_xfer) {
4244 ATAP = 0x06; /* DMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004245 pm8001_dbg(pm8001_ha, IO, "DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004246 } else {
4247 ATAP = 0x05; /* PIO*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004248 pm8001_dbg(pm8001_ha, IO, "PIO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004249 }
4250 if (task->ata_task.use_ncq &&
Hannes Reinecke1cbd7722014-11-05 13:08:20 +01004251 dev->sata_dev.class != ATA_DEV_ATAPI) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004252 ATAP = 0x07; /* FPDMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004253 pm8001_dbg(pm8001_ha, IO, "FPDMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004254 }
4255 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304256 if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4257 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
jack wangafc5ca92009-12-07 17:22:47 +08004258 ncg_tag = hdr_tag;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304259 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004260 dir = data_dir_flags[task->data_dir] << 8;
4261 sata_cmd.tag = cpu_to_le32(tag);
4262 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4263 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4264 sata_cmd.ncqtag_atap_dir_m =
4265 cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir);
4266 sata_cmd.sata_fis = task->ata_task.fis;
4267 if (likely(!task->ata_task.device_control_reg_update))
4268 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4269 sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4270 /* fill in PRD (scatter/gather) table, if any */
4271 if (task->num_scatter > 1) {
4272 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304273 phys_addr = ccb->ccb_dma_handle;
jack wangdbf9bfe2009-10-14 16:19:21 +08004274 sata_cmd.addr_low = lower_32_bits(phys_addr);
4275 sata_cmd.addr_high = upper_32_bits(phys_addr);
4276 sata_cmd.esgl = cpu_to_le32(1 << 31);
4277 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304278 u64 dma_addr = sg_dma_address(task->scatter);
jack wangdbf9bfe2009-10-14 16:19:21 +08004279 sata_cmd.addr_low = lower_32_bits(dma_addr);
4280 sata_cmd.addr_high = upper_32_bits(dma_addr);
4281 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4282 sata_cmd.esgl = 0;
4283 } else if (task->num_scatter == 0) {
4284 sata_cmd.addr_low = 0;
4285 sata_cmd.addr_high = 0;
4286 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4287 sata_cmd.esgl = 0;
4288 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304289
4290 /* Check for read log for failed drive and return */
4291 if (sata_cmd.sata_fis.command == 0x2f) {
Rickard Strandqvistd9816442014-07-09 17:19:38 +05304292 if (((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304293 (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4294 (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4295 struct task_status_struct *ts;
4296
4297 pm8001_ha_dev->id &= 0xDFFFFFFF;
4298 ts = &task->task_status;
4299
4300 spin_lock_irqsave(&task->task_state_lock, flags);
4301 ts->resp = SAS_TASK_COMPLETE;
4302 ts->stat = SAM_STAT_GOOD;
4303 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4304 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4305 task->task_state_flags |= SAS_TASK_STATE_DONE;
4306 if (unlikely((task->task_state_flags &
4307 SAS_TASK_STATE_ABORTED))) {
4308 spin_unlock_irqrestore(&task->task_state_lock,
4309 flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08004310 pm8001_dbg(pm8001_ha, FAIL,
4311 "task 0x%p resp 0x%x stat 0x%x but aborted by upper layer\n",
4312 task, ts->resp,
4313 ts->stat);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304314 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304315 } else {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304316 spin_unlock_irqrestore(&task->task_state_lock,
4317 flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304318 pm8001_ccb_task_free_done(pm8001_ha, task,
4319 ccb, tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304320 return 0;
4321 }
4322 }
4323 }
4324
peter chang91a43fa2019-11-14 15:39:05 +05304325 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
4326 sizeof(sata_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004327 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004328}
4329
4330/**
4331 * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND
4332 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004333 * @phy_id: the phy id which we wanted to start up.
4334 */
4335static int
4336pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4337{
4338 struct phy_start_req payload;
4339 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004340 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004341 u32 tag = 0x01;
4342 u32 opcode = OPC_INB_PHYSTART;
4343 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4344 memset(&payload, 0, sizeof(payload));
4345 payload.tag = cpu_to_le32(tag);
4346 /*
4347 ** [0:7] PHY Identifier
4348 ** [8:11] link rate 1.5G, 3G, 6G
4349 ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both
4350 ** [14] 0b disable spin up hold; 1b enable spin up hold
4351 */
4352 payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4353 LINKMODE_AUTO | LINKRATE_15 |
4354 LINKRATE_30 | LINKRATE_60 | phy_id);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004355 payload.sas_identify.dev_type = SAS_END_DEVICE;
jack wangdbf9bfe2009-10-14 16:19:21 +08004356 payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4357 memcpy(payload.sas_identify.sas_addr,
4358 pm8001_ha->sas_addr, SAS_ADDR_SIZE);
4359 payload.sas_identify.phy_id = phy_id;
peter chang91a43fa2019-11-14 15:39:05 +05304360 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4361 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004362 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004363}
4364
4365/**
4366 * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4367 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004368 * @phy_id: the phy id which we wanted to start up.
4369 */
Baoyou Xie7efa59e2016-09-23 21:54:22 +08004370static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4371 u8 phy_id)
jack wangdbf9bfe2009-10-14 16:19:21 +08004372{
4373 struct phy_stop_req payload;
4374 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004375 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004376 u32 tag = 0x01;
4377 u32 opcode = OPC_INB_PHYSTOP;
4378 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4379 memset(&payload, 0, sizeof(payload));
4380 payload.tag = cpu_to_le32(tag);
4381 payload.phy_id = cpu_to_le32(phy_id);
peter chang91a43fa2019-11-14 15:39:05 +05304382 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4383 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004384 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004385}
4386
Lee Jones083645b2020-07-21 17:41:24 +01004387/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304388 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004389 */
4390static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4391 struct pm8001_device *pm8001_dev, u32 flag)
4392{
4393 struct reg_dev_req payload;
4394 u32 opc;
4395 u32 stp_sspsmp_sata = 0x4;
4396 struct inbound_queue_table *circularQ;
4397 u32 linkrate, phy_id;
jack_wang72d0baa2009-11-05 22:33:35 +08004398 int rc, tag = 0xdeadbeef;
jack wangdbf9bfe2009-10-14 16:19:21 +08004399 struct pm8001_ccb_info *ccb;
4400 u8 retryFlag = 0x1;
4401 u16 firstBurstSize = 0;
4402 u16 ITNT = 2000;
4403 struct domain_device *dev = pm8001_dev->sas_device;
4404 struct domain_device *parent_dev = dev->parent;
4405 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4406
4407 memset(&payload, 0, sizeof(payload));
4408 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4409 if (rc)
4410 return rc;
4411 ccb = &pm8001_ha->ccb_info[tag];
4412 ccb->device = pm8001_dev;
4413 ccb->ccb_tag = tag;
4414 payload.tag = cpu_to_le32(tag);
4415 if (flag == 1)
4416 stp_sspsmp_sata = 0x02; /*direct attached sata */
4417 else {
James Bottomleyaa9f8322013-05-07 14:44:06 -07004418 if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004419 stp_sspsmp_sata = 0x00; /* stp*/
James Bottomleyaa9f8322013-05-07 14:44:06 -07004420 else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
4421 pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
4422 pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004423 stp_sspsmp_sata = 0x01; /*ssp or smp*/
4424 }
John Garry924a3542019-06-10 20:41:41 +08004425 if (parent_dev && dev_is_expander(parent_dev->dev_type))
jack wangdbf9bfe2009-10-14 16:19:21 +08004426 phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4427 else
4428 phy_id = pm8001_dev->attached_phy;
4429 opc = OPC_INB_REG_DEV;
4430 linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4431 pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4432 payload.phyid_portid =
4433 cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) |
4434 ((phy_id & 0x0F) << 4));
4435 payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) |
4436 ((linkrate & 0x0F) * 0x1000000) |
4437 ((stp_sspsmp_sata & 0x03) * 0x10000000));
4438 payload.firstburstsize_ITNexustimeout =
4439 cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
jack wangafc5ca92009-12-07 17:22:47 +08004440 memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
jack wangdbf9bfe2009-10-14 16:19:21 +08004441 SAS_ADDR_SIZE);
peter chang91a43fa2019-11-14 15:39:05 +05304442 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4443 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004444 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004445}
4446
Lee Jones083645b2020-07-21 17:41:24 +01004447/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304448 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004449 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304450int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004451 u32 device_id)
4452{
4453 struct dereg_dev_req payload;
4454 u32 opc = OPC_INB_DEREG_DEV_HANDLE;
jack_wang72d0baa2009-11-05 22:33:35 +08004455 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004456 struct inbound_queue_table *circularQ;
4457
4458 circularQ = &pm8001_ha->inbnd_q_tbl[0];
jack_wang72d0baa2009-11-05 22:33:35 +08004459 memset(&payload, 0, sizeof(payload));
Santosh Nayak8270ee22012-02-26 20:14:46 +05304460 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004461 payload.device_id = cpu_to_le32(device_id);
Joe Perches1b5d2792020-11-20 15:16:09 -08004462 pm8001_dbg(pm8001_ha, MSG, "unregister device device_id = %d\n",
4463 device_id);
peter chang91a43fa2019-11-14 15:39:05 +05304464 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4465 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004466 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004467}
4468
4469/**
4470 * pm8001_chip_phy_ctl_req - support the local phy operation
4471 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004472 * @phyId: the phy id which we wanted to operate
4473 * @phy_op: the phy operation to request
jack wangdbf9bfe2009-10-14 16:19:21 +08004474 */
4475static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4476 u32 phyId, u32 phy_op)
4477{
4478 struct local_phy_ctl_req payload;
4479 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004480 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004481 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
jack wang83e73322009-12-07 17:23:11 +08004482 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08004483 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Santosh Nayak8270ee22012-02-26 20:14:46 +05304484 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004485 payload.phyop_phyid =
4486 cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
peter chang91a43fa2019-11-14 15:39:05 +05304487 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4488 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004489 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004490}
4491
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004492static u32 pm8001_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08004493{
jack wangdbf9bfe2009-10-14 16:19:21 +08004494#ifdef PM8001_USE_MSIX
4495 return 1;
Colin Ian King292c04c2019-03-28 23:43:28 +00004496#else
4497 u32 value;
4498
jack wangdbf9bfe2009-10-14 16:19:21 +08004499 value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4500 if (value)
4501 return 1;
4502 return 0;
Colin Ian King292c04c2019-03-28 23:43:28 +00004503#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08004504}
4505
4506/**
4507 * pm8001_chip_isr - PM8001 isr handler.
4508 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004509 * @vec: IRQ number
jack wangdbf9bfe2009-10-14 16:19:21 +08004510 */
jack_wang72d0baa2009-11-05 22:33:35 +08004511static irqreturn_t
Sakthivel Kf74cf272013-02-27 20:27:43 +05304512pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004513{
Sakthivel Kf74cf272013-02-27 20:27:43 +05304514 pm8001_chip_interrupt_disable(pm8001_ha, vec);
Joe Perches1b5d2792020-11-20 15:16:09 -08004515 pm8001_dbg(pm8001_ha, DEVIO,
4516 "irq vec %d, ODMR:0x%x\n",
4517 vec, pm8001_cr32(pm8001_ha, 0, 0x30));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304518 process_oq(pm8001_ha, vec);
4519 pm8001_chip_interrupt_enable(pm8001_ha, vec);
jack_wang72d0baa2009-11-05 22:33:35 +08004520 return IRQ_HANDLED;
jack wangdbf9bfe2009-10-14 16:19:21 +08004521}
4522
4523static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
4524 u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag)
4525{
4526 struct task_abort_req task_abort;
4527 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004528 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004529 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4530 memset(&task_abort, 0, sizeof(task_abort));
4531 if (ABORT_SINGLE == (flag & ABORT_MASK)) {
4532 task_abort.abort_all = 0;
4533 task_abort.device_id = cpu_to_le32(dev_id);
4534 task_abort.tag_to_abort = cpu_to_le32(task_tag);
4535 task_abort.tag = cpu_to_le32(cmd_tag);
4536 } else if (ABORT_ALL == (flag & ABORT_MASK)) {
4537 task_abort.abort_all = cpu_to_le32(1);
4538 task_abort.device_id = cpu_to_le32(dev_id);
4539 task_abort.tag = cpu_to_le32(cmd_tag);
4540 }
peter chang91a43fa2019-11-14 15:39:05 +05304541 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
4542 sizeof(task_abort), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004543 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004544}
4545
Lee Jones083645b2020-07-21 17:41:24 +01004546/*
jack wangdbf9bfe2009-10-14 16:19:21 +08004547 * pm8001_chip_abort_task - SAS abort task when error or exception happened.
jack wangdbf9bfe2009-10-14 16:19:21 +08004548 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304549int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004550 struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag)
4551{
4552 u32 opc, device_id;
4553 int rc = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08004554 pm8001_dbg(pm8001_ha, EH, "cmd_tag = %x, abort task tag = 0x%x\n",
4555 cmd_tag, task_tag);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004556 if (pm8001_dev->dev_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004557 opc = OPC_INB_SSP_ABORT;
James Bottomleyaa9f8322013-05-07 14:44:06 -07004558 else if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004559 opc = OPC_INB_SATA_ABORT;
4560 else
4561 opc = OPC_INB_SMP_ABORT;/* SMP */
4562 device_id = pm8001_dev->device_id;
4563 rc = send_task_abort(pm8001_ha, opc, device_id, flag,
4564 task_tag, cmd_tag);
4565 if (rc != TMF_RESP_FUNC_COMPLETE)
Joe Perches1b5d2792020-11-20 15:16:09 -08004566 pm8001_dbg(pm8001_ha, EH, "rc= %d\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004567 return rc;
4568}
4569
4570/**
Uwe Kleine-König65155b32010-06-11 12:17:01 +02004571 * pm8001_chip_ssp_tm_req - built the task management command.
jack wangdbf9bfe2009-10-14 16:19:21 +08004572 * @pm8001_ha: our hba card information.
4573 * @ccb: the ccb information.
4574 * @tmf: task management function.
4575 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304576int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004577 struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
4578{
4579 struct sas_task *task = ccb->task;
4580 struct domain_device *dev = task->dev;
4581 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4582 u32 opc = OPC_INB_SSPINITMSTART;
4583 struct inbound_queue_table *circularQ;
4584 struct ssp_ini_tm_start_req sspTMCmd;
jack_wang72d0baa2009-11-05 22:33:35 +08004585 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004586
4587 memset(&sspTMCmd, 0, sizeof(sspTMCmd));
4588 sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4589 sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed);
4590 sspTMCmd.tmf = cpu_to_le32(tmf->tmf);
jack wangdbf9bfe2009-10-14 16:19:21 +08004591 memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8);
4592 sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05304593 if (pm8001_ha->chip_id != chip_8001)
4594 sspTMCmd.ds_ads_m = 0x08;
jack wangdbf9bfe2009-10-14 16:19:21 +08004595 circularQ = &pm8001_ha->inbnd_q_tbl[0];
peter chang91a43fa2019-11-14 15:39:05 +05304596 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd,
4597 sizeof(sspTMCmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004598 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004599}
4600
Sakthivel Kf74cf272013-02-27 20:27:43 +05304601int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004602 void *payload)
4603{
4604 u32 opc = OPC_INB_GET_NVMD_DATA;
4605 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004606 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004607 u32 tag;
4608 struct pm8001_ccb_info *ccb;
4609 struct inbound_queue_table *circularQ;
4610 struct get_nvm_data_req nvmd_req;
4611 struct fw_control_ex *fw_control_context;
4612 struct pm8001_ioctl_payload *ioctl_payload = payload;
4613
4614 nvmd_type = ioctl_payload->minor_function;
4615 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004616 if (!fw_control_context)
4617 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304618 fw_control_context->usrAddr = (u8 *)ioctl_payload->func_specific;
Viswas G9b889842020-03-16 13:19:06 +05304619 fw_control_context->len = ioctl_payload->rd_length;
jack wangdbf9bfe2009-10-14 16:19:21 +08004620 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4621 memset(&nvmd_req, 0, sizeof(nvmd_req));
4622 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004623 if (rc) {
4624 kfree(fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08004625 return rc;
Julia Lawall823d2192010-08-01 19:23:35 +02004626 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004627 ccb = &pm8001_ha->ccb_info[tag];
4628 ccb->ccb_tag = tag;
4629 ccb->fw_control_context = fw_control_context;
4630 nvmd_req.tag = cpu_to_le32(tag);
4631
4632 switch (nvmd_type) {
4633 case TWI_DEVICE: {
4634 u32 twi_addr, twi_page_size;
4635 twi_addr = 0xa8;
4636 twi_page_size = 2;
4637
4638 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4639 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304640 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004641 nvmd_req.resp_addr_hi =
4642 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4643 nvmd_req.resp_addr_lo =
4644 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4645 break;
4646 }
4647 case C_SEEPROM: {
4648 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304649 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004650 nvmd_req.resp_addr_hi =
4651 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4652 nvmd_req.resp_addr_lo =
4653 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4654 break;
4655 }
4656 case VPD_FLASH: {
4657 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304658 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004659 nvmd_req.resp_addr_hi =
4660 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4661 nvmd_req.resp_addr_lo =
4662 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4663 break;
4664 }
4665 case EXPAN_ROM: {
4666 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304667 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004668 nvmd_req.resp_addr_hi =
4669 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4670 nvmd_req.resp_addr_lo =
4671 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4672 break;
4673 }
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304674 case IOP_RDUMP: {
4675 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | IOP_RDUMP);
Viswas G9b889842020-03-16 13:19:06 +05304676 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304677 nvmd_req.vpd_offset = cpu_to_le32(ioctl_payload->offset);
4678 nvmd_req.resp_addr_hi =
4679 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4680 nvmd_req.resp_addr_lo =
4681 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4682 break;
4683 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004684 default:
4685 break;
4686 }
peter chang91a43fa2019-11-14 15:39:05 +05304687 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4688 sizeof(nvmd_req), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304689 if (rc) {
4690 kfree(fw_control_context);
4691 pm8001_tag_free(pm8001_ha, tag);
4692 }
jack_wang72d0baa2009-11-05 22:33:35 +08004693 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004694}
4695
Sakthivel Kf74cf272013-02-27 20:27:43 +05304696int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004697 void *payload)
4698{
4699 u32 opc = OPC_INB_SET_NVMD_DATA;
4700 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004701 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004702 u32 tag;
4703 struct pm8001_ccb_info *ccb;
4704 struct inbound_queue_table *circularQ;
4705 struct set_nvm_data_req nvmd_req;
4706 struct fw_control_ex *fw_control_context;
4707 struct pm8001_ioctl_payload *ioctl_payload = payload;
4708
4709 nvmd_type = ioctl_payload->minor_function;
4710 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004711 if (!fw_control_context)
4712 return -ENOMEM;
jack wangdbf9bfe2009-10-14 16:19:21 +08004713 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4714 memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr,
Sakthivel K1c75a672013-03-19 18:06:40 +05304715 &ioctl_payload->func_specific,
Viswas G9b889842020-03-16 13:19:06 +05304716 ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004717 memset(&nvmd_req, 0, sizeof(nvmd_req));
4718 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004719 if (rc) {
4720 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304721 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004722 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004723 ccb = &pm8001_ha->ccb_info[tag];
4724 ccb->fw_control_context = fw_control_context;
4725 ccb->ccb_tag = tag;
4726 nvmd_req.tag = cpu_to_le32(tag);
4727 switch (nvmd_type) {
4728 case TWI_DEVICE: {
4729 u32 twi_addr, twi_page_size;
4730 twi_addr = 0xa8;
4731 twi_page_size = 2;
4732 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4733 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4734 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304735 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004736 nvmd_req.resp_addr_hi =
4737 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4738 nvmd_req.resp_addr_lo =
4739 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4740 break;
4741 }
4742 case C_SEEPROM:
4743 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304744 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004745 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4746 nvmd_req.resp_addr_hi =
4747 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4748 nvmd_req.resp_addr_lo =
4749 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4750 break;
4751 case VPD_FLASH:
4752 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304753 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004754 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4755 nvmd_req.resp_addr_hi =
4756 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4757 nvmd_req.resp_addr_lo =
4758 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4759 break;
4760 case EXPAN_ROM:
4761 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304762 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004763 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4764 nvmd_req.resp_addr_hi =
4765 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4766 nvmd_req.resp_addr_lo =
4767 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4768 break;
4769 default:
4770 break;
4771 }
peter chang91a43fa2019-11-14 15:39:05 +05304772 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4773 sizeof(nvmd_req), 0);
Tomas Henzl9422e862014-07-07 17:20:00 +02004774 if (rc) {
4775 kfree(fw_control_context);
4776 pm8001_tag_free(pm8001_ha, tag);
4777 }
jack_wang72d0baa2009-11-05 22:33:35 +08004778 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004779}
4780
4781/**
4782 * pm8001_chip_fw_flash_update_build - support the firmware update operation
4783 * @pm8001_ha: our hba card information.
4784 * @fw_flash_updata_info: firmware flash update param
Lee Jones083645b2020-07-21 17:41:24 +01004785 * @tag: Tag to apply to the payload
jack wangdbf9bfe2009-10-14 16:19:21 +08004786 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304787int
jack wangdbf9bfe2009-10-14 16:19:21 +08004788pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
4789 void *fw_flash_updata_info, u32 tag)
4790{
4791 struct fw_flash_Update_req payload;
4792 struct fw_flash_updata_info *info;
4793 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004794 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004795 u32 opc = OPC_INB_FW_FLASH_UPDATE;
4796
jack_wang72d0baa2009-11-05 22:33:35 +08004797 memset(&payload, 0, sizeof(struct fw_flash_Update_req));
jack wangdbf9bfe2009-10-14 16:19:21 +08004798 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4799 info = fw_flash_updata_info;
4800 payload.tag = cpu_to_le32(tag);
4801 payload.cur_image_len = cpu_to_le32(info->cur_image_len);
4802 payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
4803 payload.total_image_len = cpu_to_le32(info->total_image_len);
4804 payload.len = info->sgl.im_len.len ;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304805 payload.sgl_addr_lo =
4806 cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr)));
4807 payload.sgl_addr_hi =
4808 cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr)));
peter chang91a43fa2019-11-14 15:39:05 +05304809 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4810 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004811 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004812}
4813
Sakthivel Kf74cf272013-02-27 20:27:43 +05304814int
jack wangdbf9bfe2009-10-14 16:19:21 +08004815pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
4816 void *payload)
4817{
4818 struct fw_flash_updata_info flash_update_info;
4819 struct fw_control_info *fw_control;
4820 struct fw_control_ex *fw_control_context;
jack_wang72d0baa2009-11-05 22:33:35 +08004821 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004822 u32 tag;
4823 struct pm8001_ccb_info *ccb;
Sakthivel K1c75a672013-03-19 18:06:40 +05304824 void *buffer = pm8001_ha->memoryMap.region[FW_FLASH].virt_ptr;
4825 dma_addr_t phys_addr = pm8001_ha->memoryMap.region[FW_FLASH].phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004826 struct pm8001_ioctl_payload *ioctl_payload = payload;
4827
4828 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004829 if (!fw_control_context)
4830 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304831 fw_control = (struct fw_control_info *)&ioctl_payload->func_specific;
Joe Perches1b5d2792020-11-20 15:16:09 -08004832 pm8001_dbg(pm8001_ha, DEVIO,
4833 "dma fw_control context input length :%x\n",
4834 fw_control->len);
jack_wang72d0baa2009-11-05 22:33:35 +08004835 memcpy(buffer, fw_control->buffer, fw_control->len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004836 flash_update_info.sgl.addr = cpu_to_le64(phys_addr);
4837 flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len);
4838 flash_update_info.sgl.im_len.e = 0;
4839 flash_update_info.cur_image_offset = fw_control->offset;
4840 flash_update_info.cur_image_len = fw_control->len;
4841 flash_update_info.total_image_len = fw_control->size;
4842 fw_control_context->fw_control = fw_control;
4843 fw_control_context->virtAddr = buffer;
Sakthivel K1c75a672013-03-19 18:06:40 +05304844 fw_control_context->phys_addr = phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004845 fw_control_context->len = fw_control->len;
4846 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004847 if (rc) {
4848 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304849 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004850 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004851 ccb = &pm8001_ha->ccb_info[tag];
4852 ccb->fw_control_context = fw_control_context;
4853 ccb->ccb_tag = tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004854 rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
4855 tag);
4856 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004857}
4858
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304859ssize_t
4860pm8001_get_gsm_dump(struct device *cdev, u32 length, char *buf)
4861{
4862 u32 value, rem, offset = 0, bar = 0;
4863 u32 index, work_offset, dw_length;
4864 u32 shift_value, gsm_base, gsm_dump_offset;
4865 char *direct_data;
4866 struct Scsi_Host *shost = class_to_shost(cdev);
4867 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
4868 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
4869
4870 direct_data = buf;
4871 gsm_dump_offset = pm8001_ha->fatal_forensic_shift_offset;
4872
4873 /* check max is 1 Mbytes */
4874 if ((length > 0x100000) || (gsm_dump_offset & 3) ||
4875 ((gsm_dump_offset + length) > 0x1000000))
Viswas Gcf370062013-12-10 10:31:38 +05304876 return -EINVAL;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304877
4878 if (pm8001_ha->chip_id == chip_8001)
4879 bar = 2;
4880 else
4881 bar = 1;
4882
4883 work_offset = gsm_dump_offset & 0xFFFF0000;
4884 offset = gsm_dump_offset & 0x0000FFFF;
4885 gsm_dump_offset = work_offset;
4886 /* adjust length to dword boundary */
4887 rem = length & 3;
4888 dw_length = length >> 2;
4889
4890 for (index = 0; index < dw_length; index++) {
4891 if ((work_offset + offset) & 0xFFFF0000) {
4892 if (pm8001_ha->chip_id == chip_8001)
4893 shift_value = ((gsm_dump_offset + offset) &
4894 SHIFT_REG_64K_MASK);
4895 else
4896 shift_value = (((gsm_dump_offset + offset) &
4897 SHIFT_REG_64K_MASK) >>
4898 SHIFT_REG_BIT_SHIFT);
4899
4900 if (pm8001_ha->chip_id == chip_8001) {
4901 gsm_base = GSM_BASE;
4902 if (-1 == pm8001_bar4_shift(pm8001_ha,
4903 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05304904 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304905 } else {
4906 gsm_base = 0;
4907 if (-1 == pm80xx_bar4_shift(pm8001_ha,
4908 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05304909 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304910 }
4911 gsm_dump_offset = (gsm_dump_offset + offset) &
4912 0xFFFF0000;
4913 work_offset = 0;
4914 offset = offset & 0x0000FFFF;
4915 }
4916 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
4917 0x0000FFFF);
4918 direct_data += sprintf(direct_data, "%08x ", value);
4919 offset += 4;
4920 }
4921 if (rem != 0) {
4922 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
4923 0x0000FFFF);
4924 /* xfr for non_dw */
4925 direct_data += sprintf(direct_data, "%08x ", value);
4926 }
4927 /* Shift back to BAR4 original address */
Viswas G859b5d12013-12-10 10:31:28 +05304928 if (-1 == pm8001_bar4_shift(pm8001_ha, 0))
Viswas Gcf370062013-12-10 10:31:38 +05304929 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304930 pm8001_ha->fatal_forensic_shift_offset += 1024;
4931
4932 if (pm8001_ha->fatal_forensic_shift_offset >= 0x100000)
4933 pm8001_ha->fatal_forensic_shift_offset = 0;
4934 return direct_data - buf;
4935}
4936
Sakthivel Kf74cf272013-02-27 20:27:43 +05304937int
jack wangdbf9bfe2009-10-14 16:19:21 +08004938pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
4939 struct pm8001_device *pm8001_dev, u32 state)
4940{
4941 struct set_dev_state_req payload;
4942 struct inbound_queue_table *circularQ;
4943 struct pm8001_ccb_info *ccb;
jack_wang72d0baa2009-11-05 22:33:35 +08004944 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004945 u32 tag;
4946 u32 opc = OPC_INB_SET_DEVICE_STATE;
jack_wang72d0baa2009-11-05 22:33:35 +08004947 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08004948 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4949 if (rc)
4950 return -1;
4951 ccb = &pm8001_ha->ccb_info[tag];
4952 ccb->ccb_tag = tag;
4953 ccb->device = pm8001_dev;
4954 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4955 payload.tag = cpu_to_le32(tag);
4956 payload.device_id = cpu_to_le32(pm8001_dev->device_id);
4957 payload.nds = cpu_to_le32(state);
peter chang91a43fa2019-11-14 15:39:05 +05304958 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4959 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004960 return rc;
4961
jack_wangd0b68042009-11-05 22:32:31 +08004962}
4963
4964static int
4965pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
4966{
4967 struct sas_re_initialization_req payload;
4968 struct inbound_queue_table *circularQ;
4969 struct pm8001_ccb_info *ccb;
4970 int rc;
4971 u32 tag;
4972 u32 opc = OPC_INB_SAS_RE_INITIALIZE;
4973 memset(&payload, 0, sizeof(payload));
4974 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4975 if (rc)
Tomas Henzl5533abc2014-07-09 17:20:49 +05304976 return -ENOMEM;
jack_wangd0b68042009-11-05 22:32:31 +08004977 ccb = &pm8001_ha->ccb_info[tag];
4978 ccb->ccb_tag = tag;
4979 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4980 payload.tag = cpu_to_le32(tag);
4981 payload.SSAHOLT = cpu_to_le32(0xd << 25);
4982 payload.sata_hol_tmo = cpu_to_le32(80);
4983 payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff);
peter chang91a43fa2019-11-14 15:39:05 +05304984 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4985 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304986 if (rc)
4987 pm8001_tag_free(pm8001_ha, tag);
jack_wangd0b68042009-11-05 22:32:31 +08004988 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004989
4990}
4991
4992const struct pm8001_dispatch pm8001_8001_dispatch = {
4993 .name = "pmc8001",
4994 .chip_init = pm8001_chip_init,
4995 .chip_soft_rst = pm8001_chip_soft_rst,
4996 .chip_rst = pm8001_hw_chip_rst,
4997 .chip_iounmap = pm8001_chip_iounmap,
4998 .isr = pm8001_chip_isr,
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004999 .is_our_interrupt = pm8001_chip_is_our_interrupt,
jack wangdbf9bfe2009-10-14 16:19:21 +08005000 .isr_process_oq = process_oq,
5001 .interrupt_enable = pm8001_chip_interrupt_enable,
5002 .interrupt_disable = pm8001_chip_interrupt_disable,
5003 .make_prd = pm8001_chip_make_sg,
5004 .smp_req = pm8001_chip_smp_req,
5005 .ssp_io_req = pm8001_chip_ssp_io_req,
5006 .sata_req = pm8001_chip_sata_req,
5007 .phy_start_req = pm8001_chip_phy_start_req,
5008 .phy_stop_req = pm8001_chip_phy_stop_req,
5009 .reg_dev_req = pm8001_chip_reg_dev_req,
5010 .dereg_dev_req = pm8001_chip_dereg_dev_req,
5011 .phy_ctl_req = pm8001_chip_phy_ctl_req,
5012 .task_abort = pm8001_chip_abort_task,
5013 .ssp_tm_req = pm8001_chip_ssp_tm_req,
5014 .get_nvmd_req = pm8001_chip_get_nvmd_req,
5015 .set_nvmd_req = pm8001_chip_set_nvmd_req,
5016 .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
5017 .set_dev_state_req = pm8001_chip_set_dev_state_req,
jack_wangd0b68042009-11-05 22:32:31 +08005018 .sas_re_init_req = pm8001_chip_sas_re_initialization,
akshatzena961ea02021-01-09 18:08:43 +05305019 .fatal_errors = pm80xx_fatal_errors,
jack wangdbf9bfe2009-10-14 16:19:21 +08005020};