18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2008-2009 USI Co., Ltd. 58c2ecf20Sopenharmony_ci * All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 98c2ecf20Sopenharmony_ci * are met: 108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 118c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 128c2ecf20Sopenharmony_ci * without modification. 138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer 148c2ecf20Sopenharmony_ci * substantially similar to the "NO WARRANTY" disclaimer below 158c2ecf20Sopenharmony_ci * ("Disclaimer") and any redistribution must be conditioned upon 168c2ecf20Sopenharmony_ci * including a substantially similar Disclaimer requirement for further 178c2ecf20Sopenharmony_ci * binary redistribution. 188c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names 198c2ecf20Sopenharmony_ci * of any contributors may be used to endorse or promote products derived 208c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 238c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 248c2ecf20Sopenharmony_ci * Software Foundation. 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * NO WARRANTY 278c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 288c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 298c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 308c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 318c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 328c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 338c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 348c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 358c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 368c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 378c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES. 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci #include <linux/slab.h> 418c2ecf20Sopenharmony_ci #include "pm8001_sas.h" 428c2ecf20Sopenharmony_ci #include "pm8001_hwi.h" 438c2ecf20Sopenharmony_ci #include "pm8001_chips.h" 448c2ecf20Sopenharmony_ci #include "pm8001_ctl.h" 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/** 478c2ecf20Sopenharmony_ci * read_main_config_table - read the configure table and save it. 488c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_cistatic void read_main_config_table(struct pm8001_hba_info *pm8001_ha) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->main_cfg_tbl_addr; 538c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.signature = 548c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x00); 558c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev = 568c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x04); 578c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev = 588c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x08); 598c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io = 608c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x0C); 618c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl = 628c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x10); 638c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag = 648c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x14); 658c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.gst_offset = 668c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x18); 678c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_queue_offset = 688c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_IBQ_OFFSET); 698c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_queue_offset = 708c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_OBQ_OFFSET); 718c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.hda_mode_flag = 728c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci /* read analog Setting offset from the configuration table */ 758c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.anolog_setup_table_offset = 768c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci /* read Error Dump Offset and Length */ 798c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset0 = 808c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET); 818c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length0 = 828c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH); 838c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_offset1 = 848c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET); 858c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_dump_length1 = 868c2ecf20Sopenharmony_ci pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH); 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/** 908c2ecf20Sopenharmony_ci * read_general_status_table - read the general status table and save it. 918c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_cistatic void read_general_status_table(struct pm8001_hba_info *pm8001_ha) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->general_stat_tbl_addr; 968c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.gst_len_mpistate = 978c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x00); 988c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state0 = 998c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x04); 1008c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.iq_freeze_state1 = 1018c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x08); 1028c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.msgu_tcnt = 1038c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x0C); 1048c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.iop_tcnt = 1058c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x10); 1068c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.rsvd = 1078c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x14); 1088c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[0] = 1098c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x18); 1108c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[1] = 1118c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x1C); 1128c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[2] = 1138c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x20); 1148c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[3] = 1158c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x24); 1168c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[4] = 1178c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x28); 1188c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[5] = 1198c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x2C); 1208c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[6] = 1218c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x30); 1228c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.phy_state[7] = 1238c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x34); 1248c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.gpio_input_val = 1258c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x38); 1268c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[0] = 1278c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x3C); 1288c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.rsvd1[1] = 1298c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x40); 1308c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[0] = 1318c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x44); 1328c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[1] = 1338c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x48); 1348c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[2] = 1358c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x4C); 1368c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[3] = 1378c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x50); 1388c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[4] = 1398c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x54); 1408c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[5] = 1418c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x58); 1428c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[6] = 1438c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x5C); 1448c2ecf20Sopenharmony_ci pm8001_ha->gs_tbl.pm8001_tbl.recover_err_info[7] = 1458c2ecf20Sopenharmony_ci pm8001_mr32(address, 0x60); 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/** 1498c2ecf20Sopenharmony_ci * read_inbnd_queue_table - read the inbound queue table and save it. 1508c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 1518c2ecf20Sopenharmony_ci */ 1528c2ecf20Sopenharmony_cistatic void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha) 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci int i; 1558c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->inbnd_q_tbl_addr; 1568c2ecf20Sopenharmony_ci for (i = 0; i < PM8001_MAX_INB_NUM; i++) { 1578c2ecf20Sopenharmony_ci u32 offset = i * 0x20; 1588c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].pi_pci_bar = 1598c2ecf20Sopenharmony_ci get_pci_bar_index(pm8001_mr32(address, (offset + 0x14))); 1608c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].pi_offset = 1618c2ecf20Sopenharmony_ci pm8001_mr32(address, (offset + 0x18)); 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci} 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci/** 1668c2ecf20Sopenharmony_ci * read_outbnd_queue_table - read the outbound queue table and save it. 1678c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 1688c2ecf20Sopenharmony_ci */ 1698c2ecf20Sopenharmony_cistatic void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci int i; 1728c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->outbnd_q_tbl_addr; 1738c2ecf20Sopenharmony_ci for (i = 0; i < PM8001_MAX_OUTB_NUM; i++) { 1748c2ecf20Sopenharmony_ci u32 offset = i * 0x24; 1758c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].ci_pci_bar = 1768c2ecf20Sopenharmony_ci get_pci_bar_index(pm8001_mr32(address, (offset + 0x14))); 1778c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].ci_offset = 1788c2ecf20Sopenharmony_ci pm8001_mr32(address, (offset + 0x18)); 1798c2ecf20Sopenharmony_ci } 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/** 1838c2ecf20Sopenharmony_ci * init_default_table_values - init the default table. 1848c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 1858c2ecf20Sopenharmony_ci */ 1868c2ecf20Sopenharmony_cistatic void init_default_table_values(struct pm8001_hba_info *pm8001_ha) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci int i; 1898c2ecf20Sopenharmony_ci u32 offsetib, offsetob; 1908c2ecf20Sopenharmony_ci void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr; 1918c2ecf20Sopenharmony_ci void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr; 1928c2ecf20Sopenharmony_ci u32 ib_offset = pm8001_ha->ib_offset; 1938c2ecf20Sopenharmony_ci u32 ob_offset = pm8001_ha->ob_offset; 1948c2ecf20Sopenharmony_ci u32 ci_offset = pm8001_ha->ci_offset; 1958c2ecf20Sopenharmony_ci u32 pi_offset = pm8001_ha->pi_offset; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd = 0; 1988c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3 = 0; 1998c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7 = 0; 2008c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3 = 0; 2018c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7 = 0; 2028c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid0_3 = 2038c2ecf20Sopenharmony_ci 0; 2048c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ITNexus_event_pid4_7 = 2058c2ecf20Sopenharmony_ci 0; 2068c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid0_3 = 0; 2078c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_ssp_event_pid4_7 = 0; 2088c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid0_3 = 0; 2098c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_tgt_smp_event_pid4_7 = 0; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr = 2128c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[AAP1].phys_addr_hi; 2138c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr = 2148c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[AAP1].phys_addr_lo; 2158c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size = 2168c2ecf20Sopenharmony_ci PM8001_EVENT_LOG_SIZE; 2178c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option = 0x01; 2188c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr = 2198c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[IOP].phys_addr_hi; 2208c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr = 2218c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[IOP].phys_addr_lo; 2228c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size = 2238c2ecf20Sopenharmony_ci PM8001_EVENT_LOG_SIZE; 2248c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option = 0x01; 2258c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt = 0x01; 2268c2ecf20Sopenharmony_ci for (i = 0; i < pm8001_ha->max_q_num; i++) { 2278c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt = 2288c2ecf20Sopenharmony_ci PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30); 2298c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].upper_base_addr = 2308c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_hi; 2318c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].lower_base_addr = 2328c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ib_offset + i].phys_addr_lo; 2338c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].base_virt = 2348c2ecf20Sopenharmony_ci (u8 *)pm8001_ha->memoryMap.region[ib_offset + i].virt_ptr; 2358c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].total_length = 2368c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ib_offset + i].total_len; 2378c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr = 2388c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_hi; 2398c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr = 2408c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ci_offset + i].phys_addr_lo; 2418c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].ci_virt = 2428c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ci_offset + i].virt_ptr; 2438c2ecf20Sopenharmony_ci offsetib = i * 0x20; 2448c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].pi_pci_bar = 2458c2ecf20Sopenharmony_ci get_pci_bar_index(pm8001_mr32(addressib, 2468c2ecf20Sopenharmony_ci (offsetib + 0x14))); 2478c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].pi_offset = 2488c2ecf20Sopenharmony_ci pm8001_mr32(addressib, (offsetib + 0x18)); 2498c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].producer_idx = 0; 2508c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[i].consumer_index = 0; 2518c2ecf20Sopenharmony_ci } 2528c2ecf20Sopenharmony_ci for (i = 0; i < pm8001_ha->max_q_num; i++) { 2538c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].element_size_cnt = 2548c2ecf20Sopenharmony_ci PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30); 2558c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].upper_base_addr = 2568c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_hi; 2578c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].lower_base_addr = 2588c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ob_offset + i].phys_addr_lo; 2598c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].base_virt = 2608c2ecf20Sopenharmony_ci (u8 *)pm8001_ha->memoryMap.region[ob_offset + i].virt_ptr; 2618c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].total_length = 2628c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[ob_offset + i].total_len; 2638c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr = 2648c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_hi; 2658c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr = 2668c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[pi_offset + i].phys_addr_lo; 2678c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = 2688c2ecf20Sopenharmony_ci 0 | (10 << 16) | (i << 24); 2698c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].pi_virt = 2708c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[pi_offset + i].virt_ptr; 2718c2ecf20Sopenharmony_ci offsetob = i * 0x24; 2728c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].ci_pci_bar = 2738c2ecf20Sopenharmony_ci get_pci_bar_index(pm8001_mr32(addressob, 2748c2ecf20Sopenharmony_ci offsetob + 0x14)); 2758c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].ci_offset = 2768c2ecf20Sopenharmony_ci pm8001_mr32(addressob, (offsetob + 0x18)); 2778c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0; 2788c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[i].producer_index = 0; 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci} 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/** 2838c2ecf20Sopenharmony_ci * update_main_config_table - update the main default table to the HBA. 2848c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 2858c2ecf20Sopenharmony_ci */ 2868c2ecf20Sopenharmony_cistatic void update_main_config_table(struct pm8001_hba_info *pm8001_ha) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->main_cfg_tbl_addr; 2898c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x24, 2908c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.inbound_q_nppd_hppd); 2918c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x28, 2928c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid0_3); 2938c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x2C, 2948c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_hw_event_pid4_7); 2958c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x30, 2968c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid0_3); 2978c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x34, 2988c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.outbound_ncq_event_pid4_7); 2998c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x38, 3008c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl. 3018c2ecf20Sopenharmony_ci outbound_tgt_ITNexus_event_pid0_3); 3028c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x3C, 3038c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl. 3048c2ecf20Sopenharmony_ci outbound_tgt_ITNexus_event_pid4_7); 3058c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x40, 3068c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl. 3078c2ecf20Sopenharmony_ci outbound_tgt_ssp_event_pid0_3); 3088c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x44, 3098c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl. 3108c2ecf20Sopenharmony_ci outbound_tgt_ssp_event_pid4_7); 3118c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x48, 3128c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl. 3138c2ecf20Sopenharmony_ci outbound_tgt_smp_event_pid0_3); 3148c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x4C, 3158c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl. 3168c2ecf20Sopenharmony_ci outbound_tgt_smp_event_pid4_7); 3178c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x50, 3188c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_event_log_addr); 3198c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x54, 3208c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_event_log_addr); 3218c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x58, 3228c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_size); 3238c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x5C, 3248c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.event_log_option); 3258c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x60, 3268c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.upper_iop_event_log_addr); 3278c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x64, 3288c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.lower_iop_event_log_addr); 3298c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x68, 3308c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_size); 3318c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x6C, 3328c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.iop_event_log_option); 3338c2ecf20Sopenharmony_ci pm8001_mw32(address, 0x70, 3348c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl.pm8001_tbl.fatal_err_interrupt); 3358c2ecf20Sopenharmony_ci} 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci/** 3388c2ecf20Sopenharmony_ci * update_inbnd_queue_table - update the inbound queue table to the HBA. 3398c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 3408c2ecf20Sopenharmony_ci * @number: entry in the queue 3418c2ecf20Sopenharmony_ci */ 3428c2ecf20Sopenharmony_cistatic void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha, 3438c2ecf20Sopenharmony_ci int number) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->inbnd_q_tbl_addr; 3468c2ecf20Sopenharmony_ci u16 offset = number * 0x20; 3478c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x00, 3488c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt); 3498c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x04, 3508c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[number].upper_base_addr); 3518c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x08, 3528c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[number].lower_base_addr); 3538c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x0C, 3548c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr); 3558c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x10, 3568c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr); 3578c2ecf20Sopenharmony_ci} 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci/** 3608c2ecf20Sopenharmony_ci * update_outbnd_queue_table - update the outbound queue table to the HBA. 3618c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 3628c2ecf20Sopenharmony_ci * @number: entry in the queue 3638c2ecf20Sopenharmony_ci */ 3648c2ecf20Sopenharmony_cistatic void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha, 3658c2ecf20Sopenharmony_ci int number) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci void __iomem *address = pm8001_ha->outbnd_q_tbl_addr; 3688c2ecf20Sopenharmony_ci u16 offset = number * 0x24; 3698c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x00, 3708c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[number].element_size_cnt); 3718c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x04, 3728c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[number].upper_base_addr); 3738c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x08, 3748c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[number].lower_base_addr); 3758c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x0C, 3768c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr); 3778c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x10, 3788c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr); 3798c2ecf20Sopenharmony_ci pm8001_mw32(address, offset + 0x1C, 3808c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay); 3818c2ecf20Sopenharmony_ci} 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci/** 3848c2ecf20Sopenharmony_ci * pm8001_bar4_shift - function is called to shift BAR base address 3858c2ecf20Sopenharmony_ci * @pm8001_ha : our hba card infomation 3868c2ecf20Sopenharmony_ci * @shiftValue : shifting value in memory bar. 3878c2ecf20Sopenharmony_ci */ 3888c2ecf20Sopenharmony_ciint pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue) 3898c2ecf20Sopenharmony_ci{ 3908c2ecf20Sopenharmony_ci u32 regVal; 3918c2ecf20Sopenharmony_ci unsigned long start; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci /* program the inbound AXI translation Lower Address */ 3948c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci /* confirm the setting is written */ 3978c2ecf20Sopenharmony_ci start = jiffies + HZ; /* 1 sec */ 3988c2ecf20Sopenharmony_ci do { 3998c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW); 4008c2ecf20Sopenharmony_ci } while ((regVal != shiftValue) && time_before(jiffies, start)); 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci if (regVal != shiftValue) { 4038c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 4048c2ecf20Sopenharmony_ci "TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW = 0x%x\n", 4058c2ecf20Sopenharmony_ci regVal); 4068c2ecf20Sopenharmony_ci return -1; 4078c2ecf20Sopenharmony_ci } 4088c2ecf20Sopenharmony_ci return 0; 4098c2ecf20Sopenharmony_ci} 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci/** 4128c2ecf20Sopenharmony_ci * mpi_set_phys_g3_with_ssc 4138c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 4148c2ecf20Sopenharmony_ci * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc. 4158c2ecf20Sopenharmony_ci */ 4168c2ecf20Sopenharmony_cistatic void mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha, 4178c2ecf20Sopenharmony_ci u32 SSCbit) 4188c2ecf20Sopenharmony_ci{ 4198c2ecf20Sopenharmony_ci u32 value, offset, i; 4208c2ecf20Sopenharmony_ci unsigned long flags; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci#define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000 4238c2ecf20Sopenharmony_ci#define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000 4248c2ecf20Sopenharmony_ci#define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074 4258c2ecf20Sopenharmony_ci#define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074 4268c2ecf20Sopenharmony_ci#define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12 4278c2ecf20Sopenharmony_ci#define PHY_G3_WITH_SSC_BIT_SHIFT 13 4288c2ecf20Sopenharmony_ci#define SNW3_PHY_CAPABILITIES_PARITY 31 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci /* 4318c2ecf20Sopenharmony_ci * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3) 4328c2ecf20Sopenharmony_ci * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7) 4338c2ecf20Sopenharmony_ci */ 4348c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 4358c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, 4368c2ecf20Sopenharmony_ci SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) { 4378c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 4388c2ecf20Sopenharmony_ci return; 4398c2ecf20Sopenharmony_ci } 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 4428c2ecf20Sopenharmony_ci offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i; 4438c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, offset, 0x80001501); 4448c2ecf20Sopenharmony_ci } 4458c2ecf20Sopenharmony_ci /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */ 4468c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, 4478c2ecf20Sopenharmony_ci SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) { 4488c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 4498c2ecf20Sopenharmony_ci return; 4508c2ecf20Sopenharmony_ci } 4518c2ecf20Sopenharmony_ci for (i = 4; i < 8; i++) { 4528c2ecf20Sopenharmony_ci offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4); 4538c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, offset, 0x80001501); 4548c2ecf20Sopenharmony_ci } 4558c2ecf20Sopenharmony_ci /************************************************************* 4568c2ecf20Sopenharmony_ci Change the SSC upspreading value to 0x0 so that upspreading is disabled. 4578c2ecf20Sopenharmony_ci Device MABC SMOD0 Controls 4588c2ecf20Sopenharmony_ci Address: (via MEMBASE-III): 4598c2ecf20Sopenharmony_ci Using shifted destination address 0x0_0000: with Offset 0xD8 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci 31:28 R/W Reserved Do not change 4628c2ecf20Sopenharmony_ci 27:24 R/W SAS_SMOD_SPRDUP 0000 4638c2ecf20Sopenharmony_ci 23:20 R/W SAS_SMOD_SPRDDN 0000 4648c2ecf20Sopenharmony_ci 19:0 R/W Reserved Do not change 4658c2ecf20Sopenharmony_ci Upon power-up this register will read as 0x8990c016, 4668c2ecf20Sopenharmony_ci and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000 4678c2ecf20Sopenharmony_ci so that the written value will be 0x8090c016. 4688c2ecf20Sopenharmony_ci This will ensure only down-spreading SSC is enabled on the SPC. 4698c2ecf20Sopenharmony_ci *************************************************************/ 4708c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 2, 0xd8); 4718c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016); 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci /*set the shifted destination address to 0x0 to avoid error operation */ 4748c2ecf20Sopenharmony_ci pm8001_bar4_shift(pm8001_ha, 0x0); 4758c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 4768c2ecf20Sopenharmony_ci return; 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci/** 4808c2ecf20Sopenharmony_ci * mpi_set_open_retry_interval_reg 4818c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 4828c2ecf20Sopenharmony_ci * @interval: interval time for each OPEN_REJECT (RETRY). The units are in 1us. 4838c2ecf20Sopenharmony_ci */ 4848c2ecf20Sopenharmony_cistatic void mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha, 4858c2ecf20Sopenharmony_ci u32 interval) 4868c2ecf20Sopenharmony_ci{ 4878c2ecf20Sopenharmony_ci u32 offset; 4888c2ecf20Sopenharmony_ci u32 value; 4898c2ecf20Sopenharmony_ci u32 i; 4908c2ecf20Sopenharmony_ci unsigned long flags; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci#define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000 4938c2ecf20Sopenharmony_ci#define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000 4948c2ecf20Sopenharmony_ci#define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4 4958c2ecf20Sopenharmony_ci#define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4 4968c2ecf20Sopenharmony_ci#define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci value = interval & OPEN_RETRY_INTERVAL_REG_MASK; 4998c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 5008c2ecf20Sopenharmony_ci /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/ 5018c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, 5028c2ecf20Sopenharmony_ci OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) { 5038c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 5048c2ecf20Sopenharmony_ci return; 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 5078c2ecf20Sopenharmony_ci offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i; 5088c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, offset, value); 5098c2ecf20Sopenharmony_ci } 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, 5128c2ecf20Sopenharmony_ci OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) { 5138c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 5148c2ecf20Sopenharmony_ci return; 5158c2ecf20Sopenharmony_ci } 5168c2ecf20Sopenharmony_ci for (i = 4; i < 8; i++) { 5178c2ecf20Sopenharmony_ci offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4); 5188c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, offset, value); 5198c2ecf20Sopenharmony_ci } 5208c2ecf20Sopenharmony_ci /*set the shifted destination address to 0x0 to avoid error operation */ 5218c2ecf20Sopenharmony_ci pm8001_bar4_shift(pm8001_ha, 0x0); 5228c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 5238c2ecf20Sopenharmony_ci return; 5248c2ecf20Sopenharmony_ci} 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci/** 5278c2ecf20Sopenharmony_ci * mpi_init_check - check firmware initialization status. 5288c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 5298c2ecf20Sopenharmony_ci */ 5308c2ecf20Sopenharmony_cistatic int mpi_init_check(struct pm8001_hba_info *pm8001_ha) 5318c2ecf20Sopenharmony_ci{ 5328c2ecf20Sopenharmony_ci u32 max_wait_count; 5338c2ecf20Sopenharmony_ci u32 value; 5348c2ecf20Sopenharmony_ci u32 gst_len_mpistate; 5358c2ecf20Sopenharmony_ci /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the 5368c2ecf20Sopenharmony_ci table is updated */ 5378c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE); 5388c2ecf20Sopenharmony_ci /* wait until Inbound DoorBell Clear Register toggled */ 5398c2ecf20Sopenharmony_ci max_wait_count = 1 * 1000 * 1000;/* 1 sec */ 5408c2ecf20Sopenharmony_ci do { 5418c2ecf20Sopenharmony_ci udelay(1); 5428c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET); 5438c2ecf20Sopenharmony_ci value &= SPC_MSGU_CFG_TABLE_UPDATE; 5448c2ecf20Sopenharmony_ci } while ((value != 0) && (--max_wait_count)); 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci if (!max_wait_count) 5478c2ecf20Sopenharmony_ci return -1; 5488c2ecf20Sopenharmony_ci /* check the MPI-State for initialization */ 5498c2ecf20Sopenharmony_ci gst_len_mpistate = 5508c2ecf20Sopenharmony_ci pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 5518c2ecf20Sopenharmony_ci GST_GSTLEN_MPIS_OFFSET); 5528c2ecf20Sopenharmony_ci if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK)) 5538c2ecf20Sopenharmony_ci return -1; 5548c2ecf20Sopenharmony_ci /* check MPI Initialization error */ 5558c2ecf20Sopenharmony_ci gst_len_mpistate = gst_len_mpistate >> 16; 5568c2ecf20Sopenharmony_ci if (0x0000 != gst_len_mpistate) 5578c2ecf20Sopenharmony_ci return -1; 5588c2ecf20Sopenharmony_ci return 0; 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci/** 5628c2ecf20Sopenharmony_ci * check_fw_ready - The LLDD check if the FW is ready, if not, return error. 5638c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 5648c2ecf20Sopenharmony_ci */ 5658c2ecf20Sopenharmony_cistatic int check_fw_ready(struct pm8001_hba_info *pm8001_ha) 5668c2ecf20Sopenharmony_ci{ 5678c2ecf20Sopenharmony_ci u32 value, value1; 5688c2ecf20Sopenharmony_ci u32 max_wait_count; 5698c2ecf20Sopenharmony_ci /* check error state */ 5708c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); 5718c2ecf20Sopenharmony_ci value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2); 5728c2ecf20Sopenharmony_ci /* check AAP error */ 5738c2ecf20Sopenharmony_ci if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) { 5748c2ecf20Sopenharmony_ci /* error state */ 5758c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0); 5768c2ecf20Sopenharmony_ci return -1; 5778c2ecf20Sopenharmony_ci } 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci /* check IOP error */ 5808c2ecf20Sopenharmony_ci if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) { 5818c2ecf20Sopenharmony_ci /* error state */ 5828c2ecf20Sopenharmony_ci value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3); 5838c2ecf20Sopenharmony_ci return -1; 5848c2ecf20Sopenharmony_ci } 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci /* bit 4-31 of scratch pad1 should be zeros if it is not 5878c2ecf20Sopenharmony_ci in error state*/ 5888c2ecf20Sopenharmony_ci if (value & SCRATCH_PAD1_STATE_MASK) { 5898c2ecf20Sopenharmony_ci /* error case */ 5908c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0); 5918c2ecf20Sopenharmony_ci return -1; 5928c2ecf20Sopenharmony_ci } 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci /* bit 2, 4-31 of scratch pad2 should be zeros if it is not 5958c2ecf20Sopenharmony_ci in error state */ 5968c2ecf20Sopenharmony_ci if (value1 & SCRATCH_PAD2_STATE_MASK) { 5978c2ecf20Sopenharmony_ci /* error case */ 5988c2ecf20Sopenharmony_ci return -1; 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */ 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci /* wait until scratch pad 1 and 2 registers in ready state */ 6048c2ecf20Sopenharmony_ci do { 6058c2ecf20Sopenharmony_ci udelay(1); 6068c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) 6078c2ecf20Sopenharmony_ci & SCRATCH_PAD1_RDY; 6088c2ecf20Sopenharmony_ci value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) 6098c2ecf20Sopenharmony_ci & SCRATCH_PAD2_RDY; 6108c2ecf20Sopenharmony_ci if ((--max_wait_count) == 0) 6118c2ecf20Sopenharmony_ci return -1; 6128c2ecf20Sopenharmony_ci } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY)); 6138c2ecf20Sopenharmony_ci return 0; 6148c2ecf20Sopenharmony_ci} 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_cistatic void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha) 6178c2ecf20Sopenharmony_ci{ 6188c2ecf20Sopenharmony_ci void __iomem *base_addr; 6198c2ecf20Sopenharmony_ci u32 value; 6208c2ecf20Sopenharmony_ci u32 offset; 6218c2ecf20Sopenharmony_ci u32 pcibar; 6228c2ecf20Sopenharmony_ci u32 pcilogic; 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, 0x44); 6258c2ecf20Sopenharmony_ci offset = value & 0x03FFFFFF; 6268c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 Offset: %x\n", offset); 6278c2ecf20Sopenharmony_ci pcilogic = (value & 0xFC000000) >> 26; 6288c2ecf20Sopenharmony_ci pcibar = get_pci_bar_index(pcilogic); 6298c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "Scratchpad 0 PCI BAR: %d\n", pcibar); 6308c2ecf20Sopenharmony_ci pm8001_ha->main_cfg_tbl_addr = base_addr = 6318c2ecf20Sopenharmony_ci pm8001_ha->io_mem[pcibar].memvirtaddr + offset; 6328c2ecf20Sopenharmony_ci pm8001_ha->general_stat_tbl_addr = 6338c2ecf20Sopenharmony_ci base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18); 6348c2ecf20Sopenharmony_ci pm8001_ha->inbnd_q_tbl_addr = 6358c2ecf20Sopenharmony_ci base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C); 6368c2ecf20Sopenharmony_ci pm8001_ha->outbnd_q_tbl_addr = 6378c2ecf20Sopenharmony_ci base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20); 6388c2ecf20Sopenharmony_ci} 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci/** 6418c2ecf20Sopenharmony_ci * pm8001_chip_init - the main init function that initialize whole PM8001 chip. 6428c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 6438c2ecf20Sopenharmony_ci */ 6448c2ecf20Sopenharmony_cistatic int pm8001_chip_init(struct pm8001_hba_info *pm8001_ha) 6458c2ecf20Sopenharmony_ci{ 6468c2ecf20Sopenharmony_ci u32 i = 0; 6478c2ecf20Sopenharmony_ci u16 deviceid; 6488c2ecf20Sopenharmony_ci pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid); 6498c2ecf20Sopenharmony_ci /* 8081 controllers need BAR shift to access MPI space 6508c2ecf20Sopenharmony_ci * as this is shared with BIOS data */ 6518c2ecf20Sopenharmony_ci if (deviceid == 0x8081 || deviceid == 0x0042) { 6528c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) { 6538c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 6548c2ecf20Sopenharmony_ci "Shift Bar4 to 0x%x failed\n", 6558c2ecf20Sopenharmony_ci GSM_SM_BASE); 6568c2ecf20Sopenharmony_ci return -1; 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci /* check the firmware status */ 6608c2ecf20Sopenharmony_ci if (-1 == check_fw_ready(pm8001_ha)) { 6618c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Firmware is not ready!\n"); 6628c2ecf20Sopenharmony_ci return -EBUSY; 6638c2ecf20Sopenharmony_ci } 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci /* Initialize pci space address eg: mpi offset */ 6668c2ecf20Sopenharmony_ci init_pci_device_addresses(pm8001_ha); 6678c2ecf20Sopenharmony_ci init_default_table_values(pm8001_ha); 6688c2ecf20Sopenharmony_ci read_main_config_table(pm8001_ha); 6698c2ecf20Sopenharmony_ci read_general_status_table(pm8001_ha); 6708c2ecf20Sopenharmony_ci read_inbnd_queue_table(pm8001_ha); 6718c2ecf20Sopenharmony_ci read_outbnd_queue_table(pm8001_ha); 6728c2ecf20Sopenharmony_ci /* update main config table ,inbound table and outbound table */ 6738c2ecf20Sopenharmony_ci update_main_config_table(pm8001_ha); 6748c2ecf20Sopenharmony_ci for (i = 0; i < pm8001_ha->max_q_num; i++) 6758c2ecf20Sopenharmony_ci update_inbnd_queue_table(pm8001_ha, i); 6768c2ecf20Sopenharmony_ci for (i = 0; i < pm8001_ha->max_q_num; i++) 6778c2ecf20Sopenharmony_ci update_outbnd_queue_table(pm8001_ha, i); 6788c2ecf20Sopenharmony_ci /* 8081 controller donot require these operations */ 6798c2ecf20Sopenharmony_ci if (deviceid != 0x8081 && deviceid != 0x0042) { 6808c2ecf20Sopenharmony_ci mpi_set_phys_g3_with_ssc(pm8001_ha, 0); 6818c2ecf20Sopenharmony_ci /* 7->130ms, 34->500ms, 119->1.5s */ 6828c2ecf20Sopenharmony_ci mpi_set_open_retry_interval_reg(pm8001_ha, 119); 6838c2ecf20Sopenharmony_ci } 6848c2ecf20Sopenharmony_ci /* notify firmware update finished and check initialization status */ 6858c2ecf20Sopenharmony_ci if (0 == mpi_init_check(pm8001_ha)) { 6868c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "MPI initialize successful!\n"); 6878c2ecf20Sopenharmony_ci } else 6888c2ecf20Sopenharmony_ci return -EBUSY; 6898c2ecf20Sopenharmony_ci /*This register is a 16-bit timer with a resolution of 1us. This is the 6908c2ecf20Sopenharmony_ci timer used for interrupt delay/coalescing in the PCIe Application Layer. 6918c2ecf20Sopenharmony_ci Zero is not a valid value. A value of 1 in the register will cause the 6928c2ecf20Sopenharmony_ci interrupts to be normal. A value greater than 1 will cause coalescing 6938c2ecf20Sopenharmony_ci delays.*/ 6948c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1); 6958c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0); 6968c2ecf20Sopenharmony_ci return 0; 6978c2ecf20Sopenharmony_ci} 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_cistatic int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha) 7008c2ecf20Sopenharmony_ci{ 7018c2ecf20Sopenharmony_ci u32 max_wait_count; 7028c2ecf20Sopenharmony_ci u32 value; 7038c2ecf20Sopenharmony_ci u32 gst_len_mpistate; 7048c2ecf20Sopenharmony_ci u16 deviceid; 7058c2ecf20Sopenharmony_ci pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid); 7068c2ecf20Sopenharmony_ci if (deviceid == 0x8081 || deviceid == 0x0042) { 7078c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_SM_BASE)) { 7088c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 7098c2ecf20Sopenharmony_ci "Shift Bar4 to 0x%x failed\n", 7108c2ecf20Sopenharmony_ci GSM_SM_BASE); 7118c2ecf20Sopenharmony_ci return -1; 7128c2ecf20Sopenharmony_ci } 7138c2ecf20Sopenharmony_ci } 7148c2ecf20Sopenharmony_ci init_pci_device_addresses(pm8001_ha); 7158c2ecf20Sopenharmony_ci /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the 7168c2ecf20Sopenharmony_ci table is stop */ 7178c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET); 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci /* wait until Inbound DoorBell Clear Register toggled */ 7208c2ecf20Sopenharmony_ci max_wait_count = 1 * 1000 * 1000;/* 1 sec */ 7218c2ecf20Sopenharmony_ci do { 7228c2ecf20Sopenharmony_ci udelay(1); 7238c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET); 7248c2ecf20Sopenharmony_ci value &= SPC_MSGU_CFG_TABLE_RESET; 7258c2ecf20Sopenharmony_ci } while ((value != 0) && (--max_wait_count)); 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci if (!max_wait_count) { 7288c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:IBDB value/=0x%x\n", 7298c2ecf20Sopenharmony_ci value); 7308c2ecf20Sopenharmony_ci return -1; 7318c2ecf20Sopenharmony_ci } 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci /* check the MPI-State for termination in progress */ 7348c2ecf20Sopenharmony_ci /* wait until Inbound DoorBell Clear Register toggled */ 7358c2ecf20Sopenharmony_ci max_wait_count = 1 * 1000 * 1000; /* 1 sec */ 7368c2ecf20Sopenharmony_ci do { 7378c2ecf20Sopenharmony_ci udelay(1); 7388c2ecf20Sopenharmony_ci gst_len_mpistate = 7398c2ecf20Sopenharmony_ci pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 7408c2ecf20Sopenharmony_ci GST_GSTLEN_MPIS_OFFSET); 7418c2ecf20Sopenharmony_ci if (GST_MPI_STATE_UNINIT == 7428c2ecf20Sopenharmony_ci (gst_len_mpistate & GST_MPI_STATE_MASK)) 7438c2ecf20Sopenharmony_ci break; 7448c2ecf20Sopenharmony_ci } while (--max_wait_count); 7458c2ecf20Sopenharmony_ci if (!max_wait_count) { 7468c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, " TIME OUT MPI State = 0x%x\n", 7478c2ecf20Sopenharmony_ci gst_len_mpistate & GST_MPI_STATE_MASK); 7488c2ecf20Sopenharmony_ci return -1; 7498c2ecf20Sopenharmony_ci } 7508c2ecf20Sopenharmony_ci return 0; 7518c2ecf20Sopenharmony_ci} 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci/** 7548c2ecf20Sopenharmony_ci * soft_reset_ready_check - Function to check FW is ready for soft reset. 7558c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 7568c2ecf20Sopenharmony_ci */ 7578c2ecf20Sopenharmony_cistatic u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha) 7588c2ecf20Sopenharmony_ci{ 7598c2ecf20Sopenharmony_ci u32 regVal, regVal1, regVal2; 7608c2ecf20Sopenharmony_ci if (mpi_uninit_check(pm8001_ha) != 0) { 7618c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "MPI state is not ready\n"); 7628c2ecf20Sopenharmony_ci return -1; 7638c2ecf20Sopenharmony_ci } 7648c2ecf20Sopenharmony_ci /* read the scratch pad 2 register bit 2 */ 7658c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) 7668c2ecf20Sopenharmony_ci & SCRATCH_PAD2_FWRDY_RST; 7678c2ecf20Sopenharmony_ci if (regVal == SCRATCH_PAD2_FWRDY_RST) { 7688c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "Firmware is ready for reset.\n"); 7698c2ecf20Sopenharmony_ci } else { 7708c2ecf20Sopenharmony_ci unsigned long flags; 7718c2ecf20Sopenharmony_ci /* Trigger NMI twice via RB6 */ 7728c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 7738c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) { 7748c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 7758c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 7768c2ecf20Sopenharmony_ci "Shift Bar4 to 0x%x failed\n", 7778c2ecf20Sopenharmony_ci RB6_ACCESS_REG); 7788c2ecf20Sopenharmony_ci return -1; 7798c2ecf20Sopenharmony_ci } 7808c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, 7818c2ecf20Sopenharmony_ci RB6_MAGIC_NUMBER_RST); 7828c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST); 7838c2ecf20Sopenharmony_ci /* wait for 100 ms */ 7848c2ecf20Sopenharmony_ci mdelay(100); 7858c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) & 7868c2ecf20Sopenharmony_ci SCRATCH_PAD2_FWRDY_RST; 7878c2ecf20Sopenharmony_ci if (regVal != SCRATCH_PAD2_FWRDY_RST) { 7888c2ecf20Sopenharmony_ci regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); 7898c2ecf20Sopenharmony_ci regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2); 7908c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT:MSGU_SCRATCH_PAD1=0x%x, MSGU_SCRATCH_PAD2=0x%x\n", 7918c2ecf20Sopenharmony_ci regVal1, regVal2); 7928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 7938c2ecf20Sopenharmony_ci "SCRATCH_PAD0 value = 0x%x\n", 7948c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0)); 7958c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 7968c2ecf20Sopenharmony_ci "SCRATCH_PAD3 value = 0x%x\n", 7978c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3)); 7988c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 7998c2ecf20Sopenharmony_ci return -1; 8008c2ecf20Sopenharmony_ci } 8018c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 8028c2ecf20Sopenharmony_ci } 8038c2ecf20Sopenharmony_ci return 0; 8048c2ecf20Sopenharmony_ci} 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci/** 8078c2ecf20Sopenharmony_ci * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all 8088c2ecf20Sopenharmony_ci * the FW register status to the originated status. 8098c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 8108c2ecf20Sopenharmony_ci */ 8118c2ecf20Sopenharmony_cistatic int 8128c2ecf20Sopenharmony_cipm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha) 8138c2ecf20Sopenharmony_ci{ 8148c2ecf20Sopenharmony_ci u32 regVal, toggleVal; 8158c2ecf20Sopenharmony_ci u32 max_wait_count; 8168c2ecf20Sopenharmony_ci u32 regVal1, regVal2, regVal3; 8178c2ecf20Sopenharmony_ci u32 signature = 0x252acbcd; /* for host scratch pad0 */ 8188c2ecf20Sopenharmony_ci unsigned long flags; 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci /* step1: Check FW is ready for soft reset */ 8218c2ecf20Sopenharmony_ci if (soft_reset_ready_check(pm8001_ha) != 0) { 8228c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "FW is not ready\n"); 8238c2ecf20Sopenharmony_ci return -1; 8248c2ecf20Sopenharmony_ci } 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci /* step 2: clear NMI status register on AAP1 and IOP, write the same 8278c2ecf20Sopenharmony_ci value to clear */ 8288c2ecf20Sopenharmony_ci /* map 0x60000 to BAR4(0x20), BAR2(win) */ 8298c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 8308c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) { 8318c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 8328c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n", 8338c2ecf20Sopenharmony_ci MBIC_AAP1_ADDR_BASE); 8348c2ecf20Sopenharmony_ci return -1; 8358c2ecf20Sopenharmony_ci } 8368c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP); 8378c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (IOP)= 0x%x\n", 8388c2ecf20Sopenharmony_ci regVal); 8398c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0); 8408c2ecf20Sopenharmony_ci /* map 0x70000 to BAR4(0x20), BAR2(win) */ 8418c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) { 8428c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 8438c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n", 8448c2ecf20Sopenharmony_ci MBIC_IOP_ADDR_BASE); 8458c2ecf20Sopenharmony_ci return -1; 8468c2ecf20Sopenharmony_ci } 8478c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1); 8488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n", 8498c2ecf20Sopenharmony_ci regVal); 8508c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE); 8538c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "PCIE -Event Interrupt Enable = 0x%x\n", 8548c2ecf20Sopenharmony_ci regVal); 8558c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0); 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT); 8588c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "PCIE - Event Interrupt = 0x%x\n", 8598c2ecf20Sopenharmony_ci regVal); 8608c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal); 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE); 8638c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "PCIE -Error Interrupt Enable = 0x%x\n", 8648c2ecf20Sopenharmony_ci regVal); 8658c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0); 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT); 8688c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "PCIE - Error Interrupt = 0x%x\n", regVal); 8698c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal); 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci /* read the scratch pad 1 register bit 2 */ 8728c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) 8738c2ecf20Sopenharmony_ci & SCRATCH_PAD1_RST; 8748c2ecf20Sopenharmony_ci toggleVal = regVal ^ SCRATCH_PAD1_RST; 8758c2ecf20Sopenharmony_ci 8768c2ecf20Sopenharmony_ci /* set signature in host scratch pad0 register to tell SPC that the 8778c2ecf20Sopenharmony_ci host performs the soft reset */ 8788c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature); 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci /* read required registers for confirmming */ 8818c2ecf20Sopenharmony_ci /* map 0x0700000 to BAR4(0x20), BAR2(win) */ 8828c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) { 8838c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 8848c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n", 8858c2ecf20Sopenharmony_ci GSM_ADDR_BASE); 8868c2ecf20Sopenharmony_ci return -1; 8878c2ecf20Sopenharmony_ci } 8888c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 8898c2ecf20Sopenharmony_ci "GSM 0x0(0x00007b88)-GSM Configuration and Reset = 0x%x\n", 8908c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci /* step 3: host read GSM Configuration and Reset register */ 8938c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET); 8948c2ecf20Sopenharmony_ci /* Put those bits to low */ 8958c2ecf20Sopenharmony_ci /* GSM XCBI offset = 0x70 0000 8968c2ecf20Sopenharmony_ci 0x00 Bit 13 COM_SLV_SW_RSTB 1 8978c2ecf20Sopenharmony_ci 0x00 Bit 12 QSSP_SW_RSTB 1 8988c2ecf20Sopenharmony_ci 0x00 Bit 11 RAAE_SW_RSTB 1 8998c2ecf20Sopenharmony_ci 0x00 Bit 9 RB_1_SW_RSTB 1 9008c2ecf20Sopenharmony_ci 0x00 Bit 8 SM_SW_RSTB 1 9018c2ecf20Sopenharmony_ci */ 9028c2ecf20Sopenharmony_ci regVal &= ~(0x00003b00); 9038c2ecf20Sopenharmony_ci /* host write GSM Configuration and Reset register */ 9048c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal); 9058c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9068c2ecf20Sopenharmony_ci "GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM Configuration and Reset is set to = 0x%x\n", 9078c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)); 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci /* step 4: */ 9108c2ecf20Sopenharmony_ci /* disable GSM - Read Address Parity Check */ 9118c2ecf20Sopenharmony_ci regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK); 9128c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9138c2ecf20Sopenharmony_ci "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n", 9148c2ecf20Sopenharmony_ci regVal1); 9158c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0); 9168c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9178c2ecf20Sopenharmony_ci "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n", 9188c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)); 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci /* disable GSM - Write Address Parity Check */ 9218c2ecf20Sopenharmony_ci regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK); 9228c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9238c2ecf20Sopenharmony_ci "GSM 0x700040 - Write Address Parity Check Enable = 0x%x\n", 9248c2ecf20Sopenharmony_ci regVal2); 9258c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0); 9268c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9278c2ecf20Sopenharmony_ci "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n", 9288c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)); 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci /* disable GSM - Write Data Parity Check */ 9318c2ecf20Sopenharmony_ci regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK); 9328c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "GSM 0x300048 - Write Data Parity Check Enable = 0x%x\n", 9338c2ecf20Sopenharmony_ci regVal3); 9348c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0); 9358c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9368c2ecf20Sopenharmony_ci "GSM 0x300048 - Write Data Parity Check Enable is set to = 0x%x\n", 9378c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)); 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci /* step 5: delay 10 usec */ 9408c2ecf20Sopenharmony_ci udelay(10); 9418c2ecf20Sopenharmony_ci /* step 5-b: set GPIO-0 output control to tristate anyway */ 9428c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) { 9438c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 9448c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "Shift Bar4 to 0x%x failed\n", 9458c2ecf20Sopenharmony_ci GPIO_ADDR_BASE); 9468c2ecf20Sopenharmony_ci return -1; 9478c2ecf20Sopenharmony_ci } 9488c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET); 9498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "GPIO Output Control Register: = 0x%x\n", 9508c2ecf20Sopenharmony_ci regVal); 9518c2ecf20Sopenharmony_ci /* set GPIO-0 output control to tri-state */ 9528c2ecf20Sopenharmony_ci regVal &= 0xFFFFFFFC; 9538c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal); 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci /* Step 6: Reset the IOP and AAP1 */ 9568c2ecf20Sopenharmony_ci /* map 0x00000 to BAR4(0x20), BAR2(win) */ 9578c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) { 9588c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 9598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n", 9608c2ecf20Sopenharmony_ci SPC_TOP_LEVEL_ADDR_BASE); 9618c2ecf20Sopenharmony_ci return -1; 9628c2ecf20Sopenharmony_ci } 9638c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); 9648c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting IOP/AAP1:= 0x%x\n", 9658c2ecf20Sopenharmony_ci regVal); 9668c2ecf20Sopenharmony_ci regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS); 9678c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci /* step 7: Reset the BDMA/OSSP */ 9708c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); 9718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "Top Register before resetting BDMA/OSSP: = 0x%x\n", 9728c2ecf20Sopenharmony_ci regVal); 9738c2ecf20Sopenharmony_ci regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP); 9748c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci /* step 8: delay 10 usec */ 9778c2ecf20Sopenharmony_ci udelay(10); 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci /* step 9: bring the BDMA and OSSP out of reset */ 9808c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); 9818c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9828c2ecf20Sopenharmony_ci "Top Register before bringing up BDMA/OSSP:= 0x%x\n", 9838c2ecf20Sopenharmony_ci regVal); 9848c2ecf20Sopenharmony_ci regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP); 9858c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci /* step 10: delay 10 usec */ 9888c2ecf20Sopenharmony_ci udelay(10); 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci /* step 11: reads and sets the GSM Configuration and Reset Register */ 9918c2ecf20Sopenharmony_ci /* map 0x0700000 to BAR4(0x20), BAR2(win) */ 9928c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) { 9938c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 9948c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "SPC Shift Bar4 to 0x%x failed\n", 9958c2ecf20Sopenharmony_ci GSM_ADDR_BASE); 9968c2ecf20Sopenharmony_ci return -1; 9978c2ecf20Sopenharmony_ci } 9988c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 9998c2ecf20Sopenharmony_ci "GSM 0x0 (0x00007b88)-GSM Configuration and Reset = 0x%x\n", 10008c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)); 10018c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET); 10028c2ecf20Sopenharmony_ci /* Put those bits to high */ 10038c2ecf20Sopenharmony_ci /* GSM XCBI offset = 0x70 0000 10048c2ecf20Sopenharmony_ci 0x00 Bit 13 COM_SLV_SW_RSTB 1 10058c2ecf20Sopenharmony_ci 0x00 Bit 12 QSSP_SW_RSTB 1 10068c2ecf20Sopenharmony_ci 0x00 Bit 11 RAAE_SW_RSTB 1 10078c2ecf20Sopenharmony_ci 0x00 Bit 9 RB_1_SW_RSTB 1 10088c2ecf20Sopenharmony_ci 0x00 Bit 8 SM_SW_RSTB 1 10098c2ecf20Sopenharmony_ci */ 10108c2ecf20Sopenharmony_ci regVal |= (GSM_CONFIG_RESET_VALUE); 10118c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal); 10128c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "GSM (0x00004088 ==> 0x00007b88) - GSM Configuration and Reset is set to = 0x%x\n", 10138c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)); 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci /* step 12: Restore GSM - Read Address Parity Check */ 10168c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK); 10178c2ecf20Sopenharmony_ci /* just for debugging */ 10188c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 10198c2ecf20Sopenharmony_ci "GSM 0x700038 - Read Address Parity Check Enable = 0x%x\n", 10208c2ecf20Sopenharmony_ci regVal); 10218c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1); 10228c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "GSM 0x700038 - Read Address Parity Check Enable is set to = 0x%x\n", 10238c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)); 10248c2ecf20Sopenharmony_ci /* Restore GSM - Write Address Parity Check */ 10258c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK); 10268c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2); 10278c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 10288c2ecf20Sopenharmony_ci "GSM 0x700040 - Write Address Parity Check Enable is set to = 0x%x\n", 10298c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)); 10308c2ecf20Sopenharmony_ci /* Restore GSM - Write Data Parity Check */ 10318c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK); 10328c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3); 10338c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 10348c2ecf20Sopenharmony_ci "GSM 0x700048 - Write Data Parity Check Enableis set to = 0x%x\n", 10358c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)); 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci /* step 13: bring the IOP and AAP1 out of reset */ 10388c2ecf20Sopenharmony_ci /* map 0x00000 to BAR4(0x20), BAR2(win) */ 10398c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) { 10408c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 10418c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Shift Bar4 to 0x%x failed\n", 10428c2ecf20Sopenharmony_ci SPC_TOP_LEVEL_ADDR_BASE); 10438c2ecf20Sopenharmony_ci return -1; 10448c2ecf20Sopenharmony_ci } 10458c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); 10468c2ecf20Sopenharmony_ci regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS); 10478c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci /* step 14: delay 10 usec - Normal Mode */ 10508c2ecf20Sopenharmony_ci udelay(10); 10518c2ecf20Sopenharmony_ci /* check Soft Reset Normal mode or Soft Reset HDA mode */ 10528c2ecf20Sopenharmony_ci if (signature == SPC_SOFT_RESET_SIGNATURE) { 10538c2ecf20Sopenharmony_ci /* step 15 (Normal Mode): wait until scratch pad1 register 10548c2ecf20Sopenharmony_ci bit 2 toggled */ 10558c2ecf20Sopenharmony_ci max_wait_count = 2 * 1000 * 1000;/* 2 sec */ 10568c2ecf20Sopenharmony_ci do { 10578c2ecf20Sopenharmony_ci udelay(1); 10588c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) & 10598c2ecf20Sopenharmony_ci SCRATCH_PAD1_RST; 10608c2ecf20Sopenharmony_ci } while ((regVal != toggleVal) && (--max_wait_count)); 10618c2ecf20Sopenharmony_ci 10628c2ecf20Sopenharmony_ci if (!max_wait_count) { 10638c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, 10648c2ecf20Sopenharmony_ci MSGU_SCRATCH_PAD_1); 10658c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "TIMEOUT : ToggleVal 0x%x,MSGU_SCRATCH_PAD1 = 0x%x\n", 10668c2ecf20Sopenharmony_ci toggleVal, regVal); 10678c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 10688c2ecf20Sopenharmony_ci "SCRATCH_PAD0 value = 0x%x\n", 10698c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, 10708c2ecf20Sopenharmony_ci MSGU_SCRATCH_PAD_0)); 10718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 10728c2ecf20Sopenharmony_ci "SCRATCH_PAD2 value = 0x%x\n", 10738c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, 10748c2ecf20Sopenharmony_ci MSGU_SCRATCH_PAD_2)); 10758c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 10768c2ecf20Sopenharmony_ci "SCRATCH_PAD3 value = 0x%x\n", 10778c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, 10788c2ecf20Sopenharmony_ci MSGU_SCRATCH_PAD_3)); 10798c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 10808c2ecf20Sopenharmony_ci return -1; 10818c2ecf20Sopenharmony_ci } 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci /* step 16 (Normal) - Clear ODMR and ODCR */ 10848c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL); 10858c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL); 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci /* step 17 (Normal Mode): wait for the FW and IOP to get 10888c2ecf20Sopenharmony_ci ready - 1 sec timeout */ 10898c2ecf20Sopenharmony_ci /* Wait for the SPC Configuration Table to be ready */ 10908c2ecf20Sopenharmony_ci if (check_fw_ready(pm8001_ha) == -1) { 10918c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); 10928c2ecf20Sopenharmony_ci /* return error if MPI Configuration Table not ready */ 10938c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 10948c2ecf20Sopenharmony_ci "FW not ready SCRATCH_PAD1 = 0x%x\n", 10958c2ecf20Sopenharmony_ci regVal); 10968c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2); 10978c2ecf20Sopenharmony_ci /* return error if MPI Configuration Table not ready */ 10988c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 10998c2ecf20Sopenharmony_ci "FW not ready SCRATCH_PAD2 = 0x%x\n", 11008c2ecf20Sopenharmony_ci regVal); 11018c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 11028c2ecf20Sopenharmony_ci "SCRATCH_PAD0 value = 0x%x\n", 11038c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, 11048c2ecf20Sopenharmony_ci MSGU_SCRATCH_PAD_0)); 11058c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, 11068c2ecf20Sopenharmony_ci "SCRATCH_PAD3 value = 0x%x\n", 11078c2ecf20Sopenharmony_ci pm8001_cr32(pm8001_ha, 0, 11088c2ecf20Sopenharmony_ci MSGU_SCRATCH_PAD_3)); 11098c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 11108c2ecf20Sopenharmony_ci return -1; 11118c2ecf20Sopenharmony_ci } 11128c2ecf20Sopenharmony_ci } 11138c2ecf20Sopenharmony_ci pm8001_bar4_shift(pm8001_ha, 0); 11148c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "SPC soft reset Complete\n"); 11178c2ecf20Sopenharmony_ci return 0; 11188c2ecf20Sopenharmony_ci} 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_cistatic void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha) 11218c2ecf20Sopenharmony_ci{ 11228c2ecf20Sopenharmony_ci u32 i; 11238c2ecf20Sopenharmony_ci u32 regVal; 11248c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "chip reset start\n"); 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci /* do SPC chip reset. */ 11278c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET); 11288c2ecf20Sopenharmony_ci regVal &= ~(SPC_REG_RESET_DEVICE); 11298c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal); 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci /* delay 10 usec */ 11328c2ecf20Sopenharmony_ci udelay(10); 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci /* bring chip reset out of reset */ 11358c2ecf20Sopenharmony_ci regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET); 11368c2ecf20Sopenharmony_ci regVal |= SPC_REG_RESET_DEVICE; 11378c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal); 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci /* delay 10 usec */ 11408c2ecf20Sopenharmony_ci udelay(10); 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci /* wait for 20 msec until the firmware gets reloaded */ 11438c2ecf20Sopenharmony_ci i = 20; 11448c2ecf20Sopenharmony_ci do { 11458c2ecf20Sopenharmony_ci mdelay(1); 11468c2ecf20Sopenharmony_ci } while ((--i) != 0); 11478c2ecf20Sopenharmony_ci 11488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, INIT, "chip reset finished\n"); 11498c2ecf20Sopenharmony_ci} 11508c2ecf20Sopenharmony_ci 11518c2ecf20Sopenharmony_ci/** 11528c2ecf20Sopenharmony_ci * pm8001_chip_iounmap - which maped when initialized. 11538c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 11548c2ecf20Sopenharmony_ci */ 11558c2ecf20Sopenharmony_civoid pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha) 11568c2ecf20Sopenharmony_ci{ 11578c2ecf20Sopenharmony_ci s8 bar, logical = 0; 11588c2ecf20Sopenharmony_ci for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { 11598c2ecf20Sopenharmony_ci /* 11608c2ecf20Sopenharmony_ci ** logical BARs for SPC: 11618c2ecf20Sopenharmony_ci ** bar 0 and 1 - logical BAR0 11628c2ecf20Sopenharmony_ci ** bar 2 and 3 - logical BAR1 11638c2ecf20Sopenharmony_ci ** bar4 - logical BAR2 11648c2ecf20Sopenharmony_ci ** bar5 - logical BAR3 11658c2ecf20Sopenharmony_ci ** Skip the appropriate assignments: 11668c2ecf20Sopenharmony_ci */ 11678c2ecf20Sopenharmony_ci if ((bar == 1) || (bar == 3)) 11688c2ecf20Sopenharmony_ci continue; 11698c2ecf20Sopenharmony_ci if (pm8001_ha->io_mem[logical].memvirtaddr) { 11708c2ecf20Sopenharmony_ci iounmap(pm8001_ha->io_mem[logical].memvirtaddr); 11718c2ecf20Sopenharmony_ci logical++; 11728c2ecf20Sopenharmony_ci } 11738c2ecf20Sopenharmony_ci } 11748c2ecf20Sopenharmony_ci} 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci#ifndef PM8001_USE_MSIX 11778c2ecf20Sopenharmony_ci/** 11788c2ecf20Sopenharmony_ci * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt 11798c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 11808c2ecf20Sopenharmony_ci */ 11818c2ecf20Sopenharmony_cistatic void 11828c2ecf20Sopenharmony_cipm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha) 11838c2ecf20Sopenharmony_ci{ 11848c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL); 11858c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL); 11868c2ecf20Sopenharmony_ci} 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci /** 11898c2ecf20Sopenharmony_ci * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt 11908c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 11918c2ecf20Sopenharmony_ci */ 11928c2ecf20Sopenharmony_cistatic void 11938c2ecf20Sopenharmony_cipm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha) 11948c2ecf20Sopenharmony_ci{ 11958c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL); 11968c2ecf20Sopenharmony_ci} 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci#else 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci/** 12018c2ecf20Sopenharmony_ci * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt 12028c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 12038c2ecf20Sopenharmony_ci * @int_vec_idx: interrupt number to enable 12048c2ecf20Sopenharmony_ci */ 12058c2ecf20Sopenharmony_cistatic void 12068c2ecf20Sopenharmony_cipm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha, 12078c2ecf20Sopenharmony_ci u32 int_vec_idx) 12088c2ecf20Sopenharmony_ci{ 12098c2ecf20Sopenharmony_ci u32 msi_index; 12108c2ecf20Sopenharmony_ci u32 value; 12118c2ecf20Sopenharmony_ci msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE; 12128c2ecf20Sopenharmony_ci msi_index += MSIX_TABLE_BASE; 12138c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE); 12148c2ecf20Sopenharmony_ci value = (1 << int_vec_idx); 12158c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value); 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_ci} 12188c2ecf20Sopenharmony_ci 12198c2ecf20Sopenharmony_ci/** 12208c2ecf20Sopenharmony_ci * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt 12218c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 12228c2ecf20Sopenharmony_ci * @int_vec_idx: interrupt number to disable 12238c2ecf20Sopenharmony_ci */ 12248c2ecf20Sopenharmony_cistatic void 12258c2ecf20Sopenharmony_cipm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha, 12268c2ecf20Sopenharmony_ci u32 int_vec_idx) 12278c2ecf20Sopenharmony_ci{ 12288c2ecf20Sopenharmony_ci u32 msi_index; 12298c2ecf20Sopenharmony_ci msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE; 12308c2ecf20Sopenharmony_ci msi_index += MSIX_TABLE_BASE; 12318c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE); 12328c2ecf20Sopenharmony_ci} 12338c2ecf20Sopenharmony_ci#endif 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_ci/** 12368c2ecf20Sopenharmony_ci * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt 12378c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 12388c2ecf20Sopenharmony_ci * @vec: unused 12398c2ecf20Sopenharmony_ci */ 12408c2ecf20Sopenharmony_cistatic void 12418c2ecf20Sopenharmony_cipm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec) 12428c2ecf20Sopenharmony_ci{ 12438c2ecf20Sopenharmony_ci#ifdef PM8001_USE_MSIX 12448c2ecf20Sopenharmony_ci pm8001_chip_msix_interrupt_enable(pm8001_ha, 0); 12458c2ecf20Sopenharmony_ci#else 12468c2ecf20Sopenharmony_ci pm8001_chip_intx_interrupt_enable(pm8001_ha); 12478c2ecf20Sopenharmony_ci#endif 12488c2ecf20Sopenharmony_ci} 12498c2ecf20Sopenharmony_ci 12508c2ecf20Sopenharmony_ci/** 12518c2ecf20Sopenharmony_ci * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt 12528c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 12538c2ecf20Sopenharmony_ci * @vec: unused 12548c2ecf20Sopenharmony_ci */ 12558c2ecf20Sopenharmony_cistatic void 12568c2ecf20Sopenharmony_cipm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec) 12578c2ecf20Sopenharmony_ci{ 12588c2ecf20Sopenharmony_ci#ifdef PM8001_USE_MSIX 12598c2ecf20Sopenharmony_ci pm8001_chip_msix_interrupt_disable(pm8001_ha, 0); 12608c2ecf20Sopenharmony_ci#else 12618c2ecf20Sopenharmony_ci pm8001_chip_intx_interrupt_disable(pm8001_ha); 12628c2ecf20Sopenharmony_ci#endif 12638c2ecf20Sopenharmony_ci} 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_ci/** 12668c2ecf20Sopenharmony_ci * pm8001_mpi_msg_free_get - get the free message buffer for transfer 12678c2ecf20Sopenharmony_ci * inbound queue. 12688c2ecf20Sopenharmony_ci * @circularQ: the inbound queue we want to transfer to HBA. 12698c2ecf20Sopenharmony_ci * @messageSize: the message size of this transfer, normally it is 64 bytes 12708c2ecf20Sopenharmony_ci * @messagePtr: the pointer to message. 12718c2ecf20Sopenharmony_ci */ 12728c2ecf20Sopenharmony_ciint pm8001_mpi_msg_free_get(struct inbound_queue_table *circularQ, 12738c2ecf20Sopenharmony_ci u16 messageSize, void **messagePtr) 12748c2ecf20Sopenharmony_ci{ 12758c2ecf20Sopenharmony_ci u32 offset, consumer_index; 12768c2ecf20Sopenharmony_ci struct mpi_msg_hdr *msgHeader; 12778c2ecf20Sopenharmony_ci u8 bcCount = 1; /* only support single buffer */ 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_ci /* Checks is the requested message size can be allocated in this queue*/ 12808c2ecf20Sopenharmony_ci if (messageSize > IOMB_SIZE_SPCV) { 12818c2ecf20Sopenharmony_ci *messagePtr = NULL; 12828c2ecf20Sopenharmony_ci return -1; 12838c2ecf20Sopenharmony_ci } 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci /* Stores the new consumer index */ 12868c2ecf20Sopenharmony_ci consumer_index = pm8001_read_32(circularQ->ci_virt); 12878c2ecf20Sopenharmony_ci circularQ->consumer_index = cpu_to_le32(consumer_index); 12888c2ecf20Sopenharmony_ci if (((circularQ->producer_idx + bcCount) % PM8001_MPI_QUEUE) == 12898c2ecf20Sopenharmony_ci le32_to_cpu(circularQ->consumer_index)) { 12908c2ecf20Sopenharmony_ci *messagePtr = NULL; 12918c2ecf20Sopenharmony_ci return -1; 12928c2ecf20Sopenharmony_ci } 12938c2ecf20Sopenharmony_ci /* get memory IOMB buffer address */ 12948c2ecf20Sopenharmony_ci offset = circularQ->producer_idx * messageSize; 12958c2ecf20Sopenharmony_ci /* increment to next bcCount element */ 12968c2ecf20Sopenharmony_ci circularQ->producer_idx = (circularQ->producer_idx + bcCount) 12978c2ecf20Sopenharmony_ci % PM8001_MPI_QUEUE; 12988c2ecf20Sopenharmony_ci /* Adds that distance to the base of the region virtual address plus 12998c2ecf20Sopenharmony_ci the message header size*/ 13008c2ecf20Sopenharmony_ci msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset); 13018c2ecf20Sopenharmony_ci *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr); 13028c2ecf20Sopenharmony_ci return 0; 13038c2ecf20Sopenharmony_ci} 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci/** 13068c2ecf20Sopenharmony_ci * pm8001_mpi_build_cmd- build the message queue for transfer, update the PI to 13078c2ecf20Sopenharmony_ci * FW to tell the fw to get this message from IOMB. 13088c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 13098c2ecf20Sopenharmony_ci * @circularQ: the inbound queue we want to transfer to HBA. 13108c2ecf20Sopenharmony_ci * @opCode: the operation code represents commands which LLDD and fw recognized. 13118c2ecf20Sopenharmony_ci * @payload: the command payload of each operation command. 13128c2ecf20Sopenharmony_ci * @nb: size in bytes of the command payload 13138c2ecf20Sopenharmony_ci * @responseQueue: queue to interrupt on w/ command response (if any) 13148c2ecf20Sopenharmony_ci */ 13158c2ecf20Sopenharmony_ciint pm8001_mpi_build_cmd(struct pm8001_hba_info *pm8001_ha, 13168c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ, 13178c2ecf20Sopenharmony_ci u32 opCode, void *payload, size_t nb, 13188c2ecf20Sopenharmony_ci u32 responseQueue) 13198c2ecf20Sopenharmony_ci{ 13208c2ecf20Sopenharmony_ci u32 Header = 0, hpriority = 0, bc = 1, category = 0x02; 13218c2ecf20Sopenharmony_ci void *pMessage; 13228c2ecf20Sopenharmony_ci unsigned long flags; 13238c2ecf20Sopenharmony_ci int q_index = circularQ - pm8001_ha->inbnd_q_tbl; 13248c2ecf20Sopenharmony_ci int rv = -1; 13258c2ecf20Sopenharmony_ci 13268c2ecf20Sopenharmony_ci if (WARN_ON(q_index >= pm8001_ha->max_q_num)) 13278c2ecf20Sopenharmony_ci return -EINVAL; 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ci spin_lock_irqsave(&circularQ->iq_lock, flags); 13308c2ecf20Sopenharmony_ci rv = pm8001_mpi_msg_free_get(circularQ, pm8001_ha->iomb_size, 13318c2ecf20Sopenharmony_ci &pMessage); 13328c2ecf20Sopenharmony_ci if (rv < 0) { 13338c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "No free mpi buffer\n"); 13348c2ecf20Sopenharmony_ci rv = -ENOMEM; 13358c2ecf20Sopenharmony_ci goto done; 13368c2ecf20Sopenharmony_ci } 13378c2ecf20Sopenharmony_ci 13388c2ecf20Sopenharmony_ci if (nb > (pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr))) 13398c2ecf20Sopenharmony_ci nb = pm8001_ha->iomb_size - sizeof(struct mpi_msg_hdr); 13408c2ecf20Sopenharmony_ci memcpy(pMessage, payload, nb); 13418c2ecf20Sopenharmony_ci if (nb + sizeof(struct mpi_msg_hdr) < pm8001_ha->iomb_size) 13428c2ecf20Sopenharmony_ci memset(pMessage + nb, 0, pm8001_ha->iomb_size - 13438c2ecf20Sopenharmony_ci (nb + sizeof(struct mpi_msg_hdr))); 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci /*Build the header*/ 13468c2ecf20Sopenharmony_ci Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24) 13478c2ecf20Sopenharmony_ci | ((responseQueue & 0x3F) << 16) 13488c2ecf20Sopenharmony_ci | ((category & 0xF) << 12) | (opCode & 0xFFF)); 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header)); 13518c2ecf20Sopenharmony_ci /*Update the PI to the firmware*/ 13528c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar, 13538c2ecf20Sopenharmony_ci circularQ->pi_offset, circularQ->producer_idx); 13548c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 13558c2ecf20Sopenharmony_ci "INB Q %x OPCODE:%x , UPDATED PI=%d CI=%d\n", 13568c2ecf20Sopenharmony_ci responseQueue, opCode, circularQ->producer_idx, 13578c2ecf20Sopenharmony_ci circularQ->consumer_index); 13588c2ecf20Sopenharmony_cidone: 13598c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&circularQ->iq_lock, flags); 13608c2ecf20Sopenharmony_ci return rv; 13618c2ecf20Sopenharmony_ci} 13628c2ecf20Sopenharmony_ci 13638c2ecf20Sopenharmony_ciu32 pm8001_mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg, 13648c2ecf20Sopenharmony_ci struct outbound_queue_table *circularQ, u8 bc) 13658c2ecf20Sopenharmony_ci{ 13668c2ecf20Sopenharmony_ci u32 producer_index; 13678c2ecf20Sopenharmony_ci struct mpi_msg_hdr *msgHeader; 13688c2ecf20Sopenharmony_ci struct mpi_msg_hdr *pOutBoundMsgHeader; 13698c2ecf20Sopenharmony_ci 13708c2ecf20Sopenharmony_ci msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr)); 13718c2ecf20Sopenharmony_ci pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + 13728c2ecf20Sopenharmony_ci circularQ->consumer_idx * pm8001_ha->iomb_size); 13738c2ecf20Sopenharmony_ci if (pOutBoundMsgHeader != msgHeader) { 13748c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 13758c2ecf20Sopenharmony_ci "consumer_idx = %d msgHeader = %p\n", 13768c2ecf20Sopenharmony_ci circularQ->consumer_idx, msgHeader); 13778c2ecf20Sopenharmony_ci 13788c2ecf20Sopenharmony_ci /* Update the producer index from SPC */ 13798c2ecf20Sopenharmony_ci producer_index = pm8001_read_32(circularQ->pi_virt); 13808c2ecf20Sopenharmony_ci circularQ->producer_index = cpu_to_le32(producer_index); 13818c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 13828c2ecf20Sopenharmony_ci "consumer_idx = %d producer_index = %dmsgHeader = %p\n", 13838c2ecf20Sopenharmony_ci circularQ->consumer_idx, 13848c2ecf20Sopenharmony_ci circularQ->producer_index, msgHeader); 13858c2ecf20Sopenharmony_ci return 0; 13868c2ecf20Sopenharmony_ci } 13878c2ecf20Sopenharmony_ci /* free the circular queue buffer elements associated with the message*/ 13888c2ecf20Sopenharmony_ci circularQ->consumer_idx = (circularQ->consumer_idx + bc) 13898c2ecf20Sopenharmony_ci % PM8001_MPI_QUEUE; 13908c2ecf20Sopenharmony_ci /* update the CI of outbound queue */ 13918c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset, 13928c2ecf20Sopenharmony_ci circularQ->consumer_idx); 13938c2ecf20Sopenharmony_ci /* Update the producer index from SPC*/ 13948c2ecf20Sopenharmony_ci producer_index = pm8001_read_32(circularQ->pi_virt); 13958c2ecf20Sopenharmony_ci circularQ->producer_index = cpu_to_le32(producer_index); 13968c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, " CI=%d PI=%d\n", 13978c2ecf20Sopenharmony_ci circularQ->consumer_idx, circularQ->producer_index); 13988c2ecf20Sopenharmony_ci return 0; 13998c2ecf20Sopenharmony_ci} 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_ci/** 14028c2ecf20Sopenharmony_ci * pm8001_mpi_msg_consume- get the MPI message from outbound queue 14038c2ecf20Sopenharmony_ci * message table. 14048c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 14058c2ecf20Sopenharmony_ci * @circularQ: the outbound queue table. 14068c2ecf20Sopenharmony_ci * @messagePtr1: the message contents of this outbound message. 14078c2ecf20Sopenharmony_ci * @pBC: the message size. 14088c2ecf20Sopenharmony_ci */ 14098c2ecf20Sopenharmony_ciu32 pm8001_mpi_msg_consume(struct pm8001_hba_info *pm8001_ha, 14108c2ecf20Sopenharmony_ci struct outbound_queue_table *circularQ, 14118c2ecf20Sopenharmony_ci void **messagePtr1, u8 *pBC) 14128c2ecf20Sopenharmony_ci{ 14138c2ecf20Sopenharmony_ci struct mpi_msg_hdr *msgHeader; 14148c2ecf20Sopenharmony_ci __le32 msgHeader_tmp; 14158c2ecf20Sopenharmony_ci u32 header_tmp; 14168c2ecf20Sopenharmony_ci do { 14178c2ecf20Sopenharmony_ci /* If there are not-yet-delivered messages ... */ 14188c2ecf20Sopenharmony_ci if (le32_to_cpu(circularQ->producer_index) 14198c2ecf20Sopenharmony_ci != circularQ->consumer_idx) { 14208c2ecf20Sopenharmony_ci /*Get the pointer to the circular queue buffer element*/ 14218c2ecf20Sopenharmony_ci msgHeader = (struct mpi_msg_hdr *) 14228c2ecf20Sopenharmony_ci (circularQ->base_virt + 14238c2ecf20Sopenharmony_ci circularQ->consumer_idx * pm8001_ha->iomb_size); 14248c2ecf20Sopenharmony_ci /* read header */ 14258c2ecf20Sopenharmony_ci header_tmp = pm8001_read_32(msgHeader); 14268c2ecf20Sopenharmony_ci msgHeader_tmp = cpu_to_le32(header_tmp); 14278c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 14288c2ecf20Sopenharmony_ci "outbound opcode msgheader:%x ci=%d pi=%d\n", 14298c2ecf20Sopenharmony_ci msgHeader_tmp, circularQ->consumer_idx, 14308c2ecf20Sopenharmony_ci circularQ->producer_index); 14318c2ecf20Sopenharmony_ci if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) { 14328c2ecf20Sopenharmony_ci if (OPC_OUB_SKIP_ENTRY != 14338c2ecf20Sopenharmony_ci (le32_to_cpu(msgHeader_tmp) & 0xfff)) { 14348c2ecf20Sopenharmony_ci *messagePtr1 = 14358c2ecf20Sopenharmony_ci ((u8 *)msgHeader) + 14368c2ecf20Sopenharmony_ci sizeof(struct mpi_msg_hdr); 14378c2ecf20Sopenharmony_ci *pBC = (u8)((le32_to_cpu(msgHeader_tmp) 14388c2ecf20Sopenharmony_ci >> 24) & 0x1f); 14398c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 14408c2ecf20Sopenharmony_ci ": CI=%d PI=%d msgHeader=%x\n", 14418c2ecf20Sopenharmony_ci circularQ->consumer_idx, 14428c2ecf20Sopenharmony_ci circularQ->producer_index, 14438c2ecf20Sopenharmony_ci msgHeader_tmp); 14448c2ecf20Sopenharmony_ci return MPI_IO_STATUS_SUCCESS; 14458c2ecf20Sopenharmony_ci } else { 14468c2ecf20Sopenharmony_ci circularQ->consumer_idx = 14478c2ecf20Sopenharmony_ci (circularQ->consumer_idx + 14488c2ecf20Sopenharmony_ci ((le32_to_cpu(msgHeader_tmp) 14498c2ecf20Sopenharmony_ci >> 24) & 0x1f)) 14508c2ecf20Sopenharmony_ci % PM8001_MPI_QUEUE; 14518c2ecf20Sopenharmony_ci msgHeader_tmp = 0; 14528c2ecf20Sopenharmony_ci pm8001_write_32(msgHeader, 0, 0); 14538c2ecf20Sopenharmony_ci /* update the CI of outbound queue */ 14548c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, 14558c2ecf20Sopenharmony_ci circularQ->ci_pci_bar, 14568c2ecf20Sopenharmony_ci circularQ->ci_offset, 14578c2ecf20Sopenharmony_ci circularQ->consumer_idx); 14588c2ecf20Sopenharmony_ci } 14598c2ecf20Sopenharmony_ci } else { 14608c2ecf20Sopenharmony_ci circularQ->consumer_idx = 14618c2ecf20Sopenharmony_ci (circularQ->consumer_idx + 14628c2ecf20Sopenharmony_ci ((le32_to_cpu(msgHeader_tmp) >> 24) & 14638c2ecf20Sopenharmony_ci 0x1f)) % PM8001_MPI_QUEUE; 14648c2ecf20Sopenharmony_ci msgHeader_tmp = 0; 14658c2ecf20Sopenharmony_ci pm8001_write_32(msgHeader, 0, 0); 14668c2ecf20Sopenharmony_ci /* update the CI of outbound queue */ 14678c2ecf20Sopenharmony_ci pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, 14688c2ecf20Sopenharmony_ci circularQ->ci_offset, 14698c2ecf20Sopenharmony_ci circularQ->consumer_idx); 14708c2ecf20Sopenharmony_ci return MPI_IO_STATUS_FAIL; 14718c2ecf20Sopenharmony_ci } 14728c2ecf20Sopenharmony_ci } else { 14738c2ecf20Sopenharmony_ci u32 producer_index; 14748c2ecf20Sopenharmony_ci void *pi_virt = circularQ->pi_virt; 14758c2ecf20Sopenharmony_ci /* spurious interrupt during setup if 14768c2ecf20Sopenharmony_ci * kexec-ing and driver doing a doorbell access 14778c2ecf20Sopenharmony_ci * with the pre-kexec oq interrupt setup 14788c2ecf20Sopenharmony_ci */ 14798c2ecf20Sopenharmony_ci if (!pi_virt) 14808c2ecf20Sopenharmony_ci break; 14818c2ecf20Sopenharmony_ci /* Update the producer index from SPC */ 14828c2ecf20Sopenharmony_ci producer_index = pm8001_read_32(pi_virt); 14838c2ecf20Sopenharmony_ci circularQ->producer_index = cpu_to_le32(producer_index); 14848c2ecf20Sopenharmony_ci } 14858c2ecf20Sopenharmony_ci } while (le32_to_cpu(circularQ->producer_index) != 14868c2ecf20Sopenharmony_ci circularQ->consumer_idx); 14878c2ecf20Sopenharmony_ci /* while we don't have any more not-yet-delivered message */ 14888c2ecf20Sopenharmony_ci /* report empty */ 14898c2ecf20Sopenharmony_ci return MPI_IO_STATUS_BUSY; 14908c2ecf20Sopenharmony_ci} 14918c2ecf20Sopenharmony_ci 14928c2ecf20Sopenharmony_civoid pm8001_work_fn(struct work_struct *work) 14938c2ecf20Sopenharmony_ci{ 14948c2ecf20Sopenharmony_ci struct pm8001_work *pw = container_of(work, struct pm8001_work, work); 14958c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 14968c2ecf20Sopenharmony_ci struct domain_device *dev; 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci /* 14998c2ecf20Sopenharmony_ci * So far, all users of this stash an associated structure here. 15008c2ecf20Sopenharmony_ci * If we get here, and this pointer is null, then the action 15018c2ecf20Sopenharmony_ci * was cancelled. This nullification happens when the device 15028c2ecf20Sopenharmony_ci * goes away. 15038c2ecf20Sopenharmony_ci */ 15048c2ecf20Sopenharmony_ci pm8001_dev = pw->data; /* Most stash device structure */ 15058c2ecf20Sopenharmony_ci if ((pm8001_dev == NULL) 15068c2ecf20Sopenharmony_ci || ((pw->handler != IO_XFER_ERROR_BREAK) 15078c2ecf20Sopenharmony_ci && (pm8001_dev->dev_type == SAS_PHY_UNUSED))) { 15088c2ecf20Sopenharmony_ci kfree(pw); 15098c2ecf20Sopenharmony_ci return; 15108c2ecf20Sopenharmony_ci } 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci switch (pw->handler) { 15138c2ecf20Sopenharmony_ci case IO_XFER_ERROR_BREAK: 15148c2ecf20Sopenharmony_ci { /* This one stashes the sas_task instead */ 15158c2ecf20Sopenharmony_ci struct sas_task *t = (struct sas_task *)pm8001_dev; 15168c2ecf20Sopenharmony_ci u32 tag; 15178c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 15188c2ecf20Sopenharmony_ci struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha; 15198c2ecf20Sopenharmony_ci unsigned long flags, flags1; 15208c2ecf20Sopenharmony_ci struct task_status_struct *ts; 15218c2ecf20Sopenharmony_ci int i; 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_ci if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC) 15248c2ecf20Sopenharmony_ci break; /* Task still on lu */ 15258c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags1); 15288c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) { 15298c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags1); 15308c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 15318c2ecf20Sopenharmony_ci break; /* Task got completed by another */ 15328c2ecf20Sopenharmony_ci } 15338c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags1); 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci /* Search for a possible ccb that matches the task */ 15368c2ecf20Sopenharmony_ci for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) { 15378c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[i]; 15388c2ecf20Sopenharmony_ci tag = ccb->ccb_tag; 15398c2ecf20Sopenharmony_ci if ((tag != 0xFFFFFFFF) && (ccb->task == t)) 15408c2ecf20Sopenharmony_ci break; 15418c2ecf20Sopenharmony_ci } 15428c2ecf20Sopenharmony_ci if (!ccb) { 15438c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 15448c2ecf20Sopenharmony_ci break; /* Task got freed by another */ 15458c2ecf20Sopenharmony_ci } 15468c2ecf20Sopenharmony_ci ts = &t->task_status; 15478c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 15488c2ecf20Sopenharmony_ci /* Force the midlayer to retry */ 15498c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 15508c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 15518c2ecf20Sopenharmony_ci if (pm8001_dev) 15528c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 15538c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags1); 15548c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 15558c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 15568c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 15578c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { 15588c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags1); 15598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", 15608c2ecf20Sopenharmony_ci t, pw->handler, ts->resp, ts->stat); 15618c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 15628c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 15638c2ecf20Sopenharmony_ci } else { 15648c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags1); 15658c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 15668c2ecf20Sopenharmony_ci mb();/* in order to force CPU ordering */ 15678c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 15688c2ecf20Sopenharmony_ci t->task_done(t); 15698c2ecf20Sopenharmony_ci } 15708c2ecf20Sopenharmony_ci } break; 15718c2ecf20Sopenharmony_ci case IO_XFER_OPEN_RETRY_TIMEOUT: 15728c2ecf20Sopenharmony_ci { /* This one stashes the sas_task instead */ 15738c2ecf20Sopenharmony_ci struct sas_task *t = (struct sas_task *)pm8001_dev; 15748c2ecf20Sopenharmony_ci u32 tag; 15758c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 15768c2ecf20Sopenharmony_ci struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha; 15778c2ecf20Sopenharmony_ci unsigned long flags, flags1; 15788c2ecf20Sopenharmony_ci int i, ret = 0; 15798c2ecf20Sopenharmony_ci 15808c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n"); 15818c2ecf20Sopenharmony_ci 15828c2ecf20Sopenharmony_ci ret = pm8001_query_task(t); 15838c2ecf20Sopenharmony_ci 15848c2ecf20Sopenharmony_ci if (ret == TMF_RESP_FUNC_SUCC) 15858c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "...Task on lu\n"); 15868c2ecf20Sopenharmony_ci else if (ret == TMF_RESP_FUNC_COMPLETE) 15878c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "...Task NOT on lu\n"); 15888c2ecf20Sopenharmony_ci else 15898c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "...query task failed!!!\n"); 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 15928c2ecf20Sopenharmony_ci 15938c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags1); 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) { 15968c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags1); 15978c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 15988c2ecf20Sopenharmony_ci if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */ 15998c2ecf20Sopenharmony_ci (void)pm8001_abort_task(t); 16008c2ecf20Sopenharmony_ci break; /* Task got completed by another */ 16018c2ecf20Sopenharmony_ci } 16028c2ecf20Sopenharmony_ci 16038c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags1); 16048c2ecf20Sopenharmony_ci 16058c2ecf20Sopenharmony_ci /* Search for a possible ccb that matches the task */ 16068c2ecf20Sopenharmony_ci for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) { 16078c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[i]; 16088c2ecf20Sopenharmony_ci tag = ccb->ccb_tag; 16098c2ecf20Sopenharmony_ci if ((tag != 0xFFFFFFFF) && (ccb->task == t)) 16108c2ecf20Sopenharmony_ci break; 16118c2ecf20Sopenharmony_ci } 16128c2ecf20Sopenharmony_ci if (!ccb) { 16138c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 16148c2ecf20Sopenharmony_ci if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */ 16158c2ecf20Sopenharmony_ci (void)pm8001_abort_task(t); 16168c2ecf20Sopenharmony_ci break; /* Task got freed by another */ 16178c2ecf20Sopenharmony_ci } 16188c2ecf20Sopenharmony_ci 16198c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 16208c2ecf20Sopenharmony_ci dev = pm8001_dev->sas_device; 16218c2ecf20Sopenharmony_ci 16228c2ecf20Sopenharmony_ci switch (ret) { 16238c2ecf20Sopenharmony_ci case TMF_RESP_FUNC_SUCC: /* task on lu */ 16248c2ecf20Sopenharmony_ci ccb->open_retry = 1; /* Snub completion */ 16258c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 16268c2ecf20Sopenharmony_ci ret = pm8001_abort_task(t); 16278c2ecf20Sopenharmony_ci ccb->open_retry = 0; 16288c2ecf20Sopenharmony_ci switch (ret) { 16298c2ecf20Sopenharmony_ci case TMF_RESP_FUNC_SUCC: 16308c2ecf20Sopenharmony_ci case TMF_RESP_FUNC_COMPLETE: 16318c2ecf20Sopenharmony_ci break; 16328c2ecf20Sopenharmony_ci default: /* device misbehavior */ 16338c2ecf20Sopenharmony_ci ret = TMF_RESP_FUNC_FAILED; 16348c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "...Reset phy\n"); 16358c2ecf20Sopenharmony_ci pm8001_I_T_nexus_reset(dev); 16368c2ecf20Sopenharmony_ci break; 16378c2ecf20Sopenharmony_ci } 16388c2ecf20Sopenharmony_ci break; 16398c2ecf20Sopenharmony_ci 16408c2ecf20Sopenharmony_ci case TMF_RESP_FUNC_COMPLETE: /* task not on lu */ 16418c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 16428c2ecf20Sopenharmony_ci /* Do we need to abort the task locally? */ 16438c2ecf20Sopenharmony_ci break; 16448c2ecf20Sopenharmony_ci 16458c2ecf20Sopenharmony_ci default: /* device misbehavior */ 16468c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 16478c2ecf20Sopenharmony_ci ret = TMF_RESP_FUNC_FAILED; 16488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "...Reset phy\n"); 16498c2ecf20Sopenharmony_ci pm8001_I_T_nexus_reset(dev); 16508c2ecf20Sopenharmony_ci } 16518c2ecf20Sopenharmony_ci 16528c2ecf20Sopenharmony_ci if (ret == TMF_RESP_FUNC_FAILED) 16538c2ecf20Sopenharmony_ci t = NULL; 16548c2ecf20Sopenharmony_ci pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev); 16558c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "...Complete\n"); 16568c2ecf20Sopenharmony_ci } break; 16578c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 16588c2ecf20Sopenharmony_ci dev = pm8001_dev->sas_device; 16598c2ecf20Sopenharmony_ci pm8001_I_T_nexus_event_handler(dev); 16608c2ecf20Sopenharmony_ci break; 16618c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY: 16628c2ecf20Sopenharmony_ci dev = pm8001_dev->sas_device; 16638c2ecf20Sopenharmony_ci pm8001_I_T_nexus_reset(dev); 16648c2ecf20Sopenharmony_ci break; 16658c2ecf20Sopenharmony_ci case IO_DS_IN_ERROR: 16668c2ecf20Sopenharmony_ci dev = pm8001_dev->sas_device; 16678c2ecf20Sopenharmony_ci pm8001_I_T_nexus_reset(dev); 16688c2ecf20Sopenharmony_ci break; 16698c2ecf20Sopenharmony_ci case IO_DS_NON_OPERATIONAL: 16708c2ecf20Sopenharmony_ci dev = pm8001_dev->sas_device; 16718c2ecf20Sopenharmony_ci pm8001_I_T_nexus_reset(dev); 16728c2ecf20Sopenharmony_ci break; 16738c2ecf20Sopenharmony_ci } 16748c2ecf20Sopenharmony_ci kfree(pw); 16758c2ecf20Sopenharmony_ci} 16768c2ecf20Sopenharmony_ci 16778c2ecf20Sopenharmony_ciint pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data, 16788c2ecf20Sopenharmony_ci int handler) 16798c2ecf20Sopenharmony_ci{ 16808c2ecf20Sopenharmony_ci struct pm8001_work *pw; 16818c2ecf20Sopenharmony_ci int ret = 0; 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ci pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC); 16848c2ecf20Sopenharmony_ci if (pw) { 16858c2ecf20Sopenharmony_ci pw->pm8001_ha = pm8001_ha; 16868c2ecf20Sopenharmony_ci pw->data = data; 16878c2ecf20Sopenharmony_ci pw->handler = handler; 16888c2ecf20Sopenharmony_ci INIT_WORK(&pw->work, pm8001_work_fn); 16898c2ecf20Sopenharmony_ci queue_work(pm8001_wq, &pw->work); 16908c2ecf20Sopenharmony_ci } else 16918c2ecf20Sopenharmony_ci ret = -ENOMEM; 16928c2ecf20Sopenharmony_ci 16938c2ecf20Sopenharmony_ci return ret; 16948c2ecf20Sopenharmony_ci} 16958c2ecf20Sopenharmony_ci 16968c2ecf20Sopenharmony_cistatic void pm8001_send_abort_all(struct pm8001_hba_info *pm8001_ha, 16978c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_ha_dev) 16988c2ecf20Sopenharmony_ci{ 16998c2ecf20Sopenharmony_ci int res; 17008c2ecf20Sopenharmony_ci u32 ccb_tag; 17018c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 17028c2ecf20Sopenharmony_ci struct sas_task *task = NULL; 17038c2ecf20Sopenharmony_ci struct task_abort_req task_abort; 17048c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 17058c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SATA_ABORT; 17068c2ecf20Sopenharmony_ci int ret; 17078c2ecf20Sopenharmony_ci 17088c2ecf20Sopenharmony_ci if (!pm8001_ha_dev) { 17098c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "dev is null\n"); 17108c2ecf20Sopenharmony_ci return; 17118c2ecf20Sopenharmony_ci } 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci task = sas_alloc_slow_task(GFP_ATOMIC); 17148c2ecf20Sopenharmony_ci if (!task) { 17158c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task\n"); 17168c2ecf20Sopenharmony_ci return; 17178c2ecf20Sopenharmony_ci } 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci task->task_done = pm8001_task_done; 17208c2ecf20Sopenharmony_ci 17218c2ecf20Sopenharmony_ci res = pm8001_tag_alloc(pm8001_ha, &ccb_tag); 17228c2ecf20Sopenharmony_ci if (res) { 17238c2ecf20Sopenharmony_ci sas_free_task(task); 17248c2ecf20Sopenharmony_ci return; 17258c2ecf20Sopenharmony_ci } 17268c2ecf20Sopenharmony_ci 17278c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[ccb_tag]; 17288c2ecf20Sopenharmony_ci ccb->device = pm8001_ha_dev; 17298c2ecf20Sopenharmony_ci ccb->ccb_tag = ccb_tag; 17308c2ecf20Sopenharmony_ci ccb->task = task; 17318c2ecf20Sopenharmony_ci ccb->n_elem = 0; 17328c2ecf20Sopenharmony_ci 17338c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 17348c2ecf20Sopenharmony_ci 17358c2ecf20Sopenharmony_ci memset(&task_abort, 0, sizeof(task_abort)); 17368c2ecf20Sopenharmony_ci task_abort.abort_all = cpu_to_le32(1); 17378c2ecf20Sopenharmony_ci task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id); 17388c2ecf20Sopenharmony_ci task_abort.tag = cpu_to_le32(ccb_tag); 17398c2ecf20Sopenharmony_ci 17408c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort, 17418c2ecf20Sopenharmony_ci sizeof(task_abort), 0); 17428c2ecf20Sopenharmony_ci if (ret) { 17438c2ecf20Sopenharmony_ci sas_free_task(task); 17448c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, ccb_tag); 17458c2ecf20Sopenharmony_ci } 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_ci} 17488c2ecf20Sopenharmony_ci 17498c2ecf20Sopenharmony_cistatic void pm8001_send_read_log(struct pm8001_hba_info *pm8001_ha, 17508c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_ha_dev) 17518c2ecf20Sopenharmony_ci{ 17528c2ecf20Sopenharmony_ci struct sata_start_req sata_cmd; 17538c2ecf20Sopenharmony_ci int res; 17548c2ecf20Sopenharmony_ci u32 ccb_tag; 17558c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 17568c2ecf20Sopenharmony_ci struct sas_task *task = NULL; 17578c2ecf20Sopenharmony_ci struct host_to_dev_fis fis; 17588c2ecf20Sopenharmony_ci struct domain_device *dev; 17598c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 17608c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SATA_HOST_OPSTART; 17618c2ecf20Sopenharmony_ci 17628c2ecf20Sopenharmony_ci task = sas_alloc_slow_task(GFP_ATOMIC); 17638c2ecf20Sopenharmony_ci 17648c2ecf20Sopenharmony_ci if (!task) { 17658c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "cannot allocate task !!!\n"); 17668c2ecf20Sopenharmony_ci return; 17678c2ecf20Sopenharmony_ci } 17688c2ecf20Sopenharmony_ci task->task_done = pm8001_task_done; 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_ci res = pm8001_tag_alloc(pm8001_ha, &ccb_tag); 17718c2ecf20Sopenharmony_ci if (res) { 17728c2ecf20Sopenharmony_ci sas_free_task(task); 17738c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "cannot allocate tag !!!\n"); 17748c2ecf20Sopenharmony_ci return; 17758c2ecf20Sopenharmony_ci } 17768c2ecf20Sopenharmony_ci 17778c2ecf20Sopenharmony_ci /* allocate domain device by ourselves as libsas 17788c2ecf20Sopenharmony_ci * is not going to provide any 17798c2ecf20Sopenharmony_ci */ 17808c2ecf20Sopenharmony_ci dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC); 17818c2ecf20Sopenharmony_ci if (!dev) { 17828c2ecf20Sopenharmony_ci sas_free_task(task); 17838c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, ccb_tag); 17848c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 17858c2ecf20Sopenharmony_ci "Domain device cannot be allocated\n"); 17868c2ecf20Sopenharmony_ci return; 17878c2ecf20Sopenharmony_ci } 17888c2ecf20Sopenharmony_ci task->dev = dev; 17898c2ecf20Sopenharmony_ci task->dev->lldd_dev = pm8001_ha_dev; 17908c2ecf20Sopenharmony_ci 17918c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[ccb_tag]; 17928c2ecf20Sopenharmony_ci ccb->device = pm8001_ha_dev; 17938c2ecf20Sopenharmony_ci ccb->ccb_tag = ccb_tag; 17948c2ecf20Sopenharmony_ci ccb->task = task; 17958c2ecf20Sopenharmony_ci ccb->n_elem = 0; 17968c2ecf20Sopenharmony_ci pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG; 17978c2ecf20Sopenharmony_ci pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG; 17988c2ecf20Sopenharmony_ci 17998c2ecf20Sopenharmony_ci memset(&sata_cmd, 0, sizeof(sata_cmd)); 18008c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 18018c2ecf20Sopenharmony_ci 18028c2ecf20Sopenharmony_ci /* construct read log FIS */ 18038c2ecf20Sopenharmony_ci memset(&fis, 0, sizeof(struct host_to_dev_fis)); 18048c2ecf20Sopenharmony_ci fis.fis_type = 0x27; 18058c2ecf20Sopenharmony_ci fis.flags = 0x80; 18068c2ecf20Sopenharmony_ci fis.command = ATA_CMD_READ_LOG_EXT; 18078c2ecf20Sopenharmony_ci fis.lbal = 0x10; 18088c2ecf20Sopenharmony_ci fis.sector_count = 0x1; 18098c2ecf20Sopenharmony_ci 18108c2ecf20Sopenharmony_ci sata_cmd.tag = cpu_to_le32(ccb_tag); 18118c2ecf20Sopenharmony_ci sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id); 18128c2ecf20Sopenharmony_ci sata_cmd.ncqtag_atap_dir_m = cpu_to_le32((0x1 << 7) | (0x5 << 9)); 18138c2ecf20Sopenharmony_ci memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis)); 18148c2ecf20Sopenharmony_ci 18158c2ecf20Sopenharmony_ci res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd, 18168c2ecf20Sopenharmony_ci sizeof(sata_cmd), 0); 18178c2ecf20Sopenharmony_ci if (res) { 18188c2ecf20Sopenharmony_ci sas_free_task(task); 18198c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, ccb_tag); 18208c2ecf20Sopenharmony_ci kfree(dev); 18218c2ecf20Sopenharmony_ci } 18228c2ecf20Sopenharmony_ci} 18238c2ecf20Sopenharmony_ci 18248c2ecf20Sopenharmony_ci/** 18258c2ecf20Sopenharmony_ci * mpi_ssp_completion- process the event that FW response to the SSP request. 18268c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 18278c2ecf20Sopenharmony_ci * @piomb: the message contents of this outbound message. 18288c2ecf20Sopenharmony_ci * 18298c2ecf20Sopenharmony_ci * When FW has completed a ssp request for example a IO request, after it has 18308c2ecf20Sopenharmony_ci * filled the SG data with the data, it will trigger this event represent 18318c2ecf20Sopenharmony_ci * that he has finished the job,please check the coresponding buffer. 18328c2ecf20Sopenharmony_ci * So we will tell the caller who maybe waiting the result to tell upper layer 18338c2ecf20Sopenharmony_ci * that the task has been finished. 18348c2ecf20Sopenharmony_ci */ 18358c2ecf20Sopenharmony_cistatic void 18368c2ecf20Sopenharmony_cimpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb) 18378c2ecf20Sopenharmony_ci{ 18388c2ecf20Sopenharmony_ci struct sas_task *t; 18398c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 18408c2ecf20Sopenharmony_ci unsigned long flags; 18418c2ecf20Sopenharmony_ci u32 status; 18428c2ecf20Sopenharmony_ci u32 param; 18438c2ecf20Sopenharmony_ci u32 tag; 18448c2ecf20Sopenharmony_ci struct ssp_completion_resp *psspPayload; 18458c2ecf20Sopenharmony_ci struct task_status_struct *ts; 18468c2ecf20Sopenharmony_ci struct ssp_response_iu *iu; 18478c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 18488c2ecf20Sopenharmony_ci psspPayload = (struct ssp_completion_resp *)(piomb + 4); 18498c2ecf20Sopenharmony_ci status = le32_to_cpu(psspPayload->status); 18508c2ecf20Sopenharmony_ci tag = le32_to_cpu(psspPayload->tag); 18518c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 18528c2ecf20Sopenharmony_ci if ((status == IO_ABORTED) && ccb->open_retry) { 18538c2ecf20Sopenharmony_ci /* Being completed by another */ 18548c2ecf20Sopenharmony_ci ccb->open_retry = 0; 18558c2ecf20Sopenharmony_ci return; 18568c2ecf20Sopenharmony_ci } 18578c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 18588c2ecf20Sopenharmony_ci param = le32_to_cpu(psspPayload->param); 18598c2ecf20Sopenharmony_ci 18608c2ecf20Sopenharmony_ci t = ccb->task; 18618c2ecf20Sopenharmony_ci 18628c2ecf20Sopenharmony_ci if (status && status != IO_UNDERFLOW) 18638c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", status); 18648c2ecf20Sopenharmony_ci if (unlikely(!t || !t->lldd_task || !t->dev)) 18658c2ecf20Sopenharmony_ci return; 18668c2ecf20Sopenharmony_ci ts = &t->task_status; 18678c2ecf20Sopenharmony_ci /* Print sas address of IO failed device */ 18688c2ecf20Sopenharmony_ci if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) && 18698c2ecf20Sopenharmony_ci (status != IO_UNDERFLOW)) 18708c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "SAS Address of IO Failure Drive:%016llx\n", 18718c2ecf20Sopenharmony_ci SAS_ADDR(t->dev->sas_addr)); 18728c2ecf20Sopenharmony_ci 18738c2ecf20Sopenharmony_ci if (status) 18748c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IOERR, 18758c2ecf20Sopenharmony_ci "status:0x%x, tag:0x%x, task:0x%p\n", 18768c2ecf20Sopenharmony_ci status, tag, t); 18778c2ecf20Sopenharmony_ci 18788c2ecf20Sopenharmony_ci switch (status) { 18798c2ecf20Sopenharmony_ci case IO_SUCCESS: 18808c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS,param = %d\n", 18818c2ecf20Sopenharmony_ci param); 18828c2ecf20Sopenharmony_ci if (param == 0) { 18838c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 18848c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_GOOD; 18858c2ecf20Sopenharmony_ci } else { 18868c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 18878c2ecf20Sopenharmony_ci ts->stat = SAS_PROTO_RESPONSE; 18888c2ecf20Sopenharmony_ci ts->residual = param; 18898c2ecf20Sopenharmony_ci iu = &psspPayload->ssp_resp_iu; 18908c2ecf20Sopenharmony_ci sas_ssp_task_response(pm8001_ha->dev, t, iu); 18918c2ecf20Sopenharmony_ci } 18928c2ecf20Sopenharmony_ci if (pm8001_dev) 18938c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 18948c2ecf20Sopenharmony_ci break; 18958c2ecf20Sopenharmony_ci case IO_ABORTED: 18968c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n"); 18978c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 18988c2ecf20Sopenharmony_ci ts->stat = SAS_ABORTED_TASK; 18998c2ecf20Sopenharmony_ci break; 19008c2ecf20Sopenharmony_ci case IO_UNDERFLOW: 19018c2ecf20Sopenharmony_ci /* SSP Completion with error */ 19028c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW,param = %d\n", 19038c2ecf20Sopenharmony_ci param); 19048c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19058c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_UNDERRUN; 19068c2ecf20Sopenharmony_ci ts->residual = param; 19078c2ecf20Sopenharmony_ci if (pm8001_dev) 19088c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 19098c2ecf20Sopenharmony_ci break; 19108c2ecf20Sopenharmony_ci case IO_NO_DEVICE: 19118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n"); 19128c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 19138c2ecf20Sopenharmony_ci ts->stat = SAS_PHY_DOWN; 19148c2ecf20Sopenharmony_ci break; 19158c2ecf20Sopenharmony_ci case IO_XFER_ERROR_BREAK: 19168c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n"); 19178c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19188c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19198c2ecf20Sopenharmony_ci /* Force the midlayer to retry */ 19208c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 19218c2ecf20Sopenharmony_ci break; 19228c2ecf20Sopenharmony_ci case IO_XFER_ERROR_PHY_NOT_READY: 19238c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n"); 19248c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19258c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19268c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 19278c2ecf20Sopenharmony_ci break; 19288c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: 19298c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 19308c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"); 19318c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19328c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19338c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_EPROTO; 19348c2ecf20Sopenharmony_ci break; 19358c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: 19368c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 19378c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"); 19388c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19398c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19408c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 19418c2ecf20Sopenharmony_ci break; 19428c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BREAK: 19438c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n"); 19448c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19458c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19468c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 19478c2ecf20Sopenharmony_ci break; 19488c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 19498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"); 19508c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19518c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19528c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 19538c2ecf20Sopenharmony_ci if (!t->uldd_task) 19548c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 19558c2ecf20Sopenharmony_ci pm8001_dev, 19568c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); 19578c2ecf20Sopenharmony_ci break; 19588c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BAD_DESTINATION: 19598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 19608c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"); 19618c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19628c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19638c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_BAD_DEST; 19648c2ecf20Sopenharmony_ci break; 19658c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: 19668c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"); 19678c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19688c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19698c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_CONN_RATE; 19708c2ecf20Sopenharmony_ci break; 19718c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: 19728c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 19738c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"); 19748c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 19758c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19768c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_WRONG_DEST; 19778c2ecf20Sopenharmony_ci break; 19788c2ecf20Sopenharmony_ci case IO_XFER_ERROR_NAK_RECEIVED: 19798c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n"); 19808c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19818c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19828c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 19838c2ecf20Sopenharmony_ci break; 19848c2ecf20Sopenharmony_ci case IO_XFER_ERROR_ACK_NAK_TIMEOUT: 19858c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"); 19868c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19878c2ecf20Sopenharmony_ci ts->stat = SAS_NAK_R_ERR; 19888c2ecf20Sopenharmony_ci break; 19898c2ecf20Sopenharmony_ci case IO_XFER_ERROR_DMA: 19908c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n"); 19918c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19928c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19938c2ecf20Sopenharmony_ci break; 19948c2ecf20Sopenharmony_ci case IO_XFER_OPEN_RETRY_TIMEOUT: 19958c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n"); 19968c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 19978c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 19988c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 19998c2ecf20Sopenharmony_ci break; 20008c2ecf20Sopenharmony_ci case IO_XFER_ERROR_OFFSET_MISMATCH: 20018c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n"); 20028c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20038c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20048c2ecf20Sopenharmony_ci break; 20058c2ecf20Sopenharmony_ci case IO_PORT_IN_RESET: 20068c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n"); 20078c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20088c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20098c2ecf20Sopenharmony_ci break; 20108c2ecf20Sopenharmony_ci case IO_DS_NON_OPERATIONAL: 20118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n"); 20128c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20138c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20148c2ecf20Sopenharmony_ci if (!t->uldd_task) 20158c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 20168c2ecf20Sopenharmony_ci pm8001_dev, 20178c2ecf20Sopenharmony_ci IO_DS_NON_OPERATIONAL); 20188c2ecf20Sopenharmony_ci break; 20198c2ecf20Sopenharmony_ci case IO_DS_IN_RECOVERY: 20208c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n"); 20218c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20228c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20238c2ecf20Sopenharmony_ci break; 20248c2ecf20Sopenharmony_ci case IO_TM_TAG_NOT_FOUND: 20258c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_TM_TAG_NOT_FOUND\n"); 20268c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20278c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20288c2ecf20Sopenharmony_ci break; 20298c2ecf20Sopenharmony_ci case IO_SSP_EXT_IU_ZERO_LEN_ERROR: 20308c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_SSP_EXT_IU_ZERO_LEN_ERROR\n"); 20318c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20328c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20338c2ecf20Sopenharmony_ci break; 20348c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY: 20358c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 20368c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"); 20378c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20388c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20398c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 20408c2ecf20Sopenharmony_ci break; 20418c2ecf20Sopenharmony_ci default: 20428c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status); 20438c2ecf20Sopenharmony_ci /* not allowed case. Therefore, return failed status */ 20448c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20458c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 20468c2ecf20Sopenharmony_ci break; 20478c2ecf20Sopenharmony_ci } 20488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "scsi_status = %x\n", 20498c2ecf20Sopenharmony_ci psspPayload->ssp_resp_iu.status); 20508c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags); 20518c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 20528c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 20538c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 20548c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { 20558c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 20568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", 20578c2ecf20Sopenharmony_ci t, status, ts->resp, ts->stat); 20588c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 20598c2ecf20Sopenharmony_ci } else { 20608c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 20618c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 20628c2ecf20Sopenharmony_ci mb();/* in order to force CPU ordering */ 20638c2ecf20Sopenharmony_ci t->task_done(t); 20648c2ecf20Sopenharmony_ci } 20658c2ecf20Sopenharmony_ci} 20668c2ecf20Sopenharmony_ci 20678c2ecf20Sopenharmony_ci/*See the comments for mpi_ssp_completion */ 20688c2ecf20Sopenharmony_cistatic void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb) 20698c2ecf20Sopenharmony_ci{ 20708c2ecf20Sopenharmony_ci struct sas_task *t; 20718c2ecf20Sopenharmony_ci unsigned long flags; 20728c2ecf20Sopenharmony_ci struct task_status_struct *ts; 20738c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 20748c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 20758c2ecf20Sopenharmony_ci struct ssp_event_resp *psspPayload = 20768c2ecf20Sopenharmony_ci (struct ssp_event_resp *)(piomb + 4); 20778c2ecf20Sopenharmony_ci u32 event = le32_to_cpu(psspPayload->event); 20788c2ecf20Sopenharmony_ci u32 tag = le32_to_cpu(psspPayload->tag); 20798c2ecf20Sopenharmony_ci u32 port_id = le32_to_cpu(psspPayload->port_id); 20808c2ecf20Sopenharmony_ci u32 dev_id = le32_to_cpu(psspPayload->device_id); 20818c2ecf20Sopenharmony_ci 20828c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 20838c2ecf20Sopenharmony_ci t = ccb->task; 20848c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 20858c2ecf20Sopenharmony_ci if (event) 20868c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "sas IO status 0x%x\n", event); 20878c2ecf20Sopenharmony_ci if (unlikely(!t || !t->lldd_task || !t->dev)) 20888c2ecf20Sopenharmony_ci return; 20898c2ecf20Sopenharmony_ci ts = &t->task_status; 20908c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "port_id = %x,device_id = %x\n", 20918c2ecf20Sopenharmony_ci port_id, dev_id); 20928c2ecf20Sopenharmony_ci switch (event) { 20938c2ecf20Sopenharmony_ci case IO_OVERFLOW: 20948c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n"); 20958c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 20968c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 20978c2ecf20Sopenharmony_ci ts->residual = 0; 20988c2ecf20Sopenharmony_ci if (pm8001_dev) 20998c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 21008c2ecf20Sopenharmony_ci break; 21018c2ecf20Sopenharmony_ci case IO_XFER_ERROR_BREAK: 21028c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n"); 21038c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK); 21048c2ecf20Sopenharmony_ci return; 21058c2ecf20Sopenharmony_ci case IO_XFER_ERROR_PHY_NOT_READY: 21068c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n"); 21078c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21088c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21098c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 21108c2ecf20Sopenharmony_ci break; 21118c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: 21128c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"); 21138c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21148c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21158c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_EPROTO; 21168c2ecf20Sopenharmony_ci break; 21178c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: 21188c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 21198c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"); 21208c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21218c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21228c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 21238c2ecf20Sopenharmony_ci break; 21248c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BREAK: 21258c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n"); 21268c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21278c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21288c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 21298c2ecf20Sopenharmony_ci break; 21308c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 21318c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"); 21328c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21338c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21348c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 21358c2ecf20Sopenharmony_ci if (!t->uldd_task) 21368c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 21378c2ecf20Sopenharmony_ci pm8001_dev, 21388c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); 21398c2ecf20Sopenharmony_ci break; 21408c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BAD_DESTINATION: 21418c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 21428c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"); 21438c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21448c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21458c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_BAD_DEST; 21468c2ecf20Sopenharmony_ci break; 21478c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: 21488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"); 21498c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21508c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21518c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_CONN_RATE; 21528c2ecf20Sopenharmony_ci break; 21538c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: 21548c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 21558c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"); 21568c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21578c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21588c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_WRONG_DEST; 21598c2ecf20Sopenharmony_ci break; 21608c2ecf20Sopenharmony_ci case IO_XFER_ERROR_NAK_RECEIVED: 21618c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n"); 21628c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21638c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 21648c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 21658c2ecf20Sopenharmony_ci break; 21668c2ecf20Sopenharmony_ci case IO_XFER_ERROR_ACK_NAK_TIMEOUT: 21678c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"); 21688c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21698c2ecf20Sopenharmony_ci ts->stat = SAS_NAK_R_ERR; 21708c2ecf20Sopenharmony_ci break; 21718c2ecf20Sopenharmony_ci case IO_XFER_OPEN_RETRY_TIMEOUT: 21728c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n"); 21738c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT); 21748c2ecf20Sopenharmony_ci return; 21758c2ecf20Sopenharmony_ci case IO_XFER_ERROR_UNEXPECTED_PHASE: 21768c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n"); 21778c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21788c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 21798c2ecf20Sopenharmony_ci break; 21808c2ecf20Sopenharmony_ci case IO_XFER_ERROR_XFER_RDY_OVERRUN: 21818c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n"); 21828c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21838c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 21848c2ecf20Sopenharmony_ci break; 21858c2ecf20Sopenharmony_ci case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED: 21868c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 21878c2ecf20Sopenharmony_ci "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"); 21888c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21898c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 21908c2ecf20Sopenharmony_ci break; 21918c2ecf20Sopenharmony_ci case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT: 21928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 21938c2ecf20Sopenharmony_ci "IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n"); 21948c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 21958c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 21968c2ecf20Sopenharmony_ci break; 21978c2ecf20Sopenharmony_ci case IO_XFER_ERROR_OFFSET_MISMATCH: 21988c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n"); 21998c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 22008c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 22018c2ecf20Sopenharmony_ci break; 22028c2ecf20Sopenharmony_ci case IO_XFER_ERROR_XFER_ZERO_DATA_LEN: 22038c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 22048c2ecf20Sopenharmony_ci "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"); 22058c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 22068c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 22078c2ecf20Sopenharmony_ci break; 22088c2ecf20Sopenharmony_ci case IO_XFER_CMD_FRAME_ISSUED: 22098c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n"); 22108c2ecf20Sopenharmony_ci return; 22118c2ecf20Sopenharmony_ci default: 22128c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event); 22138c2ecf20Sopenharmony_ci /* not allowed case. Therefore, return failed status */ 22148c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 22158c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 22168c2ecf20Sopenharmony_ci break; 22178c2ecf20Sopenharmony_ci } 22188c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags); 22198c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 22208c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 22218c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 22228c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { 22238c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 22248c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with event 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", 22258c2ecf20Sopenharmony_ci t, event, ts->resp, ts->stat); 22268c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 22278c2ecf20Sopenharmony_ci } else { 22288c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 22298c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 22308c2ecf20Sopenharmony_ci mb();/* in order to force CPU ordering */ 22318c2ecf20Sopenharmony_ci t->task_done(t); 22328c2ecf20Sopenharmony_ci } 22338c2ecf20Sopenharmony_ci} 22348c2ecf20Sopenharmony_ci 22358c2ecf20Sopenharmony_ci/*See the comments for mpi_ssp_completion */ 22368c2ecf20Sopenharmony_cistatic void 22378c2ecf20Sopenharmony_cimpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) 22388c2ecf20Sopenharmony_ci{ 22398c2ecf20Sopenharmony_ci struct sas_task *t; 22408c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 22418c2ecf20Sopenharmony_ci u32 param; 22428c2ecf20Sopenharmony_ci u32 status; 22438c2ecf20Sopenharmony_ci u32 tag; 22448c2ecf20Sopenharmony_ci int i, j; 22458c2ecf20Sopenharmony_ci u8 sata_addr_low[4]; 22468c2ecf20Sopenharmony_ci u32 temp_sata_addr_low; 22478c2ecf20Sopenharmony_ci u8 sata_addr_hi[4]; 22488c2ecf20Sopenharmony_ci u32 temp_sata_addr_hi; 22498c2ecf20Sopenharmony_ci struct sata_completion_resp *psataPayload; 22508c2ecf20Sopenharmony_ci struct task_status_struct *ts; 22518c2ecf20Sopenharmony_ci struct ata_task_resp *resp ; 22528c2ecf20Sopenharmony_ci u32 *sata_resp; 22538c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 22548c2ecf20Sopenharmony_ci unsigned long flags; 22558c2ecf20Sopenharmony_ci 22568c2ecf20Sopenharmony_ci psataPayload = (struct sata_completion_resp *)(piomb + 4); 22578c2ecf20Sopenharmony_ci status = le32_to_cpu(psataPayload->status); 22588c2ecf20Sopenharmony_ci tag = le32_to_cpu(psataPayload->tag); 22598c2ecf20Sopenharmony_ci 22608c2ecf20Sopenharmony_ci if (!tag) { 22618c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "tag null\n"); 22628c2ecf20Sopenharmony_ci return; 22638c2ecf20Sopenharmony_ci } 22648c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 22658c2ecf20Sopenharmony_ci param = le32_to_cpu(psataPayload->param); 22668c2ecf20Sopenharmony_ci if (ccb) { 22678c2ecf20Sopenharmony_ci t = ccb->task; 22688c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 22698c2ecf20Sopenharmony_ci } else { 22708c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "ccb null\n"); 22718c2ecf20Sopenharmony_ci return; 22728c2ecf20Sopenharmony_ci } 22738c2ecf20Sopenharmony_ci 22748c2ecf20Sopenharmony_ci if (t) { 22758c2ecf20Sopenharmony_ci if (t->dev && (t->dev->lldd_dev)) 22768c2ecf20Sopenharmony_ci pm8001_dev = t->dev->lldd_dev; 22778c2ecf20Sopenharmony_ci } else { 22788c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task null\n"); 22798c2ecf20Sopenharmony_ci return; 22808c2ecf20Sopenharmony_ci } 22818c2ecf20Sopenharmony_ci 22828c2ecf20Sopenharmony_ci if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG)) 22838c2ecf20Sopenharmony_ci && unlikely(!t || !t->lldd_task || !t->dev)) { 22848c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task or dev null\n"); 22858c2ecf20Sopenharmony_ci return; 22868c2ecf20Sopenharmony_ci } 22878c2ecf20Sopenharmony_ci 22888c2ecf20Sopenharmony_ci ts = &t->task_status; 22898c2ecf20Sopenharmony_ci if (!ts) { 22908c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "ts null\n"); 22918c2ecf20Sopenharmony_ci return; 22928c2ecf20Sopenharmony_ci } 22938c2ecf20Sopenharmony_ci 22948c2ecf20Sopenharmony_ci if (status) 22958c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IOERR, 22968c2ecf20Sopenharmony_ci "status:0x%x, tag:0x%x, task::0x%p\n", 22978c2ecf20Sopenharmony_ci status, tag, t); 22988c2ecf20Sopenharmony_ci 22998c2ecf20Sopenharmony_ci /* Print sas address of IO failed device */ 23008c2ecf20Sopenharmony_ci if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) && 23018c2ecf20Sopenharmony_ci (status != IO_UNDERFLOW)) { 23028c2ecf20Sopenharmony_ci if (!((t->dev->parent) && 23038c2ecf20Sopenharmony_ci (dev_is_expander(t->dev->parent->dev_type)))) { 23048c2ecf20Sopenharmony_ci for (i = 0 , j = 4; j <= 7 && i <= 3; i++ , j++) 23058c2ecf20Sopenharmony_ci sata_addr_low[i] = pm8001_ha->sas_addr[j]; 23068c2ecf20Sopenharmony_ci for (i = 0 , j = 0; j <= 3 && i <= 3; i++ , j++) 23078c2ecf20Sopenharmony_ci sata_addr_hi[i] = pm8001_ha->sas_addr[j]; 23088c2ecf20Sopenharmony_ci memcpy(&temp_sata_addr_low, sata_addr_low, 23098c2ecf20Sopenharmony_ci sizeof(sata_addr_low)); 23108c2ecf20Sopenharmony_ci memcpy(&temp_sata_addr_hi, sata_addr_hi, 23118c2ecf20Sopenharmony_ci sizeof(sata_addr_hi)); 23128c2ecf20Sopenharmony_ci temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff) 23138c2ecf20Sopenharmony_ci |((temp_sata_addr_hi << 8) & 23148c2ecf20Sopenharmony_ci 0xff0000) | 23158c2ecf20Sopenharmony_ci ((temp_sata_addr_hi >> 8) 23168c2ecf20Sopenharmony_ci & 0xff00) | 23178c2ecf20Sopenharmony_ci ((temp_sata_addr_hi << 24) & 23188c2ecf20Sopenharmony_ci 0xff000000)); 23198c2ecf20Sopenharmony_ci temp_sata_addr_low = ((((temp_sata_addr_low >> 24) 23208c2ecf20Sopenharmony_ci & 0xff) | 23218c2ecf20Sopenharmony_ci ((temp_sata_addr_low << 8) 23228c2ecf20Sopenharmony_ci & 0xff0000) | 23238c2ecf20Sopenharmony_ci ((temp_sata_addr_low >> 8) 23248c2ecf20Sopenharmony_ci & 0xff00) | 23258c2ecf20Sopenharmony_ci ((temp_sata_addr_low << 24) 23268c2ecf20Sopenharmony_ci & 0xff000000)) + 23278c2ecf20Sopenharmony_ci pm8001_dev->attached_phy + 23288c2ecf20Sopenharmony_ci 0x10); 23298c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 23308c2ecf20Sopenharmony_ci "SAS Address of IO Failure Drive:%08x%08x\n", 23318c2ecf20Sopenharmony_ci temp_sata_addr_hi, 23328c2ecf20Sopenharmony_ci temp_sata_addr_low); 23338c2ecf20Sopenharmony_ci } else { 23348c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 23358c2ecf20Sopenharmony_ci "SAS Address of IO Failure Drive:%016llx\n", 23368c2ecf20Sopenharmony_ci SAS_ADDR(t->dev->sas_addr)); 23378c2ecf20Sopenharmony_ci } 23388c2ecf20Sopenharmony_ci } 23398c2ecf20Sopenharmony_ci switch (status) { 23408c2ecf20Sopenharmony_ci case IO_SUCCESS: 23418c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n"); 23428c2ecf20Sopenharmony_ci if (param == 0) { 23438c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 23448c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_GOOD; 23458c2ecf20Sopenharmony_ci /* check if response is for SEND READ LOG */ 23468c2ecf20Sopenharmony_ci if (pm8001_dev && 23478c2ecf20Sopenharmony_ci (pm8001_dev->id & NCQ_READ_LOG_FLAG)) { 23488c2ecf20Sopenharmony_ci /* set new bit for abort_all */ 23498c2ecf20Sopenharmony_ci pm8001_dev->id |= NCQ_ABORT_ALL_FLAG; 23508c2ecf20Sopenharmony_ci /* clear bit for read log */ 23518c2ecf20Sopenharmony_ci pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF; 23528c2ecf20Sopenharmony_ci pm8001_send_abort_all(pm8001_ha, pm8001_dev); 23538c2ecf20Sopenharmony_ci /* Free the tag */ 23548c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 23558c2ecf20Sopenharmony_ci sas_free_task(t); 23568c2ecf20Sopenharmony_ci return; 23578c2ecf20Sopenharmony_ci } 23588c2ecf20Sopenharmony_ci } else { 23598c2ecf20Sopenharmony_ci u8 len; 23608c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 23618c2ecf20Sopenharmony_ci ts->stat = SAS_PROTO_RESPONSE; 23628c2ecf20Sopenharmony_ci ts->residual = param; 23638c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 23648c2ecf20Sopenharmony_ci "SAS_PROTO_RESPONSE len = %d\n", 23658c2ecf20Sopenharmony_ci param); 23668c2ecf20Sopenharmony_ci sata_resp = &psataPayload->sata_resp[0]; 23678c2ecf20Sopenharmony_ci resp = (struct ata_task_resp *)ts->buf; 23688c2ecf20Sopenharmony_ci if (t->ata_task.dma_xfer == 0 && 23698c2ecf20Sopenharmony_ci t->data_dir == DMA_FROM_DEVICE) { 23708c2ecf20Sopenharmony_ci len = sizeof(struct pio_setup_fis); 23718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 23728c2ecf20Sopenharmony_ci "PIO read len = %d\n", len); 23738c2ecf20Sopenharmony_ci } else if (t->ata_task.use_ncq && 23748c2ecf20Sopenharmony_ci t->data_dir != DMA_NONE) { 23758c2ecf20Sopenharmony_ci len = sizeof(struct set_dev_bits_fis); 23768c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "FPDMA len = %d\n", 23778c2ecf20Sopenharmony_ci len); 23788c2ecf20Sopenharmony_ci } else { 23798c2ecf20Sopenharmony_ci len = sizeof(struct dev_to_host_fis); 23808c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "other len = %d\n", 23818c2ecf20Sopenharmony_ci len); 23828c2ecf20Sopenharmony_ci } 23838c2ecf20Sopenharmony_ci if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) { 23848c2ecf20Sopenharmony_ci resp->frame_len = len; 23858c2ecf20Sopenharmony_ci memcpy(&resp->ending_fis[0], sata_resp, len); 23868c2ecf20Sopenharmony_ci ts->buf_valid_size = sizeof(*resp); 23878c2ecf20Sopenharmony_ci } else 23888c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 23898c2ecf20Sopenharmony_ci "response too large\n"); 23908c2ecf20Sopenharmony_ci } 23918c2ecf20Sopenharmony_ci if (pm8001_dev) 23928c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 23938c2ecf20Sopenharmony_ci break; 23948c2ecf20Sopenharmony_ci case IO_ABORTED: 23958c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB Tag\n"); 23968c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 23978c2ecf20Sopenharmony_ci ts->stat = SAS_ABORTED_TASK; 23988c2ecf20Sopenharmony_ci if (pm8001_dev) 23998c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24008c2ecf20Sopenharmony_ci break; 24018c2ecf20Sopenharmony_ci /* following cases are to do cases */ 24028c2ecf20Sopenharmony_ci case IO_UNDERFLOW: 24038c2ecf20Sopenharmony_ci /* SATA Completion with error */ 24048c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW param = %d\n", param); 24058c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24068c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_UNDERRUN; 24078c2ecf20Sopenharmony_ci ts->residual = param; 24088c2ecf20Sopenharmony_ci if (pm8001_dev) 24098c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24108c2ecf20Sopenharmony_ci break; 24118c2ecf20Sopenharmony_ci case IO_NO_DEVICE: 24128c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n"); 24138c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 24148c2ecf20Sopenharmony_ci ts->stat = SAS_PHY_DOWN; 24158c2ecf20Sopenharmony_ci if (pm8001_dev) 24168c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24178c2ecf20Sopenharmony_ci break; 24188c2ecf20Sopenharmony_ci case IO_XFER_ERROR_BREAK: 24198c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n"); 24208c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24218c2ecf20Sopenharmony_ci ts->stat = SAS_INTERRUPTED; 24228c2ecf20Sopenharmony_ci if (pm8001_dev) 24238c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24248c2ecf20Sopenharmony_ci break; 24258c2ecf20Sopenharmony_ci case IO_XFER_ERROR_PHY_NOT_READY: 24268c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n"); 24278c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24288c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 24298c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 24308c2ecf20Sopenharmony_ci if (pm8001_dev) 24318c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24328c2ecf20Sopenharmony_ci break; 24338c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: 24348c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"); 24358c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24368c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 24378c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_EPROTO; 24388c2ecf20Sopenharmony_ci if (pm8001_dev) 24398c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24408c2ecf20Sopenharmony_ci break; 24418c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: 24428c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 24438c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"); 24448c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24458c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 24468c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 24478c2ecf20Sopenharmony_ci if (pm8001_dev) 24488c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24498c2ecf20Sopenharmony_ci break; 24508c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BREAK: 24518c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n"); 24528c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24538c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 24548c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_CONT0; 24558c2ecf20Sopenharmony_ci if (pm8001_dev) 24568c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24578c2ecf20Sopenharmony_ci break; 24588c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 24598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"); 24608c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24618c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 24628c2ecf20Sopenharmony_ci if (!t->uldd_task) { 24638c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 24648c2ecf20Sopenharmony_ci pm8001_dev, 24658c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); 24668c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 24678c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 24688c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 24698c2ecf20Sopenharmony_ci return; 24708c2ecf20Sopenharmony_ci } 24718c2ecf20Sopenharmony_ci break; 24728c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BAD_DESTINATION: 24738c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 24748c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"); 24758c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 24768c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 24778c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_BAD_DEST; 24788c2ecf20Sopenharmony_ci if (!t->uldd_task) { 24798c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 24808c2ecf20Sopenharmony_ci pm8001_dev, 24818c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); 24828c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 24838c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 24848c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 24858c2ecf20Sopenharmony_ci return; 24868c2ecf20Sopenharmony_ci } 24878c2ecf20Sopenharmony_ci break; 24888c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: 24898c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"); 24908c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24918c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 24928c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_CONN_RATE; 24938c2ecf20Sopenharmony_ci if (pm8001_dev) 24948c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 24958c2ecf20Sopenharmony_ci break; 24968c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY: 24978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n"); 24988c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 24998c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 25008c2ecf20Sopenharmony_ci if (!t->uldd_task) { 25018c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 25028c2ecf20Sopenharmony_ci pm8001_dev, 25038c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY); 25048c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 25058c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 25068c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 25078c2ecf20Sopenharmony_ci return; 25088c2ecf20Sopenharmony_ci } 25098c2ecf20Sopenharmony_ci break; 25108c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: 25118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 25128c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"); 25138c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25148c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 25158c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_WRONG_DEST; 25168c2ecf20Sopenharmony_ci if (pm8001_dev) 25178c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25188c2ecf20Sopenharmony_ci break; 25198c2ecf20Sopenharmony_ci case IO_XFER_ERROR_NAK_RECEIVED: 25208c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n"); 25218c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25228c2ecf20Sopenharmony_ci ts->stat = SAS_NAK_R_ERR; 25238c2ecf20Sopenharmony_ci if (pm8001_dev) 25248c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25258c2ecf20Sopenharmony_ci break; 25268c2ecf20Sopenharmony_ci case IO_XFER_ERROR_ACK_NAK_TIMEOUT: 25278c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"); 25288c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25298c2ecf20Sopenharmony_ci ts->stat = SAS_NAK_R_ERR; 25308c2ecf20Sopenharmony_ci if (pm8001_dev) 25318c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25328c2ecf20Sopenharmony_ci break; 25338c2ecf20Sopenharmony_ci case IO_XFER_ERROR_DMA: 25348c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_DMA\n"); 25358c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25368c2ecf20Sopenharmony_ci ts->stat = SAS_ABORTED_TASK; 25378c2ecf20Sopenharmony_ci if (pm8001_dev) 25388c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25398c2ecf20Sopenharmony_ci break; 25408c2ecf20Sopenharmony_ci case IO_XFER_ERROR_SATA_LINK_TIMEOUT: 25418c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_SATA_LINK_TIMEOUT\n"); 25428c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 25438c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 25448c2ecf20Sopenharmony_ci if (pm8001_dev) 25458c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25468c2ecf20Sopenharmony_ci break; 25478c2ecf20Sopenharmony_ci case IO_XFER_ERROR_REJECTED_NCQ_MODE: 25488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n"); 25498c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25508c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_UNDERRUN; 25518c2ecf20Sopenharmony_ci if (pm8001_dev) 25528c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25538c2ecf20Sopenharmony_ci break; 25548c2ecf20Sopenharmony_ci case IO_XFER_OPEN_RETRY_TIMEOUT: 25558c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n"); 25568c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25578c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 25588c2ecf20Sopenharmony_ci if (pm8001_dev) 25598c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25608c2ecf20Sopenharmony_ci break; 25618c2ecf20Sopenharmony_ci case IO_PORT_IN_RESET: 25628c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n"); 25638c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25648c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 25658c2ecf20Sopenharmony_ci if (pm8001_dev) 25668c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25678c2ecf20Sopenharmony_ci break; 25688c2ecf20Sopenharmony_ci case IO_DS_NON_OPERATIONAL: 25698c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n"); 25708c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25718c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 25728c2ecf20Sopenharmony_ci if (!t->uldd_task) { 25738c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, pm8001_dev, 25748c2ecf20Sopenharmony_ci IO_DS_NON_OPERATIONAL); 25758c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 25768c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 25778c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 25788c2ecf20Sopenharmony_ci return; 25798c2ecf20Sopenharmony_ci } 25808c2ecf20Sopenharmony_ci break; 25818c2ecf20Sopenharmony_ci case IO_DS_IN_RECOVERY: 25828c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, " IO_DS_IN_RECOVERY\n"); 25838c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25848c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 25858c2ecf20Sopenharmony_ci if (pm8001_dev) 25868c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 25878c2ecf20Sopenharmony_ci break; 25888c2ecf20Sopenharmony_ci case IO_DS_IN_ERROR: 25898c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_ERROR\n"); 25908c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 25918c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 25928c2ecf20Sopenharmony_ci if (!t->uldd_task) { 25938c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, pm8001_dev, 25948c2ecf20Sopenharmony_ci IO_DS_IN_ERROR); 25958c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 25968c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 25978c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 25988c2ecf20Sopenharmony_ci return; 25998c2ecf20Sopenharmony_ci } 26008c2ecf20Sopenharmony_ci break; 26018c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY: 26028c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 26038c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"); 26048c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 26058c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 26068c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 26078c2ecf20Sopenharmony_ci if (pm8001_dev) 26088c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 26098c2ecf20Sopenharmony_ci break; 26108c2ecf20Sopenharmony_ci default: 26118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status); 26128c2ecf20Sopenharmony_ci /* not allowed case. Therefore, return failed status */ 26138c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 26148c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 26158c2ecf20Sopenharmony_ci if (pm8001_dev) 26168c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 26178c2ecf20Sopenharmony_ci break; 26188c2ecf20Sopenharmony_ci } 26198c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags); 26208c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 26218c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 26228c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 26238c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { 26248c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 26258c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 26268c2ecf20Sopenharmony_ci "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", 26278c2ecf20Sopenharmony_ci t, status, ts->resp, ts->stat); 26288c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 26298c2ecf20Sopenharmony_ci } else { 26308c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 26318c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 26328c2ecf20Sopenharmony_ci } 26338c2ecf20Sopenharmony_ci} 26348c2ecf20Sopenharmony_ci 26358c2ecf20Sopenharmony_ci/*See the comments for mpi_ssp_completion */ 26368c2ecf20Sopenharmony_cistatic void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb) 26378c2ecf20Sopenharmony_ci{ 26388c2ecf20Sopenharmony_ci struct sas_task *t; 26398c2ecf20Sopenharmony_ci struct task_status_struct *ts; 26408c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 26418c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 26428c2ecf20Sopenharmony_ci struct sata_event_resp *psataPayload = 26438c2ecf20Sopenharmony_ci (struct sata_event_resp *)(piomb + 4); 26448c2ecf20Sopenharmony_ci u32 event = le32_to_cpu(psataPayload->event); 26458c2ecf20Sopenharmony_ci u32 tag = le32_to_cpu(psataPayload->tag); 26468c2ecf20Sopenharmony_ci u32 port_id = le32_to_cpu(psataPayload->port_id); 26478c2ecf20Sopenharmony_ci u32 dev_id = le32_to_cpu(psataPayload->device_id); 26488c2ecf20Sopenharmony_ci unsigned long flags; 26498c2ecf20Sopenharmony_ci 26508c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 26518c2ecf20Sopenharmony_ci 26528c2ecf20Sopenharmony_ci if (ccb) { 26538c2ecf20Sopenharmony_ci t = ccb->task; 26548c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 26558c2ecf20Sopenharmony_ci } else { 26568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "No CCB !!!. returning\n"); 26578c2ecf20Sopenharmony_ci } 26588c2ecf20Sopenharmony_ci if (event) 26598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "SATA EVENT 0x%x\n", event); 26608c2ecf20Sopenharmony_ci 26618c2ecf20Sopenharmony_ci /* Check if this is NCQ error */ 26628c2ecf20Sopenharmony_ci if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) { 26638c2ecf20Sopenharmony_ci /* find device using device id */ 26648c2ecf20Sopenharmony_ci pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id); 26658c2ecf20Sopenharmony_ci /* send read log extension */ 26668c2ecf20Sopenharmony_ci if (pm8001_dev) 26678c2ecf20Sopenharmony_ci pm8001_send_read_log(pm8001_ha, pm8001_dev); 26688c2ecf20Sopenharmony_ci return; 26698c2ecf20Sopenharmony_ci } 26708c2ecf20Sopenharmony_ci 26718c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 26728c2ecf20Sopenharmony_ci t = ccb->task; 26738c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 26748c2ecf20Sopenharmony_ci if (event) 26758c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "sata IO status 0x%x\n", event); 26768c2ecf20Sopenharmony_ci if (unlikely(!t || !t->lldd_task || !t->dev)) 26778c2ecf20Sopenharmony_ci return; 26788c2ecf20Sopenharmony_ci ts = &t->task_status; 26798c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 26808c2ecf20Sopenharmony_ci "port_id:0x%x, device_id:0x%x, tag:0x%x, event:0x%x\n", 26818c2ecf20Sopenharmony_ci port_id, dev_id, tag, event); 26828c2ecf20Sopenharmony_ci switch (event) { 26838c2ecf20Sopenharmony_ci case IO_OVERFLOW: 26848c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n"); 26858c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 26868c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 26878c2ecf20Sopenharmony_ci ts->residual = 0; 26888c2ecf20Sopenharmony_ci if (pm8001_dev) 26898c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 26908c2ecf20Sopenharmony_ci break; 26918c2ecf20Sopenharmony_ci case IO_XFER_ERROR_BREAK: 26928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n"); 26938c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 26948c2ecf20Sopenharmony_ci ts->stat = SAS_INTERRUPTED; 26958c2ecf20Sopenharmony_ci break; 26968c2ecf20Sopenharmony_ci case IO_XFER_ERROR_PHY_NOT_READY: 26978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n"); 26988c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 26998c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27008c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 27018c2ecf20Sopenharmony_ci break; 27028c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: 27038c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"); 27048c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27058c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27068c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_EPROTO; 27078c2ecf20Sopenharmony_ci break; 27088c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: 27098c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 27108c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"); 27118c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27128c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27138c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 27148c2ecf20Sopenharmony_ci break; 27158c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BREAK: 27168c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n"); 27178c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27188c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27198c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_CONT0; 27208c2ecf20Sopenharmony_ci break; 27218c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 27228c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"); 27238c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 27248c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 27258c2ecf20Sopenharmony_ci if (!t->uldd_task) { 27268c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 27278c2ecf20Sopenharmony_ci pm8001_dev, 27288c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); 27298c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27308c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 27318c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 27328c2ecf20Sopenharmony_ci return; 27338c2ecf20Sopenharmony_ci } 27348c2ecf20Sopenharmony_ci break; 27358c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BAD_DESTINATION: 27368c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 27378c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"); 27388c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_UNDELIVERED; 27398c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27408c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_BAD_DEST; 27418c2ecf20Sopenharmony_ci break; 27428c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: 27438c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"); 27448c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27458c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27468c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_CONN_RATE; 27478c2ecf20Sopenharmony_ci break; 27488c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: 27498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 27508c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"); 27518c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27528c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 27538c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_WRONG_DEST; 27548c2ecf20Sopenharmony_ci break; 27558c2ecf20Sopenharmony_ci case IO_XFER_ERROR_NAK_RECEIVED: 27568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_NAK_RECEIVED\n"); 27578c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27588c2ecf20Sopenharmony_ci ts->stat = SAS_NAK_R_ERR; 27598c2ecf20Sopenharmony_ci break; 27608c2ecf20Sopenharmony_ci case IO_XFER_ERROR_PEER_ABORTED: 27618c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PEER_ABORTED\n"); 27628c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27638c2ecf20Sopenharmony_ci ts->stat = SAS_NAK_R_ERR; 27648c2ecf20Sopenharmony_ci break; 27658c2ecf20Sopenharmony_ci case IO_XFER_ERROR_REJECTED_NCQ_MODE: 27668c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_REJECTED_NCQ_MODE\n"); 27678c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27688c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_UNDERRUN; 27698c2ecf20Sopenharmony_ci break; 27708c2ecf20Sopenharmony_ci case IO_XFER_OPEN_RETRY_TIMEOUT: 27718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n"); 27728c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27738c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 27748c2ecf20Sopenharmony_ci break; 27758c2ecf20Sopenharmony_ci case IO_XFER_ERROR_UNEXPECTED_PHASE: 27768c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_UNEXPECTED_PHASE\n"); 27778c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27788c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 27798c2ecf20Sopenharmony_ci break; 27808c2ecf20Sopenharmony_ci case IO_XFER_ERROR_XFER_RDY_OVERRUN: 27818c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_XFER_RDY_OVERRUN\n"); 27828c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27838c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 27848c2ecf20Sopenharmony_ci break; 27858c2ecf20Sopenharmony_ci case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED: 27868c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 27878c2ecf20Sopenharmony_ci "IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"); 27888c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27898c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 27908c2ecf20Sopenharmony_ci break; 27918c2ecf20Sopenharmony_ci case IO_XFER_ERROR_OFFSET_MISMATCH: 27928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_OFFSET_MISMATCH\n"); 27938c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 27948c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 27958c2ecf20Sopenharmony_ci break; 27968c2ecf20Sopenharmony_ci case IO_XFER_ERROR_XFER_ZERO_DATA_LEN: 27978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 27988c2ecf20Sopenharmony_ci "IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"); 27998c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28008c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 28018c2ecf20Sopenharmony_ci break; 28028c2ecf20Sopenharmony_ci case IO_XFER_CMD_FRAME_ISSUED: 28038c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_CMD_FRAME_ISSUED\n"); 28048c2ecf20Sopenharmony_ci break; 28058c2ecf20Sopenharmony_ci case IO_XFER_PIO_SETUP_ERROR: 28068c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_PIO_SETUP_ERROR\n"); 28078c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28088c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 28098c2ecf20Sopenharmony_ci break; 28108c2ecf20Sopenharmony_ci default: 28118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", event); 28128c2ecf20Sopenharmony_ci /* not allowed case. Therefore, return failed status */ 28138c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28148c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_TO; 28158c2ecf20Sopenharmony_ci break; 28168c2ecf20Sopenharmony_ci } 28178c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags); 28188c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 28198c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 28208c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 28218c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { 28228c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 28238c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 28248c2ecf20Sopenharmony_ci "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", 28258c2ecf20Sopenharmony_ci t, event, ts->resp, ts->stat); 28268c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 28278c2ecf20Sopenharmony_ci } else { 28288c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 28298c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag); 28308c2ecf20Sopenharmony_ci } 28318c2ecf20Sopenharmony_ci} 28328c2ecf20Sopenharmony_ci 28338c2ecf20Sopenharmony_ci/*See the comments for mpi_ssp_completion */ 28348c2ecf20Sopenharmony_cistatic void 28358c2ecf20Sopenharmony_cimpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) 28368c2ecf20Sopenharmony_ci{ 28378c2ecf20Sopenharmony_ci struct sas_task *t; 28388c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 28398c2ecf20Sopenharmony_ci unsigned long flags; 28408c2ecf20Sopenharmony_ci u32 status; 28418c2ecf20Sopenharmony_ci u32 tag; 28428c2ecf20Sopenharmony_ci struct smp_completion_resp *psmpPayload; 28438c2ecf20Sopenharmony_ci struct task_status_struct *ts; 28448c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 28458c2ecf20Sopenharmony_ci 28468c2ecf20Sopenharmony_ci psmpPayload = (struct smp_completion_resp *)(piomb + 4); 28478c2ecf20Sopenharmony_ci status = le32_to_cpu(psmpPayload->status); 28488c2ecf20Sopenharmony_ci tag = le32_to_cpu(psmpPayload->tag); 28498c2ecf20Sopenharmony_ci 28508c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 28518c2ecf20Sopenharmony_ci t = ccb->task; 28528c2ecf20Sopenharmony_ci ts = &t->task_status; 28538c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 28548c2ecf20Sopenharmony_ci if (status) { 28558c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "smp IO status 0x%x\n", status); 28568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IOERR, 28578c2ecf20Sopenharmony_ci "status:0x%x, tag:0x%x, task:0x%p\n", 28588c2ecf20Sopenharmony_ci status, tag, t); 28598c2ecf20Sopenharmony_ci } 28608c2ecf20Sopenharmony_ci if (unlikely(!t || !t->lldd_task || !t->dev)) 28618c2ecf20Sopenharmony_ci return; 28628c2ecf20Sopenharmony_ci 28638c2ecf20Sopenharmony_ci switch (status) { 28648c2ecf20Sopenharmony_ci case IO_SUCCESS: 28658c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_SUCCESS\n"); 28668c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28678c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_GOOD; 28688c2ecf20Sopenharmony_ci if (pm8001_dev) 28698c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 28708c2ecf20Sopenharmony_ci break; 28718c2ecf20Sopenharmony_ci case IO_ABORTED: 28728c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_ABORTED IOMB\n"); 28738c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28748c2ecf20Sopenharmony_ci ts->stat = SAS_ABORTED_TASK; 28758c2ecf20Sopenharmony_ci if (pm8001_dev) 28768c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 28778c2ecf20Sopenharmony_ci break; 28788c2ecf20Sopenharmony_ci case IO_OVERFLOW: 28798c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_UNDERFLOW\n"); 28808c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28818c2ecf20Sopenharmony_ci ts->stat = SAS_DATA_OVERRUN; 28828c2ecf20Sopenharmony_ci ts->residual = 0; 28838c2ecf20Sopenharmony_ci if (pm8001_dev) 28848c2ecf20Sopenharmony_ci atomic_dec(&pm8001_dev->running_req); 28858c2ecf20Sopenharmony_ci break; 28868c2ecf20Sopenharmony_ci case IO_NO_DEVICE: 28878c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_NO_DEVICE\n"); 28888c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28898c2ecf20Sopenharmony_ci ts->stat = SAS_PHY_DOWN; 28908c2ecf20Sopenharmony_ci break; 28918c2ecf20Sopenharmony_ci case IO_ERROR_HW_TIMEOUT: 28928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_ERROR_HW_TIMEOUT\n"); 28938c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28948c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_BUSY; 28958c2ecf20Sopenharmony_ci break; 28968c2ecf20Sopenharmony_ci case IO_XFER_ERROR_BREAK: 28978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_BREAK\n"); 28988c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 28998c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_BUSY; 29008c2ecf20Sopenharmony_ci break; 29018c2ecf20Sopenharmony_ci case IO_XFER_ERROR_PHY_NOT_READY: 29028c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_PHY_NOT_READY\n"); 29038c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29048c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_BUSY; 29058c2ecf20Sopenharmony_ci break; 29068c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: 29078c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 29088c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"); 29098c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29108c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29118c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 29128c2ecf20Sopenharmony_ci break; 29138c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: 29148c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 29158c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"); 29168c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29178c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29188c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 29198c2ecf20Sopenharmony_ci break; 29208c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BREAK: 29218c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_BREAK\n"); 29228c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29238c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29248c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_CONT0; 29258c2ecf20Sopenharmony_ci break; 29268c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 29278c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"); 29288c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29298c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29308c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_UNKNOWN; 29318c2ecf20Sopenharmony_ci pm8001_handle_event(pm8001_ha, 29328c2ecf20Sopenharmony_ci pm8001_dev, 29338c2ecf20Sopenharmony_ci IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); 29348c2ecf20Sopenharmony_ci break; 29358c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_BAD_DESTINATION: 29368c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 29378c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"); 29388c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29398c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29408c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_BAD_DEST; 29418c2ecf20Sopenharmony_ci break; 29428c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: 29438c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"); 29448c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29458c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29468c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_CONN_RATE; 29478c2ecf20Sopenharmony_ci break; 29488c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: 29498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 29508c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"); 29518c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29528c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29538c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_WRONG_DEST; 29548c2ecf20Sopenharmony_ci break; 29558c2ecf20Sopenharmony_ci case IO_XFER_ERROR_RX_FRAME: 29568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_ERROR_RX_FRAME\n"); 29578c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29588c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 29598c2ecf20Sopenharmony_ci break; 29608c2ecf20Sopenharmony_ci case IO_XFER_OPEN_RETRY_TIMEOUT: 29618c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_XFER_OPEN_RETRY_TIMEOUT\n"); 29628c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29638c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29648c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 29658c2ecf20Sopenharmony_ci break; 29668c2ecf20Sopenharmony_ci case IO_ERROR_INTERNAL_SMP_RESOURCE: 29678c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_ERROR_INTERNAL_SMP_RESOURCE\n"); 29688c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29698c2ecf20Sopenharmony_ci ts->stat = SAS_QUEUE_FULL; 29708c2ecf20Sopenharmony_ci break; 29718c2ecf20Sopenharmony_ci case IO_PORT_IN_RESET: 29728c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_PORT_IN_RESET\n"); 29738c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29748c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29758c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 29768c2ecf20Sopenharmony_ci break; 29778c2ecf20Sopenharmony_ci case IO_DS_NON_OPERATIONAL: 29788c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_DS_NON_OPERATIONAL\n"); 29798c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29808c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 29818c2ecf20Sopenharmony_ci break; 29828c2ecf20Sopenharmony_ci case IO_DS_IN_RECOVERY: 29838c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "IO_DS_IN_RECOVERY\n"); 29848c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29858c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29868c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 29878c2ecf20Sopenharmony_ci break; 29888c2ecf20Sopenharmony_ci case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY: 29898c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, 29908c2ecf20Sopenharmony_ci "IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"); 29918c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29928c2ecf20Sopenharmony_ci ts->stat = SAS_OPEN_REJECT; 29938c2ecf20Sopenharmony_ci ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 29948c2ecf20Sopenharmony_ci break; 29958c2ecf20Sopenharmony_ci default: 29968c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "Unknown status 0x%x\n", status); 29978c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 29988c2ecf20Sopenharmony_ci ts->stat = SAS_DEV_NO_RESPONSE; 29998c2ecf20Sopenharmony_ci /* not allowed case. Therefore, return failed status */ 30008c2ecf20Sopenharmony_ci break; 30018c2ecf20Sopenharmony_ci } 30028c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags); 30038c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 30048c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 30058c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 30068c2ecf20Sopenharmony_ci if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { 30078c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 30088c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task 0x%p done with io_status 0x%x resp 0x%x stat 0x%x but aborted by upper layer!\n", 30098c2ecf20Sopenharmony_ci t, status, ts->resp, ts->stat); 30108c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 30118c2ecf20Sopenharmony_ci } else { 30128c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 30138c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 30148c2ecf20Sopenharmony_ci mb();/* in order to force CPU ordering */ 30158c2ecf20Sopenharmony_ci t->task_done(t); 30168c2ecf20Sopenharmony_ci } 30178c2ecf20Sopenharmony_ci} 30188c2ecf20Sopenharmony_ci 30198c2ecf20Sopenharmony_civoid pm8001_mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha, 30208c2ecf20Sopenharmony_ci void *piomb) 30218c2ecf20Sopenharmony_ci{ 30228c2ecf20Sopenharmony_ci struct set_dev_state_resp *pPayload = 30238c2ecf20Sopenharmony_ci (struct set_dev_state_resp *)(piomb + 4); 30248c2ecf20Sopenharmony_ci u32 tag = le32_to_cpu(pPayload->tag); 30258c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; 30268c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev = ccb->device; 30278c2ecf20Sopenharmony_ci u32 status = le32_to_cpu(pPayload->status); 30288c2ecf20Sopenharmony_ci u32 device_id = le32_to_cpu(pPayload->device_id); 30298c2ecf20Sopenharmony_ci u8 pds = le32_to_cpu(pPayload->pds_nds) & PDS_BITS; 30308c2ecf20Sopenharmony_ci u8 nds = le32_to_cpu(pPayload->pds_nds) & NDS_BITS; 30318c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "Set device id = 0x%x state from 0x%x to 0x%x status = 0x%x!\n", 30328c2ecf20Sopenharmony_ci device_id, pds, nds, status); 30338c2ecf20Sopenharmony_ci complete(pm8001_dev->setds_completion); 30348c2ecf20Sopenharmony_ci ccb->task = NULL; 30358c2ecf20Sopenharmony_ci ccb->ccb_tag = 0xFFFFFFFF; 30368c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 30378c2ecf20Sopenharmony_ci} 30388c2ecf20Sopenharmony_ci 30398c2ecf20Sopenharmony_civoid pm8001_mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) 30408c2ecf20Sopenharmony_ci{ 30418c2ecf20Sopenharmony_ci struct get_nvm_data_resp *pPayload = 30428c2ecf20Sopenharmony_ci (struct get_nvm_data_resp *)(piomb + 4); 30438c2ecf20Sopenharmony_ci u32 tag = le32_to_cpu(pPayload->tag); 30448c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; 30458c2ecf20Sopenharmony_ci u32 dlen_status = le32_to_cpu(pPayload->dlen_status); 30468c2ecf20Sopenharmony_ci complete(pm8001_ha->nvmd_completion); 30478c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "Set nvm data complete!\n"); 30488c2ecf20Sopenharmony_ci if ((dlen_status & NVMD_STAT) != 0) { 30498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Set nvm data error!\n"); 30508c2ecf20Sopenharmony_ci return; 30518c2ecf20Sopenharmony_ci } 30528c2ecf20Sopenharmony_ci ccb->task = NULL; 30538c2ecf20Sopenharmony_ci ccb->ccb_tag = 0xFFFFFFFF; 30548c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 30558c2ecf20Sopenharmony_ci} 30568c2ecf20Sopenharmony_ci 30578c2ecf20Sopenharmony_civoid 30588c2ecf20Sopenharmony_cipm8001_mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) 30598c2ecf20Sopenharmony_ci{ 30608c2ecf20Sopenharmony_ci struct fw_control_ex *fw_control_context; 30618c2ecf20Sopenharmony_ci struct get_nvm_data_resp *pPayload = 30628c2ecf20Sopenharmony_ci (struct get_nvm_data_resp *)(piomb + 4); 30638c2ecf20Sopenharmony_ci u32 tag = le32_to_cpu(pPayload->tag); 30648c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; 30658c2ecf20Sopenharmony_ci u32 dlen_status = le32_to_cpu(pPayload->dlen_status); 30668c2ecf20Sopenharmony_ci u32 ir_tds_bn_dps_das_nvm = 30678c2ecf20Sopenharmony_ci le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm); 30688c2ecf20Sopenharmony_ci void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr; 30698c2ecf20Sopenharmony_ci fw_control_context = ccb->fw_control_context; 30708c2ecf20Sopenharmony_ci 30718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "Get nvm data complete!\n"); 30728c2ecf20Sopenharmony_ci if ((dlen_status & NVMD_STAT) != 0) { 30738c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "Get nvm data error!\n"); 30748c2ecf20Sopenharmony_ci complete(pm8001_ha->nvmd_completion); 30758c2ecf20Sopenharmony_ci return; 30768c2ecf20Sopenharmony_ci } 30778c2ecf20Sopenharmony_ci 30788c2ecf20Sopenharmony_ci if (ir_tds_bn_dps_das_nvm & IPMode) { 30798c2ecf20Sopenharmony_ci /* indirect mode - IR bit set */ 30808c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "Get NVMD success, IR=1\n"); 30818c2ecf20Sopenharmony_ci if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) { 30828c2ecf20Sopenharmony_ci if (ir_tds_bn_dps_das_nvm == 0x80a80200) { 30838c2ecf20Sopenharmony_ci memcpy(pm8001_ha->sas_addr, 30848c2ecf20Sopenharmony_ci ((u8 *)virt_addr + 4), 30858c2ecf20Sopenharmony_ci SAS_ADDR_SIZE); 30868c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "Get SAS address from VPD successfully!\n"); 30878c2ecf20Sopenharmony_ci } 30888c2ecf20Sopenharmony_ci } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM) 30898c2ecf20Sopenharmony_ci || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) || 30908c2ecf20Sopenharmony_ci ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) { 30918c2ecf20Sopenharmony_ci ; 30928c2ecf20Sopenharmony_ci } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP) 30938c2ecf20Sopenharmony_ci || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) { 30948c2ecf20Sopenharmony_ci ; 30958c2ecf20Sopenharmony_ci } else { 30968c2ecf20Sopenharmony_ci /* Should not be happened*/ 30978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 30988c2ecf20Sopenharmony_ci "(IR=1)Wrong Device type 0x%x\n", 30998c2ecf20Sopenharmony_ci ir_tds_bn_dps_das_nvm); 31008c2ecf20Sopenharmony_ci } 31018c2ecf20Sopenharmony_ci } else /* direct mode */{ 31028c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 31038c2ecf20Sopenharmony_ci "Get NVMD success, IR=0, dataLen=%d\n", 31048c2ecf20Sopenharmony_ci (dlen_status & NVMD_LEN) >> 24); 31058c2ecf20Sopenharmony_ci } 31068c2ecf20Sopenharmony_ci /* Though fw_control_context is freed below, usrAddr still needs 31078c2ecf20Sopenharmony_ci * to be updated as this holds the response to the request function 31088c2ecf20Sopenharmony_ci */ 31098c2ecf20Sopenharmony_ci memcpy(fw_control_context->usrAddr, 31108c2ecf20Sopenharmony_ci pm8001_ha->memoryMap.region[NVMD].virt_ptr, 31118c2ecf20Sopenharmony_ci fw_control_context->len); 31128c2ecf20Sopenharmony_ci kfree(ccb->fw_control_context); 31138c2ecf20Sopenharmony_ci /* To avoid race condition, complete should be 31148c2ecf20Sopenharmony_ci * called after the message is copied to 31158c2ecf20Sopenharmony_ci * fw_control_context->usrAddr 31168c2ecf20Sopenharmony_ci */ 31178c2ecf20Sopenharmony_ci complete(pm8001_ha->nvmd_completion); 31188c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "Get nvmd data complete!\n"); 31198c2ecf20Sopenharmony_ci ccb->task = NULL; 31208c2ecf20Sopenharmony_ci ccb->ccb_tag = 0xFFFFFFFF; 31218c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 31228c2ecf20Sopenharmony_ci} 31238c2ecf20Sopenharmony_ci 31248c2ecf20Sopenharmony_ciint pm8001_mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb) 31258c2ecf20Sopenharmony_ci{ 31268c2ecf20Sopenharmony_ci u32 tag; 31278c2ecf20Sopenharmony_ci struct local_phy_ctl_resp *pPayload = 31288c2ecf20Sopenharmony_ci (struct local_phy_ctl_resp *)(piomb + 4); 31298c2ecf20Sopenharmony_ci u32 status = le32_to_cpu(pPayload->status); 31308c2ecf20Sopenharmony_ci u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS; 31318c2ecf20Sopenharmony_ci u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS; 31328c2ecf20Sopenharmony_ci tag = le32_to_cpu(pPayload->tag); 31338c2ecf20Sopenharmony_ci if (status != 0) { 31348c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 31358c2ecf20Sopenharmony_ci "%x phy execute %x phy op failed!\n", 31368c2ecf20Sopenharmony_ci phy_id, phy_op); 31378c2ecf20Sopenharmony_ci } else { 31388c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 31398c2ecf20Sopenharmony_ci "%x phy execute %x phy op success!\n", 31408c2ecf20Sopenharmony_ci phy_id, phy_op); 31418c2ecf20Sopenharmony_ci pm8001_ha->phy[phy_id].reset_success = true; 31428c2ecf20Sopenharmony_ci } 31438c2ecf20Sopenharmony_ci if (pm8001_ha->phy[phy_id].enable_completion) { 31448c2ecf20Sopenharmony_ci complete(pm8001_ha->phy[phy_id].enable_completion); 31458c2ecf20Sopenharmony_ci pm8001_ha->phy[phy_id].enable_completion = NULL; 31468c2ecf20Sopenharmony_ci } 31478c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 31488c2ecf20Sopenharmony_ci return 0; 31498c2ecf20Sopenharmony_ci} 31508c2ecf20Sopenharmony_ci 31518c2ecf20Sopenharmony_ci/** 31528c2ecf20Sopenharmony_ci * pm8001_bytes_dmaed - one of the interface function communication with libsas 31538c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 31548c2ecf20Sopenharmony_ci * @i: which phy that received the event. 31558c2ecf20Sopenharmony_ci * 31568c2ecf20Sopenharmony_ci * when HBA driver received the identify done event or initiate FIS received 31578c2ecf20Sopenharmony_ci * event(for SATA), it will invoke this function to notify the sas layer that 31588c2ecf20Sopenharmony_ci * the sas toplogy has formed, please discover the the whole sas domain, 31598c2ecf20Sopenharmony_ci * while receive a broadcast(change) primitive just tell the sas 31608c2ecf20Sopenharmony_ci * layer to discover the changed domain rather than the whole domain. 31618c2ecf20Sopenharmony_ci */ 31628c2ecf20Sopenharmony_civoid pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i) 31638c2ecf20Sopenharmony_ci{ 31648c2ecf20Sopenharmony_ci struct pm8001_phy *phy = &pm8001_ha->phy[i]; 31658c2ecf20Sopenharmony_ci struct asd_sas_phy *sas_phy = &phy->sas_phy; 31668c2ecf20Sopenharmony_ci if (!phy->phy_attached) 31678c2ecf20Sopenharmony_ci return; 31688c2ecf20Sopenharmony_ci 31698c2ecf20Sopenharmony_ci if (sas_phy->phy) { 31708c2ecf20Sopenharmony_ci struct sas_phy *sphy = sas_phy->phy; 31718c2ecf20Sopenharmony_ci sphy->negotiated_linkrate = sas_phy->linkrate; 31728c2ecf20Sopenharmony_ci sphy->minimum_linkrate = phy->minimum_linkrate; 31738c2ecf20Sopenharmony_ci sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; 31748c2ecf20Sopenharmony_ci sphy->maximum_linkrate = phy->maximum_linkrate; 31758c2ecf20Sopenharmony_ci sphy->maximum_linkrate_hw = phy->maximum_linkrate; 31768c2ecf20Sopenharmony_ci } 31778c2ecf20Sopenharmony_ci 31788c2ecf20Sopenharmony_ci if (phy->phy_type & PORT_TYPE_SAS) { 31798c2ecf20Sopenharmony_ci struct sas_identify_frame *id; 31808c2ecf20Sopenharmony_ci id = (struct sas_identify_frame *)phy->frame_rcvd; 31818c2ecf20Sopenharmony_ci id->dev_type = phy->identify.device_type; 31828c2ecf20Sopenharmony_ci id->initiator_bits = SAS_PROTOCOL_ALL; 31838c2ecf20Sopenharmony_ci id->target_bits = phy->identify.target_port_protocols; 31848c2ecf20Sopenharmony_ci } else if (phy->phy_type & PORT_TYPE_SATA) { 31858c2ecf20Sopenharmony_ci /*Nothing*/ 31868c2ecf20Sopenharmony_ci } 31878c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "phy %d byte dmaded.\n", i); 31888c2ecf20Sopenharmony_ci 31898c2ecf20Sopenharmony_ci sas_phy->frame_rcvd_size = phy->frame_rcvd_size; 31908c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_BYTES_DMAED); 31918c2ecf20Sopenharmony_ci} 31928c2ecf20Sopenharmony_ci 31938c2ecf20Sopenharmony_ci/* Get the link rate speed */ 31948c2ecf20Sopenharmony_civoid pm8001_get_lrate_mode(struct pm8001_phy *phy, u8 link_rate) 31958c2ecf20Sopenharmony_ci{ 31968c2ecf20Sopenharmony_ci struct sas_phy *sas_phy = phy->sas_phy.phy; 31978c2ecf20Sopenharmony_ci 31988c2ecf20Sopenharmony_ci switch (link_rate) { 31998c2ecf20Sopenharmony_ci case PHY_SPEED_120: 32008c2ecf20Sopenharmony_ci phy->sas_phy.linkrate = SAS_LINK_RATE_12_0_GBPS; 32018c2ecf20Sopenharmony_ci phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_12_0_GBPS; 32028c2ecf20Sopenharmony_ci break; 32038c2ecf20Sopenharmony_ci case PHY_SPEED_60: 32048c2ecf20Sopenharmony_ci phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS; 32058c2ecf20Sopenharmony_ci phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS; 32068c2ecf20Sopenharmony_ci break; 32078c2ecf20Sopenharmony_ci case PHY_SPEED_30: 32088c2ecf20Sopenharmony_ci phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS; 32098c2ecf20Sopenharmony_ci phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; 32108c2ecf20Sopenharmony_ci break; 32118c2ecf20Sopenharmony_ci case PHY_SPEED_15: 32128c2ecf20Sopenharmony_ci phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS; 32138c2ecf20Sopenharmony_ci phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS; 32148c2ecf20Sopenharmony_ci break; 32158c2ecf20Sopenharmony_ci } 32168c2ecf20Sopenharmony_ci sas_phy->negotiated_linkrate = phy->sas_phy.linkrate; 32178c2ecf20Sopenharmony_ci sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS; 32188c2ecf20Sopenharmony_ci sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; 32198c2ecf20Sopenharmony_ci sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS; 32208c2ecf20Sopenharmony_ci sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; 32218c2ecf20Sopenharmony_ci} 32228c2ecf20Sopenharmony_ci 32238c2ecf20Sopenharmony_ci/** 32248c2ecf20Sopenharmony_ci * asd_get_attached_sas_addr -- extract/generate attached SAS address 32258c2ecf20Sopenharmony_ci * @phy: pointer to asd_phy 32268c2ecf20Sopenharmony_ci * @sas_addr: pointer to buffer where the SAS address is to be written 32278c2ecf20Sopenharmony_ci * 32288c2ecf20Sopenharmony_ci * This function extracts the SAS address from an IDENTIFY frame 32298c2ecf20Sopenharmony_ci * received. If OOB is SATA, then a SAS address is generated from the 32308c2ecf20Sopenharmony_ci * HA tables. 32318c2ecf20Sopenharmony_ci * 32328c2ecf20Sopenharmony_ci * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame 32338c2ecf20Sopenharmony_ci * buffer. 32348c2ecf20Sopenharmony_ci */ 32358c2ecf20Sopenharmony_civoid pm8001_get_attached_sas_addr(struct pm8001_phy *phy, 32368c2ecf20Sopenharmony_ci u8 *sas_addr) 32378c2ecf20Sopenharmony_ci{ 32388c2ecf20Sopenharmony_ci if (phy->sas_phy.frame_rcvd[0] == 0x34 32398c2ecf20Sopenharmony_ci && phy->sas_phy.oob_mode == SATA_OOB_MODE) { 32408c2ecf20Sopenharmony_ci struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha; 32418c2ecf20Sopenharmony_ci /* FIS device-to-host */ 32428c2ecf20Sopenharmony_ci u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr); 32438c2ecf20Sopenharmony_ci addr += phy->sas_phy.id; 32448c2ecf20Sopenharmony_ci *(__be64 *)sas_addr = cpu_to_be64(addr); 32458c2ecf20Sopenharmony_ci } else { 32468c2ecf20Sopenharmony_ci struct sas_identify_frame *idframe = 32478c2ecf20Sopenharmony_ci (void *) phy->sas_phy.frame_rcvd; 32488c2ecf20Sopenharmony_ci memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE); 32498c2ecf20Sopenharmony_ci } 32508c2ecf20Sopenharmony_ci} 32518c2ecf20Sopenharmony_ci 32528c2ecf20Sopenharmony_ci/** 32538c2ecf20Sopenharmony_ci * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW. 32548c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 32558c2ecf20Sopenharmony_ci * @Qnum: the outbound queue message number. 32568c2ecf20Sopenharmony_ci * @SEA: source of event to ack 32578c2ecf20Sopenharmony_ci * @port_id: port id. 32588c2ecf20Sopenharmony_ci * @phyId: phy id. 32598c2ecf20Sopenharmony_ci * @param0: parameter 0. 32608c2ecf20Sopenharmony_ci * @param1: parameter 1. 32618c2ecf20Sopenharmony_ci */ 32628c2ecf20Sopenharmony_cistatic void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha, 32638c2ecf20Sopenharmony_ci u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1) 32648c2ecf20Sopenharmony_ci{ 32658c2ecf20Sopenharmony_ci struct hw_event_ack_req payload; 32668c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SAS_HW_EVENT_ACK; 32678c2ecf20Sopenharmony_ci 32688c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 32698c2ecf20Sopenharmony_ci 32708c2ecf20Sopenharmony_ci memset((u8 *)&payload, 0, sizeof(payload)); 32718c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[Qnum]; 32728c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(1); 32738c2ecf20Sopenharmony_ci payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) | 32748c2ecf20Sopenharmony_ci ((phyId & 0x0F) << 4) | (port_id & 0x0F)); 32758c2ecf20Sopenharmony_ci payload.param0 = cpu_to_le32(param0); 32768c2ecf20Sopenharmony_ci payload.param1 = cpu_to_le32(param1); 32778c2ecf20Sopenharmony_ci pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 32788c2ecf20Sopenharmony_ci sizeof(payload), 0); 32798c2ecf20Sopenharmony_ci} 32808c2ecf20Sopenharmony_ci 32818c2ecf20Sopenharmony_cistatic int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha, 32828c2ecf20Sopenharmony_ci u32 phyId, u32 phy_op); 32838c2ecf20Sopenharmony_ci 32848c2ecf20Sopenharmony_ci/** 32858c2ecf20Sopenharmony_ci * hw_event_sas_phy_up -FW tells me a SAS phy up event. 32868c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 32878c2ecf20Sopenharmony_ci * @piomb: IO message buffer 32888c2ecf20Sopenharmony_ci */ 32898c2ecf20Sopenharmony_cistatic void 32908c2ecf20Sopenharmony_cihw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb) 32918c2ecf20Sopenharmony_ci{ 32928c2ecf20Sopenharmony_ci struct hw_event_resp *pPayload = 32938c2ecf20Sopenharmony_ci (struct hw_event_resp *)(piomb + 4); 32948c2ecf20Sopenharmony_ci u32 lr_evt_status_phyid_portid = 32958c2ecf20Sopenharmony_ci le32_to_cpu(pPayload->lr_evt_status_phyid_portid); 32968c2ecf20Sopenharmony_ci u8 link_rate = 32978c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28); 32988c2ecf20Sopenharmony_ci u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); 32998c2ecf20Sopenharmony_ci u8 phy_id = 33008c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); 33018c2ecf20Sopenharmony_ci u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate); 33028c2ecf20Sopenharmony_ci u8 portstate = (u8)(npip_portstate & 0x0000000F); 33038c2ecf20Sopenharmony_ci struct pm8001_port *port = &pm8001_ha->port[port_id]; 33048c2ecf20Sopenharmony_ci struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; 33058c2ecf20Sopenharmony_ci unsigned long flags; 33068c2ecf20Sopenharmony_ci u8 deviceType = pPayload->sas_identify.dev_type; 33078c2ecf20Sopenharmony_ci port->port_state = portstate; 33088c2ecf20Sopenharmony_ci phy->phy_state = PHY_STATE_LINK_UP_SPC; 33098c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 33108c2ecf20Sopenharmony_ci "HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n", 33118c2ecf20Sopenharmony_ci port_id, phy_id); 33128c2ecf20Sopenharmony_ci 33138c2ecf20Sopenharmony_ci switch (deviceType) { 33148c2ecf20Sopenharmony_ci case SAS_PHY_UNUSED: 33158c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "device type no device.\n"); 33168c2ecf20Sopenharmony_ci break; 33178c2ecf20Sopenharmony_ci case SAS_END_DEVICE: 33188c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "end device.\n"); 33198c2ecf20Sopenharmony_ci pm8001_chip_phy_ctl_req(pm8001_ha, phy_id, 33208c2ecf20Sopenharmony_ci PHY_NOTIFY_ENABLE_SPINUP); 33218c2ecf20Sopenharmony_ci port->port_attached = 1; 33228c2ecf20Sopenharmony_ci pm8001_get_lrate_mode(phy, link_rate); 33238c2ecf20Sopenharmony_ci break; 33248c2ecf20Sopenharmony_ci case SAS_EDGE_EXPANDER_DEVICE: 33258c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "expander device.\n"); 33268c2ecf20Sopenharmony_ci port->port_attached = 1; 33278c2ecf20Sopenharmony_ci pm8001_get_lrate_mode(phy, link_rate); 33288c2ecf20Sopenharmony_ci break; 33298c2ecf20Sopenharmony_ci case SAS_FANOUT_EXPANDER_DEVICE: 33308c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "fanout expander device.\n"); 33318c2ecf20Sopenharmony_ci port->port_attached = 1; 33328c2ecf20Sopenharmony_ci pm8001_get_lrate_mode(phy, link_rate); 33338c2ecf20Sopenharmony_ci break; 33348c2ecf20Sopenharmony_ci default: 33358c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "unknown device type(%x)\n", 33368c2ecf20Sopenharmony_ci deviceType); 33378c2ecf20Sopenharmony_ci break; 33388c2ecf20Sopenharmony_ci } 33398c2ecf20Sopenharmony_ci phy->phy_type |= PORT_TYPE_SAS; 33408c2ecf20Sopenharmony_ci phy->identify.device_type = deviceType; 33418c2ecf20Sopenharmony_ci phy->phy_attached = 1; 33428c2ecf20Sopenharmony_ci if (phy->identify.device_type == SAS_END_DEVICE) 33438c2ecf20Sopenharmony_ci phy->identify.target_port_protocols = SAS_PROTOCOL_SSP; 33448c2ecf20Sopenharmony_ci else if (phy->identify.device_type != SAS_PHY_UNUSED) 33458c2ecf20Sopenharmony_ci phy->identify.target_port_protocols = SAS_PROTOCOL_SMP; 33468c2ecf20Sopenharmony_ci phy->sas_phy.oob_mode = SAS_OOB_MODE; 33478c2ecf20Sopenharmony_ci sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE); 33488c2ecf20Sopenharmony_ci spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags); 33498c2ecf20Sopenharmony_ci memcpy(phy->frame_rcvd, &pPayload->sas_identify, 33508c2ecf20Sopenharmony_ci sizeof(struct sas_identify_frame)-4); 33518c2ecf20Sopenharmony_ci phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4; 33528c2ecf20Sopenharmony_ci pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr); 33538c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags); 33548c2ecf20Sopenharmony_ci if (pm8001_ha->flags == PM8001F_RUN_TIME) 33558c2ecf20Sopenharmony_ci mdelay(200);/*delay a moment to wait disk to spinup*/ 33568c2ecf20Sopenharmony_ci pm8001_bytes_dmaed(pm8001_ha, phy_id); 33578c2ecf20Sopenharmony_ci} 33588c2ecf20Sopenharmony_ci 33598c2ecf20Sopenharmony_ci/** 33608c2ecf20Sopenharmony_ci * hw_event_sata_phy_up -FW tells me a SATA phy up event. 33618c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 33628c2ecf20Sopenharmony_ci * @piomb: IO message buffer 33638c2ecf20Sopenharmony_ci */ 33648c2ecf20Sopenharmony_cistatic void 33658c2ecf20Sopenharmony_cihw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb) 33668c2ecf20Sopenharmony_ci{ 33678c2ecf20Sopenharmony_ci struct hw_event_resp *pPayload = 33688c2ecf20Sopenharmony_ci (struct hw_event_resp *)(piomb + 4); 33698c2ecf20Sopenharmony_ci u32 lr_evt_status_phyid_portid = 33708c2ecf20Sopenharmony_ci le32_to_cpu(pPayload->lr_evt_status_phyid_portid); 33718c2ecf20Sopenharmony_ci u8 link_rate = 33728c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28); 33738c2ecf20Sopenharmony_ci u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); 33748c2ecf20Sopenharmony_ci u8 phy_id = 33758c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); 33768c2ecf20Sopenharmony_ci u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate); 33778c2ecf20Sopenharmony_ci u8 portstate = (u8)(npip_portstate & 0x0000000F); 33788c2ecf20Sopenharmony_ci struct pm8001_port *port = &pm8001_ha->port[port_id]; 33798c2ecf20Sopenharmony_ci struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; 33808c2ecf20Sopenharmony_ci unsigned long flags; 33818c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "HW_EVENT_SATA_PHY_UP port id = %d, phy id = %d\n", 33828c2ecf20Sopenharmony_ci port_id, phy_id); 33838c2ecf20Sopenharmony_ci port->port_state = portstate; 33848c2ecf20Sopenharmony_ci phy->phy_state = PHY_STATE_LINK_UP_SPC; 33858c2ecf20Sopenharmony_ci port->port_attached = 1; 33868c2ecf20Sopenharmony_ci pm8001_get_lrate_mode(phy, link_rate); 33878c2ecf20Sopenharmony_ci phy->phy_type |= PORT_TYPE_SATA; 33888c2ecf20Sopenharmony_ci phy->phy_attached = 1; 33898c2ecf20Sopenharmony_ci phy->sas_phy.oob_mode = SATA_OOB_MODE; 33908c2ecf20Sopenharmony_ci sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE); 33918c2ecf20Sopenharmony_ci spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags); 33928c2ecf20Sopenharmony_ci memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4), 33938c2ecf20Sopenharmony_ci sizeof(struct dev_to_host_fis)); 33948c2ecf20Sopenharmony_ci phy->frame_rcvd_size = sizeof(struct dev_to_host_fis); 33958c2ecf20Sopenharmony_ci phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; 33968c2ecf20Sopenharmony_ci phy->identify.device_type = SAS_SATA_DEV; 33978c2ecf20Sopenharmony_ci pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr); 33988c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags); 33998c2ecf20Sopenharmony_ci pm8001_bytes_dmaed(pm8001_ha, phy_id); 34008c2ecf20Sopenharmony_ci} 34018c2ecf20Sopenharmony_ci 34028c2ecf20Sopenharmony_ci/** 34038c2ecf20Sopenharmony_ci * hw_event_phy_down -we should notify the libsas the phy is down. 34048c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 34058c2ecf20Sopenharmony_ci * @piomb: IO message buffer 34068c2ecf20Sopenharmony_ci */ 34078c2ecf20Sopenharmony_cistatic void 34088c2ecf20Sopenharmony_cihw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb) 34098c2ecf20Sopenharmony_ci{ 34108c2ecf20Sopenharmony_ci struct hw_event_resp *pPayload = 34118c2ecf20Sopenharmony_ci (struct hw_event_resp *)(piomb + 4); 34128c2ecf20Sopenharmony_ci u32 lr_evt_status_phyid_portid = 34138c2ecf20Sopenharmony_ci le32_to_cpu(pPayload->lr_evt_status_phyid_portid); 34148c2ecf20Sopenharmony_ci u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); 34158c2ecf20Sopenharmony_ci u8 phy_id = 34168c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); 34178c2ecf20Sopenharmony_ci u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate); 34188c2ecf20Sopenharmony_ci u8 portstate = (u8)(npip_portstate & 0x0000000F); 34198c2ecf20Sopenharmony_ci struct pm8001_port *port = &pm8001_ha->port[port_id]; 34208c2ecf20Sopenharmony_ci struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; 34218c2ecf20Sopenharmony_ci port->port_state = portstate; 34228c2ecf20Sopenharmony_ci phy->phy_type = 0; 34238c2ecf20Sopenharmony_ci phy->identify.device_type = 0; 34248c2ecf20Sopenharmony_ci phy->phy_attached = 0; 34258c2ecf20Sopenharmony_ci memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE); 34268c2ecf20Sopenharmony_ci switch (portstate) { 34278c2ecf20Sopenharmony_ci case PORT_VALID: 34288c2ecf20Sopenharmony_ci break; 34298c2ecf20Sopenharmony_ci case PORT_INVALID: 34308c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, " PortInvalid portID %d\n", 34318c2ecf20Sopenharmony_ci port_id); 34328c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 34338c2ecf20Sopenharmony_ci " Last phy Down and port invalid\n"); 34348c2ecf20Sopenharmony_ci port->port_attached = 0; 34358c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN, 34368c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 34378c2ecf20Sopenharmony_ci break; 34388c2ecf20Sopenharmony_ci case PORT_IN_RESET: 34398c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, " Port In Reset portID %d\n", 34408c2ecf20Sopenharmony_ci port_id); 34418c2ecf20Sopenharmony_ci break; 34428c2ecf20Sopenharmony_ci case PORT_NOT_ESTABLISHED: 34438c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 34448c2ecf20Sopenharmony_ci " phy Down and PORT_NOT_ESTABLISHED\n"); 34458c2ecf20Sopenharmony_ci port->port_attached = 0; 34468c2ecf20Sopenharmony_ci break; 34478c2ecf20Sopenharmony_ci case PORT_LOSTCOMM: 34488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, " phy Down and PORT_LOSTCOMM\n"); 34498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 34508c2ecf20Sopenharmony_ci " Last phy Down and port invalid\n"); 34518c2ecf20Sopenharmony_ci port->port_attached = 0; 34528c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN, 34538c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 34548c2ecf20Sopenharmony_ci break; 34558c2ecf20Sopenharmony_ci default: 34568c2ecf20Sopenharmony_ci port->port_attached = 0; 34578c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, " phy Down and(default) = %x\n", 34588c2ecf20Sopenharmony_ci portstate); 34598c2ecf20Sopenharmony_ci break; 34608c2ecf20Sopenharmony_ci 34618c2ecf20Sopenharmony_ci } 34628c2ecf20Sopenharmony_ci} 34638c2ecf20Sopenharmony_ci 34648c2ecf20Sopenharmony_ci/** 34658c2ecf20Sopenharmony_ci * pm8001_mpi_reg_resp -process register device ID response. 34668c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 34678c2ecf20Sopenharmony_ci * @piomb: IO message buffer 34688c2ecf20Sopenharmony_ci * 34698c2ecf20Sopenharmony_ci * when sas layer find a device it will notify LLDD, then the driver register 34708c2ecf20Sopenharmony_ci * the domain device to FW, this event is the return device ID which the FW 34718c2ecf20Sopenharmony_ci * has assigned, from now,inter-communication with FW is no longer using the 34728c2ecf20Sopenharmony_ci * SAS address, use device ID which FW assigned. 34738c2ecf20Sopenharmony_ci */ 34748c2ecf20Sopenharmony_ciint pm8001_mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) 34758c2ecf20Sopenharmony_ci{ 34768c2ecf20Sopenharmony_ci u32 status; 34778c2ecf20Sopenharmony_ci u32 device_id; 34788c2ecf20Sopenharmony_ci u32 htag; 34798c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 34808c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 34818c2ecf20Sopenharmony_ci struct dev_reg_resp *registerRespPayload = 34828c2ecf20Sopenharmony_ci (struct dev_reg_resp *)(piomb + 4); 34838c2ecf20Sopenharmony_ci 34848c2ecf20Sopenharmony_ci htag = le32_to_cpu(registerRespPayload->tag); 34858c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[htag]; 34868c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; 34878c2ecf20Sopenharmony_ci status = le32_to_cpu(registerRespPayload->status); 34888c2ecf20Sopenharmony_ci device_id = le32_to_cpu(registerRespPayload->device_id); 34898c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, " register device is status = %d\n", 34908c2ecf20Sopenharmony_ci status); 34918c2ecf20Sopenharmony_ci switch (status) { 34928c2ecf20Sopenharmony_ci case DEVREG_SUCCESS: 34938c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "DEVREG_SUCCESS\n"); 34948c2ecf20Sopenharmony_ci pm8001_dev->device_id = device_id; 34958c2ecf20Sopenharmony_ci break; 34968c2ecf20Sopenharmony_ci case DEVREG_FAILURE_OUT_OF_RESOURCE: 34978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_OUT_OF_RESOURCE\n"); 34988c2ecf20Sopenharmony_ci break; 34998c2ecf20Sopenharmony_ci case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED: 35008c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35018c2ecf20Sopenharmony_ci "DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n"); 35028c2ecf20Sopenharmony_ci break; 35038c2ecf20Sopenharmony_ci case DEVREG_FAILURE_INVALID_PHY_ID: 35048c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "DEVREG_FAILURE_INVALID_PHY_ID\n"); 35058c2ecf20Sopenharmony_ci break; 35068c2ecf20Sopenharmony_ci case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED: 35078c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35088c2ecf20Sopenharmony_ci "DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n"); 35098c2ecf20Sopenharmony_ci break; 35108c2ecf20Sopenharmony_ci case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE: 35118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35128c2ecf20Sopenharmony_ci "DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n"); 35138c2ecf20Sopenharmony_ci break; 35148c2ecf20Sopenharmony_ci case DEVREG_FAILURE_PORT_NOT_VALID_STATE: 35158c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35168c2ecf20Sopenharmony_ci "DEVREG_FAILURE_PORT_NOT_VALID_STATE\n"); 35178c2ecf20Sopenharmony_ci break; 35188c2ecf20Sopenharmony_ci case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID: 35198c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35208c2ecf20Sopenharmony_ci "DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n"); 35218c2ecf20Sopenharmony_ci break; 35228c2ecf20Sopenharmony_ci default: 35238c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35248c2ecf20Sopenharmony_ci "DEVREG_FAILURE_DEVICE_TYPE_NOT_SUPPORTED\n"); 35258c2ecf20Sopenharmony_ci break; 35268c2ecf20Sopenharmony_ci } 35278c2ecf20Sopenharmony_ci complete(pm8001_dev->dcompletion); 35288c2ecf20Sopenharmony_ci ccb->task = NULL; 35298c2ecf20Sopenharmony_ci ccb->ccb_tag = 0xFFFFFFFF; 35308c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, htag); 35318c2ecf20Sopenharmony_ci return 0; 35328c2ecf20Sopenharmony_ci} 35338c2ecf20Sopenharmony_ci 35348c2ecf20Sopenharmony_ciint pm8001_mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) 35358c2ecf20Sopenharmony_ci{ 35368c2ecf20Sopenharmony_ci u32 status; 35378c2ecf20Sopenharmony_ci u32 device_id; 35388c2ecf20Sopenharmony_ci struct dev_reg_resp *registerRespPayload = 35398c2ecf20Sopenharmony_ci (struct dev_reg_resp *)(piomb + 4); 35408c2ecf20Sopenharmony_ci 35418c2ecf20Sopenharmony_ci status = le32_to_cpu(registerRespPayload->status); 35428c2ecf20Sopenharmony_ci device_id = le32_to_cpu(registerRespPayload->device_id); 35438c2ecf20Sopenharmony_ci if (status != 0) 35448c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35458c2ecf20Sopenharmony_ci " deregister device failed ,status = %x, device_id = %x\n", 35468c2ecf20Sopenharmony_ci status, device_id); 35478c2ecf20Sopenharmony_ci return 0; 35488c2ecf20Sopenharmony_ci} 35498c2ecf20Sopenharmony_ci 35508c2ecf20Sopenharmony_ci/** 35518c2ecf20Sopenharmony_ci * fw_flash_update_resp - Response from FW for flash update command. 35528c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 35538c2ecf20Sopenharmony_ci * @piomb: IO message buffer 35548c2ecf20Sopenharmony_ci */ 35558c2ecf20Sopenharmony_ciint pm8001_mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha, 35568c2ecf20Sopenharmony_ci void *piomb) 35578c2ecf20Sopenharmony_ci{ 35588c2ecf20Sopenharmony_ci u32 status; 35598c2ecf20Sopenharmony_ci struct fw_flash_Update_resp *ppayload = 35608c2ecf20Sopenharmony_ci (struct fw_flash_Update_resp *)(piomb + 4); 35618c2ecf20Sopenharmony_ci u32 tag = le32_to_cpu(ppayload->tag); 35628c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; 35638c2ecf20Sopenharmony_ci status = le32_to_cpu(ppayload->status); 35648c2ecf20Sopenharmony_ci switch (status) { 35658c2ecf20Sopenharmony_ci case FLASH_UPDATE_COMPLETE_PENDING_REBOOT: 35668c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35678c2ecf20Sopenharmony_ci ": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n"); 35688c2ecf20Sopenharmony_ci break; 35698c2ecf20Sopenharmony_ci case FLASH_UPDATE_IN_PROGRESS: 35708c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_IN_PROGRESS\n"); 35718c2ecf20Sopenharmony_ci break; 35728c2ecf20Sopenharmony_ci case FLASH_UPDATE_HDR_ERR: 35738c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HDR_ERR\n"); 35748c2ecf20Sopenharmony_ci break; 35758c2ecf20Sopenharmony_ci case FLASH_UPDATE_OFFSET_ERR: 35768c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_OFFSET_ERR\n"); 35778c2ecf20Sopenharmony_ci break; 35788c2ecf20Sopenharmony_ci case FLASH_UPDATE_CRC_ERR: 35798c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_CRC_ERR\n"); 35808c2ecf20Sopenharmony_ci break; 35818c2ecf20Sopenharmony_ci case FLASH_UPDATE_LENGTH_ERR: 35828c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_LENGTH_ERR\n"); 35838c2ecf20Sopenharmony_ci break; 35848c2ecf20Sopenharmony_ci case FLASH_UPDATE_HW_ERR: 35858c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_HW_ERR\n"); 35868c2ecf20Sopenharmony_ci break; 35878c2ecf20Sopenharmony_ci case FLASH_UPDATE_DNLD_NOT_SUPPORTED: 35888c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 35898c2ecf20Sopenharmony_ci ": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n"); 35908c2ecf20Sopenharmony_ci break; 35918c2ecf20Sopenharmony_ci case FLASH_UPDATE_DISABLED: 35928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, ": FLASH_UPDATE_DISABLED\n"); 35938c2ecf20Sopenharmony_ci break; 35948c2ecf20Sopenharmony_ci default: 35958c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "No matched status = %d\n", 35968c2ecf20Sopenharmony_ci status); 35978c2ecf20Sopenharmony_ci break; 35988c2ecf20Sopenharmony_ci } 35998c2ecf20Sopenharmony_ci kfree(ccb->fw_control_context); 36008c2ecf20Sopenharmony_ci ccb->task = NULL; 36018c2ecf20Sopenharmony_ci ccb->ccb_tag = 0xFFFFFFFF; 36028c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 36038c2ecf20Sopenharmony_ci complete(pm8001_ha->nvmd_completion); 36048c2ecf20Sopenharmony_ci return 0; 36058c2ecf20Sopenharmony_ci} 36068c2ecf20Sopenharmony_ci 36078c2ecf20Sopenharmony_ciint pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb) 36088c2ecf20Sopenharmony_ci{ 36098c2ecf20Sopenharmony_ci u32 status; 36108c2ecf20Sopenharmony_ci int i; 36118c2ecf20Sopenharmony_ci struct general_event_resp *pPayload = 36128c2ecf20Sopenharmony_ci (struct general_event_resp *)(piomb + 4); 36138c2ecf20Sopenharmony_ci status = le32_to_cpu(pPayload->status); 36148c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, " status = 0x%x\n", status); 36158c2ecf20Sopenharmony_ci for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++) 36168c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "inb_IOMB_payload[0x%x] 0x%x,\n", 36178c2ecf20Sopenharmony_ci i, 36188c2ecf20Sopenharmony_ci pPayload->inb_IOMB_payload[i]); 36198c2ecf20Sopenharmony_ci return 0; 36208c2ecf20Sopenharmony_ci} 36218c2ecf20Sopenharmony_ci 36228c2ecf20Sopenharmony_ciint pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) 36238c2ecf20Sopenharmony_ci{ 36248c2ecf20Sopenharmony_ci struct sas_task *t; 36258c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 36268c2ecf20Sopenharmony_ci unsigned long flags; 36278c2ecf20Sopenharmony_ci u32 status ; 36288c2ecf20Sopenharmony_ci u32 tag, scp; 36298c2ecf20Sopenharmony_ci struct task_status_struct *ts; 36308c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev; 36318c2ecf20Sopenharmony_ci 36328c2ecf20Sopenharmony_ci struct task_abort_resp *pPayload = 36338c2ecf20Sopenharmony_ci (struct task_abort_resp *)(piomb + 4); 36348c2ecf20Sopenharmony_ci 36358c2ecf20Sopenharmony_ci status = le32_to_cpu(pPayload->status); 36368c2ecf20Sopenharmony_ci tag = le32_to_cpu(pPayload->tag); 36378c2ecf20Sopenharmony_ci if (!tag) { 36388c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, " TAG NULL. RETURNING !!!\n"); 36398c2ecf20Sopenharmony_ci return -1; 36408c2ecf20Sopenharmony_ci } 36418c2ecf20Sopenharmony_ci 36428c2ecf20Sopenharmony_ci scp = le32_to_cpu(pPayload->scp); 36438c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 36448c2ecf20Sopenharmony_ci t = ccb->task; 36458c2ecf20Sopenharmony_ci pm8001_dev = ccb->device; /* retrieve device */ 36468c2ecf20Sopenharmony_ci 36478c2ecf20Sopenharmony_ci if (!t) { 36488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, " TASK NULL. RETURNING !!!\n"); 36498c2ecf20Sopenharmony_ci return -1; 36508c2ecf20Sopenharmony_ci } 36518c2ecf20Sopenharmony_ci ts = &t->task_status; 36528c2ecf20Sopenharmony_ci if (status != 0) 36538c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, "task abort failed status 0x%x ,tag = 0x%x, scp= 0x%x\n", 36548c2ecf20Sopenharmony_ci status, tag, scp); 36558c2ecf20Sopenharmony_ci switch (status) { 36568c2ecf20Sopenharmony_ci case IO_SUCCESS: 36578c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, EH, "IO_SUCCESS\n"); 36588c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 36598c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_GOOD; 36608c2ecf20Sopenharmony_ci break; 36618c2ecf20Sopenharmony_ci case IO_NOT_VALID: 36628c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, EH, "IO_NOT_VALID\n"); 36638c2ecf20Sopenharmony_ci ts->resp = TMF_RESP_FUNC_FAILED; 36648c2ecf20Sopenharmony_ci break; 36658c2ecf20Sopenharmony_ci } 36668c2ecf20Sopenharmony_ci spin_lock_irqsave(&t->task_state_lock, flags); 36678c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_STATE_PENDING; 36688c2ecf20Sopenharmony_ci t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 36698c2ecf20Sopenharmony_ci t->task_state_flags |= SAS_TASK_STATE_DONE; 36708c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&t->task_state_lock, flags); 36718c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); 36728c2ecf20Sopenharmony_ci mb(); 36738c2ecf20Sopenharmony_ci 36748c2ecf20Sopenharmony_ci if (pm8001_dev->id & NCQ_ABORT_ALL_FLAG) { 36758c2ecf20Sopenharmony_ci sas_free_task(t); 36768c2ecf20Sopenharmony_ci pm8001_dev->id &= ~NCQ_ABORT_ALL_FLAG; 36778c2ecf20Sopenharmony_ci } else { 36788c2ecf20Sopenharmony_ci t->task_done(t); 36798c2ecf20Sopenharmony_ci } 36808c2ecf20Sopenharmony_ci 36818c2ecf20Sopenharmony_ci return 0; 36828c2ecf20Sopenharmony_ci} 36838c2ecf20Sopenharmony_ci 36848c2ecf20Sopenharmony_ci/** 36858c2ecf20Sopenharmony_ci * mpi_hw_event -The hw event has come. 36868c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 36878c2ecf20Sopenharmony_ci * @piomb: IO message buffer 36888c2ecf20Sopenharmony_ci */ 36898c2ecf20Sopenharmony_cistatic int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb) 36908c2ecf20Sopenharmony_ci{ 36918c2ecf20Sopenharmony_ci unsigned long flags; 36928c2ecf20Sopenharmony_ci struct hw_event_resp *pPayload = 36938c2ecf20Sopenharmony_ci (struct hw_event_resp *)(piomb + 4); 36948c2ecf20Sopenharmony_ci u32 lr_evt_status_phyid_portid = 36958c2ecf20Sopenharmony_ci le32_to_cpu(pPayload->lr_evt_status_phyid_portid); 36968c2ecf20Sopenharmony_ci u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); 36978c2ecf20Sopenharmony_ci u8 phy_id = 36988c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); 36998c2ecf20Sopenharmony_ci u16 eventType = 37008c2ecf20Sopenharmony_ci (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8); 37018c2ecf20Sopenharmony_ci u8 status = 37028c2ecf20Sopenharmony_ci (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24); 37038c2ecf20Sopenharmony_ci struct sas_ha_struct *sas_ha = pm8001_ha->sas; 37048c2ecf20Sopenharmony_ci struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; 37058c2ecf20Sopenharmony_ci struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; 37068c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 37078c2ecf20Sopenharmony_ci "SPC HW event for portid:%d, phyid:%d, event:%x, status:%x\n", 37088c2ecf20Sopenharmony_ci port_id, phy_id, eventType, status); 37098c2ecf20Sopenharmony_ci switch (eventType) { 37108c2ecf20Sopenharmony_ci case HW_EVENT_PHY_START_STATUS: 37118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS status = %x\n", 37128c2ecf20Sopenharmony_ci status); 37138c2ecf20Sopenharmony_ci if (status == 0) 37148c2ecf20Sopenharmony_ci phy->phy_state = 1; 37158c2ecf20Sopenharmony_ci 37168c2ecf20Sopenharmony_ci if (pm8001_ha->flags == PM8001F_RUN_TIME && 37178c2ecf20Sopenharmony_ci phy->enable_completion != NULL) { 37188c2ecf20Sopenharmony_ci complete(phy->enable_completion); 37198c2ecf20Sopenharmony_ci phy->enable_completion = NULL; 37208c2ecf20Sopenharmony_ci } 37218c2ecf20Sopenharmony_ci break; 37228c2ecf20Sopenharmony_ci case HW_EVENT_SAS_PHY_UP: 37238c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_START_STATUS\n"); 37248c2ecf20Sopenharmony_ci hw_event_sas_phy_up(pm8001_ha, piomb); 37258c2ecf20Sopenharmony_ci break; 37268c2ecf20Sopenharmony_ci case HW_EVENT_SATA_PHY_UP: 37278c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_PHY_UP\n"); 37288c2ecf20Sopenharmony_ci hw_event_sata_phy_up(pm8001_ha, piomb); 37298c2ecf20Sopenharmony_ci break; 37308c2ecf20Sopenharmony_ci case HW_EVENT_PHY_STOP_STATUS: 37318c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_STOP_STATUS status = %x\n", 37328c2ecf20Sopenharmony_ci status); 37338c2ecf20Sopenharmony_ci if (status == 0) 37348c2ecf20Sopenharmony_ci phy->phy_state = 0; 37358c2ecf20Sopenharmony_ci break; 37368c2ecf20Sopenharmony_ci case HW_EVENT_SATA_SPINUP_HOLD: 37378c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_SATA_SPINUP_HOLD\n"); 37388c2ecf20Sopenharmony_ci sas_notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD); 37398c2ecf20Sopenharmony_ci break; 37408c2ecf20Sopenharmony_ci case HW_EVENT_PHY_DOWN: 37418c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_DOWN\n"); 37428c2ecf20Sopenharmony_ci sas_notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL); 37438c2ecf20Sopenharmony_ci phy->phy_attached = 0; 37448c2ecf20Sopenharmony_ci phy->phy_state = 0; 37458c2ecf20Sopenharmony_ci hw_event_phy_down(pm8001_ha, piomb); 37468c2ecf20Sopenharmony_ci break; 37478c2ecf20Sopenharmony_ci case HW_EVENT_PORT_INVALID: 37488c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_INVALID\n"); 37498c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 37508c2ecf20Sopenharmony_ci phy->phy_attached = 0; 37518c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 37528c2ecf20Sopenharmony_ci break; 37538c2ecf20Sopenharmony_ci /* the broadcast change primitive received, tell the LIBSAS this event 37548c2ecf20Sopenharmony_ci to revalidate the sas domain*/ 37558c2ecf20Sopenharmony_ci case HW_EVENT_BROADCAST_CHANGE: 37568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_CHANGE\n"); 37578c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE, 37588c2ecf20Sopenharmony_ci port_id, phy_id, 1, 0); 37598c2ecf20Sopenharmony_ci spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); 37608c2ecf20Sopenharmony_ci sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE; 37618c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); 37628c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); 37638c2ecf20Sopenharmony_ci break; 37648c2ecf20Sopenharmony_ci case HW_EVENT_PHY_ERROR: 37658c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PHY_ERROR\n"); 37668c2ecf20Sopenharmony_ci sas_phy_disconnected(&phy->sas_phy); 37678c2ecf20Sopenharmony_ci phy->phy_attached = 0; 37688c2ecf20Sopenharmony_ci sas_notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR); 37698c2ecf20Sopenharmony_ci break; 37708c2ecf20Sopenharmony_ci case HW_EVENT_BROADCAST_EXP: 37718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_EXP\n"); 37728c2ecf20Sopenharmony_ci spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); 37738c2ecf20Sopenharmony_ci sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP; 37748c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); 37758c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); 37768c2ecf20Sopenharmony_ci break; 37778c2ecf20Sopenharmony_ci case HW_EVENT_LINK_ERR_INVALID_DWORD: 37788c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 37798c2ecf20Sopenharmony_ci "HW_EVENT_LINK_ERR_INVALID_DWORD\n"); 37808c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, 37818c2ecf20Sopenharmony_ci HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0); 37828c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 37838c2ecf20Sopenharmony_ci phy->phy_attached = 0; 37848c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 37858c2ecf20Sopenharmony_ci break; 37868c2ecf20Sopenharmony_ci case HW_EVENT_LINK_ERR_DISPARITY_ERROR: 37878c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 37888c2ecf20Sopenharmony_ci "HW_EVENT_LINK_ERR_DISPARITY_ERROR\n"); 37898c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, 37908c2ecf20Sopenharmony_ci HW_EVENT_LINK_ERR_DISPARITY_ERROR, 37918c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 37928c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 37938c2ecf20Sopenharmony_ci phy->phy_attached = 0; 37948c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 37958c2ecf20Sopenharmony_ci break; 37968c2ecf20Sopenharmony_ci case HW_EVENT_LINK_ERR_CODE_VIOLATION: 37978c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 37988c2ecf20Sopenharmony_ci "HW_EVENT_LINK_ERR_CODE_VIOLATION\n"); 37998c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, 38008c2ecf20Sopenharmony_ci HW_EVENT_LINK_ERR_CODE_VIOLATION, 38018c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 38028c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 38038c2ecf20Sopenharmony_ci phy->phy_attached = 0; 38048c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 38058c2ecf20Sopenharmony_ci break; 38068c2ecf20Sopenharmony_ci case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH: 38078c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 38088c2ecf20Sopenharmony_ci "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n"); 38098c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, 38108c2ecf20Sopenharmony_ci HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH, 38118c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 38128c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 38138c2ecf20Sopenharmony_ci phy->phy_attached = 0; 38148c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 38158c2ecf20Sopenharmony_ci break; 38168c2ecf20Sopenharmony_ci case HW_EVENT_MALFUNCTION: 38178c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_MALFUNCTION\n"); 38188c2ecf20Sopenharmony_ci break; 38198c2ecf20Sopenharmony_ci case HW_EVENT_BROADCAST_SES: 38208c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_BROADCAST_SES\n"); 38218c2ecf20Sopenharmony_ci spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); 38228c2ecf20Sopenharmony_ci sas_phy->sas_prim = HW_EVENT_BROADCAST_SES; 38238c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); 38248c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); 38258c2ecf20Sopenharmony_ci break; 38268c2ecf20Sopenharmony_ci case HW_EVENT_INBOUND_CRC_ERROR: 38278c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_INBOUND_CRC_ERROR\n"); 38288c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, 38298c2ecf20Sopenharmony_ci HW_EVENT_INBOUND_CRC_ERROR, 38308c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 38318c2ecf20Sopenharmony_ci break; 38328c2ecf20Sopenharmony_ci case HW_EVENT_HARD_RESET_RECEIVED: 38338c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_HARD_RESET_RECEIVED\n"); 38348c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_HARD_RESET); 38358c2ecf20Sopenharmony_ci break; 38368c2ecf20Sopenharmony_ci case HW_EVENT_ID_FRAME_TIMEOUT: 38378c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_ID_FRAME_TIMEOUT\n"); 38388c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 38398c2ecf20Sopenharmony_ci phy->phy_attached = 0; 38408c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 38418c2ecf20Sopenharmony_ci break; 38428c2ecf20Sopenharmony_ci case HW_EVENT_LINK_ERR_PHY_RESET_FAILED: 38438c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 38448c2ecf20Sopenharmony_ci "HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n"); 38458c2ecf20Sopenharmony_ci pm8001_hw_event_ack_req(pm8001_ha, 0, 38468c2ecf20Sopenharmony_ci HW_EVENT_LINK_ERR_PHY_RESET_FAILED, 38478c2ecf20Sopenharmony_ci port_id, phy_id, 0, 0); 38488c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 38498c2ecf20Sopenharmony_ci phy->phy_attached = 0; 38508c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 38518c2ecf20Sopenharmony_ci break; 38528c2ecf20Sopenharmony_ci case HW_EVENT_PORT_RESET_TIMER_TMO: 38538c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_TIMER_TMO\n"); 38548c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 38558c2ecf20Sopenharmony_ci phy->phy_attached = 0; 38568c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 38578c2ecf20Sopenharmony_ci break; 38588c2ecf20Sopenharmony_ci case HW_EVENT_PORT_RECOVERY_TIMER_TMO: 38598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 38608c2ecf20Sopenharmony_ci "HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"); 38618c2ecf20Sopenharmony_ci sas_phy_disconnected(sas_phy); 38628c2ecf20Sopenharmony_ci phy->phy_attached = 0; 38638c2ecf20Sopenharmony_ci sas_notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); 38648c2ecf20Sopenharmony_ci break; 38658c2ecf20Sopenharmony_ci case HW_EVENT_PORT_RECOVER: 38668c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RECOVER\n"); 38678c2ecf20Sopenharmony_ci break; 38688c2ecf20Sopenharmony_ci case HW_EVENT_PORT_RESET_COMPLETE: 38698c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "HW_EVENT_PORT_RESET_COMPLETE\n"); 38708c2ecf20Sopenharmony_ci break; 38718c2ecf20Sopenharmony_ci case EVENT_BROADCAST_ASYNCH_EVENT: 38728c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "EVENT_BROADCAST_ASYNCH_EVENT\n"); 38738c2ecf20Sopenharmony_ci break; 38748c2ecf20Sopenharmony_ci default: 38758c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, "Unknown event type = %x\n", 38768c2ecf20Sopenharmony_ci eventType); 38778c2ecf20Sopenharmony_ci break; 38788c2ecf20Sopenharmony_ci } 38798c2ecf20Sopenharmony_ci return 0; 38808c2ecf20Sopenharmony_ci} 38818c2ecf20Sopenharmony_ci 38828c2ecf20Sopenharmony_ci/** 38838c2ecf20Sopenharmony_ci * process_one_iomb - process one outbound Queue memory block 38848c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information 38858c2ecf20Sopenharmony_ci * @piomb: IO message buffer 38868c2ecf20Sopenharmony_ci */ 38878c2ecf20Sopenharmony_cistatic void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb) 38888c2ecf20Sopenharmony_ci{ 38898c2ecf20Sopenharmony_ci __le32 pHeader = *(__le32 *)piomb; 38908c2ecf20Sopenharmony_ci u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF); 38918c2ecf20Sopenharmony_ci 38928c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "process_one_iomb:\n"); 38938c2ecf20Sopenharmony_ci 38948c2ecf20Sopenharmony_ci switch (opc) { 38958c2ecf20Sopenharmony_ci case OPC_OUB_ECHO: 38968c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_ECHO\n"); 38978c2ecf20Sopenharmony_ci break; 38988c2ecf20Sopenharmony_ci case OPC_OUB_HW_EVENT: 38998c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_HW_EVENT\n"); 39008c2ecf20Sopenharmony_ci mpi_hw_event(pm8001_ha, piomb); 39018c2ecf20Sopenharmony_ci break; 39028c2ecf20Sopenharmony_ci case OPC_OUB_SSP_COMP: 39038c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_COMP\n"); 39048c2ecf20Sopenharmony_ci mpi_ssp_completion(pm8001_ha, piomb); 39058c2ecf20Sopenharmony_ci break; 39068c2ecf20Sopenharmony_ci case OPC_OUB_SMP_COMP: 39078c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_COMP\n"); 39088c2ecf20Sopenharmony_ci mpi_smp_completion(pm8001_ha, piomb); 39098c2ecf20Sopenharmony_ci break; 39108c2ecf20Sopenharmony_ci case OPC_OUB_LOCAL_PHY_CNTRL: 39118c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_LOCAL_PHY_CNTRL\n"); 39128c2ecf20Sopenharmony_ci pm8001_mpi_local_phy_ctl(pm8001_ha, piomb); 39138c2ecf20Sopenharmony_ci break; 39148c2ecf20Sopenharmony_ci case OPC_OUB_DEV_REGIST: 39158c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_REGIST\n"); 39168c2ecf20Sopenharmony_ci pm8001_mpi_reg_resp(pm8001_ha, piomb); 39178c2ecf20Sopenharmony_ci break; 39188c2ecf20Sopenharmony_ci case OPC_OUB_DEREG_DEV: 39198c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "unregister the device\n"); 39208c2ecf20Sopenharmony_ci pm8001_mpi_dereg_resp(pm8001_ha, piomb); 39218c2ecf20Sopenharmony_ci break; 39228c2ecf20Sopenharmony_ci case OPC_OUB_GET_DEV_HANDLE: 39238c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEV_HANDLE\n"); 39248c2ecf20Sopenharmony_ci break; 39258c2ecf20Sopenharmony_ci case OPC_OUB_SATA_COMP: 39268c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_COMP\n"); 39278c2ecf20Sopenharmony_ci mpi_sata_completion(pm8001_ha, piomb); 39288c2ecf20Sopenharmony_ci break; 39298c2ecf20Sopenharmony_ci case OPC_OUB_SATA_EVENT: 39308c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_EVENT\n"); 39318c2ecf20Sopenharmony_ci mpi_sata_event(pm8001_ha, piomb); 39328c2ecf20Sopenharmony_ci break; 39338c2ecf20Sopenharmony_ci case OPC_OUB_SSP_EVENT: 39348c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_EVENT\n"); 39358c2ecf20Sopenharmony_ci mpi_ssp_event(pm8001_ha, piomb); 39368c2ecf20Sopenharmony_ci break; 39378c2ecf20Sopenharmony_ci case OPC_OUB_DEV_HANDLE_ARRIV: 39388c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_HANDLE_ARRIV\n"); 39398c2ecf20Sopenharmony_ci /*This is for target*/ 39408c2ecf20Sopenharmony_ci break; 39418c2ecf20Sopenharmony_ci case OPC_OUB_SSP_RECV_EVENT: 39428c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_RECV_EVENT\n"); 39438c2ecf20Sopenharmony_ci /*This is for target*/ 39448c2ecf20Sopenharmony_ci break; 39458c2ecf20Sopenharmony_ci case OPC_OUB_DEV_INFO: 39468c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEV_INFO\n"); 39478c2ecf20Sopenharmony_ci break; 39488c2ecf20Sopenharmony_ci case OPC_OUB_FW_FLASH_UPDATE: 39498c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_FW_FLASH_UPDATE\n"); 39508c2ecf20Sopenharmony_ci pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb); 39518c2ecf20Sopenharmony_ci break; 39528c2ecf20Sopenharmony_ci case OPC_OUB_GPIO_RESPONSE: 39538c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_RESPONSE\n"); 39548c2ecf20Sopenharmony_ci break; 39558c2ecf20Sopenharmony_ci case OPC_OUB_GPIO_EVENT: 39568c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GPIO_EVENT\n"); 39578c2ecf20Sopenharmony_ci break; 39588c2ecf20Sopenharmony_ci case OPC_OUB_GENERAL_EVENT: 39598c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GENERAL_EVENT\n"); 39608c2ecf20Sopenharmony_ci pm8001_mpi_general_event(pm8001_ha, piomb); 39618c2ecf20Sopenharmony_ci break; 39628c2ecf20Sopenharmony_ci case OPC_OUB_SSP_ABORT_RSP: 39638c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SSP_ABORT_RSP\n"); 39648c2ecf20Sopenharmony_ci pm8001_mpi_task_abort_resp(pm8001_ha, piomb); 39658c2ecf20Sopenharmony_ci break; 39668c2ecf20Sopenharmony_ci case OPC_OUB_SATA_ABORT_RSP: 39678c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SATA_ABORT_RSP\n"); 39688c2ecf20Sopenharmony_ci pm8001_mpi_task_abort_resp(pm8001_ha, piomb); 39698c2ecf20Sopenharmony_ci break; 39708c2ecf20Sopenharmony_ci case OPC_OUB_SAS_DIAG_MODE_START_END: 39718c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, 39728c2ecf20Sopenharmony_ci "OPC_OUB_SAS_DIAG_MODE_START_END\n"); 39738c2ecf20Sopenharmony_ci break; 39748c2ecf20Sopenharmony_ci case OPC_OUB_SAS_DIAG_EXECUTE: 39758c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_DIAG_EXECUTE\n"); 39768c2ecf20Sopenharmony_ci break; 39778c2ecf20Sopenharmony_ci case OPC_OUB_GET_TIME_STAMP: 39788c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_TIME_STAMP\n"); 39798c2ecf20Sopenharmony_ci break; 39808c2ecf20Sopenharmony_ci case OPC_OUB_SAS_HW_EVENT_ACK: 39818c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_HW_EVENT_ACK\n"); 39828c2ecf20Sopenharmony_ci break; 39838c2ecf20Sopenharmony_ci case OPC_OUB_PORT_CONTROL: 39848c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_PORT_CONTROL\n"); 39858c2ecf20Sopenharmony_ci break; 39868c2ecf20Sopenharmony_ci case OPC_OUB_SMP_ABORT_RSP: 39878c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SMP_ABORT_RSP\n"); 39888c2ecf20Sopenharmony_ci pm8001_mpi_task_abort_resp(pm8001_ha, piomb); 39898c2ecf20Sopenharmony_ci break; 39908c2ecf20Sopenharmony_ci case OPC_OUB_GET_NVMD_DATA: 39918c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_NVMD_DATA\n"); 39928c2ecf20Sopenharmony_ci pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb); 39938c2ecf20Sopenharmony_ci break; 39948c2ecf20Sopenharmony_ci case OPC_OUB_SET_NVMD_DATA: 39958c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_NVMD_DATA\n"); 39968c2ecf20Sopenharmony_ci pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb); 39978c2ecf20Sopenharmony_ci break; 39988c2ecf20Sopenharmony_ci case OPC_OUB_DEVICE_HANDLE_REMOVAL: 39998c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_DEVICE_HANDLE_REMOVAL\n"); 40008c2ecf20Sopenharmony_ci break; 40018c2ecf20Sopenharmony_ci case OPC_OUB_SET_DEVICE_STATE: 40028c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEVICE_STATE\n"); 40038c2ecf20Sopenharmony_ci pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb); 40048c2ecf20Sopenharmony_ci break; 40058c2ecf20Sopenharmony_ci case OPC_OUB_GET_DEVICE_STATE: 40068c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_GET_DEVICE_STATE\n"); 40078c2ecf20Sopenharmony_ci break; 40088c2ecf20Sopenharmony_ci case OPC_OUB_SET_DEV_INFO: 40098c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SET_DEV_INFO\n"); 40108c2ecf20Sopenharmony_ci break; 40118c2ecf20Sopenharmony_ci case OPC_OUB_SAS_RE_INITIALIZE: 40128c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "OPC_OUB_SAS_RE_INITIALIZE\n"); 40138c2ecf20Sopenharmony_ci break; 40148c2ecf20Sopenharmony_ci default: 40158c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 40168c2ecf20Sopenharmony_ci "Unknown outbound Queue IOMB OPC = %x\n", 40178c2ecf20Sopenharmony_ci opc); 40188c2ecf20Sopenharmony_ci break; 40198c2ecf20Sopenharmony_ci } 40208c2ecf20Sopenharmony_ci} 40218c2ecf20Sopenharmony_ci 40228c2ecf20Sopenharmony_cistatic int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec) 40238c2ecf20Sopenharmony_ci{ 40248c2ecf20Sopenharmony_ci struct outbound_queue_table *circularQ; 40258c2ecf20Sopenharmony_ci void *pMsg1 = NULL; 40268c2ecf20Sopenharmony_ci u8 bc; 40278c2ecf20Sopenharmony_ci u32 ret = MPI_IO_STATUS_FAIL; 40288c2ecf20Sopenharmony_ci unsigned long flags; 40298c2ecf20Sopenharmony_ci 40308c2ecf20Sopenharmony_ci spin_lock_irqsave(&pm8001_ha->lock, flags); 40318c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->outbnd_q_tbl[vec]; 40328c2ecf20Sopenharmony_ci do { 40338c2ecf20Sopenharmony_ci ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc); 40348c2ecf20Sopenharmony_ci if (MPI_IO_STATUS_SUCCESS == ret) { 40358c2ecf20Sopenharmony_ci /* process the outbound message */ 40368c2ecf20Sopenharmony_ci process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4)); 40378c2ecf20Sopenharmony_ci /* free the message from the outbound circular buffer */ 40388c2ecf20Sopenharmony_ci pm8001_mpi_msg_free_set(pm8001_ha, pMsg1, 40398c2ecf20Sopenharmony_ci circularQ, bc); 40408c2ecf20Sopenharmony_ci } 40418c2ecf20Sopenharmony_ci if (MPI_IO_STATUS_BUSY == ret) { 40428c2ecf20Sopenharmony_ci /* Update the producer index from SPC */ 40438c2ecf20Sopenharmony_ci circularQ->producer_index = 40448c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_read_32(circularQ->pi_virt)); 40458c2ecf20Sopenharmony_ci if (le32_to_cpu(circularQ->producer_index) == 40468c2ecf20Sopenharmony_ci circularQ->consumer_idx) 40478c2ecf20Sopenharmony_ci /* OQ is empty */ 40488c2ecf20Sopenharmony_ci break; 40498c2ecf20Sopenharmony_ci } 40508c2ecf20Sopenharmony_ci } while (1); 40518c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&pm8001_ha->lock, flags); 40528c2ecf20Sopenharmony_ci return ret; 40538c2ecf20Sopenharmony_ci} 40548c2ecf20Sopenharmony_ci 40558c2ecf20Sopenharmony_ci/* DMA_... to our direction translation. */ 40568c2ecf20Sopenharmony_cistatic const u8 data_dir_flags[] = { 40578c2ecf20Sopenharmony_ci [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */ 40588c2ecf20Sopenharmony_ci [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */ 40598c2ecf20Sopenharmony_ci [DMA_FROM_DEVICE] = DATA_DIR_IN, /* INBOUND */ 40608c2ecf20Sopenharmony_ci [DMA_NONE] = DATA_DIR_NONE, /* NO TRANSFER */ 40618c2ecf20Sopenharmony_ci}; 40628c2ecf20Sopenharmony_civoid 40638c2ecf20Sopenharmony_cipm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd) 40648c2ecf20Sopenharmony_ci{ 40658c2ecf20Sopenharmony_ci int i; 40668c2ecf20Sopenharmony_ci struct scatterlist *sg; 40678c2ecf20Sopenharmony_ci struct pm8001_prd *buf_prd = prd; 40688c2ecf20Sopenharmony_ci 40698c2ecf20Sopenharmony_ci for_each_sg(scatter, sg, nr, i) { 40708c2ecf20Sopenharmony_ci buf_prd->addr = cpu_to_le64(sg_dma_address(sg)); 40718c2ecf20Sopenharmony_ci buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg)); 40728c2ecf20Sopenharmony_ci buf_prd->im_len.e = 0; 40738c2ecf20Sopenharmony_ci buf_prd++; 40748c2ecf20Sopenharmony_ci } 40758c2ecf20Sopenharmony_ci} 40768c2ecf20Sopenharmony_ci 40778c2ecf20Sopenharmony_cistatic void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd) 40788c2ecf20Sopenharmony_ci{ 40798c2ecf20Sopenharmony_ci psmp_cmd->tag = hTag; 40808c2ecf20Sopenharmony_ci psmp_cmd->device_id = cpu_to_le32(deviceID); 40818c2ecf20Sopenharmony_ci psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1)); 40828c2ecf20Sopenharmony_ci} 40838c2ecf20Sopenharmony_ci 40848c2ecf20Sopenharmony_ci/** 40858c2ecf20Sopenharmony_ci * pm8001_chip_smp_req - send a SMP task to FW 40868c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 40878c2ecf20Sopenharmony_ci * @ccb: the ccb information this request used. 40888c2ecf20Sopenharmony_ci */ 40898c2ecf20Sopenharmony_cistatic int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha, 40908c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb) 40918c2ecf20Sopenharmony_ci{ 40928c2ecf20Sopenharmony_ci int elem, rc; 40938c2ecf20Sopenharmony_ci struct sas_task *task = ccb->task; 40948c2ecf20Sopenharmony_ci struct domain_device *dev = task->dev; 40958c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev = dev->lldd_dev; 40968c2ecf20Sopenharmony_ci struct scatterlist *sg_req, *sg_resp; 40978c2ecf20Sopenharmony_ci u32 req_len, resp_len; 40988c2ecf20Sopenharmony_ci struct smp_req smp_cmd; 40998c2ecf20Sopenharmony_ci u32 opc; 41008c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 41018c2ecf20Sopenharmony_ci 41028c2ecf20Sopenharmony_ci memset(&smp_cmd, 0, sizeof(smp_cmd)); 41038c2ecf20Sopenharmony_ci /* 41048c2ecf20Sopenharmony_ci * DMA-map SMP request, response buffers 41058c2ecf20Sopenharmony_ci */ 41068c2ecf20Sopenharmony_ci sg_req = &task->smp_task.smp_req; 41078c2ecf20Sopenharmony_ci elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE); 41088c2ecf20Sopenharmony_ci if (!elem) 41098c2ecf20Sopenharmony_ci return -ENOMEM; 41108c2ecf20Sopenharmony_ci req_len = sg_dma_len(sg_req); 41118c2ecf20Sopenharmony_ci 41128c2ecf20Sopenharmony_ci sg_resp = &task->smp_task.smp_resp; 41138c2ecf20Sopenharmony_ci elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE); 41148c2ecf20Sopenharmony_ci if (!elem) { 41158c2ecf20Sopenharmony_ci rc = -ENOMEM; 41168c2ecf20Sopenharmony_ci goto err_out; 41178c2ecf20Sopenharmony_ci } 41188c2ecf20Sopenharmony_ci resp_len = sg_dma_len(sg_resp); 41198c2ecf20Sopenharmony_ci /* must be in dwords */ 41208c2ecf20Sopenharmony_ci if ((req_len & 0x3) || (resp_len & 0x3)) { 41218c2ecf20Sopenharmony_ci rc = -EINVAL; 41228c2ecf20Sopenharmony_ci goto err_out_2; 41238c2ecf20Sopenharmony_ci } 41248c2ecf20Sopenharmony_ci 41258c2ecf20Sopenharmony_ci opc = OPC_INB_SMP_REQUEST; 41268c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 41278c2ecf20Sopenharmony_ci smp_cmd.tag = cpu_to_le32(ccb->ccb_tag); 41288c2ecf20Sopenharmony_ci smp_cmd.long_smp_req.long_req_addr = 41298c2ecf20Sopenharmony_ci cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req)); 41308c2ecf20Sopenharmony_ci smp_cmd.long_smp_req.long_req_size = 41318c2ecf20Sopenharmony_ci cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4); 41328c2ecf20Sopenharmony_ci smp_cmd.long_smp_req.long_resp_addr = 41338c2ecf20Sopenharmony_ci cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp)); 41348c2ecf20Sopenharmony_ci smp_cmd.long_smp_req.long_resp_size = 41358c2ecf20Sopenharmony_ci cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4); 41368c2ecf20Sopenharmony_ci build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd); 41378c2ecf20Sopenharmony_ci rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, 41388c2ecf20Sopenharmony_ci &smp_cmd, sizeof(smp_cmd), 0); 41398c2ecf20Sopenharmony_ci if (rc) 41408c2ecf20Sopenharmony_ci goto err_out_2; 41418c2ecf20Sopenharmony_ci 41428c2ecf20Sopenharmony_ci return 0; 41438c2ecf20Sopenharmony_ci 41448c2ecf20Sopenharmony_cierr_out_2: 41458c2ecf20Sopenharmony_ci dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1, 41468c2ecf20Sopenharmony_ci DMA_FROM_DEVICE); 41478c2ecf20Sopenharmony_cierr_out: 41488c2ecf20Sopenharmony_ci dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1, 41498c2ecf20Sopenharmony_ci DMA_TO_DEVICE); 41508c2ecf20Sopenharmony_ci return rc; 41518c2ecf20Sopenharmony_ci} 41528c2ecf20Sopenharmony_ci 41538c2ecf20Sopenharmony_ci/** 41548c2ecf20Sopenharmony_ci * pm8001_chip_ssp_io_req - send a SSP task to FW 41558c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 41568c2ecf20Sopenharmony_ci * @ccb: the ccb information this request used. 41578c2ecf20Sopenharmony_ci */ 41588c2ecf20Sopenharmony_cistatic int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha, 41598c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb) 41608c2ecf20Sopenharmony_ci{ 41618c2ecf20Sopenharmony_ci struct sas_task *task = ccb->task; 41628c2ecf20Sopenharmony_ci struct domain_device *dev = task->dev; 41638c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev = dev->lldd_dev; 41648c2ecf20Sopenharmony_ci struct ssp_ini_io_start_req ssp_cmd; 41658c2ecf20Sopenharmony_ci u32 tag = ccb->ccb_tag; 41668c2ecf20Sopenharmony_ci int ret; 41678c2ecf20Sopenharmony_ci u64 phys_addr; 41688c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 41698c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SSPINIIOSTART; 41708c2ecf20Sopenharmony_ci memset(&ssp_cmd, 0, sizeof(ssp_cmd)); 41718c2ecf20Sopenharmony_ci memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8); 41728c2ecf20Sopenharmony_ci ssp_cmd.dir_m_tlr = 41738c2ecf20Sopenharmony_ci cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for 41748c2ecf20Sopenharmony_ci SAS 1.1 compatible TLR*/ 41758c2ecf20Sopenharmony_ci ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len); 41768c2ecf20Sopenharmony_ci ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id); 41778c2ecf20Sopenharmony_ci ssp_cmd.tag = cpu_to_le32(tag); 41788c2ecf20Sopenharmony_ci if (task->ssp_task.enable_first_burst) 41798c2ecf20Sopenharmony_ci ssp_cmd.ssp_iu.efb_prio_attr |= 0x80; 41808c2ecf20Sopenharmony_ci ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3); 41818c2ecf20Sopenharmony_ci ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7); 41828c2ecf20Sopenharmony_ci memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd, 41838c2ecf20Sopenharmony_ci task->ssp_task.cmd->cmd_len); 41848c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 41858c2ecf20Sopenharmony_ci 41868c2ecf20Sopenharmony_ci /* fill in PRD (scatter/gather) table, if any */ 41878c2ecf20Sopenharmony_ci if (task->num_scatter > 1) { 41888c2ecf20Sopenharmony_ci pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd); 41898c2ecf20Sopenharmony_ci phys_addr = ccb->ccb_dma_handle; 41908c2ecf20Sopenharmony_ci ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr)); 41918c2ecf20Sopenharmony_ci ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr)); 41928c2ecf20Sopenharmony_ci ssp_cmd.esgl = cpu_to_le32(1<<31); 41938c2ecf20Sopenharmony_ci } else if (task->num_scatter == 1) { 41948c2ecf20Sopenharmony_ci u64 dma_addr = sg_dma_address(task->scatter); 41958c2ecf20Sopenharmony_ci ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr)); 41968c2ecf20Sopenharmony_ci ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr)); 41978c2ecf20Sopenharmony_ci ssp_cmd.len = cpu_to_le32(task->total_xfer_len); 41988c2ecf20Sopenharmony_ci ssp_cmd.esgl = 0; 41998c2ecf20Sopenharmony_ci } else if (task->num_scatter == 0) { 42008c2ecf20Sopenharmony_ci ssp_cmd.addr_low = 0; 42018c2ecf20Sopenharmony_ci ssp_cmd.addr_high = 0; 42028c2ecf20Sopenharmony_ci ssp_cmd.len = cpu_to_le32(task->total_xfer_len); 42038c2ecf20Sopenharmony_ci ssp_cmd.esgl = 0; 42048c2ecf20Sopenharmony_ci } 42058c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd, 42068c2ecf20Sopenharmony_ci sizeof(ssp_cmd), 0); 42078c2ecf20Sopenharmony_ci return ret; 42088c2ecf20Sopenharmony_ci} 42098c2ecf20Sopenharmony_ci 42108c2ecf20Sopenharmony_cistatic int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha, 42118c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb) 42128c2ecf20Sopenharmony_ci{ 42138c2ecf20Sopenharmony_ci struct sas_task *task = ccb->task; 42148c2ecf20Sopenharmony_ci struct domain_device *dev = task->dev; 42158c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_ha_dev = dev->lldd_dev; 42168c2ecf20Sopenharmony_ci u32 tag = ccb->ccb_tag; 42178c2ecf20Sopenharmony_ci int ret; 42188c2ecf20Sopenharmony_ci struct sata_start_req sata_cmd; 42198c2ecf20Sopenharmony_ci u32 hdr_tag, ncg_tag = 0; 42208c2ecf20Sopenharmony_ci u64 phys_addr; 42218c2ecf20Sopenharmony_ci u32 ATAP = 0x0; 42228c2ecf20Sopenharmony_ci u32 dir; 42238c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 42248c2ecf20Sopenharmony_ci unsigned long flags; 42258c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SATA_HOST_OPSTART; 42268c2ecf20Sopenharmony_ci memset(&sata_cmd, 0, sizeof(sata_cmd)); 42278c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 42288c2ecf20Sopenharmony_ci 42298c2ecf20Sopenharmony_ci if (task->data_dir == DMA_NONE && !task->ata_task.use_ncq) { 42308c2ecf20Sopenharmony_ci ATAP = 0x04; /* no data*/ 42318c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "no data\n"); 42328c2ecf20Sopenharmony_ci } else if (likely(!task->ata_task.device_control_reg_update)) { 42338c2ecf20Sopenharmony_ci if (task->ata_task.use_ncq && 42348c2ecf20Sopenharmony_ci dev->sata_dev.class != ATA_DEV_ATAPI) { 42358c2ecf20Sopenharmony_ci ATAP = 0x07; /* FPDMA */ 42368c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "FPDMA\n"); 42378c2ecf20Sopenharmony_ci } else if (task->ata_task.dma_xfer) { 42388c2ecf20Sopenharmony_ci ATAP = 0x06; /* DMA */ 42398c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "DMA\n"); 42408c2ecf20Sopenharmony_ci } else { 42418c2ecf20Sopenharmony_ci ATAP = 0x05; /* PIO*/ 42428c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, IO, "PIO\n"); 42438c2ecf20Sopenharmony_ci } 42448c2ecf20Sopenharmony_ci } 42458c2ecf20Sopenharmony_ci if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) { 42468c2ecf20Sopenharmony_ci task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); 42478c2ecf20Sopenharmony_ci ncg_tag = hdr_tag; 42488c2ecf20Sopenharmony_ci } 42498c2ecf20Sopenharmony_ci dir = data_dir_flags[task->data_dir] << 8; 42508c2ecf20Sopenharmony_ci sata_cmd.tag = cpu_to_le32(tag); 42518c2ecf20Sopenharmony_ci sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id); 42528c2ecf20Sopenharmony_ci sata_cmd.data_len = cpu_to_le32(task->total_xfer_len); 42538c2ecf20Sopenharmony_ci sata_cmd.ncqtag_atap_dir_m = 42548c2ecf20Sopenharmony_ci cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir); 42558c2ecf20Sopenharmony_ci sata_cmd.sata_fis = task->ata_task.fis; 42568c2ecf20Sopenharmony_ci if (likely(!task->ata_task.device_control_reg_update)) 42578c2ecf20Sopenharmony_ci sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */ 42588c2ecf20Sopenharmony_ci sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */ 42598c2ecf20Sopenharmony_ci /* fill in PRD (scatter/gather) table, if any */ 42608c2ecf20Sopenharmony_ci if (task->num_scatter > 1) { 42618c2ecf20Sopenharmony_ci pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd); 42628c2ecf20Sopenharmony_ci phys_addr = ccb->ccb_dma_handle; 42638c2ecf20Sopenharmony_ci sata_cmd.addr_low = lower_32_bits(phys_addr); 42648c2ecf20Sopenharmony_ci sata_cmd.addr_high = upper_32_bits(phys_addr); 42658c2ecf20Sopenharmony_ci sata_cmd.esgl = cpu_to_le32(1 << 31); 42668c2ecf20Sopenharmony_ci } else if (task->num_scatter == 1) { 42678c2ecf20Sopenharmony_ci u64 dma_addr = sg_dma_address(task->scatter); 42688c2ecf20Sopenharmony_ci sata_cmd.addr_low = lower_32_bits(dma_addr); 42698c2ecf20Sopenharmony_ci sata_cmd.addr_high = upper_32_bits(dma_addr); 42708c2ecf20Sopenharmony_ci sata_cmd.len = cpu_to_le32(task->total_xfer_len); 42718c2ecf20Sopenharmony_ci sata_cmd.esgl = 0; 42728c2ecf20Sopenharmony_ci } else if (task->num_scatter == 0) { 42738c2ecf20Sopenharmony_ci sata_cmd.addr_low = 0; 42748c2ecf20Sopenharmony_ci sata_cmd.addr_high = 0; 42758c2ecf20Sopenharmony_ci sata_cmd.len = cpu_to_le32(task->total_xfer_len); 42768c2ecf20Sopenharmony_ci sata_cmd.esgl = 0; 42778c2ecf20Sopenharmony_ci } 42788c2ecf20Sopenharmony_ci 42798c2ecf20Sopenharmony_ci /* Check for read log for failed drive and return */ 42808c2ecf20Sopenharmony_ci if (sata_cmd.sata_fis.command == 0x2f) { 42818c2ecf20Sopenharmony_ci if (((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) || 42828c2ecf20Sopenharmony_ci (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) || 42838c2ecf20Sopenharmony_ci (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) { 42848c2ecf20Sopenharmony_ci struct task_status_struct *ts; 42858c2ecf20Sopenharmony_ci 42868c2ecf20Sopenharmony_ci pm8001_ha_dev->id &= 0xDFFFFFFF; 42878c2ecf20Sopenharmony_ci ts = &task->task_status; 42888c2ecf20Sopenharmony_ci 42898c2ecf20Sopenharmony_ci spin_lock_irqsave(&task->task_state_lock, flags); 42908c2ecf20Sopenharmony_ci ts->resp = SAS_TASK_COMPLETE; 42918c2ecf20Sopenharmony_ci ts->stat = SAS_SAM_STAT_GOOD; 42928c2ecf20Sopenharmony_ci task->task_state_flags &= ~SAS_TASK_STATE_PENDING; 42938c2ecf20Sopenharmony_ci task->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 42948c2ecf20Sopenharmony_ci task->task_state_flags |= SAS_TASK_STATE_DONE; 42958c2ecf20Sopenharmony_ci if (unlikely((task->task_state_flags & 42968c2ecf20Sopenharmony_ci SAS_TASK_STATE_ABORTED))) { 42978c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&task->task_state_lock, 42988c2ecf20Sopenharmony_ci flags); 42998c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, FAIL, 43008c2ecf20Sopenharmony_ci "task 0x%p resp 0x%x stat 0x%x but aborted by upper layer\n", 43018c2ecf20Sopenharmony_ci task, ts->resp, 43028c2ecf20Sopenharmony_ci ts->stat); 43038c2ecf20Sopenharmony_ci pm8001_ccb_task_free(pm8001_ha, task, ccb, tag); 43048c2ecf20Sopenharmony_ci } else { 43058c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&task->task_state_lock, 43068c2ecf20Sopenharmony_ci flags); 43078c2ecf20Sopenharmony_ci pm8001_ccb_task_free_done(pm8001_ha, task, 43088c2ecf20Sopenharmony_ci ccb, tag); 43098c2ecf20Sopenharmony_ci return 0; 43108c2ecf20Sopenharmony_ci } 43118c2ecf20Sopenharmony_ci } 43128c2ecf20Sopenharmony_ci } 43138c2ecf20Sopenharmony_ci 43148c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd, 43158c2ecf20Sopenharmony_ci sizeof(sata_cmd), 0); 43168c2ecf20Sopenharmony_ci return ret; 43178c2ecf20Sopenharmony_ci} 43188c2ecf20Sopenharmony_ci 43198c2ecf20Sopenharmony_ci/** 43208c2ecf20Sopenharmony_ci * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND 43218c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 43228c2ecf20Sopenharmony_ci * @phy_id: the phy id which we wanted to start up. 43238c2ecf20Sopenharmony_ci */ 43248c2ecf20Sopenharmony_cistatic int 43258c2ecf20Sopenharmony_cipm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id) 43268c2ecf20Sopenharmony_ci{ 43278c2ecf20Sopenharmony_ci struct phy_start_req payload; 43288c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 43298c2ecf20Sopenharmony_ci int ret; 43308c2ecf20Sopenharmony_ci u32 tag = 0x01; 43318c2ecf20Sopenharmony_ci u32 opcode = OPC_INB_PHYSTART; 43328c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 43338c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 43348c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(tag); 43358c2ecf20Sopenharmony_ci /* 43368c2ecf20Sopenharmony_ci ** [0:7] PHY Identifier 43378c2ecf20Sopenharmony_ci ** [8:11] link rate 1.5G, 3G, 6G 43388c2ecf20Sopenharmony_ci ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both 43398c2ecf20Sopenharmony_ci ** [14] 0b disable spin up hold; 1b enable spin up hold 43408c2ecf20Sopenharmony_ci */ 43418c2ecf20Sopenharmony_ci payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE | 43428c2ecf20Sopenharmony_ci LINKMODE_AUTO | LINKRATE_15 | 43438c2ecf20Sopenharmony_ci LINKRATE_30 | LINKRATE_60 | phy_id); 43448c2ecf20Sopenharmony_ci payload.sas_identify.dev_type = SAS_END_DEVICE; 43458c2ecf20Sopenharmony_ci payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL; 43468c2ecf20Sopenharmony_ci memcpy(payload.sas_identify.sas_addr, 43478c2ecf20Sopenharmony_ci &pm8001_ha->phy[phy_id].dev_sas_addr, SAS_ADDR_SIZE); 43488c2ecf20Sopenharmony_ci payload.sas_identify.phy_id = phy_id; 43498c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, 43508c2ecf20Sopenharmony_ci sizeof(payload), 0); 43518c2ecf20Sopenharmony_ci return ret; 43528c2ecf20Sopenharmony_ci} 43538c2ecf20Sopenharmony_ci 43548c2ecf20Sopenharmony_ci/** 43558c2ecf20Sopenharmony_ci * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND 43568c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 43578c2ecf20Sopenharmony_ci * @phy_id: the phy id which we wanted to start up. 43588c2ecf20Sopenharmony_ci */ 43598c2ecf20Sopenharmony_cistatic int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha, 43608c2ecf20Sopenharmony_ci u8 phy_id) 43618c2ecf20Sopenharmony_ci{ 43628c2ecf20Sopenharmony_ci struct phy_stop_req payload; 43638c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 43648c2ecf20Sopenharmony_ci int ret; 43658c2ecf20Sopenharmony_ci u32 tag = 0x01; 43668c2ecf20Sopenharmony_ci u32 opcode = OPC_INB_PHYSTOP; 43678c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 43688c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 43698c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(tag); 43708c2ecf20Sopenharmony_ci payload.phy_id = cpu_to_le32(phy_id); 43718c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, 43728c2ecf20Sopenharmony_ci sizeof(payload), 0); 43738c2ecf20Sopenharmony_ci return ret; 43748c2ecf20Sopenharmony_ci} 43758c2ecf20Sopenharmony_ci 43768c2ecf20Sopenharmony_ci/* 43778c2ecf20Sopenharmony_ci * see comments on pm8001_mpi_reg_resp. 43788c2ecf20Sopenharmony_ci */ 43798c2ecf20Sopenharmony_cistatic int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha, 43808c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev, u32 flag) 43818c2ecf20Sopenharmony_ci{ 43828c2ecf20Sopenharmony_ci struct reg_dev_req payload; 43838c2ecf20Sopenharmony_ci u32 opc; 43848c2ecf20Sopenharmony_ci u32 stp_sspsmp_sata = 0x4; 43858c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 43868c2ecf20Sopenharmony_ci u32 linkrate, phy_id; 43878c2ecf20Sopenharmony_ci int rc, tag = 0xdeadbeef; 43888c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 43898c2ecf20Sopenharmony_ci u8 retryFlag = 0x1; 43908c2ecf20Sopenharmony_ci u16 firstBurstSize = 0; 43918c2ecf20Sopenharmony_ci u16 ITNT = 2000; 43928c2ecf20Sopenharmony_ci struct domain_device *dev = pm8001_dev->sas_device; 43938c2ecf20Sopenharmony_ci struct domain_device *parent_dev = dev->parent; 43948c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 43958c2ecf20Sopenharmony_ci 43968c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 43978c2ecf20Sopenharmony_ci rc = pm8001_tag_alloc(pm8001_ha, &tag); 43988c2ecf20Sopenharmony_ci if (rc) 43998c2ecf20Sopenharmony_ci return rc; 44008c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 44018c2ecf20Sopenharmony_ci ccb->device = pm8001_dev; 44028c2ecf20Sopenharmony_ci ccb->ccb_tag = tag; 44038c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(tag); 44048c2ecf20Sopenharmony_ci if (flag == 1) 44058c2ecf20Sopenharmony_ci stp_sspsmp_sata = 0x02; /*direct attached sata */ 44068c2ecf20Sopenharmony_ci else { 44078c2ecf20Sopenharmony_ci if (pm8001_dev->dev_type == SAS_SATA_DEV) 44088c2ecf20Sopenharmony_ci stp_sspsmp_sata = 0x00; /* stp*/ 44098c2ecf20Sopenharmony_ci else if (pm8001_dev->dev_type == SAS_END_DEVICE || 44108c2ecf20Sopenharmony_ci pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE || 44118c2ecf20Sopenharmony_ci pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE) 44128c2ecf20Sopenharmony_ci stp_sspsmp_sata = 0x01; /*ssp or smp*/ 44138c2ecf20Sopenharmony_ci } 44148c2ecf20Sopenharmony_ci if (parent_dev && dev_is_expander(parent_dev->dev_type)) 44158c2ecf20Sopenharmony_ci phy_id = parent_dev->ex_dev.ex_phy->phy_id; 44168c2ecf20Sopenharmony_ci else 44178c2ecf20Sopenharmony_ci phy_id = pm8001_dev->attached_phy; 44188c2ecf20Sopenharmony_ci opc = OPC_INB_REG_DEV; 44198c2ecf20Sopenharmony_ci linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ? 44208c2ecf20Sopenharmony_ci pm8001_dev->sas_device->linkrate : dev->port->linkrate; 44218c2ecf20Sopenharmony_ci payload.phyid_portid = 44228c2ecf20Sopenharmony_ci cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) | 44238c2ecf20Sopenharmony_ci ((phy_id & 0x0F) << 4)); 44248c2ecf20Sopenharmony_ci payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) | 44258c2ecf20Sopenharmony_ci ((linkrate & 0x0F) * 0x1000000) | 44268c2ecf20Sopenharmony_ci ((stp_sspsmp_sata & 0x03) * 0x10000000)); 44278c2ecf20Sopenharmony_ci payload.firstburstsize_ITNexustimeout = 44288c2ecf20Sopenharmony_ci cpu_to_le32(ITNT | (firstBurstSize * 0x10000)); 44298c2ecf20Sopenharmony_ci memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr, 44308c2ecf20Sopenharmony_ci SAS_ADDR_SIZE); 44318c2ecf20Sopenharmony_ci rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 44328c2ecf20Sopenharmony_ci sizeof(payload), 0); 44338c2ecf20Sopenharmony_ci if (rc) 44348c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 44358c2ecf20Sopenharmony_ci 44368c2ecf20Sopenharmony_ci return rc; 44378c2ecf20Sopenharmony_ci} 44388c2ecf20Sopenharmony_ci 44398c2ecf20Sopenharmony_ci/* 44408c2ecf20Sopenharmony_ci * see comments on pm8001_mpi_reg_resp. 44418c2ecf20Sopenharmony_ci */ 44428c2ecf20Sopenharmony_ciint pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha, 44438c2ecf20Sopenharmony_ci u32 device_id) 44448c2ecf20Sopenharmony_ci{ 44458c2ecf20Sopenharmony_ci struct dereg_dev_req payload; 44468c2ecf20Sopenharmony_ci u32 opc = OPC_INB_DEREG_DEV_HANDLE; 44478c2ecf20Sopenharmony_ci int ret; 44488c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 44498c2ecf20Sopenharmony_ci 44508c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 44518c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 44528c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(1); 44538c2ecf20Sopenharmony_ci payload.device_id = cpu_to_le32(device_id); 44548c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, MSG, "unregister device device_id = %d\n", 44558c2ecf20Sopenharmony_ci device_id); 44568c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 44578c2ecf20Sopenharmony_ci sizeof(payload), 0); 44588c2ecf20Sopenharmony_ci return ret; 44598c2ecf20Sopenharmony_ci} 44608c2ecf20Sopenharmony_ci 44618c2ecf20Sopenharmony_ci/** 44628c2ecf20Sopenharmony_ci * pm8001_chip_phy_ctl_req - support the local phy operation 44638c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 44648c2ecf20Sopenharmony_ci * @phyId: the phy id which we wanted to operate 44658c2ecf20Sopenharmony_ci * @phy_op: the phy operation to request 44668c2ecf20Sopenharmony_ci */ 44678c2ecf20Sopenharmony_cistatic int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha, 44688c2ecf20Sopenharmony_ci u32 phyId, u32 phy_op) 44698c2ecf20Sopenharmony_ci{ 44708c2ecf20Sopenharmony_ci struct local_phy_ctl_req payload; 44718c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 44728c2ecf20Sopenharmony_ci int ret; 44738c2ecf20Sopenharmony_ci u32 opc = OPC_INB_LOCAL_PHY_CONTROL; 44748c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 44758c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 44768c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(1); 44778c2ecf20Sopenharmony_ci payload.phyop_phyid = 44788c2ecf20Sopenharmony_ci cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F)); 44798c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 44808c2ecf20Sopenharmony_ci sizeof(payload), 0); 44818c2ecf20Sopenharmony_ci return ret; 44828c2ecf20Sopenharmony_ci} 44838c2ecf20Sopenharmony_ci 44848c2ecf20Sopenharmony_cistatic u32 pm8001_chip_is_our_interrupt(struct pm8001_hba_info *pm8001_ha) 44858c2ecf20Sopenharmony_ci{ 44868c2ecf20Sopenharmony_ci#ifdef PM8001_USE_MSIX 44878c2ecf20Sopenharmony_ci return 1; 44888c2ecf20Sopenharmony_ci#else 44898c2ecf20Sopenharmony_ci u32 value; 44908c2ecf20Sopenharmony_ci 44918c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR); 44928c2ecf20Sopenharmony_ci if (value) 44938c2ecf20Sopenharmony_ci return 1; 44948c2ecf20Sopenharmony_ci return 0; 44958c2ecf20Sopenharmony_ci#endif 44968c2ecf20Sopenharmony_ci} 44978c2ecf20Sopenharmony_ci 44988c2ecf20Sopenharmony_ci/** 44998c2ecf20Sopenharmony_ci * pm8001_chip_isr - PM8001 isr handler. 45008c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 45018c2ecf20Sopenharmony_ci * @vec: IRQ number 45028c2ecf20Sopenharmony_ci */ 45038c2ecf20Sopenharmony_cistatic irqreturn_t 45048c2ecf20Sopenharmony_cipm8001_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec) 45058c2ecf20Sopenharmony_ci{ 45068c2ecf20Sopenharmony_ci pm8001_chip_interrupt_disable(pm8001_ha, vec); 45078c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 45088c2ecf20Sopenharmony_ci "irq vec %d, ODMR:0x%x\n", 45098c2ecf20Sopenharmony_ci vec, pm8001_cr32(pm8001_ha, 0, 0x30)); 45108c2ecf20Sopenharmony_ci process_oq(pm8001_ha, vec); 45118c2ecf20Sopenharmony_ci pm8001_chip_interrupt_enable(pm8001_ha, vec); 45128c2ecf20Sopenharmony_ci return IRQ_HANDLED; 45138c2ecf20Sopenharmony_ci} 45148c2ecf20Sopenharmony_ci 45158c2ecf20Sopenharmony_cistatic int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc, 45168c2ecf20Sopenharmony_ci u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag) 45178c2ecf20Sopenharmony_ci{ 45188c2ecf20Sopenharmony_ci struct task_abort_req task_abort; 45198c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 45208c2ecf20Sopenharmony_ci int ret; 45218c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 45228c2ecf20Sopenharmony_ci memset(&task_abort, 0, sizeof(task_abort)); 45238c2ecf20Sopenharmony_ci if (ABORT_SINGLE == (flag & ABORT_MASK)) { 45248c2ecf20Sopenharmony_ci task_abort.abort_all = 0; 45258c2ecf20Sopenharmony_ci task_abort.device_id = cpu_to_le32(dev_id); 45268c2ecf20Sopenharmony_ci task_abort.tag_to_abort = cpu_to_le32(task_tag); 45278c2ecf20Sopenharmony_ci task_abort.tag = cpu_to_le32(cmd_tag); 45288c2ecf20Sopenharmony_ci } else if (ABORT_ALL == (flag & ABORT_MASK)) { 45298c2ecf20Sopenharmony_ci task_abort.abort_all = cpu_to_le32(1); 45308c2ecf20Sopenharmony_ci task_abort.device_id = cpu_to_le32(dev_id); 45318c2ecf20Sopenharmony_ci task_abort.tag = cpu_to_le32(cmd_tag); 45328c2ecf20Sopenharmony_ci } 45338c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort, 45348c2ecf20Sopenharmony_ci sizeof(task_abort), 0); 45358c2ecf20Sopenharmony_ci return ret; 45368c2ecf20Sopenharmony_ci} 45378c2ecf20Sopenharmony_ci 45388c2ecf20Sopenharmony_ci/* 45398c2ecf20Sopenharmony_ci * pm8001_chip_abort_task - SAS abort task when error or exception happened. 45408c2ecf20Sopenharmony_ci */ 45418c2ecf20Sopenharmony_ciint pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha, 45428c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag) 45438c2ecf20Sopenharmony_ci{ 45448c2ecf20Sopenharmony_ci u32 opc, device_id; 45458c2ecf20Sopenharmony_ci int rc = TMF_RESP_FUNC_FAILED; 45468c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, EH, "cmd_tag = %x, abort task tag = 0x%x\n", 45478c2ecf20Sopenharmony_ci cmd_tag, task_tag); 45488c2ecf20Sopenharmony_ci if (pm8001_dev->dev_type == SAS_END_DEVICE) 45498c2ecf20Sopenharmony_ci opc = OPC_INB_SSP_ABORT; 45508c2ecf20Sopenharmony_ci else if (pm8001_dev->dev_type == SAS_SATA_DEV) 45518c2ecf20Sopenharmony_ci opc = OPC_INB_SATA_ABORT; 45528c2ecf20Sopenharmony_ci else 45538c2ecf20Sopenharmony_ci opc = OPC_INB_SMP_ABORT;/* SMP */ 45548c2ecf20Sopenharmony_ci device_id = pm8001_dev->device_id; 45558c2ecf20Sopenharmony_ci rc = send_task_abort(pm8001_ha, opc, device_id, flag, 45568c2ecf20Sopenharmony_ci task_tag, cmd_tag); 45578c2ecf20Sopenharmony_ci if (rc != TMF_RESP_FUNC_COMPLETE) 45588c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, EH, "rc= %d\n", rc); 45598c2ecf20Sopenharmony_ci return rc; 45608c2ecf20Sopenharmony_ci} 45618c2ecf20Sopenharmony_ci 45628c2ecf20Sopenharmony_ci/** 45638c2ecf20Sopenharmony_ci * pm8001_chip_ssp_tm_req - built the task management command. 45648c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 45658c2ecf20Sopenharmony_ci * @ccb: the ccb information. 45668c2ecf20Sopenharmony_ci * @tmf: task management function. 45678c2ecf20Sopenharmony_ci */ 45688c2ecf20Sopenharmony_ciint pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha, 45698c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf) 45708c2ecf20Sopenharmony_ci{ 45718c2ecf20Sopenharmony_ci struct sas_task *task = ccb->task; 45728c2ecf20Sopenharmony_ci struct domain_device *dev = task->dev; 45738c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev = dev->lldd_dev; 45748c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SSPINITMSTART; 45758c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 45768c2ecf20Sopenharmony_ci struct ssp_ini_tm_start_req sspTMCmd; 45778c2ecf20Sopenharmony_ci int ret; 45788c2ecf20Sopenharmony_ci 45798c2ecf20Sopenharmony_ci memset(&sspTMCmd, 0, sizeof(sspTMCmd)); 45808c2ecf20Sopenharmony_ci sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id); 45818c2ecf20Sopenharmony_ci sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed); 45828c2ecf20Sopenharmony_ci sspTMCmd.tmf = cpu_to_le32(tmf->tmf); 45838c2ecf20Sopenharmony_ci memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8); 45848c2ecf20Sopenharmony_ci sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag); 45858c2ecf20Sopenharmony_ci if (pm8001_ha->chip_id != chip_8001) 45868c2ecf20Sopenharmony_ci sspTMCmd.ds_ads_m = cpu_to_le32(0x08); 45878c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 45888c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd, 45898c2ecf20Sopenharmony_ci sizeof(sspTMCmd), 0); 45908c2ecf20Sopenharmony_ci return ret; 45918c2ecf20Sopenharmony_ci} 45928c2ecf20Sopenharmony_ci 45938c2ecf20Sopenharmony_ciint pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha, 45948c2ecf20Sopenharmony_ci void *payload) 45958c2ecf20Sopenharmony_ci{ 45968c2ecf20Sopenharmony_ci u32 opc = OPC_INB_GET_NVMD_DATA; 45978c2ecf20Sopenharmony_ci u32 nvmd_type; 45988c2ecf20Sopenharmony_ci int rc; 45998c2ecf20Sopenharmony_ci u32 tag; 46008c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 46018c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 46028c2ecf20Sopenharmony_ci struct get_nvm_data_req nvmd_req; 46038c2ecf20Sopenharmony_ci struct fw_control_ex *fw_control_context; 46048c2ecf20Sopenharmony_ci struct pm8001_ioctl_payload *ioctl_payload = payload; 46058c2ecf20Sopenharmony_ci 46068c2ecf20Sopenharmony_ci nvmd_type = ioctl_payload->minor_function; 46078c2ecf20Sopenharmony_ci fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); 46088c2ecf20Sopenharmony_ci if (!fw_control_context) 46098c2ecf20Sopenharmony_ci return -ENOMEM; 46108c2ecf20Sopenharmony_ci fw_control_context->usrAddr = (u8 *)ioctl_payload->func_specific; 46118c2ecf20Sopenharmony_ci fw_control_context->len = ioctl_payload->rd_length; 46128c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 46138c2ecf20Sopenharmony_ci memset(&nvmd_req, 0, sizeof(nvmd_req)); 46148c2ecf20Sopenharmony_ci rc = pm8001_tag_alloc(pm8001_ha, &tag); 46158c2ecf20Sopenharmony_ci if (rc) { 46168c2ecf20Sopenharmony_ci kfree(fw_control_context); 46178c2ecf20Sopenharmony_ci return rc; 46188c2ecf20Sopenharmony_ci } 46198c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 46208c2ecf20Sopenharmony_ci ccb->ccb_tag = tag; 46218c2ecf20Sopenharmony_ci ccb->fw_control_context = fw_control_context; 46228c2ecf20Sopenharmony_ci nvmd_req.tag = cpu_to_le32(tag); 46238c2ecf20Sopenharmony_ci 46248c2ecf20Sopenharmony_ci switch (nvmd_type) { 46258c2ecf20Sopenharmony_ci case TWI_DEVICE: { 46268c2ecf20Sopenharmony_ci u32 twi_addr, twi_page_size; 46278c2ecf20Sopenharmony_ci twi_addr = 0xa8; 46288c2ecf20Sopenharmony_ci twi_page_size = 2; 46298c2ecf20Sopenharmony_ci 46308c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 | 46318c2ecf20Sopenharmony_ci twi_page_size << 8 | TWI_DEVICE); 46328c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); 46338c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 46348c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 46358c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 46368c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 46378c2ecf20Sopenharmony_ci break; 46388c2ecf20Sopenharmony_ci } 46398c2ecf20Sopenharmony_ci case C_SEEPROM: { 46408c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM); 46418c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); 46428c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 46438c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 46448c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 46458c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 46468c2ecf20Sopenharmony_ci break; 46478c2ecf20Sopenharmony_ci } 46488c2ecf20Sopenharmony_ci case VPD_FLASH: { 46498c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH); 46508c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); 46518c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 46528c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 46538c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 46548c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 46558c2ecf20Sopenharmony_ci break; 46568c2ecf20Sopenharmony_ci } 46578c2ecf20Sopenharmony_ci case EXPAN_ROM: { 46588c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM); 46598c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); 46608c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 46618c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 46628c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 46638c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 46648c2ecf20Sopenharmony_ci break; 46658c2ecf20Sopenharmony_ci } 46668c2ecf20Sopenharmony_ci case IOP_RDUMP: { 46678c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | IOP_RDUMP); 46688c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->rd_length); 46698c2ecf20Sopenharmony_ci nvmd_req.vpd_offset = cpu_to_le32(ioctl_payload->offset); 46708c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 46718c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 46728c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 46738c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 46748c2ecf20Sopenharmony_ci break; 46758c2ecf20Sopenharmony_ci } 46768c2ecf20Sopenharmony_ci default: 46778c2ecf20Sopenharmony_ci break; 46788c2ecf20Sopenharmony_ci } 46798c2ecf20Sopenharmony_ci rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req, 46808c2ecf20Sopenharmony_ci sizeof(nvmd_req), 0); 46818c2ecf20Sopenharmony_ci if (rc) { 46828c2ecf20Sopenharmony_ci kfree(fw_control_context); 46838c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 46848c2ecf20Sopenharmony_ci } 46858c2ecf20Sopenharmony_ci return rc; 46868c2ecf20Sopenharmony_ci} 46878c2ecf20Sopenharmony_ci 46888c2ecf20Sopenharmony_ciint pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha, 46898c2ecf20Sopenharmony_ci void *payload) 46908c2ecf20Sopenharmony_ci{ 46918c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SET_NVMD_DATA; 46928c2ecf20Sopenharmony_ci u32 nvmd_type; 46938c2ecf20Sopenharmony_ci int rc; 46948c2ecf20Sopenharmony_ci u32 tag; 46958c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 46968c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 46978c2ecf20Sopenharmony_ci struct set_nvm_data_req nvmd_req; 46988c2ecf20Sopenharmony_ci struct fw_control_ex *fw_control_context; 46998c2ecf20Sopenharmony_ci struct pm8001_ioctl_payload *ioctl_payload = payload; 47008c2ecf20Sopenharmony_ci 47018c2ecf20Sopenharmony_ci nvmd_type = ioctl_payload->minor_function; 47028c2ecf20Sopenharmony_ci fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); 47038c2ecf20Sopenharmony_ci if (!fw_control_context) 47048c2ecf20Sopenharmony_ci return -ENOMEM; 47058c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 47068c2ecf20Sopenharmony_ci memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr, 47078c2ecf20Sopenharmony_ci &ioctl_payload->func_specific, 47088c2ecf20Sopenharmony_ci ioctl_payload->wr_length); 47098c2ecf20Sopenharmony_ci memset(&nvmd_req, 0, sizeof(nvmd_req)); 47108c2ecf20Sopenharmony_ci rc = pm8001_tag_alloc(pm8001_ha, &tag); 47118c2ecf20Sopenharmony_ci if (rc) { 47128c2ecf20Sopenharmony_ci kfree(fw_control_context); 47138c2ecf20Sopenharmony_ci return -EBUSY; 47148c2ecf20Sopenharmony_ci } 47158c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 47168c2ecf20Sopenharmony_ci ccb->fw_control_context = fw_control_context; 47178c2ecf20Sopenharmony_ci ccb->ccb_tag = tag; 47188c2ecf20Sopenharmony_ci nvmd_req.tag = cpu_to_le32(tag); 47198c2ecf20Sopenharmony_ci switch (nvmd_type) { 47208c2ecf20Sopenharmony_ci case TWI_DEVICE: { 47218c2ecf20Sopenharmony_ci u32 twi_addr, twi_page_size; 47228c2ecf20Sopenharmony_ci twi_addr = 0xa8; 47238c2ecf20Sopenharmony_ci twi_page_size = 2; 47248c2ecf20Sopenharmony_ci nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); 47258c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 | 47268c2ecf20Sopenharmony_ci twi_page_size << 8 | TWI_DEVICE); 47278c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); 47288c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 47298c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 47308c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 47318c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 47328c2ecf20Sopenharmony_ci break; 47338c2ecf20Sopenharmony_ci } 47348c2ecf20Sopenharmony_ci case C_SEEPROM: 47358c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM); 47368c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); 47378c2ecf20Sopenharmony_ci nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); 47388c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 47398c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 47408c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 47418c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 47428c2ecf20Sopenharmony_ci break; 47438c2ecf20Sopenharmony_ci case VPD_FLASH: 47448c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH); 47458c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); 47468c2ecf20Sopenharmony_ci nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); 47478c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 47488c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 47498c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 47508c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 47518c2ecf20Sopenharmony_ci break; 47528c2ecf20Sopenharmony_ci case EXPAN_ROM: 47538c2ecf20Sopenharmony_ci nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM); 47548c2ecf20Sopenharmony_ci nvmd_req.resp_len = cpu_to_le32(ioctl_payload->wr_length); 47558c2ecf20Sopenharmony_ci nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); 47568c2ecf20Sopenharmony_ci nvmd_req.resp_addr_hi = 47578c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); 47588c2ecf20Sopenharmony_ci nvmd_req.resp_addr_lo = 47598c2ecf20Sopenharmony_ci cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); 47608c2ecf20Sopenharmony_ci break; 47618c2ecf20Sopenharmony_ci default: 47628c2ecf20Sopenharmony_ci break; 47638c2ecf20Sopenharmony_ci } 47648c2ecf20Sopenharmony_ci rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req, 47658c2ecf20Sopenharmony_ci sizeof(nvmd_req), 0); 47668c2ecf20Sopenharmony_ci if (rc) { 47678c2ecf20Sopenharmony_ci kfree(fw_control_context); 47688c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 47698c2ecf20Sopenharmony_ci } 47708c2ecf20Sopenharmony_ci return rc; 47718c2ecf20Sopenharmony_ci} 47728c2ecf20Sopenharmony_ci 47738c2ecf20Sopenharmony_ci/** 47748c2ecf20Sopenharmony_ci * pm8001_chip_fw_flash_update_build - support the firmware update operation 47758c2ecf20Sopenharmony_ci * @pm8001_ha: our hba card information. 47768c2ecf20Sopenharmony_ci * @fw_flash_updata_info: firmware flash update param 47778c2ecf20Sopenharmony_ci * @tag: Tag to apply to the payload 47788c2ecf20Sopenharmony_ci */ 47798c2ecf20Sopenharmony_ciint 47808c2ecf20Sopenharmony_cipm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha, 47818c2ecf20Sopenharmony_ci void *fw_flash_updata_info, u32 tag) 47828c2ecf20Sopenharmony_ci{ 47838c2ecf20Sopenharmony_ci struct fw_flash_Update_req payload; 47848c2ecf20Sopenharmony_ci struct fw_flash_updata_info *info; 47858c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 47868c2ecf20Sopenharmony_ci int ret; 47878c2ecf20Sopenharmony_ci u32 opc = OPC_INB_FW_FLASH_UPDATE; 47888c2ecf20Sopenharmony_ci 47898c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(struct fw_flash_Update_req)); 47908c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 47918c2ecf20Sopenharmony_ci info = fw_flash_updata_info; 47928c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(tag); 47938c2ecf20Sopenharmony_ci payload.cur_image_len = cpu_to_le32(info->cur_image_len); 47948c2ecf20Sopenharmony_ci payload.cur_image_offset = cpu_to_le32(info->cur_image_offset); 47958c2ecf20Sopenharmony_ci payload.total_image_len = cpu_to_le32(info->total_image_len); 47968c2ecf20Sopenharmony_ci payload.len = info->sgl.im_len.len ; 47978c2ecf20Sopenharmony_ci payload.sgl_addr_lo = 47988c2ecf20Sopenharmony_ci cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr))); 47998c2ecf20Sopenharmony_ci payload.sgl_addr_hi = 48008c2ecf20Sopenharmony_ci cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr))); 48018c2ecf20Sopenharmony_ci ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 48028c2ecf20Sopenharmony_ci sizeof(payload), 0); 48038c2ecf20Sopenharmony_ci return ret; 48048c2ecf20Sopenharmony_ci} 48058c2ecf20Sopenharmony_ci 48068c2ecf20Sopenharmony_ciint 48078c2ecf20Sopenharmony_cipm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha, 48088c2ecf20Sopenharmony_ci void *payload) 48098c2ecf20Sopenharmony_ci{ 48108c2ecf20Sopenharmony_ci struct fw_flash_updata_info flash_update_info; 48118c2ecf20Sopenharmony_ci struct fw_control_info *fw_control; 48128c2ecf20Sopenharmony_ci struct fw_control_ex *fw_control_context; 48138c2ecf20Sopenharmony_ci int rc; 48148c2ecf20Sopenharmony_ci u32 tag; 48158c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 48168c2ecf20Sopenharmony_ci void *buffer = pm8001_ha->memoryMap.region[FW_FLASH].virt_ptr; 48178c2ecf20Sopenharmony_ci dma_addr_t phys_addr = pm8001_ha->memoryMap.region[FW_FLASH].phys_addr; 48188c2ecf20Sopenharmony_ci struct pm8001_ioctl_payload *ioctl_payload = payload; 48198c2ecf20Sopenharmony_ci 48208c2ecf20Sopenharmony_ci fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); 48218c2ecf20Sopenharmony_ci if (!fw_control_context) 48228c2ecf20Sopenharmony_ci return -ENOMEM; 48238c2ecf20Sopenharmony_ci fw_control = (struct fw_control_info *)&ioctl_payload->func_specific; 48248c2ecf20Sopenharmony_ci pm8001_dbg(pm8001_ha, DEVIO, 48258c2ecf20Sopenharmony_ci "dma fw_control context input length :%x\n", 48268c2ecf20Sopenharmony_ci fw_control->len); 48278c2ecf20Sopenharmony_ci memcpy(buffer, fw_control->buffer, fw_control->len); 48288c2ecf20Sopenharmony_ci flash_update_info.sgl.addr = cpu_to_le64(phys_addr); 48298c2ecf20Sopenharmony_ci flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len); 48308c2ecf20Sopenharmony_ci flash_update_info.sgl.im_len.e = 0; 48318c2ecf20Sopenharmony_ci flash_update_info.cur_image_offset = fw_control->offset; 48328c2ecf20Sopenharmony_ci flash_update_info.cur_image_len = fw_control->len; 48338c2ecf20Sopenharmony_ci flash_update_info.total_image_len = fw_control->size; 48348c2ecf20Sopenharmony_ci fw_control_context->fw_control = fw_control; 48358c2ecf20Sopenharmony_ci fw_control_context->virtAddr = buffer; 48368c2ecf20Sopenharmony_ci fw_control_context->phys_addr = phys_addr; 48378c2ecf20Sopenharmony_ci fw_control_context->len = fw_control->len; 48388c2ecf20Sopenharmony_ci rc = pm8001_tag_alloc(pm8001_ha, &tag); 48398c2ecf20Sopenharmony_ci if (rc) { 48408c2ecf20Sopenharmony_ci kfree(fw_control_context); 48418c2ecf20Sopenharmony_ci return -EBUSY; 48428c2ecf20Sopenharmony_ci } 48438c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 48448c2ecf20Sopenharmony_ci ccb->fw_control_context = fw_control_context; 48458c2ecf20Sopenharmony_ci ccb->ccb_tag = tag; 48468c2ecf20Sopenharmony_ci rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info, 48478c2ecf20Sopenharmony_ci tag); 48488c2ecf20Sopenharmony_ci if (rc) { 48498c2ecf20Sopenharmony_ci kfree(fw_control_context); 48508c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 48518c2ecf20Sopenharmony_ci } 48528c2ecf20Sopenharmony_ci 48538c2ecf20Sopenharmony_ci return rc; 48548c2ecf20Sopenharmony_ci} 48558c2ecf20Sopenharmony_ci 48568c2ecf20Sopenharmony_cissize_t 48578c2ecf20Sopenharmony_cipm8001_get_gsm_dump(struct device *cdev, u32 length, char *buf) 48588c2ecf20Sopenharmony_ci{ 48598c2ecf20Sopenharmony_ci u32 value, rem, offset = 0, bar = 0; 48608c2ecf20Sopenharmony_ci u32 index, work_offset, dw_length; 48618c2ecf20Sopenharmony_ci u32 shift_value, gsm_base, gsm_dump_offset; 48628c2ecf20Sopenharmony_ci char *direct_data; 48638c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(cdev); 48648c2ecf20Sopenharmony_ci struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); 48658c2ecf20Sopenharmony_ci struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; 48668c2ecf20Sopenharmony_ci 48678c2ecf20Sopenharmony_ci direct_data = buf; 48688c2ecf20Sopenharmony_ci gsm_dump_offset = pm8001_ha->fatal_forensic_shift_offset; 48698c2ecf20Sopenharmony_ci 48708c2ecf20Sopenharmony_ci /* check max is 1 Mbytes */ 48718c2ecf20Sopenharmony_ci if ((length > 0x100000) || (gsm_dump_offset & 3) || 48728c2ecf20Sopenharmony_ci ((gsm_dump_offset + length) > 0x1000000)) 48738c2ecf20Sopenharmony_ci return -EINVAL; 48748c2ecf20Sopenharmony_ci 48758c2ecf20Sopenharmony_ci if (pm8001_ha->chip_id == chip_8001) 48768c2ecf20Sopenharmony_ci bar = 2; 48778c2ecf20Sopenharmony_ci else 48788c2ecf20Sopenharmony_ci bar = 1; 48798c2ecf20Sopenharmony_ci 48808c2ecf20Sopenharmony_ci work_offset = gsm_dump_offset & 0xFFFF0000; 48818c2ecf20Sopenharmony_ci offset = gsm_dump_offset & 0x0000FFFF; 48828c2ecf20Sopenharmony_ci gsm_dump_offset = work_offset; 48838c2ecf20Sopenharmony_ci /* adjust length to dword boundary */ 48848c2ecf20Sopenharmony_ci rem = length & 3; 48858c2ecf20Sopenharmony_ci dw_length = length >> 2; 48868c2ecf20Sopenharmony_ci 48878c2ecf20Sopenharmony_ci for (index = 0; index < dw_length; index++) { 48888c2ecf20Sopenharmony_ci if ((work_offset + offset) & 0xFFFF0000) { 48898c2ecf20Sopenharmony_ci if (pm8001_ha->chip_id == chip_8001) 48908c2ecf20Sopenharmony_ci shift_value = ((gsm_dump_offset + offset) & 48918c2ecf20Sopenharmony_ci SHIFT_REG_64K_MASK); 48928c2ecf20Sopenharmony_ci else 48938c2ecf20Sopenharmony_ci shift_value = (((gsm_dump_offset + offset) & 48948c2ecf20Sopenharmony_ci SHIFT_REG_64K_MASK) >> 48958c2ecf20Sopenharmony_ci SHIFT_REG_BIT_SHIFT); 48968c2ecf20Sopenharmony_ci 48978c2ecf20Sopenharmony_ci if (pm8001_ha->chip_id == chip_8001) { 48988c2ecf20Sopenharmony_ci gsm_base = GSM_BASE; 48998c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, 49008c2ecf20Sopenharmony_ci (gsm_base + shift_value))) 49018c2ecf20Sopenharmony_ci return -EIO; 49028c2ecf20Sopenharmony_ci } else { 49038c2ecf20Sopenharmony_ci gsm_base = 0; 49048c2ecf20Sopenharmony_ci if (-1 == pm80xx_bar4_shift(pm8001_ha, 49058c2ecf20Sopenharmony_ci (gsm_base + shift_value))) 49068c2ecf20Sopenharmony_ci return -EIO; 49078c2ecf20Sopenharmony_ci } 49088c2ecf20Sopenharmony_ci gsm_dump_offset = (gsm_dump_offset + offset) & 49098c2ecf20Sopenharmony_ci 0xFFFF0000; 49108c2ecf20Sopenharmony_ci work_offset = 0; 49118c2ecf20Sopenharmony_ci offset = offset & 0x0000FFFF; 49128c2ecf20Sopenharmony_ci } 49138c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) & 49148c2ecf20Sopenharmony_ci 0x0000FFFF); 49158c2ecf20Sopenharmony_ci direct_data += sprintf(direct_data, "%08x ", value); 49168c2ecf20Sopenharmony_ci offset += 4; 49178c2ecf20Sopenharmony_ci } 49188c2ecf20Sopenharmony_ci if (rem != 0) { 49198c2ecf20Sopenharmony_ci value = pm8001_cr32(pm8001_ha, bar, (work_offset + offset) & 49208c2ecf20Sopenharmony_ci 0x0000FFFF); 49218c2ecf20Sopenharmony_ci /* xfr for non_dw */ 49228c2ecf20Sopenharmony_ci direct_data += sprintf(direct_data, "%08x ", value); 49238c2ecf20Sopenharmony_ci } 49248c2ecf20Sopenharmony_ci /* Shift back to BAR4 original address */ 49258c2ecf20Sopenharmony_ci if (-1 == pm8001_bar4_shift(pm8001_ha, 0)) 49268c2ecf20Sopenharmony_ci return -EIO; 49278c2ecf20Sopenharmony_ci pm8001_ha->fatal_forensic_shift_offset += 1024; 49288c2ecf20Sopenharmony_ci 49298c2ecf20Sopenharmony_ci if (pm8001_ha->fatal_forensic_shift_offset >= 0x100000) 49308c2ecf20Sopenharmony_ci pm8001_ha->fatal_forensic_shift_offset = 0; 49318c2ecf20Sopenharmony_ci return direct_data - buf; 49328c2ecf20Sopenharmony_ci} 49338c2ecf20Sopenharmony_ci 49348c2ecf20Sopenharmony_ciint 49358c2ecf20Sopenharmony_cipm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha, 49368c2ecf20Sopenharmony_ci struct pm8001_device *pm8001_dev, u32 state) 49378c2ecf20Sopenharmony_ci{ 49388c2ecf20Sopenharmony_ci struct set_dev_state_req payload; 49398c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 49408c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 49418c2ecf20Sopenharmony_ci int rc; 49428c2ecf20Sopenharmony_ci u32 tag; 49438c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SET_DEVICE_STATE; 49448c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 49458c2ecf20Sopenharmony_ci rc = pm8001_tag_alloc(pm8001_ha, &tag); 49468c2ecf20Sopenharmony_ci if (rc) 49478c2ecf20Sopenharmony_ci return -1; 49488c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 49498c2ecf20Sopenharmony_ci ccb->ccb_tag = tag; 49508c2ecf20Sopenharmony_ci ccb->device = pm8001_dev; 49518c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 49528c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(tag); 49538c2ecf20Sopenharmony_ci payload.device_id = cpu_to_le32(pm8001_dev->device_id); 49548c2ecf20Sopenharmony_ci payload.nds = cpu_to_le32(state); 49558c2ecf20Sopenharmony_ci rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 49568c2ecf20Sopenharmony_ci sizeof(payload), 0); 49578c2ecf20Sopenharmony_ci if (rc) 49588c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 49598c2ecf20Sopenharmony_ci 49608c2ecf20Sopenharmony_ci return rc; 49618c2ecf20Sopenharmony_ci 49628c2ecf20Sopenharmony_ci} 49638c2ecf20Sopenharmony_ci 49648c2ecf20Sopenharmony_cistatic int 49658c2ecf20Sopenharmony_cipm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha) 49668c2ecf20Sopenharmony_ci{ 49678c2ecf20Sopenharmony_ci struct sas_re_initialization_req payload; 49688c2ecf20Sopenharmony_ci struct inbound_queue_table *circularQ; 49698c2ecf20Sopenharmony_ci struct pm8001_ccb_info *ccb; 49708c2ecf20Sopenharmony_ci int rc; 49718c2ecf20Sopenharmony_ci u32 tag; 49728c2ecf20Sopenharmony_ci u32 opc = OPC_INB_SAS_RE_INITIALIZE; 49738c2ecf20Sopenharmony_ci memset(&payload, 0, sizeof(payload)); 49748c2ecf20Sopenharmony_ci rc = pm8001_tag_alloc(pm8001_ha, &tag); 49758c2ecf20Sopenharmony_ci if (rc) 49768c2ecf20Sopenharmony_ci return -ENOMEM; 49778c2ecf20Sopenharmony_ci ccb = &pm8001_ha->ccb_info[tag]; 49788c2ecf20Sopenharmony_ci ccb->ccb_tag = tag; 49798c2ecf20Sopenharmony_ci circularQ = &pm8001_ha->inbnd_q_tbl[0]; 49808c2ecf20Sopenharmony_ci payload.tag = cpu_to_le32(tag); 49818c2ecf20Sopenharmony_ci payload.SSAHOLT = cpu_to_le32(0xd << 25); 49828c2ecf20Sopenharmony_ci payload.sata_hol_tmo = cpu_to_le32(80); 49838c2ecf20Sopenharmony_ci payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff); 49848c2ecf20Sopenharmony_ci rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 49858c2ecf20Sopenharmony_ci sizeof(payload), 0); 49868c2ecf20Sopenharmony_ci if (rc) 49878c2ecf20Sopenharmony_ci pm8001_tag_free(pm8001_ha, tag); 49888c2ecf20Sopenharmony_ci return rc; 49898c2ecf20Sopenharmony_ci 49908c2ecf20Sopenharmony_ci} 49918c2ecf20Sopenharmony_ci 49928c2ecf20Sopenharmony_ciconst struct pm8001_dispatch pm8001_8001_dispatch = { 49938c2ecf20Sopenharmony_ci .name = "pmc8001", 49948c2ecf20Sopenharmony_ci .chip_init = pm8001_chip_init, 49958c2ecf20Sopenharmony_ci .chip_soft_rst = pm8001_chip_soft_rst, 49968c2ecf20Sopenharmony_ci .chip_rst = pm8001_hw_chip_rst, 49978c2ecf20Sopenharmony_ci .chip_iounmap = pm8001_chip_iounmap, 49988c2ecf20Sopenharmony_ci .isr = pm8001_chip_isr, 49998c2ecf20Sopenharmony_ci .is_our_interrupt = pm8001_chip_is_our_interrupt, 50008c2ecf20Sopenharmony_ci .isr_process_oq = process_oq, 50018c2ecf20Sopenharmony_ci .interrupt_enable = pm8001_chip_interrupt_enable, 50028c2ecf20Sopenharmony_ci .interrupt_disable = pm8001_chip_interrupt_disable, 50038c2ecf20Sopenharmony_ci .make_prd = pm8001_chip_make_sg, 50048c2ecf20Sopenharmony_ci .smp_req = pm8001_chip_smp_req, 50058c2ecf20Sopenharmony_ci .ssp_io_req = pm8001_chip_ssp_io_req, 50068c2ecf20Sopenharmony_ci .sata_req = pm8001_chip_sata_req, 50078c2ecf20Sopenharmony_ci .phy_start_req = pm8001_chip_phy_start_req, 50088c2ecf20Sopenharmony_ci .phy_stop_req = pm8001_chip_phy_stop_req, 50098c2ecf20Sopenharmony_ci .reg_dev_req = pm8001_chip_reg_dev_req, 50108c2ecf20Sopenharmony_ci .dereg_dev_req = pm8001_chip_dereg_dev_req, 50118c2ecf20Sopenharmony_ci .phy_ctl_req = pm8001_chip_phy_ctl_req, 50128c2ecf20Sopenharmony_ci .task_abort = pm8001_chip_abort_task, 50138c2ecf20Sopenharmony_ci .ssp_tm_req = pm8001_chip_ssp_tm_req, 50148c2ecf20Sopenharmony_ci .get_nvmd_req = pm8001_chip_get_nvmd_req, 50158c2ecf20Sopenharmony_ci .set_nvmd_req = pm8001_chip_set_nvmd_req, 50168c2ecf20Sopenharmony_ci .fw_flash_update_req = pm8001_chip_fw_flash_update_req, 50178c2ecf20Sopenharmony_ci .set_dev_state_req = pm8001_chip_set_dev_state_req, 50188c2ecf20Sopenharmony_ci .sas_re_init_req = pm8001_chip_sas_re_initialization, 50198c2ecf20Sopenharmony_ci}; 5020