blob: 0a1e09b1cd5807c26f3f63a7169f20c1338f7716 [file] [log] [blame]
jack wangdbf9bfe2009-10-14 16:19:21 +08001/*
2 * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
3 *
4 * Copyright (c) 2008-2009 USI Co., Ltd.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * substantially similar to the "NO WARRANTY" disclaimer below
15 * ("Disclaimer") and any redistribution must be conditioned upon
16 * including a substantially similar Disclaimer requirement for further
17 * binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * Alternatively, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2 as published by the Free
24 * Software Foundation.
25 *
26 * NO WARRANTY
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
38 *
39 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040 #include <linux/slab.h>
jack wangdbf9bfe2009-10-14 16:19:21 +080041 #include "pm8001_sas.h"
42 #include "pm8001_hwi.h"
43 #include "pm8001_chips.h"
44 #include "pm8001_ctl.h"
45
46/**
47 * read_main_config_table - read the configure table and save it.
48 * @pm8001_ha: our hba card information
49 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080050static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +080051{
52 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
Sakthivel Ke5742102013-04-17 16:26:36 +053053 pm8001_ha->main_cfg_tbl.pm8001_tbl.signature =
54 pm8001_mr32(address, 0x00);
55 pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev =
56 pm8001_mr32(address, 0x04);
57 pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev =
58 pm8001_mr32(address, 0x08);
59 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io =
60 pm8001_mr32(address, 0x0C);
61 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl =
62 pm8001_mr32(address, 0x10);
63 pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag =
64 pm8001_mr32(address, 0x14);
65 pm8001_ha->main_cfg_tbl.pm8001_tbl.gst_offset =
66 pm8001_mr32(address, 0x18);
67 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_queue_offset =
jack_wangd0b68042009-11-05 22:32:31 +080068 pm8001_mr32(address, MAIN_IBQ_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053069 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_queue_offset =
jack_wangd0b68042009-11-05 22:32:31 +080070 pm8001_mr32(address, MAIN_OBQ_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053071 pm8001_ha->main_cfg_tbl.pm8001_tbl.hda_mode_flag =
jack wangdbf9bfe2009-10-14 16:19:21 +080072 pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET);
73
74 /* read analog Setting offset from the configuration table */
Sakthivel Ke5742102013-04-17 16:26:36 +053075 pm8001_ha->main_cfg_tbl.pm8001_tbl.anolog_setup_table_offset =
jack wangdbf9bfe2009-10-14 16:19:21 +080076 pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
77
78 /* read Error Dump Offset and Length */
Sakthivel Ke5742102013-04-17 16:26:36 +053079 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset0 =
jack wangdbf9bfe2009-10-14 16:19:21 +080080 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053081 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length0 =
jack wangdbf9bfe2009-10-14 16:19:21 +080082 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
Sakthivel Ke5742102013-04-17 16:26:36 +053083 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset1 =
jack wangdbf9bfe2009-10-14 16:19:21 +080084 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
Sakthivel Ke5742102013-04-17 16:26:36 +053085 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length1 =
jack wangdbf9bfe2009-10-14 16:19:21 +080086 pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
87}
88
89/**
90 * read_general_status_table - read the general status table and save it.
91 * @pm8001_ha: our hba card information
92 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080093static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +080094{
95 void __iomem *address = pm8001_ha->general_stat_tbl_addr;
Sakthivel Ke5742102013-04-17 16:26:36 +053096 pm8001_ha->gs_tbl.pm8001_tbl.gst_len_mpistate =
97 pm8001_mr32(address, 0x00);
98 pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state0 =
99 pm8001_mr32(address, 0x04);
100 pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state1 =
101 pm8001_mr32(address, 0x08);
102 pm8001_ha->gs_tbl.pm8001_tbl.msgu_tcnt =
103 pm8001_mr32(address, 0x0C);
104 pm8001_ha->gs_tbl.pm8001_tbl.iop_tcnt =
105 pm8001_mr32(address, 0x10);
106 pm8001_ha->gs_tbl.pm8001_tbl.rsvd =
107 pm8001_mr32(address, 0x14);
108 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[0] =
109 pm8001_mr32(address, 0x18);
110 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[1] =
111 pm8001_mr32(address, 0x1C);
112 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[2] =
113 pm8001_mr32(address, 0x20);
114 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[3] =
115 pm8001_mr32(address, 0x24);
116 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[4] =
117 pm8001_mr32(address, 0x28);
118 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[5] =
119 pm8001_mr32(address, 0x2C);
120 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[6] =
121 pm8001_mr32(address, 0x30);
122 pm8001_ha->gs_tbl.pm8001_tbl.phy_state[7] =
123 pm8001_mr32(address, 0x34);
124 pm8001_ha->gs_tbl.pm8001_tbl.gpio_input_val =
125 pm8001_mr32(address, 0x38);
126 pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[0] =
127 pm8001_mr32(address, 0x3C);
128 pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[1] =
129 pm8001_mr32(address, 0x40);
130 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[0] =
131 pm8001_mr32(address, 0x44);
132 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[1] =
133 pm8001_mr32(address, 0x48);
134 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[2] =
135 pm8001_mr32(address, 0x4C);
136 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[3] =
137 pm8001_mr32(address, 0x50);
138 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[4] =
139 pm8001_mr32(address, 0x54);
140 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[5] =
141 pm8001_mr32(address, 0x58);
142 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[6] =
143 pm8001_mr32(address, 0x5C);
144 pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[7] =
145 pm8001_mr32(address, 0x60);
jack wangdbf9bfe2009-10-14 16:19:21 +0800146}
147
148/**
149 * read_inbnd_queue_table - read the inbound queue table and save it.
150 * @pm8001_ha: our hba card information
151 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800152static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800153{
jack wangdbf9bfe2009-10-14 16:19:21 +0800154 int i;
155 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530156 for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
jack_wangd0b68042009-11-05 22:32:31 +0800157 u32 offset = i * 0x20;
jack wangdbf9bfe2009-10-14 16:19:21 +0800158 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
159 get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
160 pm8001_ha->inbnd_q_tbl[i].pi_offset =
161 pm8001_mr32(address, (offset + 0x18));
162 }
163}
164
165/**
166 * read_outbnd_queue_table - read the outbound queue table and save it.
167 * @pm8001_ha: our hba card information
168 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800169static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800170{
jack wangdbf9bfe2009-10-14 16:19:21 +0800171 int i;
172 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530173 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800174 u32 offset = i * 0x24;
175 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
176 get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
177 pm8001_ha->outbnd_q_tbl[i].ci_offset =
178 pm8001_mr32(address, (offset + 0x18));
179 }
180}
181
182/**
183 * init_default_table_values - init the default table.
184 * @pm8001_ha: our hba card information
185 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800186static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800187{
jack wangdbf9bfe2009-10-14 16:19:21 +0800188 int i;
189 u32 offsetib, offsetob;
190 void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
191 void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
Viswas G05c6c022020-10-05 20:20:08 +0530192 u32 ib_offset = pm8001_ha->ib_offset;
193 u32 ob_offset = pm8001_ha->ob_offset;
194 u32 ci_offset = pm8001_ha->ci_offset;
195 u32 pi_offset = pm8001_ha->pi_offset;
jack wangdbf9bfe2009-10-14 16:19:21 +0800196
Sakthivel Ke5742102013-04-17 16:26:36 +0530197 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd = 0;
198 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3 = 0;
199 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7 = 0;
200 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3 = 0;
201 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7 = 0;
202 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid0_3 =
203 0;
204 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid4_7 =
205 0;
206 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid0_3 = 0;
207 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid4_7 = 0;
208 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid0_3 = 0;
209 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid4_7 = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +0800210
Sakthivel Ke5742102013-04-17 16:26:36 +0530211 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800212 pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
Sakthivel Ke5742102013-04-17 16:26:36 +0530213 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800214 pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
Sakthivel Ke5742102013-04-17 16:26:36 +0530215 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size =
216 PM8001_EVENT_LOG_SIZE;
217 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option = 0x01;
218 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800219 pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
Sakthivel Ke5742102013-04-17 16:26:36 +0530220 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr =
jack wangdbf9bfe2009-10-14 16:19:21 +0800221 pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
Sakthivel Ke5742102013-04-17 16:26:36 +0530222 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size =
223 PM8001_EVENT_LOG_SIZE;
224 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option = 0x01;
225 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt = 0x01;
226 for (i = 0; i < PM8001_MAX_INB_NUM; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800227 pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200228 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800229 pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530230 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800231 pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530232 pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800233 pm8001_ha->inbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530234 (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800235 pm8001_ha->inbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530236 pm8001_ha->memoryMap.region[ib_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800237 pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530238 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800239 pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530240 pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800241 pm8001_ha->inbnd_q_tbl[i].ci_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530242 pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800243 offsetib = i * 0x20;
244 pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
245 get_pci_bar_index(pm8001_mr32(addressib,
246 (offsetib + 0x14)));
247 pm8001_ha->inbnd_q_tbl[i].pi_offset =
248 pm8001_mr32(addressib, (offsetib + 0x18));
249 pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
250 pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
251 }
Sakthivel Ke5742102013-04-17 16:26:36 +0530252 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800253 pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
Hans Verkuil9504a922013-07-26 18:43:45 +0200254 PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
jack wangdbf9bfe2009-10-14 16:19:21 +0800255 pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530256 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800257 pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530258 pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800259 pm8001_ha->outbnd_q_tbl[i].base_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530260 (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800261 pm8001_ha->outbnd_q_tbl[i].total_length =
Viswas G05c6c022020-10-05 20:20:08 +0530262 pm8001_ha->memoryMap.region[ob_offset + i].total_len;
jack wangdbf9bfe2009-10-14 16:19:21 +0800263 pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530264 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +0800265 pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
Viswas G05c6c022020-10-05 20:20:08 +0530266 pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo;
jack wangdbf9bfe2009-10-14 16:19:21 +0800267 pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530268 0 | (10 << 16) | (i << 24);
jack wangdbf9bfe2009-10-14 16:19:21 +0800269 pm8001_ha->outbnd_q_tbl[i].pi_virt =
Viswas G05c6c022020-10-05 20:20:08 +0530270 pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800271 offsetob = i * 0x24;
272 pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
273 get_pci_bar_index(pm8001_mr32(addressob,
274 offsetob + 0x14));
275 pm8001_ha->outbnd_q_tbl[i].ci_offset =
276 pm8001_mr32(addressob, (offsetob + 0x18));
277 pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
278 pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
279 }
280}
281
282/**
283 * update_main_config_table - update the main default table to the HBA.
284 * @pm8001_ha: our hba card information
285 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800286static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800287{
288 void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
289 pm8001_mw32(address, 0x24,
Sakthivel Ke5742102013-04-17 16:26:36 +0530290 pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd);
jack wangdbf9bfe2009-10-14 16:19:21 +0800291 pm8001_mw32(address, 0x28,
Sakthivel Ke5742102013-04-17 16:26:36 +0530292 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800293 pm8001_mw32(address, 0x2C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530294 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800295 pm8001_mw32(address, 0x30,
Sakthivel Ke5742102013-04-17 16:26:36 +0530296 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800297 pm8001_mw32(address, 0x34,
Sakthivel Ke5742102013-04-17 16:26:36 +0530298 pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800299 pm8001_mw32(address, 0x38,
Sakthivel Ke5742102013-04-17 16:26:36 +0530300 pm8001_ha->main_cfg_tbl.pm8001_tbl.
301 outbound_tgt_ITNexus_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800302 pm8001_mw32(address, 0x3C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530303 pm8001_ha->main_cfg_tbl.pm8001_tbl.
304 outbound_tgt_ITNexus_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800305 pm8001_mw32(address, 0x40,
Sakthivel Ke5742102013-04-17 16:26:36 +0530306 pm8001_ha->main_cfg_tbl.pm8001_tbl.
307 outbound_tgt_ssp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800308 pm8001_mw32(address, 0x44,
Sakthivel Ke5742102013-04-17 16:26:36 +0530309 pm8001_ha->main_cfg_tbl.pm8001_tbl.
310 outbound_tgt_ssp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800311 pm8001_mw32(address, 0x48,
Sakthivel Ke5742102013-04-17 16:26:36 +0530312 pm8001_ha->main_cfg_tbl.pm8001_tbl.
313 outbound_tgt_smp_event_pid0_3);
jack wangdbf9bfe2009-10-14 16:19:21 +0800314 pm8001_mw32(address, 0x4C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530315 pm8001_ha->main_cfg_tbl.pm8001_tbl.
316 outbound_tgt_smp_event_pid4_7);
jack wangdbf9bfe2009-10-14 16:19:21 +0800317 pm8001_mw32(address, 0x50,
Sakthivel Ke5742102013-04-17 16:26:36 +0530318 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800319 pm8001_mw32(address, 0x54,
Sakthivel Ke5742102013-04-17 16:26:36 +0530320 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr);
321 pm8001_mw32(address, 0x58,
322 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size);
323 pm8001_mw32(address, 0x5C,
324 pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800325 pm8001_mw32(address, 0x60,
Sakthivel Ke5742102013-04-17 16:26:36 +0530326 pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800327 pm8001_mw32(address, 0x64,
Sakthivel Ke5742102013-04-17 16:26:36 +0530328 pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr);
329 pm8001_mw32(address, 0x68,
330 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size);
jack wangdbf9bfe2009-10-14 16:19:21 +0800331 pm8001_mw32(address, 0x6C,
Sakthivel Ke5742102013-04-17 16:26:36 +0530332 pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option);
jack wangdbf9bfe2009-10-14 16:19:21 +0800333 pm8001_mw32(address, 0x70,
Sakthivel Ke5742102013-04-17 16:26:36 +0530334 pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt);
jack wangdbf9bfe2009-10-14 16:19:21 +0800335}
336
337/**
338 * update_inbnd_queue_table - update the inbound queue table to the HBA.
339 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100340 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800341 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800342static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
343 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800344{
345 void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
346 u16 offset = number * 0x20;
347 pm8001_mw32(address, offset + 0x00,
348 pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
349 pm8001_mw32(address, offset + 0x04,
350 pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
351 pm8001_mw32(address, offset + 0x08,
352 pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
353 pm8001_mw32(address, offset + 0x0C,
354 pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
355 pm8001_mw32(address, offset + 0x10,
356 pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
357}
358
359/**
360 * update_outbnd_queue_table - update the outbound queue table to the HBA.
361 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100362 * @number: entry in the queue
jack wangdbf9bfe2009-10-14 16:19:21 +0800363 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800364static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
365 int number)
jack wangdbf9bfe2009-10-14 16:19:21 +0800366{
367 void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
368 u16 offset = number * 0x24;
369 pm8001_mw32(address, offset + 0x00,
370 pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
371 pm8001_mw32(address, offset + 0x04,
372 pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
373 pm8001_mw32(address, offset + 0x08,
374 pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
375 pm8001_mw32(address, offset + 0x0C,
376 pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
377 pm8001_mw32(address, offset + 0x10,
378 pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
379 pm8001_mw32(address, offset + 0x1C,
380 pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
381}
382
383/**
Mark Salyzynd95d0002012-01-17 09:18:57 -0500384 * pm8001_bar4_shift - function is called to shift BAR base address
385 * @pm8001_ha : our hba card infomation
jack wangdbf9bfe2009-10-14 16:19:21 +0800386 * @shiftValue : shifting value in memory bar.
387 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500388int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue)
jack wangdbf9bfe2009-10-14 16:19:21 +0800389{
390 u32 regVal;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500391 unsigned long start;
jack wangdbf9bfe2009-10-14 16:19:21 +0800392
393 /* program the inbound AXI translation Lower Address */
394 pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue);
395
396 /* confirm the setting is written */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500397 start = jiffies + HZ; /* 1 sec */
jack wangdbf9bfe2009-10-14 16:19:21 +0800398 do {
jack wangdbf9bfe2009-10-14 16:19:21 +0800399 regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW);
Mark Salyzynd95d0002012-01-17 09:18:57 -0500400 } while ((regVal != shiftValue) && time_before(jiffies, start));
jack wangdbf9bfe2009-10-14 16:19:21 +0800401
Mark Salyzynd95d0002012-01-17 09:18:57 -0500402 if (regVal != shiftValue) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800403 PM8001_INIT_DBG(pm8001_ha,
404 pm8001_printk("TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW"
405 " = 0x%x\n", regVal));
406 return -1;
407 }
408 return 0;
409}
410
411/**
412 * mpi_set_phys_g3_with_ssc
413 * @pm8001_ha: our hba card information
414 * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc.
415 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800416static void mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha,
417 u32 SSCbit)
jack wangdbf9bfe2009-10-14 16:19:21 +0800418{
Lee Jonesa364a3e2020-11-16 10:41:19 +0000419 u32 offset, i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500420 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800421
422#define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000
423#define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000
424#define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074
425#define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074
jack_wangd0b68042009-11-05 22:32:31 +0800426#define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12
427#define PHY_G3_WITH_SSC_BIT_SHIFT 13
428#define SNW3_PHY_CAPABILITIES_PARITY 31
jack wangdbf9bfe2009-10-14 16:19:21 +0800429
430 /*
431 * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3)
432 * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7)
433 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500434 spin_lock_irqsave(&pm8001_ha->lock, flags);
435 if (-1 == pm8001_bar4_shift(pm8001_ha,
436 SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) {
437 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800438 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500439 }
jack wang0330dba2009-12-07 17:46:22 +0800440
jack wangdbf9bfe2009-10-14 16:19:21 +0800441 for (i = 0; i < 4; i++) {
442 offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i;
jack wang0330dba2009-12-07 17:46:22 +0800443 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800444 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800445 /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500446 if (-1 == pm8001_bar4_shift(pm8001_ha,
447 SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) {
448 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800449 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500450 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800451 for (i = 4; i < 8; i++) {
452 offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
jack wang0330dba2009-12-07 17:46:22 +0800453 pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
jack wangdbf9bfe2009-10-14 16:19:21 +0800454 }
jack wang0330dba2009-12-07 17:46:22 +0800455 /*************************************************************
456 Change the SSC upspreading value to 0x0 so that upspreading is disabled.
457 Device MABC SMOD0 Controls
458 Address: (via MEMBASE-III):
459 Using shifted destination address 0x0_0000: with Offset 0xD8
460
461 31:28 R/W Reserved Do not change
462 27:24 R/W SAS_SMOD_SPRDUP 0000
463 23:20 R/W SAS_SMOD_SPRDDN 0000
464 19:0 R/W Reserved Do not change
465 Upon power-up this register will read as 0x8990c016,
466 and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000
467 so that the written value will be 0x8090c016.
468 This will ensure only down-spreading SSC is enabled on the SPC.
469 *************************************************************/
Lee Jonesa364a3e2020-11-16 10:41:19 +0000470 pm8001_cr32(pm8001_ha, 2, 0xd8);
jack wang0330dba2009-12-07 17:46:22 +0800471 pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016);
jack wangdbf9bfe2009-10-14 16:19:21 +0800472
473 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500474 pm8001_bar4_shift(pm8001_ha, 0x0);
475 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800476 return;
477}
478
479/**
480 * mpi_set_open_retry_interval_reg
481 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +0100482 * @interval: interval time for each OPEN_REJECT (RETRY). The units are in 1us.
jack wangdbf9bfe2009-10-14 16:19:21 +0800483 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800484static void mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha,
485 u32 interval)
jack wangdbf9bfe2009-10-14 16:19:21 +0800486{
487 u32 offset;
488 u32 value;
489 u32 i;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500490 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800491
492#define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000
493#define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000
494#define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4
495#define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4
496#define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF
497
498 value = interval & OPEN_RETRY_INTERVAL_REG_MASK;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500499 spin_lock_irqsave(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800500 /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/
Mark Salyzynd95d0002012-01-17 09:18:57 -0500501 if (-1 == pm8001_bar4_shift(pm8001_ha,
502 OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) {
503 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800504 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500505 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800506 for (i = 0; i < 4; i++) {
507 offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i;
508 pm8001_cw32(pm8001_ha, 2, offset, value);
509 }
510
Mark Salyzynd95d0002012-01-17 09:18:57 -0500511 if (-1 == pm8001_bar4_shift(pm8001_ha,
512 OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) {
513 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800514 return;
Mark Salyzynd95d0002012-01-17 09:18:57 -0500515 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800516 for (i = 4; i < 8; i++) {
517 offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
518 pm8001_cw32(pm8001_ha, 2, offset, value);
519 }
520 /*set the shifted destination address to 0x0 to avoid error operation */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500521 pm8001_bar4_shift(pm8001_ha, 0x0);
522 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800523 return;
524}
525
526/**
527 * mpi_init_check - check firmware initialization status.
528 * @pm8001_ha: our hba card information
529 */
530static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
531{
532 u32 max_wait_count;
533 u32 value;
534 u32 gst_len_mpistate;
535 /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
536 table is updated */
537 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE);
538 /* wait until Inbound DoorBell Clear Register toggled */
539 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
540 do {
541 udelay(1);
542 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
543 value &= SPC_MSGU_CFG_TABLE_UPDATE;
544 } while ((value != 0) && (--max_wait_count));
545
546 if (!max_wait_count)
547 return -1;
548 /* check the MPI-State for initialization */
549 gst_len_mpistate =
550 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
551 GST_GSTLEN_MPIS_OFFSET);
552 if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK))
553 return -1;
554 /* check MPI Initialization error */
555 gst_len_mpistate = gst_len_mpistate >> 16;
556 if (0x0000 != gst_len_mpistate)
557 return -1;
558 return 0;
559}
560
561/**
562 * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
563 * @pm8001_ha: our hba card information
564 */
565static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
566{
567 u32 value, value1;
568 u32 max_wait_count;
569 /* check error state */
570 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
571 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
572 /* check AAP error */
573 if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) {
574 /* error state */
575 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
576 return -1;
577 }
578
579 /* check IOP error */
580 if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) {
581 /* error state */
582 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
583 return -1;
584 }
585
586 /* bit 4-31 of scratch pad1 should be zeros if it is not
587 in error state*/
588 if (value & SCRATCH_PAD1_STATE_MASK) {
589 /* error case */
590 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
591 return -1;
592 }
593
594 /* bit 2, 4-31 of scratch pad2 should be zeros if it is not
595 in error state */
596 if (value1 & SCRATCH_PAD2_STATE_MASK) {
597 /* error case */
598 return -1;
599 }
600
601 max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */
602
603 /* wait until scratch pad 1 and 2 registers in ready state */
604 do {
605 udelay(1);
606 value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
607 & SCRATCH_PAD1_RDY;
608 value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
609 & SCRATCH_PAD2_RDY;
610 if ((--max_wait_count) == 0)
611 return -1;
612 } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY));
613 return 0;
614}
615
616static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
617{
618 void __iomem *base_addr;
619 u32 value;
620 u32 offset;
621 u32 pcibar;
622 u32 pcilogic;
623
624 value = pm8001_cr32(pm8001_ha, 0, 0x44);
625 offset = value & 0x03FFFFFF;
626 PM8001_INIT_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -0700627 pm8001_printk("Scratchpad 0 Offset: %x\n", offset));
jack wangdbf9bfe2009-10-14 16:19:21 +0800628 pcilogic = (value & 0xFC000000) >> 26;
629 pcibar = get_pci_bar_index(pcilogic);
630 PM8001_INIT_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -0700631 pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar));
jack wangdbf9bfe2009-10-14 16:19:21 +0800632 pm8001_ha->main_cfg_tbl_addr = base_addr =
633 pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
634 pm8001_ha->general_stat_tbl_addr =
635 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18);
636 pm8001_ha->inbnd_q_tbl_addr =
637 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C);
638 pm8001_ha->outbnd_q_tbl_addr =
639 base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20);
640}
641
642/**
643 * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
644 * @pm8001_ha: our hba card information
645 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800646static int pm8001_chip_init(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800647{
Sakthivel Ke590adf2013-02-27 20:25:25 +0530648 u8 i = 0;
Sakthivel K54792dc2013-03-19 18:05:55 +0530649 u16 deviceid;
650 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
651 /* 8081 controllers need BAR shift to access MPI space
652 * as this is shared with BIOS data */
Bradley Grove81b86d42013-12-19 10:50:57 -0500653 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530654 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
655 PM8001_FAIL_DBG(pm8001_ha,
656 pm8001_printk("Shift Bar4 to 0x%x failed\n",
657 GSM_SM_BASE));
658 return -1;
659 }
660 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800661 /* check the firmware status */
662 if (-1 == check_fw_ready(pm8001_ha)) {
663 PM8001_FAIL_DBG(pm8001_ha,
664 pm8001_printk("Firmware is not ready!\n"));
665 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);
Sakthivel Ke590adf2013-02-27 20:25:25 +0530677 for (i = 0; i < PM8001_MAX_INB_NUM; i++)
678 update_inbnd_queue_table(pm8001_ha, i);
679 for (i = 0; i < PM8001_MAX_OUTB_NUM; i++)
680 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)) {
689 PM8001_INIT_DBG(pm8001_ha,
690 pm8001_printk("MPI initialize successful!\n"));
691 } else
692 return -EBUSY;
693 /*This register is a 16-bit timer with a resolution of 1us. This is the
694 timer used for interrupt delay/coalescing in the PCIe Application Layer.
695 Zero is not a valid value. A value of 1 in the register will cause the
696 interrupts to be normal. A value greater than 1 will cause coalescing
697 delays.*/
698 pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1);
699 pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0);
700 return 0;
701}
702
703static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
704{
705 u32 max_wait_count;
706 u32 value;
707 u32 gst_len_mpistate;
Sakthivel K54792dc2013-03-19 18:05:55 +0530708 u16 deviceid;
709 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
Bradley Grove81b86d42013-12-19 10:50:57 -0500710 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel K54792dc2013-03-19 18:05:55 +0530711 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) {
712 PM8001_FAIL_DBG(pm8001_ha,
713 pm8001_printk("Shift Bar4 to 0x%x failed\n",
714 GSM_SM_BASE));
715 return -1;
716 }
717 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800718 init_pci_device_addresses(pm8001_ha);
719 /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
720 table is stop */
721 pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET);
722
723 /* wait until Inbound DoorBell Clear Register toggled */
724 max_wait_count = 1 * 1000 * 1000;/* 1 sec */
725 do {
726 udelay(1);
727 value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
728 value &= SPC_MSGU_CFG_TABLE_RESET;
729 } while ((value != 0) && (--max_wait_count));
730
731 if (!max_wait_count) {
732 PM8001_FAIL_DBG(pm8001_ha,
733 pm8001_printk("TIMEOUT:IBDB value/=0x%x\n", value));
734 return -1;
735 }
736
737 /* check the MPI-State for termination in progress */
738 /* wait until Inbound DoorBell Clear Register toggled */
739 max_wait_count = 1 * 1000 * 1000; /* 1 sec */
740 do {
741 udelay(1);
742 gst_len_mpistate =
743 pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
744 GST_GSTLEN_MPIS_OFFSET);
745 if (GST_MPI_STATE_UNINIT ==
746 (gst_len_mpistate & GST_MPI_STATE_MASK))
747 break;
748 } while (--max_wait_count);
749 if (!max_wait_count) {
750 PM8001_FAIL_DBG(pm8001_ha,
751 pm8001_printk(" TIME OUT MPI State = 0x%x\n",
752 gst_len_mpistate & GST_MPI_STATE_MASK));
753 return -1;
754 }
755 return 0;
756}
757
758/**
759 * soft_reset_ready_check - Function to check FW is ready for soft reset.
760 * @pm8001_ha: our hba card information
761 */
762static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha)
763{
764 u32 regVal, regVal1, regVal2;
765 if (mpi_uninit_check(pm8001_ha) != 0) {
766 PM8001_FAIL_DBG(pm8001_ha,
767 pm8001_printk("MPI state is not ready\n"));
768 return -1;
769 }
770 /* read the scratch pad 2 register bit 2 */
771 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
772 & SCRATCH_PAD2_FWRDY_RST;
773 if (regVal == SCRATCH_PAD2_FWRDY_RST) {
774 PM8001_INIT_DBG(pm8001_ha,
775 pm8001_printk("Firmware is ready for reset .\n"));
776 } else {
Mark Salyzynd95d0002012-01-17 09:18:57 -0500777 unsigned long flags;
778 /* Trigger NMI twice via RB6 */
779 spin_lock_irqsave(&pm8001_ha->lock, flags);
780 if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) {
781 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800782 PM8001_FAIL_DBG(pm8001_ha,
783 pm8001_printk("Shift Bar4 to 0x%x failed\n",
784 RB6_ACCESS_REG));
785 return -1;
786 }
787 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET,
788 RB6_MAGIC_NUMBER_RST);
789 pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST);
790 /* wait for 100 ms */
791 mdelay(100);
792 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) &
793 SCRATCH_PAD2_FWRDY_RST;
794 if (regVal != SCRATCH_PAD2_FWRDY_RST) {
795 regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
796 regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
797 PM8001_FAIL_DBG(pm8001_ha,
798 pm8001_printk("TIMEOUT:MSGU_SCRATCH_PAD1"
799 "=0x%x, MSGU_SCRATCH_PAD2=0x%x\n",
800 regVal1, regVal2));
801 PM8001_FAIL_DBG(pm8001_ha,
802 pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
803 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0)));
804 PM8001_FAIL_DBG(pm8001_ha,
805 pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
806 pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3)));
Mark Salyzynd95d0002012-01-17 09:18:57 -0500807 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800808 return -1;
809 }
Mark Salyzynd95d0002012-01-17 09:18:57 -0500810 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800811 }
812 return 0;
813}
814
815/**
816 * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
817 * the FW register status to the originated status.
818 * @pm8001_ha: our hba card information
jack wangdbf9bfe2009-10-14 16:19:21 +0800819 */
820static int
Sakthivel Kf5860992013-04-17 16:37:02 +0530821pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800822{
823 u32 regVal, toggleVal;
824 u32 max_wait_count;
825 u32 regVal1, regVal2, regVal3;
Sakthivel Kf5860992013-04-17 16:37:02 +0530826 u32 signature = 0x252acbcd; /* for host scratch pad0 */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500827 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +0800828
829 /* step1: Check FW is ready for soft reset */
830 if (soft_reset_ready_check(pm8001_ha) != 0) {
831 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("FW is not ready\n"));
832 return -1;
833 }
834
835 /* step 2: clear NMI status register on AAP1 and IOP, write the same
836 value to clear */
837 /* map 0x60000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500838 spin_lock_irqsave(&pm8001_ha->lock, flags);
839 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) {
840 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800841 PM8001_FAIL_DBG(pm8001_ha,
842 pm8001_printk("Shift Bar4 to 0x%x failed\n",
843 MBIC_AAP1_ADDR_BASE));
844 return -1;
845 }
846 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP);
847 PM8001_INIT_DBG(pm8001_ha,
848 pm8001_printk("MBIC - NMI Enable VPE0 (IOP)= 0x%x\n", regVal));
849 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0);
850 /* map 0x70000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500851 if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) {
852 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800853 PM8001_FAIL_DBG(pm8001_ha,
854 pm8001_printk("Shift Bar4 to 0x%x failed\n",
855 MBIC_IOP_ADDR_BASE));
856 return -1;
857 }
858 regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1);
859 PM8001_INIT_DBG(pm8001_ha,
860 pm8001_printk("MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n", regVal));
861 pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0);
862
863 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE);
864 PM8001_INIT_DBG(pm8001_ha,
865 pm8001_printk("PCIE -Event Interrupt Enable = 0x%x\n", regVal));
866 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0);
867
868 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT);
869 PM8001_INIT_DBG(pm8001_ha,
870 pm8001_printk("PCIE - Event Interrupt = 0x%x\n", regVal));
871 pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal);
872
873 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE);
874 PM8001_INIT_DBG(pm8001_ha,
875 pm8001_printk("PCIE -Error Interrupt Enable = 0x%x\n", regVal));
876 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0);
877
878 regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT);
879 PM8001_INIT_DBG(pm8001_ha,
880 pm8001_printk("PCIE - Error Interrupt = 0x%x\n", regVal));
881 pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal);
882
883 /* read the scratch pad 1 register bit 2 */
884 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
885 & SCRATCH_PAD1_RST;
886 toggleVal = regVal ^ SCRATCH_PAD1_RST;
887
888 /* set signature in host scratch pad0 register to tell SPC that the
889 host performs the soft reset */
890 pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature);
891
892 /* read required registers for confirmming */
893 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500894 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
895 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800896 PM8001_FAIL_DBG(pm8001_ha,
897 pm8001_printk("Shift Bar4 to 0x%x failed\n",
898 GSM_ADDR_BASE));
899 return -1;
900 }
901 PM8001_INIT_DBG(pm8001_ha,
902 pm8001_printk("GSM 0x0(0x00007b88)-GSM Configuration and"
903 " Reset = 0x%x\n",
904 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
905
906 /* step 3: host read GSM Configuration and Reset register */
907 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
908 /* Put those bits to low */
909 /* GSM XCBI offset = 0x70 0000
910 0x00 Bit 13 COM_SLV_SW_RSTB 1
911 0x00 Bit 12 QSSP_SW_RSTB 1
912 0x00 Bit 11 RAAE_SW_RSTB 1
913 0x00 Bit 9 RB_1_SW_RSTB 1
914 0x00 Bit 8 SM_SW_RSTB 1
915 */
916 regVal &= ~(0x00003b00);
917 /* host write GSM Configuration and Reset register */
918 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
919 PM8001_INIT_DBG(pm8001_ha,
920 pm8001_printk("GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM "
921 "Configuration and Reset is set to = 0x%x\n",
922 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
923
924 /* step 4: */
925 /* disable GSM - Read Address Parity Check */
926 regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
927 PM8001_INIT_DBG(pm8001_ha,
928 pm8001_printk("GSM 0x700038 - Read Address Parity Check "
929 "Enable = 0x%x\n", regVal1));
930 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0);
931 PM8001_INIT_DBG(pm8001_ha,
932 pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable"
933 "is set to = 0x%x\n",
934 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)));
935
936 /* disable GSM - Write Address Parity Check */
937 regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
938 PM8001_INIT_DBG(pm8001_ha,
939 pm8001_printk("GSM 0x700040 - Write Address Parity Check"
940 " Enable = 0x%x\n", regVal2));
941 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0);
942 PM8001_INIT_DBG(pm8001_ha,
943 pm8001_printk("GSM 0x700040 - Write Address Parity Check "
944 "Enable is set to = 0x%x\n",
945 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)));
946
947 /* disable GSM - Write Data Parity Check */
948 regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
949 PM8001_INIT_DBG(pm8001_ha,
950 pm8001_printk("GSM 0x300048 - Write Data Parity Check"
951 " Enable = 0x%x\n", regVal3));
952 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0);
953 PM8001_INIT_DBG(pm8001_ha,
954 pm8001_printk("GSM 0x300048 - Write Data Parity Check Enable"
955 "is set to = 0x%x\n",
956 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)));
957
958 /* step 5: delay 10 usec */
959 udelay(10);
960 /* step 5-b: set GPIO-0 output control to tristate anyway */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500961 if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) {
962 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800963 PM8001_INIT_DBG(pm8001_ha,
964 pm8001_printk("Shift Bar4 to 0x%x failed\n",
965 GPIO_ADDR_BASE));
966 return -1;
967 }
968 regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET);
Colin Ian King9e2a07e2019-03-17 18:15:32 +0000969 PM8001_INIT_DBG(pm8001_ha,
970 pm8001_printk("GPIO Output Control Register:"
971 " = 0x%x\n", regVal));
jack wangdbf9bfe2009-10-14 16:19:21 +0800972 /* set GPIO-0 output control to tri-state */
973 regVal &= 0xFFFFFFFC;
974 pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal);
975
976 /* Step 6: Reset the IOP and AAP1 */
977 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -0500978 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
979 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +0800980 PM8001_FAIL_DBG(pm8001_ha,
981 pm8001_printk("SPC Shift Bar4 to 0x%x failed\n",
982 SPC_TOP_LEVEL_ADDR_BASE));
983 return -1;
984 }
985 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
986 PM8001_INIT_DBG(pm8001_ha,
987 pm8001_printk("Top Register before resetting IOP/AAP1"
988 ":= 0x%x\n", regVal));
989 regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
990 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
991
992 /* step 7: Reset the BDMA/OSSP */
993 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
994 PM8001_INIT_DBG(pm8001_ha,
995 pm8001_printk("Top Register before resetting BDMA/OSSP"
996 ": = 0x%x\n", regVal));
997 regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
998 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
999
1000 /* step 8: delay 10 usec */
1001 udelay(10);
1002
1003 /* step 9: bring the BDMA and OSSP out of reset */
1004 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
1005 PM8001_INIT_DBG(pm8001_ha,
1006 pm8001_printk("Top Register before bringing up BDMA/OSSP"
1007 ":= 0x%x\n", regVal));
1008 regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
1009 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
1010
1011 /* step 10: delay 10 usec */
1012 udelay(10);
1013
1014 /* step 11: reads and sets the GSM Configuration and Reset Register */
1015 /* map 0x0700000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -05001016 if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
1017 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001018 PM8001_FAIL_DBG(pm8001_ha,
1019 pm8001_printk("SPC Shift Bar4 to 0x%x failed\n",
1020 GSM_ADDR_BASE));
1021 return -1;
1022 }
1023 PM8001_INIT_DBG(pm8001_ha,
1024 pm8001_printk("GSM 0x0 (0x00007b88)-GSM Configuration and "
1025 "Reset = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
1026 regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
1027 /* Put those bits to high */
1028 /* GSM XCBI offset = 0x70 0000
1029 0x00 Bit 13 COM_SLV_SW_RSTB 1
1030 0x00 Bit 12 QSSP_SW_RSTB 1
1031 0x00 Bit 11 RAAE_SW_RSTB 1
1032 0x00 Bit 9 RB_1_SW_RSTB 1
1033 0x00 Bit 8 SM_SW_RSTB 1
1034 */
1035 regVal |= (GSM_CONFIG_RESET_VALUE);
1036 pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
1037 PM8001_INIT_DBG(pm8001_ha,
1038 pm8001_printk("GSM (0x00004088 ==> 0x00007b88) - GSM"
1039 " Configuration and Reset is set to = 0x%x\n",
1040 pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
1041
1042 /* step 12: Restore GSM - Read Address Parity Check */
1043 regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
1044 /* just for debugging */
1045 PM8001_INIT_DBG(pm8001_ha,
1046 pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable"
1047 " = 0x%x\n", regVal));
1048 pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1);
1049 PM8001_INIT_DBG(pm8001_ha,
1050 pm8001_printk("GSM 0x700038 - Read Address Parity"
1051 " Check Enable is set to = 0x%x\n",
1052 pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)));
1053 /* Restore GSM - Write Address Parity Check */
1054 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
1055 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2);
1056 PM8001_INIT_DBG(pm8001_ha,
1057 pm8001_printk("GSM 0x700040 - Write Address Parity Check"
1058 " Enable is set to = 0x%x\n",
1059 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)));
1060 /* Restore GSM - Write Data Parity Check */
1061 regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
1062 pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3);
1063 PM8001_INIT_DBG(pm8001_ha,
1064 pm8001_printk("GSM 0x700048 - Write Data Parity Check Enable"
1065 "is set to = 0x%x\n",
1066 pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)));
1067
1068 /* step 13: bring the IOP and AAP1 out of reset */
1069 /* map 0x00000 to BAR4(0x20), BAR2(win) */
Mark Salyzynd95d0002012-01-17 09:18:57 -05001070 if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
1071 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001072 PM8001_FAIL_DBG(pm8001_ha,
1073 pm8001_printk("Shift Bar4 to 0x%x failed\n",
1074 SPC_TOP_LEVEL_ADDR_BASE));
1075 return -1;
1076 }
1077 regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
1078 regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
1079 pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
1080
1081 /* step 14: delay 10 usec - Normal Mode */
1082 udelay(10);
1083 /* check Soft Reset Normal mode or Soft Reset HDA mode */
1084 if (signature == SPC_SOFT_RESET_SIGNATURE) {
1085 /* step 15 (Normal Mode): wait until scratch pad1 register
1086 bit 2 toggled */
1087 max_wait_count = 2 * 1000 * 1000;/* 2 sec */
1088 do {
1089 udelay(1);
1090 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
1091 SCRATCH_PAD1_RST;
1092 } while ((regVal != toggleVal) && (--max_wait_count));
1093
1094 if (!max_wait_count) {
1095 regVal = pm8001_cr32(pm8001_ha, 0,
1096 MSGU_SCRATCH_PAD_1);
1097 PM8001_FAIL_DBG(pm8001_ha,
1098 pm8001_printk("TIMEOUT : ToggleVal 0x%x,"
1099 "MSGU_SCRATCH_PAD1 = 0x%x\n",
1100 toggleVal, regVal));
1101 PM8001_FAIL_DBG(pm8001_ha,
1102 pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
1103 pm8001_cr32(pm8001_ha, 0,
1104 MSGU_SCRATCH_PAD_0)));
1105 PM8001_FAIL_DBG(pm8001_ha,
1106 pm8001_printk("SCRATCH_PAD2 value = 0x%x\n",
1107 pm8001_cr32(pm8001_ha, 0,
1108 MSGU_SCRATCH_PAD_2)));
1109 PM8001_FAIL_DBG(pm8001_ha,
1110 pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
1111 pm8001_cr32(pm8001_ha, 0,
1112 MSGU_SCRATCH_PAD_3)));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001113 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001114 return -1;
1115 }
1116
1117 /* step 16 (Normal) - Clear ODMR and ODCR */
1118 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1119 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1120
1121 /* step 17 (Normal Mode): wait for the FW and IOP to get
1122 ready - 1 sec timeout */
1123 /* Wait for the SPC Configuration Table to be ready */
1124 if (check_fw_ready(pm8001_ha) == -1) {
1125 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
1126 /* return error if MPI Configuration Table not ready */
1127 PM8001_INIT_DBG(pm8001_ha,
1128 pm8001_printk("FW not ready SCRATCH_PAD1"
1129 " = 0x%x\n", regVal));
1130 regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
1131 /* return error if MPI Configuration Table not ready */
1132 PM8001_INIT_DBG(pm8001_ha,
1133 pm8001_printk("FW not ready SCRATCH_PAD2"
1134 " = 0x%x\n", regVal));
1135 PM8001_INIT_DBG(pm8001_ha,
1136 pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
1137 pm8001_cr32(pm8001_ha, 0,
1138 MSGU_SCRATCH_PAD_0)));
1139 PM8001_INIT_DBG(pm8001_ha,
1140 pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
1141 pm8001_cr32(pm8001_ha, 0,
1142 MSGU_SCRATCH_PAD_3)));
Mark Salyzynd95d0002012-01-17 09:18:57 -05001143 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001144 return -1;
1145 }
1146 }
Mark Salyzynd95d0002012-01-17 09:18:57 -05001147 pm8001_bar4_shift(pm8001_ha, 0);
1148 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08001149
1150 PM8001_INIT_DBG(pm8001_ha,
1151 pm8001_printk("SPC soft reset Complete\n"));
1152 return 0;
1153}
1154
1155static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
1156{
1157 u32 i;
1158 u32 regVal;
1159 PM8001_INIT_DBG(pm8001_ha,
1160 pm8001_printk("chip reset start\n"));
1161
1162 /* do SPC chip reset. */
1163 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1164 regVal &= ~(SPC_REG_RESET_DEVICE);
1165 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1166
1167 /* delay 10 usec */
1168 udelay(10);
1169
1170 /* bring chip reset out of reset */
1171 regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
1172 regVal |= SPC_REG_RESET_DEVICE;
1173 pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
1174
1175 /* delay 10 usec */
1176 udelay(10);
1177
1178 /* wait for 20 msec until the firmware gets reloaded */
1179 i = 20;
1180 do {
1181 mdelay(1);
1182 } while ((--i) != 0);
1183
1184 PM8001_INIT_DBG(pm8001_ha,
1185 pm8001_printk("chip reset finished\n"));
1186}
1187
1188/**
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02001189 * pm8001_chip_iounmap - which maped when initialized.
jack wangdbf9bfe2009-10-14 16:19:21 +08001190 * @pm8001_ha: our hba card information
1191 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301192void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08001193{
1194 s8 bar, logical = 0;
Denis Efremovc9c13ba2019-09-28 02:43:08 +03001195 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001196 /*
1197 ** logical BARs for SPC:
1198 ** bar 0 and 1 - logical BAR0
1199 ** bar 2 and 3 - logical BAR1
1200 ** bar4 - logical BAR2
1201 ** bar5 - logical BAR3
1202 ** Skip the appropriate assignments:
1203 */
1204 if ((bar == 1) || (bar == 3))
1205 continue;
1206 if (pm8001_ha->io_mem[logical].memvirtaddr) {
1207 iounmap(pm8001_ha->io_mem[logical].memvirtaddr);
1208 logical++;
1209 }
1210 }
1211}
1212
Colin Ian King292c04c2019-03-28 23:43:28 +00001213#ifndef PM8001_USE_MSIX
jack wangdbf9bfe2009-10-14 16:19:21 +08001214/**
1215 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1216 * @pm8001_ha: our hba card information
1217 */
1218static void
1219pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
1220{
1221 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
1222 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
1223}
1224
1225 /**
1226 * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
1227 * @pm8001_ha: our hba card information
1228 */
1229static void
1230pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
1231{
1232 pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL);
1233}
1234
Colin Ian King292c04c2019-03-28 23:43:28 +00001235#else
1236
jack wangdbf9bfe2009-10-14 16:19:21 +08001237/**
1238 * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt
1239 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001240 * @int_vec_idx: interrupt number to enable
jack wangdbf9bfe2009-10-14 16:19:21 +08001241 */
1242static void
1243pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha,
1244 u32 int_vec_idx)
1245{
1246 u32 msi_index;
1247 u32 value;
1248 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1249 msi_index += MSIX_TABLE_BASE;
1250 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE);
1251 value = (1 << int_vec_idx);
1252 pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value);
1253
1254}
1255
1256/**
1257 * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt
1258 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001259 * @int_vec_idx: interrupt number to disable
jack wangdbf9bfe2009-10-14 16:19:21 +08001260 */
1261static void
1262pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha,
1263 u32 int_vec_idx)
1264{
1265 u32 msi_index;
1266 msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
1267 msi_index += MSIX_TABLE_BASE;
1268 pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE);
jack wangdbf9bfe2009-10-14 16:19:21 +08001269}
Colin Ian King292c04c2019-03-28 23:43:28 +00001270#endif
Mark Salyzynd95d0002012-01-17 09:18:57 -05001271
jack wangdbf9bfe2009-10-14 16:19:21 +08001272/**
1273 * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
1274 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001275 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001276 */
1277static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301278pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001279{
1280#ifdef PM8001_USE_MSIX
1281 pm8001_chip_msix_interrupt_enable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001282#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001283 pm8001_chip_intx_interrupt_enable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001284#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001285}
1286
1287/**
1288 * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
1289 * @pm8001_ha: our hba card information
Lee Jones083645b2020-07-21 17:41:24 +01001290 * @vec: unused
jack wangdbf9bfe2009-10-14 16:19:21 +08001291 */
1292static void
Sakthivel Kf74cf272013-02-27 20:27:43 +05301293pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08001294{
1295#ifdef PM8001_USE_MSIX
1296 pm8001_chip_msix_interrupt_disable(pm8001_ha, 0);
Colin Ian King292c04c2019-03-28 23:43:28 +00001297#else
jack wangdbf9bfe2009-10-14 16:19:21 +08001298 pm8001_chip_intx_interrupt_disable(pm8001_ha);
Colin Ian King292c04c2019-03-28 23:43:28 +00001299#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08001300}
1301
1302/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301303 * pm8001_mpi_msg_free_get - get the free message buffer for transfer
1304 * inbound queue.
jack wangdbf9bfe2009-10-14 16:19:21 +08001305 * @circularQ: the inbound queue we want to transfer to HBA.
1306 * @messageSize: the message size of this transfer, normally it is 64 bytes
1307 * @messagePtr: the pointer to message.
1308 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301309int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ,
jack wangdbf9bfe2009-10-14 16:19:21 +08001310 u16 messageSize, void **messagePtr)
1311{
1312 u32 offset, consumer_index;
1313 struct mpi_msg_hdr *msgHeader;
1314 u8 bcCount = 1; /* only support single buffer */
1315
1316 /* Checks is the requested message size can be allocated in this queue*/
Sakthivel Kf74cf272013-02-27 20:27:43 +05301317 if (messageSize > IOMB_SIZE_SPCV) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001318 *messagePtr = NULL;
1319 return -1;
1320 }
1321
1322 /* Stores the new consumer index */
1323 consumer_index = pm8001_read_32(circularQ->ci_virt);
1324 circularQ->consumer_index = cpu_to_le32(consumer_index);
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001325 if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) ==
Santosh Nayak8270ee22012-02-26 20:14:46 +05301326 le32_to_cpu(circularQ->consumer_index)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001327 *messagePtr = NULL;
1328 return -1;
1329 }
1330 /* get memory IOMB buffer address */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301331 offset = circularQ->producer_idx * messageSize;
jack wangdbf9bfe2009-10-14 16:19:21 +08001332 /* increment to next bcCount element */
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001333 circularQ->producer_idx = (circularQ->producer_idx + bcCount)
1334 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001335 /* Adds that distance to the base of the region virtual address plus
1336 the message header size*/
1337 msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset);
1338 *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr);
1339 return 0;
1340}
1341
1342/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301343 * pm8001_mpi_build_cmd- build the message queue for transfer, update the PI to
1344 * FW to tell the fw to get this message from IOMB.
jack wangdbf9bfe2009-10-14 16:19:21 +08001345 * @pm8001_ha: our hba card information
1346 * @circularQ: the inbound queue we want to transfer to HBA.
1347 * @opCode: the operation code represents commands which LLDD and fw recognized.
1348 * @payload: the command payload of each operation command.
peter chang91a43fa2019-11-14 15:39:05 +05301349 * @nb: size in bytes of the command payload
1350 * @responseQueue: queue to interrupt on w/ command response (if any)
jack wangdbf9bfe2009-10-14 16:19:21 +08001351 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301352int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001353 struct inbound_queue_table *circularQ,
peter chang91a43fa2019-11-14 15:39:05 +05301354 u32 opCode, void *payload, size_t nb,
1355 u32 responseQueue)
jack wangdbf9bfe2009-10-14 16:19:21 +08001356{
1357 u32 Header = 0, hpriority = 0, bc = 1, category = 0x02;
jack wangdbf9bfe2009-10-14 16:19:21 +08001358 void *pMessage;
peter chang7640e1e2020-11-02 22:25:25 +05301359 unsigned long flags;
1360 int q_index = circularQ - pm8001_ha->inbnd_q_tbl;
1361 int rv = -1;
jack wangdbf9bfe2009-10-14 16:19:21 +08001362
peter chang7640e1e2020-11-02 22:25:25 +05301363 WARN_ON(q_index >= PM8001_MAX_INB_NUM);
1364 spin_lock_irqsave(&circularQ->iq_lock, flags);
1365 rv = pm8001_mpi_msg_free_get(circularQ, pm8001_ha->iomb_size,
1366 &pMessage);
1367 if (rv < 0) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001368 PM8001_IO_DBG(pm8001_ha,
peter chang7640e1e2020-11-02 22:25:25 +05301369 pm8001_printk("No free mpi buffer\n"));
1370 rv = -ENOMEM;
1371 goto done;
jack wangdbf9bfe2009-10-14 16:19:21 +08001372 }
peter chang91a43fa2019-11-14 15:39:05 +05301373
1374 if (nb > (pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr)))
1375 nb = pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr);
1376 memcpy(pMessage, payload, nb);
1377 if (nb + sizeof(struct mpi_msg_hdr) < pm8001_ha->iomb_size)
1378 memset(pMessage + nb, 0, pm8001_ha->iomb_size -
1379 (nb + sizeof(struct mpi_msg_hdr)));
jack wangdbf9bfe2009-10-14 16:19:21 +08001380
1381 /*Build the header*/
1382 Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24)
1383 | ((responseQueue & 0x3F) << 16)
1384 | ((category & 0xF) << 12) | (opCode & 0xFFF));
1385
1386 pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header));
1387 /*Update the PI to the firmware*/
1388 pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
1389 circularQ->pi_offset, circularQ->producer_idx);
peter chang73706722019-11-14 15:39:02 +05301390 PM8001_DEVIO_DBG(pm8001_ha,
Sakthivel Kf74cf272013-02-27 20:27:43 +05301391 pm8001_printk("INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n",
1392 responseQueue, opCode, circularQ->producer_idx,
1393 circularQ->consumer_index));
peter chang7640e1e2020-11-02 22:25:25 +05301394done:
1395 spin_unlock_irqrestore(&circularQ->iq_lock, flags);
1396 return rv;
jack wangdbf9bfe2009-10-14 16:19:21 +08001397}
1398
Sakthivel Kf74cf272013-02-27 20:27:43 +05301399u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
jack wangdbf9bfe2009-10-14 16:19:21 +08001400 struct outbound_queue_table *circularQ, u8 bc)
1401{
1402 u32 producer_index;
jack_wang72d0baa2009-11-05 22:33:35 +08001403 struct mpi_msg_hdr *msgHeader;
1404 struct mpi_msg_hdr *pOutBoundMsgHeader;
1405
1406 msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr));
1407 pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301408 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack_wang72d0baa2009-11-05 22:33:35 +08001409 if (pOutBoundMsgHeader != msgHeader) {
1410 PM8001_FAIL_DBG(pm8001_ha,
1411 pm8001_printk("consumer_idx = %d msgHeader = %p\n",
1412 circularQ->consumer_idx, msgHeader));
1413
1414 /* Update the producer index from SPC */
1415 producer_index = pm8001_read_32(circularQ->pi_virt);
1416 circularQ->producer_index = cpu_to_le32(producer_index);
1417 PM8001_FAIL_DBG(pm8001_ha,
1418 pm8001_printk("consumer_idx = %d producer_index = %d"
1419 "msgHeader = %p\n", circularQ->consumer_idx,
1420 circularQ->producer_index, msgHeader));
1421 return 0;
1422 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001423 /* free the circular queue buffer elements associated with the message*/
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001424 circularQ->consumer_idx = (circularQ->consumer_idx + bc)
1425 % PM8001_MPI_QUEUE;
jack wangdbf9bfe2009-10-14 16:19:21 +08001426 /* update the CI of outbound queue */
1427 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset,
1428 circularQ->consumer_idx);
1429 /* Update the producer index from SPC*/
1430 producer_index = pm8001_read_32(circularQ->pi_virt);
1431 circularQ->producer_index = cpu_to_le32(producer_index);
1432 PM8001_IO_DBG(pm8001_ha,
1433 pm8001_printk(" CI=%d PI=%d\n", circularQ->consumer_idx,
1434 circularQ->producer_index));
1435 return 0;
1436}
1437
1438/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05301439 * pm8001_mpi_msg_consume- get the MPI message from outbound queue
1440 * message table.
jack wangdbf9bfe2009-10-14 16:19:21 +08001441 * @pm8001_ha: our hba card information
1442 * @circularQ: the outbound queue table.
1443 * @messagePtr1: the message contents of this outbound message.
1444 * @pBC: the message size.
1445 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05301446u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08001447 struct outbound_queue_table *circularQ,
1448 void **messagePtr1, u8 *pBC)
1449{
1450 struct mpi_msg_hdr *msgHeader;
1451 __le32 msgHeader_tmp;
1452 u32 header_tmp;
1453 do {
1454 /* If there are not-yet-delivered messages ... */
Santosh Nayak8270ee22012-02-26 20:14:46 +05301455 if (le32_to_cpu(circularQ->producer_index)
1456 != circularQ->consumer_idx) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001457 /*Get the pointer to the circular queue buffer element*/
1458 msgHeader = (struct mpi_msg_hdr *)
1459 (circularQ->base_virt +
Sakthivel Kf74cf272013-02-27 20:27:43 +05301460 circularQ->consumer_idx * pm8001_ha->iomb_size);
jack wangdbf9bfe2009-10-14 16:19:21 +08001461 /* read header */
1462 header_tmp = pm8001_read_32(msgHeader);
1463 msgHeader_tmp = cpu_to_le32(header_tmp);
peter chang73706722019-11-14 15:39:02 +05301464 PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk(
1465 "outbound opcode msgheader:%x ci=%d pi=%d\n",
1466 msgHeader_tmp, circularQ->consumer_idx,
1467 circularQ->producer_index));
Santosh Nayak8270ee22012-02-26 20:14:46 +05301468 if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001469 if (OPC_OUB_SKIP_ENTRY !=
Santosh Nayak8270ee22012-02-26 20:14:46 +05301470 (le32_to_cpu(msgHeader_tmp) & 0xfff)) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001471 *messagePtr1 =
1472 ((u8 *)msgHeader) +
1473 sizeof(struct mpi_msg_hdr);
Santosh Nayak8270ee22012-02-26 20:14:46 +05301474 *pBC = (u8)((le32_to_cpu(msgHeader_tmp)
1475 >> 24) & 0x1f);
jack wangdbf9bfe2009-10-14 16:19:21 +08001476 PM8001_IO_DBG(pm8001_ha,
jack_wang72d0baa2009-11-05 22:33:35 +08001477 pm8001_printk(": CI=%d PI=%d "
1478 "msgHeader=%x\n",
jack wangdbf9bfe2009-10-14 16:19:21 +08001479 circularQ->consumer_idx,
1480 circularQ->producer_index,
1481 msgHeader_tmp));
1482 return MPI_IO_STATUS_SUCCESS;
1483 } else {
jack wangdbf9bfe2009-10-14 16:19:21 +08001484 circularQ->consumer_idx =
1485 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301486 ((le32_to_cpu(msgHeader_tmp)
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001487 >> 24) & 0x1f))
1488 % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001489 msgHeader_tmp = 0;
1490 pm8001_write_32(msgHeader, 0, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08001491 /* update the CI of outbound queue */
1492 pm8001_cw32(pm8001_ha,
1493 circularQ->ci_pci_bar,
1494 circularQ->ci_offset,
1495 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001496 }
jack_wang72d0baa2009-11-05 22:33:35 +08001497 } else {
1498 circularQ->consumer_idx =
1499 (circularQ->consumer_idx +
Santosh Nayak8270ee22012-02-26 20:14:46 +05301500 ((le32_to_cpu(msgHeader_tmp) >> 24) &
Mark Salyzyn99c72eb2012-04-25 13:02:04 -04001501 0x1f)) % PM8001_MPI_QUEUE;
jack_wang72d0baa2009-11-05 22:33:35 +08001502 msgHeader_tmp = 0;
1503 pm8001_write_32(msgHeader, 0, 0);
1504 /* update the CI of outbound queue */
1505 pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar,
1506 circularQ->ci_offset,
1507 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001508 return MPI_IO_STATUS_FAIL;
jack_wang72d0baa2009-11-05 22:33:35 +08001509 }
1510 } else {
1511 u32 producer_index;
1512 void *pi_virt = circularQ->pi_virt;
Deepak Ukey72349b62018-09-11 14:18:04 +05301513 /* spurious interrupt during setup if
1514 * kexec-ing and driver doing a doorbell access
1515 * with the pre-kexec oq interrupt setup
1516 */
1517 if (!pi_virt)
1518 break;
jack_wang72d0baa2009-11-05 22:33:35 +08001519 /* Update the producer index from SPC */
1520 producer_index = pm8001_read_32(pi_virt);
1521 circularQ->producer_index = cpu_to_le32(producer_index);
jack wangdbf9bfe2009-10-14 16:19:21 +08001522 }
Santosh Nayak8270ee22012-02-26 20:14:46 +05301523 } while (le32_to_cpu(circularQ->producer_index) !=
1524 circularQ->consumer_idx);
jack wangdbf9bfe2009-10-14 16:19:21 +08001525 /* while we don't have any more not-yet-delivered message */
1526 /* report empty */
1527 return MPI_IO_STATUS_BUSY;
1528}
1529
Sakthivel Kf74cf272013-02-27 20:27:43 +05301530void pm8001_work_fn(struct work_struct *work)
jack wangdbf9bfe2009-10-14 16:19:21 +08001531{
Tejun Heo429305e2011-01-24 14:57:29 +01001532 struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001533 struct pm8001_device *pm8001_dev;
Tejun Heo429305e2011-01-24 14:57:29 +01001534 struct domain_device *dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08001535
Mark Salyzyn5954d732012-01-17 11:52:24 -05001536 /*
1537 * So far, all users of this stash an associated structure here.
1538 * If we get here, and this pointer is null, then the action
1539 * was cancelled. This nullification happens when the device
1540 * goes away.
1541 */
1542 pm8001_dev = pw->data; /* Most stash device structure */
1543 if ((pm8001_dev == NULL)
1544 || ((pw->handler != IO_XFER_ERROR_BREAK)
James Bottomleyaa9f8322013-05-07 14:44:06 -07001545 && (pm8001_dev->dev_type == SAS_PHY_UNUSED))) {
Mark Salyzyn5954d732012-01-17 11:52:24 -05001546 kfree(pw);
1547 return;
1548 }
1549
Tejun Heo429305e2011-01-24 14:57:29 +01001550 switch (pw->handler) {
Mark Salyzyn5954d732012-01-17 11:52:24 -05001551 case IO_XFER_ERROR_BREAK:
1552 { /* This one stashes the sas_task instead */
1553 struct sas_task *t = (struct sas_task *)pm8001_dev;
1554 u32 tag;
1555 struct pm8001_ccb_info *ccb;
1556 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1557 unsigned long flags, flags1;
1558 struct task_status_struct *ts;
1559 int i;
1560
1561 if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC)
1562 break; /* Task still on lu */
1563 spin_lock_irqsave(&pm8001_ha->lock, flags);
1564
1565 spin_lock_irqsave(&t->task_state_lock, flags1);
1566 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1567 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1568 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1569 break; /* Task got completed by another */
1570 }
1571 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1572
1573 /* Search for a possible ccb that matches the task */
1574 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1575 ccb = &pm8001_ha->ccb_info[i];
1576 tag = ccb->ccb_tag;
1577 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1578 break;
1579 }
1580 if (!ccb) {
1581 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1582 break; /* Task got freed by another */
1583 }
1584 ts = &t->task_status;
1585 ts->resp = SAS_TASK_COMPLETE;
1586 /* Force the midlayer to retry */
1587 ts->stat = SAS_QUEUE_FULL;
1588 pm8001_dev = ccb->device;
1589 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301590 atomic_dec(&pm8001_dev->running_req);
Mark Salyzyn5954d732012-01-17 11:52:24 -05001591 spin_lock_irqsave(&t->task_state_lock, flags1);
1592 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
1593 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
1594 t->task_state_flags |= SAS_TASK_STATE_DONE;
1595 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
1596 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1597 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p"
1598 " done with event 0x%x resp 0x%x stat 0x%x but"
1599 " aborted by upper layer!\n",
1600 t, pw->handler, ts->resp, ts->stat));
1601 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1602 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1603 } else {
1604 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1605 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
1606 mb();/* in order to force CPU ordering */
1607 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1608 t->task_done(t);
1609 }
1610 } break;
1611 case IO_XFER_OPEN_RETRY_TIMEOUT:
1612 { /* This one stashes the sas_task instead */
1613 struct sas_task *t = (struct sas_task *)pm8001_dev;
1614 u32 tag;
1615 struct pm8001_ccb_info *ccb;
1616 struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
1617 unsigned long flags, flags1;
1618 int i, ret = 0;
1619
1620 PM8001_IO_DBG(pm8001_ha,
1621 pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1622
1623 ret = pm8001_query_task(t);
1624
1625 PM8001_IO_DBG(pm8001_ha,
1626 switch (ret) {
1627 case TMF_RESP_FUNC_SUCC:
1628 pm8001_printk("...Task on lu\n");
1629 break;
1630
1631 case TMF_RESP_FUNC_COMPLETE:
1632 pm8001_printk("...Task NOT on lu\n");
1633 break;
1634
1635 default:
peter chang73706722019-11-14 15:39:02 +05301636 PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk(
1637 "...query task failed!!!\n"));
Mark Salyzyn5954d732012-01-17 11:52:24 -05001638 break;
1639 });
1640
1641 spin_lock_irqsave(&pm8001_ha->lock, flags);
1642
1643 spin_lock_irqsave(&t->task_state_lock, flags1);
1644
1645 if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
1646 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1647 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1648 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1649 (void)pm8001_abort_task(t);
1650 break; /* Task got completed by another */
1651 }
1652
1653 spin_unlock_irqrestore(&t->task_state_lock, flags1);
1654
1655 /* Search for a possible ccb that matches the task */
1656 for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
1657 ccb = &pm8001_ha->ccb_info[i];
1658 tag = ccb->ccb_tag;
1659 if ((tag != 0xFFFFFFFF) && (ccb->task == t))
1660 break;
1661 }
1662 if (!ccb) {
1663 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1664 if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
1665 (void)pm8001_abort_task(t);
1666 break; /* Task got freed by another */
1667 }
1668
1669 pm8001_dev = ccb->device;
1670 dev = pm8001_dev->sas_device;
1671
1672 switch (ret) {
1673 case TMF_RESP_FUNC_SUCC: /* task on lu */
1674 ccb->open_retry = 1; /* Snub completion */
1675 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1676 ret = pm8001_abort_task(t);
1677 ccb->open_retry = 0;
1678 switch (ret) {
1679 case TMF_RESP_FUNC_SUCC:
1680 case TMF_RESP_FUNC_COMPLETE:
1681 break;
1682 default: /* device misbehavior */
1683 ret = TMF_RESP_FUNC_FAILED;
1684 PM8001_IO_DBG(pm8001_ha,
1685 pm8001_printk("...Reset phy\n"));
1686 pm8001_I_T_nexus_reset(dev);
1687 break;
1688 }
1689 break;
1690
1691 case TMF_RESP_FUNC_COMPLETE: /* task not on lu */
1692 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1693 /* Do we need to abort the task locally? */
1694 break;
1695
1696 default: /* device misbehavior */
1697 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
1698 ret = TMF_RESP_FUNC_FAILED;
1699 PM8001_IO_DBG(pm8001_ha,
1700 pm8001_printk("...Reset phy\n"));
1701 pm8001_I_T_nexus_reset(dev);
1702 }
1703
1704 if (ret == TMF_RESP_FUNC_FAILED)
1705 t = NULL;
1706 pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev);
1707 PM8001_IO_DBG(pm8001_ha, pm8001_printk("...Complete\n"));
1708 } break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001709 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
jack wangdbf9bfe2009-10-14 16:19:21 +08001710 dev = pm8001_dev->sas_device;
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301711 pm8001_I_T_nexus_event_handler(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001712 break;
1713 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
jack wangdbf9bfe2009-10-14 16:19:21 +08001714 dev = pm8001_dev->sas_device;
1715 pm8001_I_T_nexus_reset(dev);
1716 break;
1717 case IO_DS_IN_ERROR:
jack wangdbf9bfe2009-10-14 16:19:21 +08001718 dev = pm8001_dev->sas_device;
1719 pm8001_I_T_nexus_reset(dev);
1720 break;
1721 case IO_DS_NON_OPERATIONAL:
jack wangdbf9bfe2009-10-14 16:19:21 +08001722 dev = pm8001_dev->sas_device;
1723 pm8001_I_T_nexus_reset(dev);
1724 break;
1725 }
Tejun Heo429305e2011-01-24 14:57:29 +01001726 kfree(pw);
jack wangdbf9bfe2009-10-14 16:19:21 +08001727}
1728
Sakthivel Kf74cf272013-02-27 20:27:43 +05301729int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
jack wangdbf9bfe2009-10-14 16:19:21 +08001730 int handler)
1731{
Tejun Heo429305e2011-01-24 14:57:29 +01001732 struct pm8001_work *pw;
jack wangdbf9bfe2009-10-14 16:19:21 +08001733 int ret = 0;
1734
Tejun Heo429305e2011-01-24 14:57:29 +01001735 pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
1736 if (pw) {
1737 pw->pm8001_ha = pm8001_ha;
1738 pw->data = data;
1739 pw->handler = handler;
1740 INIT_WORK(&pw->work, pm8001_work_fn);
1741 queue_work(pm8001_wq, &pw->work);
jack wangdbf9bfe2009-10-14 16:19:21 +08001742 } else
1743 ret = -ENOMEM;
1744
1745 return ret;
1746}
1747
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301748static void pm8001_send_abort_all(struct pm8001_hba_info *pm8001_ha,
1749 struct pm8001_device *pm8001_ha_dev)
1750{
1751 int res;
1752 u32 ccb_tag;
1753 struct pm8001_ccb_info *ccb;
1754 struct sas_task *task = NULL;
1755 struct task_abort_req task_abort;
1756 struct inbound_queue_table *circularQ;
1757 u32 opc = OPC_INB_SATA_ABORT;
1758 int ret;
1759
1760 if (!pm8001_ha_dev) {
1761 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("dev is null\n"));
1762 return;
1763 }
1764
1765 task = sas_alloc_slow_task(GFP_ATOMIC);
1766
1767 if (!task) {
1768 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("cannot "
1769 "allocate task\n"));
1770 return;
1771 }
1772
1773 task->task_done = pm8001_task_done;
1774
1775 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1776 if (res)
1777 return;
1778
1779 ccb = &pm8001_ha->ccb_info[ccb_tag];
1780 ccb->device = pm8001_ha_dev;
1781 ccb->ccb_tag = ccb_tag;
1782 ccb->task = task;
1783
1784 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1785
1786 memset(&task_abort, 0, sizeof(task_abort));
1787 task_abort.abort_all = cpu_to_le32(1);
1788 task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1789 task_abort.tag = cpu_to_le32(ccb_tag);
1790
peter chang91a43fa2019-11-14 15:39:05 +05301791 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
1792 sizeof(task_abort), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301793 if (ret)
1794 pm8001_tag_free(pm8001_ha, ccb_tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301795
1796}
1797
1798static void pm8001_send_read_log(struct pm8001_hba_info *pm8001_ha,
1799 struct pm8001_device *pm8001_ha_dev)
1800{
1801 struct sata_start_req sata_cmd;
1802 int res;
1803 u32 ccb_tag;
1804 struct pm8001_ccb_info *ccb;
1805 struct sas_task *task = NULL;
1806 struct host_to_dev_fis fis;
1807 struct domain_device *dev;
1808 struct inbound_queue_table *circularQ;
1809 u32 opc = OPC_INB_SATA_HOST_OPSTART;
1810
1811 task = sas_alloc_slow_task(GFP_ATOMIC);
1812
1813 if (!task) {
1814 PM8001_FAIL_DBG(pm8001_ha,
1815 pm8001_printk("cannot allocate task !!!\n"));
1816 return;
1817 }
1818 task->task_done = pm8001_task_done;
1819
1820 res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
1821 if (res) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301822 sas_free_task(task);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301823 PM8001_FAIL_DBG(pm8001_ha,
1824 pm8001_printk("cannot allocate tag !!!\n"));
1825 return;
1826 }
1827
1828 /* allocate domain device by ourselves as libsas
1829 * is not going to provide any
1830 */
1831 dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
1832 if (!dev) {
Tomas Henzl5533abc2014-07-09 17:20:49 +05301833 sas_free_task(task);
1834 pm8001_tag_free(pm8001_ha, ccb_tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301835 PM8001_FAIL_DBG(pm8001_ha,
1836 pm8001_printk("Domain device cannot be allocated\n"));
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301837 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301838 }
Tomas Henzl5533abc2014-07-09 17:20:49 +05301839 task->dev = dev;
1840 task->dev->lldd_dev = pm8001_ha_dev;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301841
1842 ccb = &pm8001_ha->ccb_info[ccb_tag];
1843 ccb->device = pm8001_ha_dev;
1844 ccb->ccb_tag = ccb_tag;
1845 ccb->task = task;
1846 pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
1847 pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
1848
1849 memset(&sata_cmd, 0, sizeof(sata_cmd));
1850 circularQ = &pm8001_ha->inbnd_q_tbl[0];
1851
1852 /* construct read log FIS */
1853 memset(&fis, 0, sizeof(struct host_to_dev_fis));
1854 fis.fis_type = 0x27;
1855 fis.flags = 0x80;
1856 fis.command = ATA_CMD_READ_LOG_EXT;
1857 fis.lbal = 0x10;
1858 fis.sector_count = 0x1;
1859
1860 sata_cmd.tag = cpu_to_le32(ccb_tag);
1861 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
1862 sata_cmd.ncqtag_atap_dir_m |= ((0x1 << 7) | (0x5 << 9));
1863 memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
1864
peter chang91a43fa2019-11-14 15:39:05 +05301865 res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
1866 sizeof(sata_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05301867 if (res) {
1868 sas_free_task(task);
1869 pm8001_tag_free(pm8001_ha, ccb_tag);
1870 kfree(dev);
1871 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05301872}
1873
jack wangdbf9bfe2009-10-14 16:19:21 +08001874/**
1875 * mpi_ssp_completion- process the event that FW response to the SSP request.
1876 * @pm8001_ha: our hba card information
1877 * @piomb: the message contents of this outbound message.
1878 *
1879 * When FW has completed a ssp request for example a IO request, after it has
1880 * filled the SG data with the data, it will trigger this event represent
1881 * that he has finished the job,please check the coresponding buffer.
1882 * So we will tell the caller who maybe waiting the result to tell upper layer
1883 * that the task has been finished.
1884 */
jack_wang72d0baa2009-11-05 22:33:35 +08001885static void
jack wangdbf9bfe2009-10-14 16:19:21 +08001886mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
1887{
1888 struct sas_task *t;
1889 struct pm8001_ccb_info *ccb;
1890 unsigned long flags;
1891 u32 status;
1892 u32 param;
1893 u32 tag;
1894 struct ssp_completion_resp *psspPayload;
1895 struct task_status_struct *ts;
1896 struct ssp_response_iu *iu;
1897 struct pm8001_device *pm8001_dev;
1898 psspPayload = (struct ssp_completion_resp *)(piomb + 4);
1899 status = le32_to_cpu(psspPayload->status);
1900 tag = le32_to_cpu(psspPayload->tag);
1901 ccb = &pm8001_ha->ccb_info[tag];
Mark Salyzyn5954d732012-01-17 11:52:24 -05001902 if ((status == IO_ABORTED) && ccb->open_retry) {
1903 /* Being completed by another */
1904 ccb->open_retry = 0;
1905 return;
1906 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001907 pm8001_dev = ccb->device;
1908 param = le32_to_cpu(psspPayload->param);
1909
jack wangdbf9bfe2009-10-14 16:19:21 +08001910 t = ccb->task;
1911
jack_wang72d0baa2009-11-05 22:33:35 +08001912 if (status && status != IO_UNDERFLOW)
jack wangdbf9bfe2009-10-14 16:19:21 +08001913 PM8001_FAIL_DBG(pm8001_ha,
1914 pm8001_printk("sas IO status 0x%x\n", status));
1915 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08001916 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08001917 ts = &t->task_status;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05301918 /* Print sas address of IO failed device */
1919 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
1920 (status != IO_UNDERFLOW))
1921 PM8001_FAIL_DBG(pm8001_ha,
1922 pm8001_printk("SAS Address of IO Failure Drive:"
1923 "%016llx", SAS_ADDR(t->dev->sas_addr)));
1924
peter chang73706722019-11-14 15:39:02 +05301925 if (status)
1926 PM8001_IOERR_DBG(pm8001_ha, pm8001_printk(
1927 "status:0x%x, tag:0x%x, task:0x%p\n",
1928 status, tag, t));
1929
jack wangdbf9bfe2009-10-14 16:19:21 +08001930 switch (status) {
1931 case IO_SUCCESS:
1932 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS"
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07001933 ",param = %d\n", param));
jack wangdbf9bfe2009-10-14 16:19:21 +08001934 if (param == 0) {
1935 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05001936 ts->stat = SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08001937 } else {
1938 ts->resp = SAS_TASK_COMPLETE;
1939 ts->stat = SAS_PROTO_RESPONSE;
1940 ts->residual = param;
1941 iu = &psspPayload->ssp_resp_iu;
1942 sas_ssp_task_response(pm8001_ha->dev, t, iu);
1943 }
1944 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301945 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001946 break;
1947 case IO_ABORTED:
1948 PM8001_IO_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07001949 pm8001_printk("IO_ABORTED IOMB Tag\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08001950 ts->resp = SAS_TASK_COMPLETE;
1951 ts->stat = SAS_ABORTED_TASK;
1952 break;
1953 case IO_UNDERFLOW:
1954 /* SSP Completion with error */
1955 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW"
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07001956 ",param = %d\n", param));
jack wangdbf9bfe2009-10-14 16:19:21 +08001957 ts->resp = SAS_TASK_COMPLETE;
1958 ts->stat = SAS_DATA_UNDERRUN;
1959 ts->residual = param;
1960 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05301961 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08001962 break;
1963 case IO_NO_DEVICE:
1964 PM8001_IO_DBG(pm8001_ha,
1965 pm8001_printk("IO_NO_DEVICE\n"));
1966 ts->resp = SAS_TASK_UNDELIVERED;
1967 ts->stat = SAS_PHY_DOWN;
1968 break;
1969 case IO_XFER_ERROR_BREAK:
1970 PM8001_IO_DBG(pm8001_ha,
1971 pm8001_printk("IO_XFER_ERROR_BREAK\n"));
1972 ts->resp = SAS_TASK_COMPLETE;
1973 ts->stat = SAS_OPEN_REJECT;
Mark Salyzyn5954d732012-01-17 11:52:24 -05001974 /* Force the midlayer to retry */
1975 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08001976 break;
1977 case IO_XFER_ERROR_PHY_NOT_READY:
1978 PM8001_IO_DBG(pm8001_ha,
1979 pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
1980 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:
1985 PM8001_IO_DBG(pm8001_ha,
1986 pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
1987 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:
1992 PM8001_IO_DBG(pm8001_ha,
1993 pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
1994 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:
1999 PM8001_IO_DBG(pm8001_ha,
2000 pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2001 ts->resp = SAS_TASK_COMPLETE;
2002 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002003 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002004 break;
2005 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2006 PM8001_IO_DBG(pm8001_ha,
2007 pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2008 ts->resp = SAS_TASK_COMPLETE;
2009 ts->stat = SAS_OPEN_REJECT;
2010 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2011 if (!t->uldd_task)
2012 pm8001_handle_event(pm8001_ha,
2013 pm8001_dev,
2014 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2015 break;
2016 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2017 PM8001_IO_DBG(pm8001_ha,
2018 pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2019 ts->resp = SAS_TASK_COMPLETE;
2020 ts->stat = SAS_OPEN_REJECT;
2021 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2022 break;
2023 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2024 PM8001_IO_DBG(pm8001_ha,
2025 pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
2026 "NOT_SUPPORTED\n"));
2027 ts->resp = SAS_TASK_COMPLETE;
2028 ts->stat = SAS_OPEN_REJECT;
2029 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2030 break;
2031 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2032 PM8001_IO_DBG(pm8001_ha,
2033 pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2034 ts->resp = SAS_TASK_UNDELIVERED;
2035 ts->stat = SAS_OPEN_REJECT;
2036 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2037 break;
2038 case IO_XFER_ERROR_NAK_RECEIVED:
2039 PM8001_IO_DBG(pm8001_ha,
2040 pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
2041 ts->resp = SAS_TASK_COMPLETE;
2042 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002043 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002044 break;
2045 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
2046 PM8001_IO_DBG(pm8001_ha,
2047 pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
2048 ts->resp = SAS_TASK_COMPLETE;
2049 ts->stat = SAS_NAK_R_ERR;
2050 break;
2051 case IO_XFER_ERROR_DMA:
2052 PM8001_IO_DBG(pm8001_ha,
2053 pm8001_printk("IO_XFER_ERROR_DMA\n"));
2054 ts->resp = SAS_TASK_COMPLETE;
2055 ts->stat = SAS_OPEN_REJECT;
2056 break;
2057 case IO_XFER_OPEN_RETRY_TIMEOUT:
2058 PM8001_IO_DBG(pm8001_ha,
2059 pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
2060 ts->resp = SAS_TASK_COMPLETE;
2061 ts->stat = SAS_OPEN_REJECT;
2062 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2063 break;
2064 case IO_XFER_ERROR_OFFSET_MISMATCH:
2065 PM8001_IO_DBG(pm8001_ha,
2066 pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
2067 ts->resp = SAS_TASK_COMPLETE;
2068 ts->stat = SAS_OPEN_REJECT;
2069 break;
2070 case IO_PORT_IN_RESET:
2071 PM8001_IO_DBG(pm8001_ha,
2072 pm8001_printk("IO_PORT_IN_RESET\n"));
2073 ts->resp = SAS_TASK_COMPLETE;
2074 ts->stat = SAS_OPEN_REJECT;
2075 break;
2076 case IO_DS_NON_OPERATIONAL:
2077 PM8001_IO_DBG(pm8001_ha,
2078 pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
2079 ts->resp = SAS_TASK_COMPLETE;
2080 ts->stat = SAS_OPEN_REJECT;
2081 if (!t->uldd_task)
2082 pm8001_handle_event(pm8001_ha,
2083 pm8001_dev,
2084 IO_DS_NON_OPERATIONAL);
2085 break;
2086 case IO_DS_IN_RECOVERY:
2087 PM8001_IO_DBG(pm8001_ha,
2088 pm8001_printk("IO_DS_IN_RECOVERY\n"));
2089 ts->resp = SAS_TASK_COMPLETE;
2090 ts->stat = SAS_OPEN_REJECT;
2091 break;
2092 case IO_TM_TAG_NOT_FOUND:
2093 PM8001_IO_DBG(pm8001_ha,
2094 pm8001_printk("IO_TM_TAG_NOT_FOUND\n"));
2095 ts->resp = SAS_TASK_COMPLETE;
2096 ts->stat = SAS_OPEN_REJECT;
2097 break;
2098 case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
2099 PM8001_IO_DBG(pm8001_ha,
2100 pm8001_printk("IO_SSP_EXT_IU_ZERO_LEN_ERROR\n"));
2101 ts->resp = SAS_TASK_COMPLETE;
2102 ts->stat = SAS_OPEN_REJECT;
2103 break;
2104 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
2105 PM8001_IO_DBG(pm8001_ha,
2106 pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
2107 ts->resp = SAS_TASK_COMPLETE;
2108 ts->stat = SAS_OPEN_REJECT;
2109 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07002110 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002111 default:
peter chang73706722019-11-14 15:39:02 +05302112 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08002113 pm8001_printk("Unknown status 0x%x\n", status));
2114 /* not allowed case. Therefore, return failed status */
2115 ts->resp = SAS_TASK_COMPLETE;
2116 ts->stat = SAS_OPEN_REJECT;
2117 break;
2118 }
2119 PM8001_IO_DBG(pm8001_ha,
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302120 pm8001_printk("scsi_status = %x\n ",
jack wangdbf9bfe2009-10-14 16:19:21 +08002121 psspPayload->ssp_resp_iu.status));
2122 spin_lock_irqsave(&t->task_state_lock, flags);
2123 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2124 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2125 t->task_state_flags |= SAS_TASK_STATE_DONE;
2126 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2127 spin_unlock_irqrestore(&t->task_state_lock, flags);
2128 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
2129 " io_status 0x%x resp 0x%x "
2130 "stat 0x%x but aborted by upper layer!\n",
2131 t, status, ts->resp, ts->stat));
2132 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2133 } else {
2134 spin_unlock_irqrestore(&t->task_state_lock, flags);
2135 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2136 mb();/* in order to force CPU ordering */
2137 t->task_done(t);
2138 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002139}
2140
2141/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002142static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002143{
2144 struct sas_task *t;
2145 unsigned long flags;
2146 struct task_status_struct *ts;
2147 struct pm8001_ccb_info *ccb;
2148 struct pm8001_device *pm8001_dev;
2149 struct ssp_event_resp *psspPayload =
2150 (struct ssp_event_resp *)(piomb + 4);
2151 u32 event = le32_to_cpu(psspPayload->event);
2152 u32 tag = le32_to_cpu(psspPayload->tag);
2153 u32 port_id = le32_to_cpu(psspPayload->port_id);
2154 u32 dev_id = le32_to_cpu(psspPayload->device_id);
2155
2156 ccb = &pm8001_ha->ccb_info[tag];
2157 t = ccb->task;
2158 pm8001_dev = ccb->device;
2159 if (event)
2160 PM8001_FAIL_DBG(pm8001_ha,
2161 pm8001_printk("sas IO status 0x%x\n", event));
2162 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002163 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002164 ts = &t->task_status;
peter chang73706722019-11-14 15:39:02 +05302165 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08002166 pm8001_printk("port_id = %x,device_id = %x\n",
2167 port_id, dev_id));
2168 switch (event) {
2169 case IO_OVERFLOW:
2170 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n");)
2171 ts->resp = SAS_TASK_COMPLETE;
2172 ts->stat = SAS_DATA_OVERRUN;
2173 ts->residual = 0;
2174 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302175 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002176 break;
2177 case IO_XFER_ERROR_BREAK:
2178 PM8001_IO_DBG(pm8001_ha,
2179 pm8001_printk("IO_XFER_ERROR_BREAK\n"));
Mark Salyzyn5954d732012-01-17 11:52:24 -05002180 pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
2181 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002182 case IO_XFER_ERROR_PHY_NOT_READY:
2183 PM8001_IO_DBG(pm8001_ha,
2184 pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
2185 ts->resp = SAS_TASK_COMPLETE;
2186 ts->stat = SAS_OPEN_REJECT;
2187 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2188 break;
2189 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
2190 PM8001_IO_DBG(pm8001_ha,
2191 pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
2192 "_SUPPORTED\n"));
2193 ts->resp = SAS_TASK_COMPLETE;
2194 ts->stat = SAS_OPEN_REJECT;
2195 ts->open_rej_reason = SAS_OREJ_EPROTO;
2196 break;
2197 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
2198 PM8001_IO_DBG(pm8001_ha,
2199 pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
2200 ts->resp = SAS_TASK_COMPLETE;
2201 ts->stat = SAS_OPEN_REJECT;
2202 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2203 break;
2204 case IO_OPEN_CNX_ERROR_BREAK:
2205 PM8001_IO_DBG(pm8001_ha,
2206 pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2207 ts->resp = SAS_TASK_COMPLETE;
2208 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002209 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002210 break;
2211 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2212 PM8001_IO_DBG(pm8001_ha,
2213 pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2214 ts->resp = SAS_TASK_COMPLETE;
2215 ts->stat = SAS_OPEN_REJECT;
2216 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2217 if (!t->uldd_task)
2218 pm8001_handle_event(pm8001_ha,
2219 pm8001_dev,
2220 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2221 break;
2222 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2223 PM8001_IO_DBG(pm8001_ha,
2224 pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2225 ts->resp = SAS_TASK_COMPLETE;
2226 ts->stat = SAS_OPEN_REJECT;
2227 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2228 break;
2229 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2230 PM8001_IO_DBG(pm8001_ha,
2231 pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
2232 "NOT_SUPPORTED\n"));
2233 ts->resp = SAS_TASK_COMPLETE;
2234 ts->stat = SAS_OPEN_REJECT;
2235 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2236 break;
2237 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2238 PM8001_IO_DBG(pm8001_ha,
2239 pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2240 ts->resp = SAS_TASK_COMPLETE;
2241 ts->stat = SAS_OPEN_REJECT;
2242 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2243 break;
2244 case IO_XFER_ERROR_NAK_RECEIVED:
2245 PM8001_IO_DBG(pm8001_ha,
2246 pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
2247 ts->resp = SAS_TASK_COMPLETE;
2248 ts->stat = SAS_OPEN_REJECT;
jack_wang72d0baa2009-11-05 22:33:35 +08002249 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
jack wangdbf9bfe2009-10-14 16:19:21 +08002250 break;
2251 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
2252 PM8001_IO_DBG(pm8001_ha,
2253 pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
2254 ts->resp = SAS_TASK_COMPLETE;
2255 ts->stat = SAS_NAK_R_ERR;
2256 break;
2257 case IO_XFER_OPEN_RETRY_TIMEOUT:
2258 PM8001_IO_DBG(pm8001_ha,
2259 pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
Mark Salyzyn5954d732012-01-17 11:52:24 -05002260 pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
2261 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002262 case IO_XFER_ERROR_UNEXPECTED_PHASE:
2263 PM8001_IO_DBG(pm8001_ha,
2264 pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
2265 ts->resp = SAS_TASK_COMPLETE;
2266 ts->stat = SAS_DATA_OVERRUN;
2267 break;
2268 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
2269 PM8001_IO_DBG(pm8001_ha,
2270 pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
2271 ts->resp = SAS_TASK_COMPLETE;
2272 ts->stat = SAS_DATA_OVERRUN;
2273 break;
2274 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
2275 PM8001_IO_DBG(pm8001_ha,
2276 pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
2277 ts->resp = SAS_TASK_COMPLETE;
2278 ts->stat = SAS_DATA_OVERRUN;
2279 break;
2280 case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
2281 PM8001_IO_DBG(pm8001_ha,
2282 pm8001_printk("IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n"));
2283 ts->resp = SAS_TASK_COMPLETE;
2284 ts->stat = SAS_DATA_OVERRUN;
2285 break;
2286 case IO_XFER_ERROR_OFFSET_MISMATCH:
2287 PM8001_IO_DBG(pm8001_ha,
2288 pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
2289 ts->resp = SAS_TASK_COMPLETE;
2290 ts->stat = SAS_DATA_OVERRUN;
2291 break;
2292 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
2293 PM8001_IO_DBG(pm8001_ha,
2294 pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
2295 ts->resp = SAS_TASK_COMPLETE;
2296 ts->stat = SAS_DATA_OVERRUN;
2297 break;
2298 case IO_XFER_CMD_FRAME_ISSUED:
2299 PM8001_IO_DBG(pm8001_ha,
2300 pm8001_printk(" IO_XFER_CMD_FRAME_ISSUED\n"));
jack_wang72d0baa2009-11-05 22:33:35 +08002301 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002302 default:
peter chang73706722019-11-14 15:39:02 +05302303 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08002304 pm8001_printk("Unknown status 0x%x\n", event));
2305 /* not allowed case. Therefore, return failed status */
2306 ts->resp = SAS_TASK_COMPLETE;
2307 ts->stat = SAS_DATA_OVERRUN;
2308 break;
2309 }
2310 spin_lock_irqsave(&t->task_state_lock, flags);
2311 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2312 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2313 t->task_state_flags |= SAS_TASK_STATE_DONE;
2314 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
2315 spin_unlock_irqrestore(&t->task_state_lock, flags);
2316 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
2317 " event 0x%x resp 0x%x "
2318 "stat 0x%x but aborted by upper layer!\n",
2319 t, event, ts->resp, ts->stat));
2320 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2321 } else {
2322 spin_unlock_irqrestore(&t->task_state_lock, flags);
2323 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
2324 mb();/* in order to force CPU ordering */
2325 t->task_done(t);
2326 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002327}
2328
2329/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002330static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002331mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2332{
2333 struct sas_task *t;
2334 struct pm8001_ccb_info *ccb;
jack wangdbf9bfe2009-10-14 16:19:21 +08002335 u32 param;
2336 u32 status;
2337 u32 tag;
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302338 int i, j;
2339 u8 sata_addr_low[4];
2340 u32 temp_sata_addr_low;
2341 u8 sata_addr_hi[4];
2342 u32 temp_sata_addr_hi;
jack wangdbf9bfe2009-10-14 16:19:21 +08002343 struct sata_completion_resp *psataPayload;
2344 struct task_status_struct *ts;
2345 struct ata_task_resp *resp ;
2346 u32 *sata_resp;
2347 struct pm8001_device *pm8001_dev;
Santosh Nayakb08c1852012-03-09 13:43:38 +05302348 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002349
2350 psataPayload = (struct sata_completion_resp *)(piomb + 4);
2351 status = le32_to_cpu(psataPayload->status);
2352 tag = le32_to_cpu(psataPayload->tag);
2353
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302354 if (!tag) {
2355 PM8001_FAIL_DBG(pm8001_ha,
2356 pm8001_printk("tag null\n"));
2357 return;
2358 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002359 ccb = &pm8001_ha->ccb_info[tag];
2360 param = le32_to_cpu(psataPayload->param);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302361 if (ccb) {
2362 t = ccb->task;
2363 pm8001_dev = ccb->device;
2364 } else {
jack wangdbf9bfe2009-10-14 16:19:21 +08002365 PM8001_FAIL_DBG(pm8001_ha,
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302366 pm8001_printk("ccb null\n"));
jack_wang72d0baa2009-11-05 22:33:35 +08002367 return;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302368 }
2369
2370 if (t) {
2371 if (t->dev && (t->dev->lldd_dev))
2372 pm8001_dev = t->dev->lldd_dev;
2373 } else {
2374 PM8001_FAIL_DBG(pm8001_ha,
2375 pm8001_printk("task null\n"));
2376 return;
2377 }
2378
2379 if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
2380 && unlikely(!t || !t->lldd_task || !t->dev)) {
2381 PM8001_FAIL_DBG(pm8001_ha,
2382 pm8001_printk("task or dev null\n"));
2383 return;
2384 }
2385
2386 ts = &t->task_status;
2387 if (!ts) {
2388 PM8001_FAIL_DBG(pm8001_ha,
2389 pm8001_printk("ts null\n"));
2390 return;
2391 }
peter chang73706722019-11-14 15:39:02 +05302392
2393 if (status)
2394 PM8001_IOERR_DBG(pm8001_ha, pm8001_printk(
2395 "status:0x%x, tag:0x%x, task::0x%p\n",
2396 status, tag, t));
2397
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302398 /* Print sas address of IO failed device */
2399 if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
2400 (status != IO_UNDERFLOW)) {
2401 if (!((t->dev->parent) &&
John Garry924a3542019-06-10 20:41:41 +08002402 (dev_is_expander(t->dev->parent->dev_type)))) {
Anand Kumar Santhanamcb269c22013-09-17 16:47:21 +05302403 for (i = 0 , j = 4; j <= 7 && i <= 3; i++ , j++)
2404 sata_addr_low[i] = pm8001_ha->sas_addr[j];
2405 for (i = 0 , j = 0; j <= 3 && i <= 3; i++ , j++)
2406 sata_addr_hi[i] = pm8001_ha->sas_addr[j];
2407 memcpy(&temp_sata_addr_low, sata_addr_low,
2408 sizeof(sata_addr_low));
2409 memcpy(&temp_sata_addr_hi, sata_addr_hi,
2410 sizeof(sata_addr_hi));
2411 temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
2412 |((temp_sata_addr_hi << 8) &
2413 0xff0000) |
2414 ((temp_sata_addr_hi >> 8)
2415 & 0xff00) |
2416 ((temp_sata_addr_hi << 24) &
2417 0xff000000));
2418 temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
2419 & 0xff) |
2420 ((temp_sata_addr_low << 8)
2421 & 0xff0000) |
2422 ((temp_sata_addr_low >> 8)
2423 & 0xff00) |
2424 ((temp_sata_addr_low << 24)
2425 & 0xff000000)) +
2426 pm8001_dev->attached_phy +
2427 0x10);
2428 PM8001_FAIL_DBG(pm8001_ha,
2429 pm8001_printk("SAS Address of IO Failure Drive:"
2430 "%08x%08x", temp_sata_addr_hi,
2431 temp_sata_addr_low));
2432 } else {
2433 PM8001_FAIL_DBG(pm8001_ha,
2434 pm8001_printk("SAS Address of IO Failure Drive:"
2435 "%016llx", SAS_ADDR(t->dev->sas_addr)));
2436 }
2437 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002438 switch (status) {
2439 case IO_SUCCESS:
2440 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
2441 if (param == 0) {
2442 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05002443 ts->stat = SAM_STAT_GOOD;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302444 /* check if response is for SEND READ LOG */
2445 if (pm8001_dev &&
2446 (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
2447 /* set new bit for abort_all */
2448 pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
2449 /* clear bit for read log */
2450 pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
2451 pm8001_send_abort_all(pm8001_ha, pm8001_dev);
2452 /* Free the tag */
2453 pm8001_tag_free(pm8001_ha, tag);
2454 sas_free_task(t);
2455 return;
2456 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002457 } else {
2458 u8 len;
2459 ts->resp = SAS_TASK_COMPLETE;
2460 ts->stat = SAS_PROTO_RESPONSE;
2461 ts->residual = param;
2462 PM8001_IO_DBG(pm8001_ha,
2463 pm8001_printk("SAS_PROTO_RESPONSE len = %d\n",
2464 param));
2465 sata_resp = &psataPayload->sata_resp[0];
2466 resp = (struct ata_task_resp *)ts->buf;
2467 if (t->ata_task.dma_xfer == 0 &&
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02002468 t->data_dir == DMA_FROM_DEVICE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08002469 len = sizeof(struct pio_setup_fis);
2470 PM8001_IO_DBG(pm8001_ha,
2471 pm8001_printk("PIO read len = %d\n", len));
2472 } else if (t->ata_task.use_ncq) {
2473 len = sizeof(struct set_dev_bits_fis);
2474 PM8001_IO_DBG(pm8001_ha,
2475 pm8001_printk("FPDMA len = %d\n", len));
2476 } else {
2477 len = sizeof(struct dev_to_host_fis);
2478 PM8001_IO_DBG(pm8001_ha,
2479 pm8001_printk("other len = %d\n", len));
2480 }
2481 if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
2482 resp->frame_len = len;
2483 memcpy(&resp->ending_fis[0], sata_resp, len);
2484 ts->buf_valid_size = sizeof(*resp);
2485 } else
2486 PM8001_IO_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07002487 pm8001_printk("response to large\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08002488 }
2489 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302490 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002491 break;
2492 case IO_ABORTED:
2493 PM8001_IO_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07002494 pm8001_printk("IO_ABORTED IOMB Tag\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08002495 ts->resp = SAS_TASK_COMPLETE;
2496 ts->stat = SAS_ABORTED_TASK;
2497 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302498 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002499 break;
2500 /* following cases are to do cases */
2501 case IO_UNDERFLOW:
2502 /* SATA Completion with error */
2503 PM8001_IO_DBG(pm8001_ha,
2504 pm8001_printk("IO_UNDERFLOW param = %d\n", param));
2505 ts->resp = SAS_TASK_COMPLETE;
2506 ts->stat = SAS_DATA_UNDERRUN;
2507 ts->residual = param;
2508 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302509 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002510 break;
2511 case IO_NO_DEVICE:
2512 PM8001_IO_DBG(pm8001_ha,
2513 pm8001_printk("IO_NO_DEVICE\n"));
2514 ts->resp = SAS_TASK_UNDELIVERED;
2515 ts->stat = SAS_PHY_DOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302516 if (pm8001_dev)
2517 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002518 break;
2519 case IO_XFER_ERROR_BREAK:
2520 PM8001_IO_DBG(pm8001_ha,
2521 pm8001_printk("IO_XFER_ERROR_BREAK\n"));
2522 ts->resp = SAS_TASK_COMPLETE;
2523 ts->stat = SAS_INTERRUPTED;
Viswas G4a2efd42020-11-02 22:25:26 +05302524 if (pm8001_dev)
2525 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002526 break;
2527 case IO_XFER_ERROR_PHY_NOT_READY:
2528 PM8001_IO_DBG(pm8001_ha,
2529 pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
2530 ts->resp = SAS_TASK_COMPLETE;
2531 ts->stat = SAS_OPEN_REJECT;
2532 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302533 if (pm8001_dev)
2534 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002535 break;
2536 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
2537 PM8001_IO_DBG(pm8001_ha,
2538 pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
2539 "_SUPPORTED\n"));
2540 ts->resp = SAS_TASK_COMPLETE;
2541 ts->stat = SAS_OPEN_REJECT;
2542 ts->open_rej_reason = SAS_OREJ_EPROTO;
Viswas G4a2efd42020-11-02 22:25:26 +05302543 if (pm8001_dev)
2544 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002545 break;
2546 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
2547 PM8001_IO_DBG(pm8001_ha,
2548 pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
2549 ts->resp = SAS_TASK_COMPLETE;
2550 ts->stat = SAS_OPEN_REJECT;
2551 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
Viswas G4a2efd42020-11-02 22:25:26 +05302552 if (pm8001_dev)
2553 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002554 break;
2555 case IO_OPEN_CNX_ERROR_BREAK:
2556 PM8001_IO_DBG(pm8001_ha,
2557 pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2558 ts->resp = SAS_TASK_COMPLETE;
2559 ts->stat = SAS_OPEN_REJECT;
2560 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
Viswas G4a2efd42020-11-02 22:25:26 +05302561 if (pm8001_dev)
2562 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002563 break;
2564 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2565 PM8001_IO_DBG(pm8001_ha,
2566 pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2567 ts->resp = SAS_TASK_COMPLETE;
2568 ts->stat = SAS_DEV_NO_RESPONSE;
2569 if (!t->uldd_task) {
2570 pm8001_handle_event(pm8001_ha,
2571 pm8001_dev,
2572 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2573 ts->resp = SAS_TASK_UNDELIVERED;
2574 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302575 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002576 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002577 }
2578 break;
2579 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2580 PM8001_IO_DBG(pm8001_ha,
2581 pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2582 ts->resp = SAS_TASK_UNDELIVERED;
2583 ts->stat = SAS_OPEN_REJECT;
2584 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2585 if (!t->uldd_task) {
2586 pm8001_handle_event(pm8001_ha,
2587 pm8001_dev,
2588 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2589 ts->resp = SAS_TASK_UNDELIVERED;
2590 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302591 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002592 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002593 }
2594 break;
2595 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2596 PM8001_IO_DBG(pm8001_ha,
2597 pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
2598 "NOT_SUPPORTED\n"));
2599 ts->resp = SAS_TASK_COMPLETE;
2600 ts->stat = SAS_OPEN_REJECT;
2601 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
Viswas G4a2efd42020-11-02 22:25:26 +05302602 if (pm8001_dev)
2603 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002604 break;
2605 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
2606 PM8001_IO_DBG(pm8001_ha,
2607 pm8001_printk("IO_OPEN_CNX_ERROR_STP_RESOURCES"
2608 "_BUSY\n"));
2609 ts->resp = SAS_TASK_COMPLETE;
2610 ts->stat = SAS_DEV_NO_RESPONSE;
2611 if (!t->uldd_task) {
2612 pm8001_handle_event(pm8001_ha,
2613 pm8001_dev,
2614 IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
2615 ts->resp = SAS_TASK_UNDELIVERED;
2616 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302617 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002618 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002619 }
2620 break;
2621 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2622 PM8001_IO_DBG(pm8001_ha,
2623 pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2624 ts->resp = SAS_TASK_COMPLETE;
2625 ts->stat = SAS_OPEN_REJECT;
2626 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
Viswas G4a2efd42020-11-02 22:25:26 +05302627 if (pm8001_dev)
2628 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002629 break;
2630 case IO_XFER_ERROR_NAK_RECEIVED:
2631 PM8001_IO_DBG(pm8001_ha,
2632 pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
2633 ts->resp = SAS_TASK_COMPLETE;
2634 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302635 if (pm8001_dev)
2636 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002637 break;
2638 case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
2639 PM8001_IO_DBG(pm8001_ha,
2640 pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
2641 ts->resp = SAS_TASK_COMPLETE;
2642 ts->stat = SAS_NAK_R_ERR;
Viswas G4a2efd42020-11-02 22:25:26 +05302643 if (pm8001_dev)
2644 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002645 break;
2646 case IO_XFER_ERROR_DMA:
2647 PM8001_IO_DBG(pm8001_ha,
2648 pm8001_printk("IO_XFER_ERROR_DMA\n"));
2649 ts->resp = SAS_TASK_COMPLETE;
2650 ts->stat = SAS_ABORTED_TASK;
Viswas G4a2efd42020-11-02 22:25:26 +05302651 if (pm8001_dev)
2652 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002653 break;
2654 case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
2655 PM8001_IO_DBG(pm8001_ha,
2656 pm8001_printk("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n"));
2657 ts->resp = SAS_TASK_UNDELIVERED;
2658 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302659 if (pm8001_dev)
2660 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002661 break;
2662 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
2663 PM8001_IO_DBG(pm8001_ha,
2664 pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
2665 ts->resp = SAS_TASK_COMPLETE;
2666 ts->stat = SAS_DATA_UNDERRUN;
Viswas G4a2efd42020-11-02 22:25:26 +05302667 if (pm8001_dev)
2668 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002669 break;
2670 case IO_XFER_OPEN_RETRY_TIMEOUT:
2671 PM8001_IO_DBG(pm8001_ha,
2672 pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
2673 ts->resp = SAS_TASK_COMPLETE;
2674 ts->stat = SAS_OPEN_TO;
Viswas G4a2efd42020-11-02 22:25:26 +05302675 if (pm8001_dev)
2676 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002677 break;
2678 case IO_PORT_IN_RESET:
2679 PM8001_IO_DBG(pm8001_ha,
2680 pm8001_printk("IO_PORT_IN_RESET\n"));
2681 ts->resp = SAS_TASK_COMPLETE;
2682 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302683 if (pm8001_dev)
2684 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002685 break;
2686 case IO_DS_NON_OPERATIONAL:
2687 PM8001_IO_DBG(pm8001_ha,
2688 pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
2689 ts->resp = SAS_TASK_COMPLETE;
2690 ts->stat = SAS_DEV_NO_RESPONSE;
2691 if (!t->uldd_task) {
2692 pm8001_handle_event(pm8001_ha, pm8001_dev,
2693 IO_DS_NON_OPERATIONAL);
2694 ts->resp = SAS_TASK_UNDELIVERED;
2695 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302696 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002697 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002698 }
2699 break;
2700 case IO_DS_IN_RECOVERY:
2701 PM8001_IO_DBG(pm8001_ha,
2702 pm8001_printk(" IO_DS_IN_RECOVERY\n"));
2703 ts->resp = SAS_TASK_COMPLETE;
2704 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302705 if (pm8001_dev)
2706 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002707 break;
2708 case IO_DS_IN_ERROR:
2709 PM8001_IO_DBG(pm8001_ha,
2710 pm8001_printk("IO_DS_IN_ERROR\n"));
2711 ts->resp = SAS_TASK_COMPLETE;
2712 ts->stat = SAS_DEV_NO_RESPONSE;
2713 if (!t->uldd_task) {
2714 pm8001_handle_event(pm8001_ha, pm8001_dev,
2715 IO_DS_IN_ERROR);
2716 ts->resp = SAS_TASK_UNDELIVERED;
2717 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302718 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002719 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002720 }
2721 break;
2722 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
2723 PM8001_IO_DBG(pm8001_ha,
2724 pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
2725 ts->resp = SAS_TASK_COMPLETE;
2726 ts->stat = SAS_OPEN_REJECT;
2727 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
Viswas G4a2efd42020-11-02 22:25:26 +05302728 if (pm8001_dev)
2729 atomic_dec(&pm8001_dev->running_req);
Johannes Thumshirn50acde82015-08-17 15:52:32 +02002730 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08002731 default:
peter chang73706722019-11-14 15:39:02 +05302732 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08002733 pm8001_printk("Unknown status 0x%x\n", status));
2734 /* not allowed case. Therefore, return failed status */
2735 ts->resp = SAS_TASK_COMPLETE;
2736 ts->stat = SAS_DEV_NO_RESPONSE;
Viswas G4a2efd42020-11-02 22:25:26 +05302737 if (pm8001_dev)
2738 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002739 break;
2740 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302741 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002742 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2743 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2744 t->task_state_flags |= SAS_TASK_STATE_DONE;
2745 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302746 spin_unlock_irqrestore(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002747 PM8001_FAIL_DBG(pm8001_ha,
2748 pm8001_printk("task 0x%p done with io_status 0x%x"
2749 " resp 0x%x stat 0x%x but aborted by upper layer!\n",
2750 t, status, ts->resp, ts->stat));
2751 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302752 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302753 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302754 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002755 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002756}
2757
2758/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002759static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08002760{
2761 struct sas_task *t;
jack wangdbf9bfe2009-10-14 16:19:21 +08002762 struct task_status_struct *ts;
2763 struct pm8001_ccb_info *ccb;
2764 struct pm8001_device *pm8001_dev;
2765 struct sata_event_resp *psataPayload =
2766 (struct sata_event_resp *)(piomb + 4);
2767 u32 event = le32_to_cpu(psataPayload->event);
2768 u32 tag = le32_to_cpu(psataPayload->tag);
2769 u32 port_id = le32_to_cpu(psataPayload->port_id);
2770 u32 dev_id = le32_to_cpu(psataPayload->device_id);
Santosh Nayakb08c1852012-03-09 13:43:38 +05302771 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08002772
2773 ccb = &pm8001_ha->ccb_info[tag];
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05302774
2775 if (ccb) {
2776 t = ccb->task;
2777 pm8001_dev = ccb->device;
2778 } else {
2779 PM8001_FAIL_DBG(pm8001_ha,
2780 pm8001_printk("No CCB !!!. returning\n"));
2781 }
2782 if (event)
2783 PM8001_FAIL_DBG(pm8001_ha,
2784 pm8001_printk("SATA EVENT 0x%x\n", event));
2785
2786 /* Check if this is NCQ error */
2787 if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
2788 /* find device using device id */
2789 pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
2790 /* send read log extension */
2791 if (pm8001_dev)
2792 pm8001_send_read_log(pm8001_ha, pm8001_dev);
2793 return;
2794 }
2795
2796 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002797 t = ccb->task;
2798 pm8001_dev = ccb->device;
2799 if (event)
2800 PM8001_FAIL_DBG(pm8001_ha,
2801 pm8001_printk("sata IO status 0x%x\n", event));
2802 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08002803 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002804 ts = &t->task_status;
peter chang73706722019-11-14 15:39:02 +05302805 PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk(
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05302806 "port_id:0x%x, device_id:0x%x, tag:0x%x, event:0x%x\n",
2807 port_id, dev_id, tag, event));
jack wangdbf9bfe2009-10-14 16:19:21 +08002808 switch (event) {
2809 case IO_OVERFLOW:
2810 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
2811 ts->resp = SAS_TASK_COMPLETE;
2812 ts->stat = SAS_DATA_OVERRUN;
2813 ts->residual = 0;
2814 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05302815 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08002816 break;
2817 case IO_XFER_ERROR_BREAK:
2818 PM8001_IO_DBG(pm8001_ha,
2819 pm8001_printk("IO_XFER_ERROR_BREAK\n"));
2820 ts->resp = SAS_TASK_COMPLETE;
2821 ts->stat = SAS_INTERRUPTED;
2822 break;
2823 case IO_XFER_ERROR_PHY_NOT_READY:
2824 PM8001_IO_DBG(pm8001_ha,
2825 pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
2826 ts->resp = SAS_TASK_COMPLETE;
2827 ts->stat = SAS_OPEN_REJECT;
2828 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
2829 break;
2830 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
2831 PM8001_IO_DBG(pm8001_ha,
2832 pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
2833 "_SUPPORTED\n"));
2834 ts->resp = SAS_TASK_COMPLETE;
2835 ts->stat = SAS_OPEN_REJECT;
2836 ts->open_rej_reason = SAS_OREJ_EPROTO;
2837 break;
2838 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
2839 PM8001_IO_DBG(pm8001_ha,
2840 pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
2841 ts->resp = SAS_TASK_COMPLETE;
2842 ts->stat = SAS_OPEN_REJECT;
2843 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
2844 break;
2845 case IO_OPEN_CNX_ERROR_BREAK:
2846 PM8001_IO_DBG(pm8001_ha,
2847 pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
2848 ts->resp = SAS_TASK_COMPLETE;
2849 ts->stat = SAS_OPEN_REJECT;
2850 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
2851 break;
2852 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
2853 PM8001_IO_DBG(pm8001_ha,
2854 pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
2855 ts->resp = SAS_TASK_UNDELIVERED;
2856 ts->stat = SAS_DEV_NO_RESPONSE;
2857 if (!t->uldd_task) {
2858 pm8001_handle_event(pm8001_ha,
2859 pm8001_dev,
2860 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
2861 ts->resp = SAS_TASK_COMPLETE;
2862 ts->stat = SAS_QUEUE_FULL;
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302863 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack_wang72d0baa2009-11-05 22:33:35 +08002864 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08002865 }
2866 break;
2867 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
2868 PM8001_IO_DBG(pm8001_ha,
2869 pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
2870 ts->resp = SAS_TASK_UNDELIVERED;
2871 ts->stat = SAS_OPEN_REJECT;
2872 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
2873 break;
2874 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
2875 PM8001_IO_DBG(pm8001_ha,
2876 pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
2877 "NOT_SUPPORTED\n"));
2878 ts->resp = SAS_TASK_COMPLETE;
2879 ts->stat = SAS_OPEN_REJECT;
2880 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
2881 break;
2882 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
2883 PM8001_IO_DBG(pm8001_ha,
2884 pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
2885 ts->resp = SAS_TASK_COMPLETE;
2886 ts->stat = SAS_OPEN_REJECT;
2887 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
2888 break;
2889 case IO_XFER_ERROR_NAK_RECEIVED:
2890 PM8001_IO_DBG(pm8001_ha,
2891 pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
2892 ts->resp = SAS_TASK_COMPLETE;
2893 ts->stat = SAS_NAK_R_ERR;
2894 break;
2895 case IO_XFER_ERROR_PEER_ABORTED:
2896 PM8001_IO_DBG(pm8001_ha,
2897 pm8001_printk("IO_XFER_ERROR_PEER_ABORTED\n"));
2898 ts->resp = SAS_TASK_COMPLETE;
2899 ts->stat = SAS_NAK_R_ERR;
2900 break;
2901 case IO_XFER_ERROR_REJECTED_NCQ_MODE:
2902 PM8001_IO_DBG(pm8001_ha,
2903 pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
2904 ts->resp = SAS_TASK_COMPLETE;
2905 ts->stat = SAS_DATA_UNDERRUN;
2906 break;
2907 case IO_XFER_OPEN_RETRY_TIMEOUT:
2908 PM8001_IO_DBG(pm8001_ha,
2909 pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
2910 ts->resp = SAS_TASK_COMPLETE;
2911 ts->stat = SAS_OPEN_TO;
2912 break;
2913 case IO_XFER_ERROR_UNEXPECTED_PHASE:
2914 PM8001_IO_DBG(pm8001_ha,
2915 pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
2916 ts->resp = SAS_TASK_COMPLETE;
2917 ts->stat = SAS_OPEN_TO;
2918 break;
2919 case IO_XFER_ERROR_XFER_RDY_OVERRUN:
2920 PM8001_IO_DBG(pm8001_ha,
2921 pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
2922 ts->resp = SAS_TASK_COMPLETE;
2923 ts->stat = SAS_OPEN_TO;
2924 break;
2925 case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
2926 PM8001_IO_DBG(pm8001_ha,
2927 pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
2928 ts->resp = SAS_TASK_COMPLETE;
2929 ts->stat = SAS_OPEN_TO;
2930 break;
2931 case IO_XFER_ERROR_OFFSET_MISMATCH:
2932 PM8001_IO_DBG(pm8001_ha,
2933 pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
2934 ts->resp = SAS_TASK_COMPLETE;
2935 ts->stat = SAS_OPEN_TO;
2936 break;
2937 case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
2938 PM8001_IO_DBG(pm8001_ha,
2939 pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
2940 ts->resp = SAS_TASK_COMPLETE;
2941 ts->stat = SAS_OPEN_TO;
2942 break;
2943 case IO_XFER_CMD_FRAME_ISSUED:
2944 PM8001_IO_DBG(pm8001_ha,
2945 pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
2946 break;
2947 case IO_XFER_PIO_SETUP_ERROR:
2948 PM8001_IO_DBG(pm8001_ha,
2949 pm8001_printk("IO_XFER_PIO_SETUP_ERROR\n"));
2950 ts->resp = SAS_TASK_COMPLETE;
2951 ts->stat = SAS_OPEN_TO;
2952 break;
2953 default:
peter chang73706722019-11-14 15:39:02 +05302954 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08002955 pm8001_printk("Unknown status 0x%x\n", event));
2956 /* not allowed case. Therefore, return failed status */
2957 ts->resp = SAS_TASK_COMPLETE;
2958 ts->stat = SAS_OPEN_TO;
2959 break;
2960 }
Santosh Nayakb08c1852012-03-09 13:43:38 +05302961 spin_lock_irqsave(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002962 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
2963 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
2964 t->task_state_flags |= SAS_TASK_STATE_DONE;
2965 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302966 spin_unlock_irqrestore(&t->task_state_lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08002967 PM8001_FAIL_DBG(pm8001_ha,
2968 pm8001_printk("task 0x%p done with io_status 0x%x"
2969 " resp 0x%x stat 0x%x but aborted by upper layer!\n",
2970 t, event, ts->resp, ts->stat));
2971 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302972 } else {
Santosh Nayakb08c1852012-03-09 13:43:38 +05302973 spin_unlock_irqrestore(&t->task_state_lock, flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05302974 pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08002975 }
jack wangdbf9bfe2009-10-14 16:19:21 +08002976}
2977
2978/*See the comments for mpi_ssp_completion */
jack_wang72d0baa2009-11-05 22:33:35 +08002979static void
jack wangdbf9bfe2009-10-14 16:19:21 +08002980mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
2981{
jack wangdbf9bfe2009-10-14 16:19:21 +08002982 struct sas_task *t;
2983 struct pm8001_ccb_info *ccb;
2984 unsigned long flags;
2985 u32 status;
2986 u32 tag;
2987 struct smp_completion_resp *psmpPayload;
2988 struct task_status_struct *ts;
2989 struct pm8001_device *pm8001_dev;
2990
2991 psmpPayload = (struct smp_completion_resp *)(piomb + 4);
2992 status = le32_to_cpu(psmpPayload->status);
2993 tag = le32_to_cpu(psmpPayload->tag);
2994
2995 ccb = &pm8001_ha->ccb_info[tag];
jack wangdbf9bfe2009-10-14 16:19:21 +08002996 t = ccb->task;
2997 ts = &t->task_status;
2998 pm8001_dev = ccb->device;
peter chang73706722019-11-14 15:39:02 +05302999 if (status) {
jack wangdbf9bfe2009-10-14 16:19:21 +08003000 PM8001_FAIL_DBG(pm8001_ha,
3001 pm8001_printk("smp IO status 0x%x\n", status));
peter chang73706722019-11-14 15:39:02 +05303002 PM8001_IOERR_DBG(pm8001_ha,
3003 pm8001_printk("status:0x%x, tag:0x%x, task:0x%p\n",
3004 status, tag, t));
3005 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003006 if (unlikely(!t || !t->lldd_task || !t->dev))
jack_wang72d0baa2009-11-05 22:33:35 +08003007 return;
jack wangdbf9bfe2009-10-14 16:19:21 +08003008
3009 switch (status) {
3010 case IO_SUCCESS:
3011 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
3012 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05003013 ts->stat = SAM_STAT_GOOD;
Colin Ian King9e2a07e2019-03-17 18:15:32 +00003014 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303015 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08003016 break;
3017 case IO_ABORTED:
3018 PM8001_IO_DBG(pm8001_ha,
3019 pm8001_printk("IO_ABORTED IOMB\n"));
3020 ts->resp = SAS_TASK_COMPLETE;
3021 ts->stat = SAS_ABORTED_TASK;
3022 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303023 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08003024 break;
3025 case IO_OVERFLOW:
3026 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
3027 ts->resp = SAS_TASK_COMPLETE;
3028 ts->stat = SAS_DATA_OVERRUN;
3029 ts->residual = 0;
3030 if (pm8001_dev)
Viswas G4a2efd42020-11-02 22:25:26 +05303031 atomic_dec(&pm8001_dev->running_req);
jack wangdbf9bfe2009-10-14 16:19:21 +08003032 break;
3033 case IO_NO_DEVICE:
3034 PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n"));
3035 ts->resp = SAS_TASK_COMPLETE;
3036 ts->stat = SAS_PHY_DOWN;
3037 break;
3038 case IO_ERROR_HW_TIMEOUT:
3039 PM8001_IO_DBG(pm8001_ha,
3040 pm8001_printk("IO_ERROR_HW_TIMEOUT\n"));
3041 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05003042 ts->stat = SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08003043 break;
3044 case IO_XFER_ERROR_BREAK:
3045 PM8001_IO_DBG(pm8001_ha,
3046 pm8001_printk("IO_XFER_ERROR_BREAK\n"));
3047 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05003048 ts->stat = SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08003049 break;
3050 case IO_XFER_ERROR_PHY_NOT_READY:
3051 PM8001_IO_DBG(pm8001_ha,
3052 pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
3053 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05003054 ts->stat = SAM_STAT_BUSY;
jack wangdbf9bfe2009-10-14 16:19:21 +08003055 break;
3056 case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
3057 PM8001_IO_DBG(pm8001_ha,
3058 pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
3059 ts->resp = SAS_TASK_COMPLETE;
3060 ts->stat = SAS_OPEN_REJECT;
3061 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3062 break;
3063 case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
3064 PM8001_IO_DBG(pm8001_ha,
3065 pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
3066 ts->resp = SAS_TASK_COMPLETE;
3067 ts->stat = SAS_OPEN_REJECT;
3068 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3069 break;
3070 case IO_OPEN_CNX_ERROR_BREAK:
3071 PM8001_IO_DBG(pm8001_ha,
3072 pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
3073 ts->resp = SAS_TASK_COMPLETE;
3074 ts->stat = SAS_OPEN_REJECT;
3075 ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
3076 break;
3077 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
3078 PM8001_IO_DBG(pm8001_ha,
3079 pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
3080 ts->resp = SAS_TASK_COMPLETE;
3081 ts->stat = SAS_OPEN_REJECT;
3082 ts->open_rej_reason = SAS_OREJ_UNKNOWN;
3083 pm8001_handle_event(pm8001_ha,
3084 pm8001_dev,
3085 IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
3086 break;
3087 case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
3088 PM8001_IO_DBG(pm8001_ha,
3089 pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
3090 ts->resp = SAS_TASK_COMPLETE;
3091 ts->stat = SAS_OPEN_REJECT;
3092 ts->open_rej_reason = SAS_OREJ_BAD_DEST;
3093 break;
3094 case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
3095 PM8001_IO_DBG(pm8001_ha,
3096 pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
3097 "NOT_SUPPORTED\n"));
3098 ts->resp = SAS_TASK_COMPLETE;
3099 ts->stat = SAS_OPEN_REJECT;
3100 ts->open_rej_reason = SAS_OREJ_CONN_RATE;
3101 break;
3102 case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
3103 PM8001_IO_DBG(pm8001_ha,
3104 pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
3105 ts->resp = SAS_TASK_COMPLETE;
3106 ts->stat = SAS_OPEN_REJECT;
3107 ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
3108 break;
3109 case IO_XFER_ERROR_RX_FRAME:
3110 PM8001_IO_DBG(pm8001_ha,
3111 pm8001_printk("IO_XFER_ERROR_RX_FRAME\n"));
3112 ts->resp = SAS_TASK_COMPLETE;
3113 ts->stat = SAS_DEV_NO_RESPONSE;
3114 break;
3115 case IO_XFER_OPEN_RETRY_TIMEOUT:
3116 PM8001_IO_DBG(pm8001_ha,
3117 pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
3118 ts->resp = SAS_TASK_COMPLETE;
3119 ts->stat = SAS_OPEN_REJECT;
3120 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3121 break;
3122 case IO_ERROR_INTERNAL_SMP_RESOURCE:
3123 PM8001_IO_DBG(pm8001_ha,
3124 pm8001_printk("IO_ERROR_INTERNAL_SMP_RESOURCE\n"));
3125 ts->resp = SAS_TASK_COMPLETE;
3126 ts->stat = SAS_QUEUE_FULL;
3127 break;
3128 case IO_PORT_IN_RESET:
3129 PM8001_IO_DBG(pm8001_ha,
3130 pm8001_printk("IO_PORT_IN_RESET\n"));
3131 ts->resp = SAS_TASK_COMPLETE;
3132 ts->stat = SAS_OPEN_REJECT;
3133 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3134 break;
3135 case IO_DS_NON_OPERATIONAL:
3136 PM8001_IO_DBG(pm8001_ha,
3137 pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
3138 ts->resp = SAS_TASK_COMPLETE;
3139 ts->stat = SAS_DEV_NO_RESPONSE;
3140 break;
3141 case IO_DS_IN_RECOVERY:
3142 PM8001_IO_DBG(pm8001_ha,
3143 pm8001_printk("IO_DS_IN_RECOVERY\n"));
3144 ts->resp = SAS_TASK_COMPLETE;
3145 ts->stat = SAS_OPEN_REJECT;
3146 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3147 break;
3148 case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
3149 PM8001_IO_DBG(pm8001_ha,
3150 pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
3151 ts->resp = SAS_TASK_COMPLETE;
3152 ts->stat = SAS_OPEN_REJECT;
3153 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
3154 break;
3155 default:
peter chang73706722019-11-14 15:39:02 +05303156 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08003157 pm8001_printk("Unknown status 0x%x\n", status));
3158 ts->resp = SAS_TASK_COMPLETE;
3159 ts->stat = SAS_DEV_NO_RESPONSE;
3160 /* not allowed case. Therefore, return failed status */
3161 break;
3162 }
3163 spin_lock_irqsave(&t->task_state_lock, flags);
3164 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3165 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3166 t->task_state_flags |= SAS_TASK_STATE_DONE;
3167 if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
3168 spin_unlock_irqrestore(&t->task_state_lock, flags);
3169 PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
3170 " io_status 0x%x resp 0x%x "
3171 "stat 0x%x but aborted by upper layer!\n",
3172 t, status, ts->resp, ts->stat));
3173 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3174 } else {
3175 spin_unlock_irqrestore(&t->task_state_lock, flags);
3176 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
3177 mb();/* in order to force CPU ordering */
3178 t->task_done(t);
3179 }
jack wangdbf9bfe2009-10-14 16:19:21 +08003180}
3181
Sakthivel Kf74cf272013-02-27 20:27:43 +05303182void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha,
3183 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003184{
3185 struct set_dev_state_resp *pPayload =
3186 (struct set_dev_state_resp *)(piomb + 4);
3187 u32 tag = le32_to_cpu(pPayload->tag);
3188 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3189 struct pm8001_device *pm8001_dev = ccb->device;
3190 u32 status = le32_to_cpu(pPayload->status);
3191 u32 device_id = le32_to_cpu(pPayload->device_id);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05303192 u8 pds = le32_to_cpu(pPayload->pds_nds) & PDS_BITS;
3193 u8 nds = le32_to_cpu(pPayload->pds_nds) & NDS_BITS;
jack wangdbf9bfe2009-10-14 16:19:21 +08003194 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set device id = 0x%x state "
3195 "from 0x%x to 0x%x status = 0x%x!\n",
3196 device_id, pds, nds, status));
3197 complete(pm8001_dev->setds_completion);
3198 ccb->task = NULL;
3199 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303200 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003201}
3202
Sakthivel Kf74cf272013-02-27 20:27:43 +05303203void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003204{
3205 struct get_nvm_data_resp *pPayload =
3206 (struct get_nvm_data_resp *)(piomb + 4);
3207 u32 tag = le32_to_cpu(pPayload->tag);
3208 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3209 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3210 complete(pm8001_ha->nvmd_completion);
3211 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set nvm data complete!\n"));
3212 if ((dlen_status & NVMD_STAT) != 0) {
3213 PM8001_FAIL_DBG(pm8001_ha,
3214 pm8001_printk("Set nvm data error!\n"));
3215 return;
3216 }
3217 ccb->task = NULL;
3218 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303219 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003220}
3221
Sakthivel Kf74cf272013-02-27 20:27:43 +05303222void
3223pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003224{
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303225 struct fw_control_ex *fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003226 struct get_nvm_data_resp *pPayload =
3227 (struct get_nvm_data_resp *)(piomb + 4);
3228 u32 tag = le32_to_cpu(pPayload->tag);
3229 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3230 u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
3231 u32 ir_tds_bn_dps_das_nvm =
3232 le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm);
3233 void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303234 fw_control_context = ccb->fw_control_context;
jack wangdbf9bfe2009-10-14 16:19:21 +08003235
3236 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get nvm data complete!\n"));
3237 if ((dlen_status & NVMD_STAT) != 0) {
3238 PM8001_FAIL_DBG(pm8001_ha,
3239 pm8001_printk("Get nvm data error!\n"));
3240 complete(pm8001_ha->nvmd_completion);
3241 return;
3242 }
3243
3244 if (ir_tds_bn_dps_das_nvm & IPMode) {
3245 /* indirect mode - IR bit set */
3246 PM8001_MSG_DBG(pm8001_ha,
3247 pm8001_printk("Get NVMD success, IR=1\n"));
3248 if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) {
3249 if (ir_tds_bn_dps_das_nvm == 0x80a80200) {
3250 memcpy(pm8001_ha->sas_addr,
3251 ((u8 *)virt_addr + 4),
3252 SAS_ADDR_SIZE);
3253 PM8001_MSG_DBG(pm8001_ha,
3254 pm8001_printk("Get SAS address"
3255 " from VPD successfully!\n"));
3256 }
3257 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM)
3258 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) ||
3259 ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) {
3260 ;
3261 } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP)
3262 || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) {
3263 ;
3264 } else {
3265 /* Should not be happened*/
3266 PM8001_MSG_DBG(pm8001_ha,
3267 pm8001_printk("(IR=1)Wrong Device type 0x%x\n",
3268 ir_tds_bn_dps_das_nvm));
3269 }
3270 } else /* direct mode */{
3271 PM8001_MSG_DBG(pm8001_ha,
3272 pm8001_printk("Get NVMD success, IR=0, dataLen=%d\n",
3273 (dlen_status & NVMD_LEN) >> 24));
3274 }
Suresh Thiagarajan9e032842014-08-11 11:50:35 +05303275 /* Though fw_control_context is freed below, usrAddr still needs
3276 * to be updated as this holds the response to the request function
3277 */
3278 memcpy(fw_control_context->usrAddr,
3279 pm8001_ha->memoryMap.region[NVMD].virt_ptr,
3280 fw_control_context->len);
Tomas Henzlf3a06552014-07-07 17:19:58 +02003281 kfree(ccb->fw_control_context);
yuuzheng1f889b52020-11-02 22:25:28 +05303282 /* To avoid race condition, complete should be
3283 * called after the message is copied to
3284 * fw_control_context->usrAddr
3285 */
3286 complete(pm8001_ha->nvmd_completion);
3287 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set nvm data complete!\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003288 ccb->task = NULL;
3289 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303290 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003291}
3292
Sakthivel Kf74cf272013-02-27 20:27:43 +05303293int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003294{
Viswas G25c6edb2017-10-18 11:39:10 +05303295 u32 tag;
jack wangdbf9bfe2009-10-14 16:19:21 +08003296 struct local_phy_ctl_resp *pPayload =
3297 (struct local_phy_ctl_resp *)(piomb + 4);
3298 u32 status = le32_to_cpu(pPayload->status);
3299 u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
3300 u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
Viswas G25c6edb2017-10-18 11:39:10 +05303301 tag = le32_to_cpu(pPayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003302 if (status != 0) {
3303 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003304 pm8001_printk("%x phy execute %x phy op failed!\n",
jack wangdbf9bfe2009-10-14 16:19:21 +08003305 phy_id, phy_op));
Viswas G869ddbd2017-10-18 11:39:13 +05303306 } else {
jack wangdbf9bfe2009-10-14 16:19:21 +08003307 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003308 pm8001_printk("%x phy execute %x phy op success!\n",
jack wangdbf9bfe2009-10-14 16:19:21 +08003309 phy_id, phy_op));
Viswas G869ddbd2017-10-18 11:39:13 +05303310 pm8001_ha->phy[phy_id].reset_success = true;
3311 }
3312 if (pm8001_ha->phy[phy_id].enable_completion) {
3313 complete(pm8001_ha->phy[phy_id].enable_completion);
3314 pm8001_ha->phy[phy_id].enable_completion = NULL;
3315 }
Viswas G25c6edb2017-10-18 11:39:10 +05303316 pm8001_tag_free(pm8001_ha, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003317 return 0;
3318}
3319
3320/**
3321 * pm8001_bytes_dmaed - one of the interface function communication with libsas
3322 * @pm8001_ha: our hba card information
3323 * @i: which phy that received the event.
3324 *
3325 * when HBA driver received the identify done event or initiate FIS received
3326 * event(for SATA), it will invoke this function to notify the sas layer that
3327 * the sas toplogy has formed, please discover the the whole sas domain,
3328 * while receive a broadcast(change) primitive just tell the sas
3329 * layer to discover the changed domain rather than the whole domain.
3330 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303331void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i)
jack wangdbf9bfe2009-10-14 16:19:21 +08003332{
3333 struct pm8001_phy *phy = &pm8001_ha->phy[i];
3334 struct asd_sas_phy *sas_phy = &phy->sas_phy;
jack wangdbf9bfe2009-10-14 16:19:21 +08003335 if (!phy->phy_attached)
3336 return;
3337
jack wangdbf9bfe2009-10-14 16:19:21 +08003338 if (sas_phy->phy) {
3339 struct sas_phy *sphy = sas_phy->phy;
3340 sphy->negotiated_linkrate = sas_phy->linkrate;
3341 sphy->minimum_linkrate = phy->minimum_linkrate;
3342 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3343 sphy->maximum_linkrate = phy->maximum_linkrate;
3344 sphy->maximum_linkrate_hw = phy->maximum_linkrate;
3345 }
3346
3347 if (phy->phy_type & PORT_TYPE_SAS) {
3348 struct sas_identify_frame *id;
3349 id = (struct sas_identify_frame *)phy->frame_rcvd;
3350 id->dev_type = phy->identify.device_type;
3351 id->initiator_bits = SAS_PROTOCOL_ALL;
3352 id->target_bits = phy->identify.target_port_protocols;
3353 } else if (phy->phy_type & PORT_TYPE_SATA) {
3354 /*Nothing*/
3355 }
3356 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("phy %d byte dmaded.\n", i));
3357
3358 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
3359 pm8001_ha->sas->notify_port_event(sas_phy, PORTE_BYTES_DMAED);
3360}
3361
3362/* Get the link rate speed */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303363void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate)
jack wangdbf9bfe2009-10-14 16:19:21 +08003364{
3365 struct sas_phy *sas_phy = phy->sas_phy.phy;
3366
3367 switch (link_rate) {
Viswas Gb093d592015-08-11 15:06:25 +05303368 case PHY_SPEED_120:
3369 phy->sas_phy.linkrate = SAS_LINK_RATE_12_0_GBPS;
3370 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_12_0_GBPS;
3371 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08003372 case PHY_SPEED_60:
3373 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
3374 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3375 break;
3376 case PHY_SPEED_30:
3377 phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
3378 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3379 break;
3380 case PHY_SPEED_15:
3381 phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
3382 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
3383 break;
3384 }
3385 sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
3386 sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS;
3387 sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3388 sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
3389 sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3390}
3391
3392/**
3393 * asd_get_attached_sas_addr -- extract/generate attached SAS address
3394 * @phy: pointer to asd_phy
3395 * @sas_addr: pointer to buffer where the SAS address is to be written
3396 *
3397 * This function extracts the SAS address from an IDENTIFY frame
3398 * received. If OOB is SATA, then a SAS address is generated from the
3399 * HA tables.
3400 *
3401 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
3402 * buffer.
3403 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303404void pm8001_get_attached_sas_addr(struct pm8001_phy *phy,
jack wangdbf9bfe2009-10-14 16:19:21 +08003405 u8 *sas_addr)
3406{
3407 if (phy->sas_phy.frame_rcvd[0] == 0x34
3408 && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
3409 struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha;
3410 /* FIS device-to-host */
3411 u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr);
3412 addr += phy->sas_phy.id;
3413 *(__be64 *)sas_addr = cpu_to_be64(addr);
3414 } else {
3415 struct sas_identify_frame *idframe =
3416 (void *) phy->sas_phy.frame_rcvd;
3417 memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
3418 }
3419}
3420
3421/**
3422 * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
3423 * @pm8001_ha: our hba card information
3424 * @Qnum: the outbound queue message number.
3425 * @SEA: source of event to ack
3426 * @port_id: port id.
3427 * @phyId: phy id.
3428 * @param0: parameter 0.
3429 * @param1: parameter 1.
3430 */
3431static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
3432 u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
3433{
3434 struct hw_event_ack_req payload;
3435 u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
3436
3437 struct inbound_queue_table *circularQ;
3438
3439 memset((u8 *)&payload, 0, sizeof(payload));
3440 circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
Santosh Nayak8270ee22012-02-26 20:14:46 +05303441 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08003442 payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
3443 ((phyId & 0x0F) << 4) | (port_id & 0x0F));
3444 payload.param0 = cpu_to_le32(param0);
3445 payload.param1 = cpu_to_le32(param1);
peter chang91a43fa2019-11-14 15:39:05 +05303446 pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
3447 sizeof(payload), 0);
jack wangdbf9bfe2009-10-14 16:19:21 +08003448}
3449
3450static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
3451 u32 phyId, u32 phy_op);
3452
3453/**
3454 * hw_event_sas_phy_up -FW tells me a SAS phy up event.
3455 * @pm8001_ha: our hba card information
3456 * @piomb: IO message buffer
3457 */
3458static void
3459hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3460{
3461 struct hw_event_resp *pPayload =
3462 (struct hw_event_resp *)(piomb + 4);
3463 u32 lr_evt_status_phyid_portid =
3464 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3465 u8 link_rate =
3466 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003467 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003468 u8 phy_id =
3469 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003470 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3471 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3472 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003473 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3474 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3475 unsigned long flags;
3476 u8 deviceType = pPayload->sas_identify.dev_type;
jack wang1cc943a2009-12-07 17:22:42 +08003477 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303478 phy->phy_state = PHY_STATE_LINK_UP_SPC;
jack wangdbf9bfe2009-10-14 16:19:21 +08003479 PM8001_MSG_DBG(pm8001_ha,
jack wang83e73322009-12-07 17:23:11 +08003480 pm8001_printk("HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n",
3481 port_id, phy_id));
jack wangdbf9bfe2009-10-14 16:19:21 +08003482
3483 switch (deviceType) {
3484 case SAS_PHY_UNUSED:
3485 PM8001_MSG_DBG(pm8001_ha,
3486 pm8001_printk("device type no device.\n"));
3487 break;
3488 case SAS_END_DEVICE:
3489 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
3490 pm8001_chip_phy_ctl_req(pm8001_ha, phy_id,
3491 PHY_NOTIFY_ENABLE_SPINUP);
jack wang1cc943a2009-12-07 17:22:42 +08003492 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303493 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003494 break;
3495 case SAS_EDGE_EXPANDER_DEVICE:
3496 PM8001_MSG_DBG(pm8001_ha,
3497 pm8001_printk("expander device.\n"));
jack wang1cc943a2009-12-07 17:22:42 +08003498 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303499 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003500 break;
3501 case SAS_FANOUT_EXPANDER_DEVICE:
3502 PM8001_MSG_DBG(pm8001_ha,
3503 pm8001_printk("fanout expander device.\n"));
jack wang1cc943a2009-12-07 17:22:42 +08003504 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303505 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003506 break;
3507 default:
peter chang73706722019-11-14 15:39:02 +05303508 PM8001_DEVIO_DBG(pm8001_ha,
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003509 pm8001_printk("unknown device type(%x)\n", deviceType));
jack wangdbf9bfe2009-10-14 16:19:21 +08003510 break;
3511 }
3512 phy->phy_type |= PORT_TYPE_SAS;
3513 phy->identify.device_type = deviceType;
3514 phy->phy_attached = 1;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303515 if (phy->identify.device_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08003516 phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
Santosh Nayak8270ee22012-02-26 20:14:46 +05303517 else if (phy->identify.device_type != SAS_PHY_UNUSED)
jack wangdbf9bfe2009-10-14 16:19:21 +08003518 phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
3519 phy->sas_phy.oob_mode = SAS_OOB_MODE;
3520 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
3521 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3522 memcpy(phy->frame_rcvd, &pPayload->sas_identify,
3523 sizeof(struct sas_identify_frame)-4);
3524 phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
3525 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3526 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3527 if (pm8001_ha->flags == PM8001F_RUN_TIME)
3528 mdelay(200);/*delay a moment to wait disk to spinup*/
3529 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3530}
3531
3532/**
3533 * hw_event_sata_phy_up -FW tells me a SATA phy up event.
3534 * @pm8001_ha: our hba card information
3535 * @piomb: IO message buffer
3536 */
3537static void
3538hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
3539{
3540 struct hw_event_resp *pPayload =
3541 (struct hw_event_resp *)(piomb + 4);
3542 u32 lr_evt_status_phyid_portid =
3543 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3544 u8 link_rate =
3545 (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
jack wang1cc943a2009-12-07 17:22:42 +08003546 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
jack wangdbf9bfe2009-10-14 16:19:21 +08003547 u8 phy_id =
3548 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
jack wang1cc943a2009-12-07 17:22:42 +08003549 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3550 u8 portstate = (u8)(npip_portstate & 0x0000000F);
3551 struct pm8001_port *port = &pm8001_ha->port[port_id];
jack wangdbf9bfe2009-10-14 16:19:21 +08003552 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3553 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3554 unsigned long flags;
peter chang73706722019-11-14 15:39:02 +05303555 PM8001_DEVIO_DBG(pm8001_ha,
jack wang83e73322009-12-07 17:23:11 +08003556 pm8001_printk("HW_EVENT_SATA_PHY_UP port id = %d,"
3557 " phy id = %d\n", port_id, phy_id));
jack wang1cc943a2009-12-07 17:22:42 +08003558 port->port_state = portstate;
Nikith Ganigarakoppal7d029002013-10-30 16:23:47 +05303559 phy->phy_state = PHY_STATE_LINK_UP_SPC;
jack wang1cc943a2009-12-07 17:22:42 +08003560 port->port_attached = 1;
Sakthivel Kf74cf272013-02-27 20:27:43 +05303561 pm8001_get_lrate_mode(phy, link_rate);
jack wangdbf9bfe2009-10-14 16:19:21 +08003562 phy->phy_type |= PORT_TYPE_SATA;
3563 phy->phy_attached = 1;
3564 phy->sas_phy.oob_mode = SATA_OOB_MODE;
3565 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
3566 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
3567 memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
3568 sizeof(struct dev_to_host_fis));
3569 phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
3570 phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
James Bottomleyaa9f8322013-05-07 14:44:06 -07003571 phy->identify.device_type = SAS_SATA_DEV;
jack wangdbf9bfe2009-10-14 16:19:21 +08003572 pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
3573 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
3574 pm8001_bytes_dmaed(pm8001_ha, phy_id);
3575}
3576
3577/**
3578 * hw_event_phy_down -we should notify the libsas the phy is down.
3579 * @pm8001_ha: our hba card information
3580 * @piomb: IO message buffer
3581 */
3582static void
3583hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
3584{
3585 struct hw_event_resp *pPayload =
3586 (struct hw_event_resp *)(piomb + 4);
3587 u32 lr_evt_status_phyid_portid =
3588 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3589 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3590 u8 phy_id =
3591 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3592 u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
3593 u8 portstate = (u8)(npip_portstate & 0x0000000F);
jack wang1cc943a2009-12-07 17:22:42 +08003594 struct pm8001_port *port = &pm8001_ha->port[port_id];
3595 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3596 port->port_state = portstate;
3597 phy->phy_type = 0;
3598 phy->identify.device_type = 0;
3599 phy->phy_attached = 0;
3600 memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
jack wangdbf9bfe2009-10-14 16:19:21 +08003601 switch (portstate) {
3602 case PORT_VALID:
3603 break;
3604 case PORT_INVALID:
3605 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003606 pm8001_printk(" PortInvalid portID %d\n", port_id));
jack wangdbf9bfe2009-10-14 16:19:21 +08003607 PM8001_MSG_DBG(pm8001_ha,
3608 pm8001_printk(" Last phy Down and port invalid\n"));
jack wang1cc943a2009-12-07 17:22:42 +08003609 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003610 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3611 port_id, phy_id, 0, 0);
3612 break;
3613 case PORT_IN_RESET:
3614 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003615 pm8001_printk(" Port In Reset portID %d\n", port_id));
jack wangdbf9bfe2009-10-14 16:19:21 +08003616 break;
3617 case PORT_NOT_ESTABLISHED:
3618 PM8001_MSG_DBG(pm8001_ha,
3619 pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n"));
jack wang1cc943a2009-12-07 17:22:42 +08003620 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003621 break;
3622 case PORT_LOSTCOMM:
3623 PM8001_MSG_DBG(pm8001_ha,
3624 pm8001_printk(" phy Down and PORT_LOSTCOMM\n"));
3625 PM8001_MSG_DBG(pm8001_ha,
3626 pm8001_printk(" Last phy Down and port invalid\n"));
jack wang1cc943a2009-12-07 17:22:42 +08003627 port->port_attached = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08003628 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
3629 port_id, phy_id, 0, 0);
3630 break;
3631 default:
jack wang1cc943a2009-12-07 17:22:42 +08003632 port->port_attached = 0;
peter chang73706722019-11-14 15:39:02 +05303633 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08003634 pm8001_printk(" phy Down and(default) = %x\n",
3635 portstate));
3636 break;
3637
3638 }
3639}
3640
3641/**
Sakthivel Kf74cf272013-02-27 20:27:43 +05303642 * pm8001_mpi_reg_resp -process register device ID response.
jack wangdbf9bfe2009-10-14 16:19:21 +08003643 * @pm8001_ha: our hba card information
3644 * @piomb: IO message buffer
3645 *
3646 * when sas layer find a device it will notify LLDD, then the driver register
3647 * the domain device to FW, this event is the return device ID which the FW
3648 * has assigned, from now,inter-communication with FW is no longer using the
3649 * SAS address, use device ID which FW assigned.
3650 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05303651int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003652{
3653 u32 status;
3654 u32 device_id;
3655 u32 htag;
3656 struct pm8001_ccb_info *ccb;
3657 struct pm8001_device *pm8001_dev;
3658 struct dev_reg_resp *registerRespPayload =
3659 (struct dev_reg_resp *)(piomb + 4);
3660
3661 htag = le32_to_cpu(registerRespPayload->tag);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303662 ccb = &pm8001_ha->ccb_info[htag];
jack wangdbf9bfe2009-10-14 16:19:21 +08003663 pm8001_dev = ccb->device;
3664 status = le32_to_cpu(registerRespPayload->status);
3665 device_id = le32_to_cpu(registerRespPayload->device_id);
3666 PM8001_MSG_DBG(pm8001_ha,
3667 pm8001_printk(" register device is status = %d\n", status));
3668 switch (status) {
3669 case DEVREG_SUCCESS:
3670 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_SUCCESS\n"));
3671 pm8001_dev->device_id = device_id;
3672 break;
3673 case DEVREG_FAILURE_OUT_OF_RESOURCE:
3674 PM8001_MSG_DBG(pm8001_ha,
3675 pm8001_printk("DEVREG_FAILURE_OUT_OF_RESOURCE\n"));
3676 break;
3677 case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED:
3678 PM8001_MSG_DBG(pm8001_ha,
3679 pm8001_printk("DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n"));
3680 break;
3681 case DEVREG_FAILURE_INVALID_PHY_ID:
3682 PM8001_MSG_DBG(pm8001_ha,
3683 pm8001_printk("DEVREG_FAILURE_INVALID_PHY_ID\n"));
3684 break;
3685 case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED:
3686 PM8001_MSG_DBG(pm8001_ha,
3687 pm8001_printk("DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n"));
3688 break;
3689 case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE:
3690 PM8001_MSG_DBG(pm8001_ha,
3691 pm8001_printk("DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n"));
3692 break;
3693 case DEVREG_FAILURE_PORT_NOT_VALID_STATE:
3694 PM8001_MSG_DBG(pm8001_ha,
3695 pm8001_printk("DEVREG_FAILURE_PORT_NOT_VALID_STATE\n"));
3696 break;
3697 case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID:
3698 PM8001_MSG_DBG(pm8001_ha,
3699 pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n"));
3700 break;
3701 default:
3702 PM8001_MSG_DBG(pm8001_ha,
Colin Ian King9af3c472018-05-26 15:42:18 +01003703 pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003704 break;
3705 }
3706 complete(pm8001_dev->dcompletion);
3707 ccb->task = NULL;
3708 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303709 pm8001_tag_free(pm8001_ha, htag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003710 return 0;
3711}
3712
Sakthivel Kf74cf272013-02-27 20:27:43 +05303713int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003714{
3715 u32 status;
3716 u32 device_id;
3717 struct dev_reg_resp *registerRespPayload =
3718 (struct dev_reg_resp *)(piomb + 4);
3719
3720 status = le32_to_cpu(registerRespPayload->status);
3721 device_id = le32_to_cpu(registerRespPayload->device_id);
3722 if (status != 0)
3723 PM8001_MSG_DBG(pm8001_ha,
3724 pm8001_printk(" deregister device failed ,status = %x"
3725 ", device_id = %x\n", status, device_id));
3726 return 0;
3727}
3728
Sakthivel Kf74cf272013-02-27 20:27:43 +05303729/**
3730 * fw_flash_update_resp - Response from FW for flash update command.
3731 * @pm8001_ha: our hba card information
3732 * @piomb: IO message buffer
3733 */
3734int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha,
3735 void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003736{
3737 u32 status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003738 struct fw_flash_Update_resp *ppayload =
3739 (struct fw_flash_Update_resp *)(piomb + 4);
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05303740 u32 tag = le32_to_cpu(ppayload->tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003741 struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
3742 status = le32_to_cpu(ppayload->status);
jack wangdbf9bfe2009-10-14 16:19:21 +08003743 switch (status) {
3744 case FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
3745 PM8001_MSG_DBG(pm8001_ha,
3746 pm8001_printk(": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n"));
3747 break;
3748 case FLASH_UPDATE_IN_PROGRESS:
3749 PM8001_MSG_DBG(pm8001_ha,
3750 pm8001_printk(": FLASH_UPDATE_IN_PROGRESS\n"));
3751 break;
3752 case FLASH_UPDATE_HDR_ERR:
3753 PM8001_MSG_DBG(pm8001_ha,
3754 pm8001_printk(": FLASH_UPDATE_HDR_ERR\n"));
3755 break;
3756 case FLASH_UPDATE_OFFSET_ERR:
3757 PM8001_MSG_DBG(pm8001_ha,
3758 pm8001_printk(": FLASH_UPDATE_OFFSET_ERR\n"));
3759 break;
3760 case FLASH_UPDATE_CRC_ERR:
3761 PM8001_MSG_DBG(pm8001_ha,
3762 pm8001_printk(": FLASH_UPDATE_CRC_ERR\n"));
3763 break;
3764 case FLASH_UPDATE_LENGTH_ERR:
3765 PM8001_MSG_DBG(pm8001_ha,
3766 pm8001_printk(": FLASH_UPDATE_LENGTH_ERR\n"));
3767 break;
3768 case FLASH_UPDATE_HW_ERR:
3769 PM8001_MSG_DBG(pm8001_ha,
3770 pm8001_printk(": FLASH_UPDATE_HW_ERR\n"));
3771 break;
3772 case FLASH_UPDATE_DNLD_NOT_SUPPORTED:
3773 PM8001_MSG_DBG(pm8001_ha,
3774 pm8001_printk(": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n"));
3775 break;
3776 case FLASH_UPDATE_DISABLED:
3777 PM8001_MSG_DBG(pm8001_ha,
3778 pm8001_printk(": FLASH_UPDATE_DISABLED\n"));
3779 break;
3780 default:
peter chang73706722019-11-14 15:39:02 +05303781 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08003782 pm8001_printk("No matched status = %d\n", status));
3783 break;
3784 }
Tomas Henzl9422e862014-07-07 17:20:00 +02003785 kfree(ccb->fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08003786 ccb->task = NULL;
3787 ccb->ccb_tag = 0xFFFFFFFF;
Tomas Henzlef300542014-07-09 17:20:40 +05303788 pm8001_tag_free(pm8001_ha, tag);
Tomas Henzl9422e862014-07-07 17:20:00 +02003789 complete(pm8001_ha->nvmd_completion);
jack wangdbf9bfe2009-10-14 16:19:21 +08003790 return 0;
3791}
3792
Sakthivel Kf74cf272013-02-27 20:27:43 +05303793int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003794{
3795 u32 status;
3796 int i;
3797 struct general_event_resp *pPayload =
3798 (struct general_event_resp *)(piomb + 4);
3799 status = le32_to_cpu(pPayload->status);
3800 PM8001_MSG_DBG(pm8001_ha,
3801 pm8001_printk(" status = 0x%x\n", status));
3802 for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
3803 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003804 pm8001_printk("inb_IOMB_payload[0x%x] 0x%x,\n", i,
jack wangdbf9bfe2009-10-14 16:19:21 +08003805 pPayload->inb_IOMB_payload[i]));
3806 return 0;
3807}
3808
Sakthivel Kf74cf272013-02-27 20:27:43 +05303809int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
jack wangdbf9bfe2009-10-14 16:19:21 +08003810{
3811 struct sas_task *t;
3812 struct pm8001_ccb_info *ccb;
3813 unsigned long flags;
3814 u32 status ;
3815 u32 tag, scp;
3816 struct task_status_struct *ts;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303817 struct pm8001_device *pm8001_dev;
jack wangdbf9bfe2009-10-14 16:19:21 +08003818
3819 struct task_abort_resp *pPayload =
3820 (struct task_abort_resp *)(piomb + 4);
jack wangdbf9bfe2009-10-14 16:19:21 +08003821
3822 status = le32_to_cpu(pPayload->status);
3823 tag = le32_to_cpu(pPayload->tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303824 if (!tag) {
3825 PM8001_FAIL_DBG(pm8001_ha,
3826 pm8001_printk(" TAG NULL. RETURNING !!!"));
3827 return -1;
3828 }
3829
jack wangdbf9bfe2009-10-14 16:19:21 +08003830 scp = le32_to_cpu(pPayload->scp);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303831 ccb = &pm8001_ha->ccb_info[tag];
3832 t = ccb->task;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303833 pm8001_dev = ccb->device; /* retrieve device */
3834
3835 if (!t) {
3836 PM8001_FAIL_DBG(pm8001_ha,
3837 pm8001_printk(" TASK NULL. RETURNING !!!"));
jack_wang72d0baa2009-11-05 22:33:35 +08003838 return -1;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303839 }
jack_wang72d0baa2009-11-05 22:33:35 +08003840 ts = &t->task_status;
jack wangdbf9bfe2009-10-14 16:19:21 +08003841 if (status != 0)
3842 PM8001_FAIL_DBG(pm8001_ha,
jack_wang72d0baa2009-11-05 22:33:35 +08003843 pm8001_printk("task abort failed status 0x%x ,"
3844 "tag = 0x%x, scp= 0x%x\n", status, tag, scp));
jack wangdbf9bfe2009-10-14 16:19:21 +08003845 switch (status) {
3846 case IO_SUCCESS:
jack_wang72d0baa2009-11-05 22:33:35 +08003847 PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003848 ts->resp = SAS_TASK_COMPLETE;
James Bottomleydf64d3c2010-07-27 15:51:13 -05003849 ts->stat = SAM_STAT_GOOD;
jack wangdbf9bfe2009-10-14 16:19:21 +08003850 break;
3851 case IO_NOT_VALID:
jack_wang72d0baa2009-11-05 22:33:35 +08003852 PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_NOT_VALID\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003853 ts->resp = TMF_RESP_FUNC_FAILED;
3854 break;
3855 }
3856 spin_lock_irqsave(&t->task_state_lock, flags);
3857 t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
3858 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
3859 t->task_state_flags |= SAS_TASK_STATE_DONE;
3860 spin_unlock_irqrestore(&t->task_state_lock, flags);
Santosh Nayak8270ee22012-02-26 20:14:46 +05303861 pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
jack wangdbf9bfe2009-10-14 16:19:21 +08003862 mb();
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303863
Dan Carpenter808cbb62013-05-09 15:48:13 +03003864 if (pm8001_dev->id & NCQ_ABORT_ALL_FLAG) {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05303865 pm8001_tag_free(pm8001_ha, tag);
3866 sas_free_task(t);
3867 /* clear the flag */
3868 pm8001_dev->id &= 0xBFFFFFFF;
3869 } else
3870 t->task_done(t);
3871
jack wangdbf9bfe2009-10-14 16:19:21 +08003872 return 0;
3873}
3874
3875/**
3876 * mpi_hw_event -The hw event has come.
3877 * @pm8001_ha: our hba card information
3878 * @piomb: IO message buffer
3879 */
3880static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
3881{
3882 unsigned long flags;
3883 struct hw_event_resp *pPayload =
3884 (struct hw_event_resp *)(piomb + 4);
3885 u32 lr_evt_status_phyid_portid =
3886 le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
3887 u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
3888 u8 phy_id =
3889 (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
3890 u16 eventType =
3891 (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8);
3892 u8 status =
3893 (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24);
3894 struct sas_ha_struct *sas_ha = pm8001_ha->sas;
3895 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
3896 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
peter chang73706722019-11-14 15:39:02 +05303897 PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk(
3898 "SPC HW event for portid:%d, phyid:%d, event:%x, status:%x\n",
3899 port_id, phy_id, eventType, status));
jack wangdbf9bfe2009-10-14 16:19:21 +08003900 switch (eventType) {
3901 case HW_EVENT_PHY_START_STATUS:
3902 PM8001_MSG_DBG(pm8001_ha,
3903 pm8001_printk("HW_EVENT_PHY_START_STATUS"
3904 " status = %x\n", status));
3905 if (status == 0) {
3906 phy->phy_state = 1;
Deepak Ukeycd135752018-09-11 14:18:02 +05303907 if (pm8001_ha->flags == PM8001F_RUN_TIME &&
3908 phy->enable_completion != NULL)
jack wangdbf9bfe2009-10-14 16:19:21 +08003909 complete(phy->enable_completion);
3910 }
3911 break;
3912 case HW_EVENT_SAS_PHY_UP:
3913 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003914 pm8001_printk("HW_EVENT_PHY_START_STATUS\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003915 hw_event_sas_phy_up(pm8001_ha, piomb);
3916 break;
3917 case HW_EVENT_SATA_PHY_UP:
3918 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003919 pm8001_printk("HW_EVENT_SATA_PHY_UP\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003920 hw_event_sata_phy_up(pm8001_ha, piomb);
3921 break;
3922 case HW_EVENT_PHY_STOP_STATUS:
3923 PM8001_MSG_DBG(pm8001_ha,
3924 pm8001_printk("HW_EVENT_PHY_STOP_STATUS "
3925 "status = %x\n", status));
3926 if (status == 0)
3927 phy->phy_state = 0;
3928 break;
3929 case HW_EVENT_SATA_SPINUP_HOLD:
3930 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003931 pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003932 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
3933 break;
3934 case HW_EVENT_PHY_DOWN:
3935 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07003936 pm8001_printk("HW_EVENT_PHY_DOWN\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08003937 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
3938 phy->phy_attached = 0;
3939 phy->phy_state = 0;
3940 hw_event_phy_down(pm8001_ha, piomb);
3941 break;
3942 case HW_EVENT_PORT_INVALID:
3943 PM8001_MSG_DBG(pm8001_ha,
3944 pm8001_printk("HW_EVENT_PORT_INVALID\n"));
3945 sas_phy_disconnected(sas_phy);
3946 phy->phy_attached = 0;
3947 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3948 break;
3949 /* the broadcast change primitive received, tell the LIBSAS this event
3950 to revalidate the sas domain*/
3951 case HW_EVENT_BROADCAST_CHANGE:
3952 PM8001_MSG_DBG(pm8001_ha,
3953 pm8001_printk("HW_EVENT_BROADCAST_CHANGE\n"));
3954 pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
3955 port_id, phy_id, 1, 0);
3956 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3957 sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
3958 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3959 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3960 break;
3961 case HW_EVENT_PHY_ERROR:
3962 PM8001_MSG_DBG(pm8001_ha,
3963 pm8001_printk("HW_EVENT_PHY_ERROR\n"));
3964 sas_phy_disconnected(&phy->sas_phy);
3965 phy->phy_attached = 0;
3966 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
3967 break;
3968 case HW_EVENT_BROADCAST_EXP:
3969 PM8001_MSG_DBG(pm8001_ha,
3970 pm8001_printk("HW_EVENT_BROADCAST_EXP\n"));
3971 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
3972 sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
3973 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
3974 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
3975 break;
3976 case HW_EVENT_LINK_ERR_INVALID_DWORD:
3977 PM8001_MSG_DBG(pm8001_ha,
3978 pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n"));
3979 pm8001_hw_event_ack_req(pm8001_ha, 0,
3980 HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
3981 sas_phy_disconnected(sas_phy);
3982 phy->phy_attached = 0;
3983 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3984 break;
3985 case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
3986 PM8001_MSG_DBG(pm8001_ha,
3987 pm8001_printk("HW_EVENT_LINK_ERR_DISPARITY_ERROR\n"));
3988 pm8001_hw_event_ack_req(pm8001_ha, 0,
3989 HW_EVENT_LINK_ERR_DISPARITY_ERROR,
3990 port_id, phy_id, 0, 0);
3991 sas_phy_disconnected(sas_phy);
3992 phy->phy_attached = 0;
3993 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
3994 break;
3995 case HW_EVENT_LINK_ERR_CODE_VIOLATION:
3996 PM8001_MSG_DBG(pm8001_ha,
3997 pm8001_printk("HW_EVENT_LINK_ERR_CODE_VIOLATION\n"));
3998 pm8001_hw_event_ack_req(pm8001_ha, 0,
3999 HW_EVENT_LINK_ERR_CODE_VIOLATION,
4000 port_id, phy_id, 0, 0);
4001 sas_phy_disconnected(sas_phy);
4002 phy->phy_attached = 0;
4003 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
4004 break;
4005 case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
4006 PM8001_MSG_DBG(pm8001_ha,
4007 pm8001_printk("HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n"));
4008 pm8001_hw_event_ack_req(pm8001_ha, 0,
4009 HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
4010 port_id, phy_id, 0, 0);
4011 sas_phy_disconnected(sas_phy);
4012 phy->phy_attached = 0;
4013 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
4014 break;
4015 case HW_EVENT_MALFUNCTION:
4016 PM8001_MSG_DBG(pm8001_ha,
4017 pm8001_printk("HW_EVENT_MALFUNCTION\n"));
4018 break;
4019 case HW_EVENT_BROADCAST_SES:
4020 PM8001_MSG_DBG(pm8001_ha,
4021 pm8001_printk("HW_EVENT_BROADCAST_SES\n"));
4022 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
4023 sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
4024 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
4025 sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
4026 break;
4027 case HW_EVENT_INBOUND_CRC_ERROR:
4028 PM8001_MSG_DBG(pm8001_ha,
4029 pm8001_printk("HW_EVENT_INBOUND_CRC_ERROR\n"));
4030 pm8001_hw_event_ack_req(pm8001_ha, 0,
4031 HW_EVENT_INBOUND_CRC_ERROR,
4032 port_id, phy_id, 0, 0);
4033 break;
4034 case HW_EVENT_HARD_RESET_RECEIVED:
4035 PM8001_MSG_DBG(pm8001_ha,
4036 pm8001_printk("HW_EVENT_HARD_RESET_RECEIVED\n"));
4037 sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
4038 break;
4039 case HW_EVENT_ID_FRAME_TIMEOUT:
4040 PM8001_MSG_DBG(pm8001_ha,
4041 pm8001_printk("HW_EVENT_ID_FRAME_TIMEOUT\n"));
4042 sas_phy_disconnected(sas_phy);
4043 phy->phy_attached = 0;
4044 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
4045 break;
4046 case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
4047 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004048 pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004049 pm8001_hw_event_ack_req(pm8001_ha, 0,
4050 HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
4051 port_id, phy_id, 0, 0);
4052 sas_phy_disconnected(sas_phy);
4053 phy->phy_attached = 0;
4054 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
4055 break;
4056 case HW_EVENT_PORT_RESET_TIMER_TMO:
4057 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004058 pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004059 sas_phy_disconnected(sas_phy);
4060 phy->phy_attached = 0;
4061 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
4062 break;
4063 case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
4064 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004065 pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004066 sas_phy_disconnected(sas_phy);
4067 phy->phy_attached = 0;
4068 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
4069 break;
4070 case HW_EVENT_PORT_RECOVER:
4071 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004072 pm8001_printk("HW_EVENT_PORT_RECOVER\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004073 break;
4074 case HW_EVENT_PORT_RESET_COMPLETE:
4075 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004076 pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004077 break;
4078 case EVENT_BROADCAST_ASYNCH_EVENT:
4079 PM8001_MSG_DBG(pm8001_ha,
4080 pm8001_printk("EVENT_BROADCAST_ASYNCH_EVENT\n"));
4081 break;
4082 default:
peter chang73706722019-11-14 15:39:02 +05304083 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004084 pm8001_printk("Unknown event type = %x\n", eventType));
4085 break;
4086 }
4087 return 0;
4088}
4089
4090/**
4091 * process_one_iomb - process one outbound Queue memory block
4092 * @pm8001_ha: our hba card information
4093 * @piomb: IO message buffer
4094 */
4095static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
4096{
Santosh Nayakfd00f7c2012-03-19 21:26:27 +05304097 __le32 pHeader = *(__le32 *)piomb;
4098 u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF);
jack wangdbf9bfe2009-10-14 16:19:21 +08004099
jack_wang72d0baa2009-11-05 22:33:35 +08004100 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004101
4102 switch (opc) {
4103 case OPC_OUB_ECHO:
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004104 PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004105 break;
4106 case OPC_OUB_HW_EVENT:
4107 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004108 pm8001_printk("OPC_OUB_HW_EVENT\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004109 mpi_hw_event(pm8001_ha, piomb);
4110 break;
4111 case OPC_OUB_SSP_COMP:
4112 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004113 pm8001_printk("OPC_OUB_SSP_COMP\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004114 mpi_ssp_completion(pm8001_ha, piomb);
4115 break;
4116 case OPC_OUB_SMP_COMP:
4117 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004118 pm8001_printk("OPC_OUB_SMP_COMP\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004119 mpi_smp_completion(pm8001_ha, piomb);
4120 break;
4121 case OPC_OUB_LOCAL_PHY_CNTRL:
4122 PM8001_MSG_DBG(pm8001_ha,
4123 pm8001_printk("OPC_OUB_LOCAL_PHY_CNTRL\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304124 pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004125 break;
4126 case OPC_OUB_DEV_REGIST:
4127 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004128 pm8001_printk("OPC_OUB_DEV_REGIST\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304129 pm8001_mpi_reg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004130 break;
4131 case OPC_OUB_DEREG_DEV:
4132 PM8001_MSG_DBG(pm8001_ha,
Masanari Iida44ebf892012-02-03 02:25:22 +09004133 pm8001_printk("unregister the device\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304134 pm8001_mpi_dereg_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004135 break;
4136 case OPC_OUB_GET_DEV_HANDLE:
4137 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004138 pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004139 break;
4140 case OPC_OUB_SATA_COMP:
4141 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004142 pm8001_printk("OPC_OUB_SATA_COMP\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004143 mpi_sata_completion(pm8001_ha, piomb);
4144 break;
4145 case OPC_OUB_SATA_EVENT:
4146 PM8001_MSG_DBG(pm8001_ha,
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004147 pm8001_printk("OPC_OUB_SATA_EVENT\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004148 mpi_sata_event(pm8001_ha, piomb);
4149 break;
4150 case OPC_OUB_SSP_EVENT:
4151 PM8001_MSG_DBG(pm8001_ha,
4152 pm8001_printk("OPC_OUB_SSP_EVENT\n"));
4153 mpi_ssp_event(pm8001_ha, piomb);
4154 break;
4155 case OPC_OUB_DEV_HANDLE_ARRIV:
4156 PM8001_MSG_DBG(pm8001_ha,
4157 pm8001_printk("OPC_OUB_DEV_HANDLE_ARRIV\n"));
4158 /*This is for target*/
4159 break;
4160 case OPC_OUB_SSP_RECV_EVENT:
4161 PM8001_MSG_DBG(pm8001_ha,
4162 pm8001_printk("OPC_OUB_SSP_RECV_EVENT\n"));
4163 /*This is for target*/
4164 break;
4165 case OPC_OUB_DEV_INFO:
4166 PM8001_MSG_DBG(pm8001_ha,
4167 pm8001_printk("OPC_OUB_DEV_INFO\n"));
4168 break;
4169 case OPC_OUB_FW_FLASH_UPDATE:
4170 PM8001_MSG_DBG(pm8001_ha,
4171 pm8001_printk("OPC_OUB_FW_FLASH_UPDATE\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304172 pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004173 break;
4174 case OPC_OUB_GPIO_RESPONSE:
4175 PM8001_MSG_DBG(pm8001_ha,
4176 pm8001_printk("OPC_OUB_GPIO_RESPONSE\n"));
4177 break;
4178 case OPC_OUB_GPIO_EVENT:
4179 PM8001_MSG_DBG(pm8001_ha,
4180 pm8001_printk("OPC_OUB_GPIO_EVENT\n"));
4181 break;
4182 case OPC_OUB_GENERAL_EVENT:
4183 PM8001_MSG_DBG(pm8001_ha,
4184 pm8001_printk("OPC_OUB_GENERAL_EVENT\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304185 pm8001_mpi_general_event(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004186 break;
4187 case OPC_OUB_SSP_ABORT_RSP:
4188 PM8001_MSG_DBG(pm8001_ha,
4189 pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304190 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004191 break;
4192 case OPC_OUB_SATA_ABORT_RSP:
4193 PM8001_MSG_DBG(pm8001_ha,
4194 pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304195 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004196 break;
4197 case OPC_OUB_SAS_DIAG_MODE_START_END:
4198 PM8001_MSG_DBG(pm8001_ha,
4199 pm8001_printk("OPC_OUB_SAS_DIAG_MODE_START_END\n"));
4200 break;
4201 case OPC_OUB_SAS_DIAG_EXECUTE:
4202 PM8001_MSG_DBG(pm8001_ha,
4203 pm8001_printk("OPC_OUB_SAS_DIAG_EXECUTE\n"));
4204 break;
4205 case OPC_OUB_GET_TIME_STAMP:
4206 PM8001_MSG_DBG(pm8001_ha,
4207 pm8001_printk("OPC_OUB_GET_TIME_STAMP\n"));
4208 break;
4209 case OPC_OUB_SAS_HW_EVENT_ACK:
4210 PM8001_MSG_DBG(pm8001_ha,
4211 pm8001_printk("OPC_OUB_SAS_HW_EVENT_ACK\n"));
4212 break;
4213 case OPC_OUB_PORT_CONTROL:
4214 PM8001_MSG_DBG(pm8001_ha,
4215 pm8001_printk("OPC_OUB_PORT_CONTROL\n"));
4216 break;
4217 case OPC_OUB_SMP_ABORT_RSP:
4218 PM8001_MSG_DBG(pm8001_ha,
4219 pm8001_printk("OPC_OUB_SMP_ABORT_RSP\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304220 pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004221 break;
4222 case OPC_OUB_GET_NVMD_DATA:
4223 PM8001_MSG_DBG(pm8001_ha,
4224 pm8001_printk("OPC_OUB_GET_NVMD_DATA\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304225 pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004226 break;
4227 case OPC_OUB_SET_NVMD_DATA:
4228 PM8001_MSG_DBG(pm8001_ha,
4229 pm8001_printk("OPC_OUB_SET_NVMD_DATA\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304230 pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004231 break;
4232 case OPC_OUB_DEVICE_HANDLE_REMOVAL:
4233 PM8001_MSG_DBG(pm8001_ha,
4234 pm8001_printk("OPC_OUB_DEVICE_HANDLE_REMOVAL\n"));
4235 break;
4236 case OPC_OUB_SET_DEVICE_STATE:
4237 PM8001_MSG_DBG(pm8001_ha,
4238 pm8001_printk("OPC_OUB_SET_DEVICE_STATE\n"));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304239 pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
jack wangdbf9bfe2009-10-14 16:19:21 +08004240 break;
4241 case OPC_OUB_GET_DEVICE_STATE:
4242 PM8001_MSG_DBG(pm8001_ha,
4243 pm8001_printk("OPC_OUB_GET_DEVICE_STATE\n"));
4244 break;
4245 case OPC_OUB_SET_DEV_INFO:
4246 PM8001_MSG_DBG(pm8001_ha,
4247 pm8001_printk("OPC_OUB_SET_DEV_INFO\n"));
4248 break;
4249 case OPC_OUB_SAS_RE_INITIALIZE:
4250 PM8001_MSG_DBG(pm8001_ha,
4251 pm8001_printk("OPC_OUB_SAS_RE_INITIALIZE\n"));
4252 break;
4253 default:
peter chang73706722019-11-14 15:39:02 +05304254 PM8001_DEVIO_DBG(pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004255 pm8001_printk("Unknown outbound Queue IOMB OPC = %x\n",
4256 opc));
4257 break;
4258 }
4259}
4260
Sakthivel Kf74cf272013-02-27 20:27:43 +05304261static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004262{
4263 struct outbound_queue_table *circularQ;
4264 void *pMsg1 = NULL;
Kees Cook3f649ab2020-06-03 13:09:38 -07004265 u8 bc;
jack_wang72d0baa2009-11-05 22:33:35 +08004266 u32 ret = MPI_IO_STATUS_FAIL;
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304267 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004268
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304269 spin_lock_irqsave(&pm8001_ha->lock, flags);
Sakthivel Kf74cf272013-02-27 20:27:43 +05304270 circularQ = &pm8001_ha->outbnd_q_tbl[vec];
jack wangdbf9bfe2009-10-14 16:19:21 +08004271 do {
Sakthivel Kf74cf272013-02-27 20:27:43 +05304272 ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004273 if (MPI_IO_STATUS_SUCCESS == ret) {
4274 /* process the outbound message */
jack_wang72d0baa2009-11-05 22:33:35 +08004275 process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
jack wangdbf9bfe2009-10-14 16:19:21 +08004276 /* free the message from the outbound circular buffer */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304277 pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
4278 circularQ, bc);
jack wangdbf9bfe2009-10-14 16:19:21 +08004279 }
4280 if (MPI_IO_STATUS_BUSY == ret) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004281 /* Update the producer index from SPC */
Santosh Nayak8270ee22012-02-26 20:14:46 +05304282 circularQ->producer_index =
4283 cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
4284 if (le32_to_cpu(circularQ->producer_index) ==
jack wangdbf9bfe2009-10-14 16:19:21 +08004285 circularQ->consumer_idx)
4286 /* OQ is empty */
4287 break;
4288 }
jack_wang72d0baa2009-11-05 22:33:35 +08004289 } while (1);
Santosh Nayak50ec5ba2012-02-26 19:05:03 +05304290 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
jack wangdbf9bfe2009-10-14 16:19:21 +08004291 return ret;
4292}
4293
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004294/* DMA_... to our direction translation. */
jack wangdbf9bfe2009-10-14 16:19:21 +08004295static const u8 data_dir_flags[] = {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004296 [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
4297 [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
4298 [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */
4299 [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */
jack wangdbf9bfe2009-10-14 16:19:21 +08004300};
Sakthivel Kf74cf272013-02-27 20:27:43 +05304301void
jack wangdbf9bfe2009-10-14 16:19:21 +08004302pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
4303{
4304 int i;
4305 struct scatterlist *sg;
4306 struct pm8001_prd *buf_prd = prd;
4307
4308 for_each_sg(scatter, sg, nr, i) {
4309 buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
4310 buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
4311 buf_prd->im_len.e = 0;
4312 buf_prd++;
4313 }
4314}
4315
Santosh Nayak8270ee22012-02-26 20:14:46 +05304316static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd)
jack wangdbf9bfe2009-10-14 16:19:21 +08004317{
Santosh Nayak8270ee22012-02-26 20:14:46 +05304318 psmp_cmd->tag = hTag;
jack wangdbf9bfe2009-10-14 16:19:21 +08004319 psmp_cmd->device_id = cpu_to_le32(deviceID);
4320 psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
4321}
4322
4323/**
4324 * pm8001_chip_smp_req - send a SMP task to FW
4325 * @pm8001_ha: our hba card information.
4326 * @ccb: the ccb information this request used.
4327 */
4328static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
4329 struct pm8001_ccb_info *ccb)
4330{
4331 int elem, rc;
4332 struct sas_task *task = ccb->task;
4333 struct domain_device *dev = task->dev;
4334 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4335 struct scatterlist *sg_req, *sg_resp;
4336 u32 req_len, resp_len;
4337 struct smp_req smp_cmd;
4338 u32 opc;
4339 struct inbound_queue_table *circularQ;
4340
4341 memset(&smp_cmd, 0, sizeof(smp_cmd));
4342 /*
4343 * DMA-map SMP request, response buffers
4344 */
4345 sg_req = &task->smp_task.smp_req;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004346 elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004347 if (!elem)
4348 return -ENOMEM;
4349 req_len = sg_dma_len(sg_req);
4350
4351 sg_resp = &task->smp_task.smp_resp;
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004352 elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004353 if (!elem) {
4354 rc = -ENOMEM;
4355 goto err_out;
4356 }
4357 resp_len = sg_dma_len(sg_resp);
4358 /* must be in dwords */
4359 if ((req_len & 0x3) || (resp_len & 0x3)) {
4360 rc = -EINVAL;
4361 goto err_out_2;
4362 }
4363
4364 opc = OPC_INB_SMP_REQUEST;
4365 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4366 smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
4367 smp_cmd.long_smp_req.long_req_addr =
4368 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
4369 smp_cmd.long_smp_req.long_req_size =
4370 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
4371 smp_cmd.long_smp_req.long_resp_addr =
4372 cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp));
4373 smp_cmd.long_smp_req.long_resp_size =
4374 cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
4375 build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304376 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
peter chang91a43fa2019-11-14 15:39:05 +05304377 &smp_cmd, sizeof(smp_cmd), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304378 if (rc)
4379 goto err_out_2;
4380
jack wangdbf9bfe2009-10-14 16:19:21 +08004381 return 0;
4382
4383err_out_2:
4384 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004385 DMA_FROM_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004386err_out:
4387 dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004388 DMA_TO_DEVICE);
jack wangdbf9bfe2009-10-14 16:19:21 +08004389 return rc;
4390}
4391
4392/**
4393 * pm8001_chip_ssp_io_req - send a SSP task to FW
4394 * @pm8001_ha: our hba card information.
4395 * @ccb: the ccb information this request used.
4396 */
4397static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
4398 struct pm8001_ccb_info *ccb)
4399{
4400 struct sas_task *task = ccb->task;
4401 struct domain_device *dev = task->dev;
4402 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4403 struct ssp_ini_io_start_req ssp_cmd;
4404 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004405 int ret;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304406 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004407 struct inbound_queue_table *circularQ;
4408 u32 opc = OPC_INB_SSPINIIOSTART;
4409 memset(&ssp_cmd, 0, sizeof(ssp_cmd));
4410 memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
jack wangafc5ca92009-12-07 17:22:47 +08004411 ssp_cmd.dir_m_tlr =
4412 cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for
jack wangdbf9bfe2009-10-14 16:19:21 +08004413 SAS 1.1 compatible TLR*/
4414 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4415 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4416 ssp_cmd.tag = cpu_to_le32(tag);
4417 if (task->ssp_task.enable_first_burst)
4418 ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
4419 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
4420 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
James Bottomleye73823f2013-05-07 15:38:18 -07004421 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
4422 task->ssp_task.cmd->cmd_len);
jack wangdbf9bfe2009-10-14 16:19:21 +08004423 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4424
4425 /* fill in PRD (scatter/gather) table, if any */
4426 if (task->num_scatter > 1) {
4427 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304428 phys_addr = ccb->ccb_dma_handle;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304429 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr));
4430 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004431 ssp_cmd.esgl = cpu_to_le32(1<<31);
4432 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304433 u64 dma_addr = sg_dma_address(task->scatter);
4434 ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
4435 ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr));
jack wangdbf9bfe2009-10-14 16:19:21 +08004436 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4437 ssp_cmd.esgl = 0;
4438 } else if (task->num_scatter == 0) {
4439 ssp_cmd.addr_low = 0;
4440 ssp_cmd.addr_high = 0;
4441 ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
4442 ssp_cmd.esgl = 0;
4443 }
peter chang91a43fa2019-11-14 15:39:05 +05304444 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd,
4445 sizeof(ssp_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004446 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004447}
4448
4449static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
4450 struct pm8001_ccb_info *ccb)
4451{
4452 struct sas_task *task = ccb->task;
4453 struct domain_device *dev = task->dev;
4454 struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
4455 u32 tag = ccb->ccb_tag;
jack_wang72d0baa2009-11-05 22:33:35 +08004456 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004457 struct sata_start_req sata_cmd;
4458 u32 hdr_tag, ncg_tag = 0;
Santosh Nayak8270ee22012-02-26 20:14:46 +05304459 u64 phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08004460 u32 ATAP = 0x0;
4461 u32 dir;
4462 struct inbound_queue_table *circularQ;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304463 unsigned long flags;
jack wangdbf9bfe2009-10-14 16:19:21 +08004464 u32 opc = OPC_INB_SATA_HOST_OPSTART;
4465 memset(&sata_cmd, 0, sizeof(sata_cmd));
4466 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +02004467 if (task->data_dir == DMA_NONE) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004468 ATAP = 0x04; /* no data*/
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004469 PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004470 } else if (likely(!task->ata_task.device_control_reg_update)) {
4471 if (task->ata_task.dma_xfer) {
4472 ATAP = 0x06; /* DMA */
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004473 PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004474 } else {
4475 ATAP = 0x05; /* PIO*/
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004476 PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004477 }
4478 if (task->ata_task.use_ncq &&
Hannes Reinecke1cbd7722014-11-05 13:08:20 +01004479 dev->sata_dev.class != ATA_DEV_ATAPI) {
jack wangdbf9bfe2009-10-14 16:19:21 +08004480 ATAP = 0x07; /* FPDMA */
Mark Salyzyn6fbc7692011-09-26 07:57:36 -07004481 PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n"));
jack wangdbf9bfe2009-10-14 16:19:21 +08004482 }
4483 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304484 if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
4485 task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
jack wangafc5ca92009-12-07 17:22:47 +08004486 ncg_tag = hdr_tag;
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304487 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004488 dir = data_dir_flags[task->data_dir] << 8;
4489 sata_cmd.tag = cpu_to_le32(tag);
4490 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
4491 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
4492 sata_cmd.ncqtag_atap_dir_m =
4493 cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir);
4494 sata_cmd.sata_fis = task->ata_task.fis;
4495 if (likely(!task->ata_task.device_control_reg_update))
4496 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
4497 sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
4498 /* fill in PRD (scatter/gather) table, if any */
4499 if (task->num_scatter > 1) {
4500 pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
Viswas G5a141312020-10-05 20:20:10 +05304501 phys_addr = ccb->ccb_dma_handle;
jack wangdbf9bfe2009-10-14 16:19:21 +08004502 sata_cmd.addr_low = lower_32_bits(phys_addr);
4503 sata_cmd.addr_high = upper_32_bits(phys_addr);
4504 sata_cmd.esgl = cpu_to_le32(1 << 31);
4505 } else if (task->num_scatter == 1) {
Santosh Nayak8270ee22012-02-26 20:14:46 +05304506 u64 dma_addr = sg_dma_address(task->scatter);
jack wangdbf9bfe2009-10-14 16:19:21 +08004507 sata_cmd.addr_low = lower_32_bits(dma_addr);
4508 sata_cmd.addr_high = upper_32_bits(dma_addr);
4509 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4510 sata_cmd.esgl = 0;
4511 } else if (task->num_scatter == 0) {
4512 sata_cmd.addr_low = 0;
4513 sata_cmd.addr_high = 0;
4514 sata_cmd.len = cpu_to_le32(task->total_xfer_len);
4515 sata_cmd.esgl = 0;
4516 }
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304517
4518 /* Check for read log for failed drive and return */
4519 if (sata_cmd.sata_fis.command == 0x2f) {
Rickard Strandqvistd9816442014-07-09 17:19:38 +05304520 if (((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304521 (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
4522 (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
4523 struct task_status_struct *ts;
4524
4525 pm8001_ha_dev->id &= 0xDFFFFFFF;
4526 ts = &task->task_status;
4527
4528 spin_lock_irqsave(&task->task_state_lock, flags);
4529 ts->resp = SAS_TASK_COMPLETE;
4530 ts->stat = SAM_STAT_GOOD;
4531 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
4532 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
4533 task->task_state_flags |= SAS_TASK_STATE_DONE;
4534 if (unlikely((task->task_state_flags &
4535 SAS_TASK_STATE_ABORTED))) {
4536 spin_unlock_irqrestore(&task->task_state_lock,
4537 flags);
4538 PM8001_FAIL_DBG(pm8001_ha,
4539 pm8001_printk("task 0x%p resp 0x%x "
4540 " stat 0x%x but aborted by upper layer "
4541 "\n", task, ts->resp, ts->stat));
4542 pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304543 } else {
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304544 spin_unlock_irqrestore(&task->task_state_lock,
4545 flags);
Suresh Thiagarajan2b01d812014-01-16 15:26:21 +05304546 pm8001_ccb_task_free_done(pm8001_ha, task,
4547 ccb, tag);
Sakthivel Kc6b9ef52013-03-19 18:08:08 +05304548 return 0;
4549 }
4550 }
4551 }
4552
peter chang91a43fa2019-11-14 15:39:05 +05304553 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd,
4554 sizeof(sata_cmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004555 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004556}
4557
4558/**
4559 * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND
4560 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004561 * @phy_id: the phy id which we wanted to start up.
4562 */
4563static int
4564pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
4565{
4566 struct phy_start_req payload;
4567 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004568 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004569 u32 tag = 0x01;
4570 u32 opcode = OPC_INB_PHYSTART;
4571 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4572 memset(&payload, 0, sizeof(payload));
4573 payload.tag = cpu_to_le32(tag);
4574 /*
4575 ** [0:7] PHY Identifier
4576 ** [8:11] link rate 1.5G, 3G, 6G
4577 ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both
4578 ** [14] 0b disable spin up hold; 1b enable spin up hold
4579 */
4580 payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
4581 LINKMODE_AUTO | LINKRATE_15 |
4582 LINKRATE_30 | LINKRATE_60 | phy_id);
James Bottomleyaa9f8322013-05-07 14:44:06 -07004583 payload.sas_identify.dev_type = SAS_END_DEVICE;
jack wangdbf9bfe2009-10-14 16:19:21 +08004584 payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
4585 memcpy(payload.sas_identify.sas_addr,
4586 pm8001_ha->sas_addr, SAS_ADDR_SIZE);
4587 payload.sas_identify.phy_id = phy_id;
peter chang91a43fa2019-11-14 15:39:05 +05304588 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4589 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004590 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004591}
4592
4593/**
4594 * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
4595 * @pm8001_ha: our hba card information.
jack wangdbf9bfe2009-10-14 16:19:21 +08004596 * @phy_id: the phy id which we wanted to start up.
4597 */
Baoyou Xie7efa59e2016-09-23 21:54:22 +08004598static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
4599 u8 phy_id)
jack wangdbf9bfe2009-10-14 16:19:21 +08004600{
4601 struct phy_stop_req payload;
4602 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004603 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004604 u32 tag = 0x01;
4605 u32 opcode = OPC_INB_PHYSTOP;
4606 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4607 memset(&payload, 0, sizeof(payload));
4608 payload.tag = cpu_to_le32(tag);
4609 payload.phy_id = cpu_to_le32(phy_id);
peter chang91a43fa2019-11-14 15:39:05 +05304610 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload,
4611 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004612 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004613}
4614
Lee Jones083645b2020-07-21 17:41:24 +01004615/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304616 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004617 */
4618static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
4619 struct pm8001_device *pm8001_dev, u32 flag)
4620{
4621 struct reg_dev_req payload;
4622 u32 opc;
4623 u32 stp_sspsmp_sata = 0x4;
4624 struct inbound_queue_table *circularQ;
4625 u32 linkrate, phy_id;
jack_wang72d0baa2009-11-05 22:33:35 +08004626 int rc, tag = 0xdeadbeef;
jack wangdbf9bfe2009-10-14 16:19:21 +08004627 struct pm8001_ccb_info *ccb;
4628 u8 retryFlag = 0x1;
4629 u16 firstBurstSize = 0;
4630 u16 ITNT = 2000;
4631 struct domain_device *dev = pm8001_dev->sas_device;
4632 struct domain_device *parent_dev = dev->parent;
4633 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4634
4635 memset(&payload, 0, sizeof(payload));
4636 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4637 if (rc)
4638 return rc;
4639 ccb = &pm8001_ha->ccb_info[tag];
4640 ccb->device = pm8001_dev;
4641 ccb->ccb_tag = tag;
4642 payload.tag = cpu_to_le32(tag);
4643 if (flag == 1)
4644 stp_sspsmp_sata = 0x02; /*direct attached sata */
4645 else {
James Bottomleyaa9f8322013-05-07 14:44:06 -07004646 if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004647 stp_sspsmp_sata = 0x00; /* stp*/
James Bottomleyaa9f8322013-05-07 14:44:06 -07004648 else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
4649 pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
4650 pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004651 stp_sspsmp_sata = 0x01; /*ssp or smp*/
4652 }
John Garry924a3542019-06-10 20:41:41 +08004653 if (parent_dev && dev_is_expander(parent_dev->dev_type))
jack wangdbf9bfe2009-10-14 16:19:21 +08004654 phy_id = parent_dev->ex_dev.ex_phy->phy_id;
4655 else
4656 phy_id = pm8001_dev->attached_phy;
4657 opc = OPC_INB_REG_DEV;
4658 linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
4659 pm8001_dev->sas_device->linkrate : dev->port->linkrate;
4660 payload.phyid_portid =
4661 cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) |
4662 ((phy_id & 0x0F) << 4));
4663 payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) |
4664 ((linkrate & 0x0F) * 0x1000000) |
4665 ((stp_sspsmp_sata & 0x03) * 0x10000000));
4666 payload.firstburstsize_ITNexustimeout =
4667 cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
jack wangafc5ca92009-12-07 17:22:47 +08004668 memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
jack wangdbf9bfe2009-10-14 16:19:21 +08004669 SAS_ADDR_SIZE);
peter chang91a43fa2019-11-14 15:39:05 +05304670 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4671 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004672 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004673}
4674
Lee Jones083645b2020-07-21 17:41:24 +01004675/*
Sakthivel Kf74cf272013-02-27 20:27:43 +05304676 * see comments on pm8001_mpi_reg_resp.
jack wangdbf9bfe2009-10-14 16:19:21 +08004677 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304678int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004679 u32 device_id)
4680{
4681 struct dereg_dev_req payload;
4682 u32 opc = OPC_INB_DEREG_DEV_HANDLE;
jack_wang72d0baa2009-11-05 22:33:35 +08004683 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004684 struct inbound_queue_table *circularQ;
4685
4686 circularQ = &pm8001_ha->inbnd_q_tbl[0];
jack_wang72d0baa2009-11-05 22:33:35 +08004687 memset(&payload, 0, sizeof(payload));
Santosh Nayak8270ee22012-02-26 20:14:46 +05304688 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004689 payload.device_id = cpu_to_le32(device_id);
4690 PM8001_MSG_DBG(pm8001_ha,
4691 pm8001_printk("unregister device device_id = %d\n", device_id));
peter chang91a43fa2019-11-14 15:39:05 +05304692 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4693 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004694 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004695}
4696
4697/**
4698 * pm8001_chip_phy_ctl_req - support the local phy operation
4699 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004700 * @phyId: the phy id which we wanted to operate
4701 * @phy_op: the phy operation to request
jack wangdbf9bfe2009-10-14 16:19:21 +08004702 */
4703static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
4704 u32 phyId, u32 phy_op)
4705{
4706 struct local_phy_ctl_req payload;
4707 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004708 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004709 u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
jack wang83e73322009-12-07 17:23:11 +08004710 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08004711 circularQ = &pm8001_ha->inbnd_q_tbl[0];
Santosh Nayak8270ee22012-02-26 20:14:46 +05304712 payload.tag = cpu_to_le32(1);
jack wangdbf9bfe2009-10-14 16:19:21 +08004713 payload.phyop_phyid =
4714 cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
peter chang91a43fa2019-11-14 15:39:05 +05304715 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
4716 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004717 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004718}
4719
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00004720static u32 pm8001_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +08004721{
jack wangdbf9bfe2009-10-14 16:19:21 +08004722#ifdef PM8001_USE_MSIX
4723 return 1;
Colin Ian King292c04c2019-03-28 23:43:28 +00004724#else
4725 u32 value;
4726
jack wangdbf9bfe2009-10-14 16:19:21 +08004727 value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
4728 if (value)
4729 return 1;
4730 return 0;
Colin Ian King292c04c2019-03-28 23:43:28 +00004731#endif
jack wangdbf9bfe2009-10-14 16:19:21 +08004732}
4733
4734/**
4735 * pm8001_chip_isr - PM8001 isr handler.
4736 * @pm8001_ha: our hba card information.
Lee Jones685f9472020-07-21 17:41:26 +01004737 * @vec: IRQ number
jack wangdbf9bfe2009-10-14 16:19:21 +08004738 */
jack_wang72d0baa2009-11-05 22:33:35 +08004739static irqreturn_t
Sakthivel Kf74cf272013-02-27 20:27:43 +05304740pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
jack wangdbf9bfe2009-10-14 16:19:21 +08004741{
Sakthivel Kf74cf272013-02-27 20:27:43 +05304742 pm8001_chip_interrupt_disable(pm8001_ha, vec);
peter chang73706722019-11-14 15:39:02 +05304743 PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk(
4744 "irq vec %d, ODMR:0x%x\n",
4745 vec, pm8001_cr32(pm8001_ha, 0, 0x30)));
Sakthivel Kf74cf272013-02-27 20:27:43 +05304746 process_oq(pm8001_ha, vec);
4747 pm8001_chip_interrupt_enable(pm8001_ha, vec);
jack_wang72d0baa2009-11-05 22:33:35 +08004748 return IRQ_HANDLED;
jack wangdbf9bfe2009-10-14 16:19:21 +08004749}
4750
4751static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
4752 u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag)
4753{
4754 struct task_abort_req task_abort;
4755 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08004756 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004757 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4758 memset(&task_abort, 0, sizeof(task_abort));
4759 if (ABORT_SINGLE == (flag & ABORT_MASK)) {
4760 task_abort.abort_all = 0;
4761 task_abort.device_id = cpu_to_le32(dev_id);
4762 task_abort.tag_to_abort = cpu_to_le32(task_tag);
4763 task_abort.tag = cpu_to_le32(cmd_tag);
4764 } else if (ABORT_ALL == (flag & ABORT_MASK)) {
4765 task_abort.abort_all = cpu_to_le32(1);
4766 task_abort.device_id = cpu_to_le32(dev_id);
4767 task_abort.tag = cpu_to_le32(cmd_tag);
4768 }
peter chang91a43fa2019-11-14 15:39:05 +05304769 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort,
4770 sizeof(task_abort), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004771 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004772}
4773
Lee Jones083645b2020-07-21 17:41:24 +01004774/*
jack wangdbf9bfe2009-10-14 16:19:21 +08004775 * pm8001_chip_abort_task - SAS abort task when error or exception happened.
jack wangdbf9bfe2009-10-14 16:19:21 +08004776 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304777int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004778 struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag)
4779{
4780 u32 opc, device_id;
4781 int rc = TMF_RESP_FUNC_FAILED;
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05304782 PM8001_EH_DBG(pm8001_ha,
4783 pm8001_printk("cmd_tag = %x, abort task tag = 0x%x",
4784 cmd_tag, task_tag));
James Bottomleyaa9f8322013-05-07 14:44:06 -07004785 if (pm8001_dev->dev_type == SAS_END_DEVICE)
jack wangdbf9bfe2009-10-14 16:19:21 +08004786 opc = OPC_INB_SSP_ABORT;
James Bottomleyaa9f8322013-05-07 14:44:06 -07004787 else if (pm8001_dev->dev_type == SAS_SATA_DEV)
jack wangdbf9bfe2009-10-14 16:19:21 +08004788 opc = OPC_INB_SATA_ABORT;
4789 else
4790 opc = OPC_INB_SMP_ABORT;/* SMP */
4791 device_id = pm8001_dev->device_id;
4792 rc = send_task_abort(pm8001_ha, opc, device_id, flag,
4793 task_tag, cmd_tag);
4794 if (rc != TMF_RESP_FUNC_COMPLETE)
jack_wang72d0baa2009-11-05 22:33:35 +08004795 PM8001_EH_DBG(pm8001_ha, pm8001_printk("rc= %d\n", rc));
jack wangdbf9bfe2009-10-14 16:19:21 +08004796 return rc;
4797}
4798
4799/**
Uwe Kleine-König65155b32010-06-11 12:17:01 +02004800 * pm8001_chip_ssp_tm_req - built the task management command.
jack wangdbf9bfe2009-10-14 16:19:21 +08004801 * @pm8001_ha: our hba card information.
4802 * @ccb: the ccb information.
4803 * @tmf: task management function.
4804 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05304805int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004806 struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
4807{
4808 struct sas_task *task = ccb->task;
4809 struct domain_device *dev = task->dev;
4810 struct pm8001_device *pm8001_dev = dev->lldd_dev;
4811 u32 opc = OPC_INB_SSPINITMSTART;
4812 struct inbound_queue_table *circularQ;
4813 struct ssp_ini_tm_start_req sspTMCmd;
jack_wang72d0baa2009-11-05 22:33:35 +08004814 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004815
4816 memset(&sspTMCmd, 0, sizeof(sspTMCmd));
4817 sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id);
4818 sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed);
4819 sspTMCmd.tmf = cpu_to_le32(tmf->tmf);
jack wangdbf9bfe2009-10-14 16:19:21 +08004820 memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8);
4821 sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag);
Anand Kumar Santhaname912457b2013-09-17 16:58:10 +05304822 if (pm8001_ha->chip_id != chip_8001)
4823 sspTMCmd.ds_ads_m = 0x08;
jack wangdbf9bfe2009-10-14 16:19:21 +08004824 circularQ = &pm8001_ha->inbnd_q_tbl[0];
peter chang91a43fa2019-11-14 15:39:05 +05304825 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd,
4826 sizeof(sspTMCmd), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08004827 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08004828}
4829
Sakthivel Kf74cf272013-02-27 20:27:43 +05304830int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004831 void *payload)
4832{
4833 u32 opc = OPC_INB_GET_NVMD_DATA;
4834 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004835 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004836 u32 tag;
4837 struct pm8001_ccb_info *ccb;
4838 struct inbound_queue_table *circularQ;
4839 struct get_nvm_data_req nvmd_req;
4840 struct fw_control_ex *fw_control_context;
4841 struct pm8001_ioctl_payload *ioctl_payload = payload;
4842
4843 nvmd_type = ioctl_payload->minor_function;
4844 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004845 if (!fw_control_context)
4846 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05304847 fw_control_context->usrAddr = (u8 *)ioctl_payload->func_specific;
Viswas G9b889842020-03-16 13:19:06 +05304848 fw_control_context->len = ioctl_payload->rd_length;
jack wangdbf9bfe2009-10-14 16:19:21 +08004849 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4850 memset(&nvmd_req, 0, sizeof(nvmd_req));
4851 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004852 if (rc) {
4853 kfree(fw_control_context);
jack wangdbf9bfe2009-10-14 16:19:21 +08004854 return rc;
Julia Lawall823d2192010-08-01 19:23:35 +02004855 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004856 ccb = &pm8001_ha->ccb_info[tag];
4857 ccb->ccb_tag = tag;
4858 ccb->fw_control_context = fw_control_context;
4859 nvmd_req.tag = cpu_to_le32(tag);
4860
4861 switch (nvmd_type) {
4862 case TWI_DEVICE: {
4863 u32 twi_addr, twi_page_size;
4864 twi_addr = 0xa8;
4865 twi_page_size = 2;
4866
4867 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4868 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304869 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004870 nvmd_req.resp_addr_hi =
4871 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4872 nvmd_req.resp_addr_lo =
4873 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4874 break;
4875 }
4876 case C_SEEPROM: {
4877 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304878 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004879 nvmd_req.resp_addr_hi =
4880 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4881 nvmd_req.resp_addr_lo =
4882 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4883 break;
4884 }
4885 case VPD_FLASH: {
4886 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304887 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004888 nvmd_req.resp_addr_hi =
4889 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4890 nvmd_req.resp_addr_lo =
4891 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4892 break;
4893 }
4894 case EXPAN_ROM: {
4895 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304896 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004897 nvmd_req.resp_addr_hi =
4898 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4899 nvmd_req.resp_addr_lo =
4900 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4901 break;
4902 }
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304903 case IOP_RDUMP: {
4904 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | IOP_RDUMP);
Viswas G9b889842020-03-16 13:19:06 +05304905 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05304906 nvmd_req.vpd_offset = cpu_to_le32(ioctl_payload->offset);
4907 nvmd_req.resp_addr_hi =
4908 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4909 nvmd_req.resp_addr_lo =
4910 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4911 break;
4912 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004913 default:
4914 break;
4915 }
peter chang91a43fa2019-11-14 15:39:05 +05304916 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
4917 sizeof(nvmd_req), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05304918 if (rc) {
4919 kfree(fw_control_context);
4920 pm8001_tag_free(pm8001_ha, tag);
4921 }
jack_wang72d0baa2009-11-05 22:33:35 +08004922 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004923}
4924
Sakthivel Kf74cf272013-02-27 20:27:43 +05304925int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
jack wangdbf9bfe2009-10-14 16:19:21 +08004926 void *payload)
4927{
4928 u32 opc = OPC_INB_SET_NVMD_DATA;
4929 u32 nvmd_type;
jack_wang72d0baa2009-11-05 22:33:35 +08004930 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08004931 u32 tag;
4932 struct pm8001_ccb_info *ccb;
4933 struct inbound_queue_table *circularQ;
4934 struct set_nvm_data_req nvmd_req;
4935 struct fw_control_ex *fw_control_context;
4936 struct pm8001_ioctl_payload *ioctl_payload = payload;
4937
4938 nvmd_type = ioctl_payload->minor_function;
4939 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02004940 if (!fw_control_context)
4941 return -ENOMEM;
jack wangdbf9bfe2009-10-14 16:19:21 +08004942 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4943 memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr,
Sakthivel K1c75a672013-03-19 18:06:40 +05304944 &ioctl_payload->func_specific,
Viswas G9b889842020-03-16 13:19:06 +05304945 ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004946 memset(&nvmd_req, 0, sizeof(nvmd_req));
4947 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02004948 if (rc) {
4949 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05304950 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02004951 }
jack wangdbf9bfe2009-10-14 16:19:21 +08004952 ccb = &pm8001_ha->ccb_info[tag];
4953 ccb->fw_control_context = fw_control_context;
4954 ccb->ccb_tag = tag;
4955 nvmd_req.tag = cpu_to_le32(tag);
4956 switch (nvmd_type) {
4957 case TWI_DEVICE: {
4958 u32 twi_addr, twi_page_size;
4959 twi_addr = 0xa8;
4960 twi_page_size = 2;
4961 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4962 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
4963 twi_page_size << 8 | TWI_DEVICE);
Viswas G9b889842020-03-16 13:19:06 +05304964 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004965 nvmd_req.resp_addr_hi =
4966 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4967 nvmd_req.resp_addr_lo =
4968 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4969 break;
4970 }
4971 case C_SEEPROM:
4972 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
Viswas G9b889842020-03-16 13:19:06 +05304973 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004974 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4975 nvmd_req.resp_addr_hi =
4976 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4977 nvmd_req.resp_addr_lo =
4978 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4979 break;
4980 case VPD_FLASH:
4981 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
Viswas G9b889842020-03-16 13:19:06 +05304982 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004983 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4984 nvmd_req.resp_addr_hi =
4985 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4986 nvmd_req.resp_addr_lo =
4987 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4988 break;
4989 case EXPAN_ROM:
4990 nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
Viswas G9b889842020-03-16 13:19:06 +05304991 nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length);
jack wangdbf9bfe2009-10-14 16:19:21 +08004992 nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
4993 nvmd_req.resp_addr_hi =
4994 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
4995 nvmd_req.resp_addr_lo =
4996 cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
4997 break;
4998 default:
4999 break;
5000 }
peter chang91a43fa2019-11-14 15:39:05 +05305001 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req,
5002 sizeof(nvmd_req), 0);
Tomas Henzl9422e862014-07-07 17:20:00 +02005003 if (rc) {
5004 kfree(fw_control_context);
5005 pm8001_tag_free(pm8001_ha, tag);
5006 }
jack_wang72d0baa2009-11-05 22:33:35 +08005007 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005008}
5009
5010/**
5011 * pm8001_chip_fw_flash_update_build - support the firmware update operation
5012 * @pm8001_ha: our hba card information.
5013 * @fw_flash_updata_info: firmware flash update param
Lee Jones083645b2020-07-21 17:41:24 +01005014 * @tag: Tag to apply to the payload
jack wangdbf9bfe2009-10-14 16:19:21 +08005015 */
Sakthivel Kf74cf272013-02-27 20:27:43 +05305016int
jack wangdbf9bfe2009-10-14 16:19:21 +08005017pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
5018 void *fw_flash_updata_info, u32 tag)
5019{
5020 struct fw_flash_Update_req payload;
5021 struct fw_flash_updata_info *info;
5022 struct inbound_queue_table *circularQ;
jack_wang72d0baa2009-11-05 22:33:35 +08005023 int ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08005024 u32 opc = OPC_INB_FW_FLASH_UPDATE;
5025
jack_wang72d0baa2009-11-05 22:33:35 +08005026 memset(&payload, 0, sizeof(struct fw_flash_Update_req));
jack wangdbf9bfe2009-10-14 16:19:21 +08005027 circularQ = &pm8001_ha->inbnd_q_tbl[0];
5028 info = fw_flash_updata_info;
5029 payload.tag = cpu_to_le32(tag);
5030 payload.cur_image_len = cpu_to_le32(info->cur_image_len);
5031 payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
5032 payload.total_image_len = cpu_to_le32(info->total_image_len);
5033 payload.len = info->sgl.im_len.len ;
Santosh Nayak8270ee22012-02-26 20:14:46 +05305034 payload.sgl_addr_lo =
5035 cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr)));
5036 payload.sgl_addr_hi =
5037 cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr)));
peter chang91a43fa2019-11-14 15:39:05 +05305038 ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
5039 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08005040 return ret;
jack wangdbf9bfe2009-10-14 16:19:21 +08005041}
5042
Sakthivel Kf74cf272013-02-27 20:27:43 +05305043int
jack wangdbf9bfe2009-10-14 16:19:21 +08005044pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
5045 void *payload)
5046{
5047 struct fw_flash_updata_info flash_update_info;
5048 struct fw_control_info *fw_control;
5049 struct fw_control_ex *fw_control_context;
jack_wang72d0baa2009-11-05 22:33:35 +08005050 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005051 u32 tag;
5052 struct pm8001_ccb_info *ccb;
Sakthivel K1c75a672013-03-19 18:06:40 +05305053 void *buffer = pm8001_ha->memoryMap.region[FW_FLASH].virt_ptr;
5054 dma_addr_t phys_addr = pm8001_ha->memoryMap.region[FW_FLASH].phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08005055 struct pm8001_ioctl_payload *ioctl_payload = payload;
5056
5057 fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
Dan Carpenter0caeb912010-08-17 13:54:57 +02005058 if (!fw_control_context)
5059 return -ENOMEM;
Sakthivel K1c75a672013-03-19 18:06:40 +05305060 fw_control = (struct fw_control_info *)&ioctl_payload->func_specific;
peter chang73706722019-11-14 15:39:02 +05305061 PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk(
5062 "dma fw_control context input length :%x\n", fw_control->len));
jack_wang72d0baa2009-11-05 22:33:35 +08005063 memcpy(buffer, fw_control->buffer, fw_control->len);
jack wangdbf9bfe2009-10-14 16:19:21 +08005064 flash_update_info.sgl.addr = cpu_to_le64(phys_addr);
5065 flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len);
5066 flash_update_info.sgl.im_len.e = 0;
5067 flash_update_info.cur_image_offset = fw_control->offset;
5068 flash_update_info.cur_image_len = fw_control->len;
5069 flash_update_info.total_image_len = fw_control->size;
5070 fw_control_context->fw_control = fw_control;
5071 fw_control_context->virtAddr = buffer;
Sakthivel K1c75a672013-03-19 18:06:40 +05305072 fw_control_context->phys_addr = phys_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +08005073 fw_control_context->len = fw_control->len;
5074 rc = pm8001_tag_alloc(pm8001_ha, &tag);
Julia Lawall823d2192010-08-01 19:23:35 +02005075 if (rc) {
5076 kfree(fw_control_context);
Tomas Henzl6f8f31c2014-07-30 18:42:22 +05305077 return -EBUSY;
Julia Lawall823d2192010-08-01 19:23:35 +02005078 }
jack wangdbf9bfe2009-10-14 16:19:21 +08005079 ccb = &pm8001_ha->ccb_info[tag];
5080 ccb->fw_control_context = fw_control_context;
5081 ccb->ccb_tag = tag;
jack_wang72d0baa2009-11-05 22:33:35 +08005082 rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
5083 tag);
5084 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005085}
5086
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05305087ssize_t
5088pm8001_get_gsm_dump(struct device *cdev, u32 length, char *buf)
5089{
5090 u32 value, rem, offset = 0, bar = 0;
5091 u32 index, work_offset, dw_length;
5092 u32 shift_value, gsm_base, gsm_dump_offset;
5093 char *direct_data;
5094 struct Scsi_Host *shost = class_to_shost(cdev);
5095 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
5096 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
5097
5098 direct_data = buf;
5099 gsm_dump_offset = pm8001_ha->fatal_forensic_shift_offset;
5100
5101 /* check max is 1 Mbytes */
5102 if ((length > 0x100000) || (gsm_dump_offset & 3) ||
5103 ((gsm_dump_offset + length) > 0x1000000))
Viswas Gcf370062013-12-10 10:31:38 +05305104 return -EINVAL;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05305105
5106 if (pm8001_ha->chip_id == chip_8001)
5107 bar = 2;
5108 else
5109 bar = 1;
5110
5111 work_offset = gsm_dump_offset & 0xFFFF0000;
5112 offset = gsm_dump_offset & 0x0000FFFF;
5113 gsm_dump_offset = work_offset;
5114 /* adjust length to dword boundary */
5115 rem = length & 3;
5116 dw_length = length >> 2;
5117
5118 for (index = 0; index < dw_length; index++) {
5119 if ((work_offset + offset) & 0xFFFF0000) {
5120 if (pm8001_ha->chip_id == chip_8001)
5121 shift_value = ((gsm_dump_offset + offset) &
5122 SHIFT_REG_64K_MASK);
5123 else
5124 shift_value = (((gsm_dump_offset + offset) &
5125 SHIFT_REG_64K_MASK) >>
5126 SHIFT_REG_BIT_SHIFT);
5127
5128 if (pm8001_ha->chip_id == chip_8001) {
5129 gsm_base = GSM_BASE;
5130 if (-1 == pm8001_bar4_shift(pm8001_ha,
5131 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05305132 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05305133 } else {
5134 gsm_base = 0;
5135 if (-1 == pm80xx_bar4_shift(pm8001_ha,
5136 (gsm_base + shift_value)))
Viswas Gcf370062013-12-10 10:31:38 +05305137 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05305138 }
5139 gsm_dump_offset = (gsm_dump_offset + offset) &
5140 0xFFFF0000;
5141 work_offset = 0;
5142 offset = offset & 0x0000FFFF;
5143 }
5144 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
5145 0x0000FFFF);
5146 direct_data += sprintf(direct_data, "%08x ", value);
5147 offset += 4;
5148 }
5149 if (rem != 0) {
5150 value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) &
5151 0x0000FFFF);
5152 /* xfr for non_dw */
5153 direct_data += sprintf(direct_data, "%08x ", value);
5154 }
5155 /* Shift back to BAR4 original address */
Viswas G859b5d12013-12-10 10:31:28 +05305156 if (-1 == pm8001_bar4_shift(pm8001_ha, 0))
Viswas Gcf370062013-12-10 10:31:38 +05305157 return -EIO;
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +05305158 pm8001_ha->fatal_forensic_shift_offset += 1024;
5159
5160 if (pm8001_ha->fatal_forensic_shift_offset >= 0x100000)
5161 pm8001_ha->fatal_forensic_shift_offset = 0;
5162 return direct_data - buf;
5163}
5164
Sakthivel Kf74cf272013-02-27 20:27:43 +05305165int
jack wangdbf9bfe2009-10-14 16:19:21 +08005166pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
5167 struct pm8001_device *pm8001_dev, u32 state)
5168{
5169 struct set_dev_state_req payload;
5170 struct inbound_queue_table *circularQ;
5171 struct pm8001_ccb_info *ccb;
jack_wang72d0baa2009-11-05 22:33:35 +08005172 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005173 u32 tag;
5174 u32 opc = OPC_INB_SET_DEVICE_STATE;
jack_wang72d0baa2009-11-05 22:33:35 +08005175 memset(&payload, 0, sizeof(payload));
jack wangdbf9bfe2009-10-14 16:19:21 +08005176 rc = pm8001_tag_alloc(pm8001_ha, &tag);
5177 if (rc)
5178 return -1;
5179 ccb = &pm8001_ha->ccb_info[tag];
5180 ccb->ccb_tag = tag;
5181 ccb->device = pm8001_dev;
5182 circularQ = &pm8001_ha->inbnd_q_tbl[0];
5183 payload.tag = cpu_to_le32(tag);
5184 payload.device_id = cpu_to_le32(pm8001_dev->device_id);
5185 payload.nds = cpu_to_le32(state);
peter chang91a43fa2019-11-14 15:39:05 +05305186 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
5187 sizeof(payload), 0);
jack_wang72d0baa2009-11-05 22:33:35 +08005188 return rc;
5189
jack_wangd0b68042009-11-05 22:32:31 +08005190}
5191
5192static int
5193pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
5194{
5195 struct sas_re_initialization_req payload;
5196 struct inbound_queue_table *circularQ;
5197 struct pm8001_ccb_info *ccb;
5198 int rc;
5199 u32 tag;
5200 u32 opc = OPC_INB_SAS_RE_INITIALIZE;
5201 memset(&payload, 0, sizeof(payload));
5202 rc = pm8001_tag_alloc(pm8001_ha, &tag);
5203 if (rc)
Tomas Henzl5533abc2014-07-09 17:20:49 +05305204 return -ENOMEM;
jack_wangd0b68042009-11-05 22:32:31 +08005205 ccb = &pm8001_ha->ccb_info[tag];
5206 ccb->ccb_tag = tag;
5207 circularQ = &pm8001_ha->inbnd_q_tbl[0];
5208 payload.tag = cpu_to_le32(tag);
5209 payload.SSAHOLT = cpu_to_le32(0xd << 25);
5210 payload.sata_hol_tmo = cpu_to_le32(80);
5211 payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff);
peter chang91a43fa2019-11-14 15:39:05 +05305212 rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload,
5213 sizeof(payload), 0);
Tomas Henzl5533abc2014-07-09 17:20:49 +05305214 if (rc)
5215 pm8001_tag_free(pm8001_ha, tag);
jack_wangd0b68042009-11-05 22:32:31 +08005216 return rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08005217
5218}
5219
5220const struct pm8001_dispatch pm8001_8001_dispatch = {
5221 .name = "pmc8001",
5222 .chip_init = pm8001_chip_init,
5223 .chip_soft_rst = pm8001_chip_soft_rst,
5224 .chip_rst = pm8001_hw_chip_rst,
5225 .chip_iounmap = pm8001_chip_iounmap,
5226 .isr = pm8001_chip_isr,
Colin Ian Kingf310a4e2019-03-29 23:44:23 +00005227 .is_our_interrupt = pm8001_chip_is_our_interrupt,
jack wangdbf9bfe2009-10-14 16:19:21 +08005228 .isr_process_oq = process_oq,
5229 .interrupt_enable = pm8001_chip_interrupt_enable,
5230 .interrupt_disable = pm8001_chip_interrupt_disable,
5231 .make_prd = pm8001_chip_make_sg,
5232 .smp_req = pm8001_chip_smp_req,
5233 .ssp_io_req = pm8001_chip_ssp_io_req,
5234 .sata_req = pm8001_chip_sata_req,
5235 .phy_start_req = pm8001_chip_phy_start_req,
5236 .phy_stop_req = pm8001_chip_phy_stop_req,
5237 .reg_dev_req = pm8001_chip_reg_dev_req,
5238 .dereg_dev_req = pm8001_chip_dereg_dev_req,
5239 .phy_ctl_req = pm8001_chip_phy_ctl_req,
5240 .task_abort = pm8001_chip_abort_task,
5241 .ssp_tm_req = pm8001_chip_ssp_tm_req,
5242 .get_nvmd_req = pm8001_chip_get_nvmd_req,
5243 .set_nvmd_req = pm8001_chip_set_nvmd_req,
5244 .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
5245 .set_dev_state_req = pm8001_chip_set_dev_state_req,
jack_wangd0b68042009-11-05 22:32:31 +08005246 .sas_re_init_req = pm8001_chip_sas_re_initialization,
jack wangdbf9bfe2009-10-14 16:19:21 +08005247};