jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 41 | #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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 50 | static void read_main_config_table(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 51 | { |
| 52 | void __iomem *address = pm8001_ha->main_cfg_tbl_addr; |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 53 | 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_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 68 | pm8001_mr32(address, MAIN_IBQ_OFFSET); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 69 | pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_queue_offset = |
jack_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 70 | pm8001_mr32(address, MAIN_OBQ_OFFSET); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 71 | pm8001_ha->main_cfg_tbl.pm8001_tbl.hda_mode_flag = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 72 | pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET); |
| 73 | |
| 74 | /* read analog Setting offset from the configuration table */ |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 75 | pm8001_ha->main_cfg_tbl.pm8001_tbl.anolog_setup_table_offset = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 76 | pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET); |
| 77 | |
| 78 | /* read Error Dump Offset and Length */ |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 79 | pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset0 = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 80 | pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 81 | pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length0 = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 82 | pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 83 | pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset1 = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 84 | pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 85 | pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length1 = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 86 | 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 93 | static void read_general_status_table(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 94 | { |
| 95 | void __iomem *address = pm8001_ha->general_stat_tbl_addr; |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 96 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 146 | } |
| 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 152 | static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 153 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 154 | int i; |
| 155 | void __iomem *address = pm8001_ha->inbnd_q_tbl_addr; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 156 | for (i = 0; i < PM8001_MAX_INB_NUM; i++) { |
jack_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 157 | u32 offset = i * 0x20; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 158 | 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 169 | static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 170 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 171 | int i; |
| 172 | void __iomem *address = pm8001_ha->outbnd_q_tbl_addr; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 173 | for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 174 | 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 186 | static void init_default_table_values(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 187 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 188 | 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 G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 192 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 196 | |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 197 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 210 | |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 211 | pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 212 | pm8001_ha->memoryMap.region[AAP1].phys_addr_hi; |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 213 | pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 214 | pm8001_ha->memoryMap.region[AAP1].phys_addr_lo; |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 215 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 219 | pm8001_ha->memoryMap.region[IOP].phys_addr_hi; |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 220 | pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr = |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 221 | pm8001_ha->memoryMap.region[IOP].phys_addr_lo; |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 222 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 227 | pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt = |
Hans Verkuil | 9504a92 | 2013-07-26 18:43:45 +0200 | [diff] [blame] | 228 | PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 229 | pm8001_ha->inbnd_q_tbl[i].upper_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 230 | pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 231 | pm8001_ha->inbnd_q_tbl[i].lower_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 232 | pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 233 | pm8001_ha->inbnd_q_tbl[i].base_virt = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 234 | (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 235 | pm8001_ha->inbnd_q_tbl[i].total_length = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 236 | pm8001_ha->memoryMap.region[ib_offset + i].total_len; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 237 | pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 238 | pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 239 | pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 240 | pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 241 | pm8001_ha->inbnd_q_tbl[i].ci_virt = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 242 | pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 243 | 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 K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 252 | for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 253 | pm8001_ha->outbnd_q_tbl[i].element_size_cnt = |
Hans Verkuil | 9504a92 | 2013-07-26 18:43:45 +0200 | [diff] [blame] | 254 | PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 255 | pm8001_ha->outbnd_q_tbl[i].upper_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 256 | pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 257 | pm8001_ha->outbnd_q_tbl[i].lower_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 258 | pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 259 | pm8001_ha->outbnd_q_tbl[i].base_virt = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 260 | (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 261 | pm8001_ha->outbnd_q_tbl[i].total_length = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 262 | pm8001_ha->memoryMap.region[ob_offset + i].total_len; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 263 | pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 264 | pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 265 | pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 266 | pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 267 | pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 268 | 0 | (10 << 16) | (i << 24); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 269 | pm8001_ha->outbnd_q_tbl[i].pi_virt = |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 270 | pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 271 | 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 286 | static void update_main_config_table(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 287 | { |
| 288 | void __iomem *address = pm8001_ha->main_cfg_tbl_addr; |
| 289 | pm8001_mw32(address, 0x24, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 290 | pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 291 | pm8001_mw32(address, 0x28, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 292 | pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 293 | pm8001_mw32(address, 0x2C, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 294 | pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 295 | pm8001_mw32(address, 0x30, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 296 | pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 297 | pm8001_mw32(address, 0x34, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 298 | pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 299 | pm8001_mw32(address, 0x38, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 300 | pm8001_ha->main_cfg_tbl.pm8001_tbl. |
| 301 | outbound_tgt_ITNexus_event_pid0_3); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 302 | pm8001_mw32(address, 0x3C, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 303 | pm8001_ha->main_cfg_tbl.pm8001_tbl. |
| 304 | outbound_tgt_ITNexus_event_pid4_7); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 305 | pm8001_mw32(address, 0x40, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 306 | pm8001_ha->main_cfg_tbl.pm8001_tbl. |
| 307 | outbound_tgt_ssp_event_pid0_3); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 308 | pm8001_mw32(address, 0x44, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 309 | pm8001_ha->main_cfg_tbl.pm8001_tbl. |
| 310 | outbound_tgt_ssp_event_pid4_7); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 311 | pm8001_mw32(address, 0x48, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 312 | pm8001_ha->main_cfg_tbl.pm8001_tbl. |
| 313 | outbound_tgt_smp_event_pid0_3); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 314 | pm8001_mw32(address, 0x4C, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 315 | pm8001_ha->main_cfg_tbl.pm8001_tbl. |
| 316 | outbound_tgt_smp_event_pid4_7); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 317 | pm8001_mw32(address, 0x50, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 318 | pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 319 | pm8001_mw32(address, 0x54, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 320 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 325 | pm8001_mw32(address, 0x60, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 326 | pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 327 | pm8001_mw32(address, 0x64, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 328 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 331 | pm8001_mw32(address, 0x6C, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 332 | pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 333 | pm8001_mw32(address, 0x70, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 334 | pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /** |
| 338 | * update_inbnd_queue_table - update the inbound queue table to the HBA. |
| 339 | * @pm8001_ha: our hba card information |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 340 | * @number: entry in the queue |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 341 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 342 | static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha, |
| 343 | int number) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 344 | { |
| 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 Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 362 | * @number: entry in the queue |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 363 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 364 | static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha, |
| 365 | int number) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 366 | { |
| 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 384 | * pm8001_bar4_shift - function is called to shift BAR base address |
| 385 | * @pm8001_ha : our hba card infomation |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 386 | * @shiftValue : shifting value in memory bar. |
| 387 | */ |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 388 | int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 389 | { |
| 390 | u32 regVal; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 391 | unsigned long start; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 392 | |
| 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 397 | start = jiffies + HZ; /* 1 sec */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 398 | do { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 399 | regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW); |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 400 | } while ((regVal != shiftValue) && time_before(jiffies, start)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 401 | |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 402 | if (regVal != shiftValue) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 403 | 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 416 | static void mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha, |
| 417 | u32 SSCbit) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 418 | { |
Lee Jones | a364a3e | 2020-11-16 10:41:19 +0000 | [diff] [blame^] | 419 | u32 offset, i; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 420 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 421 | |
| 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_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 426 | #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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 429 | |
| 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 434 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 438 | return; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 439 | } |
jack wang | 0330dba | 2009-12-07 17:46:22 +0800 | [diff] [blame] | 440 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 441 | for (i = 0; i < 4; i++) { |
| 442 | offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i; |
jack wang | 0330dba | 2009-12-07 17:46:22 +0800 | [diff] [blame] | 443 | pm8001_cw32(pm8001_ha, 2, offset, 0x80001501); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 444 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 445 | /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */ |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 446 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 449 | return; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 450 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 451 | for (i = 4; i < 8; i++) { |
| 452 | offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4); |
jack wang | 0330dba | 2009-12-07 17:46:22 +0800 | [diff] [blame] | 453 | pm8001_cw32(pm8001_ha, 2, offset, 0x80001501); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 454 | } |
jack wang | 0330dba | 2009-12-07 17:46:22 +0800 | [diff] [blame] | 455 | /************************************************************* |
| 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 Jones | a364a3e | 2020-11-16 10:41:19 +0000 | [diff] [blame^] | 470 | pm8001_cr32(pm8001_ha, 2, 0xd8); |
jack wang | 0330dba | 2009-12-07 17:46:22 +0800 | [diff] [blame] | 471 | pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 472 | |
| 473 | /*set the shifted destination address to 0x0 to avoid error operation */ |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 474 | pm8001_bar4_shift(pm8001_ha, 0x0); |
| 475 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * mpi_set_open_retry_interval_reg |
| 481 | * @pm8001_ha: our hba card information |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 482 | * @interval: interval time for each OPEN_REJECT (RETRY). The units are in 1us. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 483 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 484 | static void mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha, |
| 485 | u32 interval) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 486 | { |
| 487 | u32 offset; |
| 488 | u32 value; |
| 489 | u32 i; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 490 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 491 | |
| 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 499 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 500 | /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/ |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 501 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 504 | return; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 505 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 506 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 511 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 514 | return; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 515 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 516 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 521 | pm8001_bar4_shift(pm8001_ha, 0x0); |
| 522 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 523 | return; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * mpi_init_check - check firmware initialization status. |
| 528 | * @pm8001_ha: our hba card information |
| 529 | */ |
| 530 | static 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 | */ |
| 565 | static 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 | |
| 616 | static 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 627 | pm8001_printk("Scratchpad 0 Offset: %x\n", offset)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 628 | pcilogic = (value & 0xFC000000) >> 26; |
| 629 | pcibar = get_pci_bar_index(pcilogic); |
| 630 | PM8001_INIT_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 631 | pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 632 | 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-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 646 | static int pm8001_chip_init(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 647 | { |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 648 | u8 i = 0; |
Sakthivel K | 54792dc | 2013-03-19 18:05:55 +0530 | [diff] [blame] | 649 | 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 Grove | 81b86d4 | 2013-12-19 10:50:57 -0500 | [diff] [blame] | 653 | if (deviceid == 0x8081 || deviceid == 0x0042) { |
Sakthivel K | 54792dc | 2013-03-19 18:05:55 +0530 | [diff] [blame] | 654 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 661 | /* 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 K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 677 | 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 K | 54792dc | 2013-03-19 18:05:55 +0530 | [diff] [blame] | 681 | /* 8081 controller donot require these operations */ |
Bradley Grove | 81b86d4 | 2013-12-19 10:50:57 -0500 | [diff] [blame] | 682 | if (deviceid != 0x8081 && deviceid != 0x0042) { |
Sakthivel K | 54792dc | 2013-03-19 18:05:55 +0530 | [diff] [blame] | 683 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 687 | /* 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 | |
| 703 | static 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 K | 54792dc | 2013-03-19 18:05:55 +0530 | [diff] [blame] | 708 | u16 deviceid; |
| 709 | pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid); |
Bradley Grove | 81b86d4 | 2013-12-19 10:50:57 -0500 | [diff] [blame] | 710 | if (deviceid == 0x8081 || deviceid == 0x0042) { |
Sakthivel K | 54792dc | 2013-03-19 18:05:55 +0530 | [diff] [blame] | 711 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 718 | 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 | */ |
| 762 | static 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 777 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 782 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 807 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 808 | return -1; |
| 809 | } |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 810 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 811 | } |
| 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 819 | */ |
| 820 | static int |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 821 | pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 822 | { |
| 823 | u32 regVal, toggleVal; |
| 824 | u32 max_wait_count; |
| 825 | u32 regVal1, regVal2, regVal3; |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 826 | u32 signature = 0x252acbcd; /* for host scratch pad0 */ |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 827 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 828 | |
| 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 838 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 841 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 851 | if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) { |
| 852 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 853 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 894 | if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) { |
| 895 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 896 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 961 | if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) { |
| 962 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 963 | 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 King | 9e2a07e | 2019-03-17 18:15:32 +0000 | [diff] [blame] | 969 | PM8001_INIT_DBG(pm8001_ha, |
| 970 | pm8001_printk("GPIO Output Control Register:" |
| 971 | " = 0x%x\n", regVal)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 972 | /* 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 978 | if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) { |
| 979 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 980 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 1016 | if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) { |
| 1017 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1018 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 1070 | if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) { |
| 1071 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1072 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 1113 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1114 | 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 Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 1143 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1144 | return -1; |
| 1145 | } |
| 1146 | } |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 1147 | pm8001_bar4_shift(pm8001_ha, 0); |
| 1148 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1149 | |
| 1150 | PM8001_INIT_DBG(pm8001_ha, |
| 1151 | pm8001_printk("SPC soft reset Complete\n")); |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | static 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önig | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 1189 | * pm8001_chip_iounmap - which maped when initialized. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1190 | * @pm8001_ha: our hba card information |
| 1191 | */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1192 | void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1193 | { |
| 1194 | s8 bar, logical = 0; |
Denis Efremov | c9c13ba | 2019-09-28 02:43:08 +0300 | [diff] [blame] | 1195 | for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1196 | /* |
| 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 King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1213 | #ifndef PM8001_USE_MSIX |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1214 | /** |
| 1215 | * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt |
| 1216 | * @pm8001_ha: our hba card information |
| 1217 | */ |
| 1218 | static void |
| 1219 | pm8001_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 | */ |
| 1229 | static void |
| 1230 | pm8001_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 King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1235 | #else |
| 1236 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1237 | /** |
| 1238 | * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt |
| 1239 | * @pm8001_ha: our hba card information |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 1240 | * @int_vec_idx: interrupt number to enable |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1241 | */ |
| 1242 | static void |
| 1243 | pm8001_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 Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 1259 | * @int_vec_idx: interrupt number to disable |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1260 | */ |
| 1261 | static void |
| 1262 | pm8001_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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1269 | } |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1270 | #endif |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 1271 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1272 | /** |
| 1273 | * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt |
| 1274 | * @pm8001_ha: our hba card information |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 1275 | * @vec: unused |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1276 | */ |
| 1277 | static void |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1278 | pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1279 | { |
| 1280 | #ifdef PM8001_USE_MSIX |
| 1281 | pm8001_chip_msix_interrupt_enable(pm8001_ha, 0); |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1282 | #else |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1283 | pm8001_chip_intx_interrupt_enable(pm8001_ha); |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1284 | #endif |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt |
| 1289 | * @pm8001_ha: our hba card information |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 1290 | * @vec: unused |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1291 | */ |
| 1292 | static void |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1293 | pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1294 | { |
| 1295 | #ifdef PM8001_USE_MSIX |
| 1296 | pm8001_chip_msix_interrupt_disable(pm8001_ha, 0); |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1297 | #else |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1298 | pm8001_chip_intx_interrupt_disable(pm8001_ha); |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 1299 | #endif |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | /** |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1303 | * pm8001_mpi_msg_free_get - get the free message buffer for transfer |
| 1304 | * inbound queue. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1305 | * @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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1309 | int pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1310 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1317 | if (messageSize > IOMB_SIZE_SPCV) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1318 | *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 Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 1325 | if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) == |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1326 | le32_to_cpu(circularQ->consumer_index)) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1327 | *messagePtr = NULL; |
| 1328 | return -1; |
| 1329 | } |
| 1330 | /* get memory IOMB buffer address */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1331 | offset = circularQ->producer_idx * messageSize; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1332 | /* increment to next bcCount element */ |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 1333 | circularQ->producer_idx = (circularQ->producer_idx + bcCount) |
| 1334 | % PM8001_MPI_QUEUE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1335 | /* 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1343 | * 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1345 | * @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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 1349 | * @nb: size in bytes of the command payload |
| 1350 | * @responseQueue: queue to interrupt on w/ command response (if any) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1351 | */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1352 | int pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1353 | struct inbound_queue_table *circularQ, |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 1354 | u32 opCode, void *payload, size_t nb, |
| 1355 | u32 responseQueue) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1356 | { |
| 1357 | u32 Header = 0, hpriority = 0, bc = 1, category = 0x02; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1358 | void *pMessage; |
peter chang | 7640e1e | 2020-11-02 22:25:25 +0530 | [diff] [blame] | 1359 | unsigned long flags; |
| 1360 | int q_index = circularQ - pm8001_ha->inbnd_q_tbl; |
| 1361 | int rv = -1; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1362 | |
peter chang | 7640e1e | 2020-11-02 22:25:25 +0530 | [diff] [blame] | 1363 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1368 | PM8001_IO_DBG(pm8001_ha, |
peter chang | 7640e1e | 2020-11-02 22:25:25 +0530 | [diff] [blame] | 1369 | pm8001_printk("No free mpi buffer\n")); |
| 1370 | rv = -ENOMEM; |
| 1371 | goto done; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1372 | } |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 1373 | |
| 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1380 | |
| 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 1390 | PM8001_DEVIO_DBG(pm8001_ha, |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1391 | pm8001_printk("INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n", |
| 1392 | responseQueue, opCode, circularQ->producer_idx, |
| 1393 | circularQ->consumer_index)); |
peter chang | 7640e1e | 2020-11-02 22:25:25 +0530 | [diff] [blame] | 1394 | done: |
| 1395 | spin_unlock_irqrestore(&circularQ->iq_lock, flags); |
| 1396 | return rv; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1397 | } |
| 1398 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1399 | u32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1400 | struct outbound_queue_table *circularQ, u8 bc) |
| 1401 | { |
| 1402 | u32 producer_index; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1403 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1408 | circularQ->consumer_idx * pm8001_ha->iomb_size); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1409 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1423 | /* free the circular queue buffer elements associated with the message*/ |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 1424 | circularQ->consumer_idx = (circularQ->consumer_idx + bc) |
| 1425 | % PM8001_MPI_QUEUE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1426 | /* 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1439 | * pm8001_mpi_msg_consume- get the MPI message from outbound queue |
| 1440 | * message table. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1441 | * @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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1446 | u32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1447 | 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1455 | if (le32_to_cpu(circularQ->producer_index) |
| 1456 | != circularQ->consumer_idx) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1457 | /*Get the pointer to the circular queue buffer element*/ |
| 1458 | msgHeader = (struct mpi_msg_hdr *) |
| 1459 | (circularQ->base_virt + |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1460 | circularQ->consumer_idx * pm8001_ha->iomb_size); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1461 | /* read header */ |
| 1462 | header_tmp = pm8001_read_32(msgHeader); |
| 1463 | msgHeader_tmp = cpu_to_le32(header_tmp); |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 1464 | 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1468 | if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1469 | if (OPC_OUB_SKIP_ENTRY != |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1470 | (le32_to_cpu(msgHeader_tmp) & 0xfff)) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1471 | *messagePtr1 = |
| 1472 | ((u8 *)msgHeader) + |
| 1473 | sizeof(struct mpi_msg_hdr); |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1474 | *pBC = (u8)((le32_to_cpu(msgHeader_tmp) |
| 1475 | >> 24) & 0x1f); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1476 | PM8001_IO_DBG(pm8001_ha, |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1477 | pm8001_printk(": CI=%d PI=%d " |
| 1478 | "msgHeader=%x\n", |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1479 | circularQ->consumer_idx, |
| 1480 | circularQ->producer_index, |
| 1481 | msgHeader_tmp)); |
| 1482 | return MPI_IO_STATUS_SUCCESS; |
| 1483 | } else { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1484 | circularQ->consumer_idx = |
| 1485 | (circularQ->consumer_idx + |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1486 | ((le32_to_cpu(msgHeader_tmp) |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 1487 | >> 24) & 0x1f)) |
| 1488 | % PM8001_MPI_QUEUE; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1489 | msgHeader_tmp = 0; |
| 1490 | pm8001_write_32(msgHeader, 0, 0); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1491 | /* 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1496 | } |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1497 | } else { |
| 1498 | circularQ->consumer_idx = |
| 1499 | (circularQ->consumer_idx + |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1500 | ((le32_to_cpu(msgHeader_tmp) >> 24) & |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 1501 | 0x1f)) % PM8001_MPI_QUEUE; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1502 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1508 | return MPI_IO_STATUS_FAIL; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1509 | } |
| 1510 | } else { |
| 1511 | u32 producer_index; |
| 1512 | void *pi_virt = circularQ->pi_virt; |
Deepak Ukey | 72349b6 | 2018-09-11 14:18:04 +0530 | [diff] [blame] | 1513 | /* 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1519 | /* Update the producer index from SPC */ |
| 1520 | producer_index = pm8001_read_32(pi_virt); |
| 1521 | circularQ->producer_index = cpu_to_le32(producer_index); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1522 | } |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 1523 | } while (le32_to_cpu(circularQ->producer_index) != |
| 1524 | circularQ->consumer_idx); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1525 | /* while we don't have any more not-yet-delivered message */ |
| 1526 | /* report empty */ |
| 1527 | return MPI_IO_STATUS_BUSY; |
| 1528 | } |
| 1529 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1530 | void pm8001_work_fn(struct work_struct *work) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1531 | { |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1532 | struct pm8001_work *pw = container_of(work, struct pm8001_work, work); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1533 | struct pm8001_device *pm8001_dev; |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1534 | struct domain_device *dev; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1535 | |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1536 | /* |
| 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 Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1545 | && (pm8001_dev->dev_type == SAS_PHY_UNUSED))) { |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1546 | kfree(pw); |
| 1547 | return; |
| 1548 | } |
| 1549 | |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1550 | switch (pw->handler) { |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1551 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 1590 | atomic_dec(&pm8001_dev->running_req); |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1591 | 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 1636 | PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk( |
| 1637 | "...query task failed!!!\n")); |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1638 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1709 | case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1710 | dev = pm8001_dev->sas_device; |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1711 | pm8001_I_T_nexus_event_handler(dev); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1712 | break; |
| 1713 | case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1714 | dev = pm8001_dev->sas_device; |
| 1715 | pm8001_I_T_nexus_reset(dev); |
| 1716 | break; |
| 1717 | case IO_DS_IN_ERROR: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1718 | dev = pm8001_dev->sas_device; |
| 1719 | pm8001_I_T_nexus_reset(dev); |
| 1720 | break; |
| 1721 | case IO_DS_NON_OPERATIONAL: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1722 | dev = pm8001_dev->sas_device; |
| 1723 | pm8001_I_T_nexus_reset(dev); |
| 1724 | break; |
| 1725 | } |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1726 | kfree(pw); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1729 | int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1730 | int handler) |
| 1731 | { |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1732 | struct pm8001_work *pw; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1733 | int ret = 0; |
| 1734 | |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1735 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1742 | } else |
| 1743 | ret = -ENOMEM; |
| 1744 | |
| 1745 | return ret; |
| 1746 | } |
| 1747 | |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1748 | static 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 1791 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort, |
| 1792 | sizeof(task_abort), 0); |
Tomas Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 1793 | if (ret) |
| 1794 | pm8001_tag_free(pm8001_ha, ccb_tag); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1795 | |
| 1796 | } |
| 1797 | |
| 1798 | static 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 Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 1822 | sas_free_task(task); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1823 | 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 Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 1833 | sas_free_task(task); |
| 1834 | pm8001_tag_free(pm8001_ha, ccb_tag); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1835 | PM8001_FAIL_DBG(pm8001_ha, |
| 1836 | pm8001_printk("Domain device cannot be allocated\n")); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1837 | return; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1838 | } |
Tomas Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 1839 | task->dev = dev; |
| 1840 | task->dev->lldd_dev = pm8001_ha_dev; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1841 | |
| 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 1865 | res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd, |
| 1866 | sizeof(sata_cmd), 0); |
Tomas Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 1867 | if (res) { |
| 1868 | sas_free_task(task); |
| 1869 | pm8001_tag_free(pm8001_ha, ccb_tag); |
| 1870 | kfree(dev); |
| 1871 | } |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 1872 | } |
| 1873 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1874 | /** |
| 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1885 | static void |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1886 | mpi_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 Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1902 | if ((status == IO_ABORTED) && ccb->open_retry) { |
| 1903 | /* Being completed by another */ |
| 1904 | ccb->open_retry = 0; |
| 1905 | return; |
| 1906 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1907 | pm8001_dev = ccb->device; |
| 1908 | param = le32_to_cpu(psspPayload->param); |
| 1909 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1910 | t = ccb->task; |
| 1911 | |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1912 | if (status && status != IO_UNDERFLOW) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1913 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 1916 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1917 | ts = &t->task_status; |
Anand Kumar Santhanam | cb269c2 | 2013-09-17 16:47:21 +0530 | [diff] [blame] | 1918 | /* 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 1925 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1930 | switch (status) { |
| 1931 | case IO_SUCCESS: |
| 1932 | PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS" |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 1933 | ",param = %d\n", param)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1934 | if (param == 0) { |
| 1935 | ts->resp = SAS_TASK_COMPLETE; |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1936 | ts->stat = SAM_STAT_GOOD; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1937 | } 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 1945 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1946 | break; |
| 1947 | case IO_ABORTED: |
| 1948 | PM8001_IO_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 1949 | pm8001_printk("IO_ABORTED IOMB Tag\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1950 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 1956 | ",param = %d\n", param)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1957 | ts->resp = SAS_TASK_COMPLETE; |
| 1958 | ts->stat = SAS_DATA_UNDERRUN; |
| 1959 | ts->residual = param; |
| 1960 | if (pm8001_dev) |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 1961 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1962 | 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 Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 1974 | /* Force the midlayer to retry */ |
| 1975 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1976 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2003 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2004 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2043 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2044 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 2110 | break; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2111 | default: |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2112 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2113 | 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 K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2120 | pm8001_printk("scsi_status = %x\n ", |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2121 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | /*See the comments for mpi_ssp_completion */ |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2142 | static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2143 | { |
| 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2163 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2164 | ts = &t->task_status; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2165 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2166 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2175 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2176 | break; |
| 2177 | case IO_XFER_ERROR_BREAK: |
| 2178 | PM8001_IO_DBG(pm8001_ha, |
| 2179 | pm8001_printk("IO_XFER_ERROR_BREAK\n")); |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 2180 | pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK); |
| 2181 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2182 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2209 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2210 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2249 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2250 | 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 Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 2260 | pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT); |
| 2261 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2262 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2301 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2302 | default: |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2303 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2304 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | /*See the comments for mpi_ssp_completion */ |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2330 | static void |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2331 | mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) |
| 2332 | { |
| 2333 | struct sas_task *t; |
| 2334 | struct pm8001_ccb_info *ccb; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2335 | u32 param; |
| 2336 | u32 status; |
| 2337 | u32 tag; |
Anand Kumar Santhanam | cb269c2 | 2013-09-17 16:47:21 +0530 | [diff] [blame] | 2338 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2343 | 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 Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2348 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2349 | |
| 2350 | psataPayload = (struct sata_completion_resp *)(piomb + 4); |
| 2351 | status = le32_to_cpu(psataPayload->status); |
| 2352 | tag = le32_to_cpu(psataPayload->tag); |
| 2353 | |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2354 | if (!tag) { |
| 2355 | PM8001_FAIL_DBG(pm8001_ha, |
| 2356 | pm8001_printk("tag null\n")); |
| 2357 | return; |
| 2358 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2359 | ccb = &pm8001_ha->ccb_info[tag]; |
| 2360 | param = le32_to_cpu(psataPayload->param); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2361 | if (ccb) { |
| 2362 | t = ccb->task; |
| 2363 | pm8001_dev = ccb->device; |
| 2364 | } else { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2365 | PM8001_FAIL_DBG(pm8001_ha, |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2366 | pm8001_printk("ccb null\n")); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2367 | return; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2368 | } |
| 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2392 | |
| 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 Santhanam | cb269c2 | 2013-09-17 16:47:21 +0530 | [diff] [blame] | 2398 | /* 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 Garry | 924a354 | 2019-06-10 20:41:41 +0800 | [diff] [blame] | 2402 | (dev_is_expander(t->dev->parent->dev_type)))) { |
Anand Kumar Santhanam | cb269c2 | 2013-09-17 16:47:21 +0530 | [diff] [blame] | 2403 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2438 | 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 Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 2443 | ts->stat = SAM_STAT_GOOD; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2444 | /* 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2457 | } 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 Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 2468 | t->data_dir == DMA_FROM_DEVICE) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2469 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 2487 | pm8001_printk("response to large\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2488 | } |
| 2489 | if (pm8001_dev) |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2490 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2491 | break; |
| 2492 | case IO_ABORTED: |
| 2493 | PM8001_IO_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 2494 | pm8001_printk("IO_ABORTED IOMB Tag\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2495 | ts->resp = SAS_TASK_COMPLETE; |
| 2496 | ts->stat = SAS_ABORTED_TASK; |
| 2497 | if (pm8001_dev) |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2498 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2499 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2509 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2510 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2516 | if (pm8001_dev) |
| 2517 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2518 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2524 | if (pm8001_dev) |
| 2525 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2526 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2533 | if (pm8001_dev) |
| 2534 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2535 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2543 | if (pm8001_dev) |
| 2544 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2545 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2552 | if (pm8001_dev) |
| 2553 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2554 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2561 | if (pm8001_dev) |
| 2562 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2563 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2575 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2576 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2577 | } |
| 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2591 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2592 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2593 | } |
| 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2602 | if (pm8001_dev) |
| 2603 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2604 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2617 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2618 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2619 | } |
| 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2627 | if (pm8001_dev) |
| 2628 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2629 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2635 | if (pm8001_dev) |
| 2636 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2637 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2643 | if (pm8001_dev) |
| 2644 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2645 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2651 | if (pm8001_dev) |
| 2652 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2653 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2659 | if (pm8001_dev) |
| 2660 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2661 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2667 | if (pm8001_dev) |
| 2668 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2669 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2675 | if (pm8001_dev) |
| 2676 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2677 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2683 | if (pm8001_dev) |
| 2684 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2685 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2696 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2697 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2698 | } |
| 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2705 | if (pm8001_dev) |
| 2706 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2707 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2718 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2719 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2720 | } |
| 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2728 | if (pm8001_dev) |
| 2729 | atomic_dec(&pm8001_dev->running_req); |
Johannes Thumshirn | 50acde8 | 2015-08-17 15:52:32 +0200 | [diff] [blame] | 2730 | break; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2731 | default: |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2732 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2733 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2737 | if (pm8001_dev) |
| 2738 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2739 | break; |
| 2740 | } |
Santosh Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2741 | spin_lock_irqsave(&t->task_state_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2742 | 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 Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2746 | spin_unlock_irqrestore(&t->task_state_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2747 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2752 | } else { |
Santosh Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2753 | spin_unlock_irqrestore(&t->task_state_lock, flags); |
Suresh Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2754 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2755 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /*See the comments for mpi_ssp_completion */ |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2759 | static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2760 | { |
| 2761 | struct sas_task *t; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2762 | 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 Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2771 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2772 | |
| 2773 | ccb = &pm8001_ha->ccb_info[tag]; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 2774 | |
| 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2797 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2803 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2804 | ts = &t->task_status; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2805 | PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk( |
Sakthivel K | a70b8fc | 2013-03-19 18:07:09 +0530 | [diff] [blame] | 2806 | "port_id:0x%x, device_id:0x%x, tag:0x%x, event:0x%x\n", |
| 2807 | port_id, dev_id, tag, event)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2808 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 2815 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2816 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2863 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2864 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2865 | } |
| 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2954 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2955 | 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 Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2961 | spin_lock_irqsave(&t->task_state_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2962 | 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 Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2966 | spin_unlock_irqrestore(&t->task_state_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2967 | 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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2972 | } else { |
Santosh Nayak | b08c185 | 2012-03-09 13:43:38 +0530 | [diff] [blame] | 2973 | spin_unlock_irqrestore(&t->task_state_lock, flags); |
Suresh Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 2974 | pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2975 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | /*See the comments for mpi_ssp_completion */ |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 2979 | static void |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2980 | mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) |
| 2981 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2982 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 2996 | t = ccb->task; |
| 2997 | ts = &t->task_status; |
| 2998 | pm8001_dev = ccb->device; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 2999 | if (status) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3000 | PM8001_FAIL_DBG(pm8001_ha, |
| 3001 | pm8001_printk("smp IO status 0x%x\n", status)); |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3002 | PM8001_IOERR_DBG(pm8001_ha, |
| 3003 | pm8001_printk("status:0x%x, tag:0x%x, task:0x%p\n", |
| 3004 | status, tag, t)); |
| 3005 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3006 | if (unlikely(!t || !t->lldd_task || !t->dev)) |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 3007 | return; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3008 | |
| 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 Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 3013 | ts->stat = SAM_STAT_GOOD; |
Colin Ian King | 9e2a07e | 2019-03-17 18:15:32 +0000 | [diff] [blame] | 3014 | if (pm8001_dev) |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 3015 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3016 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 3023 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3024 | 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 G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 3031 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3032 | 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 Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 3042 | ts->stat = SAM_STAT_BUSY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3043 | 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 Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 3048 | ts->stat = SAM_STAT_BUSY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3049 | 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 Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 3054 | ts->stat = SAM_STAT_BUSY; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3055 | 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3156 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3157 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3180 | } |
| 3181 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3182 | void pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha, |
| 3183 | void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3184 | { |
| 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 Santhanam | e912457b | 2013-09-17 16:58:10 +0530 | [diff] [blame] | 3192 | u8 pds = le32_to_cpu(pPayload->pds_nds) & PDS_BITS; |
| 3193 | u8 nds = le32_to_cpu(pPayload->pds_nds) & NDS_BITS; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3194 | 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 Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 3200 | pm8001_tag_free(pm8001_ha, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3201 | } |
| 3202 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3203 | void pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3204 | { |
| 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 Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 3219 | pm8001_tag_free(pm8001_ha, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3220 | } |
| 3221 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3222 | void |
| 3223 | pm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3224 | { |
Suresh Thiagarajan | 9e03284 | 2014-08-11 11:50:35 +0530 | [diff] [blame] | 3225 | struct fw_control_ex *fw_control_context; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3226 | 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 Thiagarajan | 9e03284 | 2014-08-11 11:50:35 +0530 | [diff] [blame] | 3234 | fw_control_context = ccb->fw_control_context; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3235 | |
| 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 Thiagarajan | 9e03284 | 2014-08-11 11:50:35 +0530 | [diff] [blame] | 3275 | /* 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 Henzl | f3a0655 | 2014-07-07 17:19:58 +0200 | [diff] [blame] | 3281 | kfree(ccb->fw_control_context); |
yuuzheng | 1f889b5 | 2020-11-02 22:25:28 +0530 | [diff] [blame] | 3282 | /* 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3288 | ccb->task = NULL; |
| 3289 | ccb->ccb_tag = 0xFFFFFFFF; |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 3290 | pm8001_tag_free(pm8001_ha, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3291 | } |
| 3292 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3293 | int pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3294 | { |
Viswas G | 25c6edb | 2017-10-18 11:39:10 +0530 | [diff] [blame] | 3295 | u32 tag; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3296 | 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 G | 25c6edb | 2017-10-18 11:39:10 +0530 | [diff] [blame] | 3301 | tag = le32_to_cpu(pPayload->tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3302 | if (status != 0) { |
| 3303 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3304 | pm8001_printk("%x phy execute %x phy op failed!\n", |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3305 | phy_id, phy_op)); |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 3306 | } else { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3307 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3308 | pm8001_printk("%x phy execute %x phy op success!\n", |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3309 | phy_id, phy_op)); |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 3310 | 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 G | 25c6edb | 2017-10-18 11:39:10 +0530 | [diff] [blame] | 3316 | pm8001_tag_free(pm8001_ha, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3317 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3331 | void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3332 | { |
| 3333 | struct pm8001_phy *phy = &pm8001_ha->phy[i]; |
| 3334 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3335 | if (!phy->phy_attached) |
| 3336 | return; |
| 3337 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3338 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3363 | void pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3364 | { |
| 3365 | struct sas_phy *sas_phy = phy->sas_phy.phy; |
| 3366 | |
| 3367 | switch (link_rate) { |
Viswas G | b093d59 | 2015-08-11 15:06:25 +0530 | [diff] [blame] | 3368 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3372 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3404 | void pm8001_get_attached_sas_addr(struct pm8001_phy *phy, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3405 | 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 | */ |
| 3431 | static 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 3441 | payload.tag = cpu_to_le32(1); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3442 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 3446 | pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 3447 | sizeof(payload), 0); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | static 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 | */ |
| 3458 | static void |
| 3459 | hw_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 wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3467 | u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3468 | u8 phy_id = |
| 3469 | (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3470 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3473 | 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 wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3477 | port->port_state = portstate; |
Nikith Ganigarakoppal | 7d02900 | 2013-10-30 16:23:47 +0530 | [diff] [blame] | 3478 | phy->phy_state = PHY_STATE_LINK_UP_SPC; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3479 | PM8001_MSG_DBG(pm8001_ha, |
jack wang | 83e7332 | 2009-12-07 17:23:11 +0800 | [diff] [blame] | 3480 | pm8001_printk("HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n", |
| 3481 | port_id, phy_id)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3482 | |
| 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 wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3492 | port->port_attached = 1; |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3493 | pm8001_get_lrate_mode(phy, link_rate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3494 | break; |
| 3495 | case SAS_EDGE_EXPANDER_DEVICE: |
| 3496 | PM8001_MSG_DBG(pm8001_ha, |
| 3497 | pm8001_printk("expander device.\n")); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3498 | port->port_attached = 1; |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3499 | pm8001_get_lrate_mode(phy, link_rate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3500 | break; |
| 3501 | case SAS_FANOUT_EXPANDER_DEVICE: |
| 3502 | PM8001_MSG_DBG(pm8001_ha, |
| 3503 | pm8001_printk("fanout expander device.\n")); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3504 | port->port_attached = 1; |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3505 | pm8001_get_lrate_mode(phy, link_rate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3506 | break; |
| 3507 | default: |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3508 | PM8001_DEVIO_DBG(pm8001_ha, |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 3509 | pm8001_printk("unknown device type(%x)\n", deviceType)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3510 | break; |
| 3511 | } |
| 3512 | phy->phy_type |= PORT_TYPE_SAS; |
| 3513 | phy->identify.device_type = deviceType; |
| 3514 | phy->phy_attached = 1; |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 3515 | if (phy->identify.device_type == SAS_END_DEVICE) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3516 | phy->identify.target_port_protocols = SAS_PROTOCOL_SSP; |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 3517 | else if (phy->identify.device_type != SAS_PHY_UNUSED) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3518 | 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 | */ |
| 3537 | static void |
| 3538 | hw_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 wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3546 | u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3547 | u8 phy_id = |
| 3548 | (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3549 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3552 | struct sas_ha_struct *sas_ha = pm8001_ha->sas; |
| 3553 | struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; |
| 3554 | unsigned long flags; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3555 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | 83e7332 | 2009-12-07 17:23:11 +0800 | [diff] [blame] | 3556 | pm8001_printk("HW_EVENT_SATA_PHY_UP port id = %d," |
| 3557 | " phy id = %d\n", port_id, phy_id)); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3558 | port->port_state = portstate; |
Nikith Ganigarakoppal | 7d02900 | 2013-10-30 16:23:47 +0530 | [diff] [blame] | 3559 | phy->phy_state = PHY_STATE_LINK_UP_SPC; |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3560 | port->port_attached = 1; |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3561 | pm8001_get_lrate_mode(phy, link_rate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3562 | 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 Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 3571 | phy->identify.device_type = SAS_SATA_DEV; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3572 | 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 | */ |
| 3582 | static void |
| 3583 | hw_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 wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3594 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3601 | switch (portstate) { |
| 3602 | case PORT_VALID: |
| 3603 | break; |
| 3604 | case PORT_INVALID: |
| 3605 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3606 | pm8001_printk(" PortInvalid portID %d\n", port_id)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3607 | PM8001_MSG_DBG(pm8001_ha, |
| 3608 | pm8001_printk(" Last phy Down and port invalid\n")); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3609 | port->port_attached = 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3610 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3615 | pm8001_printk(" Port In Reset portID %d\n", port_id)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3616 | break; |
| 3617 | case PORT_NOT_ESTABLISHED: |
| 3618 | PM8001_MSG_DBG(pm8001_ha, |
| 3619 | pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n")); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3620 | port->port_attached = 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3621 | 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 wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3627 | port->port_attached = 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3628 | pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN, |
| 3629 | port_id, phy_id, 0, 0); |
| 3630 | break; |
| 3631 | default: |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 3632 | port->port_attached = 0; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3633 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3634 | pm8001_printk(" phy Down and(default) = %x\n", |
| 3635 | portstate)); |
| 3636 | break; |
| 3637 | |
| 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | /** |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3642 | * pm8001_mpi_reg_resp -process register device ID response. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3643 | * @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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3651 | int pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3652 | { |
| 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 3662 | ccb = &pm8001_ha->ccb_info[htag]; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3663 | 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 King | 9af3c47 | 2018-05-26 15:42:18 +0100 | [diff] [blame] | 3703 | pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3704 | break; |
| 3705 | } |
| 3706 | complete(pm8001_dev->dcompletion); |
| 3707 | ccb->task = NULL; |
| 3708 | ccb->ccb_tag = 0xFFFFFFFF; |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 3709 | pm8001_tag_free(pm8001_ha, htag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3710 | return 0; |
| 3711 | } |
| 3712 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3713 | int pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3714 | { |
| 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3729 | /** |
| 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 | */ |
| 3734 | int pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha, |
| 3735 | void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3736 | { |
| 3737 | u32 status; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3738 | struct fw_flash_Update_resp *ppayload = |
| 3739 | (struct fw_flash_Update_resp *)(piomb + 4); |
Santosh Nayak | fd00f7c | 2012-03-19 21:26:27 +0530 | [diff] [blame] | 3740 | u32 tag = le32_to_cpu(ppayload->tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3741 | struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; |
| 3742 | status = le32_to_cpu(ppayload->status); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3743 | 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3781 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3782 | pm8001_printk("No matched status = %d\n", status)); |
| 3783 | break; |
| 3784 | } |
Tomas Henzl | 9422e86 | 2014-07-07 17:20:00 +0200 | [diff] [blame] | 3785 | kfree(ccb->fw_control_context); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3786 | ccb->task = NULL; |
| 3787 | ccb->ccb_tag = 0xFFFFFFFF; |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 3788 | pm8001_tag_free(pm8001_ha, tag); |
Tomas Henzl | 9422e86 | 2014-07-07 17:20:00 +0200 | [diff] [blame] | 3789 | complete(pm8001_ha->nvmd_completion); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3790 | return 0; |
| 3791 | } |
| 3792 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3793 | int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3794 | { |
| 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3804 | pm8001_printk("inb_IOMB_payload[0x%x] 0x%x,\n", i, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3805 | pPayload->inb_IOMB_payload[i])); |
| 3806 | return 0; |
| 3807 | } |
| 3808 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 3809 | int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3810 | { |
| 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 K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 3817 | struct pm8001_device *pm8001_dev; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3818 | |
| 3819 | struct task_abort_resp *pPayload = |
| 3820 | (struct task_abort_resp *)(piomb + 4); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3821 | |
| 3822 | status = le32_to_cpu(pPayload->status); |
| 3823 | tag = le32_to_cpu(pPayload->tag); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 3824 | if (!tag) { |
| 3825 | PM8001_FAIL_DBG(pm8001_ha, |
| 3826 | pm8001_printk(" TAG NULL. RETURNING !!!")); |
| 3827 | return -1; |
| 3828 | } |
| 3829 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3830 | scp = le32_to_cpu(pPayload->scp); |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 3831 | ccb = &pm8001_ha->ccb_info[tag]; |
| 3832 | t = ccb->task; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 3833 | pm8001_dev = ccb->device; /* retrieve device */ |
| 3834 | |
| 3835 | if (!t) { |
| 3836 | PM8001_FAIL_DBG(pm8001_ha, |
| 3837 | pm8001_printk(" TASK NULL. RETURNING !!!")); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 3838 | return -1; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 3839 | } |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 3840 | ts = &t->task_status; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3841 | if (status != 0) |
| 3842 | PM8001_FAIL_DBG(pm8001_ha, |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 3843 | pm8001_printk("task abort failed status 0x%x ," |
| 3844 | "tag = 0x%x, scp= 0x%x\n", status, tag, scp)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3845 | switch (status) { |
| 3846 | case IO_SUCCESS: |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 3847 | PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3848 | ts->resp = SAS_TASK_COMPLETE; |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 3849 | ts->stat = SAM_STAT_GOOD; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3850 | break; |
| 3851 | case IO_NOT_VALID: |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 3852 | PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_NOT_VALID\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3853 | 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 3861 | pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3862 | mb(); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 3863 | |
Dan Carpenter | 808cbb6 | 2013-05-09 15:48:13 +0300 | [diff] [blame] | 3864 | if (pm8001_dev->id & NCQ_ABORT_ALL_FLAG) { |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 3865 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3872 | 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 | */ |
| 3880 | static 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 3897 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3900 | 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 Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 3907 | if (pm8001_ha->flags == PM8001F_RUN_TIME && |
| 3908 | phy->enable_completion != NULL) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3909 | complete(phy->enable_completion); |
| 3910 | } |
| 3911 | break; |
| 3912 | case HW_EVENT_SAS_PHY_UP: |
| 3913 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3914 | pm8001_printk("HW_EVENT_PHY_START_STATUS\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3915 | hw_event_sas_phy_up(pm8001_ha, piomb); |
| 3916 | break; |
| 3917 | case HW_EVENT_SATA_PHY_UP: |
| 3918 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3919 | pm8001_printk("HW_EVENT_SATA_PHY_UP\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3920 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3931 | pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3932 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 3936 | pm8001_printk("HW_EVENT_PHY_DOWN\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3937 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4048 | pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4049 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4058 | pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4059 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4065 | pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4066 | 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 Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4072 | pm8001_printk("HW_EVENT_PORT_RECOVER\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4073 | break; |
| 4074 | case HW_EVENT_PORT_RESET_COMPLETE: |
| 4075 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4076 | pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4077 | 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 4083 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4084 | 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 | */ |
| 4095 | static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb) |
| 4096 | { |
Santosh Nayak | fd00f7c | 2012-03-19 21:26:27 +0530 | [diff] [blame] | 4097 | __le32 pHeader = *(__le32 *)piomb; |
| 4098 | u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4099 | |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4100 | PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4101 | |
| 4102 | switch (opc) { |
| 4103 | case OPC_OUB_ECHO: |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4104 | PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4105 | break; |
| 4106 | case OPC_OUB_HW_EVENT: |
| 4107 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4108 | pm8001_printk("OPC_OUB_HW_EVENT\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4109 | mpi_hw_event(pm8001_ha, piomb); |
| 4110 | break; |
| 4111 | case OPC_OUB_SSP_COMP: |
| 4112 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4113 | pm8001_printk("OPC_OUB_SSP_COMP\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4114 | mpi_ssp_completion(pm8001_ha, piomb); |
| 4115 | break; |
| 4116 | case OPC_OUB_SMP_COMP: |
| 4117 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4118 | pm8001_printk("OPC_OUB_SMP_COMP\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4119 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4124 | pm8001_mpi_local_phy_ctl(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4125 | break; |
| 4126 | case OPC_OUB_DEV_REGIST: |
| 4127 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4128 | pm8001_printk("OPC_OUB_DEV_REGIST\n")); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4129 | pm8001_mpi_reg_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4130 | break; |
| 4131 | case OPC_OUB_DEREG_DEV: |
| 4132 | PM8001_MSG_DBG(pm8001_ha, |
Masanari Iida | 44ebf89 | 2012-02-03 02:25:22 +0900 | [diff] [blame] | 4133 | pm8001_printk("unregister the device\n")); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4134 | pm8001_mpi_dereg_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4135 | break; |
| 4136 | case OPC_OUB_GET_DEV_HANDLE: |
| 4137 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4138 | pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4139 | break; |
| 4140 | case OPC_OUB_SATA_COMP: |
| 4141 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4142 | pm8001_printk("OPC_OUB_SATA_COMP\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4143 | mpi_sata_completion(pm8001_ha, piomb); |
| 4144 | break; |
| 4145 | case OPC_OUB_SATA_EVENT: |
| 4146 | PM8001_MSG_DBG(pm8001_ha, |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4147 | pm8001_printk("OPC_OUB_SATA_EVENT\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4148 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4172 | pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4173 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4185 | pm8001_mpi_general_event(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4186 | break; |
| 4187 | case OPC_OUB_SSP_ABORT_RSP: |
| 4188 | PM8001_MSG_DBG(pm8001_ha, |
| 4189 | pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n")); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4190 | pm8001_mpi_task_abort_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4191 | break; |
| 4192 | case OPC_OUB_SATA_ABORT_RSP: |
| 4193 | PM8001_MSG_DBG(pm8001_ha, |
| 4194 | pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n")); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4195 | pm8001_mpi_task_abort_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4196 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4220 | pm8001_mpi_task_abort_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4221 | break; |
| 4222 | case OPC_OUB_GET_NVMD_DATA: |
| 4223 | PM8001_MSG_DBG(pm8001_ha, |
| 4224 | pm8001_printk("OPC_OUB_GET_NVMD_DATA\n")); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4225 | pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4226 | break; |
| 4227 | case OPC_OUB_SET_NVMD_DATA: |
| 4228 | PM8001_MSG_DBG(pm8001_ha, |
| 4229 | pm8001_printk("OPC_OUB_SET_NVMD_DATA\n")); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4230 | pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4231 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4239 | pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4240 | 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 chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 4254 | PM8001_DEVIO_DBG(pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4255 | pm8001_printk("Unknown outbound Queue IOMB OPC = %x\n", |
| 4256 | opc)); |
| 4257 | break; |
| 4258 | } |
| 4259 | } |
| 4260 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4261 | static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4262 | { |
| 4263 | struct outbound_queue_table *circularQ; |
| 4264 | void *pMsg1 = NULL; |
Kees Cook | 3f649ab | 2020-06-03 13:09:38 -0700 | [diff] [blame] | 4265 | u8 bc; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4266 | u32 ret = MPI_IO_STATUS_FAIL; |
Santosh Nayak | 50ec5ba | 2012-02-26 19:05:03 +0530 | [diff] [blame] | 4267 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4268 | |
Santosh Nayak | 50ec5ba | 2012-02-26 19:05:03 +0530 | [diff] [blame] | 4269 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4270 | circularQ = &pm8001_ha->outbnd_q_tbl[vec]; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4271 | do { |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4272 | ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4273 | if (MPI_IO_STATUS_SUCCESS == ret) { |
| 4274 | /* process the outbound message */ |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4275 | process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4276 | /* free the message from the outbound circular buffer */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4277 | pm8001_mpi_msg_free_set(pm8001_ha, pMsg1, |
| 4278 | circularQ, bc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4279 | } |
| 4280 | if (MPI_IO_STATUS_BUSY == ret) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4281 | /* Update the producer index from SPC */ |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4282 | circularQ->producer_index = |
| 4283 | cpu_to_le32(pm8001_read_32(circularQ->pi_virt)); |
| 4284 | if (le32_to_cpu(circularQ->producer_index) == |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4285 | circularQ->consumer_idx) |
| 4286 | /* OQ is empty */ |
| 4287 | break; |
| 4288 | } |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4289 | } while (1); |
Santosh Nayak | 50ec5ba | 2012-02-26 19:05:03 +0530 | [diff] [blame] | 4290 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4291 | return ret; |
| 4292 | } |
| 4293 | |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4294 | /* DMA_... to our direction translation. */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4295 | static const u8 data_dir_flags[] = { |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4296 | [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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4300 | }; |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4301 | void |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4302 | pm8001_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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4316 | static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4317 | { |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4318 | psmp_cmd->tag = hTag; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4319 | 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 | */ |
| 4328 | static 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 Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4346 | elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4347 | if (!elem) |
| 4348 | return -ENOMEM; |
| 4349 | req_len = sg_dma_len(sg_req); |
| 4350 | |
| 4351 | sg_resp = &task->smp_task.smp_resp; |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4352 | elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4353 | 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 Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 4376 | rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4377 | &smp_cmd, sizeof(smp_cmd), 0); |
Tomas Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 4378 | if (rc) |
| 4379 | goto err_out_2; |
| 4380 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4381 | return 0; |
| 4382 | |
| 4383 | err_out_2: |
| 4384 | dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1, |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4385 | DMA_FROM_DEVICE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4386 | err_out: |
| 4387 | dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1, |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4388 | DMA_TO_DEVICE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4389 | 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 | */ |
| 4397 | static 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4405 | int ret; |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4406 | u64 phys_addr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4407 | 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 wang | afc5ca9 | 2009-12-07 17:22:47 +0800 | [diff] [blame] | 4411 | ssp_cmd.dir_m_tlr = |
| 4412 | cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4413 | 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 Bottomley | e73823f | 2013-05-07 15:38:18 -0700 | [diff] [blame] | 4421 | memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd, |
| 4422 | task->ssp_task.cmd->cmd_len); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4423 | 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 G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 4428 | phys_addr = ccb->ccb_dma_handle; |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4429 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4431 | ssp_cmd.esgl = cpu_to_le32(1<<31); |
| 4432 | } else if (task->num_scatter == 1) { |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4433 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4436 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4444 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd, |
| 4445 | sizeof(ssp_cmd), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4446 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | static 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4456 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4457 | struct sata_start_req sata_cmd; |
| 4458 | u32 hdr_tag, ncg_tag = 0; |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4459 | u64 phys_addr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4460 | u32 ATAP = 0x0; |
| 4461 | u32 dir; |
| 4462 | struct inbound_queue_table *circularQ; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4463 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4464 | u32 opc = OPC_INB_SATA_HOST_OPSTART; |
| 4465 | memset(&sata_cmd, 0, sizeof(sata_cmd)); |
| 4466 | circularQ = &pm8001_ha->inbnd_q_tbl[0]; |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 4467 | if (task->data_dir == DMA_NONE) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4468 | ATAP = 0x04; /* no data*/ |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4469 | PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4470 | } else if (likely(!task->ata_task.device_control_reg_update)) { |
| 4471 | if (task->ata_task.dma_xfer) { |
| 4472 | ATAP = 0x06; /* DMA */ |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4473 | PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4474 | } else { |
| 4475 | ATAP = 0x05; /* PIO*/ |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4476 | PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4477 | } |
| 4478 | if (task->ata_task.use_ncq && |
Hannes Reinecke | 1cbd772 | 2014-11-05 13:08:20 +0100 | [diff] [blame] | 4479 | dev->sata_dev.class != ATA_DEV_ATAPI) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4480 | ATAP = 0x07; /* FPDMA */ |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 4481 | PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n")); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4482 | } |
| 4483 | } |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4484 | 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 wang | afc5ca9 | 2009-12-07 17:22:47 +0800 | [diff] [blame] | 4486 | ncg_tag = hdr_tag; |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4487 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4488 | 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 G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 4501 | phys_addr = ccb->ccb_dma_handle; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4502 | 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4506 | u64 dma_addr = sg_dma_address(task->scatter); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4507 | 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 K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4517 | |
| 4518 | /* Check for read log for failed drive and return */ |
| 4519 | if (sata_cmd.sata_fis.command == 0x2f) { |
Rickard Strandqvist | d981644 | 2014-07-09 17:19:38 +0530 | [diff] [blame] | 4520 | if (((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) || |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4521 | (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 Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 4543 | } else { |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4544 | spin_unlock_irqrestore(&task->task_state_lock, |
| 4545 | flags); |
Suresh Thiagarajan | 2b01d81 | 2014-01-16 15:26:21 +0530 | [diff] [blame] | 4546 | pm8001_ccb_task_free_done(pm8001_ha, task, |
| 4547 | ccb, tag); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 4548 | return 0; |
| 4549 | } |
| 4550 | } |
| 4551 | } |
| 4552 | |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4553 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd, |
| 4554 | sizeof(sata_cmd), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4555 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | /** |
| 4559 | * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND |
| 4560 | * @pm8001_ha: our hba card information. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4561 | * @phy_id: the phy id which we wanted to start up. |
| 4562 | */ |
| 4563 | static int |
| 4564 | pm8001_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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4568 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4569 | 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 Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 4583 | payload.sas_identify.dev_type = SAS_END_DEVICE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4584 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4588 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, |
| 4589 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4590 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | /** |
| 4594 | * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND |
| 4595 | * @pm8001_ha: our hba card information. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4596 | * @phy_id: the phy id which we wanted to start up. |
| 4597 | */ |
Baoyou Xie | 7efa59e | 2016-09-23 21:54:22 +0800 | [diff] [blame] | 4598 | static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha, |
| 4599 | u8 phy_id) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4600 | { |
| 4601 | struct phy_stop_req payload; |
| 4602 | struct inbound_queue_table *circularQ; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4603 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4604 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4610 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, |
| 4611 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4612 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4613 | } |
| 4614 | |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 4615 | /* |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4616 | * see comments on pm8001_mpi_reg_resp. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4617 | */ |
| 4618 | static 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4626 | int rc, tag = 0xdeadbeef; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4627 | 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 Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 4646 | if (pm8001_dev->dev_type == SAS_SATA_DEV) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4647 | stp_sspsmp_sata = 0x00; /* stp*/ |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 4648 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4651 | stp_sspsmp_sata = 0x01; /*ssp or smp*/ |
| 4652 | } |
John Garry | 924a354 | 2019-06-10 20:41:41 +0800 | [diff] [blame] | 4653 | if (parent_dev && dev_is_expander(parent_dev->dev_type)) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4654 | 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 wang | afc5ca9 | 2009-12-07 17:22:47 +0800 | [diff] [blame] | 4668 | memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4669 | SAS_ADDR_SIZE); |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4670 | rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 4671 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4672 | return rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4673 | } |
| 4674 | |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 4675 | /* |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4676 | * see comments on pm8001_mpi_reg_resp. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4677 | */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4678 | int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4679 | u32 device_id) |
| 4680 | { |
| 4681 | struct dereg_dev_req payload; |
| 4682 | u32 opc = OPC_INB_DEREG_DEV_HANDLE; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4683 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4684 | struct inbound_queue_table *circularQ; |
| 4685 | |
| 4686 | circularQ = &pm8001_ha->inbnd_q_tbl[0]; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4687 | memset(&payload, 0, sizeof(payload)); |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4688 | payload.tag = cpu_to_le32(1); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4689 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4692 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 4693 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4694 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | /** |
| 4698 | * pm8001_chip_phy_ctl_req - support the local phy operation |
| 4699 | * @pm8001_ha: our hba card information. |
Lee Jones | 685f947 | 2020-07-21 17:41:26 +0100 | [diff] [blame] | 4700 | * @phyId: the phy id which we wanted to operate |
| 4701 | * @phy_op: the phy operation to request |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4702 | */ |
| 4703 | static 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4708 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4709 | u32 opc = OPC_INB_LOCAL_PHY_CONTROL; |
jack wang | 83e7332 | 2009-12-07 17:23:11 +0800 | [diff] [blame] | 4710 | memset(&payload, 0, sizeof(payload)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4711 | circularQ = &pm8001_ha->inbnd_q_tbl[0]; |
Santosh Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 4712 | payload.tag = cpu_to_le32(1); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4713 | payload.phyop_phyid = |
| 4714 | cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F)); |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4715 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 4716 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4717 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4718 | } |
| 4719 | |
Colin Ian King | f310a4e | 2019-03-29 23:44:23 +0000 | [diff] [blame] | 4720 | static u32 pm8001_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4721 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4722 | #ifdef PM8001_USE_MSIX |
| 4723 | return 1; |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 4724 | #else |
| 4725 | u32 value; |
| 4726 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4727 | value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR); |
| 4728 | if (value) |
| 4729 | return 1; |
| 4730 | return 0; |
Colin Ian King | 292c04c | 2019-03-28 23:43:28 +0000 | [diff] [blame] | 4731 | #endif |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | /** |
| 4735 | * pm8001_chip_isr - PM8001 isr handler. |
| 4736 | * @pm8001_ha: our hba card information. |
Lee Jones | 685f947 | 2020-07-21 17:41:26 +0100 | [diff] [blame] | 4737 | * @vec: IRQ number |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4738 | */ |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4739 | static irqreturn_t |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4740 | pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4741 | { |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4742 | pm8001_chip_interrupt_disable(pm8001_ha, vec); |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 4743 | PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk( |
| 4744 | "irq vec %d, ODMR:0x%x\n", |
| 4745 | vec, pm8001_cr32(pm8001_ha, 0, 0x30))); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4746 | process_oq(pm8001_ha, vec); |
| 4747 | pm8001_chip_interrupt_enable(pm8001_ha, vec); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4748 | return IRQ_HANDLED; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | static 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4756 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4757 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4769 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort, |
| 4770 | sizeof(task_abort), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4771 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4772 | } |
| 4773 | |
Lee Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 4774 | /* |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4775 | * pm8001_chip_abort_task - SAS abort task when error or exception happened. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4776 | */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4777 | int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4778 | 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 K | a70b8fc | 2013-03-19 18:07:09 +0530 | [diff] [blame] | 4782 | PM8001_EH_DBG(pm8001_ha, |
| 4783 | pm8001_printk("cmd_tag = %x, abort task tag = 0x%x", |
| 4784 | cmd_tag, task_tag)); |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 4785 | if (pm8001_dev->dev_type == SAS_END_DEVICE) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4786 | opc = OPC_INB_SSP_ABORT; |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 4787 | else if (pm8001_dev->dev_type == SAS_SATA_DEV) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4788 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4795 | PM8001_EH_DBG(pm8001_ha, pm8001_printk("rc= %d\n", rc)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4796 | return rc; |
| 4797 | } |
| 4798 | |
| 4799 | /** |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 4800 | * pm8001_chip_ssp_tm_req - built the task management command. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4801 | * @pm8001_ha: our hba card information. |
| 4802 | * @ccb: the ccb information. |
| 4803 | * @tmf: task management function. |
| 4804 | */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4805 | int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4806 | 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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4814 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4815 | |
| 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4820 | memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8); |
| 4821 | sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag); |
Anand Kumar Santhanam | e912457b | 2013-09-17 16:58:10 +0530 | [diff] [blame] | 4822 | if (pm8001_ha->chip_id != chip_8001) |
| 4823 | sspTMCmd.ds_ads_m = 0x08; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4824 | circularQ = &pm8001_ha->inbnd_q_tbl[0]; |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4825 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd, |
| 4826 | sizeof(sspTMCmd), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4827 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4828 | } |
| 4829 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4830 | int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4831 | void *payload) |
| 4832 | { |
| 4833 | u32 opc = OPC_INB_GET_NVMD_DATA; |
| 4834 | u32 nvmd_type; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4835 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4836 | 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 Carpenter | 0caeb91 | 2010-08-17 13:54:57 +0200 | [diff] [blame] | 4845 | if (!fw_control_context) |
| 4846 | return -ENOMEM; |
Sakthivel K | 1c75a67 | 2013-03-19 18:06:40 +0530 | [diff] [blame] | 4847 | fw_control_context->usrAddr = (u8 *)ioctl_payload->func_specific; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4848 | fw_control_context->len = ioctl_payload->rd_length; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4849 | circularQ = &pm8001_ha->inbnd_q_tbl[0]; |
| 4850 | memset(&nvmd_req, 0, sizeof(nvmd_req)); |
| 4851 | rc = pm8001_tag_alloc(pm8001_ha, &tag); |
Julia Lawall | 823d219 | 2010-08-01 19:23:35 +0200 | [diff] [blame] | 4852 | if (rc) { |
| 4853 | kfree(fw_control_context); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4854 | return rc; |
Julia Lawall | 823d219 | 2010-08-01 19:23:35 +0200 | [diff] [blame] | 4855 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4856 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4869 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4870 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4878 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4879 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4887 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4888 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4896 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4897 | 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 Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 4903 | case IOP_RDUMP: { |
| 4904 | nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | IOP_RDUMP); |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4905 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 4906 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4913 | default: |
| 4914 | break; |
| 4915 | } |
peter chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 4916 | rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req, |
| 4917 | sizeof(nvmd_req), 0); |
Tomas Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 4918 | if (rc) { |
| 4919 | kfree(fw_control_context); |
| 4920 | pm8001_tag_free(pm8001_ha, tag); |
| 4921 | } |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4922 | return rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4923 | } |
| 4924 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 4925 | int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4926 | void *payload) |
| 4927 | { |
| 4928 | u32 opc = OPC_INB_SET_NVMD_DATA; |
| 4929 | u32 nvmd_type; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 4930 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4931 | 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 Carpenter | 0caeb91 | 2010-08-17 13:54:57 +0200 | [diff] [blame] | 4940 | if (!fw_control_context) |
| 4941 | return -ENOMEM; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4942 | circularQ = &pm8001_ha->inbnd_q_tbl[0]; |
| 4943 | memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr, |
Sakthivel K | 1c75a67 | 2013-03-19 18:06:40 +0530 | [diff] [blame] | 4944 | &ioctl_payload->func_specific, |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4945 | ioctl_payload->wr_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4946 | memset(&nvmd_req, 0, sizeof(nvmd_req)); |
| 4947 | rc = pm8001_tag_alloc(pm8001_ha, &tag); |
Julia Lawall | 823d219 | 2010-08-01 19:23:35 +0200 | [diff] [blame] | 4948 | if (rc) { |
| 4949 | kfree(fw_control_context); |
Tomas Henzl | 6f8f31c | 2014-07-30 18:42:22 +0530 | [diff] [blame] | 4950 | return -EBUSY; |
Julia Lawall | 823d219 | 2010-08-01 19:23:35 +0200 | [diff] [blame] | 4951 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4952 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4964 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4965 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4973 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4974 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4982 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4983 | 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 G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 4991 | nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 4992 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 5001 | rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req, |
| 5002 | sizeof(nvmd_req), 0); |
Tomas Henzl | 9422e86 | 2014-07-07 17:20:00 +0200 | [diff] [blame] | 5003 | if (rc) { |
| 5004 | kfree(fw_control_context); |
| 5005 | pm8001_tag_free(pm8001_ha, tag); |
| 5006 | } |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5007 | return rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5008 | } |
| 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 Jones | 083645b | 2020-07-21 17:41:24 +0100 | [diff] [blame] | 5014 | * @tag: Tag to apply to the payload |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5015 | */ |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 5016 | int |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5017 | pm8001_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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5023 | int ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5024 | u32 opc = OPC_INB_FW_FLASH_UPDATE; |
| 5025 | |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5026 | memset(&payload, 0, sizeof(struct fw_flash_Update_req)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5027 | 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 Nayak | 8270ee2 | 2012-02-26 20:14:46 +0530 | [diff] [blame] | 5034 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 5038 | ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 5039 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5040 | return ret; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5041 | } |
| 5042 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 5043 | int |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5044 | pm8001_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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5050 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5051 | u32 tag; |
| 5052 | struct pm8001_ccb_info *ccb; |
Sakthivel K | 1c75a67 | 2013-03-19 18:06:40 +0530 | [diff] [blame] | 5053 | 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 wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5055 | struct pm8001_ioctl_payload *ioctl_payload = payload; |
| 5056 | |
| 5057 | fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); |
Dan Carpenter | 0caeb91 | 2010-08-17 13:54:57 +0200 | [diff] [blame] | 5058 | if (!fw_control_context) |
| 5059 | return -ENOMEM; |
Sakthivel K | 1c75a67 | 2013-03-19 18:06:40 +0530 | [diff] [blame] | 5060 | fw_control = (struct fw_control_info *)&ioctl_payload->func_specific; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 5061 | PM8001_DEVIO_DBG(pm8001_ha, pm8001_printk( |
| 5062 | "dma fw_control context input length :%x\n", fw_control->len)); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5063 | memcpy(buffer, fw_control->buffer, fw_control->len); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5064 | 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 K | 1c75a67 | 2013-03-19 18:06:40 +0530 | [diff] [blame] | 5072 | fw_control_context->phys_addr = phys_addr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5073 | fw_control_context->len = fw_control->len; |
| 5074 | rc = pm8001_tag_alloc(pm8001_ha, &tag); |
Julia Lawall | 823d219 | 2010-08-01 19:23:35 +0200 | [diff] [blame] | 5075 | if (rc) { |
| 5076 | kfree(fw_control_context); |
Tomas Henzl | 6f8f31c | 2014-07-30 18:42:22 +0530 | [diff] [blame] | 5077 | return -EBUSY; |
Julia Lawall | 823d219 | 2010-08-01 19:23:35 +0200 | [diff] [blame] | 5078 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5079 | ccb = &pm8001_ha->ccb_info[tag]; |
| 5080 | ccb->fw_control_context = fw_control_context; |
| 5081 | ccb->ccb_tag = tag; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5082 | rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info, |
| 5083 | tag); |
| 5084 | return rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5085 | } |
| 5086 | |
Anand Kumar Santhanam | d078b51 | 2013-09-04 12:57:00 +0530 | [diff] [blame] | 5087 | ssize_t |
| 5088 | pm8001_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 G | cf37006 | 2013-12-10 10:31:38 +0530 | [diff] [blame] | 5104 | return -EINVAL; |
Anand Kumar Santhanam | d078b51 | 2013-09-04 12:57:00 +0530 | [diff] [blame] | 5105 | |
| 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 G | cf37006 | 2013-12-10 10:31:38 +0530 | [diff] [blame] | 5132 | return -EIO; |
Anand Kumar Santhanam | d078b51 | 2013-09-04 12:57:00 +0530 | [diff] [blame] | 5133 | } else { |
| 5134 | gsm_base = 0; |
| 5135 | if (-1 == pm80xx_bar4_shift(pm8001_ha, |
| 5136 | (gsm_base + shift_value))) |
Viswas G | cf37006 | 2013-12-10 10:31:38 +0530 | [diff] [blame] | 5137 | return -EIO; |
Anand Kumar Santhanam | d078b51 | 2013-09-04 12:57:00 +0530 | [diff] [blame] | 5138 | } |
| 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 G | 859b5d1 | 2013-12-10 10:31:28 +0530 | [diff] [blame] | 5156 | if (-1 == pm8001_bar4_shift(pm8001_ha, 0)) |
Viswas G | cf37006 | 2013-12-10 10:31:38 +0530 | [diff] [blame] | 5157 | return -EIO; |
Anand Kumar Santhanam | d078b51 | 2013-09-04 12:57:00 +0530 | [diff] [blame] | 5158 | 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 K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 5165 | int |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5166 | pm8001_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_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5172 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5173 | u32 tag; |
| 5174 | u32 opc = OPC_INB_SET_DEVICE_STATE; |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5175 | memset(&payload, 0, sizeof(payload)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5176 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 5186 | rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 5187 | sizeof(payload), 0); |
jack_wang | 72d0baa | 2009-11-05 22:33:35 +0800 | [diff] [blame] | 5188 | return rc; |
| 5189 | |
jack_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | static int |
| 5193 | pm8001_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 Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 5204 | return -ENOMEM; |
jack_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 5205 | 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 chang | 91a43fa | 2019-11-14 15:39:05 +0530 | [diff] [blame] | 5212 | rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, |
| 5213 | sizeof(payload), 0); |
Tomas Henzl | 5533abc | 2014-07-09 17:20:49 +0530 | [diff] [blame] | 5214 | if (rc) |
| 5215 | pm8001_tag_free(pm8001_ha, tag); |
jack_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 5216 | return rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5217 | |
| 5218 | } |
| 5219 | |
| 5220 | const 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 King | f310a4e | 2019-03-29 23:44:23 +0000 | [diff] [blame] | 5227 | .is_our_interrupt = pm8001_chip_is_our_interrupt, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5228 | .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_wang | d0b6804 | 2009-11-05 22:32:31 +0800 | [diff] [blame] | 5246 | .sas_re_init_req = pm8001_chip_sas_re_initialization, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 5247 | }; |