blob: 9ec310b795c3375385e6b3f756289fe6115b8d1c [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"
Changyuan Lyu0137b122021-11-15 13:57:50 -080045 #include "pm80xx_tracepoints.h"
jack wangdbf9bfe2009-10-14 16:19:21 +080046
47/**
48 * read_main_config_table - read the configure table and save it.
49 * @pm8001_ha: our hba card information
50 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080051static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +080052{
53 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
Sakthivel Ke5742102013-04-17 16:26:36 +053054 pm8001_ha->main_cfg_tbl.pm8001_tbl.signature =
55 pm8001_mr32(address, 0x00);
56 pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev =
57 pm8001_mr32(address, 0x04);
58 pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev =
59 pm8001_mr32(address, 0x08);
60 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io =
61 pm8001_mr32(address, 0x0C);
62 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl =
63 pm8001_mr32(address, 0x10);
64 pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag =
65 pm8001_mr32(address, 0x14);
66 pm8001_ha->main_cfg_tbl.pm8001_tbl.gst_offset =
67 pm8001_mr32(address, 0x18);
68 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_queue_offset =
jack_wangd0b68042009-11-05 22:32:31 +080069 pm8001_mr32(address, MAIN_IBQ_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053070 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_queue_offset =
jack_wangd0b68042009-11-05 22:32:31 +080071 pm8001_mr32(address, MAIN_OBQ_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053072 pm8001_ha->main_cfg_tbl.pm8001_tbl.hda_mode_flag =
jack wangdbf9bfe2009-10-14 16:19:21 +080073 pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET);
74
75 /* read analog Setting offset from the configuration table */
Sakthivel Ke5742102013-04-17 16:26:36 +053076 pm8001_ha->main_cfg_tbl.pm8001_tbl.anolog_setup_table_offset =
jack wangdbf9bfe2009-10-14 16:19:21 +080077 pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
78
79 /* read Error Dump Offset and Length */
Sakthivel Ke5742102013-04-17 16:26:36 +053080 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset0 =
jack wangdbf9bfe2009-10-14 16:19:21 +080081 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053082 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length0 =
jack wangdbf9bfe2009-10-14 16:19:21 +080083 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
Sakthivel Ke5742102013-04-17 16:26:36 +053084 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset1 =
jack wangdbf9bfe2009-10-14 16:19:21 +080085 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053086 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length1 =
jack wangdbf9bfe2009-10-14 16:19:21 +080087 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
88}
89
90/**
91 * read_general_status_table - read the general status table and save it.
92 * @pm8001_ha: our hba card information
93 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080094static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +080095{
96 void __iomem *address = pm8001_ha->general_stat_tbl_addr;
Sakthivel Ke5742102013-04-17 16:26:36 +053097 pm8001_ha->gs_tbl.pm8001_tbl.gst_len_mpistate =
98 pm8001_mr32(address, 0x00);
99 pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state0 =
100 pm8001_mr32(address, 0x04);
101 pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state1 =
102 pm8001_mr32(address, 0x08);
103 pm8001_ha->gs_tbl.pm8001_tbl.msgu_tcnt =
104 pm8001_mr32(address, 0x0C);
105 pm8001_ha->gs_tbl.pm8001_tbl.iop_tcnt =
106 pm8001_mr32(address, 0x10);
107 pm8001_ha->gs_tbl.pm8001_tbl.rsvd =
108 pm8001_mr32(address, 0x14);
109 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[0] =
110 pm8001_mr32(address, 0x18);
111 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[1] =
112 pm8001_mr32(address, 0x1C);
113 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[2] =
114 pm8001_mr32(address, 0x20);
115 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[3] =
116 pm8001_mr32(address, 0x24);
117 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[4] =
118 pm8001_mr32(address, 0x28);
119 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[5] =
120 pm8001_mr32(address, 0x2C);
121 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[6] =
122 pm8001_mr32(address, 0x30);
123 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[7] =
124 pm8001_mr32(address, 0x34);
125 pm8001_ha->gs_tbl.pm8001_tbl.gpio_input_val =
126 pm8001_mr32(address, 0x38);
127 pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[0] =
128 pm8001_mr32(address, 0x3C);
129 pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[1] =
130 pm8001_mr32(address, 0x40);
131 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[0] =
132 pm8001_mr32(address, 0x44);
133 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[1] =
134 pm8001_mr32(address, 0x48);
135 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[2] =
136 pm8001_mr32(address, 0x4C);
137 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[3] =
138 pm8001_mr32(address, 0x50);
139 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[4] =
140 pm8001_mr32(address, 0x54);
141 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[5] =
142 pm8001_mr32(address, 0x58);
143 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[6] =
144 pm8001_mr32(address, 0x5C);
145 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[7] =
146 pm8001_mr32(address, 0x60);
jack wangdbf9bfe2009-10-14 16:19:21 +0800147}
148
149/**
150 * read_inbnd_queue_table - read the inbound queue table and save it.
151 * @pm8001_ha: our hba card information
152 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800153static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800154{
jack wangdbf9bfe2009-10-14 16:19:21 +0800155 int i;
156 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530157 for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
jack_wangd0b68042009-11-05 22:32:31 +0800158 u32 offset = i * 0x20;
jack wangdbf9bfe2009-10-14 16:19:21 +0800159 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
160 get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
161 pm8001_ha->inbnd_q_tbl[i].pi_offset =
162 pm8001_mr32(address, (offset + 0x18));
163 }
164}
165
166/**
167 * read_outbnd_queue_table - read the outbound queue table and save it.
168 * @pm8001_ha: our hba card information
169 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800170static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800171{
jack wangdbf9bfe2009-10-14 16:19:21 +0800172 int i;
173 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530174 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800175 u32 offset = i * 0x24;
176 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
177 get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
178 pm8001_ha->outbnd_q_tbl[i].ci_offset =
179 pm8001_mr32(address, (offset + 0x18));
180 }
181}
182
183/**
184 * init_default_table_values - init the default table.
185 * @pm8001_ha: our hba card information
186 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800187static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800188{
jack wangdbf9bfe2009-10-14 16:19:21 +0800189 int i;
190 u32 offsetib, offsetob;
191 void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
192 void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530193 u32 ib_offset = pm8001_ha->ib_offset;
194 u32 ob_offset = pm8001_ha->ob_offset;
195 u32 ci_offset = pm8001_ha->ci_offset;
196 u32 pi_offset = pm8001_ha->pi_offset;
jack wangdbf9bfe2009-10-14 16:19:21 +0800197
Sakthivel Ke5742102013-04-17 16:26:36 +0530198 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd = 0;
199 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3 = 0;
200 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7 = 0;
201 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3 = 0;
202 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7 = 0;
203 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid0_3 =
204 0;
205 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid4_7 =
206 0;
207 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid0_3 = 0;
208 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid4_7 = 0;
209 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid0_3 = 0;
210 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid4_7 = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +0800211
Sakthivel Ke5742102013-04-17 16:26:36 +0530212 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800213 pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
Sakthivel Ke5742102013-04-17 16:26:36 +0530214 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800215 pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
Sakthivel Ke5742102013-04-17 16:26:36 +0530216 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size =
217 PM8001_EVENT_LOG_SIZE;
218 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option = 0x01;
219 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800220 pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
Sakthivel Ke5742102013-04-17 16:26:36 +0530221 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800222 pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
Sakthivel Ke5742102013-04-17 16:26:36 +0530223 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size =
224 PM8001_EVENT_LOG_SIZE;
225 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option = 0x01;
226 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt = 0x01;
Viswas G65df7d12021-04-02 11:12:12 +0530227 for (i = 0; i < pm8001_ha->max_q_num; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800228 pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200229 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800230 pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530231 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800232 pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530233 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800234 pm8001_ha->inbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530235 (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800236 pm8001_ha->inbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530237 pm8001_ha->memoryMap.region[ib_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800238 pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530239 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800240 pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530241 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800242 pm8001_ha->inbnd_q_tbl[i].ci_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530243 pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr;
Viswas Gb4314722021-04-15 16:03:51 +0530244 pm8001_write_32(pm8001_ha->inbnd_q_tbl[i].ci_virt, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800245 offsetib = i * 0x20;
246 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
247 get_pci_bar_index(pm8001_mr32(addressib,
248 (offsetib + 0x14)));
249 pm8001_ha->inbnd_q_tbl[i].pi_offset =
250 pm8001_mr32(addressib, (offsetib + 0x18));
251 pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
252 pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
253 }
Viswas G65df7d12021-04-02 11:12:12 +0530254 for (i = 0; i < pm8001_ha->max_q_num; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800255 pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200256 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800257 pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530258 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800259 pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530260 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800261 pm8001_ha->outbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530262 (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800263 pm8001_ha->outbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530264 pm8001_ha->memoryMap.region[ob_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800265 pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530266 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800267 pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530268 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800269 pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530270 0 | (10 << 16) | (i << 24);
jack wangdbf9bfe2009-10-14 16:19:21 +0800271 pm8001_ha->outbnd_q_tbl[i].pi_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530272 pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
Viswas Gb4314722021-04-15 16:03:51 +0530273 pm8001_write_32(pm8001_ha->outbnd_q_tbl[i].pi_virt, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800274 offsetob = i * 0x24;
275 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
276 get_pci_bar_index(pm8001_mr32(addressob,
277 offsetob + 0x14));
278 pm8001_ha->outbnd_q_tbl[i].ci_offset =
279 pm8001_mr32(addressob, (offsetob + 0x18));
280 pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
281 pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
282 }
283}
284
285/**
286 * update_main_config_table - update the main default table to the HBA.
287 * @pm8001_ha: our hba card information
288 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800289static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800290{
291 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
292 pm8001_mw32(address, 0x24,
Sakthivel Ke5742102013-04-17 16:26:36 +0530293 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd);
jack wangdbf9bfe2009-10-14 16:19:21 +0800294 pm8001_mw32(address, 0x28,
Sakthivel Ke5742102013-04-17 16:26:36 +0530295 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800296 pm8001_mw32(address, 0x2C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530297 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800298 pm8001_mw32(address, 0x30,
Sakthivel Ke5742102013-04-17 16:26:36 +0530299 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800300 pm8001_mw32(address, 0x34,
Sakthivel Ke5742102013-04-17 16:26:36 +0530301 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800302 pm8001_mw32(address, 0x38,
Sakthivel Ke5742102013-04-17 16:26:36 +0530303 pm8001_ha->main_cfg_tbl.pm8001_tbl.
304 outbound_tgt_ITNexus_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800305 pm8001_mw32(address, 0x3C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530306 pm8001_ha->main_cfg_tbl.pm8001_tbl.
307 outbound_tgt_ITNexus_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800308 pm8001_mw32(address, 0x40,
Sakthivel Ke5742102013-04-17 16:26:36 +0530309 pm8001_ha->main_cfg_tbl.pm8001_tbl.
310 outbound_tgt_ssp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800311 pm8001_mw32(address, 0x44,
Sakthivel Ke5742102013-04-17 16:26:36 +0530312 pm8001_ha->main_cfg_tbl.pm8001_tbl.
313 outbound_tgt_ssp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800314 pm8001_mw32(address, 0x48,
Sakthivel Ke5742102013-04-17 16:26:36 +0530315 pm8001_ha->main_cfg_tbl.pm8001_tbl.
316 outbound_tgt_smp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800317 pm8001_mw32(address, 0x4C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530318 pm8001_ha->main_cfg_tbl.pm8001_tbl.
319 outbound_tgt_smp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800320 pm8001_mw32(address, 0x50,
Sakthivel Ke5742102013-04-17 16:26:36 +0530321 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800322 pm8001_mw32(address, 0x54,
Sakthivel Ke5742102013-04-17 16:26:36 +0530323 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr);
324 pm8001_mw32(address, 0x58,
325 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size);
326 pm8001_mw32(address, 0x5C,
327 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800328 pm8001_mw32(address, 0x60,
Sakthivel Ke5742102013-04-17 16:26:36 +0530329 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800330 pm8001_mw32(address, 0x64,
Sakthivel Ke5742102013-04-17 16:26:36 +0530331 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr);
332 pm8001_mw32(address, 0x68,
333 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size);
jack wangdbf9bfe2009-10-14 16:19:21 +0800334 pm8001_mw32(address, 0x6C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530335 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800336 pm8001_mw32(address, 0x70,
Sakthivel Ke5742102013-04-17 16:26:36 +0530337 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt);
jack wangdbf9bfe2009-10-14 16:19:21 +0800338}
339
340/**
341 * update_inbnd_queue_table - update the inbound queue table to the HBA.
342 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100343 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800344 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800345static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
346 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800347{
348 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
349 u16 offset = number * 0x20;
350 pm8001_mw32(address, offset + 0x00,
351 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
352 pm8001_mw32(address, offset + 0x04,
353 pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
354 pm8001_mw32(address, offset + 0x08,
355 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
356 pm8001_mw32(address, offset + 0x0C,
357 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
358 pm8001_mw32(address, offset + 0x10,
359 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
360}
361
362/**
363 * update_outbnd_queue_table - update the outbound queue table to the HBA.
364 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100365 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800366 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800367static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
368 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800369{
370 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
371 u16 offset = number * 0x24;
372 pm8001_mw32(address, offset + 0x00,
373 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
374 pm8001_mw32(address, offset + 0x04,
375 pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
376 pm8001_mw32(address, offset + 0x08,
377 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
378 pm8001_mw32(address, offset + 0x0C,
379 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
380 pm8001_mw32(address, offset + 0x10,
381 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
382 pm8001_mw32(address, offset + 0x1C,
383 pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
384}
385
386/**
Mark Salyzynd95d0002012-01-17 09:18:57 -0500387 * pm8001_bar4_shift - function is called to shift BAR base address
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700388 * @pm8001_ha : our hba card information
jack wangdbf9bfe2009-10-14 16:19:21 +0800389 * @shiftValue : shifting value in memory bar.
390 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500391int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue)
jack wangdbf9bfe2009-10-14 16:19:21 +0800392{
393 u32 regVal;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500394 unsigned long start;
jack wangdbf9bfe2009-10-14 16:19:21 +0800395
396 /* program the inbound AXI translation Lower Address */
397 pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue);
398
399 /* confirm the setting is written */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500400 start = jiffies + HZ; /* 1 sec */
jack wangdbf9bfe2009-10-14 16:19:21 +0800401 do {
jack wangdbf9bfe2009-10-14 16:19:21 +0800402 regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW);
Mark Salyzynd95d0002012-01-17 09:18:57 -0500403 } while ((regVal != shiftValue) && time_before(jiffies, start));
jack wangdbf9bfe2009-10-14 16:19:21 +0800404
Mark Salyzynd95d0002012-01-17 09:18:57 -0500405 if (regVal != shiftValue) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800406 pm8001_dbg(pm8001_ha, INIT,
407 "TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW = 0x%x\n",
408 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800409 return -1;
410 }
411 return 0;
412}
413
414/**
415 * mpi_set_phys_g3_with_ssc
416 * @pm8001_ha: our hba card information
417 * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc.
418 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800419static void mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha,
420 u32 SSCbit)
jack wangdbf9bfe2009-10-14 16:19:21 +0800421{
Lee Jonesa364a3e2020-11-16 10:41:19 +0000422 u32 offset, i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500423 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800424
425#define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000
426#define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000
427#define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074
428#define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074
jack_wangd0b68042009-11-05 22:32:31 +0800429#define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12
430#define PHY_G3_WITH_SSC_BIT_SHIFT 13
431#define SNW3_PHY_CAPABILITIES_PARITY 31
jack wangdbf9bfe2009-10-14 16:19:21 +0800432
433 /*
434 * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3)
435 * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7)
436 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500437 spin_lock_irqsave(&pm8001_ha->lock, flags);
438 if (-1 == pm8001_bar4_shift(pm8001_ha,
439 SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) {
440 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800441 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500442 }
jack wang0330dba2009-12-07 17:46:22 +0800443
jack wangdbf9bfe2009-10-14 16:19:21 +0800444 for (i = 0; i < 4; i++) {
445 offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i;
jack wang0330dba2009-12-07 17:46:22 +0800446 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800447 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800448 /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500449 if (-1 == pm8001_bar4_shift(pm8001_ha,
450 SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) {
451 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800452 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500453 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800454 for (i = 4; i < 8; i++) {
455 offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
jack wang0330dba2009-12-07 17:46:22 +0800456 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800457 }
jack wang0330dba2009-12-07 17:46:22 +0800458 /*************************************************************
459 Change the SSC upspreading value to 0x0 so that upspreading is disabled.
460 Device MABC SMOD0 Controls
461 Address: (via MEMBASE-III):
462 Using shifted destination address 0x0_0000: with Offset 0xD8
463
464 31:28 R/W Reserved Do not change
465 27:24 R/W SAS_SMOD_SPRDUP 0000
466 23:20 R/W SAS_SMOD_SPRDDN 0000
467 19:0 R/W Reserved Do not change
468 Upon power-up this register will read as 0x8990c016,
469 and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000
470 so that the written value will be 0x8090c016.
471 This will ensure only down-spreading SSC is enabled on the SPC.
472 *************************************************************/
Lee Jonesa364a3e2020-11-16 10:41:19 +0000473 pm8001_cr32(pm8001_ha, 2, 0xd8);
jack wang0330dba2009-12-07 17:46:22 +0800474 pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016);
jack wangdbf9bfe2009-10-14 16:19:21 +0800475
476 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500477 pm8001_bar4_shift(pm8001_ha, 0x0);
478 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800479 return;
480}
481
482/**
483 * mpi_set_open_retry_interval_reg
484 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100485 * @interval: interval time for each OPEN_REJECT (RETRY). The units are in 1us.
jack wangdbf9bfe2009-10-14 16:19:21 +0800486 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800487static void mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha,
488 u32 interval)
jack wangdbf9bfe2009-10-14 16:19:21 +0800489{
490 u32 offset;
491 u32 value;
492 u32 i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500493 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800494
495#define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000
496#define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000
497#define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4
498#define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4
499#define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF
500
501 value = interval & OPEN_RETRY_INTERVAL_REG_MASK;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500502 spin_lock_irqsave(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800503 /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/
Mark Salyzynd95d0002012-01-17 09:18:57 -0500504 if (-1 == pm8001_bar4_shift(pm8001_ha,
505 OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) {
506 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800507 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500508 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800509 for (i = 0; i < 4; i++) {
510 offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i;
511 pm8001_cw32(pm8001_ha, 2, offset, value);
512 }
513
Mark Salyzynd95d0002012-01-17 09:18:57 -0500514 if (-1 == pm8001_bar4_shift(pm8001_ha,
515 OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) {
516 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800517 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500518 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800519 for (i = 4; i < 8; i++) {
520 offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
521 pm8001_cw32(pm8001_ha, 2, offset, value);
522 }
523 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500524 pm8001_bar4_shift(pm8001_ha, 0x0);
525 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800526 return;
527}
528
529/**
530 * mpi_init_check - check firmware initialization status.
531 * @pm8001_ha: our hba card information
532 */
533static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
534{
535 u32 max_wait_count;
536 u32 value;
537 u32 gst_len_mpistate;
538 /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
539 table is updated */
540 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE);
541 /* wait until Inbound DoorBell Clear Register toggled */
542 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
543 do {
544 udelay(1);
545 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
546 value &= SPC_MSGU_CFG_TABLE_UPDATE;
547 } while ((value != 0) && (--max_wait_count));
548
549 if (!max_wait_count)
550 return -1;
551 /* check the MPI-State for initialization */
552 gst_len_mpistate =
553 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
554 GST_GSTLEN_MPIS_OFFSET);
555 if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK))
556 return -1;
557 /* check MPI Initialization error */
558 gst_len_mpistate = gst_len_mpistate >> 16;
559 if (0x0000 != gst_len_mpistate)
560 return -1;
561 return 0;
562}
563
564/**
565 * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
566 * @pm8001_ha: our hba card information
567 */
568static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
569{
570 u32 value, value1;
571 u32 max_wait_count;
572 /* check error state */
573 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
574 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
575 /* check AAP error */
576 if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) {
577 /* error state */
578 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
579 return -1;
580 }
581
582 /* check IOP error */
583 if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) {
584 /* error state */
585 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
586 return -1;
587 }
588
589 /* bit 4-31 of scratch pad1 should be zeros if it is not
590 in error state*/
591 if (value & SCRATCH_PAD1_STATE_MASK) {
592 /* error case */
593 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
594 return -1;
595 }
596
597 /* bit 2, 4-31 of scratch pad2 should be zeros if it is not
598 in error state */
599 if (value1 & SCRATCH_PAD2_STATE_MASK) {
600 /* error case */
601 return -1;
602 }
603
604 max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */
605
606 /* wait until scratch pad 1 and 2 registers in ready state */
607 do {
608 udelay(1);
609 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
610 & SCRATCH_PAD1_RDY;
611 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
612 & SCRATCH_PAD2_RDY;
613 if ((--max_wait_count) == 0)
614 return -1;
615 } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY));
616 return 0;
617}
618
619static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
620{
621 void __iomem *base_addr;
622 u32 value;
623 u32 offset;
624 u32 pcibar;
625 u32 pcilogic;
626
627 value = pm8001_cr32(pm8001_ha, 0, 0x44);
628 offset = value & 0x03FFFFFF;
Joe Perches1b5d2792020-11-20 15:16:09 -0800629 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 Offset: %x\n", offset);
jack wangdbf9bfe2009-10-14 16:19:21 +0800630 pcilogic = (value & 0xFC000000) >> 26;
631 pcibar = get_pci_bar_index(pcilogic);
Joe Perches1b5d2792020-11-20 15:16:09 -0800632 pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar);
jack wangdbf9bfe2009-10-14 16:19:21 +0800633 pm8001_ha->main_cfg_tbl_addr = base_addr =
634 pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
635 pm8001_ha->general_stat_tbl_addr =
636 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18);
637 pm8001_ha->inbnd_q_tbl_addr =
638 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C);
639 pm8001_ha->outbnd_q_tbl_addr =
640 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20);
641}
642
643/**
644 * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
645 * @pm8001_ha: our hba card information
646 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800647static int pm8001_chip_init(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800648{
Colin Ian King40fa7392021-04-07 14:58:40 +0100649 u32 i = 0;
Sakthivel K54792dc2013-03-19 18:05:55 +0530650 u16 deviceid;
651 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
652 /* 8081 controllers need BAR shift to access MPI space
653 * as this is shared with BIOS data */
Bradley Grove81b86d42013-12-19 10:50:57 -0500654 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530655 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800656 pm8001_dbg(pm8001_ha, FAIL,
657 "Shift Bar4 to 0x%x failed\n",
658 GSM_SM_BASE);
Sakthivel K54792dc2013-03-19 18:05:55 +0530659 return -1;
660 }
661 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800662 /* check the firmware status */
663 if (-1 == check_fw_ready(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800664 pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800665 return -EBUSY;
666 }
667
668 /* Initialize pci space address eg: mpi offset */
669 init_pci_device_addresses(pm8001_ha);
670 init_default_table_values(pm8001_ha);
671 read_main_config_table(pm8001_ha);
672 read_general_status_table(pm8001_ha);
673 read_inbnd_queue_table(pm8001_ha);
674 read_outbnd_queue_table(pm8001_ha);
675 /* update main config table ,inbound table and outbound table */
676 update_main_config_table(pm8001_ha);
Viswas G65df7d12021-04-02 11:12:12 +0530677 for (i = 0; i < pm8001_ha->max_q_num; i++)
Sakthivel Ke590adf2013-02-27 20:25:25 +0530678 update_inbnd_queue_table(pm8001_ha, i);
Viswas G65df7d12021-04-02 11:12:12 +0530679 for (i = 0; i < pm8001_ha->max_q_num; i++)
Sakthivel Ke590adf2013-02-27 20:25:25 +0530680 update_outbnd_queue_table(pm8001_ha, i);
Sakthivel K54792dc2013-03-19 18:05:55 +0530681 /* 8081 controller donot require these operations */
Bradley Grove81b86d42013-12-19 10:50:57 -0500682 if (deviceid != 0x8081 && deviceid != 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530683 mpi_set_phys_g3_with_ssc(pm8001_ha, 0);
684 /* 7->130ms, 34->500ms, 119->1.5s */
685 mpi_set_open_retry_interval_reg(pm8001_ha, 119);
686 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800687 /* notify firmware update finished and check initialization status */
688 if (0 == mpi_init_check(pm8001_ha)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800689 pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800690 } else
691 return -EBUSY;
692 /*This register is a 16-bit timer with a resolution of 1us. This is the
693 timer used for interrupt delay/coalescing in the PCIe Application Layer.
694 Zero is not a valid value. A value of 1 in the register will cause the
695 interrupts to be normal. A value greater than 1 will cause coalescing
696 delays.*/
697 pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1);
698 pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0);
699 return 0;
700}
701
702static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
703{
704 u32 max_wait_count;
705 u32 value;
706 u32 gst_len_mpistate;
Sakthivel K54792dc2013-03-19 18:05:55 +0530707 u16 deviceid;
708 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
Bradley Grove81b86d42013-12-19 10:50:57 -0500709 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530710 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800711 pm8001_dbg(pm8001_ha, FAIL,
712 "Shift Bar4 to 0x%x failed\n",
713 GSM_SM_BASE);
Sakthivel K54792dc2013-03-19 18:05:55 +0530714 return -1;
715 }
716 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800717 init_pci_device_addresses(pm8001_ha);
718 /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
719 table is stop */
720 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET);
721
722 /* wait until Inbound DoorBell Clear Register toggled */
723 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
724 do {
725 udelay(1);
726 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
727 value &= SPC_MSGU_CFG_TABLE_RESET;
728 } while ((value != 0) && (--max_wait_count));
729
730 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800731 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=0x%x\n",
732 value);
jack wangdbf9bfe2009-10-14 16:19:21 +0800733 return -1;
734 }
735
736 /* check the MPI-State for termination in progress */
737 /* wait until Inbound DoorBell Clear Register toggled */
738 max_wait_count = 1 * 1000 * 1000; /* 1 sec */
739 do {
740 udelay(1);
741 gst_len_mpistate =
742 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
743 GST_GSTLEN_MPIS_OFFSET);
744 if (GST_MPI_STATE_UNINIT ==
745 (gst_len_mpistate & GST_MPI_STATE_MASK))
746 break;
747 } while (--max_wait_count);
748 if (!max_wait_count) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800749 pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n",
750 gst_len_mpistate & GST_MPI_STATE_MASK);
jack wangdbf9bfe2009-10-14 16:19:21 +0800751 return -1;
752 }
753 return 0;
754}
755
756/**
757 * soft_reset_ready_check - Function to check FW is ready for soft reset.
758 * @pm8001_ha: our hba card information
759 */
760static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha)
761{
762 u32 regVal, regVal1, regVal2;
763 if (mpi_uninit_check(pm8001_ha) != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800764 pm8001_dbg(pm8001_ha, FAIL, "MPI state is not ready\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800765 return -1;
766 }
767 /* read the scratch pad 2 register bit 2 */
768 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
769 & SCRATCH_PAD2_FWRDY_RST;
770 if (regVal == SCRATCH_PAD2_FWRDY_RST) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800771 pm8001_dbg(pm8001_ha, INIT, "Firmware is ready for reset.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800772 } else {
Mark Salyzynd95d0002012-01-17 09:18:57 -0500773 unsigned long flags;
774 /* Trigger NMI twice via RB6 */
775 spin_lock_irqsave(&pm8001_ha->lock, flags);
776 if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) {
777 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800778 pm8001_dbg(pm8001_ha, FAIL,
779 "Shift Bar4 to 0x%x failed\n",
780 RB6_ACCESS_REG);
jack wangdbf9bfe2009-10-14 16:19:21 +0800781 return -1;
782 }
783 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET,
784 RB6_MAGIC_NUMBER_RST);
785 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST);
786 /* wait for 100 ms */
787 mdelay(100);
788 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) &
789 SCRATCH_PAD2_FWRDY_RST;
790 if (regVal != SCRATCH_PAD2_FWRDY_RST) {
791 regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
792 regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
Joe Perches1b5d2792020-11-20 15:16:09 -0800793 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:MSGU_SCRATCH_PAD1=0x%x, MSGU_SCRATCH_PAD2=0x%x\n",
794 regVal1, regVal2);
795 pm8001_dbg(pm8001_ha, FAIL,
796 "SCRATCH_PAD0 value = 0x%x\n",
797 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0));
798 pm8001_dbg(pm8001_ha, FAIL,
799 "SCRATCH_PAD3 value = 0x%x\n",
800 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -0500801 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800802 return -1;
803 }
Mark Salyzynd95d0002012-01-17 09:18:57 -0500804 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800805 }
806 return 0;
807}
808
809/**
810 * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
811 * the FW register status to the originated status.
812 * @pm8001_ha: our hba card information
jack wangdbf9bfe2009-10-14 16:19:21 +0800813 */
814static int
Sakthivel Kf5860992013-04-17 16:37:02 +0530815pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800816{
817 u32 regVal, toggleVal;
818 u32 max_wait_count;
819 u32 regVal1, regVal2, regVal3;
Sakthivel Kf5860992013-04-17 16:37:02 +0530820 u32 signature = 0x252acbcd; /* for host scratch pad0 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500821 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800822
823 /* step1: Check FW is ready for soft reset */
824 if (soft_reset_ready_check(pm8001_ha) != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800825 pm8001_dbg(pm8001_ha, FAIL, "FW is not ready\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800826 return -1;
827 }
828
829 /* step 2: clear NMI status register on AAP1 and IOP, write the same
830 value to clear */
831 /* map 0x60000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500832 spin_lock_irqsave(&pm8001_ha->lock, flags);
833 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) {
834 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800835 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
836 MBIC_AAP1_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800837 return -1;
838 }
839 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP);
Joe Perches1b5d2792020-11-20 15:16:09 -0800840 pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (IOP)= 0x%x\n",
841 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800842 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0);
843 /* map 0x70000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500844 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) {
845 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800846 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
847 MBIC_IOP_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800848 return -1;
849 }
850 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1);
Joe Perches1b5d2792020-11-20 15:16:09 -0800851 pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n",
852 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800853 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0);
854
855 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800856 pm8001_dbg(pm8001_ha, INIT, "PCIE -Event Interrupt Enable = 0x%x\n",
857 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800858 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0);
859
860 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT);
Joe Perches1b5d2792020-11-20 15:16:09 -0800861 pm8001_dbg(pm8001_ha, INIT, "PCIE - Event Interrupt = 0x%x\n",
862 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800863 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal);
864
865 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800866 pm8001_dbg(pm8001_ha, INIT, "PCIE -Error Interrupt Enable = 0x%x\n",
867 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800868 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0);
869
870 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT);
Joe Perches1b5d2792020-11-20 15:16:09 -0800871 pm8001_dbg(pm8001_ha, INIT, "PCIE - Error Interrupt = 0x%x\n", regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800872 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal);
873
874 /* read the scratch pad 1 register bit 2 */
875 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
876 & SCRATCH_PAD1_RST;
877 toggleVal = regVal ^ SCRATCH_PAD1_RST;
878
879 /* set signature in host scratch pad0 register to tell SPC that the
880 host performs the soft reset */
881 pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature);
882
883 /* read required registers for confirmming */
884 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500885 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
886 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800887 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
888 GSM_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800889 return -1;
890 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800891 pm8001_dbg(pm8001_ha, INIT,
892 "GSM 0x0(0x00007b88)-GSM Configuration and Reset = 0x%x\n",
893 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +0800894
895 /* step 3: host read GSM Configuration and Reset register */
896 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
897 /* Put those bits to low */
898 /* GSM XCBI offset = 0x70 0000
899 0x00 Bit 13 COM_SLV_SW_RSTB 1
900 0x00 Bit 12 QSSP_SW_RSTB 1
901 0x00 Bit 11 RAAE_SW_RSTB 1
902 0x00 Bit 9 RB_1_SW_RSTB 1
903 0x00 Bit 8 SM_SW_RSTB 1
904 */
905 regVal &= ~(0x00003b00);
906 /* host write GSM Configuration and Reset register */
907 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
Joe Perches1b5d2792020-11-20 15:16:09 -0800908 pm8001_dbg(pm8001_ha, INIT,
909 "GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM Configuration and Reset is set to = 0x%x\n",
910 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +0800911
912 /* step 4: */
913 /* disable GSM - Read Address Parity Check */
914 regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800915 pm8001_dbg(pm8001_ha, INIT,
916 "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n",
917 regVal1);
jack wangdbf9bfe2009-10-14 16:19:21 +0800918 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800919 pm8001_dbg(pm8001_ha, INIT,
920 "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n",
921 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800922
923 /* disable GSM - Write Address Parity Check */
924 regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800925 pm8001_dbg(pm8001_ha, INIT,
926 "GSM 0x700040 - Write Address Parity Check Enable = 0x%x\n",
927 regVal2);
jack wangdbf9bfe2009-10-14 16:19:21 +0800928 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800929 pm8001_dbg(pm8001_ha, INIT,
930 "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n",
931 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800932
933 /* disable GSM - Write Data Parity Check */
934 regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
Joe Perches1b5d2792020-11-20 15:16:09 -0800935 pm8001_dbg(pm8001_ha, INIT, "GSM 0x300048 - Write Data Parity Check Enable = 0x%x\n",
936 regVal3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800937 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0);
Joe Perches1b5d2792020-11-20 15:16:09 -0800938 pm8001_dbg(pm8001_ha, INIT,
939 "GSM 0x300048 - Write Data Parity Check Enable is set to = 0x%x\n",
940 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +0800941
942 /* step 5: delay 10 usec */
943 udelay(10);
944 /* step 5-b: set GPIO-0 output control to tristate anyway */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500945 if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) {
946 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800947 pm8001_dbg(pm8001_ha, INIT, "Shift Bar4 to 0x%x failed\n",
948 GPIO_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800949 return -1;
950 }
951 regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800952 pm8001_dbg(pm8001_ha, INIT, "GPIO Output Control Register: = 0x%x\n",
953 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800954 /* set GPIO-0 output control to tri-state */
955 regVal &= 0xFFFFFFFC;
956 pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal);
957
958 /* Step 6: Reset the IOP and AAP1 */
959 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500960 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
961 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800962 pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n",
963 SPC_TOP_LEVEL_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800964 return -1;
965 }
966 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800967 pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting IOP/AAP1:= 0x%x\n",
968 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800969 regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
970 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
971
972 /* step 7: Reset the BDMA/OSSP */
973 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800974 pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting BDMA/OSSP: = 0x%x\n",
975 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800976 regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
977 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
978
979 /* step 8: delay 10 usec */
980 udelay(10);
981
982 /* step 9: bring the BDMA and OSSP out of reset */
983 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
Joe Perches1b5d2792020-11-20 15:16:09 -0800984 pm8001_dbg(pm8001_ha, INIT,
985 "Top Register before bringing up BDMA/OSSP:= 0x%x\n",
986 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +0800987 regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
988 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
989
990 /* step 10: delay 10 usec */
991 udelay(10);
992
993 /* step 11: reads and sets the GSM Configuration and Reset Register */
994 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500995 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
996 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -0800997 pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n",
998 GSM_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800999 return -1;
1000 }
Joe Perches1b5d2792020-11-20 15:16:09 -08001001 pm8001_dbg(pm8001_ha, INIT,
1002 "GSM 0x0 (0x00007b88)-GSM Configuration and Reset = 0x%x\n",
1003 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +08001004 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
1005 /* Put those bits to high */
1006 /* GSM XCBI offset = 0x70 0000
1007 0x00 Bit 13 COM_SLV_SW_RSTB 1
1008 0x00 Bit 12 QSSP_SW_RSTB 1
1009 0x00 Bit 11 RAAE_SW_RSTB 1
1010 0x00 Bit 9 RB_1_SW_RSTB 1
1011 0x00 Bit 8 SM_SW_RSTB 1
1012 */
1013 regVal |= (GSM_CONFIG_RESET_VALUE);
1014 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
Joe Perches1b5d2792020-11-20 15:16:09 -08001015 pm8001_dbg(pm8001_ha, INIT, "GSM (0x00004088 ==> 0x00007b88) - GSM Configuration and Reset is set to = 0x%x\n",
1016 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET));
jack wangdbf9bfe2009-10-14 16:19:21 +08001017
1018 /* step 12: Restore GSM - Read Address Parity Check */
1019 regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
1020 /* just for debugging */
Joe Perches1b5d2792020-11-20 15:16:09 -08001021 pm8001_dbg(pm8001_ha, INIT,
1022 "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n",
1023 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +08001024 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001025 pm8001_dbg(pm8001_ha, INIT, "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n",
1026 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001027 /* Restore GSM - Write Address Parity Check */
1028 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
1029 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2);
Joe Perches1b5d2792020-11-20 15:16:09 -08001030 pm8001_dbg(pm8001_ha, INIT,
1031 "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n",
1032 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001033 /* Restore GSM - Write Data Parity Check */
1034 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
1035 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3);
Joe Perches1b5d2792020-11-20 15:16:09 -08001036 pm8001_dbg(pm8001_ha, INIT,
Colin Ian Kingc6131852020-11-24 09:38:28 +00001037 "GSM 0x700048 - Write Data Parity Check Enable is set to = 0x%x\n",
Joe Perches1b5d2792020-11-20 15:16:09 -08001038 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK));
jack wangdbf9bfe2009-10-14 16:19:21 +08001039
1040 /* step 13: bring the IOP and AAP1 out of reset */
1041 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -05001042 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
1043 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08001044 pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n",
1045 SPC_TOP_LEVEL_ADDR_BASE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001046 return -1;
1047 }
1048 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
1049 regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
1050 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
1051
1052 /* step 14: delay 10 usec - Normal Mode */
1053 udelay(10);
1054 /* check Soft Reset Normal mode or Soft Reset HDA mode */
1055 if (signature == SPC_SOFT_RESET_SIGNATURE) {
1056 /* step 15 (Normal Mode): wait until scratch pad1 register
1057 bit 2 toggled */
1058 max_wait_count = 2 * 1000 * 1000;/* 2 sec */
1059 do {
1060 udelay(1);
1061 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1062 SCRATCH_PAD1_RST;
1063 } while ((regVal != toggleVal) && (--max_wait_count));
1064
1065 if (!max_wait_count) {
1066 regVal = pm8001_cr32(pm8001_ha, 0,
1067 MSGU_SCRATCH_PAD_1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001068 pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT : ToggleVal 0x%x,MSGU_SCRATCH_PAD1 = 0x%x\n",
1069 toggleVal, regVal);
1070 pm8001_dbg(pm8001_ha, FAIL,
1071 "SCRATCH_PAD0 value = 0x%x\n",
1072 pm8001_cr32(pm8001_ha, 0,
1073 MSGU_SCRATCH_PAD_0));
1074 pm8001_dbg(pm8001_ha, FAIL,
1075 "SCRATCH_PAD2 value = 0x%x\n",
1076 pm8001_cr32(pm8001_ha, 0,
1077 MSGU_SCRATCH_PAD_2));
1078 pm8001_dbg(pm8001_ha, FAIL,
1079 "SCRATCH_PAD3 value = 0x%x\n",
1080 pm8001_cr32(pm8001_ha, 0,
1081 MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001082 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001083 return -1;
1084 }
1085
1086 /* step 16 (Normal) - Clear ODMR and ODCR */
1087 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1088 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1089
1090 /* step 17 (Normal Mode): wait for the FW and IOP to get
1091 ready - 1 sec timeout */
1092 /* Wait for the SPC Configuration Table to be ready */
1093 if (check_fw_ready(pm8001_ha) == -1) {
1094 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1095 /* return error if MPI Configuration Table not ready */
Joe Perches1b5d2792020-11-20 15:16:09 -08001096 pm8001_dbg(pm8001_ha, INIT,
1097 "FW not ready SCRATCH_PAD1 = 0x%x\n",
1098 regVal);
jack wangdbf9bfe2009-10-14 16:19:21 +08001099 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1100 /* return error if MPI Configuration Table not ready */
Joe Perches1b5d2792020-11-20 15:16:09 -08001101 pm8001_dbg(pm8001_ha, INIT,
1102 "FW not ready SCRATCH_PAD2 = 0x%x\n",
1103 regVal);
1104 pm8001_dbg(pm8001_ha, INIT,
1105 "SCRATCH_PAD0 value = 0x%x\n",
1106 pm8001_cr32(pm8001_ha, 0,
1107 MSGU_SCRATCH_PAD_0));
1108 pm8001_dbg(pm8001_ha, INIT,
1109 "SCRATCH_PAD3 value = 0x%x\n",
1110 pm8001_cr32(pm8001_ha, 0,
1111 MSGU_SCRATCH_PAD_3));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001112 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001113 return -1;
1114 }
1115 }
Mark Salyzynd95d0002012-01-17 09:18:57 -05001116 pm8001_bar4_shift(pm8001_ha, 0);
1117 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001118
Joe Perches1b5d2792020-11-20 15:16:09 -08001119 pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001120 return 0;
1121}
1122
1123static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1124{
1125 u32 i;
1126 u32 regVal;
Joe Perches1b5d2792020-11-20 15:16:09 -08001127 pm8001_dbg(pm8001_ha, INIT, "chip reset start\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001128
1129 /* do SPC chip reset. */
1130 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1131 regVal &= ~(SPC_REG_RESET_DEVICE);
1132 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1133
1134 /* delay 10 usec */
1135 udelay(10);
1136
1137 /* bring chip reset out of reset */
1138 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1139 regVal |= SPC_REG_RESET_DEVICE;
1140 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1141
1142 /* delay 10 usec */
1143 udelay(10);
1144
1145 /* wait for 20 msec until the firmware gets reloaded */
1146 i = 20;
1147 do {
1148 mdelay(1);
1149 } while ((--i) != 0);
1150
Joe Perches1b5d2792020-11-20 15:16:09 -08001151 pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001152}
1153
1154/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001155 * pm8001_chip_iounmap - which mapped when initialized.
jack wangdbf9bfe2009-10-14 16:19:21 +08001156 * @pm8001_ha: our hba card information
1157 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301158void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08001159{
1160 s8 bar, logical = 0;
Denis Efremovc9c13ba2019-09-28 02:43:08 +03001161 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001162 /*
1163 ** logical BARs for SPC:
1164 ** bar 0 and 1 - logical BAR0
1165 ** bar 2 and 3 - logical BAR1
1166 ** bar4 - logical BAR2
1167 ** bar5 - logical BAR3
1168 ** Skip the appropriate assignments:
1169 */
1170 if ((bar == 1) || (bar == 3))
1171 continue;
1172 if (pm8001_ha->io_mem[logical].memvirtaddr) {
1173 iounmap(pm8001_ha->io_mem[logical].memvirtaddr);
1174 logical++;
1175 }
1176 }
1177}
1178
Colin Ian King292c04c2019-03-28 23:43:28 +00001179#ifndef PM8001_USE_MSIX
jack wangdbf9bfe2009-10-14 16:19:21 +08001180/**
Lee Jones6b87e432021-03-03 14:46:19 +00001181 * pm8001_chip_intx_interrupt_enable - enable PM8001 chip interrupt
jack wangdbf9bfe2009-10-14 16:19:21 +08001182 * @pm8001_ha: our hba card information
1183 */
1184static void
1185pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1186{
1187 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1188 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1189}
1190
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001191/**
1192 * pm8001_chip_intx_interrupt_disable - disable PM8001 chip interrupt
1193 * @pm8001_ha: our hba card information
1194 */
jack wangdbf9bfe2009-10-14 16:19:21 +08001195static void
1196pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1197{
1198 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL);
1199}
1200
Colin Ian King292c04c2019-03-28 23:43:28 +00001201#else
1202
jack wangdbf9bfe2009-10-14 16:19:21 +08001203/**
1204 * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt
1205 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001206 * @int_vec_idx: interrupt number to enable
jack wangdbf9bfe2009-10-14 16:19:21 +08001207 */
1208static void
1209pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha,
1210 u32 int_vec_idx)
1211{
1212 u32 msi_index;
1213 u32 value;
1214 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1215 msi_index += MSIX_TABLE_BASE;
1216 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE);
1217 value = (1 << int_vec_idx);
1218 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value);
1219
1220}
1221
1222/**
1223 * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt
1224 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001225 * @int_vec_idx: interrupt number to disable
jack wangdbf9bfe2009-10-14 16:19:21 +08001226 */
1227static void
1228pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha,
1229 u32 int_vec_idx)
1230{
1231 u32 msi_index;
1232 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1233 msi_index += MSIX_TABLE_BASE;
1234 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001235}
Colin Ian King292c04c2019-03-28 23:43:28 +00001236#endif
Mark Salyzynd95d0002012-01-17 09:18:57 -05001237
jack wangdbf9bfe2009-10-14 16:19:21 +08001238/**
1239 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1240 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001241 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001242 */
1243static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301244pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001245{
1246#ifdef PM8001_USE_MSIX
1247 pm8001_chip_msix_interrupt_enable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001248#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001249 pm8001_chip_intx_interrupt_enable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001250#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001251}
1252
1253/**
Lee Jones6b87e432021-03-03 14:46:19 +00001254 * pm8001_chip_interrupt_disable - disable PM8001 chip interrupt
jack wangdbf9bfe2009-10-14 16:19:21 +08001255 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001256 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001257 */
1258static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301259pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001260{
1261#ifdef PM8001_USE_MSIX
1262 pm8001_chip_msix_interrupt_disable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001263#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001264 pm8001_chip_intx_interrupt_disable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001265#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001266}
1267
1268/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301269 * pm8001_mpi_msg_free_get - get the free message buffer for transfer
1270 * inbound queue.
jack wangdbf9bfe2009-10-14 16:19:21 +08001271 * @circularQ: the inbound queue we want to transfer to HBA.
1272 * @messageSize: the message size of this transfer, normally it is 64 bytes
1273 * @messagePtr: the pointer to message.
1274 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301275int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ,
jack wangdbf9bfe2009-10-14 16:19:21 +08001276 u16 messageSize, void **messagePtr)
1277{
1278 u32 offset, consumer_index;
1279 struct mpi_msg_hdr *msgHeader;
1280 u8 bcCount = 1; /* only support single buffer */
1281
1282 /* Checks is the requested message size can be allocated in this queue*/
Sakthivel Kf74cf272013-02-27 20:27:43 +05301283 if (messageSize > IOMB_SIZE_SPCV) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001284 *messagePtr = NULL;
1285 return -1;
1286 }
1287
1288 /* Stores the new consumer index */
1289 consumer_index = pm8001_read_32(circularQ->ci_virt);
1290 circularQ->consumer_index = cpu_to_le32(consumer_index);
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001291 if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) ==
Santosh Nayak8270ee22012-02-26 20:14:46 +05301292 le32_to_cpu(circularQ->consumer_index)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001293 *messagePtr = NULL;
1294 return -1;
1295 }
1296 /* get memory IOMB buffer address */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301297 offset = circularQ->producer_idx * messageSize;
jack wangdbf9bfe2009-10-14 16:19:21 +08001298 /* increment to next bcCount element */
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001299 circularQ->producer_idx = (circularQ->producer_idx + bcCount)
1300 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001301 /* Adds that distance to the base of the region virtual address plus
1302 the message header size*/
1303 msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset);
1304 *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr);
1305 return 0;
1306}
1307
1308/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301309 * pm8001_mpi_build_cmd- build the message queue for transfer, update the PI to
1310 * FW to tell the fw to get this message from IOMB.
jack wangdbf9bfe2009-10-14 16:19:21 +08001311 * @pm8001_ha: our hba card information
1312 * @circularQ: the inbound queue we want to transfer to HBA.
1313 * @opCode: the operation code represents commands which LLDD and fw recognized.
1314 * @payload: the command payload of each operation command.
peter chang91a43fa2019-11-14 15:39:05 +05301315 * @nb: size in bytes of the command payload
1316 * @responseQueue: queue to interrupt on w/ command response (if any)
jack wangdbf9bfe2009-10-14 16:19:21 +08001317 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301318int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001319 struct inbound_queue_table *circularQ,
peter chang91a43fa2019-11-14 15:39:05 +05301320 u32 opCode, void *payload, size_t nb,
1321 u32 responseQueue)
jack wangdbf9bfe2009-10-14 16:19:21 +08001322{
1323 u32 Header = 0, hpriority = 0, bc = 1, category = 0x02;
jack wangdbf9bfe2009-10-14 16:19:21 +08001324 void *pMessage;
peter chang7640e1e2020-11-02 22:25:25 +05301325 unsigned long flags;
1326 int q_index = circularQ - pm8001_ha->inbnd_q_tbl;
Colin Ian King83da6ad2021-08-04 15:33:19 +01001327 int rv;
Changyuan Lyu0137b122021-11-15 13:57:50 -08001328 u32 htag = le32_to_cpu(*(__le32 *)payload);
1329
1330 trace_pm80xx_mpi_build_cmd(pm8001_ha->id, opCode, htag, q_index,
1331 circularQ->producer_idx, le32_to_cpu(circularQ->consumer_index));
jack wangdbf9bfe2009-10-14 16:19:21 +08001332
Igor Pylypiv606c54a2021-11-01 16:28:24 -07001333 if (WARN_ON(q_index >= pm8001_ha->max_q_num))
1334 return -EINVAL;
1335
peter chang7640e1e2020-11-02 22:25:25 +05301336 spin_lock_irqsave(&circularQ->iq_lock, flags);
1337 rv = pm8001_mpi_msg_free_get(circularQ, pm8001_ha->iomb_size,
1338 &pMessage);
1339 if (rv < 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001340 pm8001_dbg(pm8001_ha, IO, "No free mpi buffer\n");
peter chang7640e1e2020-11-02 22:25:25 +05301341 rv = -ENOMEM;
1342 goto done;
jack wangdbf9bfe2009-10-14 16:19:21 +08001343 }
peter chang91a43fa2019-11-14 15:39:05 +05301344
1345 if (nb > (pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr)))
1346 nb = pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr);
1347 memcpy(pMessage, payload, nb);
1348 if (nb + sizeof(struct mpi_msg_hdr) < pm8001_ha->iomb_size)
1349 memset(pMessage + nb, 0, pm8001_ha->iomb_size -
1350 (nb + sizeof(struct mpi_msg_hdr)));
jack wangdbf9bfe2009-10-14 16:19:21 +08001351
1352 /*Build the header*/
1353 Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24)
1354 | ((responseQueue & 0x3F) << 16)
1355 | ((category & 0xF) << 12) | (opCode & 0xFFF));
1356
1357 pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header));
1358 /*Update the PI to the firmware*/
1359 pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
1360 circularQ->pi_offset, circularQ->producer_idx);
Joe Perches1b5d2792020-11-20 15:16:09 -08001361 pm8001_dbg(pm8001_ha, DEVIO,
1362 "INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n",
1363 responseQueue, opCode, circularQ->producer_idx,
1364 circularQ->consumer_index);
peter chang7640e1e2020-11-02 22:25:25 +05301365done:
1366 spin_unlock_irqrestore(&circularQ->iq_lock, flags);
1367 return rv;
jack wangdbf9bfe2009-10-14 16:19:21 +08001368}
1369
Sakthivel Kf74cf272013-02-27 20:27:43 +05301370u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
jack wangdbf9bfe2009-10-14 16:19:21 +08001371 struct outbound_queue_table *circularQ, u8 bc)
1372{
1373 u32 producer_index;
jack_wang72d0baa2009-11-05 22:33:35 +08001374 struct mpi_msg_hdr *msgHeader;
1375 struct mpi_msg_hdr *pOutBoundMsgHeader;
1376
1377 msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr));
1378 pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301379 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack_wang72d0baa2009-11-05 22:33:35 +08001380 if (pOutBoundMsgHeader != msgHeader) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001381 pm8001_dbg(pm8001_ha, FAIL,
1382 "consumer_idx = %d msgHeader = %p\n",
1383 circularQ->consumer_idx, msgHeader);
jack_wang72d0baa2009-11-05 22:33:35 +08001384
1385 /* Update the producer index from SPC */
1386 producer_index = pm8001_read_32(circularQ->pi_virt);
1387 circularQ->producer_index = cpu_to_le32(producer_index);
Joe Perches1b5d2792020-11-20 15:16:09 -08001388 pm8001_dbg(pm8001_ha, FAIL,
1389 "consumer_idx = %d producer_index = %dmsgHeader = %p\n",
1390 circularQ->consumer_idx,
1391 circularQ->producer_index, msgHeader);
jack_wang72d0baa2009-11-05 22:33:35 +08001392 return 0;
1393 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001394 /* free the circular queue buffer elements associated with the message*/
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001395 circularQ->consumer_idx = (circularQ->consumer_idx + bc)
1396 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001397 /* update the CI of outbound queue */
1398 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset,
1399 circularQ->consumer_idx);
1400 /* Update the producer index from SPC*/
1401 producer_index = pm8001_read_32(circularQ->pi_virt);
1402 circularQ->producer_index = cpu_to_le32(producer_index);
Joe Perches1b5d2792020-11-20 15:16:09 -08001403 pm8001_dbg(pm8001_ha, IO, " CI=%d PI=%d\n",
1404 circularQ->consumer_idx, circularQ->producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001405 return 0;
1406}
1407
1408/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301409 * pm8001_mpi_msg_consume- get the MPI message from outbound queue
1410 * message table.
jack wangdbf9bfe2009-10-14 16:19:21 +08001411 * @pm8001_ha: our hba card information
1412 * @circularQ: the outbound queue table.
1413 * @messagePtr1: the message contents of this outbound message.
1414 * @pBC: the message size.
1415 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301416u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001417 struct outbound_queue_table *circularQ,
1418 void **messagePtr1, u8 *pBC)
1419{
1420 struct mpi_msg_hdr *msgHeader;
1421 __le32 msgHeader_tmp;
1422 u32 header_tmp;
1423 do {
1424 /* If there are not-yet-delivered messages ... */
Santosh Nayak8270ee22012-02-26 20:14:46 +05301425 if (le32_to_cpu(circularQ->producer_index)
1426 != circularQ->consumer_idx) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001427 /*Get the pointer to the circular queue buffer element*/
1428 msgHeader = (struct mpi_msg_hdr *)
1429 (circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301430 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack wangdbf9bfe2009-10-14 16:19:21 +08001431 /* read header */
1432 header_tmp = pm8001_read_32(msgHeader);
1433 msgHeader_tmp = cpu_to_le32(header_tmp);
Joe Perches1b5d2792020-11-20 15:16:09 -08001434 pm8001_dbg(pm8001_ha, DEVIO,
1435 "outbound opcode msgheader:%x ci=%d pi=%d\n",
1436 msgHeader_tmp, circularQ->consumer_idx,
1437 circularQ->producer_index);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301438 if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001439 if (OPC_OUB_SKIP_ENTRY !=
Santosh Nayak8270ee22012-02-26 20:14:46 +05301440 (le32_to_cpu(msgHeader_tmp) & 0xfff)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001441 *messagePtr1 =
1442 ((u8 *)msgHeader) +
1443 sizeof(struct mpi_msg_hdr);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301444 *pBC = (u8)((le32_to_cpu(msgHeader_tmp)
1445 >> 24) & 0x1f);
Joe Perches1b5d2792020-11-20 15:16:09 -08001446 pm8001_dbg(pm8001_ha, IO,
1447 ": CI=%d PI=%d msgHeader=%x\n",
1448 circularQ->consumer_idx,
1449 circularQ->producer_index,
1450 msgHeader_tmp);
jack wangdbf9bfe2009-10-14 16:19:21 +08001451 return MPI_IO_STATUS_SUCCESS;
1452 } else {
jack wangdbf9bfe2009-10-14 16:19:21 +08001453 circularQ->consumer_idx =
1454 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301455 ((le32_to_cpu(msgHeader_tmp)
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001456 >> 24) & 0x1f))
1457 % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001458 msgHeader_tmp = 0;
1459 pm8001_write_32(msgHeader, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08001460 /* update the CI of outbound queue */
1461 pm8001_cw32(pm8001_ha,
1462 circularQ->ci_pci_bar,
1463 circularQ->ci_offset,
1464 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001465 }
jack_wang72d0baa2009-11-05 22:33:35 +08001466 } else {
1467 circularQ->consumer_idx =
1468 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301469 ((le32_to_cpu(msgHeader_tmp) >> 24) &
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001470 0x1f)) % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001471 msgHeader_tmp = 0;
1472 pm8001_write_32(msgHeader, 0, 0);
1473 /* update the CI of outbound queue */
1474 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar,
1475 circularQ->ci_offset,
1476 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001477 return MPI_IO_STATUS_FAIL;
jack_wang72d0baa2009-11-05 22:33:35 +08001478 }
1479 } else {
1480 u32 producer_index;
1481 void *pi_virt = circularQ->pi_virt;
Deepak Ukey72349b62018-09-11 14:18:04 +05301482 /* spurious interrupt during setup if
1483 * kexec-ing and driver doing a doorbell access
1484 * with the pre-kexec oq interrupt setup
1485 */
1486 if (!pi_virt)
1487 break;
jack_wang72d0baa2009-11-05 22:33:35 +08001488 /* Update the producer index from SPC */
1489 producer_index = pm8001_read_32(pi_virt);
1490 circularQ->producer_index = cpu_to_le32(producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001491 }
Santosh Nayak8270ee22012-02-26 20:14:46 +05301492 } while (le32_to_cpu(circularQ->producer_index) !=
1493 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001494 /* while we don't have any more not-yet-delivered message */
1495 /* report empty */
1496 return MPI_IO_STATUS_BUSY;
1497}
1498
Sakthivel Kf74cf272013-02-27 20:27:43 +05301499void pm8001_work_fn(struct work_struct *work)
jack wangdbf9bfe2009-10-14 16:19:21 +08001500{
Tejun Heo429305e2011-01-24 14:57:29 +01001501 struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001502 struct pm8001_device *pm8001_dev;
Tejun Heo429305e2011-01-24 14:57:29 +01001503 struct domain_device *dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08001504
Mark Salyzyn5954d732012-01-17 11:52:24 -05001505 /*
1506 * So far, all users of this stash an associated structure here.
1507 * If we get here, and this pointer is null, then the action
1508 * was cancelled. This nullification happens when the device
1509 * goes away.
1510 */
Ruksar Devadi4f5deeb2021-04-15 16:03:50 +05301511 if (pw->handler != IO_FATAL_ERROR) {
1512 pm8001_dev = pw->data; /* Most stash device structure */
1513 if ((pm8001_dev == NULL)
1514 || ((pw->handler != IO_XFER_ERROR_BREAK)
1515 && (pm8001_dev->dev_type == SAS_PHY_UNUSED))) {
1516 kfree(pw);
1517 return;
1518 }
Mark Salyzyn5954d732012-01-17 11:52:24 -05001519 }
1520
Tejun Heo429305e2011-01-24 14:57:29 +01001521 switch (pw->handler) {
Mark Salyzyn5954d732012-01-17 11:52:24 -05001522 case IO_XFER_ERROR_BREAK:
1523 { /* This one stashes the sas_task instead */
1524 struct sas_task *t = (struct sas_task *)pm8001_dev;
1525 u32 tag;
1526 struct pm8001_ccb_info *ccb;
1527 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1528 unsigned long flags, flags1;
1529 struct task_status_struct *ts;
1530 int i;
1531
1532 if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC)
1533 break; /* Task still on lu */
1534 spin_lock_irqsave(&pm8001_ha->lock, flags);
1535
1536 spin_lock_irqsave(&t->task_state_lock, flags1);
1537 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1538 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1539 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1540 break; /* Task got completed by another */
1541 }
1542 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1543
1544 /* Search for a possible ccb that matches the task */
1545 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1546 ccb = &pm8001_ha->ccb_info[i];
1547 tag = ccb->ccb_tag;
1548 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1549 break;
1550 }
1551 if (!ccb) {
1552 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1553 break; /* Task got freed by another */
1554 }
1555 ts = &t->task_status;
1556 ts->resp = SAS_TASK_COMPLETE;
1557 /* Force the midlayer to retry */
1558 ts->stat = SAS_QUEUE_FULL;
1559 pm8001_dev = ccb->device;
1560 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301561 atomic_dec(&pm8001_dev->running_req);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001562 spin_lock_irqsave(&t->task_state_lock, flags1);
1563 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
1564 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
1565 t->task_state_flags |= SAS_TASK_STATE_DONE;
1566 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
1567 spin_unlock_irqrestore(&t->task_state_lock, flags1);
Joe Perches1b5d2792020-11-20 15:16:09 -08001568 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",
1569 t, pw->handler, ts->resp, ts->stat);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001570 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1571 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1572 } else {
1573 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1574 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1575 mb();/* in order to force CPU ordering */
1576 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1577 t->task_done(t);
1578 }
1579 } break;
1580 case IO_XFER_OPEN_RETRY_TIMEOUT:
1581 { /* This one stashes the sas_task instead */
1582 struct sas_task *t = (struct sas_task *)pm8001_dev;
1583 u32 tag;
1584 struct pm8001_ccb_info *ccb;
1585 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1586 unsigned long flags, flags1;
1587 int i, ret = 0;
1588
Joe Perches1b5d2792020-11-20 15:16:09 -08001589 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001590
1591 ret = pm8001_query_task(t);
1592
Joe Perches1b5d2792020-11-20 15:16:09 -08001593 if (ret == TMF_RESP_FUNC_SUCC)
1594 pm8001_dbg(pm8001_ha, IO, "...Task on lu\n");
1595 else if (ret == TMF_RESP_FUNC_COMPLETE)
1596 pm8001_dbg(pm8001_ha, IO, "...Task NOT on lu\n");
1597 else
1598 pm8001_dbg(pm8001_ha, DEVIO, "...query task failed!!!\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001599
1600 spin_lock_irqsave(&pm8001_ha->lock, flags);
1601
1602 spin_lock_irqsave(&t->task_state_lock, flags1);
1603
1604 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1605 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1606 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1607 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1608 (void)pm8001_abort_task(t);
1609 break; /* Task got completed by another */
1610 }
1611
1612 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1613
1614 /* Search for a possible ccb that matches the task */
1615 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1616 ccb = &pm8001_ha->ccb_info[i];
1617 tag = ccb->ccb_tag;
1618 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1619 break;
1620 }
1621 if (!ccb) {
1622 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1623 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1624 (void)pm8001_abort_task(t);
1625 break; /* Task got freed by another */
1626 }
1627
1628 pm8001_dev = ccb->device;
1629 dev = pm8001_dev->sas_device;
1630
1631 switch (ret) {
1632 case TMF_RESP_FUNC_SUCC: /* task on lu */
1633 ccb->open_retry = 1; /* Snub completion */
1634 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1635 ret = pm8001_abort_task(t);
1636 ccb->open_retry = 0;
1637 switch (ret) {
1638 case TMF_RESP_FUNC_SUCC:
1639 case TMF_RESP_FUNC_COMPLETE:
1640 break;
1641 default: /* device misbehavior */
1642 ret = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08001643 pm8001_dbg(pm8001_ha, IO, "...Reset phy\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001644 pm8001_I_T_nexus_reset(dev);
1645 break;
1646 }
1647 break;
1648
1649 case TMF_RESP_FUNC_COMPLETE: /* task not on lu */
1650 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1651 /* Do we need to abort the task locally? */
1652 break;
1653
1654 default: /* device misbehavior */
1655 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1656 ret = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08001657 pm8001_dbg(pm8001_ha, IO, "...Reset phy\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001658 pm8001_I_T_nexus_reset(dev);
1659 }
1660
1661 if (ret == TMF_RESP_FUNC_FAILED)
1662 t = NULL;
1663 pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev);
Joe Perches1b5d2792020-11-20 15:16:09 -08001664 pm8001_dbg(pm8001_ha, IO, "...Complete\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05001665 } break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001666 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
jack wangdbf9bfe2009-10-14 16:19:21 +08001667 dev = pm8001_dev->sas_device;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301668 pm8001_I_T_nexus_event_handler(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001669 break;
1670 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
jack wangdbf9bfe2009-10-14 16:19:21 +08001671 dev = pm8001_dev->sas_device;
1672 pm8001_I_T_nexus_reset(dev);
1673 break;
1674 case IO_DS_IN_ERROR:
jack wangdbf9bfe2009-10-14 16:19:21 +08001675 dev = pm8001_dev->sas_device;
1676 pm8001_I_T_nexus_reset(dev);
1677 break;
1678 case IO_DS_NON_OPERATIONAL:
jack wangdbf9bfe2009-10-14 16:19:21 +08001679 dev = pm8001_dev->sas_device;
1680 pm8001_I_T_nexus_reset(dev);
1681 break;
Ruksar Devadi4f5deeb2021-04-15 16:03:50 +05301682 case IO_FATAL_ERROR:
1683 {
1684 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1685 struct pm8001_ccb_info *ccb;
1686 struct task_status_struct *ts;
1687 struct sas_task *task;
1688 int i;
1689 u32 tag, device_id;
1690
1691 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1692 ccb = &pm8001_ha->ccb_info[i];
1693 task = ccb->task;
1694 ts = &task->task_status;
1695 tag = ccb->ccb_tag;
1696 /* check if tag is NULL */
1697 if (!tag) {
1698 pm8001_dbg(pm8001_ha, FAIL,
1699 "tag Null\n");
1700 continue;
1701 }
1702 if (task != NULL) {
1703 dev = task->dev;
1704 if (!dev) {
1705 pm8001_dbg(pm8001_ha, FAIL,
1706 "dev is NULL\n");
1707 continue;
1708 }
1709 /*complete sas task and update to top layer */
1710 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
1711 ts->resp = SAS_TASK_COMPLETE;
1712 task->task_done(task);
1713 } else if (tag != 0xFFFFFFFF) {
1714 /* complete the internal commands/non-sas task */
1715 pm8001_dev = ccb->device;
1716 if (pm8001_dev->dcompletion) {
1717 complete(pm8001_dev->dcompletion);
1718 pm8001_dev->dcompletion = NULL;
1719 }
1720 complete(pm8001_ha->nvmd_completion);
1721 pm8001_tag_free(pm8001_ha, tag);
1722 }
1723 }
1724 /* Deregister all the device ids */
1725 for (i = 0; i < PM8001_MAX_DEVICES; i++) {
1726 pm8001_dev = &pm8001_ha->devices[i];
1727 device_id = pm8001_dev->device_id;
1728 if (device_id) {
1729 PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id);
1730 pm8001_free_dev(pm8001_dev);
1731 }
1732 }
1733 } break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001734 }
Tejun Heo429305e2011-01-24 14:57:29 +01001735 kfree(pw);
jack wangdbf9bfe2009-10-14 16:19:21 +08001736}
1737
Sakthivel Kf74cf272013-02-27 20:27:43 +05301738int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
jack wangdbf9bfe2009-10-14 16:19:21 +08001739 int handler)
1740{
Tejun Heo429305e2011-01-24 14:57:29 +01001741 struct pm8001_work *pw;
jack wangdbf9bfe2009-10-14 16:19:21 +08001742 int ret = 0;
1743
Tejun Heo429305e2011-01-24 14:57:29 +01001744 pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
1745 if (pw) {
1746 pw->pm8001_ha = pm8001_ha;
1747 pw->data = data;
1748 pw->handler = handler;
1749 INIT_WORK(&pw->work, pm8001_work_fn);
1750 queue_work(pm8001_wq, &pw->work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001751 } else
1752 ret = -ENOMEM;
1753
1754 return ret;
1755}
1756
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301757static void pm8001_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1758 struct pm8001_device *pm8001_ha_dev)
1759{
1760 int res;
1761 u32 ccb_tag;
1762 struct pm8001_ccb_info *ccb;
1763 struct sas_task *task = NULL;
1764 struct task_abort_req task_abort;
1765 struct inbound_queue_table *circularQ;
1766 u32 opc = OPC_INB_SATA_ABORT;
1767 int ret;
1768
1769 if (!pm8001_ha_dev) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001770 pm8001_dbg(pm8001_ha, FAIL, "dev is null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301771 return;
1772 }
1773
1774 task = sas_alloc_slow_task(GFP_ATOMIC);
1775
1776 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001777 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301778 return;
1779 }
1780
1781 task->task_done = pm8001_task_done;
1782
1783 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1784 if (res)
1785 return;
1786
1787 ccb = &pm8001_ha->ccb_info[ccb_tag];
1788 ccb->device = pm8001_ha_dev;
1789 ccb->ccb_tag = ccb_tag;
1790 ccb->task = task;
1791
1792 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1793
1794 memset(&task_abort, 0, sizeof(task_abort));
1795 task_abort.abort_all = cpu_to_le32(1);
1796 task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1797 task_abort.tag = cpu_to_le32(ccb_tag);
1798
peter chang91a43fa2019-11-14 15:39:05 +05301799 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
1800 sizeof(task_abort), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301801 if (ret)
1802 pm8001_tag_free(pm8001_ha, ccb_tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301803
1804}
1805
1806static void pm8001_send_read_log(struct pm8001_hba_info *pm8001_ha,
1807 struct pm8001_device *pm8001_ha_dev)
1808{
1809 struct sata_start_req sata_cmd;
1810 int res;
1811 u32 ccb_tag;
1812 struct pm8001_ccb_info *ccb;
1813 struct sas_task *task = NULL;
1814 struct host_to_dev_fis fis;
1815 struct domain_device *dev;
1816 struct inbound_queue_table *circularQ;
1817 u32 opc = OPC_INB_SATA_HOST_OPSTART;
1818
1819 task = sas_alloc_slow_task(GFP_ATOMIC);
1820
1821 if (!task) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001822 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301823 return;
1824 }
1825 task->task_done = pm8001_task_done;
1826
1827 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1828 if (res) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301829 sas_free_task(task);
Joe Perches1b5d2792020-11-20 15:16:09 -08001830 pm8001_dbg(pm8001_ha, FAIL, "cannot allocate tag !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301831 return;
1832 }
1833
1834 /* allocate domain device by ourselves as libsas
1835 * is not going to provide any
1836 */
1837 dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1838 if (!dev) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301839 sas_free_task(task);
1840 pm8001_tag_free(pm8001_ha, ccb_tag);
Joe Perches1b5d2792020-11-20 15:16:09 -08001841 pm8001_dbg(pm8001_ha, FAIL,
1842 "Domain device cannot be allocated\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301843 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301844 }
Tomas Henzl5533abc2014-07-09 17:20:49 +05301845 task->dev = dev;
1846 task->dev->lldd_dev = pm8001_ha_dev;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301847
1848 ccb = &pm8001_ha->ccb_info[ccb_tag];
1849 ccb->device = pm8001_ha_dev;
1850 ccb->ccb_tag = ccb_tag;
1851 ccb->task = task;
1852 pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1853 pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1854
1855 memset(&sata_cmd, 0, sizeof(sata_cmd));
1856 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1857
1858 /* construct read log FIS */
1859 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1860 fis.fis_type = 0x27;
1861 fis.flags = 0x80;
1862 fis.command = ATA_CMD_READ_LOG_EXT;
1863 fis.lbal = 0x10;
1864 fis.sector_count = 0x1;
1865
1866 sata_cmd.tag = cpu_to_le32(ccb_tag);
1867 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1868 sata_cmd.ncqtag_atap_dir_m |= ((0x1 << 7) | (0x5 << 9));
1869 memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1870
peter chang91a43fa2019-11-14 15:39:05 +05301871 res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
1872 sizeof(sata_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301873 if (res) {
1874 sas_free_task(task);
1875 pm8001_tag_free(pm8001_ha, ccb_tag);
1876 kfree(dev);
1877 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301878}
1879
jack wangdbf9bfe2009-10-14 16:19:21 +08001880/**
1881 * mpi_ssp_completion- process the event that FW response to the SSP request.
1882 * @pm8001_ha: our hba card information
1883 * @piomb: the message contents of this outbound message.
1884 *
1885 * When FW has completed a ssp request for example a IO request, after it has
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001886 * filled the SG data with the data, it will trigger this event representing
1887 * that he has finished the job; please check the corresponding buffer.
jack wangdbf9bfe2009-10-14 16:19:21 +08001888 * So we will tell the caller who maybe waiting the result to tell upper layer
1889 * that the task has been finished.
1890 */
jack_wang72d0baa2009-11-05 22:33:35 +08001891static void
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08001892mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08001893{
1894 struct sas_task *t;
1895 struct pm8001_ccb_info *ccb;
1896 unsigned long flags;
1897 u32 status;
1898 u32 param;
1899 u32 tag;
1900 struct ssp_completion_resp *psspPayload;
1901 struct task_status_struct *ts;
1902 struct ssp_response_iu *iu;
1903 struct pm8001_device *pm8001_dev;
1904 psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1905 status = le32_to_cpu(psspPayload->status);
1906 tag = le32_to_cpu(psspPayload->tag);
1907 ccb = &pm8001_ha->ccb_info[tag];
Mark Salyzyn5954d732012-01-17 11:52:24 -05001908 if ((status == IO_ABORTED) && ccb->open_retry) {
1909 /* Being completed by another */
1910 ccb->open_retry = 0;
1911 return;
1912 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001913 pm8001_dev = ccb->device;
1914 param = le32_to_cpu(psspPayload->param);
1915
jack wangdbf9bfe2009-10-14 16:19:21 +08001916 t = ccb->task;
1917
jack_wang72d0baa2009-11-05 22:33:35 +08001918 if (status && status != IO_UNDERFLOW)
Joe Perches1b5d2792020-11-20 15:16:09 -08001919 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08001920 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08001921 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08001922 ts = &t->task_status;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301923 /* Print sas address of IO failed device */
1924 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1925 (status != IO_UNDERFLOW))
Joe Perches1b5d2792020-11-20 15:16:09 -08001926 pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n",
1927 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301928
peter chang73706722019-11-14 15:39:02 +05301929 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08001930 pm8001_dbg(pm8001_ha, IOERR,
1931 "status:0x%x, tag:0x%x, task:0x%p\n",
1932 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05301933
jack wangdbf9bfe2009-10-14 16:19:21 +08001934 switch (status) {
1935 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08001936 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS,param = %d\n",
1937 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08001938 if (param == 0) {
1939 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07001940 ts->stat = SAS_SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08001941 } else {
1942 ts->resp = SAS_TASK_COMPLETE;
1943 ts->stat = SAS_PROTO_RESPONSE;
1944 ts->residual = param;
1945 iu = &psspPayload->ssp_resp_iu;
1946 sas_ssp_task_response(pm8001_ha->dev, t, iu);
1947 }
1948 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301949 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001950 break;
1951 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001952 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001953 ts->resp = SAS_TASK_COMPLETE;
1954 ts->stat = SAS_ABORTED_TASK;
1955 break;
1956 case IO_UNDERFLOW:
1957 /* SSP Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08001958 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW,param = %d\n",
1959 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08001960 ts->resp = SAS_TASK_COMPLETE;
1961 ts->stat = SAS_DATA_UNDERRUN;
1962 ts->residual = param;
1963 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301964 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001965 break;
1966 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08001967 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001968 ts->resp = SAS_TASK_UNDELIVERED;
1969 ts->stat = SAS_PHY_DOWN;
1970 break;
1971 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001972 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001973 ts->resp = SAS_TASK_COMPLETE;
1974 ts->stat = SAS_OPEN_REJECT;
Mark Salyzyn5954d732012-01-17 11:52:24 -05001975 /* Force the midlayer to retry */
1976 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001977 break;
1978 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08001979 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\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_RSVD_RETRY;
1983 break;
1984 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08001985 pm8001_dbg(pm8001_ha, IO,
1986 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\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_EPROTO;
1990 break;
1991 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08001992 pm8001_dbg(pm8001_ha, IO,
1993 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001994 ts->resp = SAS_TASK_COMPLETE;
1995 ts->stat = SAS_OPEN_REJECT;
1996 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
1997 break;
1998 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08001999 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002000 ts->resp = SAS_TASK_COMPLETE;
2001 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002002 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002003 break;
2004 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002005 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002006 ts->resp = SAS_TASK_COMPLETE;
2007 ts->stat = SAS_OPEN_REJECT;
2008 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2009 if (!t->uldd_task)
2010 pm8001_handle_event(pm8001_ha,
2011 pm8001_dev,
2012 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2013 break;
2014 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002015 pm8001_dbg(pm8001_ha, IO,
2016 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002017 ts->resp = SAS_TASK_COMPLETE;
2018 ts->stat = SAS_OPEN_REJECT;
2019 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2020 break;
2021 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002022 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002023 ts->resp = SAS_TASK_COMPLETE;
2024 ts->stat = SAS_OPEN_REJECT;
2025 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2026 break;
2027 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002028 pm8001_dbg(pm8001_ha, IO,
2029 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002030 ts->resp = SAS_TASK_UNDELIVERED;
2031 ts->stat = SAS_OPEN_REJECT;
2032 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2033 break;
2034 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002035 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002036 ts->resp = SAS_TASK_COMPLETE;
2037 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002038 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002039 break;
2040 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002041 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002042 ts->resp = SAS_TASK_COMPLETE;
2043 ts->stat = SAS_NAK_R_ERR;
2044 break;
2045 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002046 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002047 ts->resp = SAS_TASK_COMPLETE;
2048 ts->stat = SAS_OPEN_REJECT;
2049 break;
2050 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002051 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002052 ts->resp = SAS_TASK_COMPLETE;
2053 ts->stat = SAS_OPEN_REJECT;
2054 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2055 break;
2056 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002057 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002058 ts->resp = SAS_TASK_COMPLETE;
2059 ts->stat = SAS_OPEN_REJECT;
2060 break;
2061 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002062 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002063 ts->resp = SAS_TASK_COMPLETE;
2064 ts->stat = SAS_OPEN_REJECT;
2065 break;
2066 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002067 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002068 ts->resp = SAS_TASK_COMPLETE;
2069 ts->stat = SAS_OPEN_REJECT;
2070 if (!t->uldd_task)
2071 pm8001_handle_event(pm8001_ha,
2072 pm8001_dev,
2073 IO_DS_NON_OPERATIONAL);
2074 break;
2075 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002076 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002077 ts->resp = SAS_TASK_COMPLETE;
2078 ts->stat = SAS_OPEN_REJECT;
2079 break;
2080 case IO_TM_TAG_NOT_FOUND:
Joe Perches1b5d2792020-11-20 15:16:09 -08002081 pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002082 ts->resp = SAS_TASK_COMPLETE;
2083 ts->stat = SAS_OPEN_REJECT;
2084 break;
2085 case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002086 pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002087 ts->resp = SAS_TASK_COMPLETE;
2088 ts->stat = SAS_OPEN_REJECT;
2089 break;
2090 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002091 pm8001_dbg(pm8001_ha, IO,
2092 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002093 ts->resp = SAS_TASK_COMPLETE;
2094 ts->stat = SAS_OPEN_REJECT;
2095 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07002096 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002097 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002098 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002099 /* not allowed case. Therefore, return failed status */
2100 ts->resp = SAS_TASK_COMPLETE;
2101 ts->stat = SAS_OPEN_REJECT;
2102 break;
2103 }
Joe Perches1b5d2792020-11-20 15:16:09 -08002104 pm8001_dbg(pm8001_ha, IO, "scsi_status = %x\n",
2105 psspPayload->ssp_resp_iu.status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002106 spin_lock_irqsave(&t->task_state_lock, flags);
2107 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2108 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2109 t->task_state_flags |= SAS_TASK_STATE_DONE;
2110 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2111 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002112 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",
2113 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002114 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2115 } else {
2116 spin_unlock_irqrestore(&t->task_state_lock, flags);
2117 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2118 mb();/* in order to force CPU ordering */
2119 t->task_done(t);
2120 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002121}
2122
2123/*See the comments for mpi_ssp_completion */
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002124static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002125{
2126 struct sas_task *t;
2127 unsigned long flags;
2128 struct task_status_struct *ts;
2129 struct pm8001_ccb_info *ccb;
2130 struct pm8001_device *pm8001_dev;
2131 struct ssp_event_resp *psspPayload =
2132 (struct ssp_event_resp *)(piomb + 4);
2133 u32 event = le32_to_cpu(psspPayload->event);
2134 u32 tag = le32_to_cpu(psspPayload->tag);
2135 u32 port_id = le32_to_cpu(psspPayload->port_id);
2136 u32 dev_id = le32_to_cpu(psspPayload->device_id);
2137
2138 ccb = &pm8001_ha->ccb_info[tag];
2139 t = ccb->task;
2140 pm8001_dev = ccb->device;
2141 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002142 pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002143 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002144 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002145 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002146 pm8001_dbg(pm8001_ha, DEVIO, "port_id = %x,device_id = %x\n",
2147 port_id, dev_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08002148 switch (event) {
2149 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002150 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002151 ts->resp = SAS_TASK_COMPLETE;
2152 ts->stat = SAS_DATA_OVERRUN;
2153 ts->residual = 0;
2154 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302155 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002156 break;
2157 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002158 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05002159 pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2160 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002161 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002162 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002163 ts->resp = SAS_TASK_COMPLETE;
2164 ts->stat = SAS_OPEN_REJECT;
2165 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2166 break;
2167 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002168 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\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_EPROTO;
2172 break;
2173 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002174 pm8001_dbg(pm8001_ha, IO,
2175 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002176 ts->resp = SAS_TASK_COMPLETE;
2177 ts->stat = SAS_OPEN_REJECT;
2178 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2179 break;
2180 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002181 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002182 ts->resp = SAS_TASK_COMPLETE;
2183 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002184 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002185 break;
2186 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002187 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002188 ts->resp = SAS_TASK_COMPLETE;
2189 ts->stat = SAS_OPEN_REJECT;
2190 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2191 if (!t->uldd_task)
2192 pm8001_handle_event(pm8001_ha,
2193 pm8001_dev,
2194 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2195 break;
2196 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002197 pm8001_dbg(pm8001_ha, IO,
2198 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002199 ts->resp = SAS_TASK_COMPLETE;
2200 ts->stat = SAS_OPEN_REJECT;
2201 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2202 break;
2203 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002204 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\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_CONN_RATE;
2208 break;
2209 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002210 pm8001_dbg(pm8001_ha, IO,
2211 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002212 ts->resp = SAS_TASK_COMPLETE;
2213 ts->stat = SAS_OPEN_REJECT;
2214 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2215 break;
2216 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002217 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002218 ts->resp = SAS_TASK_COMPLETE;
2219 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002220 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002221 break;
2222 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002223 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002224 ts->resp = SAS_TASK_COMPLETE;
2225 ts->stat = SAS_NAK_R_ERR;
2226 break;
2227 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002228 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
Mark Salyzyn5954d732012-01-17 11:52:24 -05002229 pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2230 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002231 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002232 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002233 ts->resp = SAS_TASK_COMPLETE;
2234 ts->stat = SAS_DATA_OVERRUN;
2235 break;
2236 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002237 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002238 ts->resp = SAS_TASK_COMPLETE;
2239 ts->stat = SAS_DATA_OVERRUN;
2240 break;
2241 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002242 pm8001_dbg(pm8001_ha, IO,
2243 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002244 ts->resp = SAS_TASK_COMPLETE;
2245 ts->stat = SAS_DATA_OVERRUN;
2246 break;
2247 case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002248 pm8001_dbg(pm8001_ha, IO,
2249 "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002250 ts->resp = SAS_TASK_COMPLETE;
2251 ts->stat = SAS_DATA_OVERRUN;
2252 break;
2253 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002254 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002255 ts->resp = SAS_TASK_COMPLETE;
2256 ts->stat = SAS_DATA_OVERRUN;
2257 break;
2258 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002259 pm8001_dbg(pm8001_ha, IO,
2260 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002261 ts->resp = SAS_TASK_COMPLETE;
2262 ts->stat = SAS_DATA_OVERRUN;
2263 break;
2264 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002265 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
jack_wang72d0baa2009-11-05 22:33:35 +08002266 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002267 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002268 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002269 /* not allowed case. Therefore, return failed status */
2270 ts->resp = SAS_TASK_COMPLETE;
2271 ts->stat = SAS_DATA_OVERRUN;
2272 break;
2273 }
2274 spin_lock_irqsave(&t->task_state_lock, flags);
2275 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2276 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2277 t->task_state_flags |= SAS_TASK_STATE_DONE;
2278 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2279 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002280 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",
2281 t, event, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002282 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2283 } else {
2284 spin_unlock_irqrestore(&t->task_state_lock, flags);
2285 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2286 mb();/* in order to force CPU ordering */
2287 t->task_done(t);
2288 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002289}
2290
2291/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002292static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002293mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2294{
2295 struct sas_task *t;
2296 struct pm8001_ccb_info *ccb;
jack wangdbf9bfe2009-10-14 16:19:21 +08002297 u32 param;
2298 u32 status;
2299 u32 tag;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302300 int i, j;
2301 u8 sata_addr_low[4];
2302 u32 temp_sata_addr_low;
2303 u8 sata_addr_hi[4];
2304 u32 temp_sata_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +08002305 struct sata_completion_resp *psataPayload;
2306 struct task_status_struct *ts;
2307 struct ata_task_resp *resp ;
2308 u32 *sata_resp;
2309 struct pm8001_device *pm8001_dev;
Santosh Nayakb08c1852012-03-09 13:43:38 +05302310 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002311
2312 psataPayload = (struct sata_completion_resp *)(piomb + 4);
2313 status = le32_to_cpu(psataPayload->status);
Igor Pylypiv60de1a62021-11-01 16:28:23 -07002314 param = le32_to_cpu(psataPayload->param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002315 tag = le32_to_cpu(psataPayload->tag);
2316
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302317 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002318 pm8001_dbg(pm8001_ha, FAIL, "tag null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302319 return;
2320 }
Igor Pylypiv60de1a62021-11-01 16:28:23 -07002321
jack wangdbf9bfe2009-10-14 16:19:21 +08002322 ccb = &pm8001_ha->ccb_info[tag];
Igor Pylypiv60de1a62021-11-01 16:28:23 -07002323 t = ccb->task;
2324 pm8001_dev = ccb->device;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302325
2326 if (t) {
2327 if (t->dev && (t->dev->lldd_dev))
2328 pm8001_dev = t->dev->lldd_dev;
2329 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002330 pm8001_dbg(pm8001_ha, FAIL, "task null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302331 return;
2332 }
2333
2334 if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2335 && unlikely(!t || !t->lldd_task || !t->dev)) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002336 pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302337 return;
2338 }
2339
2340 ts = &t->task_status;
peter chang73706722019-11-14 15:39:02 +05302341
2342 if (status)
Joe Perches1b5d2792020-11-20 15:16:09 -08002343 pm8001_dbg(pm8001_ha, IOERR,
2344 "status:0x%x, tag:0x%x, task::0x%p\n",
2345 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302346
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302347 /* Print sas address of IO failed device */
2348 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2349 (status != IO_UNDERFLOW)) {
2350 if (!((t->dev->parent) &&
John Garry924a3542019-06-10 20:41:41 +08002351 (dev_is_expander(t->dev->parent->dev_type)))) {
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002352 for (i = 0, j = 4; j <= 7 && i <= 3; i++, j++)
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302353 sata_addr_low[i] = pm8001_ha->sas_addr[j];
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002354 for (i = 0, j = 0; j <= 3 && i <= 3; i++, j++)
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302355 sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2356 memcpy(&temp_sata_addr_low, sata_addr_low,
2357 sizeof(sata_addr_low));
2358 memcpy(&temp_sata_addr_hi, sata_addr_hi,
2359 sizeof(sata_addr_hi));
2360 temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2361 |((temp_sata_addr_hi << 8) &
2362 0xff0000) |
2363 ((temp_sata_addr_hi >> 8)
2364 & 0xff00) |
2365 ((temp_sata_addr_hi << 24) &
2366 0xff000000));
2367 temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2368 & 0xff) |
2369 ((temp_sata_addr_low << 8)
2370 & 0xff0000) |
2371 ((temp_sata_addr_low >> 8)
2372 & 0xff00) |
2373 ((temp_sata_addr_low << 24)
2374 & 0xff000000)) +
2375 pm8001_dev->attached_phy +
2376 0x10);
Joe Perches1b5d2792020-11-20 15:16:09 -08002377 pm8001_dbg(pm8001_ha, FAIL,
2378 "SAS Address of IO Failure Drive:%08x%08x\n",
2379 temp_sata_addr_hi,
2380 temp_sata_addr_low);
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302381 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08002382 pm8001_dbg(pm8001_ha, FAIL,
2383 "SAS Address of IO Failure Drive:%016llx\n",
2384 SAS_ADDR(t->dev->sas_addr));
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302385 }
2386 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002387 switch (status) {
2388 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002389 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002390 if (param == 0) {
2391 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002392 ts->stat = SAS_SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302393 /* check if response is for SEND READ LOG */
2394 if (pm8001_dev &&
2395 (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2396 /* set new bit for abort_all */
2397 pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2398 /* clear bit for read log */
2399 pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2400 pm8001_send_abort_all(pm8001_ha, pm8001_dev);
2401 /* Free the tag */
2402 pm8001_tag_free(pm8001_ha, tag);
2403 sas_free_task(t);
2404 return;
2405 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002406 } else {
2407 u8 len;
2408 ts->resp = SAS_TASK_COMPLETE;
2409 ts->stat = SAS_PROTO_RESPONSE;
2410 ts->residual = param;
Joe Perches1b5d2792020-11-20 15:16:09 -08002411 pm8001_dbg(pm8001_ha, IO,
2412 "SAS_PROTO_RESPONSE len = %d\n",
2413 param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002414 sata_resp = &psataPayload->sata_resp[0];
2415 resp = (struct ata_task_resp *)ts->buf;
2416 if (t->ata_task.dma_xfer == 0 &&
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02002417 t->data_dir == DMA_FROM_DEVICE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08002418 len = sizeof(struct pio_setup_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002419 pm8001_dbg(pm8001_ha, IO,
2420 "PIO read len = %d\n", len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002421 } else if (t->ata_task.use_ncq) {
2422 len = sizeof(struct set_dev_bits_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002423 pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n",
2424 len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002425 } else {
2426 len = sizeof(struct dev_to_host_fis);
Joe Perches1b5d2792020-11-20 15:16:09 -08002427 pm8001_dbg(pm8001_ha, IO, "other len = %d\n",
2428 len);
jack wangdbf9bfe2009-10-14 16:19:21 +08002429 }
2430 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2431 resp->frame_len = len;
2432 memcpy(&resp->ending_fis[0], sata_resp, len);
2433 ts->buf_valid_size = sizeof(*resp);
2434 } else
Joe Perches1b5d2792020-11-20 15:16:09 -08002435 pm8001_dbg(pm8001_ha, IO,
2436 "response too large\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002437 }
2438 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302439 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002440 break;
2441 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002442 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002443 ts->resp = SAS_TASK_COMPLETE;
2444 ts->stat = SAS_ABORTED_TASK;
2445 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302446 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002447 break;
2448 /* following cases are to do cases */
2449 case IO_UNDERFLOW:
2450 /* SATA Completion with error */
Joe Perches1b5d2792020-11-20 15:16:09 -08002451 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param);
jack wangdbf9bfe2009-10-14 16:19:21 +08002452 ts->resp = SAS_TASK_COMPLETE;
2453 ts->stat = SAS_DATA_UNDERRUN;
2454 ts->residual = param;
2455 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302456 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002457 break;
2458 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002459 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002460 ts->resp = SAS_TASK_UNDELIVERED;
2461 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302462 if (pm8001_dev)
2463 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002464 break;
2465 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002466 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002467 ts->resp = SAS_TASK_COMPLETE;
2468 ts->stat = SAS_INTERRUPTED;
Viswas G4a2efd42020-11-02 22:25:26 +05302469 if (pm8001_dev)
2470 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002471 break;
2472 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002473 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002474 ts->resp = SAS_TASK_COMPLETE;
2475 ts->stat = SAS_OPEN_REJECT;
2476 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302477 if (pm8001_dev)
2478 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002479 break;
2480 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002481 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002482 ts->resp = SAS_TASK_COMPLETE;
2483 ts->stat = SAS_OPEN_REJECT;
2484 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302485 if (pm8001_dev)
2486 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002487 break;
2488 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002489 pm8001_dbg(pm8001_ha, IO,
2490 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002491 ts->resp = SAS_TASK_COMPLETE;
2492 ts->stat = SAS_OPEN_REJECT;
2493 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302494 if (pm8001_dev)
2495 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002496 break;
2497 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002498 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002499 ts->resp = SAS_TASK_COMPLETE;
2500 ts->stat = SAS_OPEN_REJECT;
2501 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
Viswas G4a2efd42020-11-02 22:25:26 +05302502 if (pm8001_dev)
2503 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002504 break;
2505 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002506 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002507 ts->resp = SAS_TASK_COMPLETE;
2508 ts->stat = SAS_DEV_NO_RESPONSE;
2509 if (!t->uldd_task) {
2510 pm8001_handle_event(pm8001_ha,
2511 pm8001_dev,
2512 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2513 ts->resp = SAS_TASK_UNDELIVERED;
2514 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302515 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002516 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002517 }
2518 break;
2519 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002520 pm8001_dbg(pm8001_ha, IO,
2521 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002522 ts->resp = SAS_TASK_UNDELIVERED;
2523 ts->stat = SAS_OPEN_REJECT;
2524 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2525 if (!t->uldd_task) {
2526 pm8001_handle_event(pm8001_ha,
2527 pm8001_dev,
2528 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2529 ts->resp = SAS_TASK_UNDELIVERED;
2530 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302531 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002532 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002533 }
2534 break;
2535 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002536 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002537 ts->resp = SAS_TASK_COMPLETE;
2538 ts->stat = SAS_OPEN_REJECT;
2539 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302540 if (pm8001_dev)
2541 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002542 break;
2543 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002544 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002545 ts->resp = SAS_TASK_COMPLETE;
2546 ts->stat = SAS_DEV_NO_RESPONSE;
2547 if (!t->uldd_task) {
2548 pm8001_handle_event(pm8001_ha,
2549 pm8001_dev,
2550 IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2551 ts->resp = SAS_TASK_UNDELIVERED;
2552 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302553 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002554 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002555 }
2556 break;
2557 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002558 pm8001_dbg(pm8001_ha, IO,
2559 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002560 ts->resp = SAS_TASK_COMPLETE;
2561 ts->stat = SAS_OPEN_REJECT;
2562 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302563 if (pm8001_dev)
2564 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002565 break;
2566 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002567 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002568 ts->resp = SAS_TASK_COMPLETE;
2569 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302570 if (pm8001_dev)
2571 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002572 break;
2573 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002574 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002575 ts->resp = SAS_TASK_COMPLETE;
2576 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302577 if (pm8001_dev)
2578 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002579 break;
2580 case IO_XFER_ERROR_DMA:
Joe Perches1b5d2792020-11-20 15:16:09 -08002581 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002582 ts->resp = SAS_TASK_COMPLETE;
2583 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05302584 if (pm8001_dev)
2585 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002586 break;
2587 case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002588 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002589 ts->resp = SAS_TASK_UNDELIVERED;
2590 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302591 if (pm8001_dev)
2592 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002593 break;
2594 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002595 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002596 ts->resp = SAS_TASK_COMPLETE;
2597 ts->stat = SAS_DATA_UNDERRUN;
Viswas G4a2efd42020-11-02 22:25:26 +05302598 if (pm8001_dev)
2599 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002600 break;
2601 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002602 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002603 ts->resp = SAS_TASK_COMPLETE;
2604 ts->stat = SAS_OPEN_TO;
Viswas G4a2efd42020-11-02 22:25:26 +05302605 if (pm8001_dev)
2606 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002607 break;
2608 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002609 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002610 ts->resp = SAS_TASK_COMPLETE;
2611 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302612 if (pm8001_dev)
2613 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002614 break;
2615 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002616 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002617 ts->resp = SAS_TASK_COMPLETE;
2618 ts->stat = SAS_DEV_NO_RESPONSE;
2619 if (!t->uldd_task) {
2620 pm8001_handle_event(pm8001_ha, pm8001_dev,
2621 IO_DS_NON_OPERATIONAL);
2622 ts->resp = SAS_TASK_UNDELIVERED;
2623 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302624 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002625 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002626 }
2627 break;
2628 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002629 pm8001_dbg(pm8001_ha, IO, " IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002630 ts->resp = SAS_TASK_COMPLETE;
2631 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302632 if (pm8001_dev)
2633 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002634 break;
2635 case IO_DS_IN_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002636 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002637 ts->resp = SAS_TASK_COMPLETE;
2638 ts->stat = SAS_DEV_NO_RESPONSE;
2639 if (!t->uldd_task) {
2640 pm8001_handle_event(pm8001_ha, pm8001_dev,
2641 IO_DS_IN_ERROR);
2642 ts->resp = SAS_TASK_UNDELIVERED;
2643 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302644 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002645 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002646 }
2647 break;
2648 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002649 pm8001_dbg(pm8001_ha, IO,
2650 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002651 ts->resp = SAS_TASK_COMPLETE;
2652 ts->stat = SAS_OPEN_REJECT;
2653 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302654 if (pm8001_dev)
2655 atomic_dec(&pm8001_dev->running_req);
Johannes Thumshirn50acde82015-08-17 15:52:32 +02002656 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002657 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002658 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08002659 /* not allowed case. Therefore, return failed status */
2660 ts->resp = SAS_TASK_COMPLETE;
2661 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302662 if (pm8001_dev)
2663 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002664 break;
2665 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302666 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002667 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2668 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2669 t->task_state_flags |= SAS_TASK_STATE_DONE;
2670 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302671 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08002672 pm8001_dbg(pm8001_ha, FAIL,
2673 "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n",
2674 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08002675 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302676 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302677 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302678 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002679 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002680}
2681
2682/*See the comments for mpi_ssp_completion */
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08002683static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002684{
2685 struct sas_task *t;
jack wangdbf9bfe2009-10-14 16:19:21 +08002686 struct task_status_struct *ts;
2687 struct pm8001_ccb_info *ccb;
2688 struct pm8001_device *pm8001_dev;
2689 struct sata_event_resp *psataPayload =
2690 (struct sata_event_resp *)(piomb + 4);
2691 u32 event = le32_to_cpu(psataPayload->event);
2692 u32 tag = le32_to_cpu(psataPayload->tag);
2693 u32 port_id = le32_to_cpu(psataPayload->port_id);
2694 u32 dev_id = le32_to_cpu(psataPayload->device_id);
2695
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302696 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002697 pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302698
2699 /* Check if this is NCQ error */
2700 if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2701 /* find device using device id */
2702 pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2703 /* send read log extension */
2704 if (pm8001_dev)
2705 pm8001_send_read_log(pm8001_ha, pm8001_dev);
2706 return;
2707 }
2708
2709 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002710 t = ccb->task;
2711 pm8001_dev = ccb->device;
2712 if (event)
Joe Perches1b5d2792020-11-20 15:16:09 -08002713 pm8001_dbg(pm8001_ha, FAIL, "sata IO status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002714 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002715 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002716 ts = &t->task_status;
Joe Perches1b5d2792020-11-20 15:16:09 -08002717 pm8001_dbg(pm8001_ha, DEVIO,
2718 "port_id:0x%x, device_id:0x%x, tag:0x%x, event:0x%x\n",
2719 port_id, dev_id, tag, event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002720 switch (event) {
2721 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002722 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002723 ts->resp = SAS_TASK_COMPLETE;
2724 ts->stat = SAS_DATA_OVERRUN;
2725 ts->residual = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08002726 break;
2727 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002728 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002729 ts->resp = SAS_TASK_COMPLETE;
2730 ts->stat = SAS_INTERRUPTED;
2731 break;
2732 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002733 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002734 ts->resp = SAS_TASK_COMPLETE;
2735 ts->stat = SAS_OPEN_REJECT;
2736 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2737 break;
2738 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002739 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002740 ts->resp = SAS_TASK_COMPLETE;
2741 ts->stat = SAS_OPEN_REJECT;
2742 ts->open_rej_reason = SAS_OREJ_EPROTO;
2743 break;
2744 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002745 pm8001_dbg(pm8001_ha, IO,
2746 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002747 ts->resp = SAS_TASK_COMPLETE;
2748 ts->stat = SAS_OPEN_REJECT;
2749 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2750 break;
2751 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002752 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002753 ts->resp = SAS_TASK_COMPLETE;
2754 ts->stat = SAS_OPEN_REJECT;
2755 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2756 break;
2757 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002758 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002759 ts->resp = SAS_TASK_UNDELIVERED;
2760 ts->stat = SAS_DEV_NO_RESPONSE;
2761 if (!t->uldd_task) {
2762 pm8001_handle_event(pm8001_ha,
2763 pm8001_dev,
2764 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2765 ts->resp = SAS_TASK_COMPLETE;
2766 ts->stat = SAS_QUEUE_FULL;
jack_wang72d0baa2009-11-05 22:33:35 +08002767 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002768 }
2769 break;
2770 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002771 pm8001_dbg(pm8001_ha, IO,
2772 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002773 ts->resp = SAS_TASK_UNDELIVERED;
2774 ts->stat = SAS_OPEN_REJECT;
2775 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2776 break;
2777 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002778 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002779 ts->resp = SAS_TASK_COMPLETE;
2780 ts->stat = SAS_OPEN_REJECT;
2781 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2782 break;
2783 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002784 pm8001_dbg(pm8001_ha, IO,
2785 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002786 ts->resp = SAS_TASK_COMPLETE;
2787 ts->stat = SAS_OPEN_REJECT;
2788 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2789 break;
2790 case IO_XFER_ERROR_NAK_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002791 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002792 ts->resp = SAS_TASK_COMPLETE;
2793 ts->stat = SAS_NAK_R_ERR;
2794 break;
2795 case IO_XFER_ERROR_PEER_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002796 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002797 ts->resp = SAS_TASK_COMPLETE;
2798 ts->stat = SAS_NAK_R_ERR;
2799 break;
2800 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002801 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002802 ts->resp = SAS_TASK_COMPLETE;
2803 ts->stat = SAS_DATA_UNDERRUN;
2804 break;
2805 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002806 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002807 ts->resp = SAS_TASK_COMPLETE;
2808 ts->stat = SAS_OPEN_TO;
2809 break;
2810 case IO_XFER_ERROR_UNEXPECTED_PHASE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002811 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002812 ts->resp = SAS_TASK_COMPLETE;
2813 ts->stat = SAS_OPEN_TO;
2814 break;
2815 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002816 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002817 ts->resp = SAS_TASK_COMPLETE;
2818 ts->stat = SAS_OPEN_TO;
2819 break;
2820 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002821 pm8001_dbg(pm8001_ha, IO,
2822 "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002823 ts->resp = SAS_TASK_COMPLETE;
2824 ts->stat = SAS_OPEN_TO;
2825 break;
2826 case IO_XFER_ERROR_OFFSET_MISMATCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08002827 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002828 ts->resp = SAS_TASK_COMPLETE;
2829 ts->stat = SAS_OPEN_TO;
2830 break;
2831 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
Joe Perches1b5d2792020-11-20 15:16:09 -08002832 pm8001_dbg(pm8001_ha, IO,
2833 "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002834 ts->resp = SAS_TASK_COMPLETE;
2835 ts->stat = SAS_OPEN_TO;
2836 break;
2837 case IO_XFER_CMD_FRAME_ISSUED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002838 pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002839 break;
2840 case IO_XFER_PIO_SETUP_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08002841 pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002842 ts->resp = SAS_TASK_COMPLETE;
2843 ts->stat = SAS_OPEN_TO;
2844 break;
2845 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08002846 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event);
jack wangdbf9bfe2009-10-14 16:19:21 +08002847 /* not allowed case. Therefore, return failed status */
2848 ts->resp = SAS_TASK_COMPLETE;
2849 ts->stat = SAS_OPEN_TO;
2850 break;
2851 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002852}
2853
2854/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002855static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002856mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2857{
jack wangdbf9bfe2009-10-14 16:19:21 +08002858 struct sas_task *t;
2859 struct pm8001_ccb_info *ccb;
2860 unsigned long flags;
2861 u32 status;
2862 u32 tag;
2863 struct smp_completion_resp *psmpPayload;
2864 struct task_status_struct *ts;
2865 struct pm8001_device *pm8001_dev;
2866
2867 psmpPayload = (struct smp_completion_resp *)(piomb + 4);
2868 status = le32_to_cpu(psmpPayload->status);
2869 tag = le32_to_cpu(psmpPayload->tag);
2870
2871 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002872 t = ccb->task;
2873 ts = &t->task_status;
2874 pm8001_dev = ccb->device;
peter chang73706722019-11-14 15:39:02 +05302875 if (status) {
Joe Perches1b5d2792020-11-20 15:16:09 -08002876 pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status);
2877 pm8001_dbg(pm8001_ha, IOERR,
2878 "status:0x%x, tag:0x%x, task:0x%p\n",
2879 status, tag, t);
peter chang73706722019-11-14 15:39:02 +05302880 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002881 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002882 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002883
2884 switch (status) {
2885 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002886 pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002887 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002888 ts->stat = SAS_SAM_STAT_GOOD;
Colin Ian King9e2a07e2019-03-17 18:15:32 +00002889 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302890 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002891 break;
2892 case IO_ABORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002893 pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002894 ts->resp = SAS_TASK_COMPLETE;
2895 ts->stat = SAS_ABORTED_TASK;
2896 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302897 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002898 break;
2899 case IO_OVERFLOW:
Joe Perches1b5d2792020-11-20 15:16:09 -08002900 pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002901 ts->resp = SAS_TASK_COMPLETE;
2902 ts->stat = SAS_DATA_OVERRUN;
2903 ts->residual = 0;
2904 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302905 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002906 break;
2907 case IO_NO_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002908 pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002909 ts->resp = SAS_TASK_COMPLETE;
2910 ts->stat = SAS_PHY_DOWN;
2911 break;
2912 case IO_ERROR_HW_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002913 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\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_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002916 break;
2917 case IO_XFER_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002918 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002919 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002920 ts->stat = SAS_SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002921 break;
2922 case IO_XFER_ERROR_PHY_NOT_READY:
Joe Perches1b5d2792020-11-20 15:16:09 -08002923 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002924 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07002925 ts->stat = SAS_SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002926 break;
2927 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002928 pm8001_dbg(pm8001_ha, IO,
2929 "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002930 ts->resp = SAS_TASK_COMPLETE;
2931 ts->stat = SAS_OPEN_REJECT;
2932 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2933 break;
2934 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002935 pm8001_dbg(pm8001_ha, IO,
2936 "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002937 ts->resp = SAS_TASK_COMPLETE;
2938 ts->stat = SAS_OPEN_REJECT;
2939 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2940 break;
2941 case IO_OPEN_CNX_ERROR_BREAK:
Joe Perches1b5d2792020-11-20 15:16:09 -08002942 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002943 ts->resp = SAS_TASK_COMPLETE;
2944 ts->stat = SAS_OPEN_REJECT;
2945 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2946 break;
2947 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
Joe Perches1b5d2792020-11-20 15:16:09 -08002948 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002949 ts->resp = SAS_TASK_COMPLETE;
2950 ts->stat = SAS_OPEN_REJECT;
2951 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2952 pm8001_handle_event(pm8001_ha,
2953 pm8001_dev,
2954 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2955 break;
2956 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002957 pm8001_dbg(pm8001_ha, IO,
2958 "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002959 ts->resp = SAS_TASK_COMPLETE;
2960 ts->stat = SAS_OPEN_REJECT;
2961 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2962 break;
2963 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08002964 pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002965 ts->resp = SAS_TASK_COMPLETE;
2966 ts->stat = SAS_OPEN_REJECT;
2967 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2968 break;
2969 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08002970 pm8001_dbg(pm8001_ha, IO,
2971 "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002972 ts->resp = SAS_TASK_COMPLETE;
2973 ts->stat = SAS_OPEN_REJECT;
2974 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2975 break;
2976 case IO_XFER_ERROR_RX_FRAME:
Joe Perches1b5d2792020-11-20 15:16:09 -08002977 pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002978 ts->resp = SAS_TASK_COMPLETE;
2979 ts->stat = SAS_DEV_NO_RESPONSE;
2980 break;
2981 case IO_XFER_OPEN_RETRY_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08002982 pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002983 ts->resp = SAS_TASK_COMPLETE;
2984 ts->stat = SAS_OPEN_REJECT;
2985 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2986 break;
2987 case IO_ERROR_INTERNAL_SMP_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08002988 pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002989 ts->resp = SAS_TASK_COMPLETE;
2990 ts->stat = SAS_QUEUE_FULL;
2991 break;
2992 case IO_PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08002993 pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08002994 ts->resp = SAS_TASK_COMPLETE;
2995 ts->stat = SAS_OPEN_REJECT;
2996 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2997 break;
2998 case IO_DS_NON_OPERATIONAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08002999 pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003000 ts->resp = SAS_TASK_COMPLETE;
3001 ts->stat = SAS_DEV_NO_RESPONSE;
3002 break;
3003 case IO_DS_IN_RECOVERY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003004 pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003005 ts->resp = SAS_TASK_COMPLETE;
3006 ts->stat = SAS_OPEN_REJECT;
3007 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3008 break;
3009 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
Joe Perches1b5d2792020-11-20 15:16:09 -08003010 pm8001_dbg(pm8001_ha, IO,
3011 "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003012 ts->resp = SAS_TASK_COMPLETE;
3013 ts->stat = SAS_OPEN_REJECT;
3014 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3015 break;
3016 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003017 pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003018 ts->resp = SAS_TASK_COMPLETE;
3019 ts->stat = SAS_DEV_NO_RESPONSE;
3020 /* not allowed case. Therefore, return failed status */
3021 break;
3022 }
3023 spin_lock_irqsave(&t->task_state_lock, flags);
3024 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3025 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3026 t->task_state_flags |= SAS_TASK_STATE_DONE;
3027 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3028 spin_unlock_irqrestore(&t->task_state_lock, flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08003029 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",
3030 t, status, ts->resp, ts->stat);
jack wangdbf9bfe2009-10-14 16:19:21 +08003031 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3032 } else {
3033 spin_unlock_irqrestore(&t->task_state_lock, flags);
3034 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3035 mb();/* in order to force CPU ordering */
3036 t->task_done(t);
3037 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003038}
3039
Sakthivel Kf74cf272013-02-27 20:27:43 +05303040void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha,
3041 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003042{
3043 struct set_dev_state_resp *pPayload =
3044 (struct set_dev_state_resp *)(piomb + 4);
3045 u32 tag = le32_to_cpu(pPayload->tag);
3046 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3047 struct pm8001_device *pm8001_dev = ccb->device;
3048 u32 status = le32_to_cpu(pPayload->status);
3049 u32 device_id = le32_to_cpu(pPayload->device_id);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05303050 u8 pds = le32_to_cpu(pPayload->pds_nds) & PDS_BITS;
3051 u8 nds = le32_to_cpu(pPayload->pds_nds) & NDS_BITS;
Joe Perches1b5d2792020-11-20 15:16:09 -08003052 pm8001_dbg(pm8001_ha, MSG, "Set device id = 0x%x state from 0x%x to 0x%x status = 0x%x!\n",
3053 device_id, pds, nds, status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003054 complete(pm8001_dev->setds_completion);
3055 ccb->task = NULL;
3056 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303057 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003058}
3059
Sakthivel Kf74cf272013-02-27 20:27:43 +05303060void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003061{
3062 struct get_nvm_data_resp *pPayload =
3063 (struct get_nvm_data_resp *)(piomb + 4);
3064 u32 tag = le32_to_cpu(pPayload->tag);
3065 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3066 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3067 complete(pm8001_ha->nvmd_completion);
Joe Perches1b5d2792020-11-20 15:16:09 -08003068 pm8001_dbg(pm8001_ha, MSG, "Set nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003069 if ((dlen_status & NVMD_STAT) != 0) {
akshatzen5d280262021-01-09 18:08:45 +05303070 pm8001_dbg(pm8001_ha, FAIL, "Set nvm data error %x\n",
3071 dlen_status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003072 }
3073 ccb->task = NULL;
3074 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303075 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003076}
3077
Sakthivel Kf74cf272013-02-27 20:27:43 +05303078void
3079pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003080{
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303081 struct fw_control_ex *fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003082 struct get_nvm_data_resp *pPayload =
3083 (struct get_nvm_data_resp *)(piomb + 4);
3084 u32 tag = le32_to_cpu(pPayload->tag);
3085 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3086 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3087 u32 ir_tds_bn_dps_das_nvm =
3088 le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm);
3089 void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303090 fw_control_context = ccb->fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003091
Joe Perches1b5d2792020-11-20 15:16:09 -08003092 pm8001_dbg(pm8001_ha, MSG, "Get nvm data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003093 if ((dlen_status & NVMD_STAT) != 0) {
akshatzen5d280262021-01-09 18:08:45 +05303094 pm8001_dbg(pm8001_ha, FAIL, "Get nvm data error %x\n",
3095 dlen_status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003096 complete(pm8001_ha->nvmd_completion);
akshatzen5d280262021-01-09 18:08:45 +05303097 /* We should free tag during failure also, the tag is not being
3098 * freed by requesting path anywhere.
3099 */
3100 ccb->task = NULL;
3101 ccb->ccb_tag = 0xFFFFFFFF;
3102 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003103 return;
3104 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003105 if (ir_tds_bn_dps_das_nvm & IPMode) {
3106 /* indirect mode - IR bit set */
Joe Perches1b5d2792020-11-20 15:16:09 -08003107 pm8001_dbg(pm8001_ha, MSG, "Get NVMD success, IR=1\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003108 if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) {
3109 if (ir_tds_bn_dps_das_nvm == 0x80a80200) {
3110 memcpy(pm8001_ha->sas_addr,
3111 ((u8 *)virt_addr + 4),
3112 SAS_ADDR_SIZE);
Joe Perches1b5d2792020-11-20 15:16:09 -08003113 pm8001_dbg(pm8001_ha, MSG, "Get SAS address from VPD successfully!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003114 }
3115 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM)
3116 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) ||
3117 ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) {
3118 ;
3119 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP)
3120 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) {
3121 ;
3122 } else {
3123 /* Should not be happened*/
Joe Perches1b5d2792020-11-20 15:16:09 -08003124 pm8001_dbg(pm8001_ha, MSG,
3125 "(IR=1)Wrong Device type 0x%x\n",
3126 ir_tds_bn_dps_das_nvm);
jack wangdbf9bfe2009-10-14 16:19:21 +08003127 }
3128 } else /* direct mode */{
Joe Perches1b5d2792020-11-20 15:16:09 -08003129 pm8001_dbg(pm8001_ha, MSG,
3130 "Get NVMD success, IR=0, dataLen=%d\n",
3131 (dlen_status & NVMD_LEN) >> 24);
jack wangdbf9bfe2009-10-14 16:19:21 +08003132 }
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303133 /* Though fw_control_context is freed below, usrAddr still needs
3134 * to be updated as this holds the response to the request function
3135 */
3136 memcpy(fw_control_context->usrAddr,
3137 pm8001_ha->memoryMap.region[NVMD].virt_ptr,
3138 fw_control_context->len);
Tomas Henzlf3a06552014-07-07 17:19:58 +02003139 kfree(ccb->fw_control_context);
yuuzheng1f889b52020-11-02 22:25:28 +05303140 /* To avoid race condition, complete should be
3141 * called after the message is copied to
3142 * fw_control_context->usrAddr
3143 */
3144 complete(pm8001_ha->nvmd_completion);
Igor Pylypiv4084a722021-09-28 19:58:47 -07003145 pm8001_dbg(pm8001_ha, MSG, "Get nvmd data complete!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003146 ccb->task = NULL;
3147 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303148 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003149}
3150
Sakthivel Kf74cf272013-02-27 20:27:43 +05303151int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003152{
Viswas G25c6edb2017-10-18 11:39:10 +05303153 u32 tag;
jack wangdbf9bfe2009-10-14 16:19:21 +08003154 struct local_phy_ctl_resp *pPayload =
3155 (struct local_phy_ctl_resp *)(piomb + 4);
3156 u32 status = le32_to_cpu(pPayload->status);
3157 u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
3158 u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
Viswas G25c6edb2017-10-18 11:39:10 +05303159 tag = le32_to_cpu(pPayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003160 if (status != 0) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003161 pm8001_dbg(pm8001_ha, MSG,
3162 "%x phy execute %x phy op failed!\n",
3163 phy_id, phy_op);
Viswas G869ddbd2017-10-18 11:39:13 +05303164 } else {
Joe Perches1b5d2792020-11-20 15:16:09 -08003165 pm8001_dbg(pm8001_ha, MSG,
3166 "%x phy execute %x phy op success!\n",
3167 phy_id, phy_op);
Viswas G869ddbd2017-10-18 11:39:13 +05303168 pm8001_ha->phy[phy_id].reset_success = true;
3169 }
3170 if (pm8001_ha->phy[phy_id].enable_completion) {
3171 complete(pm8001_ha->phy[phy_id].enable_completion);
3172 pm8001_ha->phy[phy_id].enable_completion = NULL;
3173 }
Viswas G25c6edb2017-10-18 11:39:10 +05303174 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003175 return 0;
3176}
3177
3178/**
3179 * pm8001_bytes_dmaed - one of the interface function communication with libsas
3180 * @pm8001_ha: our hba card information
3181 * @i: which phy that received the event.
3182 *
3183 * when HBA driver received the identify done event or initiate FIS received
3184 * event(for SATA), it will invoke this function to notify the sas layer that
3185 * the sas toplogy has formed, please discover the the whole sas domain,
3186 * while receive a broadcast(change) primitive just tell the sas
3187 * layer to discover the changed domain rather than the whole domain.
3188 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303189void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i)
jack wangdbf9bfe2009-10-14 16:19:21 +08003190{
3191 struct pm8001_phy *phy = &pm8001_ha->phy[i];
3192 struct asd_sas_phy *sas_phy = &phy->sas_phy;
jack wangdbf9bfe2009-10-14 16:19:21 +08003193 if (!phy->phy_attached)
3194 return;
3195
jack wangdbf9bfe2009-10-14 16:19:21 +08003196 if (sas_phy->phy) {
3197 struct sas_phy *sphy = sas_phy->phy;
3198 sphy->negotiated_linkrate = sas_phy->linkrate;
3199 sphy->minimum_linkrate = phy->minimum_linkrate;
3200 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3201 sphy->maximum_linkrate = phy->maximum_linkrate;
3202 sphy->maximum_linkrate_hw = phy->maximum_linkrate;
3203 }
3204
3205 if (phy->phy_type & PORT_TYPE_SAS) {
3206 struct sas_identify_frame *id;
3207 id = (struct sas_identify_frame *)phy->frame_rcvd;
3208 id->dev_type = phy->identify.device_type;
3209 id->initiator_bits = SAS_PROTOCOL_ALL;
3210 id->target_bits = phy->identify.target_port_protocols;
3211 } else if (phy->phy_type & PORT_TYPE_SATA) {
3212 /*Nothing*/
3213 }
Joe Perches1b5d2792020-11-20 15:16:09 -08003214 pm8001_dbg(pm8001_ha, MSG, "phy %d byte dmaded.\n", i);
jack wangdbf9bfe2009-10-14 16:19:21 +08003215
3216 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003217 sas_notify_port_event(sas_phy, PORTE_BYTES_DMAED, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003218}
3219
3220/* Get the link rate speed */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303221void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate)
jack wangdbf9bfe2009-10-14 16:19:21 +08003222{
3223 struct sas_phy *sas_phy = phy->sas_phy.phy;
3224
3225 switch (link_rate) {
Viswas Gb093d592015-08-11 15:06:25 +05303226 case PHY_SPEED_120:
3227 phy->sas_phy.linkrate = SAS_LINK_RATE_12_0_GBPS;
3228 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_12_0_GBPS;
3229 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08003230 case PHY_SPEED_60:
3231 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
3232 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3233 break;
3234 case PHY_SPEED_30:
3235 phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
3236 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3237 break;
3238 case PHY_SPEED_15:
3239 phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
3240 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
3241 break;
3242 }
3243 sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
3244 sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS;
3245 sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3246 sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
3247 sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3248}
3249
3250/**
Lee Jones6b87e432021-03-03 14:46:19 +00003251 * pm8001_get_attached_sas_addr - extract/generate attached SAS address
jack wangdbf9bfe2009-10-14 16:19:21 +08003252 * @phy: pointer to asd_phy
3253 * @sas_addr: pointer to buffer where the SAS address is to be written
3254 *
3255 * This function extracts the SAS address from an IDENTIFY frame
3256 * received. If OOB is SATA, then a SAS address is generated from the
3257 * HA tables.
3258 *
3259 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
3260 * buffer.
3261 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303262void pm8001_get_attached_sas_addr(struct pm8001_phy *phy,
jack wangdbf9bfe2009-10-14 16:19:21 +08003263 u8 *sas_addr)
3264{
3265 if (phy->sas_phy.frame_rcvd[0] == 0x34
3266 && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
3267 struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha;
3268 /* FIS device-to-host */
3269 u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr);
3270 addr += phy->sas_phy.id;
3271 *(__be64 *)sas_addr = cpu_to_be64(addr);
3272 } else {
3273 struct sas_identify_frame *idframe =
3274 (void *) phy->sas_phy.frame_rcvd;
3275 memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
3276 }
3277}
3278
3279/**
3280 * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
3281 * @pm8001_ha: our hba card information
3282 * @Qnum: the outbound queue message number.
3283 * @SEA: source of event to ack
3284 * @port_id: port id.
3285 * @phyId: phy id.
3286 * @param0: parameter 0.
3287 * @param1: parameter 1.
3288 */
3289static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3290 u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3291{
3292 struct hw_event_ack_req payload;
3293 u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3294
3295 struct inbound_queue_table *circularQ;
3296
3297 memset((u8 *)&payload, 0, sizeof(payload));
3298 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
Santosh Nayak8270ee22012-02-26 20:14:46 +05303299 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08003300 payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3301 ((phyId & 0x0F) << 4) | (port_id & 0x0F));
3302 payload.param0 = cpu_to_le32(param0);
3303 payload.param1 = cpu_to_le32(param1);
peter chang91a43fa2019-11-14 15:39:05 +05303304 pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
3305 sizeof(payload), 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08003306}
3307
3308static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3309 u32 phyId, u32 phy_op);
3310
3311/**
3312 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
3313 * @pm8001_ha: our hba card information
3314 * @piomb: IO message buffer
3315 */
3316static void
3317hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3318{
3319 struct hw_event_resp *pPayload =
3320 (struct hw_event_resp *)(piomb + 4);
3321 u32 lr_evt_status_phyid_portid =
3322 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3323 u8 link_rate =
3324 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003325 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003326 u8 phy_id =
3327 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003328 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3329 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3330 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003331 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3332 unsigned long flags;
3333 u8 deviceType = pPayload->sas_identify.dev_type;
Ajish Koshy08d0a992021-09-06 22:34:01 +05303334 phy->port = port;
3335 port->port_id = port_id;
jack wang1cc943a2009-12-07 17:22:42 +08003336 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303337 phy->phy_state = PHY_STATE_LINK_UP_SPC;
Joe Perches1b5d2792020-11-20 15:16:09 -08003338 pm8001_dbg(pm8001_ha, MSG,
3339 "HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n",
3340 port_id, phy_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003341
3342 switch (deviceType) {
3343 case SAS_PHY_UNUSED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003344 pm8001_dbg(pm8001_ha, MSG, "device type no device.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003345 break;
3346 case SAS_END_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003347 pm8001_dbg(pm8001_ha, MSG, "end device.\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003348 pm8001_chip_phy_ctl_req(pm8001_ha, phy_id,
3349 PHY_NOTIFY_ENABLE_SPINUP);
jack wang1cc943a2009-12-07 17:22:42 +08003350 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303351 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003352 break;
3353 case SAS_EDGE_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003354 pm8001_dbg(pm8001_ha, MSG, "expander device.\n");
jack wang1cc943a2009-12-07 17:22:42 +08003355 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303356 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003357 break;
3358 case SAS_FANOUT_EXPANDER_DEVICE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003359 pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n");
jack wang1cc943a2009-12-07 17:22:42 +08003360 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303361 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003362 break;
3363 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003364 pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n",
3365 deviceType);
jack wangdbf9bfe2009-10-14 16:19:21 +08003366 break;
3367 }
3368 phy->phy_type |= PORT_TYPE_SAS;
3369 phy->identify.device_type = deviceType;
3370 phy->phy_attached = 1;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303371 if (phy->identify.device_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08003372 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303373 else if (phy->identify.device_type != SAS_PHY_UNUSED)
jack wangdbf9bfe2009-10-14 16:19:21 +08003374 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3375 phy->sas_phy.oob_mode = SAS_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003376 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003377 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3378 memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3379 sizeof(struct sas_identify_frame)-4);
3380 phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3381 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3382 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3383 if (pm8001_ha->flags == PM8001F_RUN_TIME)
3384 mdelay(200);/*delay a moment to wait disk to spinup*/
3385 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3386}
3387
3388/**
3389 * hw_event_sata_phy_up -FW tells me a SATA phy up event.
3390 * @pm8001_ha: our hba card information
3391 * @piomb: IO message buffer
3392 */
3393static void
3394hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3395{
3396 struct hw_event_resp *pPayload =
3397 (struct hw_event_resp *)(piomb + 4);
3398 u32 lr_evt_status_phyid_portid =
3399 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3400 u8 link_rate =
3401 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003402 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003403 u8 phy_id =
3404 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003405 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3406 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3407 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003408 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3409 unsigned long flags;
Joe Perches1b5d2792020-11-20 15:16:09 -08003410 pm8001_dbg(pm8001_ha, DEVIO, "HW_EVENT_SATA_PHY_UP port id = %d, phy id = %d\n",
3411 port_id, phy_id);
Ajish Koshy08d0a992021-09-06 22:34:01 +05303412 phy->port = port;
3413 port->port_id = port_id;
jack wang1cc943a2009-12-07 17:22:42 +08003414 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303415 phy->phy_state = PHY_STATE_LINK_UP_SPC;
jack wang1cc943a2009-12-07 17:22:42 +08003416 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303417 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003418 phy->phy_type |= PORT_TYPE_SATA;
3419 phy->phy_attached = 1;
3420 phy->sas_phy.oob_mode = SATA_OOB_MODE;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003421 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003422 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3423 memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3424 sizeof(struct dev_to_host_fis));
3425 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3426 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
James Bottomleyaa9f8322013-05-07 14:44:06 -07003427 phy->identify.device_type = SAS_SATA_DEV;
jack wangdbf9bfe2009-10-14 16:19:21 +08003428 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3429 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3430 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3431}
3432
3433/**
3434 * hw_event_phy_down -we should notify the libsas the phy is down.
3435 * @pm8001_ha: our hba card information
3436 * @piomb: IO message buffer
3437 */
3438static void
3439hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3440{
3441 struct hw_event_resp *pPayload =
3442 (struct hw_event_resp *)(piomb + 4);
3443 u32 lr_evt_status_phyid_portid =
3444 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3445 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3446 u8 phy_id =
3447 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3448 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3449 u8 portstate = (u8)(npip_portstate & 0x0000000F);
jack wang1cc943a2009-12-07 17:22:42 +08003450 struct pm8001_port *port = &pm8001_ha->port[port_id];
3451 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3452 port->port_state = portstate;
3453 phy->phy_type = 0;
3454 phy->identify.device_type = 0;
3455 phy->phy_attached = 0;
3456 memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
jack wangdbf9bfe2009-10-14 16:19:21 +08003457 switch (portstate) {
3458 case PORT_VALID:
3459 break;
3460 case PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003461 pm8001_dbg(pm8001_ha, MSG, " PortInvalid portID %d\n",
3462 port_id);
3463 pm8001_dbg(pm8001_ha, MSG,
3464 " Last phy Down and port invalid\n");
jack wang1cc943a2009-12-07 17:22:42 +08003465 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003466 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3467 port_id, phy_id, 0, 0);
3468 break;
3469 case PORT_IN_RESET:
Joe Perches1b5d2792020-11-20 15:16:09 -08003470 pm8001_dbg(pm8001_ha, MSG, " Port In Reset portID %d\n",
3471 port_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003472 break;
3473 case PORT_NOT_ESTABLISHED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003474 pm8001_dbg(pm8001_ha, MSG,
3475 " phy Down and PORT_NOT_ESTABLISHED\n");
jack wang1cc943a2009-12-07 17:22:42 +08003476 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003477 break;
3478 case PORT_LOSTCOMM:
Joe Perches1b5d2792020-11-20 15:16:09 -08003479 pm8001_dbg(pm8001_ha, MSG, " phy Down and PORT_LOSTCOMM\n");
3480 pm8001_dbg(pm8001_ha, MSG,
3481 " Last phy Down and port invalid\n");
jack wang1cc943a2009-12-07 17:22:42 +08003482 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003483 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3484 port_id, phy_id, 0, 0);
3485 break;
3486 default:
jack wang1cc943a2009-12-07 17:22:42 +08003487 port->port_attached = 0;
Joe Perches1b5d2792020-11-20 15:16:09 -08003488 pm8001_dbg(pm8001_ha, DEVIO, " phy Down and(default) = %x\n",
3489 portstate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003490 break;
3491
3492 }
3493}
3494
3495/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05303496 * pm8001_mpi_reg_resp -process register device ID response.
jack wangdbf9bfe2009-10-14 16:19:21 +08003497 * @pm8001_ha: our hba card information
3498 * @piomb: IO message buffer
3499 *
3500 * when sas layer find a device it will notify LLDD, then the driver register
3501 * the domain device to FW, this event is the return device ID which the FW
Randy Dunlapbb6beab2021-07-08 09:57:23 -07003502 * has assigned, from now, inter-communication with FW is no longer using the
jack wangdbf9bfe2009-10-14 16:19:21 +08003503 * SAS address, use device ID which FW assigned.
3504 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303505int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003506{
3507 u32 status;
3508 u32 device_id;
3509 u32 htag;
3510 struct pm8001_ccb_info *ccb;
3511 struct pm8001_device *pm8001_dev;
3512 struct dev_reg_resp *registerRespPayload =
3513 (struct dev_reg_resp *)(piomb + 4);
3514
3515 htag = le32_to_cpu(registerRespPayload->tag);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303516 ccb = &pm8001_ha->ccb_info[htag];
jack wangdbf9bfe2009-10-14 16:19:21 +08003517 pm8001_dev = ccb->device;
3518 status = le32_to_cpu(registerRespPayload->status);
3519 device_id = le32_to_cpu(registerRespPayload->device_id);
Joe Perches1b5d2792020-11-20 15:16:09 -08003520 pm8001_dbg(pm8001_ha, MSG, " register device is status = %d\n",
3521 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003522 switch (status) {
3523 case DEVREG_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003524 pm8001_dbg(pm8001_ha, MSG, "DEVREG_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003525 pm8001_dev->device_id = device_id;
3526 break;
3527 case DEVREG_FAILURE_OUT_OF_RESOURCE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003528 pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_OUT_OF_RESOURCE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003529 break;
3530 case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003531 pm8001_dbg(pm8001_ha, MSG,
3532 "DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003533 break;
3534 case DEVREG_FAILURE_INVALID_PHY_ID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003535 pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_INVALID_PHY_ID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003536 break;
3537 case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003538 pm8001_dbg(pm8001_ha, MSG,
3539 "DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003540 break;
3541 case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003542 pm8001_dbg(pm8001_ha, MSG,
3543 "DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003544 break;
3545 case DEVREG_FAILURE_PORT_NOT_VALID_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003546 pm8001_dbg(pm8001_ha, MSG,
3547 "DEVREG_FAILURE_PORT_NOT_VALID_STATE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003548 break;
3549 case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003550 pm8001_dbg(pm8001_ha, MSG,
3551 "DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003552 break;
3553 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003554 pm8001_dbg(pm8001_ha, MSG,
3555 "DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003556 break;
3557 }
3558 complete(pm8001_dev->dcompletion);
3559 ccb->task = NULL;
3560 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303561 pm8001_tag_free(pm8001_ha, htag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003562 return 0;
3563}
3564
Sakthivel Kf74cf272013-02-27 20:27:43 +05303565int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003566{
3567 u32 status;
3568 u32 device_id;
3569 struct dev_reg_resp *registerRespPayload =
3570 (struct dev_reg_resp *)(piomb + 4);
3571
3572 status = le32_to_cpu(registerRespPayload->status);
3573 device_id = le32_to_cpu(registerRespPayload->device_id);
3574 if (status != 0)
Joe Perches1b5d2792020-11-20 15:16:09 -08003575 pm8001_dbg(pm8001_ha, MSG,
3576 " deregister device failed ,status = %x, device_id = %x\n",
3577 status, device_id);
jack wangdbf9bfe2009-10-14 16:19:21 +08003578 return 0;
3579}
3580
Sakthivel Kf74cf272013-02-27 20:27:43 +05303581/**
Lee Jones6b87e432021-03-03 14:46:19 +00003582 * pm8001_mpi_fw_flash_update_resp - Response from FW for flash update command.
Sakthivel Kf74cf272013-02-27 20:27:43 +05303583 * @pm8001_ha: our hba card information
3584 * @piomb: IO message buffer
3585 */
3586int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha,
3587 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003588{
3589 u32 status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003590 struct fw_flash_Update_resp *ppayload =
3591 (struct fw_flash_Update_resp *)(piomb + 4);
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303592 u32 tag = le32_to_cpu(ppayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003593 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3594 status = le32_to_cpu(ppayload->status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003595 switch (status) {
3596 case FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003597 pm8001_dbg(pm8001_ha, MSG,
3598 ": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003599 break;
3600 case FLASH_UPDATE_IN_PROGRESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003601 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_IN_PROGRESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003602 break;
3603 case FLASH_UPDATE_HDR_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003604 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HDR_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003605 break;
3606 case FLASH_UPDATE_OFFSET_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003607 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_OFFSET_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003608 break;
3609 case FLASH_UPDATE_CRC_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003610 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_CRC_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003611 break;
3612 case FLASH_UPDATE_LENGTH_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003613 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_LENGTH_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003614 break;
3615 case FLASH_UPDATE_HW_ERR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003616 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HW_ERR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003617 break;
3618 case FLASH_UPDATE_DNLD_NOT_SUPPORTED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003619 pm8001_dbg(pm8001_ha, MSG,
3620 ": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003621 break;
3622 case FLASH_UPDATE_DISABLED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003623 pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_DISABLED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003624 break;
3625 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003626 pm8001_dbg(pm8001_ha, DEVIO, "No matched status = %d\n",
3627 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003628 break;
3629 }
Tomas Henzl9422e862014-07-07 17:20:00 +02003630 kfree(ccb->fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08003631 ccb->task = NULL;
3632 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303633 pm8001_tag_free(pm8001_ha, tag);
Tomas Henzl9422e862014-07-07 17:20:00 +02003634 complete(pm8001_ha->nvmd_completion);
jack wangdbf9bfe2009-10-14 16:19:21 +08003635 return 0;
3636}
3637
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08003638int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003639{
3640 u32 status;
3641 int i;
3642 struct general_event_resp *pPayload =
3643 (struct general_event_resp *)(piomb + 4);
3644 status = le32_to_cpu(pPayload->status);
Joe Perches1b5d2792020-11-20 15:16:09 -08003645 pm8001_dbg(pm8001_ha, MSG, " status = 0x%x\n", status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003646 for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
Joe Perches1b5d2792020-11-20 15:16:09 -08003647 pm8001_dbg(pm8001_ha, MSG, "inb_IOMB_payload[0x%x] 0x%x,\n",
3648 i,
3649 pPayload->inb_IOMB_payload[i]);
jack wangdbf9bfe2009-10-14 16:19:21 +08003650 return 0;
3651}
3652
Sakthivel Kf74cf272013-02-27 20:27:43 +05303653int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003654{
3655 struct sas_task *t;
3656 struct pm8001_ccb_info *ccb;
3657 unsigned long flags;
3658 u32 status ;
3659 u32 tag, scp;
3660 struct task_status_struct *ts;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303661 struct pm8001_device *pm8001_dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08003662
3663 struct task_abort_resp *pPayload =
3664 (struct task_abort_resp *)(piomb + 4);
jack wangdbf9bfe2009-10-14 16:19:21 +08003665
3666 status = le32_to_cpu(pPayload->status);
3667 tag = le32_to_cpu(pPayload->tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303668 if (!tag) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003669 pm8001_dbg(pm8001_ha, FAIL, " TAG NULL. RETURNING !!!\n");
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303670 return -1;
3671 }
3672
jack wangdbf9bfe2009-10-14 16:19:21 +08003673 scp = le32_to_cpu(pPayload->scp);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303674 ccb = &pm8001_ha->ccb_info[tag];
3675 t = ccb->task;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303676 pm8001_dev = ccb->device; /* retrieve device */
3677
3678 if (!t) {
Joe Perches1b5d2792020-11-20 15:16:09 -08003679 pm8001_dbg(pm8001_ha, FAIL, " TASK NULL. RETURNING !!!\n");
jack_wang72d0baa2009-11-05 22:33:35 +08003680 return -1;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303681 }
jack_wang72d0baa2009-11-05 22:33:35 +08003682 ts = &t->task_status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003683 if (status != 0)
Joe Perches1b5d2792020-11-20 15:16:09 -08003684 pm8001_dbg(pm8001_ha, FAIL, "task abort failed status 0x%x ,tag = 0x%x, scp= 0x%x\n",
3685 status, tag, scp);
jack wangdbf9bfe2009-10-14 16:19:21 +08003686 switch (status) {
3687 case IO_SUCCESS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003688 pm8001_dbg(pm8001_ha, EH, "IO_SUCCESS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003689 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07003690 ts->stat = SAS_SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08003691 break;
3692 case IO_NOT_VALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003693 pm8001_dbg(pm8001_ha, EH, "IO_NOT_VALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003694 ts->resp = TMF_RESP_FUNC_FAILED;
3695 break;
3696 }
3697 spin_lock_irqsave(&t->task_state_lock, flags);
3698 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3699 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3700 t->task_state_flags |= SAS_TASK_STATE_DONE;
3701 spin_unlock_irqrestore(&t->task_state_lock, flags);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303702 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003703 mb();
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303704
Dan Carpenter808cbb62013-05-09 15:48:13 +03003705 if (pm8001_dev->id & NCQ_ABORT_ALL_FLAG) {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303706 pm8001_tag_free(pm8001_ha, tag);
3707 sas_free_task(t);
3708 /* clear the flag */
3709 pm8001_dev->id &= 0xBFFFFFFF;
3710 } else
3711 t->task_done(t);
3712
jack wangdbf9bfe2009-10-14 16:19:21 +08003713 return 0;
3714}
3715
3716/**
3717 * mpi_hw_event -The hw event has come.
3718 * @pm8001_ha: our hba card information
3719 * @piomb: IO message buffer
3720 */
Luo Jiaxing8a23dbc2021-04-08 20:56:32 +08003721static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003722{
3723 unsigned long flags;
3724 struct hw_event_resp *pPayload =
3725 (struct hw_event_resp *)(piomb + 4);
3726 u32 lr_evt_status_phyid_portid =
3727 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3728 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3729 u8 phy_id =
3730 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3731 u16 eventType =
3732 (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8);
3733 u8 status =
3734 (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24);
3735 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3736 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3737 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
Joe Perches1b5d2792020-11-20 15:16:09 -08003738 pm8001_dbg(pm8001_ha, DEVIO,
3739 "SPC HW event for portid:%d, phyid:%d, event:%x, status:%x\n",
3740 port_id, phy_id, eventType, status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003741 switch (eventType) {
3742 case HW_EVENT_PHY_START_STATUS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003743 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS status = %x\n",
3744 status);
Ajish Koshyd1acd812021-05-05 17:31:03 +05303745 if (status == 0)
jack wangdbf9bfe2009-10-14 16:19:21 +08003746 phy->phy_state = 1;
Ajish Koshyd1acd812021-05-05 17:31:03 +05303747
3748 if (pm8001_ha->flags == PM8001F_RUN_TIME &&
3749 phy->enable_completion != NULL) {
3750 complete(phy->enable_completion);
3751 phy->enable_completion = NULL;
jack wangdbf9bfe2009-10-14 16:19:21 +08003752 }
3753 break;
3754 case HW_EVENT_SAS_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003755 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003756 hw_event_sas_phy_up(pm8001_ha, piomb);
3757 break;
3758 case HW_EVENT_SATA_PHY_UP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003759 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_PHY_UP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003760 hw_event_sata_phy_up(pm8001_ha, piomb);
3761 break;
3762 case HW_EVENT_PHY_STOP_STATUS:
Joe Perches1b5d2792020-11-20 15:16:09 -08003763 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_STOP_STATUS status = %x\n",
3764 status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003765 if (status == 0)
3766 phy->phy_state = 0;
3767 break;
3768 case HW_EVENT_SATA_SPINUP_HOLD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003769 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_SPINUP_HOLD\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003770 sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003771 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003772 break;
3773 case HW_EVENT_PHY_DOWN:
Joe Perches1b5d2792020-11-20 15:16:09 -08003774 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_DOWN\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003775 sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003776 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003777 phy->phy_attached = 0;
3778 phy->phy_state = 0;
3779 hw_event_phy_down(pm8001_ha, piomb);
3780 break;
3781 case HW_EVENT_PORT_INVALID:
Joe Perches1b5d2792020-11-20 15:16:09 -08003782 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_INVALID\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003783 sas_phy_disconnected(sas_phy);
3784 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003785 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003786 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003787 break;
3788 /* the broadcast change primitive received, tell the LIBSAS this event
3789 to revalidate the sas domain*/
3790 case HW_EVENT_BROADCAST_CHANGE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003791 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003792 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3793 port_id, phy_id, 1, 0);
3794 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3795 sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3796 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003797 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003798 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003799 break;
3800 case HW_EVENT_PHY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003801 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003802 sas_phy_disconnected(&phy->sas_phy);
3803 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003804 sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003805 break;
3806 case HW_EVENT_BROADCAST_EXP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003807 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003808 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3809 sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3810 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003811 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003812 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003813 break;
3814 case HW_EVENT_LINK_ERR_INVALID_DWORD:
Joe Perches1b5d2792020-11-20 15:16:09 -08003815 pm8001_dbg(pm8001_ha, MSG,
3816 "HW_EVENT_LINK_ERR_INVALID_DWORD\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003817 pm8001_hw_event_ack_req(pm8001_ha, 0,
3818 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3819 sas_phy_disconnected(sas_phy);
3820 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003821 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003822 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003823 break;
3824 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003825 pm8001_dbg(pm8001_ha, MSG,
3826 "HW_EVENT_LINK_ERR_DISPARITY_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003827 pm8001_hw_event_ack_req(pm8001_ha, 0,
3828 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3829 port_id, phy_id, 0, 0);
3830 sas_phy_disconnected(sas_phy);
3831 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003832 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
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_CODE_VIOLATION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003836 pm8001_dbg(pm8001_ha, MSG,
3837 "HW_EVENT_LINK_ERR_CODE_VIOLATION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003838 pm8001_hw_event_ack_req(pm8001_ha, 0,
3839 HW_EVENT_LINK_ERR_CODE_VIOLATION,
3840 port_id, phy_id, 0, 0);
3841 sas_phy_disconnected(sas_phy);
3842 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003843 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003844 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003845 break;
3846 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
Joe Perches1b5d2792020-11-20 15:16:09 -08003847 pm8001_dbg(pm8001_ha, MSG,
3848 "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003849 pm8001_hw_event_ack_req(pm8001_ha, 0,
3850 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
3851 port_id, phy_id, 0, 0);
3852 sas_phy_disconnected(sas_phy);
3853 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003854 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003855 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003856 break;
3857 case HW_EVENT_MALFUNCTION:
Joe Perches1b5d2792020-11-20 15:16:09 -08003858 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_MALFUNCTION\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003859 break;
3860 case HW_EVENT_BROADCAST_SES:
Joe Perches1b5d2792020-11-20 15:16:09 -08003861 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003862 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3863 sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
3864 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003865 sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003866 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003867 break;
3868 case HW_EVENT_INBOUND_CRC_ERROR:
Joe Perches1b5d2792020-11-20 15:16:09 -08003869 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_INBOUND_CRC_ERROR\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003870 pm8001_hw_event_ack_req(pm8001_ha, 0,
3871 HW_EVENT_INBOUND_CRC_ERROR,
3872 port_id, phy_id, 0, 0);
3873 break;
3874 case HW_EVENT_HARD_RESET_RECEIVED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003875 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_HARD_RESET_RECEIVED\n");
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003876 sas_notify_port_event(sas_phy, PORTE_HARD_RESET, GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003877 break;
3878 case HW_EVENT_ID_FRAME_TIMEOUT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003879 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_ID_FRAME_TIMEOUT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003880 sas_phy_disconnected(sas_phy);
3881 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003882 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003883 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003884 break;
3885 case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
Joe Perches1b5d2792020-11-20 15:16:09 -08003886 pm8001_dbg(pm8001_ha, MSG,
3887 "HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003888 pm8001_hw_event_ack_req(pm8001_ha, 0,
3889 HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
3890 port_id, phy_id, 0, 0);
3891 sas_phy_disconnected(sas_phy);
3892 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003893 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003894 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003895 break;
3896 case HW_EVENT_PORT_RESET_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003897 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_TIMER_TMO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003898 sas_phy_disconnected(sas_phy);
3899 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003900 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003901 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003902 break;
3903 case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003904 pm8001_dbg(pm8001_ha, MSG,
3905 "HW_EVENT_PORT_RECOVERY_TIMER_TMO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003906 sas_phy_disconnected(sas_phy);
3907 phy->phy_attached = 0;
Ahmed S. Darwishde6d7542021-01-18 11:09:51 +01003908 sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR,
Ahmed S. Darwishcd4e8172021-01-18 11:09:45 +01003909 GFP_ATOMIC);
jack wangdbf9bfe2009-10-14 16:19:21 +08003910 break;
3911 case HW_EVENT_PORT_RECOVER:
Joe Perches1b5d2792020-11-20 15:16:09 -08003912 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RECOVER\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003913 break;
3914 case HW_EVENT_PORT_RESET_COMPLETE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003915 pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_COMPLETE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003916 break;
3917 case EVENT_BROADCAST_ASYNCH_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003918 pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003919 break;
3920 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08003921 pm8001_dbg(pm8001_ha, DEVIO, "Unknown event type = %x\n",
3922 eventType);
jack wangdbf9bfe2009-10-14 16:19:21 +08003923 break;
3924 }
3925 return 0;
3926}
3927
3928/**
3929 * process_one_iomb - process one outbound Queue memory block
3930 * @pm8001_ha: our hba card information
3931 * @piomb: IO message buffer
3932 */
3933static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
3934{
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303935 __le32 pHeader = *(__le32 *)piomb;
3936 u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF);
jack wangdbf9bfe2009-10-14 16:19:21 +08003937
Joe Perches1b5d2792020-11-20 15:16:09 -08003938 pm8001_dbg(pm8001_ha, MSG, "process_one_iomb:\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003939
3940 switch (opc) {
3941 case OPC_OUB_ECHO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003942 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003943 break;
3944 case OPC_OUB_HW_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003945 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003946 mpi_hw_event(pm8001_ha, piomb);
3947 break;
3948 case OPC_OUB_SSP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003949 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003950 mpi_ssp_completion(pm8001_ha, piomb);
3951 break;
3952 case OPC_OUB_SMP_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003953 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003954 mpi_smp_completion(pm8001_ha, piomb);
3955 break;
3956 case OPC_OUB_LOCAL_PHY_CNTRL:
Joe Perches1b5d2792020-11-20 15:16:09 -08003957 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303958 pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003959 break;
3960 case OPC_OUB_DEV_REGIST:
Joe Perches1b5d2792020-11-20 15:16:09 -08003961 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303962 pm8001_mpi_reg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003963 break;
3964 case OPC_OUB_DEREG_DEV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003965 pm8001_dbg(pm8001_ha, MSG, "unregister the device\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303966 pm8001_mpi_dereg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003967 break;
3968 case OPC_OUB_GET_DEV_HANDLE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003969 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003970 break;
3971 case OPC_OUB_SATA_COMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08003972 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003973 mpi_sata_completion(pm8001_ha, piomb);
3974 break;
3975 case OPC_OUB_SATA_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003976 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003977 mpi_sata_event(pm8001_ha, piomb);
3978 break;
3979 case OPC_OUB_SSP_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003980 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003981 mpi_ssp_event(pm8001_ha, piomb);
3982 break;
3983 case OPC_OUB_DEV_HANDLE_ARRIV:
Joe Perches1b5d2792020-11-20 15:16:09 -08003984 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003985 /*This is for target*/
3986 break;
3987 case OPC_OUB_SSP_RECV_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08003988 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003989 /*This is for target*/
3990 break;
3991 case OPC_OUB_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08003992 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_INFO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08003993 break;
3994 case OPC_OUB_FW_FLASH_UPDATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003995 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05303996 pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08003997 break;
3998 case OPC_OUB_GPIO_RESPONSE:
Joe Perches1b5d2792020-11-20 15:16:09 -08003999 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004000 break;
4001 case OPC_OUB_GPIO_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004002 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004003 break;
4004 case OPC_OUB_GENERAL_EVENT:
Joe Perches1b5d2792020-11-20 15:16:09 -08004005 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304006 pm8001_mpi_general_event(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004007 break;
4008 case OPC_OUB_SSP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004009 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304010 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004011 break;
4012 case OPC_OUB_SATA_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004013 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304014 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004015 break;
4016 case OPC_OUB_SAS_DIAG_MODE_START_END:
Joe Perches1b5d2792020-11-20 15:16:09 -08004017 pm8001_dbg(pm8001_ha, MSG,
4018 "OPC_OUB_SAS_DIAG_MODE_START_END\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004019 break;
4020 case OPC_OUB_SAS_DIAG_EXECUTE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004021 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004022 break;
4023 case OPC_OUB_GET_TIME_STAMP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004024 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004025 break;
4026 case OPC_OUB_SAS_HW_EVENT_ACK:
Joe Perches1b5d2792020-11-20 15:16:09 -08004027 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004028 break;
4029 case OPC_OUB_PORT_CONTROL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004030 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004031 break;
4032 case OPC_OUB_SMP_ABORT_RSP:
Joe Perches1b5d2792020-11-20 15:16:09 -08004033 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304034 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004035 break;
4036 case OPC_OUB_GET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004037 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304038 pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004039 break;
4040 case OPC_OUB_SET_NVMD_DATA:
Joe Perches1b5d2792020-11-20 15:16:09 -08004041 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304042 pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004043 break;
4044 case OPC_OUB_DEVICE_HANDLE_REMOVAL:
Joe Perches1b5d2792020-11-20 15:16:09 -08004045 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004046 break;
4047 case OPC_OUB_SET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004048 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n");
Sakthivel Kf74cf272013-02-27 20:27:43 +05304049 pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004050 break;
4051 case OPC_OUB_GET_DEVICE_STATE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004052 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004053 break;
4054 case OPC_OUB_SET_DEV_INFO:
Joe Perches1b5d2792020-11-20 15:16:09 -08004055 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004056 break;
4057 case OPC_OUB_SAS_RE_INITIALIZE:
Joe Perches1b5d2792020-11-20 15:16:09 -08004058 pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_RE_INITIALIZE\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004059 break;
4060 default:
Joe Perches1b5d2792020-11-20 15:16:09 -08004061 pm8001_dbg(pm8001_ha, DEVIO,
4062 "Unknown outbound Queue IOMB OPC = %x\n",
4063 opc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004064 break;
4065 }
4066}
4067
Sakthivel Kf74cf272013-02-27 20:27:43 +05304068static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004069{
4070 struct outbound_queue_table *circularQ;
4071 void *pMsg1 = NULL;
Kees Cook3f649ab2020-06-03 13:09:38 -07004072 u8 bc;
jack_wang72d0baa2009-11-05 22:33:35 +08004073 u32 ret = MPI_IO_STATUS_FAIL;
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304074 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004075
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304076 spin_lock_irqsave(&pm8001_ha->lock, flags);
Sakthivel Kf74cf272013-02-27 20:27:43 +05304077 circularQ = &pm8001_ha->outbnd_q_tbl[vec];
jack wangdbf9bfe2009-10-14 16:19:21 +08004078 do {
Sakthivel Kf74cf272013-02-27 20:27:43 +05304079 ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004080 if (MPI_IO_STATUS_SUCCESS == ret) {
4081 /* process the outbound message */
jack_wang72d0baa2009-11-05 22:33:35 +08004082 process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
jack wangdbf9bfe2009-10-14 16:19:21 +08004083 /* free the message from the outbound circular buffer */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304084 pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4085 circularQ, bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004086 }
4087 if (MPI_IO_STATUS_BUSY == ret) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004088 /* Update the producer index from SPC */
Santosh Nayak8270ee22012-02-26 20:14:46 +05304089 circularQ->producer_index =
4090 cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4091 if (le32_to_cpu(circularQ->producer_index) ==
jack wangdbf9bfe2009-10-14 16:19:21 +08004092 circularQ->consumer_idx)
4093 /* OQ is empty */
4094 break;
4095 }
jack_wang72d0baa2009-11-05 22:33:35 +08004096 } while (1);
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304097 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08004098 return ret;
4099}
4100
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004101/* DMA_... to our direction translation. */
jack wangdbf9bfe2009-10-14 16:19:21 +08004102static const u8 data_dir_flags[] = {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004103 [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
4104 [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
4105 [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */
4106 [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */
jack wangdbf9bfe2009-10-14 16:19:21 +08004107};
Sakthivel Kf74cf272013-02-27 20:27:43 +05304108void
jack wangdbf9bfe2009-10-14 16:19:21 +08004109pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
4110{
4111 int i;
4112 struct scatterlist *sg;
4113 struct pm8001_prd *buf_prd = prd;
4114
4115 for_each_sg(scatter, sg, nr, i) {
4116 buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
4117 buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
4118 buf_prd->im_len.e = 0;
4119 buf_prd++;
4120 }
4121}
4122
Santosh Nayak8270ee22012-02-26 20:14:46 +05304123static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd)
jack wangdbf9bfe2009-10-14 16:19:21 +08004124{
Santosh Nayak8270ee22012-02-26 20:14:46 +05304125 psmp_cmd->tag = hTag;
jack wangdbf9bfe2009-10-14 16:19:21 +08004126 psmp_cmd->device_id = cpu_to_le32(deviceID);
4127 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4128}
4129
4130/**
4131 * pm8001_chip_smp_req - send a SMP task to FW
4132 * @pm8001_ha: our hba card information.
4133 * @ccb: the ccb information this request used.
4134 */
4135static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4136 struct pm8001_ccb_info *ccb)
4137{
4138 int elem, rc;
4139 struct sas_task *task = ccb->task;
4140 struct domain_device *dev = task->dev;
4141 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4142 struct scatterlist *sg_req, *sg_resp;
4143 u32 req_len, resp_len;
4144 struct smp_req smp_cmd;
4145 u32 opc;
4146 struct inbound_queue_table *circularQ;
4147
4148 memset(&smp_cmd, 0, sizeof(smp_cmd));
4149 /*
4150 * DMA-map SMP request, response buffers
4151 */
4152 sg_req = &task->smp_task.smp_req;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004153 elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004154 if (!elem)
4155 return -ENOMEM;
4156 req_len = sg_dma_len(sg_req);
4157
4158 sg_resp = &task->smp_task.smp_resp;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004159 elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004160 if (!elem) {
4161 rc = -ENOMEM;
4162 goto err_out;
4163 }
4164 resp_len = sg_dma_len(sg_resp);
4165 /* must be in dwords */
4166 if ((req_len & 0x3) || (resp_len & 0x3)) {
4167 rc = -EINVAL;
4168 goto err_out_2;
4169 }
4170
4171 opc = OPC_INB_SMP_REQUEST;
4172 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4173 smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4174 smp_cmd.long_smp_req.long_req_addr =
4175 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4176 smp_cmd.long_smp_req.long_req_size =
4177 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4178 smp_cmd.long_smp_req.long_resp_addr =
4179 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp));
4180 smp_cmd.long_smp_req.long_resp_size =
4181 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4182 build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304183 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304184 &smp_cmd, sizeof(smp_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304185 if (rc)
4186 goto err_out_2;
4187
jack wangdbf9bfe2009-10-14 16:19:21 +08004188 return 0;
4189
4190err_out_2:
4191 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004192 DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004193err_out:
4194 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004195 DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004196 return rc;
4197}
4198
4199/**
4200 * pm8001_chip_ssp_io_req - send a SSP task to FW
4201 * @pm8001_ha: our hba card information.
4202 * @ccb: the ccb information this request used.
4203 */
4204static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4205 struct pm8001_ccb_info *ccb)
4206{
4207 struct sas_task *task = ccb->task;
4208 struct domain_device *dev = task->dev;
4209 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4210 struct ssp_ini_io_start_req ssp_cmd;
4211 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004212 int ret;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304213 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004214 struct inbound_queue_table *circularQ;
4215 u32 opc = OPC_INB_SSPINIIOSTART;
4216 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4217 memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
jack wangafc5ca92009-12-07 17:22:47 +08004218 ssp_cmd.dir_m_tlr =
4219 cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for
jack wangdbf9bfe2009-10-14 16:19:21 +08004220 SAS 1.1 compatible TLR*/
4221 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4222 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4223 ssp_cmd.tag = cpu_to_le32(tag);
4224 if (task->ssp_task.enable_first_burst)
4225 ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
4226 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
4227 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
James Bottomleye73823f2013-05-07 15:38:18 -07004228 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4229 task->ssp_task.cmd->cmd_len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004230 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4231
4232 /* fill in PRD (scatter/gather) table, if any */
4233 if (task->num_scatter > 1) {
4234 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304235 phys_addr = ccb->ccb_dma_handle;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304236 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr));
4237 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004238 ssp_cmd.esgl = cpu_to_le32(1<<31);
4239 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304240 u64 dma_addr = sg_dma_address(task->scatter);
4241 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4242 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004243 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4244 ssp_cmd.esgl = 0;
4245 } else if (task->num_scatter == 0) {
4246 ssp_cmd.addr_low = 0;
4247 ssp_cmd.addr_high = 0;
4248 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4249 ssp_cmd.esgl = 0;
4250 }
peter chang91a43fa2019-11-14 15:39:05 +05304251 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd,
4252 sizeof(ssp_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004253 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004254}
4255
4256static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4257 struct pm8001_ccb_info *ccb)
4258{
4259 struct sas_task *task = ccb->task;
4260 struct domain_device *dev = task->dev;
4261 struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4262 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004263 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004264 struct sata_start_req sata_cmd;
4265 u32 hdr_tag, ncg_tag = 0;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304266 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004267 u32 ATAP = 0x0;
4268 u32 dir;
4269 struct inbound_queue_table *circularQ;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304270 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004271 u32 opc = OPC_INB_SATA_HOST_OPSTART;
4272 memset(&sata_cmd, 0, sizeof(sata_cmd));
4273 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004274 if (task->data_dir == DMA_NONE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004275 ATAP = 0x04; /* no data*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004276 pm8001_dbg(pm8001_ha, IO, "no data\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004277 } else if (likely(!task->ata_task.device_control_reg_update)) {
4278 if (task->ata_task.dma_xfer) {
4279 ATAP = 0x06; /* DMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004280 pm8001_dbg(pm8001_ha, IO, "DMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004281 } else {
4282 ATAP = 0x05; /* PIO*/
Joe Perches1b5d2792020-11-20 15:16:09 -08004283 pm8001_dbg(pm8001_ha, IO, "PIO\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004284 }
4285 if (task->ata_task.use_ncq &&
Hannes Reinecke1cbd7722014-11-05 13:08:20 +01004286 dev->sata_dev.class != ATA_DEV_ATAPI) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004287 ATAP = 0x07; /* FPDMA */
Joe Perches1b5d2792020-11-20 15:16:09 -08004288 pm8001_dbg(pm8001_ha, IO, "FPDMA\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08004289 }
4290 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304291 if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4292 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
jack wangafc5ca92009-12-07 17:22:47 +08004293 ncg_tag = hdr_tag;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304294 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004295 dir = data_dir_flags[task->data_dir] << 8;
4296 sata_cmd.tag = cpu_to_le32(tag);
4297 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4298 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4299 sata_cmd.ncqtag_atap_dir_m =
4300 cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir);
4301 sata_cmd.sata_fis = task->ata_task.fis;
4302 if (likely(!task->ata_task.device_control_reg_update))
4303 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4304 sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4305 /* fill in PRD (scatter/gather) table, if any */
4306 if (task->num_scatter > 1) {
4307 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304308 phys_addr = ccb->ccb_dma_handle;
jack wangdbf9bfe2009-10-14 16:19:21 +08004309 sata_cmd.addr_low = lower_32_bits(phys_addr);
4310 sata_cmd.addr_high = upper_32_bits(phys_addr);
4311 sata_cmd.esgl = cpu_to_le32(1 << 31);
4312 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304313 u64 dma_addr = sg_dma_address(task->scatter);
jack wangdbf9bfe2009-10-14 16:19:21 +08004314 sata_cmd.addr_low = lower_32_bits(dma_addr);
4315 sata_cmd.addr_high = upper_32_bits(dma_addr);
4316 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4317 sata_cmd.esgl = 0;
4318 } else if (task->num_scatter == 0) {
4319 sata_cmd.addr_low = 0;
4320 sata_cmd.addr_high = 0;
4321 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4322 sata_cmd.esgl = 0;
4323 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304324
4325 /* Check for read log for failed drive and return */
4326 if (sata_cmd.sata_fis.command == 0x2f) {
Rickard Strandqvistd9816442014-07-09 17:19:38 +05304327 if (((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304328 (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4329 (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4330 struct task_status_struct *ts;
4331
4332 pm8001_ha_dev->id &= 0xDFFFFFFF;
4333 ts = &task->task_status;
4334
4335 spin_lock_irqsave(&task->task_state_lock, flags);
4336 ts->resp = SAS_TASK_COMPLETE;
Bart Van Assched377f412021-05-23 19:54:55 -07004337 ts->stat = SAS_SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304338 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4339 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4340 task->task_state_flags |= SAS_TASK_STATE_DONE;
4341 if (unlikely((task->task_state_flags &
4342 SAS_TASK_STATE_ABORTED))) {
4343 spin_unlock_irqrestore(&task->task_state_lock,
4344 flags);
Joe Perches1b5d2792020-11-20 15:16:09 -08004345 pm8001_dbg(pm8001_ha, FAIL,
4346 "task 0x%p resp 0x%x stat 0x%x but aborted by upper layer\n",
4347 task, ts->resp,
4348 ts->stat);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304349 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304350 } else {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304351 spin_unlock_irqrestore(&task->task_state_lock,
4352 flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304353 pm8001_ccb_task_free_done(pm8001_ha, task,
4354 ccb, tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304355 return 0;
4356 }
4357 }
4358 }
4359
peter chang91a43fa2019-11-14 15:39:05 +05304360 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
4361 sizeof(sata_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004362 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004363}
4364
4365/**
4366 * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND
4367 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004368 * @phy_id: the phy id which we wanted to start up.
4369 */
4370static int
4371pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4372{
4373 struct phy_start_req payload;
4374 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004375 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004376 u32 tag = 0x01;
4377 u32 opcode = OPC_INB_PHYSTART;
4378 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4379 memset(&payload, 0, sizeof(payload));
4380 payload.tag = cpu_to_le32(tag);
4381 /*
4382 ** [0:7] PHY Identifier
4383 ** [8:11] link rate 1.5G, 3G, 6G
4384 ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both
4385 ** [14] 0b disable spin up hold; 1b enable spin up hold
4386 */
4387 payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4388 LINKMODE_AUTO | LINKRATE_15 |
4389 LINKRATE_30 | LINKRATE_60 | phy_id);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004390 payload.sas_identify.dev_type = SAS_END_DEVICE;
jack wangdbf9bfe2009-10-14 16:19:21 +08004391 payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4392 memcpy(payload.sas_identify.sas_addr,
4393 pm8001_ha->sas_addr, SAS_ADDR_SIZE);
4394 payload.sas_identify.phy_id = phy_id;
peter chang91a43fa2019-11-14 15:39:05 +05304395 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4396 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004397 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004398}
4399
4400/**
4401 * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4402 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004403 * @phy_id: the phy id which we wanted to start up.
4404 */
Baoyou Xie7efa59e2016-09-23 21:54:22 +08004405static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4406 u8 phy_id)
jack wangdbf9bfe2009-10-14 16:19:21 +08004407{
4408 struct phy_stop_req payload;
4409 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004410 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004411 u32 tag = 0x01;
4412 u32 opcode = OPC_INB_PHYSTOP;
4413 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4414 memset(&payload, 0, sizeof(payload));
4415 payload.tag = cpu_to_le32(tag);
4416 payload.phy_id = cpu_to_le32(phy_id);
peter chang91a43fa2019-11-14 15:39:05 +05304417 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4418 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004419 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004420}
4421
Lee Jones083645b2020-07-21 17:41:24 +01004422/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304423 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004424 */
4425static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4426 struct pm8001_device *pm8001_dev, u32 flag)
4427{
4428 struct reg_dev_req payload;
4429 u32 opc;
4430 u32 stp_sspsmp_sata = 0x4;
4431 struct inbound_queue_table *circularQ;
4432 u32 linkrate, phy_id;
jack_wang72d0baa2009-11-05 22:33:35 +08004433 int rc, tag = 0xdeadbeef;
jack wangdbf9bfe2009-10-14 16:19:21 +08004434 struct pm8001_ccb_info *ccb;
4435 u8 retryFlag = 0x1;
4436 u16 firstBurstSize = 0;
4437 u16 ITNT = 2000;
4438 struct domain_device *dev = pm8001_dev->sas_device;
4439 struct domain_device *parent_dev = dev->parent;
Ajish Koshy08d0a992021-09-06 22:34:01 +05304440 struct pm8001_port *port = dev->port->lldd_port;
jack wangdbf9bfe2009-10-14 16:19:21 +08004441 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4442
4443 memset(&payload, 0, sizeof(payload));
4444 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4445 if (rc)
4446 return rc;
4447 ccb = &pm8001_ha->ccb_info[tag];
4448 ccb->device = pm8001_dev;
4449 ccb->ccb_tag = tag;
4450 payload.tag = cpu_to_le32(tag);
4451 if (flag == 1)
4452 stp_sspsmp_sata = 0x02; /*direct attached sata */
4453 else {
James Bottomleyaa9f8322013-05-07 14:44:06 -07004454 if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004455 stp_sspsmp_sata = 0x00; /* stp*/
James Bottomleyaa9f8322013-05-07 14:44:06 -07004456 else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
Igor Pylypiv4f632912021-09-28 19:58:07 -07004457 dev_is_expander(pm8001_dev->dev_type))
jack wangdbf9bfe2009-10-14 16:19:21 +08004458 stp_sspsmp_sata = 0x01; /*ssp or smp*/
4459 }
John Garry924a3542019-06-10 20:41:41 +08004460 if (parent_dev && dev_is_expander(parent_dev->dev_type))
jack wangdbf9bfe2009-10-14 16:19:21 +08004461 phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4462 else
4463 phy_id = pm8001_dev->attached_phy;
4464 opc = OPC_INB_REG_DEV;
4465 linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4466 pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4467 payload.phyid_portid =
Ajish Koshy08d0a992021-09-06 22:34:01 +05304468 cpu_to_le32(((port->port_id) & 0x0F) |
jack wangdbf9bfe2009-10-14 16:19:21 +08004469 ((phy_id & 0x0F) << 4));
4470 payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) |
4471 ((linkrate & 0x0F) * 0x1000000) |
4472 ((stp_sspsmp_sata & 0x03) * 0x10000000));
4473 payload.firstburstsize_ITNexustimeout =
4474 cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
jack wangafc5ca92009-12-07 17:22:47 +08004475 memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
jack wangdbf9bfe2009-10-14 16:19:21 +08004476 SAS_ADDR_SIZE);
peter chang91a43fa2019-11-14 15:39:05 +05304477 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4478 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004479 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004480}
4481
Lee Jones083645b2020-07-21 17:41:24 +01004482/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304483 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004484 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304485int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004486 u32 device_id)
4487{
4488 struct dereg_dev_req payload;
4489 u32 opc = OPC_INB_DEREG_DEV_HANDLE;
jack_wang72d0baa2009-11-05 22:33:35 +08004490 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004491 struct inbound_queue_table *circularQ;
4492
4493 circularQ = &pm8001_ha->inbnd_q_tbl[0];
jack_wang72d0baa2009-11-05 22:33:35 +08004494 memset(&payload, 0, sizeof(payload));
Santosh Nayak8270ee22012-02-26 20:14:46 +05304495 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004496 payload.device_id = cpu_to_le32(device_id);
Joe Perches1b5d2792020-11-20 15:16:09 -08004497 pm8001_dbg(pm8001_ha, MSG, "unregister device device_id = %d\n",
4498 device_id);
peter chang91a43fa2019-11-14 15:39:05 +05304499 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4500 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004501 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004502}
4503
4504/**
4505 * pm8001_chip_phy_ctl_req - support the local phy operation
4506 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004507 * @phyId: the phy id which we wanted to operate
4508 * @phy_op: the phy operation to request
jack wangdbf9bfe2009-10-14 16:19:21 +08004509 */
4510static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4511 u32 phyId, u32 phy_op)
4512{
4513 struct local_phy_ctl_req payload;
4514 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004515 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004516 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
jack wang83e73322009-12-07 17:23:11 +08004517 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08004518 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Santosh Nayak8270ee22012-02-26 20:14:46 +05304519 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004520 payload.phyop_phyid =
4521 cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
peter chang91a43fa2019-11-14 15:39:05 +05304522 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4523 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004524 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004525}
4526
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004527static u32 pm8001_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08004528{
jack wangdbf9bfe2009-10-14 16:19:21 +08004529#ifdef PM8001_USE_MSIX
4530 return 1;
Colin Ian King292c04c2019-03-28 23:43:28 +00004531#else
4532 u32 value;
4533
jack wangdbf9bfe2009-10-14 16:19:21 +08004534 value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4535 if (value)
4536 return 1;
4537 return 0;
Colin Ian King292c04c2019-03-28 23:43:28 +00004538#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08004539}
4540
4541/**
4542 * pm8001_chip_isr - PM8001 isr handler.
4543 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004544 * @vec: IRQ number
jack wangdbf9bfe2009-10-14 16:19:21 +08004545 */
jack_wang72d0baa2009-11-05 22:33:35 +08004546static irqreturn_t
Sakthivel Kf74cf272013-02-27 20:27:43 +05304547pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004548{
Sakthivel Kf74cf272013-02-27 20:27:43 +05304549 pm8001_chip_interrupt_disable(pm8001_ha, vec);
Joe Perches1b5d2792020-11-20 15:16:09 -08004550 pm8001_dbg(pm8001_ha, DEVIO,
4551 "irq vec %d, ODMR:0x%x\n",
4552 vec, pm8001_cr32(pm8001_ha, 0, 0x30));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304553 process_oq(pm8001_ha, vec);
4554 pm8001_chip_interrupt_enable(pm8001_ha, vec);
jack_wang72d0baa2009-11-05 22:33:35 +08004555 return IRQ_HANDLED;
jack wangdbf9bfe2009-10-14 16:19:21 +08004556}
4557
4558static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
4559 u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag)
4560{
4561 struct task_abort_req task_abort;
4562 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004563 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004564 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4565 memset(&task_abort, 0, sizeof(task_abort));
4566 if (ABORT_SINGLE == (flag & ABORT_MASK)) {
4567 task_abort.abort_all = 0;
4568 task_abort.device_id = cpu_to_le32(dev_id);
4569 task_abort.tag_to_abort = cpu_to_le32(task_tag);
4570 task_abort.tag = cpu_to_le32(cmd_tag);
4571 } else if (ABORT_ALL == (flag & ABORT_MASK)) {
4572 task_abort.abort_all = cpu_to_le32(1);
4573 task_abort.device_id = cpu_to_le32(dev_id);
4574 task_abort.tag = cpu_to_le32(cmd_tag);
4575 }
peter chang91a43fa2019-11-14 15:39:05 +05304576 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
4577 sizeof(task_abort), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004578 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004579}
4580
Lee Jones083645b2020-07-21 17:41:24 +01004581/*
jack wangdbf9bfe2009-10-14 16:19:21 +08004582 * pm8001_chip_abort_task - SAS abort task when error or exception happened.
jack wangdbf9bfe2009-10-14 16:19:21 +08004583 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304584int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004585 struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag)
4586{
4587 u32 opc, device_id;
4588 int rc = TMF_RESP_FUNC_FAILED;
Joe Perches1b5d2792020-11-20 15:16:09 -08004589 pm8001_dbg(pm8001_ha, EH, "cmd_tag = %x, abort task tag = 0x%x\n",
4590 cmd_tag, task_tag);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004591 if (pm8001_dev->dev_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004592 opc = OPC_INB_SSP_ABORT;
James Bottomleyaa9f8322013-05-07 14:44:06 -07004593 else if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004594 opc = OPC_INB_SATA_ABORT;
4595 else
4596 opc = OPC_INB_SMP_ABORT;/* SMP */
4597 device_id = pm8001_dev->device_id;
4598 rc = send_task_abort(pm8001_ha, opc, device_id, flag,
4599 task_tag, cmd_tag);
4600 if (rc != TMF_RESP_FUNC_COMPLETE)
Joe Perches1b5d2792020-11-20 15:16:09 -08004601 pm8001_dbg(pm8001_ha, EH, "rc= %d\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004602 return rc;
4603}
4604
4605/**
Uwe Kleine-König65155b32010-06-11 12:17:01 +02004606 * pm8001_chip_ssp_tm_req - built the task management command.
jack wangdbf9bfe2009-10-14 16:19:21 +08004607 * @pm8001_ha: our hba card information.
4608 * @ccb: the ccb information.
4609 * @tmf: task management function.
4610 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304611int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004612 struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
4613{
4614 struct sas_task *task = ccb->task;
4615 struct domain_device *dev = task->dev;
4616 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4617 u32 opc = OPC_INB_SSPINITMSTART;
4618 struct inbound_queue_table *circularQ;
4619 struct ssp_ini_tm_start_req sspTMCmd;
jack_wang72d0baa2009-11-05 22:33:35 +08004620 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004621
4622 memset(&sspTMCmd, 0, sizeof(sspTMCmd));
4623 sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4624 sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed);
4625 sspTMCmd.tmf = cpu_to_le32(tmf->tmf);
jack wangdbf9bfe2009-10-14 16:19:21 +08004626 memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8);
4627 sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05304628 if (pm8001_ha->chip_id != chip_8001)
4629 sspTMCmd.ds_ads_m = 0x08;
jack wangdbf9bfe2009-10-14 16:19:21 +08004630 circularQ = &pm8001_ha->inbnd_q_tbl[0];
peter chang91a43fa2019-11-14 15:39:05 +05304631 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd,
4632 sizeof(sspTMCmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004633 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004634}
4635
Sakthivel Kf74cf272013-02-27 20:27:43 +05304636int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004637 void *payload)
4638{
4639 u32 opc = OPC_INB_GET_NVMD_DATA;
4640 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004641 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004642 u32 tag;
4643 struct pm8001_ccb_info *ccb;
4644 struct inbound_queue_table *circularQ;
4645 struct get_nvm_data_req nvmd_req;
4646 struct fw_control_ex *fw_control_context;
4647 struct pm8001_ioctl_payload *ioctl_payload = payload;
4648
4649 nvmd_type = ioctl_payload->minor_function;
4650 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004651 if (!fw_control_context)
4652 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304653 fw_control_context->usrAddr = (u8 *)ioctl_payload->func_specific;
Viswas G9b889842020-03-16 13:19:06 +05304654 fw_control_context->len = ioctl_payload->rd_length;
jack wangdbf9bfe2009-10-14 16:19:21 +08004655 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4656 memset(&nvmd_req, 0, sizeof(nvmd_req));
4657 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004658 if (rc) {
4659 kfree(fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08004660 return rc;
Julia Lawall823d2192010-08-01 19:23:35 +02004661 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004662 ccb = &pm8001_ha->ccb_info[tag];
4663 ccb->ccb_tag = tag;
4664 ccb->fw_control_context = fw_control_context;
4665 nvmd_req.tag = cpu_to_le32(tag);
4666
4667 switch (nvmd_type) {
4668 case TWI_DEVICE: {
4669 u32 twi_addr, twi_page_size;
4670 twi_addr = 0xa8;
4671 twi_page_size = 2;
4672
4673 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4674 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304675 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004676 nvmd_req.resp_addr_hi =
4677 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4678 nvmd_req.resp_addr_lo =
4679 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4680 break;
4681 }
4682 case C_SEEPROM: {
4683 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304684 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004685 nvmd_req.resp_addr_hi =
4686 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4687 nvmd_req.resp_addr_lo =
4688 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4689 break;
4690 }
4691 case VPD_FLASH: {
4692 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304693 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004694 nvmd_req.resp_addr_hi =
4695 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4696 nvmd_req.resp_addr_lo =
4697 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4698 break;
4699 }
4700 case EXPAN_ROM: {
4701 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304702 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004703 nvmd_req.resp_addr_hi =
4704 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4705 nvmd_req.resp_addr_lo =
4706 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4707 break;
4708 }
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304709 case IOP_RDUMP: {
4710 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | IOP_RDUMP);
Viswas G9b889842020-03-16 13:19:06 +05304711 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304712 nvmd_req.vpd_offset = cpu_to_le32(ioctl_payload->offset);
4713 nvmd_req.resp_addr_hi =
4714 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4715 nvmd_req.resp_addr_lo =
4716 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4717 break;
4718 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004719 default:
4720 break;
4721 }
peter chang91a43fa2019-11-14 15:39:05 +05304722 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4723 sizeof(nvmd_req), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304724 if (rc) {
4725 kfree(fw_control_context);
4726 pm8001_tag_free(pm8001_ha, tag);
4727 }
jack_wang72d0baa2009-11-05 22:33:35 +08004728 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004729}
4730
Sakthivel Kf74cf272013-02-27 20:27:43 +05304731int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004732 void *payload)
4733{
4734 u32 opc = OPC_INB_SET_NVMD_DATA;
4735 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004736 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004737 u32 tag;
4738 struct pm8001_ccb_info *ccb;
4739 struct inbound_queue_table *circularQ;
4740 struct set_nvm_data_req nvmd_req;
4741 struct fw_control_ex *fw_control_context;
4742 struct pm8001_ioctl_payload *ioctl_payload = payload;
4743
4744 nvmd_type = ioctl_payload->minor_function;
4745 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004746 if (!fw_control_context)
4747 return -ENOMEM;
jack wangdbf9bfe2009-10-14 16:19:21 +08004748 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4749 memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr,
Sakthivel K1c75a672013-03-19 18:06:40 +05304750 &ioctl_payload->func_specific,
Viswas G9b889842020-03-16 13:19:06 +05304751 ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004752 memset(&nvmd_req, 0, sizeof(nvmd_req));
4753 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004754 if (rc) {
4755 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304756 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004757 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004758 ccb = &pm8001_ha->ccb_info[tag];
4759 ccb->fw_control_context = fw_control_context;
4760 ccb->ccb_tag = tag;
4761 nvmd_req.tag = cpu_to_le32(tag);
4762 switch (nvmd_type) {
4763 case TWI_DEVICE: {
4764 u32 twi_addr, twi_page_size;
4765 twi_addr = 0xa8;
4766 twi_page_size = 2;
4767 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4768 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4769 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304770 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004771 nvmd_req.resp_addr_hi =
4772 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4773 nvmd_req.resp_addr_lo =
4774 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4775 break;
4776 }
4777 case C_SEEPROM:
4778 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304779 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004780 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4781 nvmd_req.resp_addr_hi =
4782 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4783 nvmd_req.resp_addr_lo =
4784 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4785 break;
4786 case VPD_FLASH:
4787 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304788 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004789 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4790 nvmd_req.resp_addr_hi =
4791 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4792 nvmd_req.resp_addr_lo =
4793 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4794 break;
4795 case EXPAN_ROM:
4796 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304797 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004798 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4799 nvmd_req.resp_addr_hi =
4800 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4801 nvmd_req.resp_addr_lo =
4802 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4803 break;
4804 default:
4805 break;
4806 }
peter chang91a43fa2019-11-14 15:39:05 +05304807 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4808 sizeof(nvmd_req), 0);
Tomas Henzl9422e862014-07-07 17:20:00 +02004809 if (rc) {
4810 kfree(fw_control_context);
4811 pm8001_tag_free(pm8001_ha, tag);
4812 }
jack_wang72d0baa2009-11-05 22:33:35 +08004813 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004814}
4815
4816/**
4817 * pm8001_chip_fw_flash_update_build - support the firmware update operation
4818 * @pm8001_ha: our hba card information.
4819 * @fw_flash_updata_info: firmware flash update param
Lee Jones083645b2020-07-21 17:41:24 +01004820 * @tag: Tag to apply to the payload
jack wangdbf9bfe2009-10-14 16:19:21 +08004821 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304822int
jack wangdbf9bfe2009-10-14 16:19:21 +08004823pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
4824 void *fw_flash_updata_info, u32 tag)
4825{
4826 struct fw_flash_Update_req payload;
4827 struct fw_flash_updata_info *info;
4828 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004829 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004830 u32 opc = OPC_INB_FW_FLASH_UPDATE;
4831
jack_wang72d0baa2009-11-05 22:33:35 +08004832 memset(&payload, 0, sizeof(struct fw_flash_Update_req));
jack wangdbf9bfe2009-10-14 16:19:21 +08004833 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4834 info = fw_flash_updata_info;
4835 payload.tag = cpu_to_le32(tag);
4836 payload.cur_image_len = cpu_to_le32(info->cur_image_len);
4837 payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
4838 payload.total_image_len = cpu_to_le32(info->total_image_len);
4839 payload.len = info->sgl.im_len.len ;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304840 payload.sgl_addr_lo =
4841 cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr)));
4842 payload.sgl_addr_hi =
4843 cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr)));
peter chang91a43fa2019-11-14 15:39:05 +05304844 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4845 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004846 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004847}
4848
Sakthivel Kf74cf272013-02-27 20:27:43 +05304849int
jack wangdbf9bfe2009-10-14 16:19:21 +08004850pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
4851 void *payload)
4852{
4853 struct fw_flash_updata_info flash_update_info;
4854 struct fw_control_info *fw_control;
4855 struct fw_control_ex *fw_control_context;
jack_wang72d0baa2009-11-05 22:33:35 +08004856 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004857 u32 tag;
4858 struct pm8001_ccb_info *ccb;
Sakthivel K1c75a672013-03-19 18:06:40 +05304859 void *buffer = pm8001_ha->memoryMap.region[FW_FLASH].virt_ptr;
4860 dma_addr_t phys_addr = pm8001_ha->memoryMap.region[FW_FLASH].phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004861 struct pm8001_ioctl_payload *ioctl_payload = payload;
4862
4863 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004864 if (!fw_control_context)
4865 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304866 fw_control = (struct fw_control_info *)&ioctl_payload->func_specific;
Joe Perches1b5d2792020-11-20 15:16:09 -08004867 pm8001_dbg(pm8001_ha, DEVIO,
4868 "dma fw_control context input length :%x\n",
4869 fw_control->len);
jack_wang72d0baa2009-11-05 22:33:35 +08004870 memcpy(buffer, fw_control->buffer, fw_control->len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004871 flash_update_info.sgl.addr = cpu_to_le64(phys_addr);
4872 flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len);
4873 flash_update_info.sgl.im_len.e = 0;
4874 flash_update_info.cur_image_offset = fw_control->offset;
4875 flash_update_info.cur_image_len = fw_control->len;
4876 flash_update_info.total_image_len = fw_control->size;
4877 fw_control_context->fw_control = fw_control;
4878 fw_control_context->virtAddr = buffer;
Sakthivel K1c75a672013-03-19 18:06:40 +05304879 fw_control_context->phys_addr = phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004880 fw_control_context->len = fw_control->len;
4881 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004882 if (rc) {
4883 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304884 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004885 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004886 ccb = &pm8001_ha->ccb_info[tag];
4887 ccb->fw_control_context = fw_control_context;
4888 ccb->ccb_tag = tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004889 rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
4890 tag);
4891 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004892}
4893
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304894ssize_t
4895pm8001_get_gsm_dump(struct device *cdev, u32 length, char *buf)
4896{
4897 u32 value, rem, offset = 0, bar = 0;
4898 u32 index, work_offset, dw_length;
4899 u32 shift_value, gsm_base, gsm_dump_offset;
4900 char *direct_data;
4901 struct Scsi_Host *shost = class_to_shost(cdev);
4902 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
4903 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
4904
4905 direct_data = buf;
4906 gsm_dump_offset = pm8001_ha->fatal_forensic_shift_offset;
4907
4908 /* check max is 1 Mbytes */
4909 if ((length > 0x100000) || (gsm_dump_offset & 3) ||
4910 ((gsm_dump_offset + length) > 0x1000000))
Viswas Gcf370062013-12-10 10:31:38 +05304911 return -EINVAL;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304912
4913 if (pm8001_ha->chip_id == chip_8001)
4914 bar = 2;
4915 else
4916 bar = 1;
4917
4918 work_offset = gsm_dump_offset & 0xFFFF0000;
4919 offset = gsm_dump_offset & 0x0000FFFF;
4920 gsm_dump_offset = work_offset;
4921 /* adjust length to dword boundary */
4922 rem = length & 3;
4923 dw_length = length >> 2;
4924
4925 for (index = 0; index < dw_length; index++) {
4926 if ((work_offset + offset) & 0xFFFF0000) {
4927 if (pm8001_ha->chip_id == chip_8001)
4928 shift_value = ((gsm_dump_offset + offset) &
4929 SHIFT_REG_64K_MASK);
4930 else
4931 shift_value = (((gsm_dump_offset + offset) &
4932 SHIFT_REG_64K_MASK) >>
4933 SHIFT_REG_BIT_SHIFT);
4934
4935 if (pm8001_ha->chip_id == chip_8001) {
4936 gsm_base = GSM_BASE;
4937 if (-1 == pm8001_bar4_shift(pm8001_ha,
4938 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05304939 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304940 } else {
4941 gsm_base = 0;
4942 if (-1 == pm80xx_bar4_shift(pm8001_ha,
4943 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05304944 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304945 }
4946 gsm_dump_offset = (gsm_dump_offset + offset) &
4947 0xFFFF0000;
4948 work_offset = 0;
4949 offset = offset & 0x0000FFFF;
4950 }
4951 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
4952 0x0000FFFF);
4953 direct_data += sprintf(direct_data, "%08x ", value);
4954 offset += 4;
4955 }
4956 if (rem != 0) {
4957 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
4958 0x0000FFFF);
4959 /* xfr for non_dw */
4960 direct_data += sprintf(direct_data, "%08x ", value);
4961 }
4962 /* Shift back to BAR4 original address */
Viswas G859b5d12013-12-10 10:31:28 +05304963 if (-1 == pm8001_bar4_shift(pm8001_ha, 0))
Viswas Gcf370062013-12-10 10:31:38 +05304964 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05304965 pm8001_ha->fatal_forensic_shift_offset += 1024;
4966
4967 if (pm8001_ha->fatal_forensic_shift_offset >= 0x100000)
4968 pm8001_ha->fatal_forensic_shift_offset = 0;
4969 return direct_data - buf;
4970}
4971
Sakthivel Kf74cf272013-02-27 20:27:43 +05304972int
jack wangdbf9bfe2009-10-14 16:19:21 +08004973pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
4974 struct pm8001_device *pm8001_dev, u32 state)
4975{
4976 struct set_dev_state_req payload;
4977 struct inbound_queue_table *circularQ;
4978 struct pm8001_ccb_info *ccb;
jack_wang72d0baa2009-11-05 22:33:35 +08004979 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004980 u32 tag;
4981 u32 opc = OPC_INB_SET_DEVICE_STATE;
jack_wang72d0baa2009-11-05 22:33:35 +08004982 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08004983 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4984 if (rc)
4985 return -1;
4986 ccb = &pm8001_ha->ccb_info[tag];
4987 ccb->ccb_tag = tag;
4988 ccb->device = pm8001_dev;
4989 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4990 payload.tag = cpu_to_le32(tag);
4991 payload.device_id = cpu_to_le32(pm8001_dev->device_id);
4992 payload.nds = cpu_to_le32(state);
peter chang91a43fa2019-11-14 15:39:05 +05304993 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4994 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004995 return rc;
4996
jack_wangd0b68042009-11-05 22:32:31 +08004997}
4998
4999static int
5000pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
5001{
5002 struct sas_re_initialization_req payload;
5003 struct inbound_queue_table *circularQ;
5004 struct pm8001_ccb_info *ccb;
5005 int rc;
5006 u32 tag;
5007 u32 opc = OPC_INB_SAS_RE_INITIALIZE;
5008 memset(&payload, 0, sizeof(payload));
5009 rc = pm8001_tag_alloc(pm8001_ha, &tag);
5010 if (rc)
Tomas Henzl5533abc2014-07-09 17:20:49 +05305011 return -ENOMEM;
jack_wangd0b68042009-11-05 22:32:31 +08005012 ccb = &pm8001_ha->ccb_info[tag];
5013 ccb->ccb_tag = tag;
5014 circularQ = &pm8001_ha->inbnd_q_tbl[0];
5015 payload.tag = cpu_to_le32(tag);
5016 payload.SSAHOLT = cpu_to_le32(0xd << 25);
5017 payload.sata_hol_tmo = cpu_to_le32(80);
5018 payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff);
peter chang91a43fa2019-11-14 15:39:05 +05305019 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
5020 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05305021 if (rc)
5022 pm8001_tag_free(pm8001_ha, tag);
jack_wangd0b68042009-11-05 22:32:31 +08005023 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005024
5025}
5026
5027const struct pm8001_dispatch pm8001_8001_dispatch = {
5028 .name = "pmc8001",
5029 .chip_init = pm8001_chip_init,
5030 .chip_soft_rst = pm8001_chip_soft_rst,
5031 .chip_rst = pm8001_hw_chip_rst,
5032 .chip_iounmap = pm8001_chip_iounmap,
5033 .isr = pm8001_chip_isr,
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00005034 .is_our_interrupt = pm8001_chip_is_our_interrupt,
jack wangdbf9bfe2009-10-14 16:19:21 +08005035 .isr_process_oq = process_oq,
5036 .interrupt_enable = pm8001_chip_interrupt_enable,
5037 .interrupt_disable = pm8001_chip_interrupt_disable,
5038 .make_prd = pm8001_chip_make_sg,
5039 .smp_req = pm8001_chip_smp_req,
5040 .ssp_io_req = pm8001_chip_ssp_io_req,
5041 .sata_req = pm8001_chip_sata_req,
5042 .phy_start_req = pm8001_chip_phy_start_req,
5043 .phy_stop_req = pm8001_chip_phy_stop_req,
5044 .reg_dev_req = pm8001_chip_reg_dev_req,
5045 .dereg_dev_req = pm8001_chip_dereg_dev_req,
5046 .phy_ctl_req = pm8001_chip_phy_ctl_req,
5047 .task_abort = pm8001_chip_abort_task,
5048 .ssp_tm_req = pm8001_chip_ssp_tm_req,
5049 .get_nvmd_req = pm8001_chip_get_nvmd_req,
5050 .set_nvmd_req = pm8001_chip_set_nvmd_req,
5051 .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
5052 .set_dev_state_req = pm8001_chip_set_dev_state_req,
jack_wangd0b68042009-11-05 22:32:31 +08005053 .sas_re_init_req = pm8001_chip_sas_re_initialization,
akshatzena961ea02021-01-09 18:08:43 +05305054 .fatal_errors = pm80xx_fatal_errors,
jack wangdbf9bfe2009-10-14 16:19:21 +08005055};