blob: 0fb04cec5fe2acb0a56a7e14efb95604fecddf45 [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;
Viswas Gb4314722021-04-15 16:03:51 +0530243 pm8001_write_32(pm8001_ha->inbnd_q_tbl[i].ci_virt, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800244 offsetib = i * 0x20;
245 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
246 get_pci_bar_index(pm8001_mr32(addressib,
247 (offsetib + 0x14)));
248 pm8001_ha->inbnd_q_tbl[i].pi_offset =
249 pm8001_mr32(addressib, (offsetib + 0x18));
250 pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
251 pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
252 }
Viswas G65df7d12021-04-02 11:12:12 +0530253 for (i = 0; i < pm8001_ha->max_q_num; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800254 pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200255 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800256 pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530257 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800258 pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530259 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800260 pm8001_ha->outbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530261 (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800262 pm8001_ha->outbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530263 pm8001_ha->memoryMap.region[ob_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800264 pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530265 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800266 pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530267 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800268 pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530269 0 | (10 << 16) | (i << 24);
jack wangdbf9bfe2009-10-14 16:19:21 +0800270 pm8001_ha->outbnd_q_tbl[i].pi_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530271 pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
Viswas Gb4314722021-04-15 16:03:51 +0530272 pm8001_write_32(pm8001_ha->outbnd_q_tbl[i].pi_virt, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800273 offsetob = i * 0x24;
274 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
275 get_pci_bar_index(pm8001_mr32(addressob,
276 offsetob + 0x14));
277 pm8001_ha->outbnd_q_tbl[i].ci_offset =
278 pm8001_mr32(addressob, (offsetob + 0x18));
279 pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
280 pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
281 }
282}
283
284/**
285 * update_main_config_table - update the main default table to the HBA.
286 * @pm8001_ha: our hba card information
287 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800288static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800289{
290 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
291 pm8001_mw32(address, 0x24,
Sakthivel Ke5742102013-04-17 16:26:36 +0530292 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd);
jack wangdbf9bfe2009-10-14 16:19:21 +0800293 pm8001_mw32(address, 0x28,
Sakthivel Ke5742102013-04-17 16:26:36 +0530294 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800295 pm8001_mw32(address, 0x2C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530296 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800297 pm8001_mw32(address, 0x30,
Sakthivel Ke5742102013-04-17 16:26:36 +0530298 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800299 pm8001_mw32(address, 0x34,
Sakthivel Ke5742102013-04-17 16:26:36 +0530300 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800301 pm8001_mw32(address, 0x38,
Sakthivel Ke5742102013-04-17 16:26:36 +0530302 pm8001_ha->main_cfg_tbl.pm8001_tbl.
303 outbound_tgt_ITNexus_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800304 pm8001_mw32(address, 0x3C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530305 pm8001_ha->main_cfg_tbl.pm8001_tbl.
306 outbound_tgt_ITNexus_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800307 pm8001_mw32(address, 0x40,
Sakthivel Ke5742102013-04-17 16:26:36 +0530308 pm8001_ha->main_cfg_tbl.pm8001_tbl.
309 outbound_tgt_ssp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800310 pm8001_mw32(address, 0x44,
Sakthivel Ke5742102013-04-17 16:26:36 +0530311 pm8001_ha->main_cfg_tbl.pm8001_tbl.
312 outbound_tgt_ssp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800313 pm8001_mw32(address, 0x48,
Sakthivel Ke5742102013-04-17 16:26:36 +0530314 pm8001_ha->main_cfg_tbl.pm8001_tbl.
315 outbound_tgt_smp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800316 pm8001_mw32(address, 0x4C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530317 pm8001_ha->main_cfg_tbl.pm8001_tbl.
318 outbound_tgt_smp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800319 pm8001_mw32(address, 0x50,
Sakthivel Ke5742102013-04-17 16:26:36 +0530320 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800321 pm8001_mw32(address, 0x54,
Sakthivel Ke5742102013-04-17 16:26:36 +0530322 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr);
323 pm8001_mw32(address, 0x58,
324 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size);
325 pm8001_mw32(address, 0x5C,
326 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800327 pm8001_mw32(address, 0x60,
Sakthivel Ke5742102013-04-17 16:26:36 +0530328 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800329 pm8001_mw32(address, 0x64,
Sakthivel Ke5742102013-04-17 16:26:36 +0530330 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr);
331 pm8001_mw32(address, 0x68,
332 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size);
jack wangdbf9bfe2009-10-14 16:19:21 +0800333 pm8001_mw32(address, 0x6C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530334 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800335 pm8001_mw32(address, 0x70,
Sakthivel Ke5742102013-04-17 16:26:36 +0530336 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt);
jack wangdbf9bfe2009-10-14 16:19:21 +0800337}
338
339/**
340 * update_inbnd_queue_table - update the inbound queue table to the HBA.
341 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100342 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800343 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800344static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
345 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800346{
347 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
348 u16 offset = number * 0x20;
349 pm8001_mw32(address, offset + 0x00,
350 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
351 pm8001_mw32(address, offset + 0x04,
352 pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
353 pm8001_mw32(address, offset + 0x08,
354 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
355 pm8001_mw32(address, offset + 0x0C,
356 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
357 pm8001_mw32(address, offset + 0x10,
358 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
359}
360
361/**
362 * update_outbnd_queue_table - update the outbound queue table to the HBA.
363 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100364 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800365 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800366static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
367 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800368{
369 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
370 u16 offset = number * 0x24;
371 pm8001_mw32(address, offset + 0x00,
372 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
373 pm8001_mw32(address, offset + 0x04,
374 pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
375 pm8001_mw32(address, offset + 0x08,
376 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
377 pm8001_mw32(address, offset + 0x0C,
378 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
379 pm8001_mw32(address, offset + 0x10,
380 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
381 pm8001_mw32(address, offset + 0x1C,
382 pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
383}
384
385/**
Mark Salyzynd95d0002012-01-17 09:18:57 -0500386 * pm8001_bar4_shift - function is called to shift BAR base address
387 * @pm8001_ha : our hba card infomation
jack wangdbf9bfe2009-10-14 16:19:21 +0800388 * @shiftValue : shifting value in memory bar.
389 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500390int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue)
jack wangdbf9bfe2009-10-14 16:19:21 +0800391{
392 u32 regVal;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500393 unsigned long start;
jack wangdbf9bfe2009-10-14 16:19:21 +0800394
395 /* program the inbound AXI translation Lower Address */
396 pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue);
397
398 /* confirm the setting is written */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500399 start = jiffies + HZ; /* 1 sec */
jack wangdbf9bfe2009-10-14 16:19:21 +0800400 do {
jack wangdbf9bfe2009-10-14 16:19:21 +0800401 regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW);
Mark Salyzynd95d0002012-01-17 09:18:57 -0500402 } while ((regVal != shiftValue) && time_before(jiffies, start));
jack wangdbf9bfe2009-10-14 16:19:21 +0800403
Mark Salyzynd95d0002012-01-17 09:18:57 -0500404 if (regVal != shiftValue) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800405 pm8001_dbg(pm8001_ha, INIT,
406 "TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW = 0x%x\n",
407 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800408 return -1;
409 }
410 return 0;
411}
412
413/**
414 * mpi_set_phys_g3_with_ssc
415 * @pm8001_ha: our hba card information
416 * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc.
417 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800418static void mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha,
419 u32 SSCbit)
jack wangdbf9bfe2009-10-14 16:19:21 +0800420{
Lee Jonesa364a3e2020-11-16 10:41:19 +0000421 u32 offset, i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500422 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800423
424#define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000
425#define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000
426#define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074
427#define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074
jack_wangd0b68042009-11-05 22:32:31 +0800428#define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12
429#define PHY_G3_WITH_SSC_BIT_SHIFT 13
430#define SNW3_PHY_CAPABILITIES_PARITY 31
jack wangdbf9bfe2009-10-14 16:19:21 +0800431
432 /*
433 * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3)
434 * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7)
435 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500436 spin_lock_irqsave(&pm8001_ha->lock, flags);
437 if (-1 == pm8001_bar4_shift(pm8001_ha,
438 SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) {
439 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800440 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500441 }
jack wang0330dba2009-12-07 17:46:22 +0800442
jack wangdbf9bfe2009-10-14 16:19:21 +0800443 for (i = 0; i < 4; i++) {
444 offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i;
jack wang0330dba2009-12-07 17:46:22 +0800445 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800446 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800447 /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500448 if (-1 == pm8001_bar4_shift(pm8001_ha,
449 SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) {
450 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800451 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500452 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800453 for (i = 4; i < 8; i++) {
454 offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
jack wang0330dba2009-12-07 17:46:22 +0800455 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800456 }
jack wang0330dba2009-12-07 17:46:22 +0800457 /*************************************************************
458 Change the SSC upspreading value to 0x0 so that upspreading is disabled.
459 Device MABC SMOD0 Controls
460 Address: (via MEMBASE-III):
461 Using shifted destination address 0x0_0000: with Offset 0xD8
462
463 31:28 R/W Reserved Do not change
464 27:24 R/W SAS_SMOD_SPRDUP 0000
465 23:20 R/W SAS_SMOD_SPRDDN 0000
466 19:0 R/W Reserved Do not change
467 Upon power-up this register will read as 0x8990c016,
468 and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000
469 so that the written value will be 0x8090c016.
470 This will ensure only down-spreading SSC is enabled on the SPC.
471 *************************************************************/
Lee Jonesa364a3e2020-11-16 10:41:19 +0000472 pm8001_cr32(pm8001_ha, 2, 0xd8);
jack wang0330dba2009-12-07 17:46:22 +0800473 pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016);
jack wangdbf9bfe2009-10-14 16:19:21 +0800474
475 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500476 pm8001_bar4_shift(pm8001_ha, 0x0);
477 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800478 return;
479}
480
481/**
482 * mpi_set_open_retry_interval_reg
483 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100484 * @interval: interval time for each OPEN_REJECT (RETRY). The units are in 1us.
jack wangdbf9bfe2009-10-14 16:19:21 +0800485 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800486static void mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha,
487 u32 interval)
jack wangdbf9bfe2009-10-14 16:19:21 +0800488{
489 u32 offset;
490 u32 value;
491 u32 i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500492 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800493
494#define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000
495#define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000
496#define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4
497#define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4
498#define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF
499
500 value = interval & OPEN_RETRY_INTERVAL_REG_MASK;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500501 spin_lock_irqsave(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800502 /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/
Mark Salyzynd95d0002012-01-17 09:18:57 -0500503 if (-1 == pm8001_bar4_shift(pm8001_ha,
504 OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) {
505 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800506 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500507 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800508 for (i = 0; i < 4; i++) {
509 offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i;
510 pm8001_cw32(pm8001_ha, 2, offset, value);
511 }
512
Mark Salyzynd95d0002012-01-17 09:18:57 -0500513 if (-1 == pm8001_bar4_shift(pm8001_ha,
514 OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) {
515 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800516 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500517 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800518 for (i = 4; i < 8; i++) {
519 offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
520 pm8001_cw32(pm8001_ha, 2, offset, value);
521 }
522 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500523 pm8001_bar4_shift(pm8001_ha, 0x0);
524 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800525 return;
526}
527
528/**
529 * mpi_init_check - check firmware initialization status.
530 * @pm8001_ha: our hba card information
531 */
532static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
533{
534 u32 max_wait_count;
535 u32 value;
536 u32 gst_len_mpistate;
537 /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
538 table is updated */
539 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE);
540 /* wait until Inbound DoorBell Clear Register toggled */
541 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
542 do {
543 udelay(1);
544 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
545 value &= SPC_MSGU_CFG_TABLE_UPDATE;
546 } while ((value != 0) && (--max_wait_count));
547
548 if (!max_wait_count)
549 return -1;
550 /* check the MPI-State for initialization */
551 gst_len_mpistate =
552 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
553 GST_GSTLEN_MPIS_OFFSET);
554 if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK))
555 return -1;
556 /* check MPI Initialization error */
557 gst_len_mpistate = gst_len_mpistate >> 16;
558 if (0x0000 != gst_len_mpistate)
559 return -1;
560 return 0;
561}
562
563/**
564 * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
565 * @pm8001_ha: our hba card information
566 */
567static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
568{
569 u32 value, value1;
570 u32 max_wait_count;
571 /* check error state */
572 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
573 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
574 /* check AAP error */
575 if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) {
576 /* error state */
577 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
578 return -1;
579 }
580
581 /* check IOP error */
582 if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) {
583 /* error state */
584 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
585 return -1;
586 }
587
588 /* bit 4-31 of scratch pad1 should be zeros if it is not
589 in error state*/
590 if (value & SCRATCH_PAD1_STATE_MASK) {
591 /* error case */
592 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
593 return -1;
594 }
595
596 /* bit 2, 4-31 of scratch pad2 should be zeros if it is not
597 in error state */
598 if (value1 & SCRATCH_PAD2_STATE_MASK) {
599 /* error case */
600 return -1;
601 }
602
603 max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */
604
605 /* wait until scratch pad 1 and 2 registers in ready state */
606 do {
607 udelay(1);
608 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
609 & SCRATCH_PAD1_RDY;
610 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
611 & SCRATCH_PAD2_RDY;
612 if ((--max_wait_count) == 0)
613 return -1;
614 } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY));
615 return 0;
616}
617
618static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
619{
620 void __iomem *base_addr;
621 u32 value;
622 u32 offset;
623 u32 pcibar;
624 u32 pcilogic;
625
626 value = pm8001_cr32(pm8001_ha, 0, 0x44);
627 offset = value & 0x03FFFFFF;
Joe Perches1b5d2792020-11-20 15:16:09 -0800628 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 Offset: %x\n", offset);
jack wangdbf9bfe2009-10-14 16:19:21 +0800629 pcilogic = (value & 0xFC000000) >> 26;
630 pcibar = get_pci_bar_index(pcilogic);
Joe Perches1b5d2792020-11-20 15:16:09 -0800631 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar);
jack wangdbf9bfe2009-10-14 16:19:21 +0800632 pm8001_ha->main_cfg_tbl_addr = base_addr =
633 pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
634 pm8001_ha->general_stat_tbl_addr =
635 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18);
636 pm8001_ha->inbnd_q_tbl_addr =
637 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C);
638 pm8001_ha->outbnd_q_tbl_addr =
639 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20);
640}
641
642/**
643 * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
644 * @pm8001_ha: our hba card information
645 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800646static int pm8001_chip_init(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800647{
Colin Ian King40fa7392021-04-07 14:58:40 +0100648 u32 i = 0;
Sakthivel K54792dc2013-03-19 18:05:55 +0530649 u16 deviceid;
650 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
651 /* 8081 controllers need BAR shift to access MPI space
652 * as this is shared with BIOS data */
Bradley Grove81b86d42013-12-19 10:50:57 -0500653 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530654 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800655 pm8001_dbg(pm8001_ha, FAIL,
656 "Shift Bar4 to 0x%x failed\n",
657 GSM_SM_BASE);
Sakthivel K54792dc2013-03-19 18:05:55 +0530658 return -1;
659 }
660 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800661 /* check the firmware status */
662 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800663 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800664 return -EBUSY;
665 }
666
667 /* Initialize pci space address eg: mpi offset */
668 init_pci_device_addresses(pm8001_ha);
669 init_default_table_values(pm8001_ha);
670 read_main_config_table(pm8001_ha);
671 read_general_status_table(pm8001_ha);
672 read_inbnd_queue_table(pm8001_ha);
673 read_outbnd_queue_table(pm8001_ha);
674 /* update main config table ,inbound table and outbound table */
675 update_main_config_table(pm8001_ha);
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_inbnd_queue_table(pm8001_ha, i);
Viswas G65df7d12021-04-02 11:12:12 +0530678 for (i = 0; i < pm8001_ha->max_q_num; i++)
Sakthivel Ke590adf2013-02-27 20:25:25 +0530679 update_outbnd_queue_table(pm8001_ha, i);
Sakthivel K54792dc2013-03-19 18:05:55 +0530680 /* 8081 controller donot require these operations */
Bradley Grove81b86d42013-12-19 10:50:57 -0500681 if (deviceid != 0x8081 && deviceid != 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530682 mpi_set_phys_g3_with_ssc(pm8001_ha, 0);
683 /* 7->130ms, 34->500ms, 119->1.5s */
684 mpi_set_open_retry_interval_reg(pm8001_ha, 119);
685 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800686 /* notify firmware update finished and check initialization status */
687 if (0 == mpi_init_check(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800688 pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800689 } else
690 return -EBUSY;
691 /*This register is a 16-bit timer with a resolution of 1us. This is the
692 timer used for interrupt delay/coalescing in the PCIe Application Layer.
693 Zero is not a valid value. A value of 1 in the register will cause the
694 interrupts to be normal. A value greater than 1 will cause coalescing
695 delays.*/
696 pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1);
697 pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0);
698 return 0;
699}
700
701static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
702{
703 u32 max_wait_count;
704 u32 value;
705 u32 gst_len_mpistate;
Sakthivel K54792dc2013-03-19 18:05:55 +0530706 u16 deviceid;
707 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
Bradley Grove81b86d42013-12-19 10:50:57 -0500708 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530709 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800710 pm8001_dbg(pm8001_ha, FAIL,
711 "Shift Bar4 to 0x%x failed\n",
712 GSM_SM_BASE);
Sakthivel K54792dc2013-03-19 18:05:55 +0530713 return -1;
714 }
715 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800716 init_pci_device_addresses(pm8001_ha);
717 /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
718 table is stop */
719 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET);
720
721 /* wait until Inbound DoorBell Clear Register toggled */
722 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
723 do {
724 udelay(1);
725 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
726 value &= SPC_MSGU_CFG_TABLE_RESET;
727 } while ((value != 0) && (--max_wait_count));
728
729 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800730 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=0x%x\n",
731 value);
jack wangdbf9bfe2009-10-14 16:19:21 +0800732 return -1;
733 }
734
735 /* check the MPI-State for termination in progress */
736 /* wait until Inbound DoorBell Clear Register toggled */
737 max_wait_count = 1 * 1000 * 1000; /* 1 sec */
738 do {
739 udelay(1);
740 gst_len_mpistate =
741 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
742 GST_GSTLEN_MPIS_OFFSET);
743 if (GST_MPI_STATE_UNINIT ==
744 (gst_len_mpistate & GST_MPI_STATE_MASK))
745 break;
746 } while (--max_wait_count);
747 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800748 pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n",
749 gst_len_mpistate & GST_MPI_STATE_MASK);
jack wangdbf9bfe2009-10-14 16:19:21 +0800750 return -1;
751 }
752 return 0;
753}
754
755/**
756 * soft_reset_ready_check - Function to check FW is ready for soft reset.
757 * @pm8001_ha: our hba card information
758 */
759static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha)
760{
761 u32 regVal, regVal1, regVal2;
762 if (mpi_uninit_check(pm8001_ha) != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800763 pm8001_dbg(pm8001_ha, FAIL, "MPI state is not ready\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800764 return -1;
765 }
766 /* read the scratch pad 2 register bit 2 */
767 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
768 & SCRATCH_PAD2_FWRDY_RST;
769 if (regVal == SCRATCH_PAD2_FWRDY_RST) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800770 pm8001_dbg(pm8001_ha, INIT, "Firmware is ready for reset.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800771 } else {
Mark Salyzynd95d0002012-01-17 09:18:57 -0500772 unsigned long flags;
773 /* Trigger NMI twice via RB6 */
774 spin_lock_irqsave(&pm8001_ha->lock, flags);
775 if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) {
776 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800777 pm8001_dbg(pm8001_ha, FAIL,
778 "Shift Bar4 to 0x%x failed\n",
779 RB6_ACCESS_REG);
jack wangdbf9bfe2009-10-14 16:19:21 +0800780 return -1;
781 }
782 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET,
783 RB6_MAGIC_NUMBER_RST);
784 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST);
785 /* wait for 100 ms */
786 mdelay(100);
787 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) &
788 SCRATCH_PAD2_FWRDY_RST;
789 if (regVal != SCRATCH_PAD2_FWRDY_RST) {
790 regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
791 regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
Joe Perches1b5d2792020-11-20 15:16:09 -0800792 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:MSGU_SCRATCH_PAD1=0x%x, MSGU_SCRATCH_PAD2=0x%x\n",
793 regVal1, regVal2);
794 pm8001_dbg(pm8001_ha, FAIL,
795 "SCRATCH_PAD0 value = 0x%x\n",
796 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0));
797 pm8001_dbg(pm8001_ha, FAIL,
798 "SCRATCH_PAD3 value = 0x%x\n",
799 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -0500800 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800801 return -1;
802 }
Mark Salyzynd95d0002012-01-17 09:18:57 -0500803 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800804 }
805 return 0;
806}
807
808/**
809 * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
810 * the FW register status to the originated status.
811 * @pm8001_ha: our hba card information
jack wangdbf9bfe2009-10-14 16:19:21 +0800812 */
813static int
Sakthivel Kf5860992013-04-17 16:37:02 +0530814pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800815{
816 u32 regVal, toggleVal;
817 u32 max_wait_count;
818 u32 regVal1, regVal2, regVal3;
Sakthivel Kf5860992013-04-17 16:37:02 +0530819 u32 signature = 0x252acbcd; /* for host scratch pad0 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500820 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800821
822 /* step1: Check FW is ready for soft reset */
823 if (soft_reset_ready_check(pm8001_ha) != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800824 pm8001_dbg(pm8001_ha, FAIL, "FW is not ready\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800825 return -1;
826 }
827
828 /* step 2: clear NMI status register on AAP1 and IOP, write the same
829 value to clear */
830 /* map 0x60000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500831 spin_lock_irqsave(&pm8001_ha->lock, flags);
832 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) {
833 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800834 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
835 MBIC_AAP1_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800836 return -1;
837 }
838 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP);
Joe Perches1b5d2792020-11-20 15:16:09 -0800839 pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (IOP)= 0x%x\n",
840 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800841 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0);
842 /* map 0x70000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500843 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) {
844 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800845 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
846 MBIC_IOP_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800847 return -1;
848 }
849 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1);
Joe Perches1b5d2792020-11-20 15:16:09 -0800850 pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n",
851 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800852 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0);
853
854 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800855 pm8001_dbg(pm8001_ha, INIT, "PCIE -Event Interrupt Enable = 0x%x\n",
856 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800857 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0);
858
859 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT);
Joe Perches1b5d2792020-11-20 15:16:09 -0800860 pm8001_dbg(pm8001_ha, INIT, "PCIE - Event Interrupt = 0x%x\n",
861 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800862 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal);
863
864 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800865 pm8001_dbg(pm8001_ha, INIT, "PCIE -Error Interrupt Enable = 0x%x\n",
866 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800867 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0);
868
869 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT);
Joe Perches1b5d2792020-11-20 15:16:09 -0800870 pm8001_dbg(pm8001_ha, INIT, "PCIE - Error Interrupt = 0x%x\n", regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800871 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal);
872
873 /* read the scratch pad 1 register bit 2 */
874 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
875 & SCRATCH_PAD1_RST;
876 toggleVal = regVal ^ SCRATCH_PAD1_RST;
877
878 /* set signature in host scratch pad0 register to tell SPC that the
879 host performs the soft reset */
880 pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature);
881
882 /* read required registers for confirmming */
883 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500884 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
885 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800886 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
887 GSM_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800888 return -1;
889 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800890 pm8001_dbg(pm8001_ha, INIT,
891 "GSM 0x0(0x00007b88)-GSM Configuration and Reset = 0x%x\n",
892 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +0800893
894 /* step 3: host read GSM Configuration and Reset register */
895 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
896 /* Put those bits to low */
897 /* GSM XCBI offset = 0x70 0000
898 0x00 Bit 13 COM_SLV_SW_RSTB 1
899 0x00 Bit 12 QSSP_SW_RSTB 1
900 0x00 Bit 11 RAAE_SW_RSTB 1
901 0x00 Bit 9 RB_1_SW_RSTB 1
902 0x00 Bit 8 SM_SW_RSTB 1
903 */
904 regVal &= ~(0x00003b00);
905 /* host write GSM Configuration and Reset register */
906 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
Joe Perches1b5d2792020-11-20 15:16:09 -0800907 pm8001_dbg(pm8001_ha, INIT,
908 "GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM Configuration and Reset is set to = 0x%x\n",
909 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +0800910
911 /* step 4: */
912 /* disable GSM - Read Address Parity Check */
913 regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800914 pm8001_dbg(pm8001_ha, INIT,
915 "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n",
916 regVal1);
jack wangdbf9bfe2009-10-14 16:19:21 +0800917 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800918 pm8001_dbg(pm8001_ha, INIT,
919 "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n",
920 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800921
922 /* disable GSM - Write Address Parity Check */
923 regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800924 pm8001_dbg(pm8001_ha, INIT,
925 "GSM 0x700040 - Write Address Parity Check Enable = 0x%x\n",
926 regVal2);
jack wangdbf9bfe2009-10-14 16:19:21 +0800927 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800928 pm8001_dbg(pm8001_ha, INIT,
929 "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n",
930 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800931
932 /* disable GSM - Write Data Parity Check */
933 regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800934 pm8001_dbg(pm8001_ha, INIT, "GSM 0x300048 - Write Data Parity Check Enable = 0x%x\n",
935 regVal3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800936 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800937 pm8001_dbg(pm8001_ha, INIT,
938 "GSM 0x300048 - Write Data Parity Check Enable is set to = 0x%x\n",
939 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800940
941 /* step 5: delay 10 usec */
942 udelay(10);
943 /* step 5-b: set GPIO-0 output control to tristate anyway */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500944 if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) {
945 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800946 pm8001_dbg(pm8001_ha, INIT, "Shift Bar4 to 0x%x failed\n",
947 GPIO_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800948 return -1;
949 }
950 regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800951 pm8001_dbg(pm8001_ha, INIT, "GPIO Output Control Register: = 0x%x\n",
952 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800953 /* set GPIO-0 output control to tri-state */
954 regVal &= 0xFFFFFFFC;
955 pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal);
956
957 /* Step 6: Reset the IOP and AAP1 */
958 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500959 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
960 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800961 pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n",
962 SPC_TOP_LEVEL_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800963 return -1;
964 }
965 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800966 pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting IOP/AAP1:= 0x%x\n",
967 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800968 regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
969 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
970
971 /* step 7: Reset the BDMA/OSSP */
972 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800973 pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting BDMA/OSSP: = 0x%x\n",
974 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800975 regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
976 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
977
978 /* step 8: delay 10 usec */
979 udelay(10);
980
981 /* step 9: bring the BDMA and OSSP out of reset */
982 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800983 pm8001_dbg(pm8001_ha, INIT,
984 "Top Register before bringing up BDMA/OSSP:= 0x%x\n",
985 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800986 regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
987 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
988
989 /* step 10: delay 10 usec */
990 udelay(10);
991
992 /* step 11: reads and sets the GSM Configuration and Reset Register */
993 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500994 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
995 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800996 pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n",
997 GSM_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800998 return -1;
999 }
Joe Perches1b5d2792020-11-20 15:16:09 -08001000 pm8001_dbg(pm8001_ha, INIT,
1001 "GSM 0x0 (0x00007b88)-GSM Configuration and Reset = 0x%x\n",
1002 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +08001003 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
1004 /* Put those bits to high */
1005 /* GSM XCBI offset = 0x70 0000
1006 0x00 Bit 13 COM_SLV_SW_RSTB 1
1007 0x00 Bit 12 QSSP_SW_RSTB 1
1008 0x00 Bit 11 RAAE_SW_RSTB 1
1009 0x00 Bit 9 RB_1_SW_RSTB 1
1010 0x00 Bit 8 SM_SW_RSTB 1
1011 */
1012 regVal |= (GSM_CONFIG_RESET_VALUE);
1013 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
Joe Perches1b5d2792020-11-20 15:16:09 -08001014 pm8001_dbg(pm8001_ha, INIT, "GSM (0x00004088 ==> 0x00007b88) - GSM Configuration and Reset is set to = 0x%x\n",
1015 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +08001016
1017 /* step 12: Restore GSM - Read Address Parity Check */
1018 regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
1019 /* just for debugging */
Joe Perches1b5d2792020-11-20 15:16:09 -08001020 pm8001_dbg(pm8001_ha, INIT,
1021 "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n",
1022 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +08001023 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001024 pm8001_dbg(pm8001_ha, INIT, "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n",
1025 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001026 /* Restore GSM - Write Address Parity Check */
1027 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
1028 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2);
Joe Perches1b5d2792020-11-20 15:16:09 -08001029 pm8001_dbg(pm8001_ha, INIT,
1030 "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n",
1031 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001032 /* Restore GSM - Write Data Parity Check */
1033 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
1034 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3);
Joe Perches1b5d2792020-11-20 15:16:09 -08001035 pm8001_dbg(pm8001_ha, INIT,
Colin Ian Kingc6131852020-11-24 09:38:28 +00001036 "GSM 0x700048 - Write Data Parity Check Enable is set to = 0x%x\n",
Joe Perches1b5d2792020-11-20 15:16:09 -08001037 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001038
1039 /* step 13: bring the IOP and AAP1 out of reset */
1040 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -05001041 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
1042 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08001043 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
1044 SPC_TOP_LEVEL_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001045 return -1;
1046 }
1047 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
1048 regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
1049 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
1050
1051 /* step 14: delay 10 usec - Normal Mode */
1052 udelay(10);
1053 /* check Soft Reset Normal mode or Soft Reset HDA mode */
1054 if (signature == SPC_SOFT_RESET_SIGNATURE) {
1055 /* step 15 (Normal Mode): wait until scratch pad1 register
1056 bit 2 toggled */
1057 max_wait_count = 2 * 1000 * 1000;/* 2 sec */
1058 do {
1059 udelay(1);
1060 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1061 SCRATCH_PAD1_RST;
1062 } while ((regVal != toggleVal) && (--max_wait_count));
1063
1064 if (!max_wait_count) {
1065 regVal = pm8001_cr32(pm8001_ha, 0,
1066 MSGU_SCRATCH_PAD_1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001067 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT : ToggleVal 0x%x,MSGU_SCRATCH_PAD1 = 0x%x\n",
1068 toggleVal, regVal);
1069 pm8001_dbg(pm8001_ha, FAIL,
1070 "SCRATCH_PAD0 value = 0x%x\n",
1071 pm8001_cr32(pm8001_ha, 0,
1072 MSGU_SCRATCH_PAD_0));
1073 pm8001_dbg(pm8001_ha, FAIL,
1074 "SCRATCH_PAD2 value = 0x%x\n",
1075 pm8001_cr32(pm8001_ha, 0,
1076 MSGU_SCRATCH_PAD_2));
1077 pm8001_dbg(pm8001_ha, FAIL,
1078 "SCRATCH_PAD3 value = 0x%x\n",
1079 pm8001_cr32(pm8001_ha, 0,
1080 MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001081 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001082 return -1;
1083 }
1084
1085 /* step 16 (Normal) - Clear ODMR and ODCR */
1086 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1087 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1088
1089 /* step 17 (Normal Mode): wait for the FW and IOP to get
1090 ready - 1 sec timeout */
1091 /* Wait for the SPC Configuration Table to be ready */
1092 if (check_fw_ready(pm8001_ha) == -1) {
1093 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1094 /* return error if MPI Configuration Table not ready */
Joe Perches1b5d2792020-11-20 15:16:09 -08001095 pm8001_dbg(pm8001_ha, INIT,
1096 "FW not ready SCRATCH_PAD1 = 0x%x\n",
1097 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +08001098 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1099 /* return error if MPI Configuration Table not ready */
Joe Perches1b5d2792020-11-20 15:16:09 -08001100 pm8001_dbg(pm8001_ha, INIT,
1101 "FW not ready SCRATCH_PAD2 = 0x%x\n",
1102 regVal);
1103 pm8001_dbg(pm8001_ha, INIT,
1104 "SCRATCH_PAD0 value = 0x%x\n",
1105 pm8001_cr32(pm8001_ha, 0,
1106 MSGU_SCRATCH_PAD_0));
1107 pm8001_dbg(pm8001_ha, INIT,
1108 "SCRATCH_PAD3 value = 0x%x\n",
1109 pm8001_cr32(pm8001_ha, 0,
1110 MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001111 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001112 return -1;
1113 }
1114 }
Mark Salyzynd95d0002012-01-17 09:18:57 -05001115 pm8001_bar4_shift(pm8001_ha, 0);
1116 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001117
Joe Perches1b5d2792020-11-20 15:16:09 -08001118 pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001119 return 0;
1120}
1121
1122static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1123{
1124 u32 i;
1125 u32 regVal;
Joe Perches1b5d2792020-11-20 15:16:09 -08001126 pm8001_dbg(pm8001_ha, INIT, "chip reset start\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001127
1128 /* do SPC chip reset. */
1129 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1130 regVal &= ~(SPC_REG_RESET_DEVICE);
1131 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1132
1133 /* delay 10 usec */
1134 udelay(10);
1135
1136 /* bring chip reset out of reset */
1137 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1138 regVal |= SPC_REG_RESET_DEVICE;
1139 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1140
1141 /* delay 10 usec */
1142 udelay(10);
1143
1144 /* wait for 20 msec until the firmware gets reloaded */
1145 i = 20;
1146 do {
1147 mdelay(1);
1148 } while ((--i) != 0);
1149
Joe Perches1b5d2792020-11-20 15:16:09 -08001150 pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001151}
1152
1153/**
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02001154 * pm8001_chip_iounmap - which maped when initialized.
jack wangdbf9bfe2009-10-14 16:19:21 +08001155 * @pm8001_ha: our hba card information
1156 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301157void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08001158{
1159 s8 bar, logical = 0;
Denis Efremovc9c13ba2019-09-28 02:43:08 +03001160 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001161 /*
1162 ** logical BARs for SPC:
1163 ** bar 0 and 1 - logical BAR0
1164 ** bar 2 and 3 - logical BAR1
1165 ** bar4 - logical BAR2
1166 ** bar5 - logical BAR3
1167 ** Skip the appropriate assignments:
1168 */
1169 if ((bar == 1) || (bar == 3))
1170 continue;
1171 if (pm8001_ha->io_mem[logical].memvirtaddr) {
1172 iounmap(pm8001_ha->io_mem[logical].memvirtaddr);
1173 logical++;
1174 }
1175 }
1176}
1177
Colin Ian King292c04c2019-03-28 23:43:28 +00001178#ifndef PM8001_USE_MSIX
jack wangdbf9bfe2009-10-14 16:19:21 +08001179/**
Lee Jones6b87e432021-03-03 14:46:19 +00001180 * pm8001_chip_intx_interrupt_enable - enable PM8001 chip interrupt
jack wangdbf9bfe2009-10-14 16:19:21 +08001181 * @pm8001_ha: our hba card information
1182 */
1183static void
1184pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1185{
1186 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1187 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1188}
1189
1190 /**
1191 * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
1192 * @pm8001_ha: our hba card information
1193 */
1194static void
1195pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1196{
1197 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL);
1198}
1199
Colin Ian King292c04c2019-03-28 23:43:28 +00001200#else
1201
jack wangdbf9bfe2009-10-14 16:19:21 +08001202/**
1203 * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt
1204 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001205 * @int_vec_idx: interrupt number to enable
jack wangdbf9bfe2009-10-14 16:19:21 +08001206 */
1207static void
1208pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha,
1209 u32 int_vec_idx)
1210{
1211 u32 msi_index;
1212 u32 value;
1213 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1214 msi_index += MSIX_TABLE_BASE;
1215 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE);
1216 value = (1 << int_vec_idx);
1217 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value);
1218
1219}
1220
1221/**
1222 * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt
1223 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001224 * @int_vec_idx: interrupt number to disable
jack wangdbf9bfe2009-10-14 16:19:21 +08001225 */
1226static void
1227pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha,
1228 u32 int_vec_idx)
1229{
1230 u32 msi_index;
1231 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1232 msi_index += MSIX_TABLE_BASE;
1233 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001234}
Colin Ian King292c04c2019-03-28 23:43:28 +00001235#endif
Mark Salyzynd95d0002012-01-17 09:18:57 -05001236
jack wangdbf9bfe2009-10-14 16:19:21 +08001237/**
1238 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1239 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001240 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001241 */
1242static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301243pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001244{
1245#ifdef PM8001_USE_MSIX
1246 pm8001_chip_msix_interrupt_enable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001247#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001248 pm8001_chip_intx_interrupt_enable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001249#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001250}
1251
1252/**
Lee Jones6b87e432021-03-03 14:46:19 +00001253 * pm8001_chip_interrupt_disable - disable PM8001 chip interrupt
jack wangdbf9bfe2009-10-14 16:19:21 +08001254 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001255 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001256 */
1257static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301258pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001259{
1260#ifdef PM8001_USE_MSIX
1261 pm8001_chip_msix_interrupt_disable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001262#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001263 pm8001_chip_intx_interrupt_disable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001264#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001265}
1266
1267/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301268 * pm8001_mpi_msg_free_get - get the free message buffer for transfer
1269 * inbound queue.
jack wangdbf9bfe2009-10-14 16:19:21 +08001270 * @circularQ: the inbound queue we want to transfer to HBA.
1271 * @messageSize: the message size of this transfer, normally it is 64 bytes
1272 * @messagePtr: the pointer to message.
1273 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301274int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ,
jack wangdbf9bfe2009-10-14 16:19:21 +08001275 u16 messageSize, void **messagePtr)
1276{
1277 u32 offset, consumer_index;
1278 struct mpi_msg_hdr *msgHeader;
1279 u8 bcCount = 1; /* only support single buffer */
1280
1281 /* Checks is the requested message size can be allocated in this queue*/
Sakthivel Kf74cf272013-02-27 20:27:43 +05301282 if (messageSize > IOMB_SIZE_SPCV) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001283 *messagePtr = NULL;
1284 return -1;
1285 }
1286
1287 /* Stores the new consumer index */
1288 consumer_index = pm8001_read_32(circularQ->ci_virt);
1289 circularQ->consumer_index = cpu_to_le32(consumer_index);
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001290 if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) ==
Santosh Nayak8270ee22012-02-26 20:14:46 +05301291 le32_to_cpu(circularQ->consumer_index)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001292 *messagePtr = NULL;
1293 return -1;
1294 }
1295 /* get memory IOMB buffer address */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301296 offset = circularQ->producer_idx * messageSize;
jack wangdbf9bfe2009-10-14 16:19:21 +08001297 /* increment to next bcCount element */
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001298 circularQ->producer_idx = (circularQ->producer_idx + bcCount)
1299 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001300 /* Adds that distance to the base of the region virtual address plus
1301 the message header size*/
1302 msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset);
1303 *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr);
1304 return 0;
1305}
1306
1307/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301308 * pm8001_mpi_build_cmd- build the message queue for transfer, update the PI to
1309 * FW to tell the fw to get this message from IOMB.
jack wangdbf9bfe2009-10-14 16:19:21 +08001310 * @pm8001_ha: our hba card information
1311 * @circularQ: the inbound queue we want to transfer to HBA.
1312 * @opCode: the operation code represents commands which LLDD and fw recognized.
1313 * @payload: the command payload of each operation command.
peter chang91a43fa2019-11-14 15:39:05 +05301314 * @nb: size in bytes of the command payload
1315 * @responseQueue: queue to interrupt on w/ command response (if any)
jack wangdbf9bfe2009-10-14 16:19:21 +08001316 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301317int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001318 struct inbound_queue_table *circularQ,
peter chang91a43fa2019-11-14 15:39:05 +05301319 u32 opCode, void *payload, size_t nb,
1320 u32 responseQueue)
jack wangdbf9bfe2009-10-14 16:19:21 +08001321{
1322 u32 Header = 0, hpriority = 0, bc = 1, category = 0x02;
jack wangdbf9bfe2009-10-14 16:19:21 +08001323 void *pMessage;
peter chang7640e1e2020-11-02 22:25:25 +05301324 unsigned long flags;
1325 int q_index = circularQ - pm8001_ha->inbnd_q_tbl;
1326 int rv = -1;
jack wangdbf9bfe2009-10-14 16:19:21 +08001327
peter chang7640e1e2020-11-02 22:25:25 +05301328 WARN_ON(q_index >= PM8001_MAX_INB_NUM);
1329 spin_lock_irqsave(&circularQ->iq_lock, flags);
1330 rv = pm8001_mpi_msg_free_get(circularQ, pm8001_ha->iomb_size,
1331 &pMessage);
1332 if (rv < 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001333 pm8001_dbg(pm8001_ha, IO, "No free mpi buffer\n");
peter chang7640e1e2020-11-02 22:25:25 +05301334 rv = -ENOMEM;
1335 goto done;
jack wangdbf9bfe2009-10-14 16:19:21 +08001336 }
peter chang91a43fa2019-11-14 15:39:05 +05301337
1338 if (nb > (pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr)))
1339 nb = pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr);
1340 memcpy(pMessage, payload, nb);
1341 if (nb + sizeof(struct mpi_msg_hdr) < pm8001_ha->iomb_size)
1342 memset(pMessage + nb, 0, pm8001_ha->iomb_size -
1343 (nb + sizeof(struct mpi_msg_hdr)));
jack wangdbf9bfe2009-10-14 16:19:21 +08001344
1345 /*Build the header*/
1346 Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24)
1347 | ((responseQueue & 0x3F) << 16)
1348 | ((category & 0xF) << 12) | (opCode & 0xFFF));
1349
1350 pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header));
1351 /*Update the PI to the firmware*/
1352 pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
1353 circularQ->pi_offset, circularQ->producer_idx);
Joe Perches1b5d2792020-11-20 15:16:09 -08001354 pm8001_dbg(pm8001_ha, DEVIO,
1355 "INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n",
1356 responseQueue, opCode, circularQ->producer_idx,
1357 circularQ->consumer_index);
peter chang7640e1e2020-11-02 22:25:25 +05301358done:
1359 spin_unlock_irqrestore(&circularQ->iq_lock, flags);
1360 return rv;
jack wangdbf9bfe2009-10-14 16:19:21 +08001361}
1362
Sakthivel Kf74cf272013-02-27 20:27:43 +05301363u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
jack wangdbf9bfe2009-10-14 16:19:21 +08001364 struct outbound_queue_table *circularQ, u8 bc)
1365{
1366 u32 producer_index;
jack_wang72d0baa2009-11-05 22:33:35 +08001367 struct mpi_msg_hdr *msgHeader;
1368 struct mpi_msg_hdr *pOutBoundMsgHeader;
1369
1370 msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr));
1371 pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301372 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack_wang72d0baa2009-11-05 22:33:35 +08001373 if (pOutBoundMsgHeader != msgHeader) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001374 pm8001_dbg(pm8001_ha, FAIL,
1375 "consumer_idx = %d msgHeader = %p\n",
1376 circularQ->consumer_idx, msgHeader);
jack_wang72d0baa2009-11-05 22:33:35 +08001377
1378 /* Update the producer index from SPC */
1379 producer_index = pm8001_read_32(circularQ->pi_virt);
1380 circularQ->producer_index = cpu_to_le32(producer_index);
Joe Perches1b5d2792020-11-20 15:16:09 -08001381 pm8001_dbg(pm8001_ha, FAIL,
1382 "consumer_idx = %d producer_index = %dmsgHeader = %p\n",
1383 circularQ->consumer_idx,
1384 circularQ->producer_index, msgHeader);
jack_wang72d0baa2009-11-05 22:33:35 +08001385 return 0;
1386 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001387 /* free the circular queue buffer elements associated with the message*/
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001388 circularQ->consumer_idx = (circularQ->consumer_idx + bc)
1389 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001390 /* update the CI of outbound queue */
1391 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset,
1392 circularQ->consumer_idx);
1393 /* Update the producer index from SPC*/
1394 producer_index = pm8001_read_32(circularQ->pi_virt);
1395 circularQ->producer_index = cpu_to_le32(producer_index);
Joe Perches1b5d2792020-11-20 15:16:09 -08001396 pm8001_dbg(pm8001_ha, IO, " CI=%d PI=%d\n",
1397 circularQ->consumer_idx, circularQ->producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001398 return 0;
1399}
1400
1401/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301402 * pm8001_mpi_msg_consume- get the MPI message from outbound queue
1403 * message table.
jack wangdbf9bfe2009-10-14 16:19:21 +08001404 * @pm8001_ha: our hba card information
1405 * @circularQ: the outbound queue table.
1406 * @messagePtr1: the message contents of this outbound message.
1407 * @pBC: the message size.
1408 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301409u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001410 struct outbound_queue_table *circularQ,
1411 void **messagePtr1, u8 *pBC)
1412{
1413 struct mpi_msg_hdr *msgHeader;
1414 __le32 msgHeader_tmp;
1415 u32 header_tmp;
1416 do {
1417 /* If there are not-yet-delivered messages ... */
Santosh Nayak8270ee22012-02-26 20:14:46 +05301418 if (le32_to_cpu(circularQ->producer_index)
1419 != circularQ->consumer_idx) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001420 /*Get the pointer to the circular queue buffer element*/
1421 msgHeader = (struct mpi_msg_hdr *)
1422 (circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301423 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack wangdbf9bfe2009-10-14 16:19:21 +08001424 /* read header */
1425 header_tmp = pm8001_read_32(msgHeader);
1426 msgHeader_tmp = cpu_to_le32(header_tmp);
Joe Perches1b5d2792020-11-20 15:16:09 -08001427 pm8001_dbg(pm8001_ha, DEVIO,
1428 "outbound opcode msgheader:%x ci=%d pi=%d\n",
1429 msgHeader_tmp, circularQ->consumer_idx,
1430 circularQ->producer_index);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301431 if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001432 if (OPC_OUB_SKIP_ENTRY !=
Santosh Nayak8270ee22012-02-26 20:14:46 +05301433 (le32_to_cpu(msgHeader_tmp) & 0xfff)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001434 *messagePtr1 =
1435 ((u8 *)msgHeader) +
1436 sizeof(struct mpi_msg_hdr);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301437 *pBC = (u8)((le32_to_cpu(msgHeader_tmp)
1438 >> 24) & 0x1f);
Joe Perches1b5d2792020-11-20 15:16:09 -08001439 pm8001_dbg(pm8001_ha, IO,
1440 ": CI=%d PI=%d msgHeader=%x\n",
1441 circularQ->consumer_idx,
1442 circularQ->producer_index,
1443 msgHeader_tmp);
jack wangdbf9bfe2009-10-14 16:19:21 +08001444 return MPI_IO_STATUS_SUCCESS;
1445 } else {
jack wangdbf9bfe2009-10-14 16:19:21 +08001446 circularQ->consumer_idx =
1447 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301448 ((le32_to_cpu(msgHeader_tmp)
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001449 >> 24) & 0x1f))
1450 % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001451 msgHeader_tmp = 0;
1452 pm8001_write_32(msgHeader, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08001453 /* update the CI of outbound queue */
1454 pm8001_cw32(pm8001_ha,
1455 circularQ->ci_pci_bar,
1456 circularQ->ci_offset,
1457 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001458 }
jack_wang72d0baa2009-11-05 22:33:35 +08001459 } else {
1460 circularQ->consumer_idx =
1461 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301462 ((le32_to_cpu(msgHeader_tmp) >> 24) &
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001463 0x1f)) % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001464 msgHeader_tmp = 0;
1465 pm8001_write_32(msgHeader, 0, 0);
1466 /* update the CI of outbound queue */
1467 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar,
1468 circularQ->ci_offset,
1469 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001470 return MPI_IO_STATUS_FAIL;
jack_wang72d0baa2009-11-05 22:33:35 +08001471 }
1472 } else {
1473 u32 producer_index;
1474 void *pi_virt = circularQ->pi_virt;
Deepak Ukey72349b62018-09-11 14:18:04 +05301475 /* spurious interrupt during setup if
1476 * kexec-ing and driver doing a doorbell access
1477 * with the pre-kexec oq interrupt setup
1478 */
1479 if (!pi_virt)
1480 break;
jack_wang72d0baa2009-11-05 22:33:35 +08001481 /* Update the producer index from SPC */
1482 producer_index = pm8001_read_32(pi_virt);
1483 circularQ->producer_index = cpu_to_le32(producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001484 }
Santosh Nayak8270ee22012-02-26 20:14:46 +05301485 } while (le32_to_cpu(circularQ->producer_index) !=
1486 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001487 /* while we don't have any more not-yet-delivered message */
1488 /* report empty */
1489 return MPI_IO_STATUS_BUSY;
1490}
1491
Sakthivel Kf74cf272013-02-27 20:27:43 +05301492void pm8001_work_fn(struct work_struct *work)
jack wangdbf9bfe2009-10-14 16:19:21 +08001493{
Tejun Heo429305e2011-01-24 14:57:29 +01001494 struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001495 struct pm8001_device *pm8001_dev;
Tejun Heo429305e2011-01-24 14:57:29 +01001496 struct domain_device *dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08001497
Mark Salyzyn5954d732012-01-17 11:52:24 -05001498 /*
1499 * So far, all users of this stash an associated structure here.
1500 * If we get here, and this pointer is null, then the action
1501 * was cancelled. This nullification happens when the device
1502 * goes away.
1503 */
Ruksar Devadi4f5deeb2021-04-15 16:03:50 +05301504 if (pw->handler != IO_FATAL_ERROR) {
1505 pm8001_dev = pw->data; /* Most stash device structure */
1506 if ((pm8001_dev == NULL)
1507 || ((pw->handler != IO_XFER_ERROR_BREAK)
1508 && (pm8001_dev->dev_type == SAS_PHY_UNUSED))) {
1509 kfree(pw);
1510 return;
1511 }
Mark Salyzyn5954d732012-01-17 11:52:24 -05001512 }
1513
Tejun Heo429305e2011-01-24 14:57:29 +01001514 switch (pw->handler) {
Mark Salyzyn5954d732012-01-17 11:52:24 -05001515 case IO_XFER_ERROR_BREAK:
1516 { /* This one stashes the sas_task instead */
1517 struct sas_task *t = (struct sas_task *)pm8001_dev;
1518 u32 tag;
1519 struct pm8001_ccb_info *ccb;
1520 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1521 unsigned long flags, flags1;
1522 struct task_status_struct *ts;
1523 int i;
1524
1525 if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC)
1526 break; /* Task still on lu */
1527 spin_lock_irqsave(&pm8001_ha->lock, flags);
1528
1529 spin_lock_irqsave(&t->task_state_lock, flags1);
1530 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1531 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1532 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1533 break; /* Task got completed by another */
1534 }
1535 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1536
1537 /* Search for a possible ccb that matches the task */
1538 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1539 ccb = &pm8001_ha->ccb_info[i];
1540 tag = ccb->ccb_tag;
1541 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1542 break;
1543 }
1544 if (!ccb) {
1545 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1546 break; /* Task got freed by another */
1547 }
1548 ts = &t->task_status;
1549 ts->resp = SAS_TASK_COMPLETE;
1550 /* Force the midlayer to retry */
1551 ts->stat = SAS_QUEUE_FULL;
1552 pm8001_dev = ccb->device;
1553 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301554 atomic_dec(&pm8001_dev->running_req);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001555 spin_lock_irqsave(&t->task_state_lock, flags1);
1556 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
1557 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
1558 t->task_state_flags |= SAS_TASK_STATE_DONE;
1559 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
1560 spin_unlock_irqrestore(&t->task_state_lock, flags1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001561 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",
1562 t, pw->handler, ts->resp, ts->stat);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001563 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1564 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1565 } else {
1566 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1567 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1568 mb();/* in order to force CPU ordering */
1569 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1570 t->task_done(t);
1571 }
1572 } break;
1573 case IO_XFER_OPEN_RETRY_TIMEOUT:
1574 { /* This one stashes the sas_task instead */
1575 struct sas_task *t = (struct sas_task *)pm8001_dev;
1576 u32 tag;
1577 struct pm8001_ccb_info *ccb;
1578 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1579 unsigned long flags, flags1;
1580 int i, ret = 0;
1581
Joe Perches1b5d2792020-11-20 15:16:09 -08001582 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001583
1584 ret = pm8001_query_task(t);
1585
Joe Perches1b5d2792020-11-20 15:16:09 -08001586 if (ret == TMF_RESP_FUNC_SUCC)
1587 pm8001_dbg(pm8001_ha, IO, "...Task on lu\n");
1588 else if (ret == TMF_RESP_FUNC_COMPLETE)
1589 pm8001_dbg(pm8001_ha, IO, "...Task NOT on lu\n");
1590 else
1591 pm8001_dbg(pm8001_ha, DEVIO, "...query task failed!!!\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001592
1593 spin_lock_irqsave(&pm8001_ha->lock, flags);
1594
1595 spin_lock_irqsave(&t->task_state_lock, flags1);
1596
1597 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1598 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1599 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1600 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1601 (void)pm8001_abort_task(t);
1602 break; /* Task got completed by another */
1603 }
1604
1605 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1606
1607 /* Search for a possible ccb that matches the task */
1608 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1609 ccb = &pm8001_ha->ccb_info[i];
1610 tag = ccb->ccb_tag;
1611 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1612 break;
1613 }
1614 if (!ccb) {
1615 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1616 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1617 (void)pm8001_abort_task(t);
1618 break; /* Task got freed by another */
1619 }
1620
1621 pm8001_dev = ccb->device;
1622 dev = pm8001_dev->sas_device;
1623
1624 switch (ret) {
1625 case TMF_RESP_FUNC_SUCC: /* task on lu */
1626 ccb->open_retry = 1; /* Snub completion */
1627 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1628 ret = pm8001_abort_task(t);
1629 ccb->open_retry = 0;
1630 switch (ret) {
1631 case TMF_RESP_FUNC_SUCC:
1632 case TMF_RESP_FUNC_COMPLETE:
1633 break;
1634 default: /* device misbehavior */
1635 ret = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08001636 pm8001_dbg(pm8001_ha, IO, "...Reset phy\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001637 pm8001_I_T_nexus_reset(dev);
1638 break;
1639 }
1640 break;
1641
1642 case TMF_RESP_FUNC_COMPLETE: /* task not on lu */
1643 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1644 /* Do we need to abort the task locally? */
1645 break;
1646
1647 default: /* device misbehavior */
1648 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1649 ret = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08001650 pm8001_dbg(pm8001_ha, IO, "...Reset phy\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001651 pm8001_I_T_nexus_reset(dev);
1652 }
1653
1654 if (ret == TMF_RESP_FUNC_FAILED)
1655 t = NULL;
1656 pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev);
Joe Perches1b5d2792020-11-20 15:16:09 -08001657 pm8001_dbg(pm8001_ha, IO, "...Complete\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001658 } break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001659 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
jack wangdbf9bfe2009-10-14 16:19:21 +08001660 dev = pm8001_dev->sas_device;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301661 pm8001_I_T_nexus_event_handler(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001662 break;
1663 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
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_IN_ERROR:
jack wangdbf9bfe2009-10-14 16:19:21 +08001668 dev = pm8001_dev->sas_device;
1669 pm8001_I_T_nexus_reset(dev);
1670 break;
1671 case IO_DS_NON_OPERATIONAL:
jack wangdbf9bfe2009-10-14 16:19:21 +08001672 dev = pm8001_dev->sas_device;
1673 pm8001_I_T_nexus_reset(dev);
1674 break;
Ruksar Devadi4f5deeb2021-04-15 16:03:50 +05301675 case IO_FATAL_ERROR:
1676 {
1677 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1678 struct pm8001_ccb_info *ccb;
1679 struct task_status_struct *ts;
1680 struct sas_task *task;
1681 int i;
1682 u32 tag, device_id;
1683
1684 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1685 ccb = &pm8001_ha->ccb_info[i];
1686 task = ccb->task;
1687 ts = &task->task_status;
1688 tag = ccb->ccb_tag;
1689 /* check if tag is NULL */
1690 if (!tag) {
1691 pm8001_dbg(pm8001_ha, FAIL,
1692 "tag Null\n");
1693 continue;
1694 }
1695 if (task != NULL) {
1696 dev = task->dev;
1697 if (!dev) {
1698 pm8001_dbg(pm8001_ha, FAIL,
1699 "dev is NULL\n");
1700 continue;
1701 }
1702 /*complete sas task and update to top layer */
1703 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
1704 ts->resp = SAS_TASK_COMPLETE;
1705 task->task_done(task);
1706 } else if (tag != 0xFFFFFFFF) {
1707 /* complete the internal commands/non-sas task */
1708 pm8001_dev = ccb->device;
1709 if (pm8001_dev->dcompletion) {
1710 complete(pm8001_dev->dcompletion);
1711 pm8001_dev->dcompletion = NULL;
1712 }
1713 complete(pm8001_ha->nvmd_completion);
1714 pm8001_tag_free(pm8001_ha, tag);
1715 }
1716 }
1717 /* Deregister all the device ids */
1718 for (i = 0; i < PM8001_MAX_DEVICES; i++) {
1719 pm8001_dev = &pm8001_ha->devices[i];
1720 device_id = pm8001_dev->device_id;
1721 if (device_id) {
1722 PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
1723 pm8001_free_dev(pm8001_dev);
1724 }
1725 }
1726 } break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001727 }
Tejun Heo429305e2011-01-24 14:57:29 +01001728 kfree(pw);
jack wangdbf9bfe2009-10-14 16:19:21 +08001729}
1730
Sakthivel Kf74cf272013-02-27 20:27:43 +05301731int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
jack wangdbf9bfe2009-10-14 16:19:21 +08001732 int handler)
1733{
Tejun Heo429305e2011-01-24 14:57:29 +01001734 struct pm8001_work *pw;
jack wangdbf9bfe2009-10-14 16:19:21 +08001735 int ret = 0;
1736
Tejun Heo429305e2011-01-24 14:57:29 +01001737 pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
1738 if (pw) {
1739 pw->pm8001_ha = pm8001_ha;
1740 pw->data = data;
1741 pw->handler = handler;
1742 INIT_WORK(&pw->work, pm8001_work_fn);
1743 queue_work(pm8001_wq, &pw->work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001744 } else
1745 ret = -ENOMEM;
1746
1747 return ret;
1748}
1749
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301750static void pm8001_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1751 struct pm8001_device *pm8001_ha_dev)
1752{
1753 int res;
1754 u32 ccb_tag;
1755 struct pm8001_ccb_info *ccb;
1756 struct sas_task *task = NULL;
1757 struct task_abort_req task_abort;
1758 struct inbound_queue_table *circularQ;
1759 u32 opc = OPC_INB_SATA_ABORT;
1760 int ret;
1761
1762 if (!pm8001_ha_dev) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001763 pm8001_dbg(pm8001_ha, FAIL, "dev is null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301764 return;
1765 }
1766
1767 task = sas_alloc_slow_task(GFP_ATOMIC);
1768
1769 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001770 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301771 return;
1772 }
1773
1774 task->task_done = pm8001_task_done;
1775
1776 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1777 if (res)
1778 return;
1779
1780 ccb = &pm8001_ha->ccb_info[ccb_tag];
1781 ccb->device = pm8001_ha_dev;
1782 ccb->ccb_tag = ccb_tag;
1783 ccb->task = task;
1784
1785 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1786
1787 memset(&task_abort, 0, sizeof(task_abort));
1788 task_abort.abort_all = cpu_to_le32(1);
1789 task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1790 task_abort.tag = cpu_to_le32(ccb_tag);
1791
peter chang91a43fa2019-11-14 15:39:05 +05301792 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
1793 sizeof(task_abort), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301794 if (ret)
1795 pm8001_tag_free(pm8001_ha, ccb_tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301796
1797}
1798
1799static void pm8001_send_read_log(struct pm8001_hba_info *pm8001_ha,
1800 struct pm8001_device *pm8001_ha_dev)
1801{
1802 struct sata_start_req sata_cmd;
1803 int res;
1804 u32 ccb_tag;
1805 struct pm8001_ccb_info *ccb;
1806 struct sas_task *task = NULL;
1807 struct host_to_dev_fis fis;
1808 struct domain_device *dev;
1809 struct inbound_queue_table *circularQ;
1810 u32 opc = OPC_INB_SATA_HOST_OPSTART;
1811
1812 task = sas_alloc_slow_task(GFP_ATOMIC);
1813
1814 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001815 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301816 return;
1817 }
1818 task->task_done = pm8001_task_done;
1819
1820 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1821 if (res) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301822 sas_free_task(task);
Joe Perches1b5d2792020-11-20 15:16:09 -08001823 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate tag !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301824 return;
1825 }
1826
1827 /* allocate domain device by ourselves as libsas
1828 * is not going to provide any
1829 */
1830 dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1831 if (!dev) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301832 sas_free_task(task);
1833 pm8001_tag_free(pm8001_ha, ccb_tag);
Joe Perches1b5d2792020-11-20 15:16:09 -08001834 pm8001_dbg(pm8001_ha, FAIL,
1835 "Domain device cannot be allocated\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301836 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301837 }
Tomas Henzl5533abc2014-07-09 17:20:49 +05301838 task->dev = dev;
1839 task->dev->lldd_dev = pm8001_ha_dev;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301840
1841 ccb = &pm8001_ha->ccb_info[ccb_tag];
1842 ccb->device = pm8001_ha_dev;
1843 ccb->ccb_tag = ccb_tag;
1844 ccb->task = task;
1845 pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1846 pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1847
1848 memset(&sata_cmd, 0, sizeof(sata_cmd));
1849 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1850
1851 /* construct read log FIS */
1852 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1853 fis.fis_type = 0x27;
1854 fis.flags = 0x80;
1855 fis.command = ATA_CMD_READ_LOG_EXT;
1856 fis.lbal = 0x10;
1857 fis.sector_count = 0x1;
1858
1859 sata_cmd.tag = cpu_to_le32(ccb_tag);
1860 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1861 sata_cmd.ncqtag_atap_dir_m |= ((0x1 << 7) | (0x5 << 9));
1862 memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1863
peter chang91a43fa2019-11-14 15:39:05 +05301864 res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
1865 sizeof(sata_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301866 if (res) {
1867 sas_free_task(task);
1868 pm8001_tag_free(pm8001_ha, ccb_tag);
1869 kfree(dev);
1870 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301871}
1872
jack wangdbf9bfe2009-10-14 16:19:21 +08001873/**
1874 * mpi_ssp_completion- process the event that FW response to the SSP request.
1875 * @pm8001_ha: our hba card information
1876 * @piomb: the message contents of this outbound message.
1877 *
1878 * When FW has completed a ssp request for example a IO request, after it has
1879 * filled the SG data with the data, it will trigger this event represent
1880 * that he has finished the job,please check the coresponding buffer.
1881 * So we will tell the caller who maybe waiting the result to tell upper layer
1882 * that the task has been finished.
1883 */
jack_wang72d0baa2009-11-05 22:33:35 +08001884static void
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08001885mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08001886{
1887 struct sas_task *t;
1888 struct pm8001_ccb_info *ccb;
1889 unsigned long flags;
1890 u32 status;
1891 u32 param;
1892 u32 tag;
1893 struct ssp_completion_resp *psspPayload;
1894 struct task_status_struct *ts;
1895 struct ssp_response_iu *iu;
1896 struct pm8001_device *pm8001_dev;
1897 psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1898 status = le32_to_cpu(psspPayload->status);
1899 tag = le32_to_cpu(psspPayload->tag);
1900 ccb = &pm8001_ha->ccb_info[tag];
Mark Salyzyn5954d732012-01-17 11:52:24 -05001901 if ((status == IO_ABORTED) && ccb->open_retry) {
1902 /* Being completed by another */
1903 ccb->open_retry = 0;
1904 return;
1905 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001906 pm8001_dev = ccb->device;
1907 param = le32_to_cpu(psspPayload->param);
1908
jack wangdbf9bfe2009-10-14 16:19:21 +08001909 t = ccb->task;
1910
jack_wang72d0baa2009-11-05 22:33:35 +08001911 if (status && status != IO_UNDERFLOW)
Joe Perches1b5d2792020-11-20 15:16:09 -08001912 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08001913 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08001914 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08001915 ts = &t->task_status;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301916 /* Print sas address of IO failed device */
1917 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1918 (status != IO_UNDERFLOW))
Joe Perches1b5d2792020-11-20 15:16:09 -08001919 pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n",
1920 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301921
peter chang73706722019-11-14 15:39:02 +05301922 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08001923 pm8001_dbg(pm8001_ha, IOERR,
1924 "status:0x%x, tag:0x%x, task:0x%p\n",
1925 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05301926
jack wangdbf9bfe2009-10-14 16:19:21 +08001927 switch (status) {
1928 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001929 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS,param = %d\n",
1930 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08001931 if (param == 0) {
1932 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07001933 ts->stat = SAS_SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08001934 } else {
1935 ts->resp = SAS_TASK_COMPLETE;
1936 ts->stat = SAS_PROTO_RESPONSE;
1937 ts->residual = param;
1938 iu = &psspPayload->ssp_resp_iu;
1939 sas_ssp_task_response(pm8001_ha->dev, t, iu);
1940 }
1941 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301942 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001943 break;
1944 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001945 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001946 ts->resp = SAS_TASK_COMPLETE;
1947 ts->stat = SAS_ABORTED_TASK;
1948 break;
1949 case IO_UNDERFLOW:
1950 /* SSP Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08001951 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW,param = %d\n",
1952 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08001953 ts->resp = SAS_TASK_COMPLETE;
1954 ts->stat = SAS_DATA_UNDERRUN;
1955 ts->residual = param;
1956 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301957 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001958 break;
1959 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08001960 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001961 ts->resp = SAS_TASK_UNDELIVERED;
1962 ts->stat = SAS_PHY_DOWN;
1963 break;
1964 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001965 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001966 ts->resp = SAS_TASK_COMPLETE;
1967 ts->stat = SAS_OPEN_REJECT;
Mark Salyzyn5954d732012-01-17 11:52:24 -05001968 /* Force the midlayer to retry */
1969 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001970 break;
1971 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08001972 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001973 ts->resp = SAS_TASK_COMPLETE;
1974 ts->stat = SAS_OPEN_REJECT;
1975 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
1976 break;
1977 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001978 pm8001_dbg(pm8001_ha, IO,
1979 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001980 ts->resp = SAS_TASK_COMPLETE;
1981 ts->stat = SAS_OPEN_REJECT;
1982 ts->open_rej_reason = SAS_OREJ_EPROTO;
1983 break;
1984 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08001985 pm8001_dbg(pm8001_ha, IO,
1986 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001987 ts->resp = SAS_TASK_COMPLETE;
1988 ts->stat = SAS_OPEN_REJECT;
1989 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1990 break;
1991 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001992 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001993 ts->resp = SAS_TASK_COMPLETE;
1994 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08001995 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001996 break;
1997 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001998 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001999 ts->resp = SAS_TASK_COMPLETE;
2000 ts->stat = SAS_OPEN_REJECT;
2001 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2002 if (!t->uldd_task)
2003 pm8001_handle_event(pm8001_ha,
2004 pm8001_dev,
2005 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2006 break;
2007 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002008 pm8001_dbg(pm8001_ha, IO,
2009 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002010 ts->resp = SAS_TASK_COMPLETE;
2011 ts->stat = SAS_OPEN_REJECT;
2012 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2013 break;
2014 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002015 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002016 ts->resp = SAS_TASK_COMPLETE;
2017 ts->stat = SAS_OPEN_REJECT;
2018 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2019 break;
2020 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002021 pm8001_dbg(pm8001_ha, IO,
2022 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002023 ts->resp = SAS_TASK_UNDELIVERED;
2024 ts->stat = SAS_OPEN_REJECT;
2025 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2026 break;
2027 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002028 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002029 ts->resp = SAS_TASK_COMPLETE;
2030 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002031 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002032 break;
2033 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002034 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002035 ts->resp = SAS_TASK_COMPLETE;
2036 ts->stat = SAS_NAK_R_ERR;
2037 break;
2038 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002039 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002040 ts->resp = SAS_TASK_COMPLETE;
2041 ts->stat = SAS_OPEN_REJECT;
2042 break;
2043 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002044 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002045 ts->resp = SAS_TASK_COMPLETE;
2046 ts->stat = SAS_OPEN_REJECT;
2047 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2048 break;
2049 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002050 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002051 ts->resp = SAS_TASK_COMPLETE;
2052 ts->stat = SAS_OPEN_REJECT;
2053 break;
2054 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002055 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002056 ts->resp = SAS_TASK_COMPLETE;
2057 ts->stat = SAS_OPEN_REJECT;
2058 break;
2059 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002060 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002061 ts->resp = SAS_TASK_COMPLETE;
2062 ts->stat = SAS_OPEN_REJECT;
2063 if (!t->uldd_task)
2064 pm8001_handle_event(pm8001_ha,
2065 pm8001_dev,
2066 IO_DS_NON_OPERATIONAL);
2067 break;
2068 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002069 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002070 ts->resp = SAS_TASK_COMPLETE;
2071 ts->stat = SAS_OPEN_REJECT;
2072 break;
2073 case IO_TM_TAG_NOT_FOUND:
Joe Perches1b5d2792020-11-20 15:16:09 -08002074 pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002075 ts->resp = SAS_TASK_COMPLETE;
2076 ts->stat = SAS_OPEN_REJECT;
2077 break;
2078 case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002079 pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002080 ts->resp = SAS_TASK_COMPLETE;
2081 ts->stat = SAS_OPEN_REJECT;
2082 break;
2083 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002084 pm8001_dbg(pm8001_ha, IO,
2085 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002086 ts->resp = SAS_TASK_COMPLETE;
2087 ts->stat = SAS_OPEN_REJECT;
2088 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07002089 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002090 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002091 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002092 /* not allowed case. Therefore, return failed status */
2093 ts->resp = SAS_TASK_COMPLETE;
2094 ts->stat = SAS_OPEN_REJECT;
2095 break;
2096 }
Joe Perches1b5d2792020-11-20 15:16:09 -08002097 pm8001_dbg(pm8001_ha, IO, "scsi_status = %x\n",
2098 psspPayload->ssp_resp_iu.status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002099 spin_lock_irqsave(&t->task_state_lock, flags);
2100 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2101 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2102 t->task_state_flags |= SAS_TASK_STATE_DONE;
2103 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2104 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002105 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",
2106 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002107 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2108 } else {
2109 spin_unlock_irqrestore(&t->task_state_lock, flags);
2110 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2111 mb();/* in order to force CPU ordering */
2112 t->task_done(t);
2113 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002114}
2115
2116/*See the comments for mpi_ssp_completion */
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002117static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002118{
2119 struct sas_task *t;
2120 unsigned long flags;
2121 struct task_status_struct *ts;
2122 struct pm8001_ccb_info *ccb;
2123 struct pm8001_device *pm8001_dev;
2124 struct ssp_event_resp *psspPayload =
2125 (struct ssp_event_resp *)(piomb + 4);
2126 u32 event = le32_to_cpu(psspPayload->event);
2127 u32 tag = le32_to_cpu(psspPayload->tag);
2128 u32 port_id = le32_to_cpu(psspPayload->port_id);
2129 u32 dev_id = le32_to_cpu(psspPayload->device_id);
2130
2131 ccb = &pm8001_ha->ccb_info[tag];
2132 t = ccb->task;
2133 pm8001_dev = ccb->device;
2134 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002135 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002136 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002137 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002138 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002139 pm8001_dbg(pm8001_ha, DEVIO, "port_id = %x,device_id = %x\n",
2140 port_id, dev_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08002141 switch (event) {
2142 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002143 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002144 ts->resp = SAS_TASK_COMPLETE;
2145 ts->stat = SAS_DATA_OVERRUN;
2146 ts->residual = 0;
2147 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302148 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002149 break;
2150 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002151 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05002152 pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2153 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002154 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002155 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002156 ts->resp = SAS_TASK_COMPLETE;
2157 ts->stat = SAS_OPEN_REJECT;
2158 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2159 break;
2160 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002161 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002162 ts->resp = SAS_TASK_COMPLETE;
2163 ts->stat = SAS_OPEN_REJECT;
2164 ts->open_rej_reason = SAS_OREJ_EPROTO;
2165 break;
2166 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002167 pm8001_dbg(pm8001_ha, IO,
2168 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002169 ts->resp = SAS_TASK_COMPLETE;
2170 ts->stat = SAS_OPEN_REJECT;
2171 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2172 break;
2173 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002174 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002175 ts->resp = SAS_TASK_COMPLETE;
2176 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002177 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002178 break;
2179 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002180 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002181 ts->resp = SAS_TASK_COMPLETE;
2182 ts->stat = SAS_OPEN_REJECT;
2183 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2184 if (!t->uldd_task)
2185 pm8001_handle_event(pm8001_ha,
2186 pm8001_dev,
2187 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2188 break;
2189 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002190 pm8001_dbg(pm8001_ha, IO,
2191 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002192 ts->resp = SAS_TASK_COMPLETE;
2193 ts->stat = SAS_OPEN_REJECT;
2194 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2195 break;
2196 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002197 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002198 ts->resp = SAS_TASK_COMPLETE;
2199 ts->stat = SAS_OPEN_REJECT;
2200 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2201 break;
2202 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002203 pm8001_dbg(pm8001_ha, IO,
2204 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002205 ts->resp = SAS_TASK_COMPLETE;
2206 ts->stat = SAS_OPEN_REJECT;
2207 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2208 break;
2209 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002210 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002211 ts->resp = SAS_TASK_COMPLETE;
2212 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002213 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002214 break;
2215 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002216 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002217 ts->resp = SAS_TASK_COMPLETE;
2218 ts->stat = SAS_NAK_R_ERR;
2219 break;
2220 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002221 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05002222 pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2223 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002224 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002225 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002226 ts->resp = SAS_TASK_COMPLETE;
2227 ts->stat = SAS_DATA_OVERRUN;
2228 break;
2229 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002230 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002231 ts->resp = SAS_TASK_COMPLETE;
2232 ts->stat = SAS_DATA_OVERRUN;
2233 break;
2234 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002235 pm8001_dbg(pm8001_ha, IO,
2236 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002237 ts->resp = SAS_TASK_COMPLETE;
2238 ts->stat = SAS_DATA_OVERRUN;
2239 break;
2240 case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002241 pm8001_dbg(pm8001_ha, IO,
2242 "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002243 ts->resp = SAS_TASK_COMPLETE;
2244 ts->stat = SAS_DATA_OVERRUN;
2245 break;
2246 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002247 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002248 ts->resp = SAS_TASK_COMPLETE;
2249 ts->stat = SAS_DATA_OVERRUN;
2250 break;
2251 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002252 pm8001_dbg(pm8001_ha, IO,
2253 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002254 ts->resp = SAS_TASK_COMPLETE;
2255 ts->stat = SAS_DATA_OVERRUN;
2256 break;
2257 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002258 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
jack_wang72d0baa2009-11-05 22:33:35 +08002259 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002260 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002261 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002262 /* not allowed case. Therefore, return failed status */
2263 ts->resp = SAS_TASK_COMPLETE;
2264 ts->stat = SAS_DATA_OVERRUN;
2265 break;
2266 }
2267 spin_lock_irqsave(&t->task_state_lock, flags);
2268 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2269 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2270 t->task_state_flags |= SAS_TASK_STATE_DONE;
2271 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2272 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002273 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",
2274 t, event, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002275 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2276 } else {
2277 spin_unlock_irqrestore(&t->task_state_lock, flags);
2278 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2279 mb();/* in order to force CPU ordering */
2280 t->task_done(t);
2281 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002282}
2283
2284/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002285static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002286mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2287{
2288 struct sas_task *t;
2289 struct pm8001_ccb_info *ccb;
jack wangdbf9bfe2009-10-14 16:19:21 +08002290 u32 param;
2291 u32 status;
2292 u32 tag;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302293 int i, j;
2294 u8 sata_addr_low[4];
2295 u32 temp_sata_addr_low;
2296 u8 sata_addr_hi[4];
2297 u32 temp_sata_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +08002298 struct sata_completion_resp *psataPayload;
2299 struct task_status_struct *ts;
2300 struct ata_task_resp *resp ;
2301 u32 *sata_resp;
2302 struct pm8001_device *pm8001_dev;
Santosh Nayakb08c1852012-03-09 13:43:38 +05302303 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002304
2305 psataPayload = (struct sata_completion_resp *)(piomb + 4);
2306 status = le32_to_cpu(psataPayload->status);
2307 tag = le32_to_cpu(psataPayload->tag);
2308
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302309 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002310 pm8001_dbg(pm8001_ha, FAIL, "tag null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302311 return;
2312 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002313 ccb = &pm8001_ha->ccb_info[tag];
2314 param = le32_to_cpu(psataPayload->param);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302315 if (ccb) {
2316 t = ccb->task;
2317 pm8001_dev = ccb->device;
2318 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002319 pm8001_dbg(pm8001_ha, FAIL, "ccb null\n");
jack_wang72d0baa2009-11-05 22:33:35 +08002320 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302321 }
2322
2323 if (t) {
2324 if (t->dev && (t->dev->lldd_dev))
2325 pm8001_dev = t->dev->lldd_dev;
2326 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002327 pm8001_dbg(pm8001_ha, FAIL, "task null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302328 return;
2329 }
2330
2331 if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2332 && unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002333 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302334 return;
2335 }
2336
2337 ts = &t->task_status;
2338 if (!ts) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002339 pm8001_dbg(pm8001_ha, FAIL, "ts null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302340 return;
2341 }
peter chang73706722019-11-14 15:39:02 +05302342
2343 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08002344 pm8001_dbg(pm8001_ha, IOERR,
2345 "status:0x%x, tag:0x%x, task::0x%p\n",
2346 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302347
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302348 /* Print sas address of IO failed device */
2349 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2350 (status != IO_UNDERFLOW)) {
2351 if (!((t->dev->parent) &&
John Garry924a3542019-06-10 20:41:41 +08002352 (dev_is_expander(t->dev->parent->dev_type)))) {
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002353 for (i = 0, j = 4; j <= 7 && i <= 3; i++, j++)
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302354 sata_addr_low[i] = pm8001_ha->sas_addr[j];
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002355 for (i = 0, j = 0; j <= 3 && i <= 3; i++, j++)
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302356 sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2357 memcpy(&temp_sata_addr_low, sata_addr_low,
2358 sizeof(sata_addr_low));
2359 memcpy(&temp_sata_addr_hi, sata_addr_hi,
2360 sizeof(sata_addr_hi));
2361 temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2362 |((temp_sata_addr_hi << 8) &
2363 0xff0000) |
2364 ((temp_sata_addr_hi >> 8)
2365 & 0xff00) |
2366 ((temp_sata_addr_hi << 24) &
2367 0xff000000));
2368 temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2369 & 0xff) |
2370 ((temp_sata_addr_low << 8)
2371 & 0xff0000) |
2372 ((temp_sata_addr_low >> 8)
2373 & 0xff00) |
2374 ((temp_sata_addr_low << 24)
2375 & 0xff000000)) +
2376 pm8001_dev->attached_phy +
2377 0x10);
Joe Perches1b5d2792020-11-20 15:16:09 -08002378 pm8001_dbg(pm8001_ha, FAIL,
2379 "SAS Address of IO Failure Drive:%08x%08x\n",
2380 temp_sata_addr_hi,
2381 temp_sata_addr_low);
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302382 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002383 pm8001_dbg(pm8001_ha, FAIL,
2384 "SAS Address of IO Failure Drive:%016llx\n",
2385 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302386 }
2387 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002388 switch (status) {
2389 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002390 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002391 if (param == 0) {
2392 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002393 ts->stat = SAS_SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302394 /* check if response is for SEND READ LOG */
2395 if (pm8001_dev &&
2396 (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2397 /* set new bit for abort_all */
2398 pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2399 /* clear bit for read log */
2400 pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2401 pm8001_send_abort_all(pm8001_ha, pm8001_dev);
2402 /* Free the tag */
2403 pm8001_tag_free(pm8001_ha, tag);
2404 sas_free_task(t);
2405 return;
2406 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002407 } else {
2408 u8 len;
2409 ts->resp = SAS_TASK_COMPLETE;
2410 ts->stat = SAS_PROTO_RESPONSE;
2411 ts->residual = param;
Joe Perches1b5d2792020-11-20 15:16:09 -08002412 pm8001_dbg(pm8001_ha, IO,
2413 "SAS_PROTO_RESPONSE len = %d\n",
2414 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002415 sata_resp = &psataPayload->sata_resp[0];
2416 resp = (struct ata_task_resp *)ts->buf;
2417 if (t->ata_task.dma_xfer == 0 &&
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02002418 t->data_dir == DMA_FROM_DEVICE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08002419 len = sizeof(struct pio_setup_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002420 pm8001_dbg(pm8001_ha, IO,
2421 "PIO read len = %d\n", len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002422 } else if (t->ata_task.use_ncq) {
2423 len = sizeof(struct set_dev_bits_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002424 pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n",
2425 len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002426 } else {
2427 len = sizeof(struct dev_to_host_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002428 pm8001_dbg(pm8001_ha, IO, "other len = %d\n",
2429 len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002430 }
2431 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2432 resp->frame_len = len;
2433 memcpy(&resp->ending_fis[0], sata_resp, len);
2434 ts->buf_valid_size = sizeof(*resp);
2435 } else
Joe Perches1b5d2792020-11-20 15:16:09 -08002436 pm8001_dbg(pm8001_ha, IO,
2437 "response too large\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002438 }
2439 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302440 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002441 break;
2442 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002443 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002444 ts->resp = SAS_TASK_COMPLETE;
2445 ts->stat = SAS_ABORTED_TASK;
2446 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302447 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002448 break;
2449 /* following cases are to do cases */
2450 case IO_UNDERFLOW:
2451 /* SATA Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08002452 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002453 ts->resp = SAS_TASK_COMPLETE;
2454 ts->stat = SAS_DATA_UNDERRUN;
2455 ts->residual = param;
2456 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302457 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002458 break;
2459 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002460 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002461 ts->resp = SAS_TASK_UNDELIVERED;
2462 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302463 if (pm8001_dev)
2464 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002465 break;
2466 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002467 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002468 ts->resp = SAS_TASK_COMPLETE;
2469 ts->stat = SAS_INTERRUPTED;
Viswas G4a2efd42020-11-02 22:25:26 +05302470 if (pm8001_dev)
2471 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002472 break;
2473 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002474 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002475 ts->resp = SAS_TASK_COMPLETE;
2476 ts->stat = SAS_OPEN_REJECT;
2477 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302478 if (pm8001_dev)
2479 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002480 break;
2481 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002482 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002483 ts->resp = SAS_TASK_COMPLETE;
2484 ts->stat = SAS_OPEN_REJECT;
2485 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302486 if (pm8001_dev)
2487 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002488 break;
2489 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002490 pm8001_dbg(pm8001_ha, IO,
2491 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002492 ts->resp = SAS_TASK_COMPLETE;
2493 ts->stat = SAS_OPEN_REJECT;
2494 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302495 if (pm8001_dev)
2496 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002497 break;
2498 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002499 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002500 ts->resp = SAS_TASK_COMPLETE;
2501 ts->stat = SAS_OPEN_REJECT;
2502 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
Viswas G4a2efd42020-11-02 22:25:26 +05302503 if (pm8001_dev)
2504 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002505 break;
2506 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002507 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002508 ts->resp = SAS_TASK_COMPLETE;
2509 ts->stat = SAS_DEV_NO_RESPONSE;
2510 if (!t->uldd_task) {
2511 pm8001_handle_event(pm8001_ha,
2512 pm8001_dev,
2513 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2514 ts->resp = SAS_TASK_UNDELIVERED;
2515 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302516 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002517 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002518 }
2519 break;
2520 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002521 pm8001_dbg(pm8001_ha, IO,
2522 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002523 ts->resp = SAS_TASK_UNDELIVERED;
2524 ts->stat = SAS_OPEN_REJECT;
2525 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2526 if (!t->uldd_task) {
2527 pm8001_handle_event(pm8001_ha,
2528 pm8001_dev,
2529 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2530 ts->resp = SAS_TASK_UNDELIVERED;
2531 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302532 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002533 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002534 }
2535 break;
2536 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002537 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002538 ts->resp = SAS_TASK_COMPLETE;
2539 ts->stat = SAS_OPEN_REJECT;
2540 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302541 if (pm8001_dev)
2542 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002543 break;
2544 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002545 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002546 ts->resp = SAS_TASK_COMPLETE;
2547 ts->stat = SAS_DEV_NO_RESPONSE;
2548 if (!t->uldd_task) {
2549 pm8001_handle_event(pm8001_ha,
2550 pm8001_dev,
2551 IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2552 ts->resp = SAS_TASK_UNDELIVERED;
2553 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302554 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002555 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002556 }
2557 break;
2558 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002559 pm8001_dbg(pm8001_ha, IO,
2560 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002561 ts->resp = SAS_TASK_COMPLETE;
2562 ts->stat = SAS_OPEN_REJECT;
2563 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302564 if (pm8001_dev)
2565 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002566 break;
2567 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002568 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002569 ts->resp = SAS_TASK_COMPLETE;
2570 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302571 if (pm8001_dev)
2572 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002573 break;
2574 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002575 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002576 ts->resp = SAS_TASK_COMPLETE;
2577 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302578 if (pm8001_dev)
2579 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002580 break;
2581 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002582 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002583 ts->resp = SAS_TASK_COMPLETE;
2584 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05302585 if (pm8001_dev)
2586 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002587 break;
2588 case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002589 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002590 ts->resp = SAS_TASK_UNDELIVERED;
2591 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302592 if (pm8001_dev)
2593 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002594 break;
2595 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002596 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002597 ts->resp = SAS_TASK_COMPLETE;
2598 ts->stat = SAS_DATA_UNDERRUN;
Viswas G4a2efd42020-11-02 22:25:26 +05302599 if (pm8001_dev)
2600 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002601 break;
2602 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002603 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002604 ts->resp = SAS_TASK_COMPLETE;
2605 ts->stat = SAS_OPEN_TO;
Viswas G4a2efd42020-11-02 22:25:26 +05302606 if (pm8001_dev)
2607 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002608 break;
2609 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002610 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002611 ts->resp = SAS_TASK_COMPLETE;
2612 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302613 if (pm8001_dev)
2614 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002615 break;
2616 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002617 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002618 ts->resp = SAS_TASK_COMPLETE;
2619 ts->stat = SAS_DEV_NO_RESPONSE;
2620 if (!t->uldd_task) {
2621 pm8001_handle_event(pm8001_ha, pm8001_dev,
2622 IO_DS_NON_OPERATIONAL);
2623 ts->resp = SAS_TASK_UNDELIVERED;
2624 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302625 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002626 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002627 }
2628 break;
2629 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002630 pm8001_dbg(pm8001_ha, IO, " IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002631 ts->resp = SAS_TASK_COMPLETE;
2632 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302633 if (pm8001_dev)
2634 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002635 break;
2636 case IO_DS_IN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002637 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002638 ts->resp = SAS_TASK_COMPLETE;
2639 ts->stat = SAS_DEV_NO_RESPONSE;
2640 if (!t->uldd_task) {
2641 pm8001_handle_event(pm8001_ha, pm8001_dev,
2642 IO_DS_IN_ERROR);
2643 ts->resp = SAS_TASK_UNDELIVERED;
2644 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302645 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002646 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002647 }
2648 break;
2649 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002650 pm8001_dbg(pm8001_ha, IO,
2651 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002652 ts->resp = SAS_TASK_COMPLETE;
2653 ts->stat = SAS_OPEN_REJECT;
2654 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302655 if (pm8001_dev)
2656 atomic_dec(&pm8001_dev->running_req);
Johannes Thumshirn50acde82015-08-17 15:52:32 +02002657 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002658 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002659 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002660 /* not allowed case. Therefore, return failed status */
2661 ts->resp = SAS_TASK_COMPLETE;
2662 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302663 if (pm8001_dev)
2664 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002665 break;
2666 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302667 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002668 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2669 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2670 t->task_state_flags |= SAS_TASK_STATE_DONE;
2671 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302672 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002673 pm8001_dbg(pm8001_ha, FAIL,
2674 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2675 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002676 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302677 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302678 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302679 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002680 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002681}
2682
2683/*See the comments for mpi_ssp_completion */
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002684static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002685{
2686 struct sas_task *t;
jack wangdbf9bfe2009-10-14 16:19:21 +08002687 struct task_status_struct *ts;
2688 struct pm8001_ccb_info *ccb;
2689 struct pm8001_device *pm8001_dev;
2690 struct sata_event_resp *psataPayload =
2691 (struct sata_event_resp *)(piomb + 4);
2692 u32 event = le32_to_cpu(psataPayload->event);
2693 u32 tag = le32_to_cpu(psataPayload->tag);
2694 u32 port_id = le32_to_cpu(psataPayload->port_id);
2695 u32 dev_id = le32_to_cpu(psataPayload->device_id);
Santosh Nayakb08c1852012-03-09 13:43:38 +05302696 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002697
2698 ccb = &pm8001_ha->ccb_info[tag];
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302699
2700 if (ccb) {
2701 t = ccb->task;
2702 pm8001_dev = ccb->device;
2703 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002704 pm8001_dbg(pm8001_ha, FAIL, "No CCB !!!. returning\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302705 }
2706 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002707 pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302708
2709 /* Check if this is NCQ error */
2710 if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2711 /* find device using device id */
2712 pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2713 /* send read log extension */
2714 if (pm8001_dev)
2715 pm8001_send_read_log(pm8001_ha, pm8001_dev);
2716 return;
2717 }
2718
2719 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002720 t = ccb->task;
2721 pm8001_dev = ccb->device;
2722 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002723 pm8001_dbg(pm8001_ha, FAIL, "sata IO status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002724 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002725 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002726 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002727 pm8001_dbg(pm8001_ha, DEVIO,
2728 "port_id:0x%x, device_id:0x%x, tag:0x%x, event:0x%x\n",
2729 port_id, dev_id, tag, event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002730 switch (event) {
2731 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002732 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002733 ts->resp = SAS_TASK_COMPLETE;
2734 ts->stat = SAS_DATA_OVERRUN;
2735 ts->residual = 0;
2736 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302737 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002738 break;
2739 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002740 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002741 ts->resp = SAS_TASK_COMPLETE;
2742 ts->stat = SAS_INTERRUPTED;
2743 break;
2744 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002745 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002746 ts->resp = SAS_TASK_COMPLETE;
2747 ts->stat = SAS_OPEN_REJECT;
2748 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2749 break;
2750 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002751 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002752 ts->resp = SAS_TASK_COMPLETE;
2753 ts->stat = SAS_OPEN_REJECT;
2754 ts->open_rej_reason = SAS_OREJ_EPROTO;
2755 break;
2756 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002757 pm8001_dbg(pm8001_ha, IO,
2758 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002759 ts->resp = SAS_TASK_COMPLETE;
2760 ts->stat = SAS_OPEN_REJECT;
2761 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2762 break;
2763 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002764 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002765 ts->resp = SAS_TASK_COMPLETE;
2766 ts->stat = SAS_OPEN_REJECT;
2767 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2768 break;
2769 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002770 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002771 ts->resp = SAS_TASK_UNDELIVERED;
2772 ts->stat = SAS_DEV_NO_RESPONSE;
2773 if (!t->uldd_task) {
2774 pm8001_handle_event(pm8001_ha,
2775 pm8001_dev,
2776 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2777 ts->resp = SAS_TASK_COMPLETE;
2778 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302779 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002780 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002781 }
2782 break;
2783 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002784 pm8001_dbg(pm8001_ha, IO,
2785 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002786 ts->resp = SAS_TASK_UNDELIVERED;
2787 ts->stat = SAS_OPEN_REJECT;
2788 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2789 break;
2790 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002791 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002792 ts->resp = SAS_TASK_COMPLETE;
2793 ts->stat = SAS_OPEN_REJECT;
2794 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2795 break;
2796 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002797 pm8001_dbg(pm8001_ha, IO,
2798 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002799 ts->resp = SAS_TASK_COMPLETE;
2800 ts->stat = SAS_OPEN_REJECT;
2801 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2802 break;
2803 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002804 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002805 ts->resp = SAS_TASK_COMPLETE;
2806 ts->stat = SAS_NAK_R_ERR;
2807 break;
2808 case IO_XFER_ERROR_PEER_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002809 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002810 ts->resp = SAS_TASK_COMPLETE;
2811 ts->stat = SAS_NAK_R_ERR;
2812 break;
2813 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002814 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002815 ts->resp = SAS_TASK_COMPLETE;
2816 ts->stat = SAS_DATA_UNDERRUN;
2817 break;
2818 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002819 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002820 ts->resp = SAS_TASK_COMPLETE;
2821 ts->stat = SAS_OPEN_TO;
2822 break;
2823 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002824 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002825 ts->resp = SAS_TASK_COMPLETE;
2826 ts->stat = SAS_OPEN_TO;
2827 break;
2828 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002829 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002830 ts->resp = SAS_TASK_COMPLETE;
2831 ts->stat = SAS_OPEN_TO;
2832 break;
2833 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002834 pm8001_dbg(pm8001_ha, IO,
2835 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002836 ts->resp = SAS_TASK_COMPLETE;
2837 ts->stat = SAS_OPEN_TO;
2838 break;
2839 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002840 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002841 ts->resp = SAS_TASK_COMPLETE;
2842 ts->stat = SAS_OPEN_TO;
2843 break;
2844 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002845 pm8001_dbg(pm8001_ha, IO,
2846 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002847 ts->resp = SAS_TASK_COMPLETE;
2848 ts->stat = SAS_OPEN_TO;
2849 break;
2850 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002851 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002852 break;
2853 case IO_XFER_PIO_SETUP_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002854 pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002855 ts->resp = SAS_TASK_COMPLETE;
2856 ts->stat = SAS_OPEN_TO;
2857 break;
2858 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002859 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002860 /* not allowed case. Therefore, return failed status */
2861 ts->resp = SAS_TASK_COMPLETE;
2862 ts->stat = SAS_OPEN_TO;
2863 break;
2864 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302865 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002866 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2867 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2868 t->task_state_flags |= SAS_TASK_STATE_DONE;
2869 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302870 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002871 pm8001_dbg(pm8001_ha, FAIL,
2872 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2873 t, event, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002874 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302875 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302876 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302877 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002878 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002879}
2880
2881/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002882static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002883mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2884{
jack wangdbf9bfe2009-10-14 16:19:21 +08002885 struct sas_task *t;
2886 struct pm8001_ccb_info *ccb;
2887 unsigned long flags;
2888 u32 status;
2889 u32 tag;
2890 struct smp_completion_resp *psmpPayload;
2891 struct task_status_struct *ts;
2892 struct pm8001_device *pm8001_dev;
2893
2894 psmpPayload = (struct smp_completion_resp *)(piomb + 4);
2895 status = le32_to_cpu(psmpPayload->status);
2896 tag = le32_to_cpu(psmpPayload->tag);
2897
2898 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002899 t = ccb->task;
2900 ts = &t->task_status;
2901 pm8001_dev = ccb->device;
peter chang73706722019-11-14 15:39:02 +05302902 if (status) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002903 pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status);
2904 pm8001_dbg(pm8001_ha, IOERR,
2905 "status:0x%x, tag:0x%x, task:0x%p\n",
2906 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302907 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002908 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002909 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002910
2911 switch (status) {
2912 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002913 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002914 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002915 ts->stat = SAS_SAM_STAT_GOOD;
Colin Ian King9e2a07e2019-03-17 18:15:32 +00002916 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302917 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002918 break;
2919 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002920 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002921 ts->resp = SAS_TASK_COMPLETE;
2922 ts->stat = SAS_ABORTED_TASK;
2923 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302924 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002925 break;
2926 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002927 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002928 ts->resp = SAS_TASK_COMPLETE;
2929 ts->stat = SAS_DATA_OVERRUN;
2930 ts->residual = 0;
2931 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302932 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002933 break;
2934 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002935 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002936 ts->resp = SAS_TASK_COMPLETE;
2937 ts->stat = SAS_PHY_DOWN;
2938 break;
2939 case IO_ERROR_HW_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002940 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002941 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002942 ts->stat = SAS_SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002943 break;
2944 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002945 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002946 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002947 ts->stat = SAS_SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002948 break;
2949 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002950 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002951 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002952 ts->stat = SAS_SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002953 break;
2954 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002955 pm8001_dbg(pm8001_ha, IO,
2956 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002957 ts->resp = SAS_TASK_COMPLETE;
2958 ts->stat = SAS_OPEN_REJECT;
2959 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2960 break;
2961 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002962 pm8001_dbg(pm8001_ha, IO,
2963 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002964 ts->resp = SAS_TASK_COMPLETE;
2965 ts->stat = SAS_OPEN_REJECT;
2966 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2967 break;
2968 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002969 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002970 ts->resp = SAS_TASK_COMPLETE;
2971 ts->stat = SAS_OPEN_REJECT;
2972 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2973 break;
2974 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002975 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\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_UNKNOWN;
2979 pm8001_handle_event(pm8001_ha,
2980 pm8001_dev,
2981 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2982 break;
2983 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002984 pm8001_dbg(pm8001_ha, IO,
2985 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002986 ts->resp = SAS_TASK_COMPLETE;
2987 ts->stat = SAS_OPEN_REJECT;
2988 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2989 break;
2990 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002991 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002992 ts->resp = SAS_TASK_COMPLETE;
2993 ts->stat = SAS_OPEN_REJECT;
2994 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2995 break;
2996 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002997 pm8001_dbg(pm8001_ha, IO,
2998 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002999 ts->resp = SAS_TASK_COMPLETE;
3000 ts->stat = SAS_OPEN_REJECT;
3001 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
3002 break;
3003 case IO_XFER_ERROR_RX_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08003004 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003005 ts->resp = SAS_TASK_COMPLETE;
3006 ts->stat = SAS_DEV_NO_RESPONSE;
3007 break;
3008 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003009 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003010 ts->resp = SAS_TASK_COMPLETE;
3011 ts->stat = SAS_OPEN_REJECT;
3012 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3013 break;
3014 case IO_ERROR_INTERNAL_SMP_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003015 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003016 ts->resp = SAS_TASK_COMPLETE;
3017 ts->stat = SAS_QUEUE_FULL;
3018 break;
3019 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003020 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003021 ts->resp = SAS_TASK_COMPLETE;
3022 ts->stat = SAS_OPEN_REJECT;
3023 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3024 break;
3025 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003026 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003027 ts->resp = SAS_TASK_COMPLETE;
3028 ts->stat = SAS_DEV_NO_RESPONSE;
3029 break;
3030 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003031 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003032 ts->resp = SAS_TASK_COMPLETE;
3033 ts->stat = SAS_OPEN_REJECT;
3034 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3035 break;
3036 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003037 pm8001_dbg(pm8001_ha, IO,
3038 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003039 ts->resp = SAS_TASK_COMPLETE;
3040 ts->stat = SAS_OPEN_REJECT;
3041 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3042 break;
3043 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003044 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003045 ts->resp = SAS_TASK_COMPLETE;
3046 ts->stat = SAS_DEV_NO_RESPONSE;
3047 /* not allowed case. Therefore, return failed status */
3048 break;
3049 }
3050 spin_lock_irqsave(&t->task_state_lock, flags);
3051 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3052 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3053 t->task_state_flags |= SAS_TASK_STATE_DONE;
3054 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3055 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08003056 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",
3057 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08003058 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3059 } else {
3060 spin_unlock_irqrestore(&t->task_state_lock, flags);
3061 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3062 mb();/* in order to force CPU ordering */
3063 t->task_done(t);
3064 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003065}
3066
Sakthivel Kf74cf272013-02-27 20:27:43 +05303067void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha,
3068 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003069{
3070 struct set_dev_state_resp *pPayload =
3071 (struct set_dev_state_resp *)(piomb + 4);
3072 u32 tag = le32_to_cpu(pPayload->tag);
3073 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3074 struct pm8001_device *pm8001_dev = ccb->device;
3075 u32 status = le32_to_cpu(pPayload->status);
3076 u32 device_id = le32_to_cpu(pPayload->device_id);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05303077 u8 pds = le32_to_cpu(pPayload->pds_nds) & PDS_BITS;
3078 u8 nds = le32_to_cpu(pPayload->pds_nds) & NDS_BITS;
Joe Perches1b5d2792020-11-20 15:16:09 -08003079 pm8001_dbg(pm8001_ha, MSG, "Set device id = 0x%x state from 0x%x to 0x%x status = 0x%x!\n",
3080 device_id, pds, nds, status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003081 complete(pm8001_dev->setds_completion);
3082 ccb->task = NULL;
3083 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303084 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003085}
3086
Sakthivel Kf74cf272013-02-27 20:27:43 +05303087void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003088{
3089 struct get_nvm_data_resp *pPayload =
3090 (struct get_nvm_data_resp *)(piomb + 4);
3091 u32 tag = le32_to_cpu(pPayload->tag);
3092 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3093 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3094 complete(pm8001_ha->nvmd_completion);
Joe Perches1b5d2792020-11-20 15:16:09 -08003095 pm8001_dbg(pm8001_ha, MSG, "Set nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003096 if ((dlen_status & NVMD_STAT) != 0) {
akshatzen5d280262021-01-09 18:08:45 +05303097 pm8001_dbg(pm8001_ha, FAIL, "Set nvm data error %x\n",
3098 dlen_status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003099 }
3100 ccb->task = NULL;
3101 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303102 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003103}
3104
Sakthivel Kf74cf272013-02-27 20:27:43 +05303105void
3106pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003107{
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303108 struct fw_control_ex *fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003109 struct get_nvm_data_resp *pPayload =
3110 (struct get_nvm_data_resp *)(piomb + 4);
3111 u32 tag = le32_to_cpu(pPayload->tag);
3112 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3113 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3114 u32 ir_tds_bn_dps_das_nvm =
3115 le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm);
3116 void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303117 fw_control_context = ccb->fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003118
Joe Perches1b5d2792020-11-20 15:16:09 -08003119 pm8001_dbg(pm8001_ha, MSG, "Get nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003120 if ((dlen_status & NVMD_STAT) != 0) {
akshatzen5d280262021-01-09 18:08:45 +05303121 pm8001_dbg(pm8001_ha, FAIL, "Get nvm data error %x\n",
3122 dlen_status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003123 complete(pm8001_ha->nvmd_completion);
akshatzen5d280262021-01-09 18:08:45 +05303124 /* We should free tag during failure also, the tag is not being
3125 * freed by requesting path anywhere.
3126 */
3127 ccb->task = NULL;
3128 ccb->ccb_tag = 0xFFFFFFFF;
3129 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003130 return;
3131 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003132 if (ir_tds_bn_dps_das_nvm & IPMode) {
3133 /* indirect mode - IR bit set */
Joe Perches1b5d2792020-11-20 15:16:09 -08003134 pm8001_dbg(pm8001_ha, MSG, "Get NVMD success, IR=1\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003135 if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) {
3136 if (ir_tds_bn_dps_das_nvm == 0x80a80200) {
3137 memcpy(pm8001_ha->sas_addr,
3138 ((u8 *)virt_addr + 4),
3139 SAS_ADDR_SIZE);
Joe Perches1b5d2792020-11-20 15:16:09 -08003140 pm8001_dbg(pm8001_ha, MSG, "Get SAS address from VPD successfully!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003141 }
3142 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM)
3143 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) ||
3144 ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) {
3145 ;
3146 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP)
3147 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) {
3148 ;
3149 } else {
3150 /* Should not be happened*/
Joe Perches1b5d2792020-11-20 15:16:09 -08003151 pm8001_dbg(pm8001_ha, MSG,
3152 "(IR=1)Wrong Device type 0x%x\n",
3153 ir_tds_bn_dps_das_nvm);
jack wangdbf9bfe2009-10-14 16:19:21 +08003154 }
3155 } else /* direct mode */{
Joe Perches1b5d2792020-11-20 15:16:09 -08003156 pm8001_dbg(pm8001_ha, MSG,
3157 "Get NVMD success, IR=0, dataLen=%d\n",
3158 (dlen_status & NVMD_LEN) >> 24);
jack wangdbf9bfe2009-10-14 16:19:21 +08003159 }
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303160 /* Though fw_control_context is freed below, usrAddr still needs
3161 * to be updated as this holds the response to the request function
3162 */
3163 memcpy(fw_control_context->usrAddr,
3164 pm8001_ha->memoryMap.region[NVMD].virt_ptr,
3165 fw_control_context->len);
Tomas Henzlf3a06552014-07-07 17:19:58 +02003166 kfree(ccb->fw_control_context);
yuuzheng1f889b52020-11-02 22:25:28 +05303167 /* To avoid race condition, complete should be
3168 * called after the message is copied to
3169 * fw_control_context->usrAddr
3170 */
3171 complete(pm8001_ha->nvmd_completion);
Joe Perches1b5d2792020-11-20 15:16:09 -08003172 pm8001_dbg(pm8001_ha, MSG, "Set nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003173 ccb->task = NULL;
3174 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303175 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003176}
3177
Sakthivel Kf74cf272013-02-27 20:27:43 +05303178int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003179{
Viswas G25c6edb2017-10-18 11:39:10 +05303180 u32 tag;
jack wangdbf9bfe2009-10-14 16:19:21 +08003181 struct local_phy_ctl_resp *pPayload =
3182 (struct local_phy_ctl_resp *)(piomb + 4);
3183 u32 status = le32_to_cpu(pPayload->status);
3184 u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
3185 u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
Viswas G25c6edb2017-10-18 11:39:10 +05303186 tag = le32_to_cpu(pPayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003187 if (status != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003188 pm8001_dbg(pm8001_ha, MSG,
3189 "%x phy execute %x phy op failed!\n",
3190 phy_id, phy_op);
Viswas G869ddbd2017-10-18 11:39:13 +05303191 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08003192 pm8001_dbg(pm8001_ha, MSG,
3193 "%x phy execute %x phy op success!\n",
3194 phy_id, phy_op);
Viswas G869ddbd2017-10-18 11:39:13 +05303195 pm8001_ha->phy[phy_id].reset_success = true;
3196 }
3197 if (pm8001_ha->phy[phy_id].enable_completion) {
3198 complete(pm8001_ha->phy[phy_id].enable_completion);
3199 pm8001_ha->phy[phy_id].enable_completion = NULL;
3200 }
Viswas G25c6edb2017-10-18 11:39:10 +05303201 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003202 return 0;
3203}
3204
3205/**
3206 * pm8001_bytes_dmaed - one of the interface function communication with libsas
3207 * @pm8001_ha: our hba card information
3208 * @i: which phy that received the event.
3209 *
3210 * when HBA driver received the identify done event or initiate FIS received
3211 * event(for SATA), it will invoke this function to notify the sas layer that
3212 * the sas toplogy has formed, please discover the the whole sas domain,
3213 * while receive a broadcast(change) primitive just tell the sas
3214 * layer to discover the changed domain rather than the whole domain.
3215 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303216void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i)
jack wangdbf9bfe2009-10-14 16:19:21 +08003217{
3218 struct pm8001_phy *phy = &pm8001_ha->phy[i];
3219 struct asd_sas_phy *sas_phy = &phy->sas_phy;
jack wangdbf9bfe2009-10-14 16:19:21 +08003220 if (!phy->phy_attached)
3221 return;
3222
jack wangdbf9bfe2009-10-14 16:19:21 +08003223 if (sas_phy->phy) {
3224 struct sas_phy *sphy = sas_phy->phy;
3225 sphy->negotiated_linkrate = sas_phy->linkrate;
3226 sphy->minimum_linkrate = phy->minimum_linkrate;
3227 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3228 sphy->maximum_linkrate = phy->maximum_linkrate;
3229 sphy->maximum_linkrate_hw = phy->maximum_linkrate;
3230 }
3231
3232 if (phy->phy_type & PORT_TYPE_SAS) {
3233 struct sas_identify_frame *id;
3234 id = (struct sas_identify_frame *)phy->frame_rcvd;
3235 id->dev_type = phy->identify.device_type;
3236 id->initiator_bits = SAS_PROTOCOL_ALL;
3237 id->target_bits = phy->identify.target_port_protocols;
3238 } else if (phy->phy_type & PORT_TYPE_SATA) {
3239 /*Nothing*/
3240 }
Joe Perches1b5d2792020-11-20 15:16:09 -08003241 pm8001_dbg(pm8001_ha, MSG, "phy %d byte dmaded.\n", i);
jack wangdbf9bfe2009-10-14 16:19:21 +08003242
3243 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003244 sas_notify_port_event(sas_phy, PORTE_BYTES_DMAED, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003245}
3246
3247/* Get the link rate speed */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303248void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate)
jack wangdbf9bfe2009-10-14 16:19:21 +08003249{
3250 struct sas_phy *sas_phy = phy->sas_phy.phy;
3251
3252 switch (link_rate) {
Viswas Gb093d592015-08-11 15:06:25 +05303253 case PHY_SPEED_120:
3254 phy->sas_phy.linkrate = SAS_LINK_RATE_12_0_GBPS;
3255 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_12_0_GBPS;
3256 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08003257 case PHY_SPEED_60:
3258 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
3259 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3260 break;
3261 case PHY_SPEED_30:
3262 phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
3263 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3264 break;
3265 case PHY_SPEED_15:
3266 phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
3267 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
3268 break;
3269 }
3270 sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
3271 sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS;
3272 sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3273 sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
3274 sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3275}
3276
3277/**
Lee Jones6b87e432021-03-03 14:46:19 +00003278 * pm8001_get_attached_sas_addr - extract/generate attached SAS address
jack wangdbf9bfe2009-10-14 16:19:21 +08003279 * @phy: pointer to asd_phy
3280 * @sas_addr: pointer to buffer where the SAS address is to be written
3281 *
3282 * This function extracts the SAS address from an IDENTIFY frame
3283 * received. If OOB is SATA, then a SAS address is generated from the
3284 * HA tables.
3285 *
3286 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
3287 * buffer.
3288 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303289void pm8001_get_attached_sas_addr(struct pm8001_phy *phy,
jack wangdbf9bfe2009-10-14 16:19:21 +08003290 u8 *sas_addr)
3291{
3292 if (phy->sas_phy.frame_rcvd[0] == 0x34
3293 && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
3294 struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha;
3295 /* FIS device-to-host */
3296 u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr);
3297 addr += phy->sas_phy.id;
3298 *(__be64 *)sas_addr = cpu_to_be64(addr);
3299 } else {
3300 struct sas_identify_frame *idframe =
3301 (void *) phy->sas_phy.frame_rcvd;
3302 memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
3303 }
3304}
3305
3306/**
3307 * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
3308 * @pm8001_ha: our hba card information
3309 * @Qnum: the outbound queue message number.
3310 * @SEA: source of event to ack
3311 * @port_id: port id.
3312 * @phyId: phy id.
3313 * @param0: parameter 0.
3314 * @param1: parameter 1.
3315 */
3316static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3317 u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3318{
3319 struct hw_event_ack_req payload;
3320 u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3321
3322 struct inbound_queue_table *circularQ;
3323
3324 memset((u8 *)&payload, 0, sizeof(payload));
3325 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
Santosh Nayak8270ee22012-02-26 20:14:46 +05303326 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08003327 payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3328 ((phyId & 0x0F) << 4) | (port_id & 0x0F));
3329 payload.param0 = cpu_to_le32(param0);
3330 payload.param1 = cpu_to_le32(param1);
peter chang91a43fa2019-11-14 15:39:05 +05303331 pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
3332 sizeof(payload), 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08003333}
3334
3335static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3336 u32 phyId, u32 phy_op);
3337
3338/**
3339 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
3340 * @pm8001_ha: our hba card information
3341 * @piomb: IO message buffer
3342 */
3343static void
3344hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3345{
3346 struct hw_event_resp *pPayload =
3347 (struct hw_event_resp *)(piomb + 4);
3348 u32 lr_evt_status_phyid_portid =
3349 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3350 u8 link_rate =
3351 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003352 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003353 u8 phy_id =
3354 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003355 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3356 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3357 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003358 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3359 unsigned long flags;
3360 u8 deviceType = pPayload->sas_identify.dev_type;
jack wang1cc943a2009-12-07 17:22:42 +08003361 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303362 phy->phy_state = PHY_STATE_LINK_UP_SPC;
Joe Perches1b5d2792020-11-20 15:16:09 -08003363 pm8001_dbg(pm8001_ha, MSG,
3364 "HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n",
3365 port_id, phy_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003366
3367 switch (deviceType) {
3368 case SAS_PHY_UNUSED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003369 pm8001_dbg(pm8001_ha, MSG, "device type no device.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003370 break;
3371 case SAS_END_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003372 pm8001_dbg(pm8001_ha, MSG, "end device.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003373 pm8001_chip_phy_ctl_req(pm8001_ha, phy_id,
3374 PHY_NOTIFY_ENABLE_SPINUP);
jack wang1cc943a2009-12-07 17:22:42 +08003375 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303376 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003377 break;
3378 case SAS_EDGE_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003379 pm8001_dbg(pm8001_ha, MSG, "expander device.\n");
jack wang1cc943a2009-12-07 17:22:42 +08003380 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303381 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003382 break;
3383 case SAS_FANOUT_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003384 pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n");
jack wang1cc943a2009-12-07 17:22:42 +08003385 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303386 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003387 break;
3388 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003389 pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n",
3390 deviceType);
jack wangdbf9bfe2009-10-14 16:19:21 +08003391 break;
3392 }
3393 phy->phy_type |= PORT_TYPE_SAS;
3394 phy->identify.device_type = deviceType;
3395 phy->phy_attached = 1;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303396 if (phy->identify.device_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08003397 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303398 else if (phy->identify.device_type != SAS_PHY_UNUSED)
jack wangdbf9bfe2009-10-14 16:19:21 +08003399 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3400 phy->sas_phy.oob_mode = SAS_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003401 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003402 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3403 memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3404 sizeof(struct sas_identify_frame)-4);
3405 phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3406 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3407 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3408 if (pm8001_ha->flags == PM8001F_RUN_TIME)
3409 mdelay(200);/*delay a moment to wait disk to spinup*/
3410 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3411}
3412
3413/**
3414 * hw_event_sata_phy_up -FW tells me a SATA phy up event.
3415 * @pm8001_ha: our hba card information
3416 * @piomb: IO message buffer
3417 */
3418static void
3419hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3420{
3421 struct hw_event_resp *pPayload =
3422 (struct hw_event_resp *)(piomb + 4);
3423 u32 lr_evt_status_phyid_portid =
3424 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3425 u8 link_rate =
3426 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003427 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003428 u8 phy_id =
3429 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003430 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3431 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3432 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003433 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3434 unsigned long flags;
Joe Perches1b5d2792020-11-20 15:16:09 -08003435 pm8001_dbg(pm8001_ha, DEVIO, "HW_EVENT_SATA_PHY_UP port id = %d, phy id = %d\n",
3436 port_id, phy_id);
jack wang1cc943a2009-12-07 17:22:42 +08003437 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303438 phy->phy_state = PHY_STATE_LINK_UP_SPC;
jack wang1cc943a2009-12-07 17:22:42 +08003439 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303440 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003441 phy->phy_type |= PORT_TYPE_SATA;
3442 phy->phy_attached = 1;
3443 phy->sas_phy.oob_mode = SATA_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003444 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003445 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3446 memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3447 sizeof(struct dev_to_host_fis));
3448 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3449 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
James Bottomleyaa9f8322013-05-07 14:44:06 -07003450 phy->identify.device_type = SAS_SATA_DEV;
jack wangdbf9bfe2009-10-14 16:19:21 +08003451 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3452 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3453 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3454}
3455
3456/**
3457 * hw_event_phy_down -we should notify the libsas the phy is down.
3458 * @pm8001_ha: our hba card information
3459 * @piomb: IO message buffer
3460 */
3461static void
3462hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3463{
3464 struct hw_event_resp *pPayload =
3465 (struct hw_event_resp *)(piomb + 4);
3466 u32 lr_evt_status_phyid_portid =
3467 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3468 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3469 u8 phy_id =
3470 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3471 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3472 u8 portstate = (u8)(npip_portstate & 0x0000000F);
jack wang1cc943a2009-12-07 17:22:42 +08003473 struct pm8001_port *port = &pm8001_ha->port[port_id];
3474 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3475 port->port_state = portstate;
3476 phy->phy_type = 0;
3477 phy->identify.device_type = 0;
3478 phy->phy_attached = 0;
3479 memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
jack wangdbf9bfe2009-10-14 16:19:21 +08003480 switch (portstate) {
3481 case PORT_VALID:
3482 break;
3483 case PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003484 pm8001_dbg(pm8001_ha, MSG, " PortInvalid portID %d\n",
3485 port_id);
3486 pm8001_dbg(pm8001_ha, MSG,
3487 " Last phy Down and port invalid\n");
jack wang1cc943a2009-12-07 17:22:42 +08003488 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003489 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3490 port_id, phy_id, 0, 0);
3491 break;
3492 case PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003493 pm8001_dbg(pm8001_ha, MSG, " Port In Reset portID %d\n",
3494 port_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003495 break;
3496 case PORT_NOT_ESTABLISHED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003497 pm8001_dbg(pm8001_ha, MSG,
3498 " phy Down and PORT_NOT_ESTABLISHED\n");
jack wang1cc943a2009-12-07 17:22:42 +08003499 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003500 break;
3501 case PORT_LOSTCOMM:
Joe Perches1b5d2792020-11-20 15:16:09 -08003502 pm8001_dbg(pm8001_ha, MSG, " phy Down and PORT_LOSTCOMM\n");
3503 pm8001_dbg(pm8001_ha, MSG,
3504 " Last phy Down and port invalid\n");
jack wang1cc943a2009-12-07 17:22:42 +08003505 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003506 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3507 port_id, phy_id, 0, 0);
3508 break;
3509 default:
jack wang1cc943a2009-12-07 17:22:42 +08003510 port->port_attached = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08003511 pm8001_dbg(pm8001_ha, DEVIO, " phy Down and(default) = %x\n",
3512 portstate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003513 break;
3514
3515 }
3516}
3517
3518/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05303519 * pm8001_mpi_reg_resp -process register device ID response.
jack wangdbf9bfe2009-10-14 16:19:21 +08003520 * @pm8001_ha: our hba card information
3521 * @piomb: IO message buffer
3522 *
3523 * when sas layer find a device it will notify LLDD, then the driver register
3524 * the domain device to FW, this event is the return device ID which the FW
3525 * has assigned, from now,inter-communication with FW is no longer using the
3526 * SAS address, use device ID which FW assigned.
3527 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303528int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003529{
3530 u32 status;
3531 u32 device_id;
3532 u32 htag;
3533 struct pm8001_ccb_info *ccb;
3534 struct pm8001_device *pm8001_dev;
3535 struct dev_reg_resp *registerRespPayload =
3536 (struct dev_reg_resp *)(piomb + 4);
3537
3538 htag = le32_to_cpu(registerRespPayload->tag);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303539 ccb = &pm8001_ha->ccb_info[htag];
jack wangdbf9bfe2009-10-14 16:19:21 +08003540 pm8001_dev = ccb->device;
3541 status = le32_to_cpu(registerRespPayload->status);
3542 device_id = le32_to_cpu(registerRespPayload->device_id);
Joe Perches1b5d2792020-11-20 15:16:09 -08003543 pm8001_dbg(pm8001_ha, MSG, " register device is status = %d\n",
3544 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003545 switch (status) {
3546 case DEVREG_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003547 pm8001_dbg(pm8001_ha, MSG, "DEVREG_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003548 pm8001_dev->device_id = device_id;
3549 break;
3550 case DEVREG_FAILURE_OUT_OF_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003551 pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_OUT_OF_RESOURCE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003552 break;
3553 case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003554 pm8001_dbg(pm8001_ha, MSG,
3555 "DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003556 break;
3557 case DEVREG_FAILURE_INVALID_PHY_ID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003558 pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_INVALID_PHY_ID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003559 break;
3560 case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003561 pm8001_dbg(pm8001_ha, MSG,
3562 "DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003563 break;
3564 case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003565 pm8001_dbg(pm8001_ha, MSG,
3566 "DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003567 break;
3568 case DEVREG_FAILURE_PORT_NOT_VALID_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003569 pm8001_dbg(pm8001_ha, MSG,
3570 "DEVREG_FAILURE_PORT_NOT_VALID_STATE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003571 break;
3572 case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003573 pm8001_dbg(pm8001_ha, MSG,
3574 "DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003575 break;
3576 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003577 pm8001_dbg(pm8001_ha, MSG,
3578 "DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003579 break;
3580 }
3581 complete(pm8001_dev->dcompletion);
3582 ccb->task = NULL;
3583 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303584 pm8001_tag_free(pm8001_ha, htag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003585 return 0;
3586}
3587
Sakthivel Kf74cf272013-02-27 20:27:43 +05303588int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003589{
3590 u32 status;
3591 u32 device_id;
3592 struct dev_reg_resp *registerRespPayload =
3593 (struct dev_reg_resp *)(piomb + 4);
3594
3595 status = le32_to_cpu(registerRespPayload->status);
3596 device_id = le32_to_cpu(registerRespPayload->device_id);
3597 if (status != 0)
Joe Perches1b5d2792020-11-20 15:16:09 -08003598 pm8001_dbg(pm8001_ha, MSG,
3599 " deregister device failed ,status = %x, device_id = %x\n",
3600 status, device_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003601 return 0;
3602}
3603
Sakthivel Kf74cf272013-02-27 20:27:43 +05303604/**
Lee Jones6b87e432021-03-03 14:46:19 +00003605 * pm8001_mpi_fw_flash_update_resp - Response from FW for flash update command.
Sakthivel Kf74cf272013-02-27 20:27:43 +05303606 * @pm8001_ha: our hba card information
3607 * @piomb: IO message buffer
3608 */
3609int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha,
3610 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003611{
3612 u32 status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003613 struct fw_flash_Update_resp *ppayload =
3614 (struct fw_flash_Update_resp *)(piomb + 4);
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303615 u32 tag = le32_to_cpu(ppayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003616 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3617 status = le32_to_cpu(ppayload->status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003618 switch (status) {
3619 case FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003620 pm8001_dbg(pm8001_ha, MSG,
3621 ": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003622 break;
3623 case FLASH_UPDATE_IN_PROGRESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003624 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_IN_PROGRESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003625 break;
3626 case FLASH_UPDATE_HDR_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003627 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HDR_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003628 break;
3629 case FLASH_UPDATE_OFFSET_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003630 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_OFFSET_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003631 break;
3632 case FLASH_UPDATE_CRC_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003633 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_CRC_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003634 break;
3635 case FLASH_UPDATE_LENGTH_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003636 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_LENGTH_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003637 break;
3638 case FLASH_UPDATE_HW_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003639 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HW_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003640 break;
3641 case FLASH_UPDATE_DNLD_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003642 pm8001_dbg(pm8001_ha, MSG,
3643 ": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003644 break;
3645 case FLASH_UPDATE_DISABLED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003646 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_DISABLED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003647 break;
3648 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003649 pm8001_dbg(pm8001_ha, DEVIO, "No matched status = %d\n",
3650 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003651 break;
3652 }
Tomas Henzl9422e862014-07-07 17:20:00 +02003653 kfree(ccb->fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08003654 ccb->task = NULL;
3655 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303656 pm8001_tag_free(pm8001_ha, tag);
Tomas Henzl9422e862014-07-07 17:20:00 +02003657 complete(pm8001_ha->nvmd_completion);
jack wangdbf9bfe2009-10-14 16:19:21 +08003658 return 0;
3659}
3660
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08003661int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003662{
3663 u32 status;
3664 int i;
3665 struct general_event_resp *pPayload =
3666 (struct general_event_resp *)(piomb + 4);
3667 status = le32_to_cpu(pPayload->status);
Joe Perches1b5d2792020-11-20 15:16:09 -08003668 pm8001_dbg(pm8001_ha, MSG, " status = 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003669 for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
Joe Perches1b5d2792020-11-20 15:16:09 -08003670 pm8001_dbg(pm8001_ha, MSG, "inb_IOMB_payload[0x%x] 0x%x,\n",
3671 i,
3672 pPayload->inb_IOMB_payload[i]);
jack wangdbf9bfe2009-10-14 16:19:21 +08003673 return 0;
3674}
3675
Sakthivel Kf74cf272013-02-27 20:27:43 +05303676int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003677{
3678 struct sas_task *t;
3679 struct pm8001_ccb_info *ccb;
3680 unsigned long flags;
3681 u32 status ;
3682 u32 tag, scp;
3683 struct task_status_struct *ts;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303684 struct pm8001_device *pm8001_dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08003685
3686 struct task_abort_resp *pPayload =
3687 (struct task_abort_resp *)(piomb + 4);
jack wangdbf9bfe2009-10-14 16:19:21 +08003688
3689 status = le32_to_cpu(pPayload->status);
3690 tag = le32_to_cpu(pPayload->tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303691 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003692 pm8001_dbg(pm8001_ha, FAIL, " TAG NULL. RETURNING !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303693 return -1;
3694 }
3695
jack wangdbf9bfe2009-10-14 16:19:21 +08003696 scp = le32_to_cpu(pPayload->scp);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303697 ccb = &pm8001_ha->ccb_info[tag];
3698 t = ccb->task;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303699 pm8001_dev = ccb->device; /* retrieve device */
3700
3701 if (!t) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003702 pm8001_dbg(pm8001_ha, FAIL, " TASK NULL. RETURNING !!!\n");
jack_wang72d0baa2009-11-05 22:33:35 +08003703 return -1;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303704 }
jack_wang72d0baa2009-11-05 22:33:35 +08003705 ts = &t->task_status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003706 if (status != 0)
Joe Perches1b5d2792020-11-20 15:16:09 -08003707 pm8001_dbg(pm8001_ha, FAIL, "task abort failed status 0x%x ,tag = 0x%x, scp= 0x%x\n",
3708 status, tag, scp);
jack wangdbf9bfe2009-10-14 16:19:21 +08003709 switch (status) {
3710 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003711 pm8001_dbg(pm8001_ha, EH, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003712 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07003713 ts->stat = SAS_SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08003714 break;
3715 case IO_NOT_VALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003716 pm8001_dbg(pm8001_ha, EH, "IO_NOT_VALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003717 ts->resp = TMF_RESP_FUNC_FAILED;
3718 break;
3719 }
3720 spin_lock_irqsave(&t->task_state_lock, flags);
3721 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3722 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3723 t->task_state_flags |= SAS_TASK_STATE_DONE;
3724 spin_unlock_irqrestore(&t->task_state_lock, flags);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303725 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003726 mb();
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303727
Dan Carpenter808cbb62013-05-09 15:48:13 +03003728 if (pm8001_dev->id & NCQ_ABORT_ALL_FLAG) {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303729 pm8001_tag_free(pm8001_ha, tag);
3730 sas_free_task(t);
3731 /* clear the flag */
3732 pm8001_dev->id &= 0xBFFFFFFF;
3733 } else
3734 t->task_done(t);
3735
jack wangdbf9bfe2009-10-14 16:19:21 +08003736 return 0;
3737}
3738
3739/**
3740 * mpi_hw_event -The hw event has come.
3741 * @pm8001_ha: our hba card information
3742 * @piomb: IO message buffer
3743 */
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08003744static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003745{
3746 unsigned long flags;
3747 struct hw_event_resp *pPayload =
3748 (struct hw_event_resp *)(piomb + 4);
3749 u32 lr_evt_status_phyid_portid =
3750 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3751 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3752 u8 phy_id =
3753 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3754 u16 eventType =
3755 (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8);
3756 u8 status =
3757 (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24);
3758 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3759 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3760 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
Joe Perches1b5d2792020-11-20 15:16:09 -08003761 pm8001_dbg(pm8001_ha, DEVIO,
3762 "SPC HW event for portid:%d, phyid:%d, event:%x, status:%x\n",
3763 port_id, phy_id, eventType, status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003764 switch (eventType) {
3765 case HW_EVENT_PHY_START_STATUS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003766 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS status = %x\n",
3767 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003768 if (status == 0) {
3769 phy->phy_state = 1;
Deepak Ukeycd135752018-09-11 14:18:02 +05303770 if (pm8001_ha->flags == PM8001F_RUN_TIME &&
3771 phy->enable_completion != NULL)
jack wangdbf9bfe2009-10-14 16:19:21 +08003772 complete(phy->enable_completion);
3773 }
3774 break;
3775 case HW_EVENT_SAS_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003776 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003777 hw_event_sas_phy_up(pm8001_ha, piomb);
3778 break;
3779 case HW_EVENT_SATA_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003780 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_PHY_UP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003781 hw_event_sata_phy_up(pm8001_ha, piomb);
3782 break;
3783 case HW_EVENT_PHY_STOP_STATUS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003784 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_STOP_STATUS status = %x\n",
3785 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003786 if (status == 0)
3787 phy->phy_state = 0;
3788 break;
3789 case HW_EVENT_SATA_SPINUP_HOLD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003790 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_SPINUP_HOLD\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003791 sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003792 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003793 break;
3794 case HW_EVENT_PHY_DOWN:
Joe Perches1b5d2792020-11-20 15:16:09 -08003795 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_DOWN\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003796 sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003797 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003798 phy->phy_attached = 0;
3799 phy->phy_state = 0;
3800 hw_event_phy_down(pm8001_ha, piomb);
3801 break;
3802 case HW_EVENT_PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003803 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_INVALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003804 sas_phy_disconnected(sas_phy);
3805 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003806 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003807 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003808 break;
3809 /* the broadcast change primitive received, tell the LIBSAS this event
3810 to revalidate the sas domain*/
3811 case HW_EVENT_BROADCAST_CHANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003812 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003813 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3814 port_id, phy_id, 1, 0);
3815 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3816 sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3817 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003818 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003819 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003820 break;
3821 case HW_EVENT_PHY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003822 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003823 sas_phy_disconnected(&phy->sas_phy);
3824 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003825 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003826 break;
3827 case HW_EVENT_BROADCAST_EXP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003828 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003829 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3830 sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3831 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003832 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003833 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003834 break;
3835 case HW_EVENT_LINK_ERR_INVALID_DWORD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003836 pm8001_dbg(pm8001_ha, MSG,
3837 "HW_EVENT_LINK_ERR_INVALID_DWORD\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003838 pm8001_hw_event_ack_req(pm8001_ha, 0,
3839 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3840 sas_phy_disconnected(sas_phy);
3841 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003842 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003843 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003844 break;
3845 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003846 pm8001_dbg(pm8001_ha, MSG,
3847 "HW_EVENT_LINK_ERR_DISPARITY_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003848 pm8001_hw_event_ack_req(pm8001_ha, 0,
3849 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3850 port_id, phy_id, 0, 0);
3851 sas_phy_disconnected(sas_phy);
3852 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003853 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003854 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003855 break;
3856 case HW_EVENT_LINK_ERR_CODE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003857 pm8001_dbg(pm8001_ha, MSG,
3858 "HW_EVENT_LINK_ERR_CODE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003859 pm8001_hw_event_ack_req(pm8001_ha, 0,
3860 HW_EVENT_LINK_ERR_CODE_VIOLATION,
3861 port_id, phy_id, 0, 0);
3862 sas_phy_disconnected(sas_phy);
3863 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003864 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003865 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003866 break;
3867 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08003868 pm8001_dbg(pm8001_ha, MSG,
3869 "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003870 pm8001_hw_event_ack_req(pm8001_ha, 0,
3871 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3872 port_id, phy_id, 0, 0);
3873 sas_phy_disconnected(sas_phy);
3874 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003875 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003876 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003877 break;
3878 case HW_EVENT_MALFUNCTION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003879 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_MALFUNCTION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003880 break;
3881 case HW_EVENT_BROADCAST_SES:
Joe Perches1b5d2792020-11-20 15:16:09 -08003882 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003883 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3884 sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3885 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003886 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003887 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003888 break;
3889 case HW_EVENT_INBOUND_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003890 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_INBOUND_CRC_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003891 pm8001_hw_event_ack_req(pm8001_ha, 0,
3892 HW_EVENT_INBOUND_CRC_ERROR,
3893 port_id, phy_id, 0, 0);
3894 break;
3895 case HW_EVENT_HARD_RESET_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003896 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_HARD_RESET_RECEIVED\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003897 sas_notify_port_event(sas_phy, PORTE_HARD_RESET, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003898 break;
3899 case HW_EVENT_ID_FRAME_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003900 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_ID_FRAME_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003901 sas_phy_disconnected(sas_phy);
3902 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003903 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003904 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003905 break;
3906 case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003907 pm8001_dbg(pm8001_ha, MSG,
3908 "HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003909 pm8001_hw_event_ack_req(pm8001_ha, 0,
3910 HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3911 port_id, phy_id, 0, 0);
3912 sas_phy_disconnected(sas_phy);
3913 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003914 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003915 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003916 break;
3917 case HW_EVENT_PORT_RESET_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003918 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_TIMER_TMO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003919 sas_phy_disconnected(sas_phy);
3920 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003921 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003922 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003923 break;
3924 case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003925 pm8001_dbg(pm8001_ha, MSG,
3926 "HW_EVENT_PORT_RECOVERY_TIMER_TMO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003927 sas_phy_disconnected(sas_phy);
3928 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003929 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003930 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003931 break;
3932 case HW_EVENT_PORT_RECOVER:
Joe Perches1b5d2792020-11-20 15:16:09 -08003933 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RECOVER\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003934 break;
3935 case HW_EVENT_PORT_RESET_COMPLETE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003936 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_COMPLETE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003937 break;
3938 case EVENT_BROADCAST_ASYNCH_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003939 pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003940 break;
3941 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003942 pm8001_dbg(pm8001_ha, DEVIO, "Unknown event type = %x\n",
3943 eventType);
jack wangdbf9bfe2009-10-14 16:19:21 +08003944 break;
3945 }
3946 return 0;
3947}
3948
3949/**
3950 * process_one_iomb - process one outbound Queue memory block
3951 * @pm8001_ha: our hba card information
3952 * @piomb: IO message buffer
3953 */
3954static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3955{
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303956 __le32 pHeader = *(__le32 *)piomb;
3957 u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF);
jack wangdbf9bfe2009-10-14 16:19:21 +08003958
Joe Perches1b5d2792020-11-20 15:16:09 -08003959 pm8001_dbg(pm8001_ha, MSG, "process_one_iomb:\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003960
3961 switch (opc) {
3962 case OPC_OUB_ECHO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003963 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003964 break;
3965 case OPC_OUB_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003966 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003967 mpi_hw_event(pm8001_ha, piomb);
3968 break;
3969 case OPC_OUB_SSP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003970 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003971 mpi_ssp_completion(pm8001_ha, piomb);
3972 break;
3973 case OPC_OUB_SMP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003974 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003975 mpi_smp_completion(pm8001_ha, piomb);
3976 break;
3977 case OPC_OUB_LOCAL_PHY_CNTRL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003978 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303979 pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003980 break;
3981 case OPC_OUB_DEV_REGIST:
Joe Perches1b5d2792020-11-20 15:16:09 -08003982 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303983 pm8001_mpi_reg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003984 break;
3985 case OPC_OUB_DEREG_DEV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003986 pm8001_dbg(pm8001_ha, MSG, "unregister the device\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303987 pm8001_mpi_dereg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003988 break;
3989 case OPC_OUB_GET_DEV_HANDLE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003990 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003991 break;
3992 case OPC_OUB_SATA_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003993 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003994 mpi_sata_completion(pm8001_ha, piomb);
3995 break;
3996 case OPC_OUB_SATA_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003997 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003998 mpi_sata_event(pm8001_ha, piomb);
3999 break;
4000 case OPC_OUB_SSP_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004001 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004002 mpi_ssp_event(pm8001_ha, piomb);
4003 break;
4004 case OPC_OUB_DEV_HANDLE_ARRIV:
Joe Perches1b5d2792020-11-20 15:16:09 -08004005 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004006 /*This is for target*/
4007 break;
4008 case OPC_OUB_SSP_RECV_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004009 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004010 /*This is for target*/
4011 break;
4012 case OPC_OUB_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08004013 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_INFO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004014 break;
4015 case OPC_OUB_FW_FLASH_UPDATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004016 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304017 pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004018 break;
4019 case OPC_OUB_GPIO_RESPONSE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004020 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004021 break;
4022 case OPC_OUB_GPIO_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004023 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004024 break;
4025 case OPC_OUB_GENERAL_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004026 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304027 pm8001_mpi_general_event(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004028 break;
4029 case OPC_OUB_SSP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004030 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304031 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004032 break;
4033 case OPC_OUB_SATA_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004034 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304035 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004036 break;
4037 case OPC_OUB_SAS_DIAG_MODE_START_END:
Joe Perches1b5d2792020-11-20 15:16:09 -08004038 pm8001_dbg(pm8001_ha, MSG,
4039 "OPC_OUB_SAS_DIAG_MODE_START_END\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004040 break;
4041 case OPC_OUB_SAS_DIAG_EXECUTE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004042 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004043 break;
4044 case OPC_OUB_GET_TIME_STAMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004045 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004046 break;
4047 case OPC_OUB_SAS_HW_EVENT_ACK:
Joe Perches1b5d2792020-11-20 15:16:09 -08004048 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004049 break;
4050 case OPC_OUB_PORT_CONTROL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004051 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004052 break;
4053 case OPC_OUB_SMP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004054 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304055 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004056 break;
4057 case OPC_OUB_GET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004058 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304059 pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004060 break;
4061 case OPC_OUB_SET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004062 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304063 pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004064 break;
4065 case OPC_OUB_DEVICE_HANDLE_REMOVAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004066 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004067 break;
4068 case OPC_OUB_SET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004069 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304070 pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004071 break;
4072 case OPC_OUB_GET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004073 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004074 break;
4075 case OPC_OUB_SET_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08004076 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004077 break;
4078 case OPC_OUB_SAS_RE_INITIALIZE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004079 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_RE_INITIALIZE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004080 break;
4081 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08004082 pm8001_dbg(pm8001_ha, DEVIO,
4083 "Unknown outbound Queue IOMB OPC = %x\n",
4084 opc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004085 break;
4086 }
4087}
4088
Sakthivel Kf74cf272013-02-27 20:27:43 +05304089static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004090{
4091 struct outbound_queue_table *circularQ;
4092 void *pMsg1 = NULL;
Kees Cook3f649ab2020-06-03 13:09:38 -07004093 u8 bc;
jack_wang72d0baa2009-11-05 22:33:35 +08004094 u32 ret = MPI_IO_STATUS_FAIL;
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304095 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004096
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304097 spin_lock_irqsave(&pm8001_ha->lock, flags);
Sakthivel Kf74cf272013-02-27 20:27:43 +05304098 circularQ = &pm8001_ha->outbnd_q_tbl[vec];
jack wangdbf9bfe2009-10-14 16:19:21 +08004099 do {
Sakthivel Kf74cf272013-02-27 20:27:43 +05304100 ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004101 if (MPI_IO_STATUS_SUCCESS == ret) {
4102 /* process the outbound message */
jack_wang72d0baa2009-11-05 22:33:35 +08004103 process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
jack wangdbf9bfe2009-10-14 16:19:21 +08004104 /* free the message from the outbound circular buffer */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304105 pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4106 circularQ, bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004107 }
4108 if (MPI_IO_STATUS_BUSY == ret) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004109 /* Update the producer index from SPC */
Santosh Nayak8270ee22012-02-26 20:14:46 +05304110 circularQ->producer_index =
4111 cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4112 if (le32_to_cpu(circularQ->producer_index) ==
jack wangdbf9bfe2009-10-14 16:19:21 +08004113 circularQ->consumer_idx)
4114 /* OQ is empty */
4115 break;
4116 }
jack_wang72d0baa2009-11-05 22:33:35 +08004117 } while (1);
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304118 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08004119 return ret;
4120}
4121
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004122/* DMA_... to our direction translation. */
jack wangdbf9bfe2009-10-14 16:19:21 +08004123static const u8 data_dir_flags[] = {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004124 [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
4125 [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
4126 [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */
4127 [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */
jack wangdbf9bfe2009-10-14 16:19:21 +08004128};
Sakthivel Kf74cf272013-02-27 20:27:43 +05304129void
jack wangdbf9bfe2009-10-14 16:19:21 +08004130pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
4131{
4132 int i;
4133 struct scatterlist *sg;
4134 struct pm8001_prd *buf_prd = prd;
4135
4136 for_each_sg(scatter, sg, nr, i) {
4137 buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
4138 buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
4139 buf_prd->im_len.e = 0;
4140 buf_prd++;
4141 }
4142}
4143
Santosh Nayak8270ee22012-02-26 20:14:46 +05304144static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd)
jack wangdbf9bfe2009-10-14 16:19:21 +08004145{
Santosh Nayak8270ee22012-02-26 20:14:46 +05304146 psmp_cmd->tag = hTag;
jack wangdbf9bfe2009-10-14 16:19:21 +08004147 psmp_cmd->device_id = cpu_to_le32(deviceID);
4148 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4149}
4150
4151/**
4152 * pm8001_chip_smp_req - send a SMP task to FW
4153 * @pm8001_ha: our hba card information.
4154 * @ccb: the ccb information this request used.
4155 */
4156static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4157 struct pm8001_ccb_info *ccb)
4158{
4159 int elem, rc;
4160 struct sas_task *task = ccb->task;
4161 struct domain_device *dev = task->dev;
4162 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4163 struct scatterlist *sg_req, *sg_resp;
4164 u32 req_len, resp_len;
4165 struct smp_req smp_cmd;
4166 u32 opc;
4167 struct inbound_queue_table *circularQ;
4168
4169 memset(&smp_cmd, 0, sizeof(smp_cmd));
4170 /*
4171 * DMA-map SMP request, response buffers
4172 */
4173 sg_req = &task->smp_task.smp_req;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004174 elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004175 if (!elem)
4176 return -ENOMEM;
4177 req_len = sg_dma_len(sg_req);
4178
4179 sg_resp = &task->smp_task.smp_resp;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004180 elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004181 if (!elem) {
4182 rc = -ENOMEM;
4183 goto err_out;
4184 }
4185 resp_len = sg_dma_len(sg_resp);
4186 /* must be in dwords */
4187 if ((req_len & 0x3) || (resp_len & 0x3)) {
4188 rc = -EINVAL;
4189 goto err_out_2;
4190 }
4191
4192 opc = OPC_INB_SMP_REQUEST;
4193 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4194 smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4195 smp_cmd.long_smp_req.long_req_addr =
4196 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4197 smp_cmd.long_smp_req.long_req_size =
4198 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4199 smp_cmd.long_smp_req.long_resp_addr =
4200 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp));
4201 smp_cmd.long_smp_req.long_resp_size =
4202 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4203 build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304204 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304205 &smp_cmd, sizeof(smp_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304206 if (rc)
4207 goto err_out_2;
4208
jack wangdbf9bfe2009-10-14 16:19:21 +08004209 return 0;
4210
4211err_out_2:
4212 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004213 DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004214err_out:
4215 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004216 DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004217 return rc;
4218}
4219
4220/**
4221 * pm8001_chip_ssp_io_req - send a SSP task to FW
4222 * @pm8001_ha: our hba card information.
4223 * @ccb: the ccb information this request used.
4224 */
4225static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4226 struct pm8001_ccb_info *ccb)
4227{
4228 struct sas_task *task = ccb->task;
4229 struct domain_device *dev = task->dev;
4230 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4231 struct ssp_ini_io_start_req ssp_cmd;
4232 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004233 int ret;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304234 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004235 struct inbound_queue_table *circularQ;
4236 u32 opc = OPC_INB_SSPINIIOSTART;
4237 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4238 memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
jack wangafc5ca92009-12-07 17:22:47 +08004239 ssp_cmd.dir_m_tlr =
4240 cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for
jack wangdbf9bfe2009-10-14 16:19:21 +08004241 SAS 1.1 compatible TLR*/
4242 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4243 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4244 ssp_cmd.tag = cpu_to_le32(tag);
4245 if (task->ssp_task.enable_first_burst)
4246 ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
4247 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
4248 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
James Bottomleye73823f2013-05-07 15:38:18 -07004249 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4250 task->ssp_task.cmd->cmd_len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004251 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4252
4253 /* fill in PRD (scatter/gather) table, if any */
4254 if (task->num_scatter > 1) {
4255 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304256 phys_addr = ccb->ccb_dma_handle;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304257 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr));
4258 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004259 ssp_cmd.esgl = cpu_to_le32(1<<31);
4260 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304261 u64 dma_addr = sg_dma_address(task->scatter);
4262 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4263 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004264 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4265 ssp_cmd.esgl = 0;
4266 } else if (task->num_scatter == 0) {
4267 ssp_cmd.addr_low = 0;
4268 ssp_cmd.addr_high = 0;
4269 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4270 ssp_cmd.esgl = 0;
4271 }
peter chang91a43fa2019-11-14 15:39:05 +05304272 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd,
4273 sizeof(ssp_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004274 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004275}
4276
4277static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4278 struct pm8001_ccb_info *ccb)
4279{
4280 struct sas_task *task = ccb->task;
4281 struct domain_device *dev = task->dev;
4282 struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4283 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004284 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004285 struct sata_start_req sata_cmd;
4286 u32 hdr_tag, ncg_tag = 0;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304287 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004288 u32 ATAP = 0x0;
4289 u32 dir;
4290 struct inbound_queue_table *circularQ;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304291 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004292 u32 opc = OPC_INB_SATA_HOST_OPSTART;
4293 memset(&sata_cmd, 0, sizeof(sata_cmd));
4294 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004295 if (task->data_dir == DMA_NONE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004296 ATAP = 0x04; /* no data*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004297 pm8001_dbg(pm8001_ha, IO, "no data\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004298 } else if (likely(!task->ata_task.device_control_reg_update)) {
4299 if (task->ata_task.dma_xfer) {
4300 ATAP = 0x06; /* DMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004301 pm8001_dbg(pm8001_ha, IO, "DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004302 } else {
4303 ATAP = 0x05; /* PIO*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004304 pm8001_dbg(pm8001_ha, IO, "PIO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004305 }
4306 if (task->ata_task.use_ncq &&
Hannes Reinecke1cbd7722014-11-05 13:08:20 +01004307 dev->sata_dev.class != ATA_DEV_ATAPI) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004308 ATAP = 0x07; /* FPDMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004309 pm8001_dbg(pm8001_ha, IO, "FPDMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004310 }
4311 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304312 if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4313 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
jack wangafc5ca92009-12-07 17:22:47 +08004314 ncg_tag = hdr_tag;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304315 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004316 dir = data_dir_flags[task->data_dir] << 8;
4317 sata_cmd.tag = cpu_to_le32(tag);
4318 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4319 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4320 sata_cmd.ncqtag_atap_dir_m =
4321 cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir);
4322 sata_cmd.sata_fis = task->ata_task.fis;
4323 if (likely(!task->ata_task.device_control_reg_update))
4324 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4325 sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4326 /* fill in PRD (scatter/gather) table, if any */
4327 if (task->num_scatter > 1) {
4328 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304329 phys_addr = ccb->ccb_dma_handle;
jack wangdbf9bfe2009-10-14 16:19:21 +08004330 sata_cmd.addr_low = lower_32_bits(phys_addr);
4331 sata_cmd.addr_high = upper_32_bits(phys_addr);
4332 sata_cmd.esgl = cpu_to_le32(1 << 31);
4333 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304334 u64 dma_addr = sg_dma_address(task->scatter);
jack wangdbf9bfe2009-10-14 16:19:21 +08004335 sata_cmd.addr_low = lower_32_bits(dma_addr);
4336 sata_cmd.addr_high = upper_32_bits(dma_addr);
4337 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4338 sata_cmd.esgl = 0;
4339 } else if (task->num_scatter == 0) {
4340 sata_cmd.addr_low = 0;
4341 sata_cmd.addr_high = 0;
4342 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4343 sata_cmd.esgl = 0;
4344 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304345
4346 /* Check for read log for failed drive and return */
4347 if (sata_cmd.sata_fis.command == 0x2f) {
Rickard Strandqvistd9816442014-07-09 17:19:38 +05304348 if (((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304349 (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4350 (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4351 struct task_status_struct *ts;
4352
4353 pm8001_ha_dev->id &= 0xDFFFFFFF;
4354 ts = &task->task_status;
4355
4356 spin_lock_irqsave(&task->task_state_lock, flags);
4357 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07004358 ts->stat = SAS_SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304359 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4360 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4361 task->task_state_flags |= SAS_TASK_STATE_DONE;
4362 if (unlikely((task->task_state_flags &
4363 SAS_TASK_STATE_ABORTED))) {
4364 spin_unlock_irqrestore(&task->task_state_lock,
4365 flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08004366 pm8001_dbg(pm8001_ha, FAIL,
4367 "task 0x%p resp 0x%x stat 0x%x but aborted by upper layer\n",
4368 task, ts->resp,
4369 ts->stat);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304370 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304371 } else {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304372 spin_unlock_irqrestore(&task->task_state_lock,
4373 flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304374 pm8001_ccb_task_free_done(pm8001_ha, task,
4375 ccb, tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304376 return 0;
4377 }
4378 }
4379 }
4380
peter chang91a43fa2019-11-14 15:39:05 +05304381 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
4382 sizeof(sata_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004383 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004384}
4385
4386/**
4387 * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND
4388 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004389 * @phy_id: the phy id which we wanted to start up.
4390 */
4391static int
4392pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4393{
4394 struct phy_start_req payload;
4395 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004396 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004397 u32 tag = 0x01;
4398 u32 opcode = OPC_INB_PHYSTART;
4399 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4400 memset(&payload, 0, sizeof(payload));
4401 payload.tag = cpu_to_le32(tag);
4402 /*
4403 ** [0:7] PHY Identifier
4404 ** [8:11] link rate 1.5G, 3G, 6G
4405 ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both
4406 ** [14] 0b disable spin up hold; 1b enable spin up hold
4407 */
4408 payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4409 LINKMODE_AUTO | LINKRATE_15 |
4410 LINKRATE_30 | LINKRATE_60 | phy_id);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004411 payload.sas_identify.dev_type = SAS_END_DEVICE;
jack wangdbf9bfe2009-10-14 16:19:21 +08004412 payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4413 memcpy(payload.sas_identify.sas_addr,
4414 pm8001_ha->sas_addr, SAS_ADDR_SIZE);
4415 payload.sas_identify.phy_id = phy_id;
peter chang91a43fa2019-11-14 15:39:05 +05304416 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4417 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004418 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004419}
4420
4421/**
4422 * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4423 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004424 * @phy_id: the phy id which we wanted to start up.
4425 */
Baoyou Xie7efa59e2016-09-23 21:54:22 +08004426static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4427 u8 phy_id)
jack wangdbf9bfe2009-10-14 16:19:21 +08004428{
4429 struct phy_stop_req payload;
4430 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004431 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004432 u32 tag = 0x01;
4433 u32 opcode = OPC_INB_PHYSTOP;
4434 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4435 memset(&payload, 0, sizeof(payload));
4436 payload.tag = cpu_to_le32(tag);
4437 payload.phy_id = cpu_to_le32(phy_id);
peter chang91a43fa2019-11-14 15:39:05 +05304438 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4439 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004440 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004441}
4442
Lee Jones083645b2020-07-21 17:41:24 +01004443/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304444 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004445 */
4446static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4447 struct pm8001_device *pm8001_dev, u32 flag)
4448{
4449 struct reg_dev_req payload;
4450 u32 opc;
4451 u32 stp_sspsmp_sata = 0x4;
4452 struct inbound_queue_table *circularQ;
4453 u32 linkrate, phy_id;
jack_wang72d0baa2009-11-05 22:33:35 +08004454 int rc, tag = 0xdeadbeef;
jack wangdbf9bfe2009-10-14 16:19:21 +08004455 struct pm8001_ccb_info *ccb;
4456 u8 retryFlag = 0x1;
4457 u16 firstBurstSize = 0;
4458 u16 ITNT = 2000;
4459 struct domain_device *dev = pm8001_dev->sas_device;
4460 struct domain_device *parent_dev = dev->parent;
4461 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4462
4463 memset(&payload, 0, sizeof(payload));
4464 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4465 if (rc)
4466 return rc;
4467 ccb = &pm8001_ha->ccb_info[tag];
4468 ccb->device = pm8001_dev;
4469 ccb->ccb_tag = tag;
4470 payload.tag = cpu_to_le32(tag);
4471 if (flag == 1)
4472 stp_sspsmp_sata = 0x02; /*direct attached sata */
4473 else {
James Bottomleyaa9f8322013-05-07 14:44:06 -07004474 if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004475 stp_sspsmp_sata = 0x00; /* stp*/
James Bottomleyaa9f8322013-05-07 14:44:06 -07004476 else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
4477 pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
4478 pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004479 stp_sspsmp_sata = 0x01; /*ssp or smp*/
4480 }
John Garry924a3542019-06-10 20:41:41 +08004481 if (parent_dev && dev_is_expander(parent_dev->dev_type))
jack wangdbf9bfe2009-10-14 16:19:21 +08004482 phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4483 else
4484 phy_id = pm8001_dev->attached_phy;
4485 opc = OPC_INB_REG_DEV;
4486 linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4487 pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4488 payload.phyid_portid =
4489 cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) |
4490 ((phy_id & 0x0F) << 4));
4491 payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) |
4492 ((linkrate & 0x0F) * 0x1000000) |
4493 ((stp_sspsmp_sata & 0x03) * 0x10000000));
4494 payload.firstburstsize_ITNexustimeout =
4495 cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
jack wangafc5ca92009-12-07 17:22:47 +08004496 memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
jack wangdbf9bfe2009-10-14 16:19:21 +08004497 SAS_ADDR_SIZE);
peter chang91a43fa2019-11-14 15:39:05 +05304498 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4499 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004500 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004501}
4502
Lee Jones083645b2020-07-21 17:41:24 +01004503/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304504 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004505 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304506int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004507 u32 device_id)
4508{
4509 struct dereg_dev_req payload;
4510 u32 opc = OPC_INB_DEREG_DEV_HANDLE;
jack_wang72d0baa2009-11-05 22:33:35 +08004511 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004512 struct inbound_queue_table *circularQ;
4513
4514 circularQ = &pm8001_ha->inbnd_q_tbl[0];
jack_wang72d0baa2009-11-05 22:33:35 +08004515 memset(&payload, 0, sizeof(payload));
Santosh Nayak8270ee22012-02-26 20:14:46 +05304516 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004517 payload.device_id = cpu_to_le32(device_id);
Joe Perches1b5d2792020-11-20 15:16:09 -08004518 pm8001_dbg(pm8001_ha, MSG, "unregister device device_id = %d\n",
4519 device_id);
peter chang91a43fa2019-11-14 15:39:05 +05304520 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4521 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004522 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004523}
4524
4525/**
4526 * pm8001_chip_phy_ctl_req - support the local phy operation
4527 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004528 * @phyId: the phy id which we wanted to operate
4529 * @phy_op: the phy operation to request
jack wangdbf9bfe2009-10-14 16:19:21 +08004530 */
4531static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4532 u32 phyId, u32 phy_op)
4533{
4534 struct local_phy_ctl_req payload;
4535 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004536 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004537 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
jack wang83e73322009-12-07 17:23:11 +08004538 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08004539 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Santosh Nayak8270ee22012-02-26 20:14:46 +05304540 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004541 payload.phyop_phyid =
4542 cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
peter chang91a43fa2019-11-14 15:39:05 +05304543 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4544 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004545 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004546}
4547
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004548static u32 pm8001_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08004549{
jack wangdbf9bfe2009-10-14 16:19:21 +08004550#ifdef PM8001_USE_MSIX
4551 return 1;
Colin Ian King292c04c2019-03-28 23:43:28 +00004552#else
4553 u32 value;
4554
jack wangdbf9bfe2009-10-14 16:19:21 +08004555 value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4556 if (value)
4557 return 1;
4558 return 0;
Colin Ian King292c04c2019-03-28 23:43:28 +00004559#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08004560}
4561
4562/**
4563 * pm8001_chip_isr - PM8001 isr handler.
4564 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004565 * @vec: IRQ number
jack wangdbf9bfe2009-10-14 16:19:21 +08004566 */
jack_wang72d0baa2009-11-05 22:33:35 +08004567static irqreturn_t
Sakthivel Kf74cf272013-02-27 20:27:43 +05304568pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004569{
Sakthivel Kf74cf272013-02-27 20:27:43 +05304570 pm8001_chip_interrupt_disable(pm8001_ha, vec);
Joe Perches1b5d2792020-11-20 15:16:09 -08004571 pm8001_dbg(pm8001_ha, DEVIO,
4572 "irq vec %d, ODMR:0x%x\n",
4573 vec, pm8001_cr32(pm8001_ha, 0, 0x30));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304574 process_oq(pm8001_ha, vec);
4575 pm8001_chip_interrupt_enable(pm8001_ha, vec);
jack_wang72d0baa2009-11-05 22:33:35 +08004576 return IRQ_HANDLED;
jack wangdbf9bfe2009-10-14 16:19:21 +08004577}
4578
4579static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
4580 u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag)
4581{
4582 struct task_abort_req task_abort;
4583 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004584 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004585 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4586 memset(&task_abort, 0, sizeof(task_abort));
4587 if (ABORT_SINGLE == (flag & ABORT_MASK)) {
4588 task_abort.abort_all = 0;
4589 task_abort.device_id = cpu_to_le32(dev_id);
4590 task_abort.tag_to_abort = cpu_to_le32(task_tag);
4591 task_abort.tag = cpu_to_le32(cmd_tag);
4592 } else if (ABORT_ALL == (flag & ABORT_MASK)) {
4593 task_abort.abort_all = cpu_to_le32(1);
4594 task_abort.device_id = cpu_to_le32(dev_id);
4595 task_abort.tag = cpu_to_le32(cmd_tag);
4596 }
peter chang91a43fa2019-11-14 15:39:05 +05304597 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
4598 sizeof(task_abort), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004599 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004600}
4601
Lee Jones083645b2020-07-21 17:41:24 +01004602/*
jack wangdbf9bfe2009-10-14 16:19:21 +08004603 * pm8001_chip_abort_task - SAS abort task when error or exception happened.
jack wangdbf9bfe2009-10-14 16:19:21 +08004604 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304605int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004606 struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag)
4607{
4608 u32 opc, device_id;
4609 int rc = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08004610 pm8001_dbg(pm8001_ha, EH, "cmd_tag = %x, abort task tag = 0x%x\n",
4611 cmd_tag, task_tag);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004612 if (pm8001_dev->dev_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004613 opc = OPC_INB_SSP_ABORT;
James Bottomleyaa9f8322013-05-07 14:44:06 -07004614 else if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004615 opc = OPC_INB_SATA_ABORT;
4616 else
4617 opc = OPC_INB_SMP_ABORT;/* SMP */
4618 device_id = pm8001_dev->device_id;
4619 rc = send_task_abort(pm8001_ha, opc, device_id, flag,
4620 task_tag, cmd_tag);
4621 if (rc != TMF_RESP_FUNC_COMPLETE)
Joe Perches1b5d2792020-11-20 15:16:09 -08004622 pm8001_dbg(pm8001_ha, EH, "rc= %d\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004623 return rc;
4624}
4625
4626/**
Uwe Kleine-König65155b32010-06-11 12:17:01 +02004627 * pm8001_chip_ssp_tm_req - built the task management command.
jack wangdbf9bfe2009-10-14 16:19:21 +08004628 * @pm8001_ha: our hba card information.
4629 * @ccb: the ccb information.
4630 * @tmf: task management function.
4631 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304632int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004633 struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
4634{
4635 struct sas_task *task = ccb->task;
4636 struct domain_device *dev = task->dev;
4637 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4638 u32 opc = OPC_INB_SSPINITMSTART;
4639 struct inbound_queue_table *circularQ;
4640 struct ssp_ini_tm_start_req sspTMCmd;
jack_wang72d0baa2009-11-05 22:33:35 +08004641 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004642
4643 memset(&sspTMCmd, 0, sizeof(sspTMCmd));
4644 sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4645 sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed);
4646 sspTMCmd.tmf = cpu_to_le32(tmf->tmf);
jack wangdbf9bfe2009-10-14 16:19:21 +08004647 memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8);
4648 sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05304649 if (pm8001_ha->chip_id != chip_8001)
4650 sspTMCmd.ds_ads_m = 0x08;
jack wangdbf9bfe2009-10-14 16:19:21 +08004651 circularQ = &pm8001_ha->inbnd_q_tbl[0];
peter chang91a43fa2019-11-14 15:39:05 +05304652 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd,
4653 sizeof(sspTMCmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004654 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004655}
4656
Sakthivel Kf74cf272013-02-27 20:27:43 +05304657int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004658 void *payload)
4659{
4660 u32 opc = OPC_INB_GET_NVMD_DATA;
4661 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004662 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004663 u32 tag;
4664 struct pm8001_ccb_info *ccb;
4665 struct inbound_queue_table *circularQ;
4666 struct get_nvm_data_req nvmd_req;
4667 struct fw_control_ex *fw_control_context;
4668 struct pm8001_ioctl_payload *ioctl_payload = payload;
4669
4670 nvmd_type = ioctl_payload->minor_function;
4671 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004672 if (!fw_control_context)
4673 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304674 fw_control_context->usrAddr = (u8 *)ioctl_payload->func_specific;
Viswas G9b889842020-03-16 13:19:06 +05304675 fw_control_context->len = ioctl_payload->rd_length;
jack wangdbf9bfe2009-10-14 16:19:21 +08004676 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4677 memset(&nvmd_req, 0, sizeof(nvmd_req));
4678 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004679 if (rc) {
4680 kfree(fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08004681 return rc;
Julia Lawall823d2192010-08-01 19:23:35 +02004682 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004683 ccb = &pm8001_ha->ccb_info[tag];
4684 ccb->ccb_tag = tag;
4685 ccb->fw_control_context = fw_control_context;
4686 nvmd_req.tag = cpu_to_le32(tag);
4687
4688 switch (nvmd_type) {
4689 case TWI_DEVICE: {
4690 u32 twi_addr, twi_page_size;
4691 twi_addr = 0xa8;
4692 twi_page_size = 2;
4693
4694 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4695 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304696 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004697 nvmd_req.resp_addr_hi =
4698 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4699 nvmd_req.resp_addr_lo =
4700 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4701 break;
4702 }
4703 case C_SEEPROM: {
4704 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304705 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004706 nvmd_req.resp_addr_hi =
4707 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4708 nvmd_req.resp_addr_lo =
4709 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4710 break;
4711 }
4712 case VPD_FLASH: {
4713 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304714 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004715 nvmd_req.resp_addr_hi =
4716 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4717 nvmd_req.resp_addr_lo =
4718 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4719 break;
4720 }
4721 case EXPAN_ROM: {
4722 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304723 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004724 nvmd_req.resp_addr_hi =
4725 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4726 nvmd_req.resp_addr_lo =
4727 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4728 break;
4729 }
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304730 case IOP_RDUMP: {
4731 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | IOP_RDUMP);
Viswas G9b889842020-03-16 13:19:06 +05304732 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304733 nvmd_req.vpd_offset = cpu_to_le32(ioctl_payload->offset);
4734 nvmd_req.resp_addr_hi =
4735 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4736 nvmd_req.resp_addr_lo =
4737 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4738 break;
4739 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004740 default:
4741 break;
4742 }
peter chang91a43fa2019-11-14 15:39:05 +05304743 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4744 sizeof(nvmd_req), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304745 if (rc) {
4746 kfree(fw_control_context);
4747 pm8001_tag_free(pm8001_ha, tag);
4748 }
jack_wang72d0baa2009-11-05 22:33:35 +08004749 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004750}
4751
Sakthivel Kf74cf272013-02-27 20:27:43 +05304752int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004753 void *payload)
4754{
4755 u32 opc = OPC_INB_SET_NVMD_DATA;
4756 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004757 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004758 u32 tag;
4759 struct pm8001_ccb_info *ccb;
4760 struct inbound_queue_table *circularQ;
4761 struct set_nvm_data_req nvmd_req;
4762 struct fw_control_ex *fw_control_context;
4763 struct pm8001_ioctl_payload *ioctl_payload = payload;
4764
4765 nvmd_type = ioctl_payload->minor_function;
4766 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004767 if (!fw_control_context)
4768 return -ENOMEM;
jack wangdbf9bfe2009-10-14 16:19:21 +08004769 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4770 memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr,
Sakthivel K1c75a672013-03-19 18:06:40 +05304771 &ioctl_payload->func_specific,
Viswas G9b889842020-03-16 13:19:06 +05304772 ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004773 memset(&nvmd_req, 0, sizeof(nvmd_req));
4774 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004775 if (rc) {
4776 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304777 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004778 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004779 ccb = &pm8001_ha->ccb_info[tag];
4780 ccb->fw_control_context = fw_control_context;
4781 ccb->ccb_tag = tag;
4782 nvmd_req.tag = cpu_to_le32(tag);
4783 switch (nvmd_type) {
4784 case TWI_DEVICE: {
4785 u32 twi_addr, twi_page_size;
4786 twi_addr = 0xa8;
4787 twi_page_size = 2;
4788 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4789 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4790 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304791 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004792 nvmd_req.resp_addr_hi =
4793 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4794 nvmd_req.resp_addr_lo =
4795 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4796 break;
4797 }
4798 case C_SEEPROM:
4799 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304800 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004801 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4802 nvmd_req.resp_addr_hi =
4803 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4804 nvmd_req.resp_addr_lo =
4805 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4806 break;
4807 case VPD_FLASH:
4808 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304809 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004810 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4811 nvmd_req.resp_addr_hi =
4812 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4813 nvmd_req.resp_addr_lo =
4814 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4815 break;
4816 case EXPAN_ROM:
4817 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304818 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004819 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4820 nvmd_req.resp_addr_hi =
4821 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4822 nvmd_req.resp_addr_lo =
4823 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4824 break;
4825 default:
4826 break;
4827 }
peter chang91a43fa2019-11-14 15:39:05 +05304828 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4829 sizeof(nvmd_req), 0);
Tomas Henzl9422e862014-07-07 17:20:00 +02004830 if (rc) {
4831 kfree(fw_control_context);
4832 pm8001_tag_free(pm8001_ha, tag);
4833 }
jack_wang72d0baa2009-11-05 22:33:35 +08004834 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004835}
4836
4837/**
4838 * pm8001_chip_fw_flash_update_build - support the firmware update operation
4839 * @pm8001_ha: our hba card information.
4840 * @fw_flash_updata_info: firmware flash update param
Lee Jones083645b2020-07-21 17:41:24 +01004841 * @tag: Tag to apply to the payload
jack wangdbf9bfe2009-10-14 16:19:21 +08004842 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304843int
jack wangdbf9bfe2009-10-14 16:19:21 +08004844pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
4845 void *fw_flash_updata_info, u32 tag)
4846{
4847 struct fw_flash_Update_req payload;
4848 struct fw_flash_updata_info *info;
4849 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004850 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004851 u32 opc = OPC_INB_FW_FLASH_UPDATE;
4852
jack_wang72d0baa2009-11-05 22:33:35 +08004853 memset(&payload, 0, sizeof(struct fw_flash_Update_req));
jack wangdbf9bfe2009-10-14 16:19:21 +08004854 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4855 info = fw_flash_updata_info;
4856 payload.tag = cpu_to_le32(tag);
4857 payload.cur_image_len = cpu_to_le32(info->cur_image_len);
4858 payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
4859 payload.total_image_len = cpu_to_le32(info->total_image_len);
4860 payload.len = info->sgl.im_len.len ;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304861 payload.sgl_addr_lo =
4862 cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr)));
4863 payload.sgl_addr_hi =
4864 cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr)));
peter chang91a43fa2019-11-14 15:39:05 +05304865 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4866 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004867 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004868}
4869
Sakthivel Kf74cf272013-02-27 20:27:43 +05304870int
jack wangdbf9bfe2009-10-14 16:19:21 +08004871pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
4872 void *payload)
4873{
4874 struct fw_flash_updata_info flash_update_info;
4875 struct fw_control_info *fw_control;
4876 struct fw_control_ex *fw_control_context;
jack_wang72d0baa2009-11-05 22:33:35 +08004877 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004878 u32 tag;
4879 struct pm8001_ccb_info *ccb;
Sakthivel K1c75a672013-03-19 18:06:40 +05304880 void *buffer = pm8001_ha->memoryMap.region[FW_FLASH].virt_ptr;
4881 dma_addr_t phys_addr = pm8001_ha->memoryMap.region[FW_FLASH].phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004882 struct pm8001_ioctl_payload *ioctl_payload = payload;
4883
4884 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004885 if (!fw_control_context)
4886 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304887 fw_control = (struct fw_control_info *)&ioctl_payload->func_specific;
Joe Perches1b5d2792020-11-20 15:16:09 -08004888 pm8001_dbg(pm8001_ha, DEVIO,
4889 "dma fw_control context input length :%x\n",
4890 fw_control->len);
jack_wang72d0baa2009-11-05 22:33:35 +08004891 memcpy(buffer, fw_control->buffer, fw_control->len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004892 flash_update_info.sgl.addr = cpu_to_le64(phys_addr);
4893 flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len);
4894 flash_update_info.sgl.im_len.e = 0;
4895 flash_update_info.cur_image_offset = fw_control->offset;
4896 flash_update_info.cur_image_len = fw_control->len;
4897 flash_update_info.total_image_len = fw_control->size;
4898 fw_control_context->fw_control = fw_control;
4899 fw_control_context->virtAddr = buffer;
Sakthivel K1c75a672013-03-19 18:06:40 +05304900 fw_control_context->phys_addr = phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004901 fw_control_context->len = fw_control->len;
4902 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004903 if (rc) {
4904 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304905 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004906 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004907 ccb = &pm8001_ha->ccb_info[tag];
4908 ccb->fw_control_context = fw_control_context;
4909 ccb->ccb_tag = tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004910 rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
4911 tag);
4912 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004913}
4914
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304915ssize_t
4916pm8001_get_gsm_dump(struct device *cdev, u32 length, char *buf)
4917{
4918 u32 value, rem, offset = 0, bar = 0;
4919 u32 index, work_offset, dw_length;
4920 u32 shift_value, gsm_base, gsm_dump_offset;
4921 char *direct_data;
4922 struct Scsi_Host *shost = class_to_shost(cdev);
4923 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
4924 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
4925
4926 direct_data = buf;
4927 gsm_dump_offset = pm8001_ha->fatal_forensic_shift_offset;
4928
4929 /* check max is 1 Mbytes */
4930 if ((length > 0x100000) || (gsm_dump_offset & 3) ||
4931 ((gsm_dump_offset + length) > 0x1000000))
Viswas Gcf370062013-12-10 10:31:38 +05304932 return -EINVAL;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304933
4934 if (pm8001_ha->chip_id == chip_8001)
4935 bar = 2;
4936 else
4937 bar = 1;
4938
4939 work_offset = gsm_dump_offset & 0xFFFF0000;
4940 offset = gsm_dump_offset & 0x0000FFFF;
4941 gsm_dump_offset = work_offset;
4942 /* adjust length to dword boundary */
4943 rem = length & 3;
4944 dw_length = length >> 2;
4945
4946 for (index = 0; index < dw_length; index++) {
4947 if ((work_offset + offset) & 0xFFFF0000) {
4948 if (pm8001_ha->chip_id == chip_8001)
4949 shift_value = ((gsm_dump_offset + offset) &
4950 SHIFT_REG_64K_MASK);
4951 else
4952 shift_value = (((gsm_dump_offset + offset) &
4953 SHIFT_REG_64K_MASK) >>
4954 SHIFT_REG_BIT_SHIFT);
4955
4956 if (pm8001_ha->chip_id == chip_8001) {
4957 gsm_base = GSM_BASE;
4958 if (-1 == pm8001_bar4_shift(pm8001_ha,
4959 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05304960 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304961 } else {
4962 gsm_base = 0;
4963 if (-1 == pm80xx_bar4_shift(pm8001_ha,
4964 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05304965 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304966 }
4967 gsm_dump_offset = (gsm_dump_offset + offset) &
4968 0xFFFF0000;
4969 work_offset = 0;
4970 offset = offset & 0x0000FFFF;
4971 }
4972 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
4973 0x0000FFFF);
4974 direct_data += sprintf(direct_data, "%08x ", value);
4975 offset += 4;
4976 }
4977 if (rem != 0) {
4978 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
4979 0x0000FFFF);
4980 /* xfr for non_dw */
4981 direct_data += sprintf(direct_data, "%08x ", value);
4982 }
4983 /* Shift back to BAR4 original address */
Viswas G859b5d12013-12-10 10:31:28 +05304984 if (-1 == pm8001_bar4_shift(pm8001_ha, 0))
Viswas Gcf370062013-12-10 10:31:38 +05304985 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304986 pm8001_ha->fatal_forensic_shift_offset += 1024;
4987
4988 if (pm8001_ha->fatal_forensic_shift_offset >= 0x100000)
4989 pm8001_ha->fatal_forensic_shift_offset = 0;
4990 return direct_data - buf;
4991}
4992
Sakthivel Kf74cf272013-02-27 20:27:43 +05304993int
jack wangdbf9bfe2009-10-14 16:19:21 +08004994pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
4995 struct pm8001_device *pm8001_dev, u32 state)
4996{
4997 struct set_dev_state_req payload;
4998 struct inbound_queue_table *circularQ;
4999 struct pm8001_ccb_info *ccb;
jack_wang72d0baa2009-11-05 22:33:35 +08005000 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005001 u32 tag;
5002 u32 opc = OPC_INB_SET_DEVICE_STATE;
jack_wang72d0baa2009-11-05 22:33:35 +08005003 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08005004 rc = pm8001_tag_alloc(pm8001_ha, &tag);
5005 if (rc)
5006 return -1;
5007 ccb = &pm8001_ha->ccb_info[tag];
5008 ccb->ccb_tag = tag;
5009 ccb->device = pm8001_dev;
5010 circularQ = &pm8001_ha->inbnd_q_tbl[0];
5011 payload.tag = cpu_to_le32(tag);
5012 payload.device_id = cpu_to_le32(pm8001_dev->device_id);
5013 payload.nds = cpu_to_le32(state);
peter chang91a43fa2019-11-14 15:39:05 +05305014 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
5015 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08005016 return rc;
5017
jack_wangd0b68042009-11-05 22:32:31 +08005018}
5019
5020static int
5021pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
5022{
5023 struct sas_re_initialization_req payload;
5024 struct inbound_queue_table *circularQ;
5025 struct pm8001_ccb_info *ccb;
5026 int rc;
5027 u32 tag;
5028 u32 opc = OPC_INB_SAS_RE_INITIALIZE;
5029 memset(&payload, 0, sizeof(payload));
5030 rc = pm8001_tag_alloc(pm8001_ha, &tag);
5031 if (rc)
Tomas Henzl5533abc2014-07-09 17:20:49 +05305032 return -ENOMEM;
jack_wangd0b68042009-11-05 22:32:31 +08005033 ccb = &pm8001_ha->ccb_info[tag];
5034 ccb->ccb_tag = tag;
5035 circularQ = &pm8001_ha->inbnd_q_tbl[0];
5036 payload.tag = cpu_to_le32(tag);
5037 payload.SSAHOLT = cpu_to_le32(0xd << 25);
5038 payload.sata_hol_tmo = cpu_to_le32(80);
5039 payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff);
peter chang91a43fa2019-11-14 15:39:05 +05305040 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
5041 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05305042 if (rc)
5043 pm8001_tag_free(pm8001_ha, tag);
jack_wangd0b68042009-11-05 22:32:31 +08005044 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005045
5046}
5047
5048const struct pm8001_dispatch pm8001_8001_dispatch = {
5049 .name = "pmc8001",
5050 .chip_init = pm8001_chip_init,
5051 .chip_soft_rst = pm8001_chip_soft_rst,
5052 .chip_rst = pm8001_hw_chip_rst,
5053 .chip_iounmap = pm8001_chip_iounmap,
5054 .isr = pm8001_chip_isr,
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00005055 .is_our_interrupt = pm8001_chip_is_our_interrupt,
jack wangdbf9bfe2009-10-14 16:19:21 +08005056 .isr_process_oq = process_oq,
5057 .interrupt_enable = pm8001_chip_interrupt_enable,
5058 .interrupt_disable = pm8001_chip_interrupt_disable,
5059 .make_prd = pm8001_chip_make_sg,
5060 .smp_req = pm8001_chip_smp_req,
5061 .ssp_io_req = pm8001_chip_ssp_io_req,
5062 .sata_req = pm8001_chip_sata_req,
5063 .phy_start_req = pm8001_chip_phy_start_req,
5064 .phy_stop_req = pm8001_chip_phy_stop_req,
5065 .reg_dev_req = pm8001_chip_reg_dev_req,
5066 .dereg_dev_req = pm8001_chip_dereg_dev_req,
5067 .phy_ctl_req = pm8001_chip_phy_ctl_req,
5068 .task_abort = pm8001_chip_abort_task,
5069 .ssp_tm_req = pm8001_chip_ssp_tm_req,
5070 .get_nvmd_req = pm8001_chip_get_nvmd_req,
5071 .set_nvmd_req = pm8001_chip_set_nvmd_req,
5072 .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
5073 .set_dev_state_req = pm8001_chip_set_dev_state_req,
jack_wangd0b68042009-11-05 22:32:31 +08005074 .sas_re_init_req = pm8001_chip_sas_re_initialization,
akshatzena961ea02021-01-09 18:08:43 +05305075 .fatal_errors = pm80xx_fatal_errors,
jack wangdbf9bfe2009-10-14 16:19:21 +08005076};