Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1 | /* |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 2 | * Linux MegaRAID driver for SAS based RAID controllers |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 4 | * Copyright (c) 2003-2013 LSI Corporation |
| 5 | * Copyright (c) 2013-2014 Avago Technologies |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 11 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 16 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 19 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 20 | * Authors: Avago Technologies |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 21 | * Sreenivas Bagalkote |
| 22 | * Sumant Patro |
| 23 | * Bo Yang |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 24 | * Adam Radford |
| 25 | * Kashyap Desai <kashyap.desai@avagotech.com> |
| 26 | * Sumit Saxena <sumit.saxena@avagotech.com> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 27 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 28 | * Send feedback to: megaraidlinux.pdl@avagotech.com |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 29 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 30 | * Mail to: Avago Technologies, 350 West Trimble Road, Building 90, |
| 31 | * San Jose, California 95131 |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/types.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/list.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 38 | #include <linux/moduleparam.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/spinlock.h> |
| 41 | #include <linux/interrupt.h> |
| 42 | #include <linux/delay.h> |
| 43 | #include <linux/uio.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 45 | #include <linux/uaccess.h> |
Al Viro | 4339923 | 2005-10-04 17:36:04 +0100 | [diff] [blame] | 46 | #include <linux/fs.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 47 | #include <linux/compat.h> |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 48 | #include <linux/blkdev.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 49 | #include <linux/mutex.h> |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 50 | #include <linux/poll.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 51 | |
| 52 | #include <scsi/scsi.h> |
| 53 | #include <scsi/scsi_cmnd.h> |
| 54 | #include <scsi/scsi_device.h> |
| 55 | #include <scsi/scsi_host.h> |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 56 | #include <scsi/scsi_tcq.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 57 | #include "megaraid_sas_fusion.h" |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 58 | #include "megaraid_sas.h" |
| 59 | |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 60 | /* |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 61 | * Number of sectors per IO command |
| 62 | * Will be set in megasas_init_mfi if user does not provide |
| 63 | */ |
| 64 | static unsigned int max_sectors; |
| 65 | module_param_named(max_sectors, max_sectors, int, 0); |
| 66 | MODULE_PARM_DESC(max_sectors, |
| 67 | "Maximum number of sectors per IO command"); |
| 68 | |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 69 | static int msix_disable; |
| 70 | module_param(msix_disable, int, S_IRUGO); |
| 71 | MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0"); |
| 72 | |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 73 | static unsigned int msix_vectors; |
| 74 | module_param(msix_vectors, int, S_IRUGO); |
| 75 | MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW"); |
| 76 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 77 | static int allow_vf_ioctls; |
| 78 | module_param(allow_vf_ioctls, int, S_IRUGO); |
| 79 | MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0"); |
| 80 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 81 | static unsigned int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH; |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 82 | module_param(throttlequeuedepth, int, S_IRUGO); |
| 83 | MODULE_PARM_DESC(throttlequeuedepth, |
| 84 | "Adapter queue depth when throttled due to I/O timeout. Default: 16"); |
| 85 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 86 | unsigned int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 87 | module_param(resetwaittime, int, S_IRUGO); |
| 88 | MODULE_PARM_DESC(resetwaittime, "Wait time in seconds after I/O timeout " |
| 89 | "before resetting adapter. Default: 180"); |
| 90 | |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 91 | int smp_affinity_enable = 1; |
| 92 | module_param(smp_affinity_enable, int, S_IRUGO); |
| 93 | MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disbale Default: enable(1)"); |
| 94 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 95 | int rdpq_enable = 1; |
| 96 | module_param(rdpq_enable, int, S_IRUGO); |
| 97 | MODULE_PARM_DESC(rdpq_enable, " Allocate reply queue in chunks for large queue depth enable/disable Default: disable(0)"); |
| 98 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 99 | unsigned int dual_qdepth_disable; |
| 100 | module_param(dual_qdepth_disable, int, S_IRUGO); |
| 101 | MODULE_PARM_DESC(dual_qdepth_disable, "Disable dual queue depth feature. Default: 0"); |
| 102 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 103 | unsigned int scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
| 104 | module_param(scmd_timeout, int, S_IRUGO); |
| 105 | MODULE_PARM_DESC(scmd_timeout, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer."); |
| 106 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 107 | MODULE_LICENSE("GPL"); |
| 108 | MODULE_VERSION(MEGASAS_VERSION); |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 109 | MODULE_AUTHOR("megaraidlinux.pdl@avagotech.com"); |
| 110 | MODULE_DESCRIPTION("Avago MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 111 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 112 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 113 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 114 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 115 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 116 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 117 | static int megasas_register_aen(struct megasas_instance *instance, |
| 118 | u32 seq_num, u32 class_locale_word); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 119 | static void megasas_get_pd_info(struct megasas_instance *instance, |
| 120 | struct scsi_device *sdev); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 121 | static int megasas_get_target_prop(struct megasas_instance *instance, |
| 122 | struct scsi_device *sdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 123 | /* |
| 124 | * PCI ID table for all supported controllers |
| 125 | */ |
| 126 | static struct pci_device_id megasas_pci_table[] = { |
| 127 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 128 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 129 | /* xscale IOP */ |
| 130 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 131 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 132 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 133 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 134 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 135 | /* gen2*/ |
| 136 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 137 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 138 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 139 | /* skinny*/ |
| 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 141 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 142 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 143 | /* xscale IOP, vega */ |
| 144 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 145 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 146 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 147 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 148 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 149 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 150 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 151 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 152 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 153 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 154 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 155 | /* Intruder */ |
| 156 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 157 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 158 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 159 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_53)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 160 | /* VENTURA */ |
| 161 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)}, |
| 162 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)}, |
| 163 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)}, |
| 164 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)}, |
| 165 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER_4PORT)}, |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 166 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 170 | |
| 171 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 172 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 173 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 174 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 175 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 176 | static int megasas_poll_wait_aen; |
| 177 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 178 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 179 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 180 | static u32 support_device_change; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 181 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 182 | /* define lock for aen poll */ |
| 183 | spinlock_t poll_aen_lock; |
| 184 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 185 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 186 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 187 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 188 | static u32 |
| 189 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs); |
| 190 | static int |
| 191 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 192 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 193 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 194 | static u32 |
| 195 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 196 | u32 |
| 197 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 198 | struct scsi_cmnd *scmd); |
| 199 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 200 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 201 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 202 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 203 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 204 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 205 | int initial); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 206 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 207 | void |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 208 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 209 | { |
| 210 | instance->instancet->fire_cmd(instance, |
| 211 | cmd->frame_phys_addr, 0, instance->reg_set); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 212 | return; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 213 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 214 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 215 | /** |
| 216 | * megasas_get_cmd - Get a command from the free pool |
| 217 | * @instance: Adapter soft state |
| 218 | * |
| 219 | * Returns a free command from the pool |
| 220 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 221 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 222 | *instance) |
| 223 | { |
| 224 | unsigned long flags; |
| 225 | struct megasas_cmd *cmd = NULL; |
| 226 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 227 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 228 | |
| 229 | if (!list_empty(&instance->cmd_pool)) { |
| 230 | cmd = list_entry((&instance->cmd_pool)->next, |
| 231 | struct megasas_cmd, list); |
| 232 | list_del_init(&cmd->list); |
| 233 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 234 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 235 | } |
| 236 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 237 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 238 | return cmd; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * megasas_return_cmd - Return a cmd to free command pool |
| 243 | * @instance: Adapter soft state |
| 244 | * @cmd: Command packet to be returned to free command pool |
| 245 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 246 | inline void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 247 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 248 | { |
| 249 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 250 | u32 blk_tags; |
| 251 | struct megasas_cmd_fusion *cmd_fusion; |
| 252 | struct fusion_context *fusion = instance->ctrl_context; |
| 253 | |
| 254 | /* This flag is used only for fusion adapter. |
| 255 | * Wait for Interrupt for Polled mode DCMD |
| 256 | */ |
| 257 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 258 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 259 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 260 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 261 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 262 | if (fusion) { |
| 263 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 264 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 265 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 266 | } |
| 267 | cmd->scmd = NULL; |
| 268 | cmd->frame_count = 0; |
| 269 | cmd->flags = 0; |
| 270 | if (!fusion && reset_devices) |
| 271 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 272 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 273 | |
| 274 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 275 | |
| 276 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 277 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 278 | static const char * |
| 279 | format_timestamp(uint32_t timestamp) |
| 280 | { |
| 281 | static char buffer[32]; |
| 282 | |
| 283 | if ((timestamp & 0xff000000) == 0xff000000) |
| 284 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 285 | 0x00ffffff); |
| 286 | else |
| 287 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 288 | return buffer; |
| 289 | } |
| 290 | |
| 291 | static const char * |
| 292 | format_class(int8_t class) |
| 293 | { |
| 294 | static char buffer[6]; |
| 295 | |
| 296 | switch (class) { |
| 297 | case MFI_EVT_CLASS_DEBUG: |
| 298 | return "debug"; |
| 299 | case MFI_EVT_CLASS_PROGRESS: |
| 300 | return "progress"; |
| 301 | case MFI_EVT_CLASS_INFO: |
| 302 | return "info"; |
| 303 | case MFI_EVT_CLASS_WARNING: |
| 304 | return "WARN"; |
| 305 | case MFI_EVT_CLASS_CRITICAL: |
| 306 | return "CRIT"; |
| 307 | case MFI_EVT_CLASS_FATAL: |
| 308 | return "FATAL"; |
| 309 | case MFI_EVT_CLASS_DEAD: |
| 310 | return "DEAD"; |
| 311 | default: |
| 312 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 313 | return buffer; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 319 | * for information. |
| 320 | * @instance: Adapter soft state |
| 321 | */ |
| 322 | static void |
| 323 | megasas_decode_evt(struct megasas_instance *instance) |
| 324 | { |
| 325 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 326 | union megasas_evt_class_locale class_locale; |
| 327 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 328 | |
| 329 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 330 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 331 | le32_to_cpu(evt_detail->seq_num), |
| 332 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 333 | (class_locale.members.locale), |
| 334 | format_class(class_locale.members.class), |
| 335 | evt_detail->description); |
| 336 | } |
| 337 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 338 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 339 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 340 | * (deviceid : 1064R, PERC5) controllers |
| 341 | */ |
| 342 | |
| 343 | /** |
| 344 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 345 | * @regs: MFI register set |
| 346 | */ |
| 347 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 348 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 349 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 350 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 351 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 352 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 353 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 354 | |
| 355 | /* Dummy readl to force pci flush */ |
| 356 | readl(®s->outbound_intr_mask); |
| 357 | } |
| 358 | |
| 359 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 360 | * megasas_disable_intr_xscale -Disables interrupt |
| 361 | * @regs: MFI register set |
| 362 | */ |
| 363 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 364 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 365 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 366 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 367 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 368 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 369 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 370 | writel(mask, ®s->outbound_intr_mask); |
| 371 | /* Dummy readl to force pci flush */ |
| 372 | readl(®s->outbound_intr_mask); |
| 373 | } |
| 374 | |
| 375 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 376 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 377 | * @regs: MFI register set |
| 378 | */ |
| 379 | static u32 |
| 380 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 381 | { |
| 382 | return readl(&(regs)->outbound_msg_0); |
| 383 | } |
| 384 | /** |
| 385 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 386 | * @regs: MFI register set |
| 387 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 388 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 389 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 390 | { |
| 391 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 392 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 393 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 394 | /* |
| 395 | * Check if it is our interrupt |
| 396 | */ |
| 397 | status = readl(®s->outbound_intr_status); |
| 398 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 399 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 400 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 401 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 402 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | * Clear the interrupt by writing back the same value |
| 406 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 407 | if (mfiStatus) |
| 408 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 409 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 410 | /* Dummy readl to force pci flush */ |
| 411 | readl(®s->outbound_intr_status); |
| 412 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 413 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /** |
| 417 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 418 | * @frame_phys_addr : Physical address of cmd |
| 419 | * @frame_count : Number of frames for the command |
| 420 | * @regs : MFI register set |
| 421 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 422 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 423 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 424 | dma_addr_t frame_phys_addr, |
| 425 | u32 frame_count, |
| 426 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 427 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 428 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 429 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 430 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 431 | writel((frame_phys_addr >> 3)|(frame_count), |
| 432 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 433 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * megasas_adp_reset_xscale - For controller reset |
| 438 | * @regs: MFI register set |
| 439 | */ |
| 440 | static int |
| 441 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 442 | struct megasas_register_set __iomem *regs) |
| 443 | { |
| 444 | u32 i; |
| 445 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 446 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 447 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 448 | |
| 449 | for (i = 0; i < 3; i++) |
| 450 | msleep(1000); /* sleep for 3 secs */ |
| 451 | pcidata = 0; |
| 452 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 453 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 454 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 455 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 456 | pcidata &= ~0x2; |
| 457 | pci_write_config_dword(instance->pdev, |
| 458 | MFI_1068_PCSR_OFFSET, pcidata); |
| 459 | |
| 460 | for (i = 0; i < 2; i++) |
| 461 | msleep(1000); /* need to wait 2 secs again */ |
| 462 | |
| 463 | pcidata = 0; |
| 464 | pci_read_config_dword(instance->pdev, |
| 465 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 466 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 467 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 468 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 469 | pcidata = 0; |
| 470 | pci_write_config_dword(instance->pdev, |
| 471 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 472 | } |
| 473 | } |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * megasas_check_reset_xscale - For controller reset check |
| 479 | * @regs: MFI register set |
| 480 | */ |
| 481 | static int |
| 482 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 483 | struct megasas_register_set __iomem *regs) |
| 484 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 485 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 486 | (le32_to_cpu(*instance->consumer) == |
| 487 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 488 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 489 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 493 | |
| 494 | .fire_cmd = megasas_fire_cmd_xscale, |
| 495 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 496 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 497 | .clear_intr = megasas_clear_intr_xscale, |
| 498 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 499 | .adp_reset = megasas_adp_reset_xscale, |
| 500 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 501 | .service_isr = megasas_isr, |
| 502 | .tasklet = megasas_complete_cmd_dpc, |
| 503 | .init_adapter = megasas_init_adapter_mfi, |
| 504 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 505 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 509 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 510 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 511 | */ |
| 512 | |
| 513 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 514 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 515 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 516 | */ |
| 517 | |
| 518 | /** |
| 519 | * megasas_enable_intr_ppc - Enables interrupts |
| 520 | * @regs: MFI register set |
| 521 | */ |
| 522 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 523 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 524 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 525 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 526 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 527 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 528 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 529 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 530 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 531 | |
| 532 | /* Dummy readl to force pci flush */ |
| 533 | readl(®s->outbound_intr_mask); |
| 534 | } |
| 535 | |
| 536 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 537 | * megasas_disable_intr_ppc - Disable interrupt |
| 538 | * @regs: MFI register set |
| 539 | */ |
| 540 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 541 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 542 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 543 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 544 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 545 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 546 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 547 | writel(mask, ®s->outbound_intr_mask); |
| 548 | /* Dummy readl to force pci flush */ |
| 549 | readl(®s->outbound_intr_mask); |
| 550 | } |
| 551 | |
| 552 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 553 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 554 | * @regs: MFI register set |
| 555 | */ |
| 556 | static u32 |
| 557 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 558 | { |
| 559 | return readl(&(regs)->outbound_scratch_pad); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 564 | * @regs: MFI register set |
| 565 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 566 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 567 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 568 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 569 | u32 status, mfiStatus = 0; |
| 570 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 571 | /* |
| 572 | * Check if it is our interrupt |
| 573 | */ |
| 574 | status = readl(®s->outbound_intr_status); |
| 575 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 576 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 577 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 578 | |
| 579 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 580 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 581 | |
| 582 | /* |
| 583 | * Clear the interrupt by writing back the same value |
| 584 | */ |
| 585 | writel(status, ®s->outbound_doorbell_clear); |
| 586 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 587 | /* Dummy readl to force pci flush */ |
| 588 | readl(®s->outbound_doorbell_clear); |
| 589 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 590 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 591 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 592 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 593 | /** |
| 594 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 595 | * @frame_phys_addr : Physical address of cmd |
| 596 | * @frame_count : Number of frames for the command |
| 597 | * @regs : MFI register set |
| 598 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 599 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 600 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 601 | dma_addr_t frame_phys_addr, |
| 602 | u32 frame_count, |
| 603 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 604 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 605 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 606 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 607 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 608 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 609 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 610 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 611 | } |
| 612 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 613 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 614 | * megasas_check_reset_ppc - For controller reset check |
| 615 | * @regs: MFI register set |
| 616 | */ |
| 617 | static int |
| 618 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 619 | struct megasas_register_set __iomem *regs) |
| 620 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 621 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 622 | return 1; |
| 623 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 624 | return 0; |
| 625 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 626 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 627 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 628 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 629 | .fire_cmd = megasas_fire_cmd_ppc, |
| 630 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 631 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 632 | .clear_intr = megasas_clear_intr_ppc, |
| 633 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 634 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 635 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 636 | .service_isr = megasas_isr, |
| 637 | .tasklet = megasas_complete_cmd_dpc, |
| 638 | .init_adapter = megasas_init_adapter_mfi, |
| 639 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 640 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 641 | }; |
| 642 | |
| 643 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 644 | * megasas_enable_intr_skinny - Enables interrupts |
| 645 | * @regs: MFI register set |
| 646 | */ |
| 647 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 648 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 649 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 650 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 651 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 652 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 653 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 654 | |
| 655 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 656 | |
| 657 | /* Dummy readl to force pci flush */ |
| 658 | readl(®s->outbound_intr_mask); |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * megasas_disable_intr_skinny - Disables interrupt |
| 663 | * @regs: MFI register set |
| 664 | */ |
| 665 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 666 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 667 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 668 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 669 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 670 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 671 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 672 | writel(mask, ®s->outbound_intr_mask); |
| 673 | /* Dummy readl to force pci flush */ |
| 674 | readl(®s->outbound_intr_mask); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 679 | * @regs: MFI register set |
| 680 | */ |
| 681 | static u32 |
| 682 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 683 | { |
| 684 | return readl(&(regs)->outbound_scratch_pad); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 689 | * @regs: MFI register set |
| 690 | */ |
| 691 | static int |
| 692 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 693 | { |
| 694 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 695 | u32 mfiStatus = 0; |
| 696 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 697 | /* |
| 698 | * Check if it is our interrupt |
| 699 | */ |
| 700 | status = readl(®s->outbound_intr_status); |
| 701 | |
| 702 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 703 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 707 | * Check if it is our interrupt |
| 708 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 709 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 710 | MFI_STATE_FAULT) { |
| 711 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 712 | } else |
| 713 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 714 | |
| 715 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 716 | * Clear the interrupt by writing back the same value |
| 717 | */ |
| 718 | writel(status, ®s->outbound_intr_status); |
| 719 | |
| 720 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 721 | * dummy read to flush PCI |
| 722 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 723 | readl(®s->outbound_intr_status); |
| 724 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 725 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /** |
| 729 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 730 | * @frame_phys_addr : Physical address of cmd |
| 731 | * @frame_count : Number of frames for the command |
| 732 | * @regs : MFI register set |
| 733 | */ |
| 734 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 735 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 736 | dma_addr_t frame_phys_addr, |
| 737 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 738 | struct megasas_register_set __iomem *regs) |
| 739 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 740 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 741 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 742 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 743 | writel(upper_32_bits(frame_phys_addr), |
| 744 | &(regs)->inbound_high_queue_port); |
| 745 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 746 | &(regs)->inbound_low_queue_port); |
Tomas Henzl | b99dbe5 | 2016-02-01 15:12:04 +0100 | [diff] [blame] | 747 | mmiowb(); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 748 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 749 | } |
| 750 | |
| 751 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 752 | * megasas_check_reset_skinny - For controller reset check |
| 753 | * @regs: MFI register set |
| 754 | */ |
| 755 | static int |
| 756 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 757 | struct megasas_register_set __iomem *regs) |
| 758 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 759 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 760 | return 1; |
| 761 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 762 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 766 | |
| 767 | .fire_cmd = megasas_fire_cmd_skinny, |
| 768 | .enable_intr = megasas_enable_intr_skinny, |
| 769 | .disable_intr = megasas_disable_intr_skinny, |
| 770 | .clear_intr = megasas_clear_intr_skinny, |
| 771 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 772 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 773 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 774 | .service_isr = megasas_isr, |
| 775 | .tasklet = megasas_complete_cmd_dpc, |
| 776 | .init_adapter = megasas_init_adapter_mfi, |
| 777 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 778 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | |
| 782 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 783 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 784 | * controllers |
| 785 | */ |
| 786 | |
| 787 | /** |
| 788 | * megasas_enable_intr_gen2 - Enables interrupts |
| 789 | * @regs: MFI register set |
| 790 | */ |
| 791 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 792 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 793 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 794 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 795 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 796 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 797 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 798 | |
| 799 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 800 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 801 | |
| 802 | /* Dummy readl to force pci flush */ |
| 803 | readl(®s->outbound_intr_mask); |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * megasas_disable_intr_gen2 - Disables interrupt |
| 808 | * @regs: MFI register set |
| 809 | */ |
| 810 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 811 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 812 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 813 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 814 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 815 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 816 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 817 | writel(mask, ®s->outbound_intr_mask); |
| 818 | /* Dummy readl to force pci flush */ |
| 819 | readl(®s->outbound_intr_mask); |
| 820 | } |
| 821 | |
| 822 | /** |
| 823 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 824 | * @regs: MFI register set |
| 825 | */ |
| 826 | static u32 |
| 827 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 828 | { |
| 829 | return readl(&(regs)->outbound_scratch_pad); |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 834 | * @regs: MFI register set |
| 835 | */ |
| 836 | static int |
| 837 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 838 | { |
| 839 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 840 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 841 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 842 | /* |
| 843 | * Check if it is our interrupt |
| 844 | */ |
| 845 | status = readl(®s->outbound_intr_status); |
| 846 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 847 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 848 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 849 | } |
| 850 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 851 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 852 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 853 | |
| 854 | /* |
| 855 | * Clear the interrupt by writing back the same value |
| 856 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 857 | if (mfiStatus) |
| 858 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 859 | |
| 860 | /* Dummy readl to force pci flush */ |
| 861 | readl(®s->outbound_intr_status); |
| 862 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 863 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 864 | } |
| 865 | /** |
| 866 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 867 | * @frame_phys_addr : Physical address of cmd |
| 868 | * @frame_count : Number of frames for the command |
| 869 | * @regs : MFI register set |
| 870 | */ |
| 871 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 872 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 873 | dma_addr_t frame_phys_addr, |
| 874 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 875 | struct megasas_register_set __iomem *regs) |
| 876 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 877 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 878 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 879 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 880 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 881 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 882 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * megasas_adp_reset_gen2 - For controller reset |
| 887 | * @regs: MFI register set |
| 888 | */ |
| 889 | static int |
| 890 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 891 | struct megasas_register_set __iomem *reg_set) |
| 892 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 893 | u32 retry = 0 ; |
| 894 | u32 HostDiag; |
| 895 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 896 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 897 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 898 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 899 | seq_offset = ®_set->fusion_seq_offset; |
| 900 | hostdiag_offset = ®_set->fusion_host_diag; |
| 901 | } |
| 902 | |
| 903 | writel(0, seq_offset); |
| 904 | writel(4, seq_offset); |
| 905 | writel(0xb, seq_offset); |
| 906 | writel(2, seq_offset); |
| 907 | writel(7, seq_offset); |
| 908 | writel(0xd, seq_offset); |
| 909 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 910 | msleep(1000); |
| 911 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 912 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 913 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 914 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 915 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 916 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 917 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 918 | retry, HostDiag); |
| 919 | |
| 920 | if (retry++ >= 100) |
| 921 | return 1; |
| 922 | |
| 923 | } |
| 924 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 925 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 926 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 927 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 928 | |
| 929 | ssleep(10); |
| 930 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 931 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 932 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 933 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 934 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 935 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 936 | retry, HostDiag); |
| 937 | |
| 938 | if (retry++ >= 1000) |
| 939 | return 1; |
| 940 | |
| 941 | } |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | /** |
| 946 | * megasas_check_reset_gen2 - For controller reset check |
| 947 | * @regs: MFI register set |
| 948 | */ |
| 949 | static int |
| 950 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 951 | struct megasas_register_set __iomem *regs) |
| 952 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 953 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 954 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 955 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 956 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 960 | |
| 961 | .fire_cmd = megasas_fire_cmd_gen2, |
| 962 | .enable_intr = megasas_enable_intr_gen2, |
| 963 | .disable_intr = megasas_disable_intr_gen2, |
| 964 | .clear_intr = megasas_clear_intr_gen2, |
| 965 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 966 | .adp_reset = megasas_adp_reset_gen2, |
| 967 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 968 | .service_isr = megasas_isr, |
| 969 | .tasklet = megasas_complete_cmd_dpc, |
| 970 | .init_adapter = megasas_init_adapter_mfi, |
| 971 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 972 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 973 | }; |
| 974 | |
| 975 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 976 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 977 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 978 | */ |
| 979 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 980 | /* |
| 981 | * Template added for TB (Fusion) |
| 982 | */ |
| 983 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 984 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 985 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 986 | * megasas_issue_polled - Issues a polling command |
| 987 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 988 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 989 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 990 | * For polling, MFI requires the cmd_status to be set to MFI_STAT_INVALID_STATUS before posting. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 991 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 992 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 993 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 994 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 995 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 996 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 997 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 998 | frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 999 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1000 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1001 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1002 | __func__, __LINE__); |
| 1003 | return DCMD_NOT_FIRED; |
| 1004 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1005 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1006 | instance->instancet->issue_dcmd(instance, cmd); |
| 1007 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1008 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1009 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1014 | * @instance: Adapter soft state |
| 1015 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1016 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1017 | * |
| 1018 | * This function waits on an event for the command to be returned from ISR. |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1019 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1020 | * Used to issue ioctl commands. |
| 1021 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1022 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1023 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1024 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1025 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1026 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1027 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1028 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1029 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1030 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1031 | __func__, __LINE__); |
| 1032 | return DCMD_NOT_FIRED; |
| 1033 | } |
| 1034 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1035 | instance->instancet->issue_dcmd(instance, cmd); |
| 1036 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1037 | if (timeout) { |
| 1038 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1039 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1040 | if (!ret) { |
| 1041 | dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n", |
| 1042 | __func__, __LINE__); |
| 1043 | return DCMD_TIMEOUT; |
| 1044 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1045 | } else |
| 1046 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1047 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1048 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1049 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1050 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1055 | * @instance: Adapter soft state |
| 1056 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1057 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1058 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1059 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1060 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1061 | * cmd and waits for return status. |
| 1062 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1063 | */ |
| 1064 | static int |
| 1065 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1066 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1067 | { |
| 1068 | struct megasas_cmd *cmd; |
| 1069 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1070 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1071 | |
| 1072 | cmd = megasas_get_cmd(instance); |
| 1073 | |
| 1074 | if (!cmd) |
| 1075 | return -1; |
| 1076 | |
| 1077 | abort_fr = &cmd->frame->abort; |
| 1078 | |
| 1079 | /* |
| 1080 | * Prepare and issue the abort frame |
| 1081 | */ |
| 1082 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1083 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1084 | abort_fr->flags = cpu_to_le16(0); |
| 1085 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1086 | abort_fr->abort_mfi_phys_addr_lo = |
| 1087 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1088 | abort_fr->abort_mfi_phys_addr_hi = |
| 1089 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1090 | |
| 1091 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1092 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1093 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1094 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1095 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1096 | __func__, __LINE__); |
| 1097 | return DCMD_NOT_FIRED; |
| 1098 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1099 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1100 | instance->instancet->issue_dcmd(instance, cmd); |
| 1101 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1102 | if (timeout) { |
| 1103 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1104 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1105 | if (!ret) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1106 | dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n", |
| 1107 | __func__, __LINE__); |
| 1108 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1109 | } |
| 1110 | } else |
| 1111 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1112 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1113 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1114 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1115 | |
| 1116 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1117 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1118 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1123 | * @instance: Adapter soft state |
| 1124 | * @scp: SCSI command from the mid-layer |
| 1125 | * @mfi_sgl: SGL to be filled in |
| 1126 | * |
| 1127 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1128 | * it returnes -1. |
| 1129 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1130 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1131 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1132 | union megasas_sgl *mfi_sgl) |
| 1133 | { |
| 1134 | int i; |
| 1135 | int sge_count; |
| 1136 | struct scatterlist *os_sgl; |
| 1137 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1138 | sge_count = scsi_dma_map(scp); |
| 1139 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1140 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1141 | if (sge_count) { |
| 1142 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1143 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1144 | mfi_sgl->sge32[i].phys_addr = cpu_to_le32(sg_dma_address(os_sgl)); |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1145 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1146 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1147 | return sge_count; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1152 | * @instance: Adapter soft state |
| 1153 | * @scp: SCSI command from the mid-layer |
| 1154 | * @mfi_sgl: SGL to be filled in |
| 1155 | * |
| 1156 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1157 | * it returnes -1. |
| 1158 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1159 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1160 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1161 | union megasas_sgl *mfi_sgl) |
| 1162 | { |
| 1163 | int i; |
| 1164 | int sge_count; |
| 1165 | struct scatterlist *os_sgl; |
| 1166 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1167 | sge_count = scsi_dma_map(scp); |
| 1168 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1169 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1170 | if (sge_count) { |
| 1171 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1172 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1173 | mfi_sgl->sge64[i].phys_addr = cpu_to_le64(sg_dma_address(os_sgl)); |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1174 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1175 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1176 | return sge_count; |
| 1177 | } |
| 1178 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1179 | /** |
| 1180 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1181 | * @instance: Adapter soft state |
| 1182 | * @scp: SCSI command from the mid-layer |
| 1183 | * @mfi_sgl: SGL to be filled in |
| 1184 | * |
| 1185 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1186 | * it returnes -1. |
| 1187 | */ |
| 1188 | static int |
| 1189 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1190 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1191 | { |
| 1192 | int i; |
| 1193 | int sge_count; |
| 1194 | struct scatterlist *os_sgl; |
| 1195 | |
| 1196 | sge_count = scsi_dma_map(scp); |
| 1197 | |
| 1198 | if (sge_count) { |
| 1199 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1200 | mfi_sgl->sge_skinny[i].length = |
| 1201 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1202 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1203 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1204 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | return sge_count; |
| 1208 | } |
| 1209 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1210 | /** |
| 1211 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1212 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1213 | * @sge_count : number of sg elements |
| 1214 | * |
| 1215 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1216 | */ |
| 1217 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1218 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1219 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1220 | { |
| 1221 | int num_cnt; |
| 1222 | int sge_bytes; |
| 1223 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1224 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1225 | |
| 1226 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1227 | sizeof(struct megasas_sge32); |
| 1228 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1229 | if (instance->flag_ieee) { |
| 1230 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1231 | } |
| 1232 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1233 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1234 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1235 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1236 | * 1 SGEs for 64-bit SGLs and |
| 1237 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1238 | */ |
| 1239 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1240 | if (instance->flag_ieee == 1) { |
| 1241 | num_cnt = sge_count - 1; |
| 1242 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1243 | num_cnt = sge_count - 1; |
| 1244 | else |
| 1245 | num_cnt = sge_count - 2; |
| 1246 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1247 | if (instance->flag_ieee == 1) { |
| 1248 | num_cnt = sge_count - 1; |
| 1249 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1250 | num_cnt = sge_count - 2; |
| 1251 | else |
| 1252 | num_cnt = sge_count - 3; |
| 1253 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1254 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1255 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1256 | sge_bytes = sge_sz * num_cnt; |
| 1257 | |
| 1258 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1259 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1260 | } |
| 1261 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1262 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1263 | |
| 1264 | if (frame_count > 7) |
| 1265 | frame_count = 8; |
| 1266 | return frame_count; |
| 1267 | } |
| 1268 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1269 | /** |
| 1270 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1271 | * @instance: Adapter soft state |
| 1272 | * @scp: SCSI command |
| 1273 | * @cmd: Command to be prepared in |
| 1274 | * |
| 1275 | * This function prepares CDB commands. These are typcially pass-through |
| 1276 | * commands to the devices. |
| 1277 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1278 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1279 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1280 | struct megasas_cmd *cmd) |
| 1281 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1282 | u32 is_logical; |
| 1283 | u32 device_id; |
| 1284 | u16 flags = 0; |
| 1285 | struct megasas_pthru_frame *pthru; |
| 1286 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1287 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1288 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1289 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1290 | |
| 1291 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1292 | flags = MFI_FRAME_DIR_WRITE; |
| 1293 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1294 | flags = MFI_FRAME_DIR_READ; |
| 1295 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1296 | flags = MFI_FRAME_DIR_NONE; |
| 1297 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1298 | if (instance->flag_ieee == 1) { |
| 1299 | flags |= MFI_FRAME_IEEE; |
| 1300 | } |
| 1301 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1302 | /* |
| 1303 | * Prepare the DCDB frame |
| 1304 | */ |
| 1305 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1306 | pthru->cmd_status = 0x0; |
| 1307 | pthru->scsi_status = 0x0; |
| 1308 | pthru->target_id = device_id; |
| 1309 | pthru->lun = scp->device->lun; |
| 1310 | pthru->cdb_len = scp->cmd_len; |
| 1311 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1312 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1313 | pthru->flags = cpu_to_le16(flags); |
| 1314 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1315 | |
| 1316 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1317 | |
| 1318 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1319 | * If the command is for the tape device, set the |
| 1320 | * pthru timeout to the os layer timeout value. |
| 1321 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1322 | if (scp->device->type == TYPE_TAPE) { |
| 1323 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1324 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1325 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1326 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1330 | * Construct SGL |
| 1331 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1332 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1333 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1334 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1335 | &pthru->sgl); |
| 1336 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1337 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1338 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1339 | &pthru->sgl); |
| 1340 | } else |
| 1341 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1342 | &pthru->sgl); |
| 1343 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1344 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1345 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1346 | pthru->sge_count); |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1350 | /* |
| 1351 | * Sense info specific |
| 1352 | */ |
| 1353 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1354 | pthru->sense_buf_phys_addr_hi = |
| 1355 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1356 | pthru->sense_buf_phys_addr_lo = |
| 1357 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1358 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1359 | /* |
| 1360 | * Compute the total number of frames this command consumes. FW uses |
| 1361 | * this number to pull sufficient number of frames from host memory. |
| 1362 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1363 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1364 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1365 | |
| 1366 | return cmd->frame_count; |
| 1367 | } |
| 1368 | |
| 1369 | /** |
| 1370 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1371 | * @instance: Adapter soft state |
| 1372 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1373 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1374 | * |
| 1375 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1376 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1377 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1378 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1379 | struct megasas_cmd *cmd) |
| 1380 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1381 | u32 device_id; |
| 1382 | u8 sc = scp->cmnd[0]; |
| 1383 | u16 flags = 0; |
| 1384 | struct megasas_io_frame *ldio; |
| 1385 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1386 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1387 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1388 | |
| 1389 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1390 | flags = MFI_FRAME_DIR_WRITE; |
| 1391 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1392 | flags = MFI_FRAME_DIR_READ; |
| 1393 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1394 | if (instance->flag_ieee == 1) { |
| 1395 | flags |= MFI_FRAME_IEEE; |
| 1396 | } |
| 1397 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1398 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1399 | * Prepare the Logical IO frame: 2nd bit is zero for all read cmds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1400 | */ |
| 1401 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1402 | ldio->cmd_status = 0x0; |
| 1403 | ldio->scsi_status = 0x0; |
| 1404 | ldio->target_id = device_id; |
| 1405 | ldio->timeout = 0; |
| 1406 | ldio->reserved_0 = 0; |
| 1407 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1408 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1409 | ldio->start_lba_hi = 0; |
| 1410 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1411 | |
| 1412 | /* |
| 1413 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1414 | */ |
| 1415 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1416 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1417 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1418 | ((u32) scp->cmnd[2] << 8) | |
| 1419 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1420 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1421 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1426 | */ |
| 1427 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1428 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1429 | ((u32) scp->cmnd[7] << 8)); |
| 1430 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1431 | ((u32) scp->cmnd[3] << 16) | |
| 1432 | ((u32) scp->cmnd[4] << 8) | |
| 1433 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | /* |
| 1437 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1438 | */ |
| 1439 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1440 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1441 | ((u32) scp->cmnd[7] << 16) | |
| 1442 | ((u32) scp->cmnd[8] << 8) | |
| 1443 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1444 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1445 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1446 | ((u32) scp->cmnd[3] << 16) | |
| 1447 | ((u32) scp->cmnd[4] << 8) | |
| 1448 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | /* |
| 1452 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1453 | */ |
| 1454 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1455 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1456 | ((u32) scp->cmnd[11] << 16) | |
| 1457 | ((u32) scp->cmnd[12] << 8) | |
| 1458 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1459 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1460 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1461 | ((u32) scp->cmnd[7] << 16) | |
| 1462 | ((u32) scp->cmnd[8] << 8) | |
| 1463 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1464 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1465 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1466 | ((u32) scp->cmnd[3] << 16) | |
| 1467 | ((u32) scp->cmnd[4] << 8) | |
| 1468 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1469 | |
| 1470 | } |
| 1471 | |
| 1472 | /* |
| 1473 | * Construct SGL |
| 1474 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1475 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1476 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1477 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1478 | &ldio->sgl); |
| 1479 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1480 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1481 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1482 | } else |
| 1483 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1484 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1485 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1486 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1487 | ldio->sge_count); |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1491 | /* |
| 1492 | * Sense info specific |
| 1493 | */ |
| 1494 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1495 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1496 | ldio->sense_buf_phys_addr_lo = cpu_to_le32(cmd->sense_phys_addr); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1497 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1498 | /* |
| 1499 | * Compute the total number of frames this command consumes. FW uses |
| 1500 | * this number to pull sufficient number of frames from host memory. |
| 1501 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1502 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1503 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1504 | |
| 1505 | return cmd->frame_count; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1509 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1510 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1511 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1512 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1513 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1514 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1515 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1516 | int ret; |
| 1517 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1518 | switch (cmd->cmnd[0]) { |
| 1519 | case READ_10: |
| 1520 | case WRITE_10: |
| 1521 | case READ_12: |
| 1522 | case WRITE_12: |
| 1523 | case READ_6: |
| 1524 | case WRITE_6: |
| 1525 | case READ_16: |
| 1526 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1527 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1528 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1529 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1530 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1531 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1532 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1533 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1534 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1537 | /** |
| 1538 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1539 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1540 | * @instance: Adapter soft state |
| 1541 | */ |
| 1542 | static inline void |
| 1543 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1544 | { |
| 1545 | struct megasas_cmd *cmd; |
| 1546 | int i,n; |
| 1547 | union megasas_sgl *mfi_sgl; |
| 1548 | struct megasas_io_frame *ldio; |
| 1549 | struct megasas_pthru_frame *pthru; |
| 1550 | u32 sgcount; |
| 1551 | u32 max_cmd = instance->max_fw_cmds; |
| 1552 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1553 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1554 | dev_err(&instance->pdev->dev, "[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1555 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1556 | dev_err(&instance->pdev->dev, "[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1557 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1558 | dev_err(&instance->pdev->dev, "[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1559 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1560 | dev_err(&instance->pdev->dev, "[%d]: Pending OS cmds in FW : \n",instance->host->host_no); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1561 | for (i = 0; i < max_cmd; i++) { |
| 1562 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1563 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1564 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1565 | dev_err(&instance->pdev->dev, "[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr); |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1566 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1567 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1568 | mfi_sgl = &ldio->sgl; |
| 1569 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1570 | dev_err(&instance->pdev->dev, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x," |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1571 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1572 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1573 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1574 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1575 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1576 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1577 | mfi_sgl = &pthru->sgl; |
| 1578 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1579 | dev_err(&instance->pdev->dev, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, " |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1580 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1581 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1582 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1583 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1584 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1585 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1586 | for (n = 0; n < sgcount; n++) { |
| 1587 | if (IS_DMA64) |
| 1588 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1589 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1590 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1591 | else |
| 1592 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1593 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1594 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1597 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1598 | dev_err(&instance->pdev->dev, "[%d]: Pending Internal cmds in FW : \n",instance->host->host_no); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1599 | for (i = 0; i < max_cmd; i++) { |
| 1600 | |
| 1601 | cmd = instance->cmd_list[i]; |
| 1602 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1603 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1604 | dev_err(&instance->pdev->dev, "0x%08lx : ", (unsigned long)cmd->frame_phys_addr); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1605 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1606 | dev_err(&instance->pdev->dev, "[%d]: Dumping Done\n\n",instance->host->host_no); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1609 | u32 |
| 1610 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1611 | struct scsi_cmnd *scmd) |
| 1612 | { |
| 1613 | struct megasas_cmd *cmd; |
| 1614 | u32 frame_count; |
| 1615 | |
| 1616 | cmd = megasas_get_cmd(instance); |
| 1617 | if (!cmd) |
| 1618 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1619 | |
| 1620 | /* |
| 1621 | * Logical drive command |
| 1622 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1623 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1624 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1625 | else |
| 1626 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1627 | |
| 1628 | if (!frame_count) |
| 1629 | goto out_return_cmd; |
| 1630 | |
| 1631 | cmd->scmd = scmd; |
| 1632 | scmd->SCp.ptr = (char *)cmd; |
| 1633 | |
| 1634 | /* |
| 1635 | * Issue the command to the FW |
| 1636 | */ |
| 1637 | atomic_inc(&instance->fw_outstanding); |
| 1638 | |
| 1639 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1640 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1641 | |
| 1642 | return 0; |
| 1643 | out_return_cmd: |
| 1644 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1645 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1649 | /** |
| 1650 | * megasas_queue_command - Queue entry point |
| 1651 | * @scmd: SCSI command to be queued |
| 1652 | * @done: Callback entry point |
| 1653 | */ |
| 1654 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1655 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1656 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1657 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1658 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1659 | |
| 1660 | instance = (struct megasas_instance *) |
| 1661 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1662 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1663 | if (instance->unload == 1) { |
| 1664 | scmd->result = DID_NO_CONNECT << 16; |
| 1665 | scmd->scsi_done(scmd); |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1669 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1670 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1671 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1672 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1673 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1674 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1675 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 1676 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1677 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1678 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1679 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1680 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1681 | return 0; |
| 1682 | } |
| 1683 | } |
| 1684 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1685 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1686 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1687 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1688 | return 0; |
| 1689 | } |
| 1690 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1691 | mr_device_priv_data = scmd->device->hostdata; |
| 1692 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1693 | scmd->result = DID_NO_CONNECT << 16; |
| 1694 | scmd->scsi_done(scmd); |
| 1695 | return 0; |
| 1696 | } |
| 1697 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1698 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1699 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1700 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1701 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1702 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1703 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1704 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1705 | scmd->result = 0; |
| 1706 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1707 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1708 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1709 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1710 | scmd->result = DID_BAD_TARGET << 16; |
| 1711 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1714 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1715 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1716 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1717 | scmd->result = DID_OK << 16; |
| 1718 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1719 | } |
| 1720 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1721 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1722 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1723 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1724 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1725 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1726 | } |
| 1727 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1728 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1729 | { |
| 1730 | int i; |
| 1731 | |
| 1732 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1733 | |
| 1734 | if ((megasas_mgmt_info.instance[i]) && |
| 1735 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1736 | return megasas_mgmt_info.instance[i]; |
| 1737 | } |
| 1738 | |
| 1739 | return NULL; |
| 1740 | } |
| 1741 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1742 | /* |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1743 | * megasas_set_dynamic_target_properties - |
| 1744 | * Device property set by driver may not be static and it is required to be |
| 1745 | * updated after OCR |
| 1746 | * |
| 1747 | * set tm_capable. |
| 1748 | * set dma alignment (only for eedp protection enable vd). |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1749 | * |
| 1750 | * @sdev: OS provided scsi device |
| 1751 | * |
| 1752 | * Returns void |
| 1753 | */ |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1754 | void megasas_set_dynamic_target_properties(struct scsi_device *sdev) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1755 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1756 | u16 pd_index = 0, ld; |
| 1757 | u32 device_id; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1758 | struct megasas_instance *instance; |
| 1759 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1760 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1761 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1762 | struct MR_LD_RAID *raid; |
| 1763 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1764 | |
| 1765 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1766 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1767 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1768 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1769 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1770 | return; |
| 1771 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1772 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1773 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1774 | + sdev->id; |
| 1775 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1776 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1777 | if (ld >= instance->fw_supported_vd_count) |
| 1778 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1779 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1780 | |
| 1781 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1782 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1783 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1784 | mr_device_priv_data->is_tm_capable = |
| 1785 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1786 | } else if (instance->use_seqnum_jbod_fp) { |
| 1787 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1788 | sdev->id; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1789 | pd_sync = (void *)fusion->pd_seq_sync |
| 1790 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1791 | mr_device_priv_data->is_tm_capable = |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1792 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1796 | /* |
| 1797 | * megasas_set_nvme_device_properties - |
| 1798 | * set nomerges=2 |
| 1799 | * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K). |
| 1800 | * set maximum io transfer = MDTS of NVME device provided by MR firmware. |
| 1801 | * |
| 1802 | * MR firmware provides value in KB. Caller of this function converts |
| 1803 | * kb into bytes. |
| 1804 | * |
| 1805 | * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size, |
| 1806 | * MR firmware provides value 128 as (32 * 4K) = 128K. |
| 1807 | * |
| 1808 | * @sdev: scsi device |
| 1809 | * @max_io_size: maximum io transfer size |
| 1810 | * |
| 1811 | */ |
| 1812 | static inline void |
| 1813 | megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1814 | { |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1815 | struct megasas_instance *instance; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1816 | u32 mr_nvme_pg_size; |
| 1817 | |
| 1818 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 1819 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1820 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1821 | |
| 1822 | blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512)); |
| 1823 | |
| 1824 | queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue); |
| 1825 | blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1); |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | /* |
| 1830 | * megasas_set_static_target_properties - |
| 1831 | * Device property set by driver are static and it is not required to be |
| 1832 | * updated after OCR. |
| 1833 | * |
| 1834 | * set io timeout |
| 1835 | * set device queue depth |
| 1836 | * set nvme device properties. see - megasas_set_nvme_device_properties |
| 1837 | * |
| 1838 | * @sdev: scsi device |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1839 | * @is_target_prop true, if fw provided target properties. |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1840 | */ |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1841 | static void megasas_set_static_target_properties(struct scsi_device *sdev, |
| 1842 | bool is_target_prop) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1843 | { |
| 1844 | u16 target_index = 0; |
| 1845 | u8 interface_type; |
| 1846 | u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN; |
| 1847 | u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1848 | u32 tgt_device_qd; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1849 | struct megasas_instance *instance; |
| 1850 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1851 | |
| 1852 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1853 | mr_device_priv_data = sdev->hostdata; |
| 1854 | interface_type = mr_device_priv_data->interface_type; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1855 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1856 | /* |
| 1857 | * The RAID firmware may require extended timeouts. |
| 1858 | */ |
| 1859 | blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1860 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1861 | target_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1862 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1863 | switch (interface_type) { |
| 1864 | case SAS_PD: |
| 1865 | device_qd = MEGASAS_SAS_QD; |
| 1866 | break; |
| 1867 | case SATA_PD: |
| 1868 | device_qd = MEGASAS_SATA_QD; |
| 1869 | break; |
| 1870 | case NVME_PD: |
| 1871 | device_qd = MEGASAS_NVME_QD; |
| 1872 | break; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1873 | } |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1874 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1875 | if (is_target_prop) { |
| 1876 | tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth); |
| 1877 | if (tgt_device_qd && |
| 1878 | (tgt_device_qd <= instance->host->can_queue)) |
| 1879 | device_qd = tgt_device_qd; |
| 1880 | |
| 1881 | /* max_io_size_kb will be set to non zero for |
| 1882 | * nvme based vd and syspd. |
| 1883 | */ |
| 1884 | max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb); |
| 1885 | } |
| 1886 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1887 | if (instance->nvme_page_size && max_io_size_kb) |
| 1888 | megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10)); |
| 1889 | |
| 1890 | scsi_change_queue_depth(sdev, device_qd); |
| 1891 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1892 | } |
| 1893 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1894 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1895 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1896 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1897 | u16 pd_index = 0; |
| 1898 | struct megasas_instance *instance; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1899 | int ret_target_prop = DCMD_FAILED; |
| 1900 | bool is_target_prop = false; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1901 | |
| 1902 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1903 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1904 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1905 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1906 | sdev->id; |
| 1907 | if (instance->pd_list[pd_index].driveState != |
| 1908 | MR_PD_STATE_SYSTEM) |
| 1909 | return -ENXIO; |
| 1910 | } |
| 1911 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1912 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1913 | mutex_lock(&instance->hba_mutex); |
| 1914 | /* Send DCMD to Firmware and cache the information */ |
| 1915 | if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev)) |
| 1916 | megasas_get_pd_info(instance, sdev); |
| 1917 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1918 | /* Some ventura firmware may not have instance->nvme_page_size set. |
| 1919 | * Do not send MR_DCMD_DRV_GET_TARGET_PROP |
| 1920 | */ |
| 1921 | if ((instance->tgt_prop) && (instance->nvme_page_size)) |
| 1922 | ret_target_prop = megasas_get_target_prop(instance, sdev); |
| 1923 | |
| 1924 | is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false; |
| 1925 | megasas_set_static_target_properties(sdev, is_target_prop); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1926 | |
| 1927 | mutex_unlock(&instance->hba_mutex); |
| 1928 | |
| 1929 | /* This sdev property may change post OCR */ |
| 1930 | megasas_set_dynamic_target_properties(sdev); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1931 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1932 | return 0; |
| 1933 | } |
| 1934 | |
| 1935 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1936 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1937 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1938 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1939 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1940 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1941 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1942 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1943 | /* |
| 1944 | * Open the OS scan to the SYSTEM PD |
| 1945 | */ |
| 1946 | pd_index = |
| 1947 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1948 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1949 | if ((instance->pd_list_not_supported || |
| 1950 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1951 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1952 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1953 | } |
| 1954 | return -ENXIO; |
| 1955 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1956 | |
| 1957 | scan_target: |
| 1958 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 1959 | GFP_KERNEL); |
| 1960 | if (!mr_device_priv_data) |
| 1961 | return -ENOMEM; |
| 1962 | sdev->hostdata = mr_device_priv_data; |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1963 | return 0; |
| 1964 | } |
| 1965 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1966 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 1967 | { |
| 1968 | kfree(sdev->hostdata); |
| 1969 | sdev->hostdata = NULL; |
| 1970 | } |
| 1971 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1972 | /* |
| 1973 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 1974 | * kill adapter |
| 1975 | * @instance: Adapter soft state |
| 1976 | * |
| 1977 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 1978 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1979 | { |
| 1980 | int i; |
| 1981 | struct megasas_cmd *cmd_mfi; |
| 1982 | struct megasas_cmd_fusion *cmd_fusion; |
| 1983 | struct fusion_context *fusion = instance->ctrl_context; |
| 1984 | |
| 1985 | /* Find all outstanding ioctls */ |
| 1986 | if (fusion) { |
| 1987 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1988 | cmd_fusion = fusion->cmd_list[i]; |
| 1989 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 1990 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 1991 | if (cmd_mfi->sync_cmd && |
| 1992 | cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT) |
| 1993 | megasas_complete_cmd(instance, |
| 1994 | cmd_mfi, DID_OK); |
| 1995 | } |
| 1996 | } |
| 1997 | } else { |
| 1998 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1999 | cmd_mfi = instance->cmd_list[i]; |
| 2000 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 2001 | MFI_CMD_ABORT) |
| 2002 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2008 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2009 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2010 | /* Set critical error to block I/O & ioctls in case caller didn't */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2011 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2012 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 2013 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2014 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2015 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 2016 | (instance->ctrl_context)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2017 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2018 | /* Flush */ |
| 2019 | readl(&instance->reg_set->doorbell); |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 2020 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2021 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2022 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2023 | writel(MFI_STOP_ADP, |
| 2024 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2025 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2026 | /* Complete outstanding ioctls when adapter is killed */ |
| 2027 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 2032 | * restored to max value |
| 2033 | * @instance: Adapter soft state |
| 2034 | * |
| 2035 | */ |
| 2036 | void |
| 2037 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 2038 | { |
| 2039 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 2040 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2041 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2042 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 2043 | && atomic_read(&instance->fw_outstanding) < |
| 2044 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2045 | |
| 2046 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2047 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2048 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2049 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2050 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2054 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2055 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 2056 | * @instance_addr: Address of adapter soft state |
| 2057 | * |
| 2058 | * Tasklet to complete cmds |
| 2059 | */ |
| 2060 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 2061 | { |
| 2062 | u32 producer; |
| 2063 | u32 consumer; |
| 2064 | u32 context; |
| 2065 | struct megasas_cmd *cmd; |
| 2066 | struct megasas_instance *instance = |
| 2067 | (struct megasas_instance *)instance_addr; |
| 2068 | unsigned long flags; |
| 2069 | |
| 2070 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2071 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2072 | return; |
| 2073 | |
| 2074 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 2075 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2076 | producer = le32_to_cpu(*instance->producer); |
| 2077 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2078 | |
| 2079 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2080 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2081 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2082 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2083 | context); |
| 2084 | BUG(); |
| 2085 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2086 | |
| 2087 | cmd = instance->cmd_list[context]; |
| 2088 | |
| 2089 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2090 | |
| 2091 | consumer++; |
| 2092 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2093 | consumer = 0; |
| 2094 | } |
| 2095 | } |
| 2096 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2097 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2098 | |
| 2099 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2100 | |
| 2101 | /* |
| 2102 | * Check if we can restore can_queue |
| 2103 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2104 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2105 | } |
| 2106 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2107 | /** |
| 2108 | * megasas_start_timer - Initializes a timer object |
| 2109 | * @instance: Adapter soft state |
| 2110 | * @timer: timer object to be initialized |
| 2111 | * @fn: timer function |
| 2112 | * @interval: time interval between timer function call |
| 2113 | * |
| 2114 | */ |
| 2115 | void megasas_start_timer(struct megasas_instance *instance, |
| 2116 | struct timer_list *timer, |
| 2117 | void *fn, unsigned long interval) |
| 2118 | { |
| 2119 | init_timer(timer); |
| 2120 | timer->expires = jiffies + interval; |
| 2121 | timer->data = (unsigned long)instance; |
| 2122 | timer->function = fn; |
| 2123 | add_timer(timer); |
| 2124 | } |
| 2125 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2126 | static void |
| 2127 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2128 | |
| 2129 | static void |
| 2130 | process_fw_state_change_wq(struct work_struct *work); |
| 2131 | |
| 2132 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2133 | { |
| 2134 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2135 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2136 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2137 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2138 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2139 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2140 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2141 | instance->issuepend_done = 0; |
| 2142 | |
| 2143 | atomic_set(&instance->fw_outstanding, 0); |
| 2144 | megasas_internal_reset_defer_cmds(instance); |
| 2145 | process_fw_state_change_wq(&instance->work_init); |
| 2146 | } |
| 2147 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2148 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2149 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2150 | { |
| 2151 | struct megasas_cmd *cmd; |
| 2152 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2153 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2154 | dma_addr_t new_affiliation_111_h; |
| 2155 | int ld, retval = 0; |
| 2156 | u8 thisVf; |
| 2157 | |
| 2158 | cmd = megasas_get_cmd(instance); |
| 2159 | |
| 2160 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2161 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2162 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2163 | instance->host->host_no); |
| 2164 | return -ENOMEM; |
| 2165 | } |
| 2166 | |
| 2167 | dcmd = &cmd->frame->dcmd; |
| 2168 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2169 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2170 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2171 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2172 | megasas_return_cmd(instance, cmd); |
| 2173 | return -ENOMEM; |
| 2174 | } |
| 2175 | |
| 2176 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2177 | memset(instance->vf_affiliation_111, 0, |
| 2178 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2179 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2180 | new_affiliation_111 = |
| 2181 | pci_alloc_consistent(instance->pdev, |
| 2182 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2183 | &new_affiliation_111_h); |
| 2184 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2185 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2186 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2187 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2188 | megasas_return_cmd(instance, cmd); |
| 2189 | return -ENOMEM; |
| 2190 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2191 | memset(new_affiliation_111, 0, |
| 2192 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2196 | |
| 2197 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2198 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2199 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2200 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2201 | dcmd->timeout = 0; |
| 2202 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2203 | dcmd->data_xfer_len = |
| 2204 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2205 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2206 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2207 | if (initial) |
| 2208 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2209 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2210 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2211 | dcmd->sgl.sge32[0].phys_addr = |
| 2212 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2213 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2214 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2215 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2216 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2217 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2218 | "scsi%d\n", instance->host->host_no); |
| 2219 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2220 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2221 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2222 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2223 | dcmd->cmd_status, instance->host->host_no); |
| 2224 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2225 | goto out; |
| 2226 | } |
| 2227 | |
| 2228 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2229 | thisVf = new_affiliation_111->thisVf; |
| 2230 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2231 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2232 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2233 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2234 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2235 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2236 | memcpy(instance->vf_affiliation_111, |
| 2237 | new_affiliation_111, |
| 2238 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2239 | retval = 1; |
| 2240 | goto out; |
| 2241 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2242 | } |
| 2243 | out: |
| 2244 | if (new_affiliation_111) { |
| 2245 | pci_free_consistent(instance->pdev, |
| 2246 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2247 | new_affiliation_111, |
| 2248 | new_affiliation_111_h); |
| 2249 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2250 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2251 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2252 | |
| 2253 | return retval; |
| 2254 | } |
| 2255 | |
| 2256 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2257 | int initial) |
| 2258 | { |
| 2259 | struct megasas_cmd *cmd; |
| 2260 | struct megasas_dcmd_frame *dcmd; |
| 2261 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2262 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2263 | dma_addr_t new_affiliation_h; |
| 2264 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2265 | u8 thisVf; |
| 2266 | |
| 2267 | cmd = megasas_get_cmd(instance); |
| 2268 | |
| 2269 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2270 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2271 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2272 | instance->host->host_no); |
| 2273 | return -ENOMEM; |
| 2274 | } |
| 2275 | |
| 2276 | dcmd = &cmd->frame->dcmd; |
| 2277 | |
| 2278 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2279 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2280 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2281 | megasas_return_cmd(instance, cmd); |
| 2282 | return -ENOMEM; |
| 2283 | } |
| 2284 | |
| 2285 | if (initial) |
| 2286 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2287 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2288 | else { |
| 2289 | new_affiliation = |
| 2290 | pci_alloc_consistent(instance->pdev, |
| 2291 | (MAX_LOGICAL_DRIVES + 1) * |
| 2292 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2293 | &new_affiliation_h); |
| 2294 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2295 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2296 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2297 | instance->host->host_no); |
| 2298 | megasas_return_cmd(instance, cmd); |
| 2299 | return -ENOMEM; |
| 2300 | } |
| 2301 | memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2302 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2303 | } |
| 2304 | |
| 2305 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2306 | |
| 2307 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2308 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2309 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2310 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2311 | dcmd->timeout = 0; |
| 2312 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2313 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2314 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2315 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2316 | |
| 2317 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2318 | dcmd->sgl.sge32[0].phys_addr = |
| 2319 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2320 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2321 | dcmd->sgl.sge32[0].phys_addr = |
| 2322 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2323 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2324 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2325 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2326 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2327 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2328 | "scsi%d\n", instance->host->host_no); |
| 2329 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2330 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2331 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2332 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2333 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2334 | dcmd->cmd_status, instance->host->host_no); |
| 2335 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2336 | goto out; |
| 2337 | } |
| 2338 | |
| 2339 | if (!initial) { |
| 2340 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2341 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2342 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2343 | instance->host->host_no); |
| 2344 | retval = 1; |
| 2345 | goto out; |
| 2346 | } |
| 2347 | newmap = new_affiliation->map; |
| 2348 | savedmap = instance->vf_affiliation->map; |
| 2349 | thisVf = new_affiliation->thisVf; |
| 2350 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2351 | found = 0; |
| 2352 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2353 | j++) { |
| 2354 | if (newmap->ref.targetId == |
| 2355 | savedmap->ref.targetId) { |
| 2356 | found = 1; |
| 2357 | if (newmap->policy[thisVf] != |
| 2358 | savedmap->policy[thisVf]) { |
| 2359 | doscan = 1; |
| 2360 | goto out; |
| 2361 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2362 | } |
| 2363 | savedmap = (struct MR_LD_VF_MAP *) |
| 2364 | ((unsigned char *)savedmap + |
| 2365 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2366 | } |
| 2367 | if (!found && newmap->policy[thisVf] != |
| 2368 | MR_LD_ACCESS_HIDDEN) { |
| 2369 | doscan = 1; |
| 2370 | goto out; |
| 2371 | } |
| 2372 | newmap = (struct MR_LD_VF_MAP *) |
| 2373 | ((unsigned char *)newmap + newmap->size); |
| 2374 | } |
| 2375 | |
| 2376 | newmap = new_affiliation->map; |
| 2377 | savedmap = instance->vf_affiliation->map; |
| 2378 | |
| 2379 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2380 | found = 0; |
| 2381 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2382 | if (savedmap->ref.targetId == |
| 2383 | newmap->ref.targetId) { |
| 2384 | found = 1; |
| 2385 | if (savedmap->policy[thisVf] != |
| 2386 | newmap->policy[thisVf]) { |
| 2387 | doscan = 1; |
| 2388 | goto out; |
| 2389 | } |
| 2390 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2391 | newmap = (struct MR_LD_VF_MAP *) |
| 2392 | ((unsigned char *)newmap + |
| 2393 | newmap->size); |
| 2394 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2395 | if (!found && savedmap->policy[thisVf] != |
| 2396 | MR_LD_ACCESS_HIDDEN) { |
| 2397 | doscan = 1; |
| 2398 | goto out; |
| 2399 | } |
| 2400 | savedmap = (struct MR_LD_VF_MAP *) |
| 2401 | ((unsigned char *)savedmap + |
| 2402 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2406 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2407 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2408 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2409 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2410 | new_affiliation->size); |
| 2411 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2412 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2413 | |
| 2414 | if (new_affiliation) |
| 2415 | pci_free_consistent(instance->pdev, |
| 2416 | (MAX_LOGICAL_DRIVES + 1) * |
| 2417 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2418 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2419 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2420 | |
| 2421 | return retval; |
| 2422 | } |
| 2423 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2424 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2425 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2426 | int initial) |
| 2427 | { |
| 2428 | int retval; |
| 2429 | |
| 2430 | if (instance->PlasmaFW111) |
| 2431 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2432 | else |
| 2433 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2434 | return retval; |
| 2435 | } |
| 2436 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2437 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2438 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2439 | int initial) |
| 2440 | { |
| 2441 | struct megasas_cmd *cmd; |
| 2442 | struct megasas_dcmd_frame *dcmd; |
| 2443 | int retval = 0; |
| 2444 | |
| 2445 | cmd = megasas_get_cmd(instance); |
| 2446 | |
| 2447 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2448 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2449 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2450 | instance->host->host_no); |
| 2451 | return -ENOMEM; |
| 2452 | } |
| 2453 | |
| 2454 | dcmd = &cmd->frame->dcmd; |
| 2455 | |
| 2456 | if (initial) { |
| 2457 | instance->hb_host_mem = |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 2458 | pci_zalloc_consistent(instance->pdev, |
| 2459 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2460 | &instance->hb_host_mem_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2461 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2462 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2463 | " memory for heartbeat host memory for scsi%d\n", |
| 2464 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2465 | retval = -ENOMEM; |
| 2466 | goto out; |
| 2467 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2471 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2472 | dcmd->mbox.s[0] = cpu_to_le16(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2473 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2474 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2475 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2476 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2477 | dcmd->timeout = 0; |
| 2478 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2479 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2480 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
| 2481 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->hb_host_mem_h); |
| 2482 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2483 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2484 | dev_warn(&instance->pdev->dev, "SR-IOV: Starting heartbeat for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2485 | instance->host->host_no); |
| 2486 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2487 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 2488 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2489 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2490 | else |
| 2491 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2492 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2493 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2494 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2495 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2496 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2497 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2498 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | out: |
| 2502 | megasas_return_cmd(instance, cmd); |
| 2503 | |
| 2504 | return retval; |
| 2505 | } |
| 2506 | |
| 2507 | /* Handler for SR-IOV heartbeat */ |
| 2508 | void megasas_sriov_heartbeat_handler(unsigned long instance_addr) |
| 2509 | { |
| 2510 | struct megasas_instance *instance = |
| 2511 | (struct megasas_instance *)instance_addr; |
| 2512 | |
| 2513 | if (instance->hb_host_mem->HB.fwCounter != |
| 2514 | instance->hb_host_mem->HB.driverCounter) { |
| 2515 | instance->hb_host_mem->HB.driverCounter = |
| 2516 | instance->hb_host_mem->HB.fwCounter; |
| 2517 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2518 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2519 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2520 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2521 | "completed for scsi%d\n", instance->host->host_no); |
| 2522 | schedule_work(&instance->work_init); |
| 2523 | } |
| 2524 | } |
| 2525 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2526 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2527 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2528 | * @instance: Adapter soft state |
| 2529 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2530 | * This function waits for up to MEGASAS_RESET_WAIT_TIME seconds for FW to |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2531 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2532 | * are pending after this time period. It also marks the controller dead. |
| 2533 | */ |
| 2534 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2535 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2536 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2537 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2538 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2539 | unsigned long flags; |
| 2540 | struct list_head clist_local; |
| 2541 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2542 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2543 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2544 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2545 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2546 | __func__, __LINE__); |
| 2547 | return FAILED; |
| 2548 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2549 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2550 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2551 | |
| 2552 | INIT_LIST_HEAD(&clist_local); |
| 2553 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2554 | list_splice_init(&instance->internal_reset_pending_q, |
| 2555 | &clist_local); |
| 2556 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2557 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2558 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2559 | for (i = 0; i < wait_time; i++) { |
| 2560 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2561 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2562 | break; |
| 2563 | } |
| 2564 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2565 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2566 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2567 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2568 | return FAILED; |
| 2569 | } |
| 2570 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2571 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2572 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2573 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2574 | struct megasas_cmd, list); |
| 2575 | list_del_init(&reset_cmd->list); |
| 2576 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 2577 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2578 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2579 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2580 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2581 | |
| 2582 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2583 | megasas_return_cmd(instance, reset_cmd); |
| 2584 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2585 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2586 | "reset queue\n", |
| 2587 | reset_cmd); |
| 2588 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2589 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2590 | instance->instancet->fire_cmd(instance, |
| 2591 | reset_cmd->frame_phys_addr, |
| 2592 | 0, instance->reg_set); |
| 2593 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2594 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2595 | "cmds lst\n", |
| 2596 | reset_cmd); |
| 2597 | } |
| 2598 | reset_index++; |
| 2599 | } |
| 2600 | |
| 2601 | return SUCCESS; |
| 2602 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2603 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2604 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2605 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2606 | |
| 2607 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2608 | break; |
| 2609 | |
| 2610 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2611 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2612 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2613 | /* |
| 2614 | * Call cmd completion routine. Cmd to be |
| 2615 | * be completed directly without depending on isr. |
| 2616 | */ |
| 2617 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | msleep(1000); |
| 2621 | } |
| 2622 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2623 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2624 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2625 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2626 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2627 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2628 | goto no_outstanding; |
| 2629 | |
| 2630 | if (instance->disableOnlineCtrlReset) |
| 2631 | goto kill_hba_and_failed; |
| 2632 | do { |
| 2633 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2634 | dev_info(&instance->pdev->dev, |
| 2635 | "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, oustanding 0x%x\n", |
| 2636 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2637 | if (i == 3) |
| 2638 | goto kill_hba_and_failed; |
| 2639 | megasas_do_ocr(instance); |
| 2640 | |
| 2641 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2642 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2643 | __func__, __LINE__); |
| 2644 | return FAILED; |
| 2645 | } |
| 2646 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2647 | __func__, __LINE__); |
| 2648 | |
| 2649 | for (sl = 0; sl < 10; sl++) |
| 2650 | msleep(500); |
| 2651 | |
| 2652 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2653 | |
| 2654 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
| 2655 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2656 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2657 | } |
| 2658 | i++; |
| 2659 | } while (i <= 3); |
| 2660 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2661 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2662 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2663 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2664 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2665 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2666 | |
| 2667 | kill_hba_and_failed: |
| 2668 | |
| 2669 | /* Reset not supported, kill adapter */ |
| 2670 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2671 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2672 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2673 | atomic_read(&instance->fw_outstanding)); |
| 2674 | megasas_dump_pending_frames(instance); |
| 2675 | megaraid_sas_kill_hba(instance); |
| 2676 | |
| 2677 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | /** |
| 2681 | * megasas_generic_reset - Generic reset routine |
| 2682 | * @scmd: Mid-layer SCSI command |
| 2683 | * |
| 2684 | * This routine implements a generic reset handler for device, bus and host |
| 2685 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2686 | * function after they do their specific tasks. |
| 2687 | */ |
| 2688 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2689 | { |
| 2690 | int ret_val; |
| 2691 | struct megasas_instance *instance; |
| 2692 | |
| 2693 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2694 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2695 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2696 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2697 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2698 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2699 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2700 | return FAILED; |
| 2701 | } |
| 2702 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2703 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2704 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2705 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2706 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2707 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2708 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2709 | return ret_val; |
| 2710 | } |
| 2711 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2712 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2713 | * megasas_reset_timer - quiesce the adapter if required |
| 2714 | * @scmd: scsi cmnd |
| 2715 | * |
| 2716 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2717 | * cmd has not been completed within the timeout period. |
| 2718 | */ |
| 2719 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2720 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2721 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2722 | struct megasas_instance *instance; |
| 2723 | unsigned long flags; |
| 2724 | |
| 2725 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2726 | (scmd_timeout * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2727 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2730 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2731 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2732 | /* FW is busy, throttle IO */ |
| 2733 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2734 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2735 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2736 | instance->last_time = jiffies; |
| 2737 | instance->flag |= MEGASAS_FW_BUSY; |
| 2738 | |
| 2739 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2740 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2741 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | /** |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame^] | 2745 | * megasas_dump_frame - This function will dump MPT/MFI frame |
| 2746 | */ |
| 2747 | static inline void |
| 2748 | megasas_dump_frame(void *mpi_request, int sz) |
| 2749 | { |
| 2750 | int i; |
| 2751 | __le32 *mfp = (__le32 *)mpi_request; |
| 2752 | |
| 2753 | printk(KERN_INFO "IO request frame:\n\t"); |
| 2754 | for (i = 0; i < sz; i++) { |
| 2755 | if (i && ((i % 8) == 0)) |
| 2756 | printk("\n\t"); |
| 2757 | printk("%08x ", le32_to_cpu(mfp[i])); |
| 2758 | } |
| 2759 | printk("\n"); |
| 2760 | } |
| 2761 | |
| 2762 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2763 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2764 | */ |
| 2765 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2766 | { |
| 2767 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2768 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2769 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2770 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2771 | |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame^] | 2772 | scmd_printk(KERN_INFO, scmd, |
| 2773 | "Controller reset is requested due to IO timeout\n" |
| 2774 | "SCSI command pointer: (%p)\t SCSI host state: %d\t" |
| 2775 | " SCSI host busy: %d\t FW outstanding: %d\n", |
| 2776 | scmd, scmd->device->host->shost_state, |
| 2777 | atomic_read((atomic_t *)&scmd->device->host->host_busy), |
| 2778 | atomic_read(&instance->fw_outstanding)); |
| 2779 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2780 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2781 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2782 | */ |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame^] | 2783 | if (instance->ctrl_context) { |
| 2784 | struct megasas_cmd_fusion *cmd; |
| 2785 | cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr; |
| 2786 | if (cmd) |
| 2787 | megasas_dump_frame(cmd->io_request, |
| 2788 | sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)); |
| 2789 | ret = megasas_reset_fusion(scmd->device->host, |
| 2790 | SCSIIO_TIMEOUT_OCR); |
| 2791 | } else |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2792 | ret = megasas_generic_reset(scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2793 | |
| 2794 | return ret; |
| 2795 | } |
| 2796 | |
| 2797 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2798 | * megasas_task_abort - Issues task abort request to firmware |
| 2799 | * (supported only for fusion adapters) |
| 2800 | * @scmd: SCSI command pointer |
| 2801 | */ |
| 2802 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 2803 | { |
| 2804 | int ret; |
| 2805 | struct megasas_instance *instance; |
| 2806 | |
| 2807 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2808 | |
| 2809 | if (instance->ctrl_context) |
| 2810 | ret = megasas_task_abort_fusion(scmd); |
| 2811 | else { |
| 2812 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 2813 | ret = FAILED; |
| 2814 | } |
| 2815 | |
| 2816 | return ret; |
| 2817 | } |
| 2818 | |
| 2819 | /** |
| 2820 | * megasas_reset_target: Issues target reset request to firmware |
| 2821 | * (supported only for fusion adapters) |
| 2822 | * @scmd: SCSI command pointer |
| 2823 | */ |
| 2824 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 2825 | { |
| 2826 | int ret; |
| 2827 | struct megasas_instance *instance; |
| 2828 | |
| 2829 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2830 | |
| 2831 | if (instance->ctrl_context) |
| 2832 | ret = megasas_reset_target_fusion(scmd); |
| 2833 | else { |
| 2834 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 2835 | ret = FAILED; |
| 2836 | } |
| 2837 | |
| 2838 | return ret; |
| 2839 | } |
| 2840 | |
| 2841 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2842 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2843 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2844 | * @bdev: block device |
| 2845 | * @capacity: drive capacity |
| 2846 | * @geom: geometry parameters |
| 2847 | */ |
| 2848 | static int |
| 2849 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2850 | sector_t capacity, int geom[]) |
| 2851 | { |
| 2852 | int heads; |
| 2853 | int sectors; |
| 2854 | sector_t cylinders; |
| 2855 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2856 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2857 | /* Default heads (64) & sectors (32) */ |
| 2858 | heads = 64; |
| 2859 | sectors = 32; |
| 2860 | |
| 2861 | tmp = heads * sectors; |
| 2862 | cylinders = capacity; |
| 2863 | |
| 2864 | sector_div(cylinders, tmp); |
| 2865 | |
| 2866 | /* |
| 2867 | * Handle extended translation size for logical drives > 1Gb |
| 2868 | */ |
| 2869 | |
| 2870 | if (capacity >= 0x200000) { |
| 2871 | heads = 255; |
| 2872 | sectors = 63; |
| 2873 | tmp = heads*sectors; |
| 2874 | cylinders = capacity; |
| 2875 | sector_div(cylinders, tmp); |
| 2876 | } |
| 2877 | |
| 2878 | geom[0] = heads; |
| 2879 | geom[1] = sectors; |
| 2880 | geom[2] = cylinders; |
| 2881 | |
| 2882 | return 0; |
| 2883 | } |
| 2884 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2885 | static void megasas_aen_polling(struct work_struct *work); |
| 2886 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2887 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2888 | * megasas_service_aen - Processes an event notification |
| 2889 | * @instance: Adapter soft state |
| 2890 | * @cmd: AEN command completed by the ISR |
| 2891 | * |
| 2892 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2893 | * event occurs. When an event of interest occurs, FW completes the command |
| 2894 | * that it was previously holding. |
| 2895 | * |
| 2896 | * This routines sends SIGIO signal to processes that have registered with the |
| 2897 | * driver for AEN. |
| 2898 | */ |
| 2899 | static void |
| 2900 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2901 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2902 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2903 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2904 | /* |
| 2905 | * Don't signal app if it is just an aborted previously registered aen |
| 2906 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2907 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2908 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2909 | megasas_poll_wait_aen = 1; |
| 2910 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2911 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2912 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2913 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2914 | else |
| 2915 | cmd->abort_aen = 0; |
| 2916 | |
| 2917 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2918 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2919 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2920 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2921 | if ((instance->unload == 0) && |
| 2922 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2923 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2924 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2925 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2926 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2927 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2928 | } else { |
| 2929 | ev->instance = instance; |
| 2930 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2931 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2932 | megasas_aen_polling); |
| 2933 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2934 | } |
| 2935 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2936 | } |
| 2937 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2938 | static ssize_t |
| 2939 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 2940 | struct device_attribute *attr, const char *buf, size_t count) |
| 2941 | { |
| 2942 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2943 | struct megasas_instance *instance = |
| 2944 | (struct megasas_instance *) shost->hostdata; |
| 2945 | int val = 0; |
| 2946 | unsigned long flags; |
| 2947 | |
| 2948 | if (kstrtoint(buf, 0, &val) != 0) |
| 2949 | return -EINVAL; |
| 2950 | |
| 2951 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2952 | instance->fw_crash_buffer_offset = val; |
| 2953 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2954 | return strlen(buf); |
| 2955 | } |
| 2956 | |
| 2957 | static ssize_t |
| 2958 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 2959 | struct device_attribute *attr, char *buf) |
| 2960 | { |
| 2961 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2962 | struct megasas_instance *instance = |
| 2963 | (struct megasas_instance *) shost->hostdata; |
| 2964 | u32 size; |
| 2965 | unsigned long buff_addr; |
| 2966 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 2967 | unsigned long src_addr; |
| 2968 | unsigned long flags; |
| 2969 | u32 buff_offset; |
| 2970 | |
| 2971 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2972 | buff_offset = instance->fw_crash_buffer_offset; |
| 2973 | if (!instance->crash_dump_buf && |
| 2974 | !((instance->fw_crash_state == AVAILABLE) || |
| 2975 | (instance->fw_crash_state == COPYING))) { |
| 2976 | dev_err(&instance->pdev->dev, |
| 2977 | "Firmware crash dump is not available\n"); |
| 2978 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2979 | return -EINVAL; |
| 2980 | } |
| 2981 | |
| 2982 | buff_addr = (unsigned long) buf; |
| 2983 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2984 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2985 | dev_err(&instance->pdev->dev, |
| 2986 | "Firmware crash dump offset is out of range\n"); |
| 2987 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2988 | return 0; |
| 2989 | } |
| 2990 | |
| 2991 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 2992 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 2993 | |
| 2994 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 2995 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2996 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2997 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2998 | |
| 2999 | return size; |
| 3000 | } |
| 3001 | |
| 3002 | static ssize_t |
| 3003 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 3004 | struct device_attribute *attr, char *buf) |
| 3005 | { |
| 3006 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3007 | struct megasas_instance *instance = |
| 3008 | (struct megasas_instance *) shost->hostdata; |
| 3009 | |
| 3010 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 3011 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 3012 | } |
| 3013 | |
| 3014 | static ssize_t |
| 3015 | megasas_fw_crash_state_store(struct device *cdev, |
| 3016 | struct device_attribute *attr, const char *buf, size_t count) |
| 3017 | { |
| 3018 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3019 | struct megasas_instance *instance = |
| 3020 | (struct megasas_instance *) shost->hostdata; |
| 3021 | int val = 0; |
| 3022 | unsigned long flags; |
| 3023 | |
| 3024 | if (kstrtoint(buf, 0, &val) != 0) |
| 3025 | return -EINVAL; |
| 3026 | |
| 3027 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 3028 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 3029 | "firmware crash state\n"); |
| 3030 | return -EINVAL; |
| 3031 | } |
| 3032 | |
| 3033 | instance->fw_crash_state = val; |
| 3034 | |
| 3035 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 3036 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3037 | megasas_free_host_crash_buffer(instance); |
| 3038 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3039 | if (val == COPY_ERROR) |
| 3040 | dev_info(&instance->pdev->dev, "application failed to " |
| 3041 | "copy Firmware crash dump\n"); |
| 3042 | else |
| 3043 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3044 | "copied successfully\n"); |
| 3045 | } |
| 3046 | return strlen(buf); |
| 3047 | } |
| 3048 | |
| 3049 | static ssize_t |
| 3050 | megasas_fw_crash_state_show(struct device *cdev, |
| 3051 | struct device_attribute *attr, char *buf) |
| 3052 | { |
| 3053 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3054 | struct megasas_instance *instance = |
| 3055 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3056 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3057 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 3058 | } |
| 3059 | |
| 3060 | static ssize_t |
| 3061 | megasas_page_size_show(struct device *cdev, |
| 3062 | struct device_attribute *attr, char *buf) |
| 3063 | { |
| 3064 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 3065 | } |
| 3066 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3067 | static ssize_t |
| 3068 | megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
| 3069 | char *buf) |
| 3070 | { |
| 3071 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3072 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3073 | |
| 3074 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 3075 | } |
| 3076 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3077 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 3078 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 3079 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 3080 | megasas_fw_crash_buffer_size_show, NULL); |
| 3081 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 3082 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 3083 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 3084 | megasas_page_size_show, NULL); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3085 | static DEVICE_ATTR(ldio_outstanding, S_IRUGO, |
| 3086 | megasas_ldio_outstanding_show, NULL); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3087 | |
| 3088 | struct device_attribute *megaraid_host_attrs[] = { |
| 3089 | &dev_attr_fw_crash_buffer_size, |
| 3090 | &dev_attr_fw_crash_buffer, |
| 3091 | &dev_attr_fw_crash_state, |
| 3092 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3093 | &dev_attr_ldio_outstanding, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3094 | NULL, |
| 3095 | }; |
| 3096 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3097 | /* |
| 3098 | * Scsi host template for megaraid_sas driver |
| 3099 | */ |
| 3100 | static struct scsi_host_template megasas_template = { |
| 3101 | |
| 3102 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 3103 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3104 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 3105 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 3106 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3107 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3108 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3109 | .eh_target_reset_handler = megasas_reset_target, |
| 3110 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3111 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3112 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3113 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3114 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3115 | .use_clustering = ENABLE_CLUSTERING, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3116 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3117 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3118 | }; |
| 3119 | |
| 3120 | /** |
| 3121 | * megasas_complete_int_cmd - Completes an internal command |
| 3122 | * @instance: Adapter soft state |
| 3123 | * @cmd: Command to be completed |
| 3124 | * |
| 3125 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3126 | * after it issues a command. This function wakes up that waiting routine by |
| 3127 | * calling wake_up() on the wait queue. |
| 3128 | */ |
| 3129 | static void |
| 3130 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3131 | struct megasas_cmd *cmd) |
| 3132 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3133 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3134 | wake_up(&instance->int_cmd_wait_q); |
| 3135 | } |
| 3136 | |
| 3137 | /** |
| 3138 | * megasas_complete_abort - Completes aborting a command |
| 3139 | * @instance: Adapter soft state |
| 3140 | * @cmd: Cmd that was issued to abort another cmd |
| 3141 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3142 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3143 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3144 | * wakes up all functions waiting on the same wait queue. |
| 3145 | */ |
| 3146 | static void |
| 3147 | megasas_complete_abort(struct megasas_instance *instance, |
| 3148 | struct megasas_cmd *cmd) |
| 3149 | { |
| 3150 | if (cmd->sync_cmd) { |
| 3151 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3152 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3153 | wake_up(&instance->abort_cmd_wait_q); |
| 3154 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3158 | * megasas_complete_cmd - Completes a command |
| 3159 | * @instance: Adapter soft state |
| 3160 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3161 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3162 | * SCSI mid-layer instead of the value returned |
| 3163 | * by the FW. This should be used if caller wants |
| 3164 | * an alternate status (as in the case of aborted |
| 3165 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3166 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3167 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3168 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3169 | u8 alt_status) |
| 3170 | { |
| 3171 | int exception = 0; |
| 3172 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3173 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3174 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3175 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3176 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3177 | /* flag for the retry reset */ |
| 3178 | cmd->retry_for_fw_reset = 0; |
| 3179 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3180 | if (cmd->scmd) |
| 3181 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3182 | |
| 3183 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3184 | case MFI_CMD_INVALID: |
| 3185 | /* Some older 1068 controller FW may keep a pended |
| 3186 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3187 | when booting the kdump kernel. Ignore this command to |
| 3188 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3189 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3190 | "completed\n"); |
| 3191 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3192 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3193 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3194 | case MFI_CMD_PD_SCSI_IO: |
| 3195 | case MFI_CMD_LD_SCSI_IO: |
| 3196 | |
| 3197 | /* |
| 3198 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3199 | * issued either through an IO path or an IOCTL path. If it |
| 3200 | * was via IOCTL, we will send it to internal completion. |
| 3201 | */ |
| 3202 | if (cmd->sync_cmd) { |
| 3203 | cmd->sync_cmd = 0; |
| 3204 | megasas_complete_int_cmd(instance, cmd); |
| 3205 | break; |
| 3206 | } |
| 3207 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3208 | case MFI_CMD_LD_READ: |
| 3209 | case MFI_CMD_LD_WRITE: |
| 3210 | |
| 3211 | if (alt_status) { |
| 3212 | cmd->scmd->result = alt_status << 16; |
| 3213 | exception = 1; |
| 3214 | } |
| 3215 | |
| 3216 | if (exception) { |
| 3217 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3218 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3219 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3220 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3221 | cmd->scmd->scsi_done(cmd->scmd); |
| 3222 | megasas_return_cmd(instance, cmd); |
| 3223 | |
| 3224 | break; |
| 3225 | } |
| 3226 | |
| 3227 | switch (hdr->cmd_status) { |
| 3228 | |
| 3229 | case MFI_STAT_OK: |
| 3230 | cmd->scmd->result = DID_OK << 16; |
| 3231 | break; |
| 3232 | |
| 3233 | case MFI_STAT_SCSI_IO_FAILED: |
| 3234 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3235 | cmd->scmd->result = |
| 3236 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3237 | break; |
| 3238 | |
| 3239 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3240 | |
| 3241 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3242 | |
| 3243 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3244 | memset(cmd->scmd->sense_buffer, 0, |
| 3245 | SCSI_SENSE_BUFFERSIZE); |
| 3246 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3247 | hdr->sense_len); |
| 3248 | |
| 3249 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3250 | } |
| 3251 | |
| 3252 | break; |
| 3253 | |
| 3254 | case MFI_STAT_LD_OFFLINE: |
| 3255 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3256 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3257 | break; |
| 3258 | |
| 3259 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3260 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3261 | hdr->cmd_status); |
| 3262 | cmd->scmd->result = DID_ERROR << 16; |
| 3263 | break; |
| 3264 | } |
| 3265 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3266 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3267 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3268 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3269 | cmd->scmd->scsi_done(cmd->scmd); |
| 3270 | megasas_return_cmd(instance, cmd); |
| 3271 | |
| 3272 | break; |
| 3273 | |
| 3274 | case MFI_CMD_SMP: |
| 3275 | case MFI_CMD_STP: |
| 3276 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3277 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3278 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3279 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3280 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3281 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3282 | spin_lock_irqsave(instance->host->host_lock, flags); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3283 | instance->map_update_cmd = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3284 | if (cmd->frame->hdr.cmd_status != 0) { |
| 3285 | if (cmd->frame->hdr.cmd_status != |
| 3286 | MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3287 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3288 | cmd->frame->hdr.cmd_status); |
| 3289 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3290 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3291 | spin_unlock_irqrestore( |
| 3292 | instance->host->host_lock, |
| 3293 | flags); |
| 3294 | break; |
| 3295 | } |
| 3296 | } else |
| 3297 | instance->map_id++; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3298 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3299 | |
| 3300 | /* |
| 3301 | * Set fast path IO to ZERO. |
| 3302 | * Validate Map will set proper value. |
| 3303 | * Meanwhile all IOs will go as LD IO. |
| 3304 | */ |
| 3305 | if (MR_ValidateMapInfo(instance)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3306 | fusion->fast_path_io = 1; |
| 3307 | else |
| 3308 | fusion->fast_path_io = 0; |
| 3309 | megasas_sync_map_info(instance); |
| 3310 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3311 | flags); |
| 3312 | break; |
| 3313 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3314 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3315 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3316 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3317 | megasas_poll_wait_aen = 0; |
| 3318 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3319 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3320 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3321 | /* FW has an updated PD sequence */ |
| 3322 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3323 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3324 | |
| 3325 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3326 | status = cmd->frame->hdr.cmd_status; |
| 3327 | instance->jbod_seq_cmd = NULL; |
| 3328 | megasas_return_cmd(instance, cmd); |
| 3329 | |
| 3330 | if (status == MFI_STAT_OK) { |
| 3331 | instance->pd_seq_map_id++; |
| 3332 | /* Re-register a pd sync seq num cmd */ |
| 3333 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3334 | instance->use_seqnum_jbod_fp = false; |
| 3335 | } else |
| 3336 | instance->use_seqnum_jbod_fp = false; |
| 3337 | |
| 3338 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3339 | break; |
| 3340 | } |
| 3341 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3342 | /* |
| 3343 | * See if got an event notification |
| 3344 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3345 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3346 | megasas_service_aen(instance, cmd); |
| 3347 | else |
| 3348 | megasas_complete_int_cmd(instance, cmd); |
| 3349 | |
| 3350 | break; |
| 3351 | |
| 3352 | case MFI_CMD_ABORT: |
| 3353 | /* |
| 3354 | * Cmd issued to abort another cmd returned |
| 3355 | */ |
| 3356 | megasas_complete_abort(instance, cmd); |
| 3357 | break; |
| 3358 | |
| 3359 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3360 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3361 | hdr->cmd); |
| 3362 | break; |
| 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3367 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3368 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3369 | * @instance: Adapter soft state |
| 3370 | */ |
| 3371 | static inline void |
| 3372 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3373 | { |
| 3374 | struct megasas_cmd *cmd; |
| 3375 | struct list_head clist_local; |
| 3376 | union megasas_evt_class_locale class_locale; |
| 3377 | unsigned long flags; |
| 3378 | u32 seq_num; |
| 3379 | |
| 3380 | INIT_LIST_HEAD(&clist_local); |
| 3381 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3382 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3383 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3384 | |
| 3385 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3386 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3387 | struct megasas_cmd, list); |
| 3388 | list_del_init(&cmd->list); |
| 3389 | |
| 3390 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3391 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3392 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3393 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3394 | |
| 3395 | cmd->retry_for_fw_reset++; |
| 3396 | |
| 3397 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3398 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3399 | "was tried multiple times during reset." |
| 3400 | "Shutting down the HBA\n", |
| 3401 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3402 | instance->instancet->disable_intr(instance); |
| 3403 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3404 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3405 | return; |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | if (cmd->sync_cmd == 1) { |
| 3410 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3411 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3412 | "cmd attached to internal command!\n"); |
| 3413 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3414 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3415 | "on the internal reset queue," |
| 3416 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3417 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3418 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3419 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3420 | 0, instance->reg_set); |
| 3421 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3422 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3423 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3424 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3425 | |
| 3426 | atomic_inc(&instance->fw_outstanding); |
| 3427 | instance->instancet->fire_cmd(instance, |
| 3428 | cmd->frame_phys_addr, |
| 3429 | cmd->frame_count-1, instance->reg_set); |
| 3430 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3431 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3432 | "internal reset defer list while re-issue!!\n", |
| 3433 | cmd); |
| 3434 | } |
| 3435 | } |
| 3436 | |
| 3437 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3438 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3439 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3440 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3441 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3445 | * Initiate AEN (Asynchronous Event Notification) |
| 3446 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3447 | seq_num = instance->last_seq_num; |
| 3448 | class_locale.members.reserved = 0; |
| 3449 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3450 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3451 | |
| 3452 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3453 | } |
| 3454 | |
| 3455 | /** |
| 3456 | * Move the internal reset pending commands to a deferred queue. |
| 3457 | * |
| 3458 | * We move the commands pending at internal reset time to a |
| 3459 | * pending queue. This queue would be flushed after successful |
| 3460 | * completion of the internal reset sequence. if the internal reset |
| 3461 | * did not complete in time, the kernel reset handler would flush |
| 3462 | * these commands. |
| 3463 | **/ |
| 3464 | static void |
| 3465 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3466 | { |
| 3467 | struct megasas_cmd *cmd; |
| 3468 | int i; |
| 3469 | u32 max_cmd = instance->max_fw_cmds; |
| 3470 | u32 defer_index; |
| 3471 | unsigned long flags; |
| 3472 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3473 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3474 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3475 | for (i = 0; i < max_cmd; i++) { |
| 3476 | cmd = instance->cmd_list[i]; |
| 3477 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3478 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3479 | "on the defer queue as internal\n", |
| 3480 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3481 | |
| 3482 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3483 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3484 | " moving this cmd:%p, %d %p, it was" |
| 3485 | "discovered on some list?\n", |
| 3486 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3487 | |
| 3488 | list_del_init(&cmd->list); |
| 3489 | } |
| 3490 | defer_index++; |
| 3491 | list_add_tail(&cmd->list, |
| 3492 | &instance->internal_reset_pending_q); |
| 3493 | } |
| 3494 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3495 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | |
| 3499 | static void |
| 3500 | process_fw_state_change_wq(struct work_struct *work) |
| 3501 | { |
| 3502 | struct megasas_instance *instance = |
| 3503 | container_of(work, struct megasas_instance, work_init); |
| 3504 | u32 wait; |
| 3505 | unsigned long flags; |
| 3506 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3507 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3508 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3509 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3510 | return ; |
| 3511 | } |
| 3512 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3513 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3514 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3515 | "state, restarting it...\n"); |
| 3516 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3517 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3518 | atomic_set(&instance->fw_outstanding, 0); |
| 3519 | |
| 3520 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3521 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3522 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3523 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3524 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3525 | "initiating next stage...\n"); |
| 3526 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3527 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3528 | "state 2 starting...\n"); |
| 3529 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3530 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3531 | for (wait = 0; wait < 30; wait++) { |
| 3532 | msleep(1000); |
| 3533 | } |
| 3534 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3535 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3536 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3537 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3538 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3539 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3540 | return ; |
| 3541 | } |
| 3542 | |
| 3543 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3544 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3545 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3546 | ) { |
| 3547 | *instance->consumer = *instance->producer; |
| 3548 | } else { |
| 3549 | *instance->consumer = 0; |
| 3550 | *instance->producer = 0; |
| 3551 | } |
| 3552 | |
| 3553 | megasas_issue_init_mfi(instance); |
| 3554 | |
| 3555 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3556 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3557 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3558 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3559 | |
| 3560 | megasas_issue_pending_cmds_again(instance); |
| 3561 | instance->issuepend_done = 1; |
| 3562 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3566 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3567 | * @instance: Adapter soft state |
| 3568 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3569 | * SCSI mid-layer instead of the status |
| 3570 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3571 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3572 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3573 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3574 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3575 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3576 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3577 | u32 mfiStatus; |
| 3578 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3579 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3580 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3581 | instance->reg_set)) == 1) { |
| 3582 | return IRQ_HANDLED; |
| 3583 | } |
| 3584 | |
| 3585 | if ((mfiStatus = instance->instancet->clear_intr( |
| 3586 | instance->reg_set) |
| 3587 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3588 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3589 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3590 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | instance->mfiStatus = mfiStatus; |
| 3594 | |
| 3595 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3596 | fw_state = instance->instancet->read_fw_status_reg( |
| 3597 | instance->reg_set) & MFI_STATE_MASK; |
| 3598 | |
| 3599 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3600 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3601 | fw_state); |
| 3602 | } |
| 3603 | |
| 3604 | if ((fw_state == MFI_STATE_FAULT) && |
| 3605 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3606 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3607 | |
| 3608 | if ((instance->pdev->device == |
| 3609 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3610 | (instance->pdev->device == |
| 3611 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3612 | (instance->pdev->device == |
| 3613 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3614 | |
| 3615 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3616 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3620 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3621 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3622 | instance->issuepend_done = 0; |
| 3623 | |
| 3624 | atomic_set(&instance->fw_outstanding, 0); |
| 3625 | megasas_internal_reset_defer_cmds(instance); |
| 3626 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3627 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3628 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3629 | |
| 3630 | schedule_work(&instance->work_init); |
| 3631 | return IRQ_HANDLED; |
| 3632 | |
| 3633 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3634 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3635 | fw_state, instance->disableOnlineCtrlReset); |
| 3636 | } |
| 3637 | } |
| 3638 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3639 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3640 | return IRQ_HANDLED; |
| 3641 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3642 | /** |
| 3643 | * megasas_isr - isr entry point |
| 3644 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3645 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3646 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3647 | struct megasas_irq_context *irq_context = devp; |
| 3648 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3649 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3650 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3651 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3652 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3653 | return IRQ_HANDLED; |
| 3654 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3655 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3656 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3657 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3658 | |
| 3659 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3664 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3665 | * |
| 3666 | * During the initialization, FW passes can potentially be in any one of |
| 3667 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3668 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3669 | * has to wait for the ready state. |
| 3670 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3671 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3672 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3673 | { |
| 3674 | int i; |
| 3675 | u8 max_wait; |
| 3676 | u32 fw_state; |
| 3677 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3678 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3679 | |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3680 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3681 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3682 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3683 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3684 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3685 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3686 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3687 | while (fw_state != MFI_STATE_READY) { |
| 3688 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3689 | switch (fw_state) { |
| 3690 | |
| 3691 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3692 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3693 | if (ocr) { |
| 3694 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3695 | cur_state = MFI_STATE_FAULT; |
| 3696 | break; |
| 3697 | } else |
| 3698 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3699 | |
| 3700 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3701 | /* |
| 3702 | * Set the CLR bit in inbound doorbell |
| 3703 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3704 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3705 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3706 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3707 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3708 | (instance->ctrl_context)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3709 | writel( |
| 3710 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3711 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3712 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3713 | writel( |
| 3714 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3715 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3716 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3717 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3718 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3719 | break; |
| 3720 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3721 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3722 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3723 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3724 | (instance->pdev->device == |
| 3725 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3726 | (instance->ctrl_context)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3727 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3728 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3729 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3730 | writel(MFI_INIT_HOTPLUG, |
| 3731 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3732 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3733 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3734 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3735 | break; |
| 3736 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3737 | case MFI_STATE_OPERATIONAL: |
| 3738 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3739 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3740 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3741 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3742 | if ((instance->pdev->device == |
| 3743 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3744 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3745 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3746 | (instance->ctrl_context)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3747 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3748 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3749 | |
| 3750 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3751 | for (i = 0; i < (10 * 1000); i += 20) { |
| 3752 | if (readl( |
| 3753 | &instance-> |
| 3754 | reg_set-> |
| 3755 | doorbell) & 1) |
| 3756 | msleep(20); |
| 3757 | else |
| 3758 | break; |
| 3759 | } |
| 3760 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3761 | } else |
| 3762 | writel(MFI_RESET_FLAGS, |
| 3763 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3764 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3765 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3766 | cur_state = MFI_STATE_OPERATIONAL; |
| 3767 | break; |
| 3768 | |
| 3769 | case MFI_STATE_UNDEFINED: |
| 3770 | /* |
| 3771 | * This state should not last for more than 2 seconds |
| 3772 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3773 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3774 | cur_state = MFI_STATE_UNDEFINED; |
| 3775 | break; |
| 3776 | |
| 3777 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3778 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3779 | cur_state = MFI_STATE_BB_INIT; |
| 3780 | break; |
| 3781 | |
| 3782 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3783 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3784 | cur_state = MFI_STATE_FW_INIT; |
| 3785 | break; |
| 3786 | |
| 3787 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3788 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3789 | cur_state = MFI_STATE_FW_INIT_2; |
| 3790 | break; |
| 3791 | |
| 3792 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3793 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3794 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3795 | break; |
| 3796 | |
| 3797 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3798 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3799 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3800 | break; |
| 3801 | |
| 3802 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3803 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3804 | fw_state); |
| 3805 | return -ENODEV; |
| 3806 | } |
| 3807 | |
| 3808 | /* |
| 3809 | * The cur_state should not last for more than max_wait secs |
| 3810 | */ |
| 3811 | for (i = 0; i < (max_wait * 1000); i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3812 | curr_abs_state = instance->instancet-> |
| 3813 | read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3814 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3815 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3816 | msleep(1); |
| 3817 | } else |
| 3818 | break; |
| 3819 | } |
| 3820 | |
| 3821 | /* |
| 3822 | * Return error if fw_state hasn't changed after max_wait |
| 3823 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3824 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3825 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW state [%d] hasn't changed " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3826 | "in %d secs\n", fw_state, max_wait); |
| 3827 | return -ENODEV; |
| 3828 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3829 | |
| 3830 | abs_state = curr_abs_state; |
| 3831 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3832 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3833 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3834 | |
| 3835 | return 0; |
| 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3840 | * @instance: Adapter soft state |
| 3841 | */ |
| 3842 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3843 | { |
| 3844 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3845 | u32 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3846 | struct megasas_cmd *cmd; |
| 3847 | |
| 3848 | if (!instance->frame_dma_pool) |
| 3849 | return; |
| 3850 | |
| 3851 | /* |
| 3852 | * Return all frames to pool |
| 3853 | */ |
| 3854 | for (i = 0; i < max_cmd; i++) { |
| 3855 | |
| 3856 | cmd = instance->cmd_list[i]; |
| 3857 | |
| 3858 | if (cmd->frame) |
| 3859 | pci_pool_free(instance->frame_dma_pool, cmd->frame, |
| 3860 | cmd->frame_phys_addr); |
| 3861 | |
| 3862 | if (cmd->sense) |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3863 | pci_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3864 | cmd->sense_phys_addr); |
| 3865 | } |
| 3866 | |
| 3867 | /* |
| 3868 | * Now destroy the pool itself |
| 3869 | */ |
| 3870 | pci_pool_destroy(instance->frame_dma_pool); |
| 3871 | pci_pool_destroy(instance->sense_dma_pool); |
| 3872 | |
| 3873 | instance->frame_dma_pool = NULL; |
| 3874 | instance->sense_dma_pool = NULL; |
| 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3879 | * @instance: Adapter soft state |
| 3880 | * |
| 3881 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3882 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3883 | * function creates those DMA memory buffers for each command packet by using |
| 3884 | * PCI pool facility. |
| 3885 | */ |
| 3886 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3887 | { |
| 3888 | int i; |
| 3889 | u32 max_cmd; |
| 3890 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3891 | u32 total_sz; |
| 3892 | u32 frame_count; |
| 3893 | struct megasas_cmd *cmd; |
| 3894 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3895 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3896 | |
| 3897 | /* |
| 3898 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 3899 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 3900 | */ |
| 3901 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 3902 | sizeof(struct megasas_sge32); |
| 3903 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3904 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3905 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3906 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3907 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3908 | * For MFI controllers. |
| 3909 | * max_num_sge = 60 |
| 3910 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 3911 | * Total 960 byte (15 MFI frame of 64 byte) |
| 3912 | * |
| 3913 | * Fusion adapter require only 3 extra frame. |
| 3914 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 3915 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 3916 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3917 | */ |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3918 | frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3919 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; |
| 3920 | /* |
| 3921 | * Use DMA pool facility provided by PCI layer |
| 3922 | */ |
| 3923 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3924 | instance->pdev, total_sz, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3925 | |
| 3926 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3927 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup frame pool\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3928 | return -ENOMEM; |
| 3929 | } |
| 3930 | |
| 3931 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", |
| 3932 | instance->pdev, 128, 4, 0); |
| 3933 | |
| 3934 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3935 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup sense pool\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3936 | |
| 3937 | pci_pool_destroy(instance->frame_dma_pool); |
| 3938 | instance->frame_dma_pool = NULL; |
| 3939 | |
| 3940 | return -ENOMEM; |
| 3941 | } |
| 3942 | |
| 3943 | /* |
| 3944 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 3945 | * By making cmd->index as the context instead of the &cmd, we can |
| 3946 | * always use 32bit context regardless of the architecture |
| 3947 | */ |
| 3948 | for (i = 0; i < max_cmd; i++) { |
| 3949 | |
| 3950 | cmd = instance->cmd_list[i]; |
| 3951 | |
| 3952 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, |
| 3953 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 3954 | |
| 3955 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, |
| 3956 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 3957 | |
| 3958 | /* |
| 3959 | * megasas_teardown_frame_pool() takes care of freeing |
| 3960 | * whatever has been allocated |
| 3961 | */ |
| 3962 | if (!cmd->frame || !cmd->sense) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3963 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "pci_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3964 | megasas_teardown_frame_pool(instance); |
| 3965 | return -ENOMEM; |
| 3966 | } |
| 3967 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 3968 | memset(cmd->frame, 0, total_sz); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3969 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3970 | cmd->frame->io.pad_0 = 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3971 | if (!instance->ctrl_context && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3972 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | return 0; |
| 3976 | } |
| 3977 | |
| 3978 | /** |
| 3979 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 3980 | * @instance: Adapter soft state |
| 3981 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3982 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3983 | { |
| 3984 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3985 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3986 | /* First free the MFI frame pool */ |
| 3987 | megasas_teardown_frame_pool(instance); |
| 3988 | |
| 3989 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3990 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 3991 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3992 | kfree(instance->cmd_list[i]); |
| 3993 | |
| 3994 | /* Free the cmd_list buffer itself */ |
| 3995 | kfree(instance->cmd_list); |
| 3996 | instance->cmd_list = NULL; |
| 3997 | |
| 3998 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 3999 | } |
| 4000 | |
| 4001 | /** |
| 4002 | * megasas_alloc_cmds - Allocates the command packets |
| 4003 | * @instance: Adapter soft state |
| 4004 | * |
| 4005 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 4006 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 4007 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 4008 | * the FW. |
| 4009 | * |
| 4010 | * Each frame has a 32-bit field called context (tag). This context is used |
| 4011 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 4012 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 4013 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 4014 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 4015 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 4016 | * This array is used only to look up the megasas_cmd given the context. The |
| 4017 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 4018 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4019 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4020 | { |
| 4021 | int i; |
| 4022 | int j; |
| 4023 | u32 max_cmd; |
| 4024 | struct megasas_cmd *cmd; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4025 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4026 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4027 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4028 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4029 | |
| 4030 | /* |
| 4031 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 4032 | * Allocate the dynamic array first and then allocate individual |
| 4033 | * commands. |
| 4034 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4035 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4036 | |
| 4037 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4038 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4039 | return -ENOMEM; |
| 4040 | } |
| 4041 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4042 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4043 | |
| 4044 | for (i = 0; i < max_cmd; i++) { |
| 4045 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 4046 | GFP_KERNEL); |
| 4047 | |
| 4048 | if (!instance->cmd_list[i]) { |
| 4049 | |
| 4050 | for (j = 0; j < i; j++) |
| 4051 | kfree(instance->cmd_list[j]); |
| 4052 | |
| 4053 | kfree(instance->cmd_list); |
| 4054 | instance->cmd_list = NULL; |
| 4055 | |
| 4056 | return -ENOMEM; |
| 4057 | } |
| 4058 | } |
| 4059 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4060 | for (i = 0; i < max_cmd; i++) { |
| 4061 | cmd = instance->cmd_list[i]; |
| 4062 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 4063 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4064 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4065 | cmd->instance = instance; |
| 4066 | |
| 4067 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 4068 | } |
| 4069 | |
| 4070 | /* |
| 4071 | * Create a frame pool and assign one frame to each cmd |
| 4072 | */ |
| 4073 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4074 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Error creating frame DMA pool\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4075 | megasas_free_cmds(instance); |
| 4076 | } |
| 4077 | |
| 4078 | return 0; |
| 4079 | } |
| 4080 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4081 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4082 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 4083 | * @instance: Adapter soft state |
| 4084 | * |
| 4085 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 4086 | * or FW is not under OCR. |
| 4087 | */ |
| 4088 | inline int |
| 4089 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 4090 | |
| 4091 | if (!instance->ctrl_context) |
| 4092 | return KILL_ADAPTER; |
| 4093 | else if (instance->unload || |
| 4094 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 4095 | return IGNORE_TIMEOUT; |
| 4096 | else |
| 4097 | return INITIATE_OCR; |
| 4098 | } |
| 4099 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4100 | static void |
| 4101 | megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4102 | { |
| 4103 | int ret; |
| 4104 | struct megasas_cmd *cmd; |
| 4105 | struct megasas_dcmd_frame *dcmd; |
| 4106 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4107 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 4108 | u16 device_id = 0; |
| 4109 | |
| 4110 | device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4111 | cmd = megasas_get_cmd(instance); |
| 4112 | |
| 4113 | if (!cmd) { |
| 4114 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4115 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | dcmd = &cmd->frame->dcmd; |
| 4119 | |
| 4120 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4121 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4122 | |
| 4123 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4124 | dcmd->cmd = MFI_CMD_DCMD; |
| 4125 | dcmd->cmd_status = 0xFF; |
| 4126 | dcmd->sge_count = 1; |
| 4127 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 4128 | dcmd->timeout = 0; |
| 4129 | dcmd->pad_0 = 0; |
| 4130 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4131 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
| 4132 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->pd_info_h); |
| 4133 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4134 | |
| 4135 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4136 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4137 | else |
| 4138 | ret = megasas_issue_polled(instance, cmd); |
| 4139 | |
| 4140 | switch (ret) { |
| 4141 | case DCMD_SUCCESS: |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4142 | mr_device_priv_data = sdev->hostdata; |
| 4143 | le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType); |
| 4144 | mr_device_priv_data->interface_type = |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4145 | instance->pd_info->state.ddf.pdType.intf; |
| 4146 | break; |
| 4147 | |
| 4148 | case DCMD_TIMEOUT: |
| 4149 | |
| 4150 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4151 | case INITIATE_OCR: |
| 4152 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4153 | megasas_reset_fusion(instance->host, |
| 4154 | MFI_IO_TIMEOUT_OCR); |
| 4155 | break; |
| 4156 | case KILL_ADAPTER: |
| 4157 | megaraid_sas_kill_hba(instance); |
| 4158 | break; |
| 4159 | case IGNORE_TIMEOUT: |
| 4160 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4161 | __func__, __LINE__); |
| 4162 | break; |
| 4163 | } |
| 4164 | |
| 4165 | break; |
| 4166 | } |
| 4167 | |
| 4168 | if (ret != DCMD_TIMEOUT) |
| 4169 | megasas_return_cmd(instance, cmd); |
| 4170 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4171 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4172 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4173 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4174 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4175 | * @instance: Adapter soft state |
| 4176 | * @pd_list: pd_list structure |
| 4177 | * |
| 4178 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4179 | * list structure. This information is mainly used to find out SYSTEM |
| 4180 | * supported by the FW. |
| 4181 | */ |
| 4182 | static int |
| 4183 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4184 | { |
| 4185 | int ret = 0, pd_index = 0; |
| 4186 | struct megasas_cmd *cmd; |
| 4187 | struct megasas_dcmd_frame *dcmd; |
| 4188 | struct MR_PD_LIST *ci; |
| 4189 | struct MR_PD_ADDRESS *pd_addr; |
| 4190 | dma_addr_t ci_h = 0; |
| 4191 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4192 | if (instance->pd_list_not_supported) { |
| 4193 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4194 | "not supported by firmware\n"); |
| 4195 | return ret; |
| 4196 | } |
| 4197 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4198 | cmd = megasas_get_cmd(instance); |
| 4199 | |
| 4200 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4201 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "(get_pd_list): Failed to get cmd\n"); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4202 | return -ENOMEM; |
| 4203 | } |
| 4204 | |
| 4205 | dcmd = &cmd->frame->dcmd; |
| 4206 | |
| 4207 | ci = pci_alloc_consistent(instance->pdev, |
| 4208 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h); |
| 4209 | |
| 4210 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4211 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for pd_list\n"); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4212 | megasas_return_cmd(instance, cmd); |
| 4213 | return -ENOMEM; |
| 4214 | } |
| 4215 | |
| 4216 | memset(ci, 0, sizeof(*ci)); |
| 4217 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4218 | |
| 4219 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4220 | dcmd->mbox.b[1] = 0; |
| 4221 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4222 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4223 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4224 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4225 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4226 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4227 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4228 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
| 4229 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4230 | dcmd->sgl.sge32[0].length = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4231 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4232 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4233 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4234 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4235 | else |
| 4236 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4237 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4238 | switch (ret) { |
| 4239 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4240 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4241 | "failed/not supported by firmware\n"); |
| 4242 | |
| 4243 | if (instance->ctrl_context) |
| 4244 | megaraid_sas_kill_hba(instance); |
| 4245 | else |
| 4246 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4247 | break; |
| 4248 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4249 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4250 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4251 | case INITIATE_OCR: |
| 4252 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4253 | /* |
| 4254 | * DCMD failed from AEN path. |
| 4255 | * AEN path already hold reset_mutex to avoid PCI access |
| 4256 | * while OCR is in progress. |
| 4257 | */ |
| 4258 | mutex_unlock(&instance->reset_mutex); |
| 4259 | megasas_reset_fusion(instance->host, |
| 4260 | MFI_IO_TIMEOUT_OCR); |
| 4261 | mutex_lock(&instance->reset_mutex); |
| 4262 | break; |
| 4263 | case KILL_ADAPTER: |
| 4264 | megaraid_sas_kill_hba(instance); |
| 4265 | break; |
| 4266 | case IGNORE_TIMEOUT: |
| 4267 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4268 | __func__, __LINE__); |
| 4269 | break; |
| 4270 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4271 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4272 | break; |
| 4273 | |
| 4274 | case DCMD_SUCCESS: |
| 4275 | pd_addr = ci->addr; |
| 4276 | |
| 4277 | if ((le32_to_cpu(ci->count) > |
| 4278 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4279 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4280 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4281 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4282 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4283 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4284 | for (pd_index = 0; pd_index < le32_to_cpu(ci->count); pd_index++) { |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4285 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4286 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4287 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4288 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4289 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4290 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4291 | pd_addr++; |
| 4292 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4293 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4294 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4295 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4296 | break; |
| 4297 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | pci_free_consistent(instance->pdev, |
| 4301 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 4302 | ci, ci_h); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4303 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4304 | if (ret != DCMD_TIMEOUT) |
| 4305 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4306 | |
| 4307 | return ret; |
| 4308 | } |
| 4309 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4310 | /* |
| 4311 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4312 | * @instance: Adapter soft state |
| 4313 | * @ld_list: ld_list structure |
| 4314 | * |
| 4315 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4316 | * list structure. This information is mainly used to find out SYSTEM |
| 4317 | * supported by the FW. |
| 4318 | */ |
| 4319 | static int |
| 4320 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4321 | { |
| 4322 | int ret = 0, ld_index = 0, ids = 0; |
| 4323 | struct megasas_cmd *cmd; |
| 4324 | struct megasas_dcmd_frame *dcmd; |
| 4325 | struct MR_LD_LIST *ci; |
| 4326 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4327 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4328 | |
| 4329 | cmd = megasas_get_cmd(instance); |
| 4330 | |
| 4331 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4332 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_list: Failed to get cmd\n"); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4333 | return -ENOMEM; |
| 4334 | } |
| 4335 | |
| 4336 | dcmd = &cmd->frame->dcmd; |
| 4337 | |
| 4338 | ci = pci_alloc_consistent(instance->pdev, |
| 4339 | sizeof(struct MR_LD_LIST), |
| 4340 | &ci_h); |
| 4341 | |
| 4342 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4343 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem in get_ld_list\n"); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4344 | megasas_return_cmd(instance, cmd); |
| 4345 | return -ENOMEM; |
| 4346 | } |
| 4347 | |
| 4348 | memset(ci, 0, sizeof(*ci)); |
| 4349 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4350 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4351 | if (instance->supportmax256vd) |
| 4352 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4353 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4354 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4355 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4356 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4357 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4358 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4359 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
| 4360 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4361 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4362 | dcmd->pad_0 = 0; |
| 4363 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4364 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4365 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4366 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4367 | else |
| 4368 | ret = megasas_issue_polled(instance, cmd); |
| 4369 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4370 | ld_count = le32_to_cpu(ci->ldCount); |
| 4371 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4372 | switch (ret) { |
| 4373 | case DCMD_FAILED: |
| 4374 | megaraid_sas_kill_hba(instance); |
| 4375 | break; |
| 4376 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4377 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4378 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4379 | case INITIATE_OCR: |
| 4380 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4381 | /* |
| 4382 | * DCMD failed from AEN path. |
| 4383 | * AEN path already hold reset_mutex to avoid PCI access |
| 4384 | * while OCR is in progress. |
| 4385 | */ |
| 4386 | mutex_unlock(&instance->reset_mutex); |
| 4387 | megasas_reset_fusion(instance->host, |
| 4388 | MFI_IO_TIMEOUT_OCR); |
| 4389 | mutex_lock(&instance->reset_mutex); |
| 4390 | break; |
| 4391 | case KILL_ADAPTER: |
| 4392 | megaraid_sas_kill_hba(instance); |
| 4393 | break; |
| 4394 | case IGNORE_TIMEOUT: |
| 4395 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4396 | __func__, __LINE__); |
| 4397 | break; |
| 4398 | } |
| 4399 | |
| 4400 | break; |
| 4401 | |
| 4402 | case DCMD_SUCCESS: |
| 4403 | if (ld_count > instance->fw_supported_vd_count) |
| 4404 | break; |
| 4405 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4406 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4407 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4408 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4409 | if (ci->ldList[ld_index].state != 0) { |
| 4410 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4411 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4412 | } |
| 4413 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4414 | |
| 4415 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4418 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_LIST), ci, ci_h); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4419 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4420 | if (ret != DCMD_TIMEOUT) |
| 4421 | megasas_return_cmd(instance, cmd); |
| 4422 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4423 | return ret; |
| 4424 | } |
| 4425 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4426 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4427 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4428 | * @instance: Adapter soft state |
| 4429 | * @ld_list: ld_list structure |
| 4430 | * |
| 4431 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4432 | * list structure. This information is mainly used to find out SYSTEM |
| 4433 | * supported by the FW. |
| 4434 | */ |
| 4435 | static int |
| 4436 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4437 | { |
| 4438 | int ret = 0, ld_index = 0, ids = 0; |
| 4439 | struct megasas_cmd *cmd; |
| 4440 | struct megasas_dcmd_frame *dcmd; |
| 4441 | struct MR_LD_TARGETID_LIST *ci; |
| 4442 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4443 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4444 | |
| 4445 | cmd = megasas_get_cmd(instance); |
| 4446 | |
| 4447 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4448 | dev_warn(&instance->pdev->dev, |
| 4449 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4450 | return -ENOMEM; |
| 4451 | } |
| 4452 | |
| 4453 | dcmd = &cmd->frame->dcmd; |
| 4454 | |
| 4455 | ci = pci_alloc_consistent(instance->pdev, |
| 4456 | sizeof(struct MR_LD_TARGETID_LIST), &ci_h); |
| 4457 | |
| 4458 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4459 | dev_warn(&instance->pdev->dev, |
| 4460 | "Failed to alloc mem for ld_list_query\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4461 | megasas_return_cmd(instance, cmd); |
| 4462 | return -ENOMEM; |
| 4463 | } |
| 4464 | |
| 4465 | memset(ci, 0, sizeof(*ci)); |
| 4466 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4467 | |
| 4468 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4469 | if (instance->supportmax256vd) |
| 4470 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4471 | |
| 4472 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4473 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4474 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4475 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4476 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4477 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4478 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
| 4479 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4480 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4481 | dcmd->pad_0 = 0; |
| 4482 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4483 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4484 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4485 | else |
| 4486 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4487 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4488 | switch (ret) { |
| 4489 | case DCMD_FAILED: |
| 4490 | dev_info(&instance->pdev->dev, |
| 4491 | "DCMD not supported by firmware - %s %d\n", |
| 4492 | __func__, __LINE__); |
| 4493 | ret = megasas_get_ld_list(instance); |
| 4494 | break; |
| 4495 | case DCMD_TIMEOUT: |
| 4496 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4497 | case INITIATE_OCR: |
| 4498 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4499 | /* |
| 4500 | * DCMD failed from AEN path. |
| 4501 | * AEN path already hold reset_mutex to avoid PCI access |
| 4502 | * while OCR is in progress. |
| 4503 | */ |
| 4504 | mutex_unlock(&instance->reset_mutex); |
| 4505 | megasas_reset_fusion(instance->host, |
| 4506 | MFI_IO_TIMEOUT_OCR); |
| 4507 | mutex_lock(&instance->reset_mutex); |
| 4508 | break; |
| 4509 | case KILL_ADAPTER: |
| 4510 | megaraid_sas_kill_hba(instance); |
| 4511 | break; |
| 4512 | case IGNORE_TIMEOUT: |
| 4513 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4514 | __func__, __LINE__); |
| 4515 | break; |
| 4516 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4517 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4518 | break; |
| 4519 | case DCMD_SUCCESS: |
| 4520 | tgtid_count = le32_to_cpu(ci->count); |
| 4521 | |
| 4522 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4523 | break; |
| 4524 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4525 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4526 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4527 | ids = ci->targetId[ld_index]; |
| 4528 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4529 | } |
| 4530 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4531 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4532 | } |
| 4533 | |
| 4534 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_TARGETID_LIST), |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4535 | ci, ci_h); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4536 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4537 | if (ret != DCMD_TIMEOUT) |
| 4538 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4539 | |
| 4540 | return ret; |
| 4541 | } |
| 4542 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4543 | /* |
| 4544 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4545 | * instance : Controller's instance |
| 4546 | */ |
| 4547 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4548 | { |
| 4549 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4550 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4551 | |
| 4552 | fusion = instance->ctrl_context; |
| 4553 | /* For MFI based controllers return dummy success */ |
| 4554 | if (!fusion) |
| 4555 | return; |
| 4556 | |
| 4557 | instance->supportmax256vd = |
| 4558 | instance->ctrl_info->adapterOperations3.supportMaxExtLDs; |
| 4559 | /* Below is additional check to address future FW enhancement */ |
| 4560 | if (instance->ctrl_info->max_lds > 64) |
| 4561 | instance->supportmax256vd = 1; |
| 4562 | |
| 4563 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4564 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4565 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4566 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4567 | if (instance->supportmax256vd) { |
| 4568 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4569 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4570 | } else { |
| 4571 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4572 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4573 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4574 | |
| 4575 | dev_info(&instance->pdev->dev, |
| 4576 | "firmware type\t: %s\n", |
| 4577 | instance->supportmax256vd ? "Extended VD(240 VD)firmware" : |
| 4578 | "Legacy(64 VD) firmware"); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4579 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4580 | if (instance->max_raid_mapsize) { |
| 4581 | ventura_map_sz = instance->max_raid_mapsize * |
| 4582 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4583 | fusion->current_map_sz = ventura_map_sz; |
| 4584 | fusion->max_map_sz = ventura_map_sz; |
| 4585 | } else { |
| 4586 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4587 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4588 | (instance->fw_supported_vd_count - 1)); |
| 4589 | fusion->new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4590 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4591 | fusion->max_map_sz = |
| 4592 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4593 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4594 | if (instance->supportmax256vd) |
| 4595 | fusion->current_map_sz = fusion->new_map_sz; |
| 4596 | else |
| 4597 | fusion->current_map_sz = fusion->old_map_sz; |
| 4598 | } |
| 4599 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4600 | fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4601 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4602 | #if VD_EXT_DEBUG |
| 4603 | dev_info(&instance->pdev->dev, "instance->max_raid_mapsize 0x%x\n ", |
| 4604 | instance->max_raid_mapsize); |
| 4605 | dev_info(&instance->pdev->dev, "new_map_sz = 0x%x, old_map_sz = 0x%x\n", |
| 4606 | fusion->new_map_sz, fusion->old_map_sz); |
| 4607 | dev_info(&instance->pdev->dev, "ventura_map_sz = 0x%x, current_map_sz = 0x%x\n", |
| 4608 | ventura_map_sz, fusion->current_map_sz); |
| 4609 | dev_info(&instance->pdev->dev, "fusion->drv_map_sz =0x%x, size of driver raid map 0x%lx\n", |
| 4610 | fusion->drv_map_sz, sizeof(struct MR_DRV_RAID_MAP_ALL)); |
| 4611 | #endif |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4612 | } |
| 4613 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4614 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4615 | * megasas_get_controller_info - Returns FW's controller structure |
| 4616 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4617 | * |
| 4618 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4619 | * This information is mainly used to find out the maximum IO transfer per |
| 4620 | * command supported by the FW. |
| 4621 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4622 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4623 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4624 | { |
| 4625 | int ret = 0; |
| 4626 | struct megasas_cmd *cmd; |
| 4627 | struct megasas_dcmd_frame *dcmd; |
| 4628 | struct megasas_ctrl_info *ci; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4629 | struct megasas_ctrl_info *ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4630 | dma_addr_t ci_h = 0; |
| 4631 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4632 | ctrl_info = instance->ctrl_info; |
| 4633 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4634 | cmd = megasas_get_cmd(instance); |
| 4635 | |
| 4636 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4637 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get a free cmd\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4638 | return -ENOMEM; |
| 4639 | } |
| 4640 | |
| 4641 | dcmd = &cmd->frame->dcmd; |
| 4642 | |
| 4643 | ci = pci_alloc_consistent(instance->pdev, |
| 4644 | sizeof(struct megasas_ctrl_info), &ci_h); |
| 4645 | |
| 4646 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4647 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ctrl info\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4648 | megasas_return_cmd(instance, cmd); |
| 4649 | return -ENOMEM; |
| 4650 | } |
| 4651 | |
| 4652 | memset(ci, 0, sizeof(*ci)); |
| 4653 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4654 | |
| 4655 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4656 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4657 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4658 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4659 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4660 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4661 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4662 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
| 4663 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4664 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4665 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4666 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4667 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4668 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4669 | else |
| 4670 | ret = megasas_issue_polled(instance, cmd); |
| 4671 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4672 | switch (ret) { |
| 4673 | case DCMD_SUCCESS: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4674 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4675 | /* Save required controller information in |
| 4676 | * CPU endianness format. |
| 4677 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4678 | le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties); |
| 4679 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations2); |
| 4680 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations3); |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4681 | le16_to_cpus((u16 *)&ctrl_info->adapter_operations4); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4682 | |
| 4683 | /* Update the latest Ext VD info. |
| 4684 | * From Init path, store current firmware details. |
| 4685 | * From OCR path, detect any firmware properties changes. |
| 4686 | * in case of Firmware upgrade without system reboot. |
| 4687 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4688 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4689 | instance->use_seqnum_jbod_fp = |
| 4690 | ctrl_info->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4691 | instance->support_morethan256jbod = |
| 4692 | ctrl_info->adapter_operations4.support_pd_map_target_id; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4693 | |
| 4694 | /*Check whether controller is iMR or MR */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4695 | instance->is_imr = (ctrl_info->memory_size ? 0 : 1); |
| 4696 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4697 | "controller type\t: %s(%dMB)\n", |
| 4698 | instance->is_imr ? "iMR" : "MR", |
| 4699 | le16_to_cpu(ctrl_info->memory_size)); |
| 4700 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 4701 | instance->disableOnlineCtrlReset = |
| 4702 | ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4703 | instance->secure_jbod_support = |
| 4704 | ctrl_info->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4705 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 4706 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4707 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 4708 | instance->secure_jbod_support ? "Yes" : "No"); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4709 | break; |
| 4710 | |
| 4711 | case DCMD_TIMEOUT: |
| 4712 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4713 | case INITIATE_OCR: |
| 4714 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4715 | megasas_reset_fusion(instance->host, |
| 4716 | MFI_IO_TIMEOUT_OCR); |
| 4717 | break; |
| 4718 | case KILL_ADAPTER: |
| 4719 | megaraid_sas_kill_hba(instance); |
| 4720 | break; |
| 4721 | case IGNORE_TIMEOUT: |
| 4722 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4723 | __func__, __LINE__); |
| 4724 | break; |
| 4725 | } |
| 4726 | case DCMD_FAILED: |
| 4727 | megaraid_sas_kill_hba(instance); |
| 4728 | break; |
| 4729 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4730 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4731 | |
| 4732 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), |
| 4733 | ci, ci_h); |
| 4734 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4735 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4736 | |
| 4737 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4738 | return ret; |
| 4739 | } |
| 4740 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4741 | /* |
| 4742 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 4743 | * to firmware |
| 4744 | * |
| 4745 | * @instance: Adapter soft state |
| 4746 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 4747 | MR_CRASH_BUF_TURN_OFF = 0 |
| 4748 | MR_CRASH_BUF_TURN_ON = 1 |
| 4749 | * @return 0 on success non-zero on failure. |
| 4750 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 4751 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 4752 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 4753 | * crash dump feature is supported by the FW. |
| 4754 | * |
| 4755 | */ |
| 4756 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 4757 | u8 crash_buf_state) |
| 4758 | { |
| 4759 | int ret = 0; |
| 4760 | struct megasas_cmd *cmd; |
| 4761 | struct megasas_dcmd_frame *dcmd; |
| 4762 | |
| 4763 | cmd = megasas_get_cmd(instance); |
| 4764 | |
| 4765 | if (!cmd) { |
| 4766 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4767 | return -ENOMEM; |
| 4768 | } |
| 4769 | |
| 4770 | |
| 4771 | dcmd = &cmd->frame->dcmd; |
| 4772 | |
| 4773 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4774 | dcmd->mbox.b[0] = crash_buf_state; |
| 4775 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4776 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4777 | dcmd->sge_count = 1; |
| 4778 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
| 4779 | dcmd->timeout = 0; |
| 4780 | dcmd->pad_0 = 0; |
| 4781 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4782 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
| 4783 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h); |
| 4784 | dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4785 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4786 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4787 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4788 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4789 | ret = megasas_issue_polled(instance, cmd); |
| 4790 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4791 | if (ret == DCMD_TIMEOUT) { |
| 4792 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4793 | case INITIATE_OCR: |
| 4794 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4795 | megasas_reset_fusion(instance->host, |
| 4796 | MFI_IO_TIMEOUT_OCR); |
| 4797 | break; |
| 4798 | case KILL_ADAPTER: |
| 4799 | megaraid_sas_kill_hba(instance); |
| 4800 | break; |
| 4801 | case IGNORE_TIMEOUT: |
| 4802 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4803 | __func__, __LINE__); |
| 4804 | break; |
| 4805 | } |
| 4806 | } else |
| 4807 | megasas_return_cmd(instance, cmd); |
| 4808 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4809 | return ret; |
| 4810 | } |
| 4811 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4812 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4813 | * megasas_issue_init_mfi - Initializes the FW |
| 4814 | * @instance: Adapter soft state |
| 4815 | * |
| 4816 | * Issues the INIT MFI cmd |
| 4817 | */ |
| 4818 | static int |
| 4819 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 4820 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 4821 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4822 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4823 | struct megasas_init_frame *init_frame; |
| 4824 | struct megasas_init_queue_info *initq_info; |
| 4825 | dma_addr_t init_frame_h; |
| 4826 | dma_addr_t initq_info_h; |
| 4827 | |
| 4828 | /* |
| 4829 | * Prepare a init frame. Note the init frame points to queue info |
| 4830 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 4831 | * this frame - since we don't need any SGL - we use SGL's space as |
| 4832 | * queue info structure |
| 4833 | * |
| 4834 | * We will not get a NULL command below. We just created the pool. |
| 4835 | */ |
| 4836 | cmd = megasas_get_cmd(instance); |
| 4837 | |
| 4838 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 4839 | initq_info = (struct megasas_init_queue_info *) |
| 4840 | ((unsigned long)init_frame + 64); |
| 4841 | |
| 4842 | init_frame_h = cmd->frame_phys_addr; |
| 4843 | initq_info_h = init_frame_h + 64; |
| 4844 | |
| 4845 | context = init_frame->context; |
| 4846 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 4847 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 4848 | init_frame->context = context; |
| 4849 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4850 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 4851 | initq_info->reply_queue_start_phys_addr_lo = cpu_to_le32(instance->reply_queue_h); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4852 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4853 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 4854 | initq_info->consumer_index_phys_addr_lo = cpu_to_le32(instance->consumer_h); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4855 | |
| 4856 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4857 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4858 | init_frame->queue_info_new_phys_addr_lo = |
| 4859 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 4860 | init_frame->queue_info_new_phys_addr_hi = |
| 4861 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4862 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4863 | init_frame->data_xfer_len = cpu_to_le32(sizeof(struct megasas_init_queue_info)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4864 | |
| 4865 | /* |
| 4866 | * disable the intr before firing the init frame to FW |
| 4867 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4868 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4869 | |
| 4870 | /* |
| 4871 | * Issue the init frame in polled mode |
| 4872 | */ |
| 4873 | |
| 4874 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4875 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4876 | megasas_return_cmd(instance, cmd); |
| 4877 | goto fail_fw_init; |
| 4878 | } |
| 4879 | |
| 4880 | megasas_return_cmd(instance, cmd); |
| 4881 | |
| 4882 | return 0; |
| 4883 | |
| 4884 | fail_fw_init: |
| 4885 | return -EINVAL; |
| 4886 | } |
| 4887 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4888 | static u32 |
| 4889 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4890 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4891 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4892 | u32 context_sz; |
| 4893 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4894 | |
| 4895 | reg_set = instance->reg_set; |
| 4896 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4897 | /* |
| 4898 | * Get various operational parameters from status register |
| 4899 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4900 | instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 4901 | /* |
| 4902 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 4903 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 4904 | * does not exceed max cmds that the FW can support |
| 4905 | */ |
| 4906 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4907 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4908 | instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >> |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4909 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4910 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4911 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 4912 | * are reserved for IOCTL + driver's internal DCMDs. |
| 4913 | */ |
| 4914 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 4915 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 4916 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4917 | MEGASAS_SKINNY_INT_CMDS); |
| 4918 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 4919 | } else { |
| 4920 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4921 | MEGASAS_INT_CMDS); |
| 4922 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 4923 | } |
| 4924 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 4925 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4926 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4927 | * Create a pool of commands |
| 4928 | */ |
| 4929 | if (megasas_alloc_cmds(instance)) |
| 4930 | goto fail_alloc_cmds; |
| 4931 | |
| 4932 | /* |
| 4933 | * Allocate memory for reply queue. Length of reply queue should |
| 4934 | * be _one_ more than the maximum commands handled by the firmware. |
| 4935 | * |
| 4936 | * Note: When FW completes commands, it places corresponding contex |
| 4937 | * values in this circular reply queue. This circular queue is a fairly |
| 4938 | * typical producer-consumer queue. FW is the producer (of completed |
| 4939 | * commands) and the driver is the consumer. |
| 4940 | */ |
| 4941 | context_sz = sizeof(u32); |
| 4942 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 4943 | |
| 4944 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 4945 | reply_q_sz, |
| 4946 | &instance->reply_queue_h); |
| 4947 | |
| 4948 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4949 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Out of DMA mem for reply queue\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4950 | goto fail_reply_queue; |
| 4951 | } |
| 4952 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4953 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4954 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4955 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4956 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4957 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 4958 | "Fail from %s %d\n", instance->unique_id, |
| 4959 | __func__, __LINE__); |
| 4960 | goto fail_fw_init; |
| 4961 | } |
| 4962 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4963 | instance->fw_support_ieee = 0; |
| 4964 | instance->fw_support_ieee = |
| 4965 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 4966 | 0x04000000); |
| 4967 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4968 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4969 | instance->fw_support_ieee); |
| 4970 | |
| 4971 | if (instance->fw_support_ieee) |
| 4972 | instance->flag_ieee = 1; |
| 4973 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4974 | return 0; |
| 4975 | |
| 4976 | fail_fw_init: |
| 4977 | |
| 4978 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 4979 | instance->reply_queue, instance->reply_queue_h); |
| 4980 | fail_reply_queue: |
| 4981 | megasas_free_cmds(instance); |
| 4982 | |
| 4983 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4984 | return 1; |
| 4985 | } |
| 4986 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4987 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4988 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4989 | * @instance: Adapter soft state |
| 4990 | * |
| 4991 | * Do not enable interrupt, only setup ISRs. |
| 4992 | * |
| 4993 | * Return 0 on success. |
| 4994 | */ |
| 4995 | static int |
| 4996 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 4997 | { |
| 4998 | struct pci_dev *pdev; |
| 4999 | |
| 5000 | pdev = instance->pdev; |
| 5001 | instance->irq_context[0].instance = instance; |
| 5002 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5003 | if (request_irq(pci_irq_vector(pdev, 0), |
| 5004 | instance->instancet->service_isr, IRQF_SHARED, |
| 5005 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5006 | dev_err(&instance->pdev->dev, |
| 5007 | "Failed to register IRQ from %s %d\n", |
| 5008 | __func__, __LINE__); |
| 5009 | return -1; |
| 5010 | } |
| 5011 | return 0; |
| 5012 | } |
| 5013 | |
| 5014 | /** |
| 5015 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 5016 | * @instance: Adapter soft state |
| 5017 | * @is_probe: Driver probe check |
| 5018 | * |
| 5019 | * Do not enable interrupt, only setup ISRs. |
| 5020 | * |
| 5021 | * Return 0 on success. |
| 5022 | */ |
| 5023 | static int |
| 5024 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 5025 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5026 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5027 | struct pci_dev *pdev; |
| 5028 | |
| 5029 | pdev = instance->pdev; |
| 5030 | |
| 5031 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5032 | for (i = 0; i < instance->msix_vectors; i++) { |
| 5033 | instance->irq_context[i].instance = instance; |
| 5034 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5035 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5036 | instance->instancet->service_isr, 0, "megasas", |
| 5037 | &instance->irq_context[i])) { |
| 5038 | dev_err(&instance->pdev->dev, |
| 5039 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5040 | for (j = 0; j < i; j++) |
| 5041 | free_irq(pci_irq_vector(pdev, j), |
| 5042 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5043 | /* Retry irq register for IO_APIC*/ |
| 5044 | instance->msix_vectors = 0; |
| 5045 | if (is_probe) |
| 5046 | return megasas_setup_irqs_ioapic(instance); |
| 5047 | else |
| 5048 | return -1; |
| 5049 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5050 | } |
| 5051 | return 0; |
| 5052 | } |
| 5053 | |
| 5054 | /* |
| 5055 | * megasas_destroy_irqs- unregister interrupts. |
| 5056 | * @instance: Adapter soft state |
| 5057 | * return: void |
| 5058 | */ |
| 5059 | static void |
| 5060 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 5061 | |
| 5062 | int i; |
| 5063 | |
| 5064 | if (instance->msix_vectors) |
| 5065 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5066 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5067 | &instance->irq_context[i]); |
| 5068 | } |
| 5069 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5070 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 5071 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5072 | } |
| 5073 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5074 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5075 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 5076 | * @instance: Adapter soft state |
| 5077 | * @is_probe: Driver probe check |
| 5078 | * |
| 5079 | * Return 0 on success. |
| 5080 | */ |
| 5081 | void |
| 5082 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 5083 | { |
| 5084 | int i; |
| 5085 | struct fusion_context *fusion = instance->ctrl_context; |
| 5086 | u32 pd_seq_map_sz; |
| 5087 | |
| 5088 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 5089 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 5090 | |
| 5091 | if (reset_devices || !fusion || |
| 5092 | !instance->ctrl_info->adapterOperations3.useSeqNumJbodFP) { |
| 5093 | dev_info(&instance->pdev->dev, |
| 5094 | "Jbod map is not supported %s %d\n", |
| 5095 | __func__, __LINE__); |
| 5096 | instance->use_seqnum_jbod_fp = false; |
| 5097 | return; |
| 5098 | } |
| 5099 | |
| 5100 | if (fusion->pd_seq_sync[0]) |
| 5101 | goto skip_alloc; |
| 5102 | |
| 5103 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 5104 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 5105 | (&instance->pdev->dev, pd_seq_map_sz, |
| 5106 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 5107 | if (!fusion->pd_seq_sync[i]) { |
| 5108 | dev_err(&instance->pdev->dev, |
| 5109 | "Failed to allocate memory from %s %d\n", |
| 5110 | __func__, __LINE__); |
| 5111 | if (i == 1) { |
| 5112 | dma_free_coherent(&instance->pdev->dev, |
| 5113 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 5114 | fusion->pd_seq_phys[0]); |
| 5115 | fusion->pd_seq_sync[0] = NULL; |
| 5116 | } |
| 5117 | instance->use_seqnum_jbod_fp = false; |
| 5118 | return; |
| 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | skip_alloc: |
| 5123 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5124 | !megasas_sync_pd_seq_num(instance, true)) |
| 5125 | instance->use_seqnum_jbod_fp = true; |
| 5126 | else |
| 5127 | instance->use_seqnum_jbod_fp = false; |
| 5128 | } |
| 5129 | |
| 5130 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5131 | * megasas_init_fw - Initializes the FW |
| 5132 | * @instance: Adapter soft state |
| 5133 | * |
| 5134 | * This is the main function for initializing firmware |
| 5135 | */ |
| 5136 | |
| 5137 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5138 | { |
| 5139 | u32 max_sectors_1; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5140 | u32 max_sectors_2, tmp_sectors, msix_enable; |
| 5141 | u32 scratch_pad_2, scratch_pad_3, scratch_pad_4; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5142 | resource_size_t base_addr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5143 | struct megasas_register_set __iomem *reg_set; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5144 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5145 | unsigned long bar_list; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5146 | int i, j, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5147 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5148 | struct fusion_context *fusion; |
| 5149 | |
| 5150 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5151 | |
| 5152 | /* Find first memory bar */ |
| 5153 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5154 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5155 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5156 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5157 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5158 | return -EBUSY; |
| 5159 | } |
| 5160 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5161 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5162 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5163 | |
| 5164 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5165 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to map IO mem\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5166 | goto fail_ioremap; |
| 5167 | } |
| 5168 | |
| 5169 | reg_set = instance->reg_set; |
| 5170 | |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5171 | if (fusion) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5172 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5173 | else { |
| 5174 | switch (instance->pdev->device) { |
| 5175 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5176 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5177 | instance->instancet = &megasas_instance_template_ppc; |
| 5178 | break; |
| 5179 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5180 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5181 | instance->instancet = &megasas_instance_template_gen2; |
| 5182 | break; |
| 5183 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5184 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5185 | instance->instancet = &megasas_instance_template_skinny; |
| 5186 | break; |
| 5187 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5188 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5189 | default: |
| 5190 | instance->instancet = &megasas_instance_template_xscale; |
| 5191 | instance->pd_list_not_supported = 1; |
| 5192 | break; |
| 5193 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5194 | } |
| 5195 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5196 | if (megasas_transition_to_ready(instance, 0)) { |
| 5197 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5198 | instance->instancet->adp_reset |
| 5199 | (instance, instance->reg_set); |
| 5200 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 5201 | dev_info(&instance->pdev->dev, |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5202 | "FW restarted successfully from %s!\n", |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5203 | __func__); |
| 5204 | |
| 5205 | /*waitting for about 30 second before retry*/ |
| 5206 | ssleep(30); |
| 5207 | |
| 5208 | if (megasas_transition_to_ready(instance, 0)) |
| 5209 | goto fail_ready_state; |
| 5210 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5211 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5212 | if (instance->is_ventura) { |
| 5213 | scratch_pad_3 = |
| 5214 | readl(&instance->reg_set->outbound_scratch_pad_3); |
| 5215 | #if VD_EXT_DEBUG |
| 5216 | dev_info(&instance->pdev->dev, "scratch_pad3 0x%x\n", |
| 5217 | scratch_pad_3); |
| 5218 | #endif |
| 5219 | instance->max_raid_mapsize = ((scratch_pad_3 >> |
| 5220 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5221 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5222 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5223 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5224 | /* Check if MSI-X is supported while in ready state */ |
| 5225 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 5226 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5227 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5228 | int irq_flags = PCI_IRQ_MSIX; |
| 5229 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5230 | scratch_pad_2 = readl |
| 5231 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5232 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5233 | if (fusion) { |
| 5234 | if (fusion->adapter_type == THUNDERBOLT_SERIES) { /* Thunderbolt Series*/ |
| 5235 | instance->msix_vectors = (scratch_pad_2 |
| 5236 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 5237 | fw_msix_count = instance->msix_vectors; |
| 5238 | } else { /* Invader series supports more than 8 MSI-x vectors*/ |
| 5239 | instance->msix_vectors = ((scratch_pad_2 |
| 5240 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5241 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5242 | if (instance->msix_vectors > 16) |
| 5243 | instance->msix_combined = true; |
| 5244 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5245 | if (rdpq_enable) |
| 5246 | instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? |
| 5247 | 1 : 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5248 | fw_msix_count = instance->msix_vectors; |
| 5249 | /* Save 1-15 reply post index address to local memory |
| 5250 | * Index 0 is already saved from reg offset |
| 5251 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5252 | */ |
| 5253 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5254 | instance->reply_post_host_index_addr[loop] = |
| 5255 | (u32 __iomem *) |
| 5256 | ((u8 __iomem *)instance->reg_set + |
| 5257 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5258 | + (loop * 0x10)); |
| 5259 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5260 | } |
| 5261 | if (msix_vectors) |
| 5262 | instance->msix_vectors = min(msix_vectors, |
| 5263 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5264 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5265 | instance->msix_vectors = 1; |
| 5266 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 5267 | instance->msix_vectors = min(instance->msix_vectors, |
| 5268 | (unsigned int)num_online_cpus()); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5269 | if (smp_affinity_enable) |
| 5270 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5271 | i = pci_alloc_irq_vectors(instance->pdev, 1, |
| 5272 | instance->msix_vectors, irq_flags); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 5273 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5274 | instance->msix_vectors = i; |
| 5275 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5276 | instance->msix_vectors = 0; |
| 5277 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5278 | /* |
| 5279 | * MSI-X host index 0 is common for all adapter. |
| 5280 | * It is used for all MPT based Adapters. |
| 5281 | */ |
| 5282 | if (instance->msix_combined) { |
| 5283 | instance->reply_post_host_index_addr[0] = |
| 5284 | (u32 *)((u8 *)instance->reg_set + |
| 5285 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 5286 | } else { |
| 5287 | instance->reply_post_host_index_addr[0] = |
| 5288 | (u32 *)((u8 *)instance->reg_set + |
| 5289 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 5290 | } |
| 5291 | |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5292 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 5293 | if (i < 0) |
| 5294 | goto fail_setup_irqs; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5295 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5296 | dev_info(&instance->pdev->dev, |
| 5297 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5298 | dev_info(&instance->pdev->dev, |
| 5299 | "current msix/online cpus\t: (%d/%d)\n", |
| 5300 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5301 | dev_info(&instance->pdev->dev, |
| 5302 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5303 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5304 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5305 | (unsigned long)instance); |
| 5306 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5307 | instance->ctrl_info = kzalloc(sizeof(struct megasas_ctrl_info), |
| 5308 | GFP_KERNEL); |
| 5309 | if (instance->ctrl_info == NULL) |
| 5310 | goto fail_init_adapter; |
| 5311 | |
| 5312 | /* |
| 5313 | * Below are default value for legacy Firmware. |
| 5314 | * non-fusion based controllers |
| 5315 | */ |
| 5316 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5317 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5318 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5319 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5320 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5321 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5322 | if (instance->is_ventura) { |
| 5323 | scratch_pad_4 = |
| 5324 | readl(&instance->reg_set->outbound_scratch_pad_4); |
| 5325 | if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >= |
| 5326 | MR_DEFAULT_NVME_PAGE_SHIFT) |
| 5327 | instance->nvme_page_size = |
| 5328 | (1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK)); |
| 5329 | |
| 5330 | dev_info(&instance->pdev->dev, |
| 5331 | "NVME page size\t: (%d)\n", instance->nvme_page_size); |
| 5332 | } |
| 5333 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5334 | if (instance->msix_vectors ? |
| 5335 | megasas_setup_irqs_msix(instance, 1) : |
| 5336 | megasas_setup_irqs_ioapic(instance)) |
| 5337 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5338 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5339 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5340 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 5341 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5342 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5343 | megasas_setup_jbod_map(instance); |
| 5344 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5345 | /** for passthrough |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5346 | * the following function will get the PD LIST. |
| 5347 | */ |
| 5348 | memset(instance->pd_list, 0, |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5349 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5350 | if (megasas_get_pd_list(instance) < 0) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5351 | dev_err(&instance->pdev->dev, "failed to get PD list\n"); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5352 | goto fail_get_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5353 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5354 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5355 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5356 | |
| 5357 | /* stream detection initialization */ |
| 5358 | if (instance->is_ventura) { |
| 5359 | fusion->stream_detect_by_ld = |
| 5360 | kzalloc(sizeof(struct LD_STREAM_DETECT *) |
| 5361 | * MAX_LOGICAL_DRIVES_EXT, |
| 5362 | GFP_KERNEL); |
| 5363 | if (!fusion->stream_detect_by_ld) { |
| 5364 | dev_err(&instance->pdev->dev, |
| 5365 | "unable to allocate stream detection for pool of LDs\n"); |
| 5366 | goto fail_get_ld_pd_list; |
| 5367 | } |
| 5368 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 5369 | fusion->stream_detect_by_ld[i] = |
| 5370 | kmalloc(sizeof(struct LD_STREAM_DETECT), |
| 5371 | GFP_KERNEL); |
| 5372 | if (!fusion->stream_detect_by_ld[i]) { |
| 5373 | dev_err(&instance->pdev->dev, |
| 5374 | "unable to allocate stream detect by LD\n "); |
| 5375 | for (j = 0; j < i; ++j) |
| 5376 | kfree(fusion->stream_detect_by_ld[j]); |
| 5377 | kfree(fusion->stream_detect_by_ld); |
| 5378 | fusion->stream_detect_by_ld = NULL; |
| 5379 | goto fail_get_ld_pd_list; |
| 5380 | } |
| 5381 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 5382 | = MR_STREAM_BITMAP; |
| 5383 | } |
| 5384 | } |
| 5385 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5386 | if (megasas_ld_list_query(instance, |
| 5387 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 5388 | megasas_get_ld_list(instance); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5389 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5390 | /* |
| 5391 | * Compute the max allowed sectors per IO: The controller info has two |
| 5392 | * limits on max sectors. Driver should use the minimum of these two. |
| 5393 | * |
| 5394 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5395 | * |
| 5396 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5397 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5398 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5399 | tmp_sectors = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5400 | ctrl_info = instance->ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5401 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5402 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5403 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5404 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5405 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5406 | tmp_sectors = min_t(u32, max_sectors_1, max_sectors_2); |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5407 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 5408 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 5409 | instance->passive = ctrl_info->cluster.passive; |
| 5410 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5411 | instance->UnevenSpanSupport = |
| 5412 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5413 | if (instance->UnevenSpanSupport) { |
| 5414 | struct fusion_context *fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5415 | if (MR_ValidateMapInfo(instance)) |
| 5416 | fusion->fast_path_io = 1; |
| 5417 | else |
| 5418 | fusion->fast_path_io = 0; |
| 5419 | |
| 5420 | } |
| 5421 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5422 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5423 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5424 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5425 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5426 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5427 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5428 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5429 | |
| 5430 | if (instance->PlasmaFW111) { |
| 5431 | iovPtr = (struct IOV_111 *) |
| 5432 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5433 | instance->requestorId = iovPtr->requestorId; |
| 5434 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5435 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5436 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5437 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5438 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5439 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5440 | instance->crash_dump_fw_support = |
| 5441 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5442 | instance->crash_dump_drv_support = |
| 5443 | (instance->crash_dump_fw_support && |
| 5444 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5445 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5446 | megasas_set_crash_dump_params(instance, |
| 5447 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5448 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5449 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5450 | if (instance->crash_dump_buf) |
| 5451 | pci_free_consistent(instance->pdev, |
| 5452 | CRASH_DMA_BUF_SIZE, |
| 5453 | instance->crash_dump_buf, |
| 5454 | instance->crash_dump_h); |
| 5455 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5456 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5457 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5458 | |
| 5459 | dev_info(&instance->pdev->dev, |
| 5460 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5461 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5462 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5463 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5464 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5465 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 5466 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5467 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 5468 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5469 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 5470 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5471 | |
| 5472 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5473 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 5474 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5475 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 5476 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5477 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5478 | /* Check for valid throttlequeuedepth module parameter */ |
| 5479 | if (throttlequeuedepth && |
| 5480 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 5481 | instance->throttlequeuedepth = throttlequeuedepth; |
| 5482 | else |
| 5483 | instance->throttlequeuedepth = |
| 5484 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 5485 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 5486 | if (resetwaittime > MEGASAS_RESET_WAIT_TIME) |
| 5487 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 5488 | |
| 5489 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 5490 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5491 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5492 | /* Launch SR-IOV heartbeat timer */ |
| 5493 | if (instance->requestorId) { |
| 5494 | if (!megasas_sriov_start_heartbeat(instance, 1)) |
| 5495 | megasas_start_timer(instance, |
| 5496 | &instance->sriov_heartbeat_timer, |
| 5497 | megasas_sriov_heartbeat_handler, |
| 5498 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 5499 | else |
| 5500 | instance->skip_heartbeat_timer_del = 1; |
| 5501 | } |
| 5502 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5503 | return 0; |
| 5504 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5505 | fail_get_ld_pd_list: |
| 5506 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5507 | fail_get_pd_list: |
| 5508 | instance->instancet->disable_intr(instance); |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5509 | fail_init_adapter: |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5510 | megasas_destroy_irqs(instance); |
| 5511 | fail_setup_irqs: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5512 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5513 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5514 | instance->msix_vectors = 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5515 | fail_ready_state: |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5516 | kfree(instance->ctrl_info); |
| 5517 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5518 | iounmap(instance->reg_set); |
| 5519 | |
| 5520 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5521 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5522 | |
| 5523 | return -EINVAL; |
| 5524 | } |
| 5525 | |
| 5526 | /** |
| 5527 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 5528 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5529 | */ |
| 5530 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 5531 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5532 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5533 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5534 | if (instance->reply_queue) |
| 5535 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5536 | instance->reply_queue, instance->reply_queue_h); |
| 5537 | |
| 5538 | megasas_free_cmds(instance); |
| 5539 | |
| 5540 | iounmap(instance->reg_set); |
| 5541 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5542 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | /** |
| 5546 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 5547 | * @instance: Adapter soft state |
| 5548 | * @eli: FW event log sequence numbers information |
| 5549 | * |
| 5550 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 5551 | * usually find out the latest sequence number of the events, the seq number at |
| 5552 | * the boot etc. They would "read" all the events below the latest seq number |
| 5553 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 5554 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 5555 | * wait for the events to happen. |
| 5556 | */ |
| 5557 | static int |
| 5558 | megasas_get_seq_num(struct megasas_instance *instance, |
| 5559 | struct megasas_evt_log_info *eli) |
| 5560 | { |
| 5561 | struct megasas_cmd *cmd; |
| 5562 | struct megasas_dcmd_frame *dcmd; |
| 5563 | struct megasas_evt_log_info *el_info; |
| 5564 | dma_addr_t el_info_h = 0; |
| 5565 | |
| 5566 | cmd = megasas_get_cmd(instance); |
| 5567 | |
| 5568 | if (!cmd) { |
| 5569 | return -ENOMEM; |
| 5570 | } |
| 5571 | |
| 5572 | dcmd = &cmd->frame->dcmd; |
| 5573 | el_info = pci_alloc_consistent(instance->pdev, |
| 5574 | sizeof(struct megasas_evt_log_info), |
| 5575 | &el_info_h); |
| 5576 | |
| 5577 | if (!el_info) { |
| 5578 | megasas_return_cmd(instance, cmd); |
| 5579 | return -ENOMEM; |
| 5580 | } |
| 5581 | |
| 5582 | memset(el_info, 0, sizeof(*el_info)); |
| 5583 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5584 | |
| 5585 | dcmd->cmd = MFI_CMD_DCMD; |
| 5586 | dcmd->cmd_status = 0x0; |
| 5587 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5588 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5589 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5590 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5591 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 5592 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
| 5593 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(el_info_h); |
| 5594 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5595 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5596 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) == |
| 5597 | DCMD_SUCCESS) { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5598 | /* |
| 5599 | * Copy the data back into callers buffer |
| 5600 | */ |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5601 | eli->newest_seq_num = el_info->newest_seq_num; |
| 5602 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 5603 | eli->clear_seq_num = el_info->clear_seq_num; |
| 5604 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 5605 | eli->boot_seq_num = el_info->boot_seq_num; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5606 | } else |
| 5607 | dev_err(&instance->pdev->dev, "DCMD failed " |
| 5608 | "from %s\n", __func__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5609 | |
| 5610 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 5611 | el_info, el_info_h); |
| 5612 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5613 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5614 | |
| 5615 | return 0; |
| 5616 | } |
| 5617 | |
| 5618 | /** |
| 5619 | * megasas_register_aen - Registers for asynchronous event notification |
| 5620 | * @instance: Adapter soft state |
| 5621 | * @seq_num: The starting sequence number |
| 5622 | * @class_locale: Class of the event |
| 5623 | * |
| 5624 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 5625 | * to be notified if and only if the event is of type @class_locale |
| 5626 | */ |
| 5627 | static int |
| 5628 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 5629 | u32 class_locale_word) |
| 5630 | { |
| 5631 | int ret_val; |
| 5632 | struct megasas_cmd *cmd; |
| 5633 | struct megasas_dcmd_frame *dcmd; |
| 5634 | union megasas_evt_class_locale curr_aen; |
| 5635 | union megasas_evt_class_locale prev_aen; |
| 5636 | |
| 5637 | /* |
| 5638 | * If there an AEN pending already (aen_cmd), check if the |
| 5639 | * class_locale of that pending AEN is inclusive of the new |
| 5640 | * AEN request we currently have. If it is, then we don't have |
| 5641 | * to do anything. In other words, whichever events the current |
| 5642 | * AEN request is subscribing to, have already been subscribed |
| 5643 | * to. |
| 5644 | * |
| 5645 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 5646 | * that command, form a class_locale that is superset of both |
| 5647 | * old and current and re-issue to the FW |
| 5648 | */ |
| 5649 | |
| 5650 | curr_aen.word = class_locale_word; |
| 5651 | |
| 5652 | if (instance->aen_cmd) { |
| 5653 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 5654 | prev_aen.word = |
| 5655 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5656 | |
| 5657 | /* |
| 5658 | * A class whose enum value is smaller is inclusive of all |
| 5659 | * higher values. If a PROGRESS (= -1) was previously |
| 5660 | * registered, then a new registration requests for higher |
| 5661 | * classes need not be sent to FW. They are automatically |
| 5662 | * included. |
| 5663 | * |
| 5664 | * Locale numbers don't have such hierarchy. They are bitmap |
| 5665 | * values |
| 5666 | */ |
| 5667 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5668 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5669 | curr_aen.members.locale)) { |
| 5670 | /* |
| 5671 | * Previously issued event registration includes |
| 5672 | * current request. Nothing to do. |
| 5673 | */ |
| 5674 | return 0; |
| 5675 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5676 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5677 | |
| 5678 | if (prev_aen.members.class < curr_aen.members.class) |
| 5679 | curr_aen.members.class = prev_aen.members.class; |
| 5680 | |
| 5681 | instance->aen_cmd->abort_aen = 1; |
| 5682 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 5683 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5684 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5685 | |
| 5686 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5687 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5688 | "previous AEN command\n"); |
| 5689 | return ret_val; |
| 5690 | } |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | cmd = megasas_get_cmd(instance); |
| 5695 | |
| 5696 | if (!cmd) |
| 5697 | return -ENOMEM; |
| 5698 | |
| 5699 | dcmd = &cmd->frame->dcmd; |
| 5700 | |
| 5701 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 5702 | |
| 5703 | /* |
| 5704 | * Prepare DCMD for aen registration |
| 5705 | */ |
| 5706 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5707 | |
| 5708 | dcmd->cmd = MFI_CMD_DCMD; |
| 5709 | dcmd->cmd_status = 0x0; |
| 5710 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5711 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5712 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5713 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5714 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 5715 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 5716 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5717 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5718 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
| 5719 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->evt_detail_h); |
| 5720 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5721 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5722 | if (instance->aen_cmd != NULL) { |
| 5723 | megasas_return_cmd(instance, cmd); |
| 5724 | return 0; |
| 5725 | } |
| 5726 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5727 | /* |
| 5728 | * Store reference to the cmd used to register for AEN. When an |
| 5729 | * application wants us to register for AEN, we have to abort this |
| 5730 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 5731 | */ |
| 5732 | instance->aen_cmd = cmd; |
| 5733 | |
| 5734 | /* |
| 5735 | * Issue the aen registration frame |
| 5736 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5737 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5738 | |
| 5739 | return 0; |
| 5740 | } |
| 5741 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5742 | /* megasas_get_target_prop - Send DCMD with below details to firmware. |
| 5743 | * |
| 5744 | * This DCMD will fetch few properties of LD/system PD defined |
| 5745 | * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value. |
| 5746 | * |
| 5747 | * DCMD send by drivers whenever new target is added to the OS. |
| 5748 | * |
| 5749 | * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP |
| 5750 | * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD. |
| 5751 | * 0 = system PD, 1 = LD. |
| 5752 | * dcmd.mbox.s[1] - TargetID for LD/system PD. |
| 5753 | * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES. |
| 5754 | * |
| 5755 | * @instance: Adapter soft state |
| 5756 | * @sdev: OS provided scsi device |
| 5757 | * |
| 5758 | * Returns 0 on success non-zero on failure. |
| 5759 | */ |
| 5760 | static int |
| 5761 | megasas_get_target_prop(struct megasas_instance *instance, |
| 5762 | struct scsi_device *sdev) |
| 5763 | { |
| 5764 | int ret; |
| 5765 | struct megasas_cmd *cmd; |
| 5766 | struct megasas_dcmd_frame *dcmd; |
| 5767 | u16 targetId = (sdev->channel % 2) + sdev->id; |
| 5768 | |
| 5769 | cmd = megasas_get_cmd(instance); |
| 5770 | |
| 5771 | if (!cmd) { |
| 5772 | dev_err(&instance->pdev->dev, |
| 5773 | "Failed to get cmd %s\n", __func__); |
| 5774 | return -ENOMEM; |
| 5775 | } |
| 5776 | |
| 5777 | dcmd = &cmd->frame->dcmd; |
| 5778 | |
| 5779 | memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop)); |
| 5780 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5781 | dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev); |
| 5782 | |
| 5783 | dcmd->mbox.s[1] = cpu_to_le16(targetId); |
| 5784 | dcmd->cmd = MFI_CMD_DCMD; |
| 5785 | dcmd->cmd_status = 0xFF; |
| 5786 | dcmd->sge_count = 1; |
| 5787 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 5788 | dcmd->timeout = 0; |
| 5789 | dcmd->pad_0 = 0; |
| 5790 | dcmd->data_xfer_len = |
| 5791 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 5792 | dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP); |
| 5793 | dcmd->sgl.sge32[0].phys_addr = |
| 5794 | cpu_to_le32(instance->tgt_prop_h); |
| 5795 | dcmd->sgl.sge32[0].length = |
| 5796 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 5797 | |
| 5798 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 5799 | ret = megasas_issue_blocked_cmd(instance, |
| 5800 | cmd, MFI_IO_TIMEOUT_SECS); |
| 5801 | else |
| 5802 | ret = megasas_issue_polled(instance, cmd); |
| 5803 | |
| 5804 | switch (ret) { |
| 5805 | case DCMD_TIMEOUT: |
| 5806 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5807 | case INITIATE_OCR: |
| 5808 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5809 | megasas_reset_fusion(instance->host, |
| 5810 | MFI_IO_TIMEOUT_OCR); |
| 5811 | break; |
| 5812 | case KILL_ADAPTER: |
| 5813 | megaraid_sas_kill_hba(instance); |
| 5814 | break; |
| 5815 | case IGNORE_TIMEOUT: |
| 5816 | dev_info(&instance->pdev->dev, |
| 5817 | "Ignore DCMD timeout: %s %d\n", |
| 5818 | __func__, __LINE__); |
| 5819 | break; |
| 5820 | } |
| 5821 | break; |
| 5822 | |
| 5823 | default: |
| 5824 | megasas_return_cmd(instance, cmd); |
| 5825 | } |
| 5826 | if (ret != DCMD_SUCCESS) |
| 5827 | dev_err(&instance->pdev->dev, |
| 5828 | "return from %s %d return value %d\n", |
| 5829 | __func__, __LINE__, ret); |
| 5830 | |
| 5831 | return ret; |
| 5832 | } |
| 5833 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5834 | /** |
| 5835 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 5836 | * @instance: Adapter soft state |
| 5837 | */ |
| 5838 | static int megasas_start_aen(struct megasas_instance *instance) |
| 5839 | { |
| 5840 | struct megasas_evt_log_info eli; |
| 5841 | union megasas_evt_class_locale class_locale; |
| 5842 | |
| 5843 | /* |
| 5844 | * Get the latest sequence number from FW |
| 5845 | */ |
| 5846 | memset(&eli, 0, sizeof(eli)); |
| 5847 | |
| 5848 | if (megasas_get_seq_num(instance, &eli)) |
| 5849 | return -1; |
| 5850 | |
| 5851 | /* |
| 5852 | * Register AEN with FW for latest sequence number plus 1 |
| 5853 | */ |
| 5854 | class_locale.members.reserved = 0; |
| 5855 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 5856 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 5857 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5858 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5859 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5860 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | /** |
| 5864 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 5865 | * @instance: Adapter soft state |
| 5866 | */ |
| 5867 | static int megasas_io_attach(struct megasas_instance *instance) |
| 5868 | { |
| 5869 | struct Scsi_Host *host = instance->host; |
| 5870 | |
| 5871 | /* |
| 5872 | * Export parameters required by SCSI mid-layer |
| 5873 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5874 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5875 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5876 | host->this_id = instance->init_id; |
| 5877 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 5878 | |
| 5879 | if (instance->fw_support_ieee) |
| 5880 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 5881 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5882 | /* |
| 5883 | * Check if the module parameter value for max_sectors can be used |
| 5884 | */ |
| 5885 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 5886 | instance->max_sectors_per_req = max_sectors; |
| 5887 | else { |
| 5888 | if (max_sectors) { |
| 5889 | if (((instance->pdev->device == |
| 5890 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 5891 | (instance->pdev->device == |
| 5892 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 5893 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 5894 | instance->max_sectors_per_req = max_sectors; |
| 5895 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5896 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5897 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 5898 | instance->max_sectors_per_req); |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5903 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5904 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5905 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 5906 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5907 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 5908 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5909 | |
| 5910 | /* |
| 5911 | * Notify the mid-layer about the new controller |
| 5912 | */ |
| 5913 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5914 | dev_err(&instance->pdev->dev, |
| 5915 | "Failed to add host from %s %d\n", |
| 5916 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5917 | return -ENODEV; |
| 5918 | } |
| 5919 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5920 | return 0; |
| 5921 | } |
| 5922 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5923 | static int |
| 5924 | megasas_set_dma_mask(struct pci_dev *pdev) |
| 5925 | { |
| 5926 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5927 | * All our controllers are capable of performing 64-bit DMA |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5928 | */ |
| 5929 | if (IS_DMA64) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5930 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5931 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5932 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5933 | goto fail_set_dma_mask; |
| 5934 | } |
| 5935 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5936 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5937 | goto fail_set_dma_mask; |
| 5938 | } |
Sumit.Saxena@lsi.com | 46de63e2 | 2014-02-12 23:38:44 +0530 | [diff] [blame] | 5939 | /* |
| 5940 | * Ensure that all data structures are allocated in 32-bit |
| 5941 | * memory. |
| 5942 | */ |
| 5943 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
| 5944 | /* Try 32bit DMA mask and 32 bit Consistent dma mask */ |
| 5945 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 5946 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 5947 | dev_info(&pdev->dev, "set 32bit DMA mask" |
| 5948 | "and 32 bit consistent mask\n"); |
| 5949 | else |
| 5950 | goto fail_set_dma_mask; |
| 5951 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5952 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5953 | return 0; |
| 5954 | |
| 5955 | fail_set_dma_mask: |
| 5956 | return 1; |
| 5957 | } |
| 5958 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5959 | /** |
| 5960 | * megasas_probe_one - PCI hotplug entry point |
| 5961 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 5962 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5963 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5964 | static int megasas_probe_one(struct pci_dev *pdev, |
| 5965 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5966 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5967 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5968 | struct Scsi_Host *host; |
| 5969 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5970 | u16 control = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5971 | struct fusion_context *fusion = NULL; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5972 | |
| 5973 | /* Reset MSI-X in the kdump kernel */ |
| 5974 | if (reset_devices) { |
| 5975 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 5976 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5977 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5978 | &control); |
| 5979 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 5980 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 5981 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5982 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5983 | control & |
| 5984 | ~PCI_MSIX_FLAGS_ENABLE); |
| 5985 | } |
| 5986 | } |
| 5987 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5988 | |
| 5989 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5990 | * PCI prepping: enable device set bus mastering and dma mask |
| 5991 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 5992 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5993 | |
| 5994 | if (rval) { |
| 5995 | return rval; |
| 5996 | } |
| 5997 | |
| 5998 | pci_set_master(pdev); |
| 5999 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6000 | if (megasas_set_dma_mask(pdev)) |
| 6001 | goto fail_set_dma_mask; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6002 | |
| 6003 | host = scsi_host_alloc(&megasas_template, |
| 6004 | sizeof(struct megasas_instance)); |
| 6005 | |
| 6006 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6007 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6008 | goto fail_alloc_instance; |
| 6009 | } |
| 6010 | |
| 6011 | instance = (struct megasas_instance *)host->hostdata; |
| 6012 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6013 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6014 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6015 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6016 | switch (instance->pdev->device) { |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 6017 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 6018 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 6019 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 6020 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 6021 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 6022 | instance->is_ventura = true; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6023 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6024 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 6025 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 6026 | case PCI_DEVICE_ID_LSI_FURY: |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 6027 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 6028 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 6029 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 6030 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6031 | { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6032 | instance->ctrl_context_pages = |
| 6033 | get_order(sizeof(struct fusion_context)); |
| 6034 | instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL, |
| 6035 | instance->ctrl_context_pages); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6036 | if (!instance->ctrl_context) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6037 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6038 | "memory for Fusion context info\n"); |
| 6039 | goto fail_alloc_dma_buf; |
| 6040 | } |
| 6041 | fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 6042 | memset(fusion, 0, |
| 6043 | ((1 << PAGE_SHIFT) << instance->ctrl_context_pages)); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6044 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
| 6045 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA)) |
| 6046 | fusion->adapter_type = THUNDERBOLT_SERIES; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 6047 | else if (instance->is_ventura) |
| 6048 | fusion->adapter_type = VENTURA_SERIES; |
| 6049 | else |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6050 | fusion->adapter_type = INVADER_SERIES; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6051 | } |
| 6052 | break; |
| 6053 | default: /* For all other supported controllers */ |
| 6054 | |
| 6055 | instance->producer = |
| 6056 | pci_alloc_consistent(pdev, sizeof(u32), |
| 6057 | &instance->producer_h); |
| 6058 | instance->consumer = |
| 6059 | pci_alloc_consistent(pdev, sizeof(u32), |
| 6060 | &instance->consumer_h); |
| 6061 | |
| 6062 | if (!instance->producer || !instance->consumer) { |
Colin Ian King | 4086eae5 | 2016-09-12 13:42:12 +0100 | [diff] [blame] | 6063 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6064 | "memory for producer, consumer\n"); |
| 6065 | goto fail_alloc_dma_buf; |
| 6066 | } |
| 6067 | |
| 6068 | *instance->producer = 0; |
| 6069 | *instance->consumer = 0; |
| 6070 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6071 | } |
| 6072 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6073 | /* Crash dump feature related initialisation*/ |
| 6074 | instance->drv_buf_index = 0; |
| 6075 | instance->drv_buf_alloc = 0; |
| 6076 | instance->crash_dump_fw_support = 0; |
| 6077 | instance->crash_dump_app_support = 0; |
| 6078 | instance->fw_crash_state = UNAVAILABLE; |
| 6079 | spin_lock_init(&instance->crashdump_lock); |
| 6080 | instance->crash_dump_buf = NULL; |
| 6081 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6082 | megasas_poll_wait_aen = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6083 | instance->flag_ieee = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6084 | instance->ev = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6085 | instance->issuepend_done = 1; |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6086 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 6087 | instance->is_imr = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6088 | |
| 6089 | instance->evt_detail = pci_alloc_consistent(pdev, |
| 6090 | sizeof(struct |
| 6091 | megasas_evt_detail), |
| 6092 | &instance->evt_detail_h); |
| 6093 | |
| 6094 | if (!instance->evt_detail) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6095 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate memory for " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6096 | "event detail structure\n"); |
| 6097 | goto fail_alloc_dma_buf; |
| 6098 | } |
| 6099 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6100 | if (!reset_devices) { |
| 6101 | instance->system_info_buf = pci_zalloc_consistent(pdev, |
| 6102 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6103 | &instance->system_info_h); |
| 6104 | if (!instance->system_info_buf) |
| 6105 | dev_info(&instance->pdev->dev, "Can't allocate system info buffer\n"); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6106 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6107 | instance->pd_info = pci_alloc_consistent(pdev, |
| 6108 | sizeof(struct MR_PD_INFO), &instance->pd_info_h); |
| 6109 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6110 | instance->pd_info = pci_alloc_consistent(pdev, |
| 6111 | sizeof(struct MR_PD_INFO), &instance->pd_info_h); |
| 6112 | instance->tgt_prop = pci_alloc_consistent(pdev, |
| 6113 | sizeof(struct MR_TARGET_PROPERTIES), &instance->tgt_prop_h); |
| 6114 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6115 | if (!instance->pd_info) |
| 6116 | dev_err(&instance->pdev->dev, "Failed to alloc mem for pd_info\n"); |
| 6117 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6118 | if (!instance->tgt_prop) |
| 6119 | dev_err(&instance->pdev->dev, "Failed to alloc mem for tgt_prop\n"); |
| 6120 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6121 | instance->crash_dump_buf = pci_alloc_consistent(pdev, |
| 6122 | CRASH_DMA_BUF_SIZE, |
| 6123 | &instance->crash_dump_h); |
| 6124 | if (!instance->crash_dump_buf) |
| 6125 | dev_err(&pdev->dev, "Can't allocate Firmware " |
| 6126 | "crash dump DMA buffer\n"); |
| 6127 | } |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6128 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6129 | /* |
| 6130 | * Initialize locks and queues |
| 6131 | */ |
| 6132 | INIT_LIST_HEAD(&instance->cmd_pool); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6133 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6134 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 6135 | atomic_set(&instance->fw_outstanding,0); |
| 6136 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6137 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 6138 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 6139 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 6140 | spin_lock_init(&instance->mfi_pool_lock); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6141 | spin_lock_init(&instance->hba_lock); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6142 | spin_lock_init(&instance->stream_lock); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 6143 | spin_lock_init(&instance->completion_lock); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6144 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6145 | mutex_init(&instance->reset_mutex); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6146 | mutex_init(&instance->hba_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6147 | |
| 6148 | /* |
| 6149 | * Initialize PCI related and misc parameters |
| 6150 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6151 | instance->host = host; |
| 6152 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 6153 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6154 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6155 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6156 | |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 6157 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6158 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6159 | instance->flag_ieee = 1; |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 6160 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6161 | megasas_dbg_lvl = 0; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 6162 | instance->flag = 0; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6163 | instance->unload = 1; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 6164 | instance->last_time = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6165 | instance->disableOnlineCtrlReset = 1; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 6166 | instance->UnevenSpanSupport = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6167 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6168 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6169 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6170 | INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq); |
| 6171 | } else |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6172 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6173 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6174 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 6175 | * Initialize MFI Firmware |
| 6176 | */ |
| 6177 | if (megasas_init_fw(instance)) |
| 6178 | goto fail_init_mfi; |
| 6179 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6180 | if (instance->requestorId) { |
| 6181 | if (instance->PlasmaFW111) { |
| 6182 | instance->vf_affiliation_111 = |
| 6183 | pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6184 | &instance->vf_affiliation_111_h); |
| 6185 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6186 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6187 | "memory for VF affiliation buffer\n"); |
| 6188 | } else { |
| 6189 | instance->vf_affiliation = |
| 6190 | pci_alloc_consistent(pdev, |
| 6191 | (MAX_LOGICAL_DRIVES + 1) * |
| 6192 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6193 | &instance->vf_affiliation_h); |
| 6194 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6195 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6196 | "memory for VF affiliation buffer\n"); |
| 6197 | } |
| 6198 | } |
| 6199 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6200 | /* |
| 6201 | * Store instance in PCI softstate |
| 6202 | */ |
| 6203 | pci_set_drvdata(pdev, instance); |
| 6204 | |
| 6205 | /* |
| 6206 | * Add this controller to megasas_mgmt_info structure so that it |
| 6207 | * can be exported to management applications |
| 6208 | */ |
| 6209 | megasas_mgmt_info.count++; |
| 6210 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 6211 | megasas_mgmt_info.max_index++; |
| 6212 | |
| 6213 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6214 | * Register with SCSI mid-layer |
| 6215 | */ |
| 6216 | if (megasas_io_attach(instance)) |
| 6217 | goto fail_io_attach; |
| 6218 | |
| 6219 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6220 | /* |
| 6221 | * Trigger SCSI to scan our drives |
| 6222 | */ |
| 6223 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6224 | |
| 6225 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6226 | * Initiate AEN (Asynchronous Event Notification) |
| 6227 | */ |
| 6228 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6229 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6230 | goto fail_start_aen; |
| 6231 | } |
| 6232 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 6233 | /* Get current SR-IOV LD/VF affiliation */ |
| 6234 | if (instance->requestorId) |
| 6235 | megasas_get_ld_vf_affiliation(instance, 1); |
| 6236 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6237 | return 0; |
| 6238 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6239 | fail_start_aen: |
| 6240 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6241 | megasas_mgmt_info.count--; |
| 6242 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
| 6243 | megasas_mgmt_info.max_index--; |
| 6244 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6245 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6246 | megasas_destroy_irqs(instance); |
| 6247 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6248 | if (instance->ctrl_context) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6249 | megasas_release_fusion(instance); |
| 6250 | else |
| 6251 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6252 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6253 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6254 | fail_init_mfi: |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6255 | fail_alloc_dma_buf: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6256 | if (instance->evt_detail) |
| 6257 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6258 | instance->evt_detail, |
| 6259 | instance->evt_detail_h); |
| 6260 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6261 | if (instance->pd_info) |
| 6262 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6263 | instance->pd_info, |
| 6264 | instance->pd_info_h); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6265 | if (instance->tgt_prop) |
| 6266 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6267 | instance->tgt_prop, |
| 6268 | instance->tgt_prop_h); |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6269 | if (instance->producer) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6270 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6271 | instance->producer_h); |
| 6272 | if (instance->consumer) |
| 6273 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6274 | instance->consumer_h); |
| 6275 | scsi_host_put(host); |
| 6276 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6277 | fail_alloc_instance: |
| 6278 | fail_set_dma_mask: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6279 | pci_disable_device(pdev); |
| 6280 | |
| 6281 | return -ENODEV; |
| 6282 | } |
| 6283 | |
| 6284 | /** |
| 6285 | * megasas_flush_cache - Requests FW to flush all its caches |
| 6286 | * @instance: Adapter soft state |
| 6287 | */ |
| 6288 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 6289 | { |
| 6290 | struct megasas_cmd *cmd; |
| 6291 | struct megasas_dcmd_frame *dcmd; |
| 6292 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6293 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6294 | return; |
| 6295 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6296 | cmd = megasas_get_cmd(instance); |
| 6297 | |
| 6298 | if (!cmd) |
| 6299 | return; |
| 6300 | |
| 6301 | dcmd = &cmd->frame->dcmd; |
| 6302 | |
| 6303 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6304 | |
| 6305 | dcmd->cmd = MFI_CMD_DCMD; |
| 6306 | dcmd->cmd_status = 0x0; |
| 6307 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6308 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6309 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6310 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6311 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6312 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6313 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 6314 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6315 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6316 | != DCMD_SUCCESS) { |
| 6317 | dev_err(&instance->pdev->dev, |
| 6318 | "return from %s %d\n", __func__, __LINE__); |
| 6319 | return; |
| 6320 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6321 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6322 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6323 | } |
| 6324 | |
| 6325 | /** |
| 6326 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 6327 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6328 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6329 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6330 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 6331 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6332 | { |
| 6333 | struct megasas_cmd *cmd; |
| 6334 | struct megasas_dcmd_frame *dcmd; |
| 6335 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6336 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6337 | return; |
| 6338 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6339 | cmd = megasas_get_cmd(instance); |
| 6340 | |
| 6341 | if (!cmd) |
| 6342 | return; |
| 6343 | |
| 6344 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6345 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6346 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6347 | if (instance->map_update_cmd) |
| 6348 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6349 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6350 | if (instance->jbod_seq_cmd) |
| 6351 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6352 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6353 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6354 | dcmd = &cmd->frame->dcmd; |
| 6355 | |
| 6356 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6357 | |
| 6358 | dcmd->cmd = MFI_CMD_DCMD; |
| 6359 | dcmd->cmd_status = 0x0; |
| 6360 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6361 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6362 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6363 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6364 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6365 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6366 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6367 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6368 | != DCMD_SUCCESS) { |
| 6369 | dev_err(&instance->pdev->dev, |
| 6370 | "return from %s %d\n", __func__, __LINE__); |
| 6371 | return; |
| 6372 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6373 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6374 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6375 | } |
| 6376 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6377 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6378 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6379 | * megasas_suspend - driver suspend entry point |
| 6380 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6381 | * @state: PCI power state to suspend routine |
| 6382 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6383 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6384 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6385 | { |
| 6386 | struct Scsi_Host *host; |
| 6387 | struct megasas_instance *instance; |
| 6388 | |
| 6389 | instance = pci_get_drvdata(pdev); |
| 6390 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6391 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6392 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6393 | /* Shutdown SR-IOV heartbeat timer */ |
| 6394 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6395 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6396 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6397 | megasas_flush_cache(instance); |
| 6398 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6399 | |
| 6400 | /* cancel the delayed work if this work still in queue */ |
| 6401 | if (instance->ev != NULL) { |
| 6402 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6403 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6404 | instance->ev = NULL; |
| 6405 | } |
| 6406 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6407 | tasklet_kill(&instance->isr_tasklet); |
| 6408 | |
| 6409 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6410 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6411 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6412 | megasas_destroy_irqs(instance); |
| 6413 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6414 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6415 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6416 | |
| 6417 | pci_save_state(pdev); |
| 6418 | pci_disable_device(pdev); |
| 6419 | |
| 6420 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 6421 | |
| 6422 | return 0; |
| 6423 | } |
| 6424 | |
| 6425 | /** |
| 6426 | * megasas_resume- driver resume entry point |
| 6427 | * @pdev: PCI device structure |
| 6428 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6429 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6430 | megasas_resume(struct pci_dev *pdev) |
| 6431 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6432 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6433 | struct Scsi_Host *host; |
| 6434 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6435 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6436 | |
| 6437 | instance = pci_get_drvdata(pdev); |
| 6438 | host = instance->host; |
| 6439 | pci_set_power_state(pdev, PCI_D0); |
| 6440 | pci_enable_wake(pdev, PCI_D0, 0); |
| 6441 | pci_restore_state(pdev); |
| 6442 | |
| 6443 | /* |
| 6444 | * PCI prepping: enable device set bus mastering and dma mask |
| 6445 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6446 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6447 | |
| 6448 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6449 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6450 | return rval; |
| 6451 | } |
| 6452 | |
| 6453 | pci_set_master(pdev); |
| 6454 | |
| 6455 | if (megasas_set_dma_mask(pdev)) |
| 6456 | goto fail_set_dma_mask; |
| 6457 | |
| 6458 | /* |
| 6459 | * Initialize MFI Firmware |
| 6460 | */ |
| 6461 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6462 | atomic_set(&instance->fw_outstanding, 0); |
| 6463 | |
| 6464 | /* |
| 6465 | * We expect the FW state to be READY |
| 6466 | */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 6467 | if (megasas_transition_to_ready(instance, 0)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6468 | goto fail_ready_state; |
| 6469 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6470 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6471 | if (instance->msix_vectors) { |
| 6472 | irq_flags = PCI_IRQ_MSIX; |
| 6473 | if (smp_affinity_enable) |
| 6474 | irq_flags |= PCI_IRQ_AFFINITY; |
| 6475 | } |
| 6476 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 6477 | instance->msix_vectors ? |
| 6478 | instance->msix_vectors : 1, irq_flags); |
| 6479 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6480 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6481 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6482 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6483 | megasas_reset_reply_desc(instance); |
| 6484 | if (megasas_ioc_init_fusion(instance)) { |
| 6485 | megasas_free_cmds(instance); |
| 6486 | megasas_free_cmds_fusion(instance); |
| 6487 | goto fail_init_mfi; |
| 6488 | } |
| 6489 | if (!megasas_get_map_info(instance)) |
| 6490 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6491 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6492 | *instance->producer = 0; |
| 6493 | *instance->consumer = 0; |
| 6494 | if (megasas_issue_init_mfi(instance)) |
| 6495 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6496 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6497 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6498 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 6499 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6500 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6501 | if (instance->msix_vectors ? |
| 6502 | megasas_setup_irqs_msix(instance, 0) : |
| 6503 | megasas_setup_irqs_ioapic(instance)) |
| 6504 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6505 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6506 | /* Re-launch SR-IOV heartbeat timer */ |
| 6507 | if (instance->requestorId) { |
| 6508 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 6509 | megasas_start_timer(instance, |
| 6510 | &instance->sriov_heartbeat_timer, |
| 6511 | megasas_sriov_heartbeat_handler, |
| 6512 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6513 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6514 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6515 | goto fail_init_mfi; |
| 6516 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6517 | } |
| 6518 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6519 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6520 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6521 | instance->unload = 0; |
| 6522 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6523 | /* |
| 6524 | * Initiate AEN (Asynchronous Event Notification) |
| 6525 | */ |
| 6526 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6527 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6528 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6529 | return 0; |
| 6530 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6531 | fail_init_mfi: |
| 6532 | if (instance->evt_detail) |
| 6533 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6534 | instance->evt_detail, |
| 6535 | instance->evt_detail_h); |
| 6536 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6537 | if (instance->pd_info) |
| 6538 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6539 | instance->pd_info, |
| 6540 | instance->pd_info_h); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6541 | if (instance->tgt_prop) |
| 6542 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6543 | instance->tgt_prop, |
| 6544 | instance->tgt_prop_h); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6545 | if (instance->producer) |
| 6546 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6547 | instance->producer_h); |
| 6548 | if (instance->consumer) |
| 6549 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6550 | instance->consumer_h); |
| 6551 | scsi_host_put(host); |
| 6552 | |
| 6553 | fail_set_dma_mask: |
| 6554 | fail_ready_state: |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6555 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6556 | |
| 6557 | pci_disable_device(pdev); |
| 6558 | |
| 6559 | return -ENODEV; |
| 6560 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6561 | #else |
| 6562 | #define megasas_suspend NULL |
| 6563 | #define megasas_resume NULL |
| 6564 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6565 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6566 | static inline int |
| 6567 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 6568 | { |
| 6569 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 6570 | int i; |
| 6571 | |
| 6572 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
| 6573 | return 1; |
| 6574 | |
| 6575 | for (i = 0; i < wait_time; i++) { |
| 6576 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
| 6577 | break; |
| 6578 | |
| 6579 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 6580 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 6581 | |
| 6582 | msleep(1000); |
| 6583 | } |
| 6584 | |
| 6585 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
| 6586 | dev_info(&instance->pdev->dev, "%s timed out while waiting for HBA to recover.\n", |
| 6587 | __func__); |
| 6588 | return 1; |
| 6589 | } |
| 6590 | |
| 6591 | return 0; |
| 6592 | } |
| 6593 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6594 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6595 | * megasas_detach_one - PCI hot"un"plug entry point |
| 6596 | * @pdev: PCI device structure |
| 6597 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6598 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6599 | { |
| 6600 | int i; |
| 6601 | struct Scsi_Host *host; |
| 6602 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6603 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6604 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6605 | |
| 6606 | instance = pci_get_drvdata(pdev); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6607 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6608 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6609 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6610 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6611 | /* Shutdown SR-IOV heartbeat timer */ |
| 6612 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6613 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6614 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6615 | if (instance->fw_crash_state != UNAVAILABLE) |
| 6616 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6617 | scsi_remove_host(instance->host); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6618 | |
| 6619 | if (megasas_wait_for_adapter_operational(instance)) |
| 6620 | goto skip_firing_dcmds; |
| 6621 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6622 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6623 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6624 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6625 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6626 | /* cancel the delayed work if this work still in queue*/ |
| 6627 | if (instance->ev != NULL) { |
| 6628 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6629 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6630 | instance->ev = NULL; |
| 6631 | } |
| 6632 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6633 | /* cancel all wait events */ |
| 6634 | wake_up_all(&instance->int_cmd_wait_q); |
| 6635 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 6636 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6637 | |
| 6638 | /* |
| 6639 | * Take the instance off the instance array. Note that we will not |
| 6640 | * decrement the max_index. We let this array be sparse array |
| 6641 | */ |
| 6642 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6643 | if (megasas_mgmt_info.instance[i] == instance) { |
| 6644 | megasas_mgmt_info.count--; |
| 6645 | megasas_mgmt_info.instance[i] = NULL; |
| 6646 | |
| 6647 | break; |
| 6648 | } |
| 6649 | } |
| 6650 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6651 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6652 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6653 | megasas_destroy_irqs(instance); |
| 6654 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6655 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6656 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6657 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6658 | if (instance->is_ventura) { |
| 6659 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 6660 | kfree(fusion->stream_detect_by_ld[i]); |
| 6661 | kfree(fusion->stream_detect_by_ld); |
| 6662 | fusion->stream_detect_by_ld = NULL; |
| 6663 | } |
| 6664 | |
| 6665 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6666 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6667 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6668 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 6669 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 6670 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6671 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6672 | if (fusion->ld_map[i]) |
| 6673 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6674 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6675 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6676 | fusion->ld_map_phys[i]); |
| 6677 | if (fusion->ld_drv_map[i]) |
| 6678 | free_pages((ulong)fusion->ld_drv_map[i], |
| 6679 | fusion->drv_map_pages); |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 6680 | if (fusion->pd_seq_sync[i]) |
| 6681 | dma_free_coherent(&instance->pdev->dev, |
| 6682 | pd_seq_map_sz, |
| 6683 | fusion->pd_seq_sync[i], |
| 6684 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6685 | } |
| 6686 | free_pages((ulong)instance->ctrl_context, |
| 6687 | instance->ctrl_context_pages); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6688 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6689 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6690 | pci_free_consistent(pdev, sizeof(u32), |
| 6691 | instance->producer, |
| 6692 | instance->producer_h); |
| 6693 | pci_free_consistent(pdev, sizeof(u32), |
| 6694 | instance->consumer, |
| 6695 | instance->consumer_h); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6696 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6697 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6698 | kfree(instance->ctrl_info); |
| 6699 | |
Sumit.Saxena@lsi.com | 105900d | 2013-05-22 12:30:54 +0530 | [diff] [blame] | 6700 | if (instance->evt_detail) |
| 6701 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6702 | instance->evt_detail, instance->evt_detail_h); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6703 | if (instance->pd_info) |
| 6704 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6705 | instance->pd_info, |
| 6706 | instance->pd_info_h); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6707 | if (instance->tgt_prop) |
| 6708 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6709 | instance->tgt_prop, |
| 6710 | instance->tgt_prop_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6711 | if (instance->vf_affiliation) |
| 6712 | pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) * |
| 6713 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6714 | instance->vf_affiliation, |
| 6715 | instance->vf_affiliation_h); |
| 6716 | |
| 6717 | if (instance->vf_affiliation_111) |
| 6718 | pci_free_consistent(pdev, |
| 6719 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6720 | instance->vf_affiliation_111, |
| 6721 | instance->vf_affiliation_111_h); |
| 6722 | |
| 6723 | if (instance->hb_host_mem) |
| 6724 | pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 6725 | instance->hb_host_mem, |
| 6726 | instance->hb_host_mem_h); |
| 6727 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6728 | if (instance->crash_dump_buf) |
| 6729 | pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE, |
| 6730 | instance->crash_dump_buf, instance->crash_dump_h); |
| 6731 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6732 | if (instance->system_info_buf) |
| 6733 | pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6734 | instance->system_info_buf, instance->system_info_h); |
| 6735 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6736 | scsi_host_put(host); |
| 6737 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6738 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | /** |
| 6742 | * megasas_shutdown - Shutdown entry point |
| 6743 | * @device: Generic device structure |
| 6744 | */ |
| 6745 | static void megasas_shutdown(struct pci_dev *pdev) |
| 6746 | { |
| 6747 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6748 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6749 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6750 | |
| 6751 | if (megasas_wait_for_adapter_operational(instance)) |
| 6752 | goto skip_firing_dcmds; |
| 6753 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6754 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 6755 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6756 | |
| 6757 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6758 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6759 | megasas_destroy_irqs(instance); |
| 6760 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6761 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6762 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * megasas_mgmt_open - char node "open" entry point |
| 6767 | */ |
| 6768 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 6769 | { |
| 6770 | /* |
| 6771 | * Allow only those users with admin rights |
| 6772 | */ |
| 6773 | if (!capable(CAP_SYS_ADMIN)) |
| 6774 | return -EACCES; |
| 6775 | |
| 6776 | return 0; |
| 6777 | } |
| 6778 | |
| 6779 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6780 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 6781 | * |
| 6782 | * This function adds the calling process to a driver global queue. When an |
| 6783 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 6784 | */ |
| 6785 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 6786 | { |
| 6787 | int rc; |
| 6788 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6789 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6790 | |
| 6791 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 6792 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6793 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6794 | |
| 6795 | if (rc >= 0) { |
| 6796 | /* For sanity check when we get ioctl */ |
| 6797 | filep->private_data = filep; |
| 6798 | return 0; |
| 6799 | } |
| 6800 | |
| 6801 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 6802 | |
| 6803 | return rc; |
| 6804 | } |
| 6805 | |
| 6806 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6807 | * megasas_mgmt_poll - char node "poll" entry point |
| 6808 | * */ |
| 6809 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 6810 | { |
| 6811 | unsigned int mask; |
| 6812 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6813 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6814 | poll_wait(file, &megasas_poll_wait, wait); |
| 6815 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 6816 | if (megasas_poll_wait_aen) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6817 | mask = (POLLIN | POLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6818 | else |
| 6819 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6820 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6821 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 6822 | return mask; |
| 6823 | } |
| 6824 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6825 | /* |
| 6826 | * megasas_set_crash_dump_params_ioctl: |
| 6827 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 6828 | * @cmd: MFI command frame |
| 6829 | */ |
| 6830 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6831 | static int megasas_set_crash_dump_params_ioctl(struct megasas_cmd *cmd) |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6832 | { |
| 6833 | struct megasas_instance *local_instance; |
| 6834 | int i, error = 0; |
| 6835 | int crash_support; |
| 6836 | |
| 6837 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 6838 | |
| 6839 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6840 | local_instance = megasas_mgmt_info.instance[i]; |
| 6841 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6842 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6843 | MEGASAS_HBA_OPERATIONAL) && |
| 6844 | !megasas_set_crash_dump_params(local_instance, |
| 6845 | crash_support)) { |
| 6846 | local_instance->crash_dump_app_support = |
| 6847 | crash_support; |
| 6848 | dev_info(&local_instance->pdev->dev, |
| 6849 | "Application firmware crash " |
| 6850 | "dump mode set success\n"); |
| 6851 | error = 0; |
| 6852 | } else { |
| 6853 | dev_info(&local_instance->pdev->dev, |
| 6854 | "Application firmware crash " |
| 6855 | "dump mode set failed\n"); |
| 6856 | error = -1; |
| 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | return error; |
| 6861 | } |
| 6862 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6863 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6864 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 6865 | * @instance: Adapter soft state |
| 6866 | * @argp: User's ioctl packet |
| 6867 | */ |
| 6868 | static int |
| 6869 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 6870 | struct megasas_iocpacket __user * user_ioc, |
| 6871 | struct megasas_iocpacket *ioc) |
| 6872 | { |
| 6873 | struct megasas_sge32 *kern_sge32; |
| 6874 | struct megasas_cmd *cmd; |
| 6875 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 6876 | dma_addr_t buf_handle = 0; |
| 6877 | int error = 0, i; |
| 6878 | void *sense = NULL; |
| 6879 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6880 | unsigned long *sense_ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6881 | |
| 6882 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 6883 | |
| 6884 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6885 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SGE count [%d] > max limit [%d]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6886 | ioc->sge_count, MAX_IOCTL_SGE); |
| 6887 | return -EINVAL; |
| 6888 | } |
| 6889 | |
| 6890 | cmd = megasas_get_cmd(instance); |
| 6891 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6892 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get a cmd packet\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6893 | return -ENOMEM; |
| 6894 | } |
| 6895 | |
| 6896 | /* |
| 6897 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 6898 | * frames into our cmd's frames. cmd->frame's context will get |
| 6899 | * overwritten when we copy from user's frames. So set that value |
| 6900 | * alone separately |
| 6901 | */ |
| 6902 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6903 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6904 | cmd->frame->hdr.pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6905 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE | |
| 6906 | MFI_FRAME_SGL64 | |
| 6907 | MFI_FRAME_SENSE64)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6908 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6909 | if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
| 6910 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 6911 | megasas_return_cmd(instance, cmd); |
| 6912 | return error; |
| 6913 | } |
| 6914 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6915 | /* |
| 6916 | * The management interface between applications and the fw uses |
| 6917 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 6918 | * etc are accomplishes through different kinds of MFI frames. The |
| 6919 | * driver needs to care only about substituting user buffers with |
| 6920 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 6921 | * struct iocpacket itself. |
| 6922 | */ |
| 6923 | kern_sge32 = (struct megasas_sge32 *) |
| 6924 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 6925 | |
| 6926 | /* |
| 6927 | * For each user buffer, create a mirror buffer and copy in |
| 6928 | */ |
| 6929 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 6930 | if (!ioc->sgl[i].iov_len) |
| 6931 | continue; |
| 6932 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6933 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6934 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6935 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6936 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6937 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 6938 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6939 | error = -ENOMEM; |
| 6940 | goto out; |
| 6941 | } |
| 6942 | |
| 6943 | /* |
| 6944 | * We don't change the dma_coherent_mask, so |
| 6945 | * pci_alloc_consistent only returns 32bit addresses |
| 6946 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6947 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 6948 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6949 | |
| 6950 | /* |
| 6951 | * We created a kernel buffer corresponding to the |
| 6952 | * user buffer. Now copy in from the user buffer |
| 6953 | */ |
| 6954 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 6955 | (u32) (ioc->sgl[i].iov_len))) { |
| 6956 | error = -EFAULT; |
| 6957 | goto out; |
| 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6962 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 6963 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6964 | if (!sense) { |
| 6965 | error = -ENOMEM; |
| 6966 | goto out; |
| 6967 | } |
| 6968 | |
| 6969 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6970 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6971 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | /* |
| 6975 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 6976 | * cmd to the SCSI mid-layer |
| 6977 | */ |
| 6978 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6979 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 6980 | cmd->sync_cmd = 0; |
| 6981 | dev_err(&instance->pdev->dev, |
| 6982 | "return -EBUSY from %s %d opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 6983 | __func__, __LINE__, cmd->frame->dcmd.opcode, |
| 6984 | cmd->cmd_status_drv); |
| 6985 | return -EBUSY; |
| 6986 | } |
| 6987 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6988 | cmd->sync_cmd = 0; |
| 6989 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6990 | if (instance->unload == 1) { |
| 6991 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 6992 | "don't submit data to application\n"); |
| 6993 | goto out; |
| 6994 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6995 | /* |
| 6996 | * copy out the kernel buffers to user buffers |
| 6997 | */ |
| 6998 | for (i = 0; i < ioc->sge_count; i++) { |
| 6999 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 7000 | ioc->sgl[i].iov_len)) { |
| 7001 | error = -EFAULT; |
| 7002 | goto out; |
| 7003 | } |
| 7004 | } |
| 7005 | |
| 7006 | /* |
| 7007 | * copy out the sense |
| 7008 | */ |
| 7009 | if (ioc->sense_len) { |
| 7010 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7011 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7012 | * sense buffer address |
| 7013 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7014 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 7015 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7016 | |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7017 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), |
| 7018 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7019 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 7020 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7021 | error = -EFAULT; |
| 7022 | goto out; |
| 7023 | } |
| 7024 | } |
| 7025 | |
| 7026 | /* |
| 7027 | * copy the status codes returned by the fw |
| 7028 | */ |
| 7029 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 7030 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7031 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Error copying out cmd_status\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7032 | error = -EFAULT; |
| 7033 | } |
| 7034 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7035 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7036 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7037 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7038 | sense, sense_handle); |
| 7039 | } |
| 7040 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7041 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7042 | if (kbuff_arr[i]) { |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7043 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7044 | le32_to_cpu(kern_sge32[i].length), |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7045 | kbuff_arr[i], |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7046 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 7047 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7048 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7049 | } |
| 7050 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7051 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7052 | return error; |
| 7053 | } |
| 7054 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7055 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 7056 | { |
| 7057 | struct megasas_iocpacket __user *user_ioc = |
| 7058 | (struct megasas_iocpacket __user *)arg; |
| 7059 | struct megasas_iocpacket *ioc; |
| 7060 | struct megasas_instance *instance; |
| 7061 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7062 | int i; |
| 7063 | unsigned long flags; |
| 7064 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7065 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 7066 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 7067 | if (IS_ERR(ioc)) |
| 7068 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7069 | |
| 7070 | instance = megasas_lookup_instance(ioc->host_no); |
| 7071 | if (!instance) { |
| 7072 | error = -ENODEV; |
| 7073 | goto out_kfree_ioc; |
| 7074 | } |
| 7075 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7076 | /* Adjust ioctl wait time for VF mode */ |
| 7077 | if (instance->requestorId) |
| 7078 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 7079 | |
| 7080 | /* Block ioctls in VF mode */ |
| 7081 | if (instance->requestorId && !allow_vf_ioctls) { |
| 7082 | error = -ENODEV; |
| 7083 | goto out_kfree_ioc; |
| 7084 | } |
| 7085 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7086 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7087 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7088 | error = -ENODEV; |
| 7089 | goto out_kfree_ioc; |
| 7090 | } |
| 7091 | |
| 7092 | if (instance->unload == 1) { |
| 7093 | error = -ENODEV; |
| 7094 | goto out_kfree_ioc; |
| 7095 | } |
| 7096 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7097 | if (down_interruptible(&instance->ioctl_sem)) { |
| 7098 | error = -ERESTARTSYS; |
| 7099 | goto out_kfree_ioc; |
| 7100 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7101 | |
| 7102 | for (i = 0; i < wait_time; i++) { |
| 7103 | |
| 7104 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7105 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7106 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7107 | break; |
| 7108 | } |
| 7109 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7110 | |
| 7111 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7112 | dev_notice(&instance->pdev->dev, "waiting" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7113 | "for controller reset to finish\n"); |
| 7114 | } |
| 7115 | |
| 7116 | msleep(1000); |
| 7117 | } |
| 7118 | |
| 7119 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7120 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7121 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7122 | |
Colin Ian King | 644da3c | 2016-11-12 16:25:24 +0000 | [diff] [blame] | 7123 | dev_err(&instance->pdev->dev, "timed out while waiting for HBA to recover\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7124 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 7125 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7126 | } |
| 7127 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7128 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7129 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7130 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7131 | up(&instance->ioctl_sem); |
| 7132 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7133 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7134 | kfree(ioc); |
| 7135 | return error; |
| 7136 | } |
| 7137 | |
| 7138 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 7139 | { |
| 7140 | struct megasas_instance *instance; |
| 7141 | struct megasas_aen aen; |
| 7142 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7143 | int i; |
| 7144 | unsigned long flags; |
| 7145 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7146 | |
| 7147 | if (file->private_data != file) { |
| 7148 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 7149 | "called first\n"); |
| 7150 | return -EINVAL; |
| 7151 | } |
| 7152 | |
| 7153 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 7154 | return -EFAULT; |
| 7155 | |
| 7156 | instance = megasas_lookup_instance(aen.host_no); |
| 7157 | |
| 7158 | if (!instance) |
| 7159 | return -ENODEV; |
| 7160 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7161 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7162 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7163 | } |
| 7164 | |
| 7165 | if (instance->unload == 1) { |
| 7166 | return -ENODEV; |
| 7167 | } |
| 7168 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7169 | for (i = 0; i < wait_time; i++) { |
| 7170 | |
| 7171 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7172 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7173 | spin_unlock_irqrestore(&instance->hba_lock, |
| 7174 | flags); |
| 7175 | break; |
| 7176 | } |
| 7177 | |
| 7178 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7179 | |
| 7180 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7181 | dev_notice(&instance->pdev->dev, "waiting for" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7182 | "controller reset to finish\n"); |
| 7183 | } |
| 7184 | |
| 7185 | msleep(1000); |
| 7186 | } |
| 7187 | |
| 7188 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7189 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7190 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Colin Ian King | 644da3c | 2016-11-12 16:25:24 +0000 | [diff] [blame] | 7191 | dev_err(&instance->pdev->dev, "timed out while waiting for HBA to recover\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7192 | return -ENODEV; |
| 7193 | } |
| 7194 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7195 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7196 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7197 | error = megasas_register_aen(instance, aen.seq_num, |
| 7198 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7199 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7200 | return error; |
| 7201 | } |
| 7202 | |
| 7203 | /** |
| 7204 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 7205 | */ |
| 7206 | static long |
| 7207 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 7208 | { |
| 7209 | switch (cmd) { |
| 7210 | case MEGASAS_IOC_FIRMWARE: |
| 7211 | return megasas_mgmt_ioctl_fw(file, arg); |
| 7212 | |
| 7213 | case MEGASAS_IOC_GET_AEN: |
| 7214 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7215 | } |
| 7216 | |
| 7217 | return -ENOTTY; |
| 7218 | } |
| 7219 | |
| 7220 | #ifdef CONFIG_COMPAT |
| 7221 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 7222 | { |
| 7223 | struct compat_megasas_iocpacket __user *cioc = |
| 7224 | (struct compat_megasas_iocpacket __user *)arg; |
| 7225 | struct megasas_iocpacket __user *ioc = |
| 7226 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 7227 | int i; |
| 7228 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7229 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7230 | u32 local_sense_off; |
| 7231 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7232 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7233 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7234 | if (clear_user(ioc, sizeof(*ioc))) |
| 7235 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7236 | |
| 7237 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 7238 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 7239 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 7240 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 7241 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 7242 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 7243 | return -EFAULT; |
| 7244 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7245 | /* |
| 7246 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 7247 | * sense_len is not null, so prepare the 64bit value under |
| 7248 | * the same condition. |
| 7249 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7250 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 7251 | get_user(local_sense_len, &ioc->sense_len) || |
| 7252 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7253 | return -EFAULT; |
| 7254 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7255 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7256 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7257 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7258 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7259 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7260 | if (get_user(ptr, sense_cioc_ptr) || |
| 7261 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 7262 | return -EFAULT; |
| 7263 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7264 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7265 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7266 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 7267 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 7268 | copy_in_user(&ioc->sgl[i].iov_len, |
| 7269 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 7270 | return -EFAULT; |
| 7271 | } |
| 7272 | |
| 7273 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 7274 | |
| 7275 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 7276 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 7277 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 7278 | return -EFAULT; |
| 7279 | } |
| 7280 | return error; |
| 7281 | } |
| 7282 | |
| 7283 | static long |
| 7284 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 7285 | unsigned long arg) |
| 7286 | { |
| 7287 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 7288 | case MEGASAS_IOC_FIRMWARE32: |
| 7289 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7290 | case MEGASAS_IOC_GET_AEN: |
| 7291 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7292 | } |
| 7293 | |
| 7294 | return -ENOTTY; |
| 7295 | } |
| 7296 | #endif |
| 7297 | |
| 7298 | /* |
| 7299 | * File operations structure for management interface |
| 7300 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 7301 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7302 | .owner = THIS_MODULE, |
| 7303 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7304 | .fasync = megasas_mgmt_fasync, |
| 7305 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7306 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7307 | #ifdef CONFIG_COMPAT |
| 7308 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 7309 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 7310 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7311 | }; |
| 7312 | |
| 7313 | /* |
| 7314 | * PCI hotplug support registration structure |
| 7315 | */ |
| 7316 | static struct pci_driver megasas_pci_driver = { |
| 7317 | |
| 7318 | .name = "megaraid_sas", |
| 7319 | .id_table = megasas_pci_table, |
| 7320 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7321 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7322 | .suspend = megasas_suspend, |
| 7323 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7324 | .shutdown = megasas_shutdown, |
| 7325 | }; |
| 7326 | |
| 7327 | /* |
| 7328 | * Sysfs driver attributes |
| 7329 | */ |
| 7330 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) |
| 7331 | { |
| 7332 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 7333 | MEGASAS_VERSION); |
| 7334 | } |
| 7335 | |
| 7336 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); |
| 7337 | |
| 7338 | static ssize_t |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7339 | megasas_sysfs_show_release_date(struct device_driver *dd, char *buf) |
| 7340 | { |
| 7341 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 7342 | MEGASAS_RELDATE); |
| 7343 | } |
| 7344 | |
| 7345 | static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, NULL); |
| 7346 | |
| 7347 | static ssize_t |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7348 | megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) |
| 7349 | { |
| 7350 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 7351 | } |
| 7352 | |
| 7353 | static DRIVER_ATTR(support_poll_for_event, S_IRUGO, |
| 7354 | megasas_sysfs_show_support_poll_for_event, NULL); |
| 7355 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7356 | static ssize_t |
| 7357 | megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf) |
| 7358 | { |
| 7359 | return sprintf(buf, "%u\n", support_device_change); |
| 7360 | } |
| 7361 | |
| 7362 | static DRIVER_ATTR(support_device_change, S_IRUGO, |
| 7363 | megasas_sysfs_show_support_device_change, NULL); |
| 7364 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7365 | static ssize_t |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7366 | megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) |
| 7367 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7368 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7369 | } |
| 7370 | |
| 7371 | static ssize_t |
| 7372 | megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count) |
| 7373 | { |
| 7374 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7375 | |
| 7376 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7377 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 7378 | retval = -EINVAL; |
| 7379 | } |
| 7380 | return retval; |
| 7381 | } |
| 7382 | |
Joe Malicki | 66dca9b | 2008-08-14 17:14:48 -0400 | [diff] [blame] | 7383 | static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7384 | megasas_sysfs_set_dbg_lvl); |
| 7385 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7386 | static void |
| 7387 | megasas_aen_polling(struct work_struct *work) |
| 7388 | { |
| 7389 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7390 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7391 | struct megasas_instance *instance = ev->instance; |
| 7392 | union megasas_evt_class_locale class_locale; |
| 7393 | struct Scsi_Host *host; |
| 7394 | struct scsi_device *sdev1; |
| 7395 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7396 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7397 | int i, j, doscan = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7398 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7399 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7400 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7401 | |
| 7402 | if (!instance) { |
| 7403 | printk(KERN_ERR "invalid instance!\n"); |
| 7404 | kfree(ev); |
| 7405 | return; |
| 7406 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7407 | |
| 7408 | /* Adjust event workqueue thread wait time for VF mode */ |
| 7409 | if (instance->requestorId) |
| 7410 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 7411 | |
| 7412 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7413 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7414 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7415 | instance->ev = NULL; |
| 7416 | host = instance->host; |
| 7417 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 7418 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7419 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7420 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7421 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7422 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7423 | case MR_EVT_PD_REMOVED: |
| 7424 | dcmd_ret = megasas_get_pd_list(instance); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7425 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7426 | doscan = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7427 | break; |
| 7428 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7429 | case MR_EVT_LD_OFFLINE: |
| 7430 | case MR_EVT_CFG_CLEARED: |
| 7431 | case MR_EVT_LD_DELETED: |
| 7432 | case MR_EVT_LD_CREATED: |
| 7433 | if (!instance->requestorId || |
| 7434 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7435 | dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7436 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7437 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7438 | doscan = SCAN_VD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7439 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7440 | break; |
| 7441 | |
| 7442 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 7443 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 7444 | case MR_EVT_LD_STATE_CHANGE: |
| 7445 | dcmd_ret = megasas_get_pd_list(instance); |
| 7446 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7447 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7448 | break; |
| 7449 | |
| 7450 | if (!instance->requestorId || |
| 7451 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7452 | dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 7453 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7454 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7455 | break; |
| 7456 | |
| 7457 | doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL; |
| 7458 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 7459 | instance->host->host_no); |
| 7460 | break; |
| 7461 | |
| 7462 | case MR_EVT_CTRL_PROP_CHANGED: |
| 7463 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 7464 | break; |
| 7465 | default: |
| 7466 | doscan = 0; |
| 7467 | break; |
| 7468 | } |
| 7469 | } else { |
| 7470 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 7471 | mutex_unlock(&instance->reset_mutex); |
| 7472 | kfree(ev); |
| 7473 | return; |
| 7474 | } |
| 7475 | |
| 7476 | mutex_unlock(&instance->reset_mutex); |
| 7477 | |
| 7478 | if (doscan & SCAN_PD_CHANNEL) { |
| 7479 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 7480 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7481 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7482 | sdev1 = scsi_device_lookup(host, i, j, 0); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7483 | if (instance->pd_list[pd_index].driveState == |
| 7484 | MR_PD_STATE_SYSTEM) { |
| 7485 | if (!sdev1) |
| 7486 | scsi_add_device(host, i, j, 0); |
| 7487 | else |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7488 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7489 | } else { |
| 7490 | if (sdev1) { |
| 7491 | scsi_remove_device(sdev1); |
| 7492 | scsi_device_put(sdev1); |
| 7493 | } |
| 7494 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7495 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7496 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7497 | } |
| 7498 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7499 | if (doscan & SCAN_VD_CHANNEL) { |
| 7500 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 7501 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7502 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 7503 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7504 | if (instance->ld_ids[ld_index] != 0xff) { |
| 7505 | if (!sdev1) |
| 7506 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7507 | else |
| 7508 | scsi_device_put(sdev1); |
| 7509 | } else { |
| 7510 | if (sdev1) { |
| 7511 | scsi_remove_device(sdev1); |
| 7512 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7513 | } |
| 7514 | } |
| 7515 | } |
| 7516 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7517 | } |
| 7518 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7519 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7520 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 7521 | else |
| 7522 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7523 | |
| 7524 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 7525 | class_locale.members.reserved = 0; |
| 7526 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 7527 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7528 | |
| 7529 | if (instance->aen_cmd != NULL) { |
| 7530 | kfree(ev); |
| 7531 | return; |
| 7532 | } |
| 7533 | |
| 7534 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7535 | error = megasas_register_aen(instance, seq_num, |
| 7536 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7537 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7538 | dev_err(&instance->pdev->dev, |
| 7539 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7540 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7541 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7542 | kfree(ev); |
| 7543 | } |
| 7544 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7545 | /** |
| 7546 | * megasas_init - Driver load entry point |
| 7547 | */ |
| 7548 | static int __init megasas_init(void) |
| 7549 | { |
| 7550 | int rval; |
| 7551 | |
| 7552 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 7553 | * Booted in kdump kernel, minimize memory footprints by |
| 7554 | * disabling few features |
| 7555 | */ |
| 7556 | if (reset_devices) { |
| 7557 | msix_vectors = 1; |
| 7558 | rdpq_enable = 0; |
| 7559 | dual_qdepth_disable = 1; |
| 7560 | } |
| 7561 | |
| 7562 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7563 | * Announce driver version and other information |
| 7564 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 7565 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7566 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 7567 | spin_lock_init(&poll_aen_lock); |
| 7568 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7569 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7570 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7571 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7572 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 7573 | |
| 7574 | /* |
| 7575 | * Register character device node |
| 7576 | */ |
| 7577 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 7578 | |
| 7579 | if (rval < 0) { |
| 7580 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 7581 | return rval; |
| 7582 | } |
| 7583 | |
| 7584 | megasas_mgmt_majorno = rval; |
| 7585 | |
| 7586 | /* |
| 7587 | * Register ourselves as PCI hotplug module |
| 7588 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 7589 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7590 | |
| 7591 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 7592 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7593 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7594 | } |
| 7595 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7596 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7597 | &driver_attr_version); |
| 7598 | if (rval) |
| 7599 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7600 | |
| 7601 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7602 | &driver_attr_release_date); |
| 7603 | if (rval) |
| 7604 | goto err_dcf_rel_date; |
| 7605 | |
| 7606 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7607 | &driver_attr_support_poll_for_event); |
| 7608 | if (rval) |
| 7609 | goto err_dcf_support_poll_for_event; |
| 7610 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7611 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7612 | &driver_attr_dbg_lvl); |
| 7613 | if (rval) |
| 7614 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7615 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7616 | &driver_attr_support_device_change); |
| 7617 | if (rval) |
| 7618 | goto err_dcf_support_device_change; |
| 7619 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7620 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7621 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7622 | err_dcf_support_device_change: |
| 7623 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7624 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7625 | err_dcf_dbg_lvl: |
| 7626 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7627 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7628 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7629 | driver_remove_file(&megasas_pci_driver.driver, |
| 7630 | &driver_attr_release_date); |
| 7631 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7632 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 7633 | err_dcf_attr_ver: |
| 7634 | pci_unregister_driver(&megasas_pci_driver); |
| 7635 | err_pcidrv: |
| 7636 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 7637 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | /** |
| 7641 | * megasas_exit - Driver unload entry point |
| 7642 | */ |
| 7643 | static void __exit megasas_exit(void) |
| 7644 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7645 | driver_remove_file(&megasas_pci_driver.driver, |
| 7646 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7647 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7648 | &driver_attr_support_poll_for_event); |
| 7649 | driver_remove_file(&megasas_pci_driver.driver, |
| 7650 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7651 | driver_remove_file(&megasas_pci_driver.driver, |
| 7652 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7653 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7654 | |
| 7655 | pci_unregister_driver(&megasas_pci_driver); |
| 7656 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 7657 | } |
| 7658 | |
| 7659 | module_init(megasas_init); |
| 7660 | module_exit(megasas_exit); |