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); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 119 | static int |
| 120 | megasas_get_pd_info(struct megasas_instance *instance, u16 device_id); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 121 | /* |
| 122 | * PCI ID table for all supported controllers |
| 123 | */ |
| 124 | static struct pci_device_id megasas_pci_table[] = { |
| 125 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 126 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 127 | /* xscale IOP */ |
| 128 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 129 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 130 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 131 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 132 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 133 | /* gen2*/ |
| 134 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 135 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 136 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 137 | /* skinny*/ |
| 138 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 139 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 141 | /* xscale IOP, vega */ |
| 142 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 143 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 144 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 145 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 146 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 147 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 148 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 149 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 150 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 151 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 152 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 153 | /* Intruder */ |
| 154 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 155 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 156 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 157 | {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] | 158 | /* VENTURA */ |
| 159 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)}, |
| 160 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)}, |
| 161 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)}, |
| 162 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)}, |
| 163 | {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] | 164 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 168 | |
| 169 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 170 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 171 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 172 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 173 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 174 | static int megasas_poll_wait_aen; |
| 175 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 176 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 177 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 178 | static u32 support_device_change; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 179 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 180 | /* define lock for aen poll */ |
| 181 | spinlock_t poll_aen_lock; |
| 182 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 183 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 184 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 185 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 186 | static u32 |
| 187 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs); |
| 188 | static int |
| 189 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 190 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 191 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 192 | static u32 |
| 193 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 194 | u32 |
| 195 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 196 | struct scsi_cmnd *scmd); |
| 197 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 198 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 199 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 200 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 201 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 202 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 203 | int initial); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 204 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 205 | int |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 206 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 207 | { |
| 208 | instance->instancet->fire_cmd(instance, |
| 209 | cmd->frame_phys_addr, 0, instance->reg_set); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 210 | return 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 211 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 212 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 213 | /** |
| 214 | * megasas_get_cmd - Get a command from the free pool |
| 215 | * @instance: Adapter soft state |
| 216 | * |
| 217 | * Returns a free command from the pool |
| 218 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 219 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 220 | *instance) |
| 221 | { |
| 222 | unsigned long flags; |
| 223 | struct megasas_cmd *cmd = NULL; |
| 224 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 225 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 226 | |
| 227 | if (!list_empty(&instance->cmd_pool)) { |
| 228 | cmd = list_entry((&instance->cmd_pool)->next, |
| 229 | struct megasas_cmd, list); |
| 230 | list_del_init(&cmd->list); |
| 231 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 232 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 233 | } |
| 234 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 235 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 236 | return cmd; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * megasas_return_cmd - Return a cmd to free command pool |
| 241 | * @instance: Adapter soft state |
| 242 | * @cmd: Command packet to be returned to free command pool |
| 243 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 244 | inline void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 245 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 246 | { |
| 247 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 248 | u32 blk_tags; |
| 249 | struct megasas_cmd_fusion *cmd_fusion; |
| 250 | struct fusion_context *fusion = instance->ctrl_context; |
| 251 | |
| 252 | /* This flag is used only for fusion adapter. |
| 253 | * Wait for Interrupt for Polled mode DCMD |
| 254 | */ |
| 255 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 256 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 257 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 258 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 259 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 260 | if (fusion) { |
| 261 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 262 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 263 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 264 | } |
| 265 | cmd->scmd = NULL; |
| 266 | cmd->frame_count = 0; |
| 267 | cmd->flags = 0; |
| 268 | if (!fusion && reset_devices) |
| 269 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 270 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 271 | |
| 272 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 273 | |
| 274 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 275 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 276 | static const char * |
| 277 | format_timestamp(uint32_t timestamp) |
| 278 | { |
| 279 | static char buffer[32]; |
| 280 | |
| 281 | if ((timestamp & 0xff000000) == 0xff000000) |
| 282 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 283 | 0x00ffffff); |
| 284 | else |
| 285 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 286 | return buffer; |
| 287 | } |
| 288 | |
| 289 | static const char * |
| 290 | format_class(int8_t class) |
| 291 | { |
| 292 | static char buffer[6]; |
| 293 | |
| 294 | switch (class) { |
| 295 | case MFI_EVT_CLASS_DEBUG: |
| 296 | return "debug"; |
| 297 | case MFI_EVT_CLASS_PROGRESS: |
| 298 | return "progress"; |
| 299 | case MFI_EVT_CLASS_INFO: |
| 300 | return "info"; |
| 301 | case MFI_EVT_CLASS_WARNING: |
| 302 | return "WARN"; |
| 303 | case MFI_EVT_CLASS_CRITICAL: |
| 304 | return "CRIT"; |
| 305 | case MFI_EVT_CLASS_FATAL: |
| 306 | return "FATAL"; |
| 307 | case MFI_EVT_CLASS_DEAD: |
| 308 | return "DEAD"; |
| 309 | default: |
| 310 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 311 | return buffer; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 317 | * for information. |
| 318 | * @instance: Adapter soft state |
| 319 | */ |
| 320 | static void |
| 321 | megasas_decode_evt(struct megasas_instance *instance) |
| 322 | { |
| 323 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 324 | union megasas_evt_class_locale class_locale; |
| 325 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 326 | |
| 327 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 328 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 329 | le32_to_cpu(evt_detail->seq_num), |
| 330 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 331 | (class_locale.members.locale), |
| 332 | format_class(class_locale.members.class), |
| 333 | evt_detail->description); |
| 334 | } |
| 335 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 336 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 337 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 338 | * (deviceid : 1064R, PERC5) controllers |
| 339 | */ |
| 340 | |
| 341 | /** |
| 342 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 343 | * @regs: MFI register set |
| 344 | */ |
| 345 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 346 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 347 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 348 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 349 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 350 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 351 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 352 | |
| 353 | /* Dummy readl to force pci flush */ |
| 354 | readl(®s->outbound_intr_mask); |
| 355 | } |
| 356 | |
| 357 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 358 | * megasas_disable_intr_xscale -Disables interrupt |
| 359 | * @regs: MFI register set |
| 360 | */ |
| 361 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 362 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 363 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 364 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 365 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 366 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 367 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 368 | writel(mask, ®s->outbound_intr_mask); |
| 369 | /* Dummy readl to force pci flush */ |
| 370 | readl(®s->outbound_intr_mask); |
| 371 | } |
| 372 | |
| 373 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 374 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 375 | * @regs: MFI register set |
| 376 | */ |
| 377 | static u32 |
| 378 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 379 | { |
| 380 | return readl(&(regs)->outbound_msg_0); |
| 381 | } |
| 382 | /** |
| 383 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 384 | * @regs: MFI register set |
| 385 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 386 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 387 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 388 | { |
| 389 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 390 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 391 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 392 | /* |
| 393 | * Check if it is our interrupt |
| 394 | */ |
| 395 | status = readl(®s->outbound_intr_status); |
| 396 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 397 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 398 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 399 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 400 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 401 | |
| 402 | /* |
| 403 | * Clear the interrupt by writing back the same value |
| 404 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 405 | if (mfiStatus) |
| 406 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 407 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 408 | /* Dummy readl to force pci flush */ |
| 409 | readl(®s->outbound_intr_status); |
| 410 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 411 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /** |
| 415 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 416 | * @frame_phys_addr : Physical address of cmd |
| 417 | * @frame_count : Number of frames for the command |
| 418 | * @regs : MFI register set |
| 419 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 420 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 421 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 422 | dma_addr_t frame_phys_addr, |
| 423 | u32 frame_count, |
| 424 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 425 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 426 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 427 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 428 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 429 | writel((frame_phys_addr >> 3)|(frame_count), |
| 430 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 431 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * megasas_adp_reset_xscale - For controller reset |
| 436 | * @regs: MFI register set |
| 437 | */ |
| 438 | static int |
| 439 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 440 | struct megasas_register_set __iomem *regs) |
| 441 | { |
| 442 | u32 i; |
| 443 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 444 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 445 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 446 | |
| 447 | for (i = 0; i < 3; i++) |
| 448 | msleep(1000); /* sleep for 3 secs */ |
| 449 | pcidata = 0; |
| 450 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 451 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 452 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 453 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 454 | pcidata &= ~0x2; |
| 455 | pci_write_config_dword(instance->pdev, |
| 456 | MFI_1068_PCSR_OFFSET, pcidata); |
| 457 | |
| 458 | for (i = 0; i < 2; i++) |
| 459 | msleep(1000); /* need to wait 2 secs again */ |
| 460 | |
| 461 | pcidata = 0; |
| 462 | pci_read_config_dword(instance->pdev, |
| 463 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 464 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 465 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 466 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 467 | pcidata = 0; |
| 468 | pci_write_config_dword(instance->pdev, |
| 469 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 470 | } |
| 471 | } |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * megasas_check_reset_xscale - For controller reset check |
| 477 | * @regs: MFI register set |
| 478 | */ |
| 479 | static int |
| 480 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 481 | struct megasas_register_set __iomem *regs) |
| 482 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 483 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 484 | (le32_to_cpu(*instance->consumer) == |
| 485 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 486 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 487 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 491 | |
| 492 | .fire_cmd = megasas_fire_cmd_xscale, |
| 493 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 494 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 495 | .clear_intr = megasas_clear_intr_xscale, |
| 496 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 497 | .adp_reset = megasas_adp_reset_xscale, |
| 498 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 499 | .service_isr = megasas_isr, |
| 500 | .tasklet = megasas_complete_cmd_dpc, |
| 501 | .init_adapter = megasas_init_adapter_mfi, |
| 502 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 503 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 507 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 508 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 509 | */ |
| 510 | |
| 511 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 512 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 513 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 514 | */ |
| 515 | |
| 516 | /** |
| 517 | * megasas_enable_intr_ppc - Enables interrupts |
| 518 | * @regs: MFI register set |
| 519 | */ |
| 520 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 521 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 522 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 523 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 524 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 525 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 526 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 527 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 528 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 529 | |
| 530 | /* Dummy readl to force pci flush */ |
| 531 | readl(®s->outbound_intr_mask); |
| 532 | } |
| 533 | |
| 534 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 535 | * megasas_disable_intr_ppc - Disable interrupt |
| 536 | * @regs: MFI register set |
| 537 | */ |
| 538 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 539 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 540 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 541 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 542 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 543 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 544 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 545 | writel(mask, ®s->outbound_intr_mask); |
| 546 | /* Dummy readl to force pci flush */ |
| 547 | readl(®s->outbound_intr_mask); |
| 548 | } |
| 549 | |
| 550 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 551 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 552 | * @regs: MFI register set |
| 553 | */ |
| 554 | static u32 |
| 555 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 556 | { |
| 557 | return readl(&(regs)->outbound_scratch_pad); |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 562 | * @regs: MFI register set |
| 563 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 564 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 565 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 566 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 567 | u32 status, mfiStatus = 0; |
| 568 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 569 | /* |
| 570 | * Check if it is our interrupt |
| 571 | */ |
| 572 | status = readl(®s->outbound_intr_status); |
| 573 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 574 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 575 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 576 | |
| 577 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 578 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 579 | |
| 580 | /* |
| 581 | * Clear the interrupt by writing back the same value |
| 582 | */ |
| 583 | writel(status, ®s->outbound_doorbell_clear); |
| 584 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 585 | /* Dummy readl to force pci flush */ |
| 586 | readl(®s->outbound_doorbell_clear); |
| 587 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 588 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 589 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 590 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 591 | /** |
| 592 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 593 | * @frame_phys_addr : Physical address of cmd |
| 594 | * @frame_count : Number of frames for the command |
| 595 | * @regs : MFI register set |
| 596 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 597 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 598 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 599 | dma_addr_t frame_phys_addr, |
| 600 | u32 frame_count, |
| 601 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 602 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 603 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 604 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 605 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 606 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 607 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 608 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 609 | } |
| 610 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 611 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 612 | * megasas_check_reset_ppc - For controller reset check |
| 613 | * @regs: MFI register set |
| 614 | */ |
| 615 | static int |
| 616 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 617 | struct megasas_register_set __iomem *regs) |
| 618 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 619 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 620 | return 1; |
| 621 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 622 | return 0; |
| 623 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 624 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 625 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 626 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 627 | .fire_cmd = megasas_fire_cmd_ppc, |
| 628 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 629 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 630 | .clear_intr = megasas_clear_intr_ppc, |
| 631 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 632 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 633 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 634 | .service_isr = megasas_isr, |
| 635 | .tasklet = megasas_complete_cmd_dpc, |
| 636 | .init_adapter = megasas_init_adapter_mfi, |
| 637 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 638 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 639 | }; |
| 640 | |
| 641 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 642 | * megasas_enable_intr_skinny - Enables interrupts |
| 643 | * @regs: MFI register set |
| 644 | */ |
| 645 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 646 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 647 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 648 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 649 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 650 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 651 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 652 | |
| 653 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 654 | |
| 655 | /* Dummy readl to force pci flush */ |
| 656 | readl(®s->outbound_intr_mask); |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * megasas_disable_intr_skinny - Disables interrupt |
| 661 | * @regs: MFI register set |
| 662 | */ |
| 663 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 664 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 665 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 666 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 667 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 668 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 669 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 670 | writel(mask, ®s->outbound_intr_mask); |
| 671 | /* Dummy readl to force pci flush */ |
| 672 | readl(®s->outbound_intr_mask); |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 677 | * @regs: MFI register set |
| 678 | */ |
| 679 | static u32 |
| 680 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 681 | { |
| 682 | return readl(&(regs)->outbound_scratch_pad); |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 687 | * @regs: MFI register set |
| 688 | */ |
| 689 | static int |
| 690 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 691 | { |
| 692 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 693 | u32 mfiStatus = 0; |
| 694 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 695 | /* |
| 696 | * Check if it is our interrupt |
| 697 | */ |
| 698 | status = readl(®s->outbound_intr_status); |
| 699 | |
| 700 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 701 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 705 | * Check if it is our interrupt |
| 706 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 707 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 708 | MFI_STATE_FAULT) { |
| 709 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 710 | } else |
| 711 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 712 | |
| 713 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 714 | * Clear the interrupt by writing back the same value |
| 715 | */ |
| 716 | writel(status, ®s->outbound_intr_status); |
| 717 | |
| 718 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 719 | * dummy read to flush PCI |
| 720 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 721 | readl(®s->outbound_intr_status); |
| 722 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 723 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 728 | * @frame_phys_addr : Physical address of cmd |
| 729 | * @frame_count : Number of frames for the command |
| 730 | * @regs : MFI register set |
| 731 | */ |
| 732 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 733 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 734 | dma_addr_t frame_phys_addr, |
| 735 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 736 | struct megasas_register_set __iomem *regs) |
| 737 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 738 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 739 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 740 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 741 | writel(upper_32_bits(frame_phys_addr), |
| 742 | &(regs)->inbound_high_queue_port); |
| 743 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 744 | &(regs)->inbound_low_queue_port); |
Tomas Henzl | b99dbe5 | 2016-02-01 15:12:04 +0100 | [diff] [blame] | 745 | mmiowb(); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 746 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 747 | } |
| 748 | |
| 749 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 750 | * megasas_check_reset_skinny - For controller reset check |
| 751 | * @regs: MFI register set |
| 752 | */ |
| 753 | static int |
| 754 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 755 | struct megasas_register_set __iomem *regs) |
| 756 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 757 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 758 | return 1; |
| 759 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 760 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 764 | |
| 765 | .fire_cmd = megasas_fire_cmd_skinny, |
| 766 | .enable_intr = megasas_enable_intr_skinny, |
| 767 | .disable_intr = megasas_disable_intr_skinny, |
| 768 | .clear_intr = megasas_clear_intr_skinny, |
| 769 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 770 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 771 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 772 | .service_isr = megasas_isr, |
| 773 | .tasklet = megasas_complete_cmd_dpc, |
| 774 | .init_adapter = megasas_init_adapter_mfi, |
| 775 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 776 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 777 | }; |
| 778 | |
| 779 | |
| 780 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 781 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 782 | * controllers |
| 783 | */ |
| 784 | |
| 785 | /** |
| 786 | * megasas_enable_intr_gen2 - Enables interrupts |
| 787 | * @regs: MFI register set |
| 788 | */ |
| 789 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 790 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 791 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 792 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 793 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 794 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 795 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 796 | |
| 797 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 798 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 799 | |
| 800 | /* Dummy readl to force pci flush */ |
| 801 | readl(®s->outbound_intr_mask); |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * megasas_disable_intr_gen2 - Disables interrupt |
| 806 | * @regs: MFI register set |
| 807 | */ |
| 808 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 809 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 810 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 811 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 812 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 813 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 814 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 815 | writel(mask, ®s->outbound_intr_mask); |
| 816 | /* Dummy readl to force pci flush */ |
| 817 | readl(®s->outbound_intr_mask); |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 822 | * @regs: MFI register set |
| 823 | */ |
| 824 | static u32 |
| 825 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 826 | { |
| 827 | return readl(&(regs)->outbound_scratch_pad); |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 832 | * @regs: MFI register set |
| 833 | */ |
| 834 | static int |
| 835 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 836 | { |
| 837 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 838 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 839 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 840 | /* |
| 841 | * Check if it is our interrupt |
| 842 | */ |
| 843 | status = readl(®s->outbound_intr_status); |
| 844 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 845 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 846 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 847 | } |
| 848 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 849 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 850 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * Clear the interrupt by writing back the same value |
| 854 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 855 | if (mfiStatus) |
| 856 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 857 | |
| 858 | /* Dummy readl to force pci flush */ |
| 859 | readl(®s->outbound_intr_status); |
| 860 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 861 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 862 | } |
| 863 | /** |
| 864 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 865 | * @frame_phys_addr : Physical address of cmd |
| 866 | * @frame_count : Number of frames for the command |
| 867 | * @regs : MFI register set |
| 868 | */ |
| 869 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 870 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 871 | dma_addr_t frame_phys_addr, |
| 872 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 873 | struct megasas_register_set __iomem *regs) |
| 874 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 875 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 876 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 877 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 878 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 879 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 880 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * megasas_adp_reset_gen2 - For controller reset |
| 885 | * @regs: MFI register set |
| 886 | */ |
| 887 | static int |
| 888 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 889 | struct megasas_register_set __iomem *reg_set) |
| 890 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 891 | u32 retry = 0 ; |
| 892 | u32 HostDiag; |
| 893 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 894 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 895 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 896 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 897 | seq_offset = ®_set->fusion_seq_offset; |
| 898 | hostdiag_offset = ®_set->fusion_host_diag; |
| 899 | } |
| 900 | |
| 901 | writel(0, seq_offset); |
| 902 | writel(4, seq_offset); |
| 903 | writel(0xb, seq_offset); |
| 904 | writel(2, seq_offset); |
| 905 | writel(7, seq_offset); |
| 906 | writel(0xd, seq_offset); |
| 907 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 908 | msleep(1000); |
| 909 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 910 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 911 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 912 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 913 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 914 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 915 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 916 | retry, HostDiag); |
| 917 | |
| 918 | if (retry++ >= 100) |
| 919 | return 1; |
| 920 | |
| 921 | } |
| 922 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 923 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 924 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 925 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 926 | |
| 927 | ssleep(10); |
| 928 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 929 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 930 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 931 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 932 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 933 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 934 | retry, HostDiag); |
| 935 | |
| 936 | if (retry++ >= 1000) |
| 937 | return 1; |
| 938 | |
| 939 | } |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * megasas_check_reset_gen2 - For controller reset check |
| 945 | * @regs: MFI register set |
| 946 | */ |
| 947 | static int |
| 948 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 949 | struct megasas_register_set __iomem *regs) |
| 950 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 951 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 952 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 953 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 954 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 958 | |
| 959 | .fire_cmd = megasas_fire_cmd_gen2, |
| 960 | .enable_intr = megasas_enable_intr_gen2, |
| 961 | .disable_intr = megasas_disable_intr_gen2, |
| 962 | .clear_intr = megasas_clear_intr_gen2, |
| 963 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 964 | .adp_reset = megasas_adp_reset_gen2, |
| 965 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 966 | .service_isr = megasas_isr, |
| 967 | .tasklet = megasas_complete_cmd_dpc, |
| 968 | .init_adapter = megasas_init_adapter_mfi, |
| 969 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 970 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 971 | }; |
| 972 | |
| 973 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 974 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 975 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 976 | */ |
| 977 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 978 | /* |
| 979 | * Template added for TB (Fusion) |
| 980 | */ |
| 981 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 982 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 983 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 984 | * megasas_issue_polled - Issues a polling command |
| 985 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 986 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 987 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 988 | * 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] | 989 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 990 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 991 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 992 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 993 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 994 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 995 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 996 | 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] | 997 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 998 | if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) || |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 999 | (instance->instancet->issue_dcmd(instance, cmd))) { |
| 1000 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1001 | __func__, __LINE__); |
| 1002 | return DCMD_NOT_FIRED; |
| 1003 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1004 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1005 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1006 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1011 | * @instance: Adapter soft state |
| 1012 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1013 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1014 | * |
| 1015 | * 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] | 1016 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1017 | * Used to issue ioctl commands. |
| 1018 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1019 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1020 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1021 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1022 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1023 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1024 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1025 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1026 | if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) || |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1027 | (instance->instancet->issue_dcmd(instance, cmd))) { |
| 1028 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1029 | __func__, __LINE__); |
| 1030 | return DCMD_NOT_FIRED; |
| 1031 | } |
| 1032 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1033 | if (timeout) { |
| 1034 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1035 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1036 | if (!ret) { |
| 1037 | dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n", |
| 1038 | __func__, __LINE__); |
| 1039 | return DCMD_TIMEOUT; |
| 1040 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1041 | } else |
| 1042 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1043 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1044 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1045 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1046 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | /** |
| 1050 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1051 | * @instance: Adapter soft state |
| 1052 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1053 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1054 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1055 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1056 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1057 | * cmd and waits for return status. |
| 1058 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1059 | */ |
| 1060 | static int |
| 1061 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1062 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1063 | { |
| 1064 | struct megasas_cmd *cmd; |
| 1065 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1066 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1067 | |
| 1068 | cmd = megasas_get_cmd(instance); |
| 1069 | |
| 1070 | if (!cmd) |
| 1071 | return -1; |
| 1072 | |
| 1073 | abort_fr = &cmd->frame->abort; |
| 1074 | |
| 1075 | /* |
| 1076 | * Prepare and issue the abort frame |
| 1077 | */ |
| 1078 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1079 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1080 | abort_fr->flags = cpu_to_le16(0); |
| 1081 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1082 | abort_fr->abort_mfi_phys_addr_lo = |
| 1083 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1084 | abort_fr->abort_mfi_phys_addr_hi = |
| 1085 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1086 | |
| 1087 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1088 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1089 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1090 | if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) || |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1091 | (instance->instancet->issue_dcmd(instance, cmd))) { |
| 1092 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1093 | __func__, __LINE__); |
| 1094 | return DCMD_NOT_FIRED; |
| 1095 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1096 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1097 | if (timeout) { |
| 1098 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1099 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1100 | if (!ret) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1101 | dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n", |
| 1102 | __func__, __LINE__); |
| 1103 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1104 | } |
| 1105 | } else |
| 1106 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1107 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1108 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1109 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1110 | |
| 1111 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1112 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1113 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1118 | * @instance: Adapter soft state |
| 1119 | * @scp: SCSI command from the mid-layer |
| 1120 | * @mfi_sgl: SGL to be filled in |
| 1121 | * |
| 1122 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1123 | * it returnes -1. |
| 1124 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1125 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1126 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1127 | union megasas_sgl *mfi_sgl) |
| 1128 | { |
| 1129 | int i; |
| 1130 | int sge_count; |
| 1131 | struct scatterlist *os_sgl; |
| 1132 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1133 | sge_count = scsi_dma_map(scp); |
| 1134 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1135 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1136 | if (sge_count) { |
| 1137 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1138 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1139 | 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] | 1140 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1141 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1142 | return sge_count; |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1147 | * @instance: Adapter soft state |
| 1148 | * @scp: SCSI command from the mid-layer |
| 1149 | * @mfi_sgl: SGL to be filled in |
| 1150 | * |
| 1151 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1152 | * it returnes -1. |
| 1153 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1154 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1155 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1156 | union megasas_sgl *mfi_sgl) |
| 1157 | { |
| 1158 | int i; |
| 1159 | int sge_count; |
| 1160 | struct scatterlist *os_sgl; |
| 1161 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1162 | sge_count = scsi_dma_map(scp); |
| 1163 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1164 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1165 | if (sge_count) { |
| 1166 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1167 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1168 | 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] | 1169 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1170 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1171 | return sge_count; |
| 1172 | } |
| 1173 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1174 | /** |
| 1175 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1176 | * @instance: Adapter soft state |
| 1177 | * @scp: SCSI command from the mid-layer |
| 1178 | * @mfi_sgl: SGL to be filled in |
| 1179 | * |
| 1180 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1181 | * it returnes -1. |
| 1182 | */ |
| 1183 | static int |
| 1184 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1185 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1186 | { |
| 1187 | int i; |
| 1188 | int sge_count; |
| 1189 | struct scatterlist *os_sgl; |
| 1190 | |
| 1191 | sge_count = scsi_dma_map(scp); |
| 1192 | |
| 1193 | if (sge_count) { |
| 1194 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1195 | mfi_sgl->sge_skinny[i].length = |
| 1196 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1197 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1198 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1199 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | return sge_count; |
| 1203 | } |
| 1204 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1205 | /** |
| 1206 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1207 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1208 | * @sge_count : number of sg elements |
| 1209 | * |
| 1210 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1211 | */ |
| 1212 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1213 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1214 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1215 | { |
| 1216 | int num_cnt; |
| 1217 | int sge_bytes; |
| 1218 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1219 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1220 | |
| 1221 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1222 | sizeof(struct megasas_sge32); |
| 1223 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1224 | if (instance->flag_ieee) { |
| 1225 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1226 | } |
| 1227 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1228 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1229 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1230 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1231 | * 1 SGEs for 64-bit SGLs and |
| 1232 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1233 | */ |
| 1234 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1235 | if (instance->flag_ieee == 1) { |
| 1236 | num_cnt = sge_count - 1; |
| 1237 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1238 | num_cnt = sge_count - 1; |
| 1239 | else |
| 1240 | num_cnt = sge_count - 2; |
| 1241 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1242 | if (instance->flag_ieee == 1) { |
| 1243 | num_cnt = sge_count - 1; |
| 1244 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1245 | num_cnt = sge_count - 2; |
| 1246 | else |
| 1247 | num_cnt = sge_count - 3; |
| 1248 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1249 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1250 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1251 | sge_bytes = sge_sz * num_cnt; |
| 1252 | |
| 1253 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1254 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1255 | } |
| 1256 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1257 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1258 | |
| 1259 | if (frame_count > 7) |
| 1260 | frame_count = 8; |
| 1261 | return frame_count; |
| 1262 | } |
| 1263 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1264 | /** |
| 1265 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1266 | * @instance: Adapter soft state |
| 1267 | * @scp: SCSI command |
| 1268 | * @cmd: Command to be prepared in |
| 1269 | * |
| 1270 | * This function prepares CDB commands. These are typcially pass-through |
| 1271 | * commands to the devices. |
| 1272 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1273 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1274 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1275 | struct megasas_cmd *cmd) |
| 1276 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1277 | u32 is_logical; |
| 1278 | u32 device_id; |
| 1279 | u16 flags = 0; |
| 1280 | struct megasas_pthru_frame *pthru; |
| 1281 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1282 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1283 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1284 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1285 | |
| 1286 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1287 | flags = MFI_FRAME_DIR_WRITE; |
| 1288 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1289 | flags = MFI_FRAME_DIR_READ; |
| 1290 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1291 | flags = MFI_FRAME_DIR_NONE; |
| 1292 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1293 | if (instance->flag_ieee == 1) { |
| 1294 | flags |= MFI_FRAME_IEEE; |
| 1295 | } |
| 1296 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1297 | /* |
| 1298 | * Prepare the DCDB frame |
| 1299 | */ |
| 1300 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1301 | pthru->cmd_status = 0x0; |
| 1302 | pthru->scsi_status = 0x0; |
| 1303 | pthru->target_id = device_id; |
| 1304 | pthru->lun = scp->device->lun; |
| 1305 | pthru->cdb_len = scp->cmd_len; |
| 1306 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1307 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1308 | pthru->flags = cpu_to_le16(flags); |
| 1309 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1310 | |
| 1311 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1312 | |
| 1313 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1314 | * If the command is for the tape device, set the |
| 1315 | * pthru timeout to the os layer timeout value. |
| 1316 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1317 | if (scp->device->type == TYPE_TAPE) { |
| 1318 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1319 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1320 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1321 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1325 | * Construct SGL |
| 1326 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1327 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1328 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1329 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1330 | &pthru->sgl); |
| 1331 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1332 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1333 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1334 | &pthru->sgl); |
| 1335 | } else |
| 1336 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1337 | &pthru->sgl); |
| 1338 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1339 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1340 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1341 | pthru->sge_count); |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1345 | /* |
| 1346 | * Sense info specific |
| 1347 | */ |
| 1348 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1349 | pthru->sense_buf_phys_addr_hi = |
| 1350 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1351 | pthru->sense_buf_phys_addr_lo = |
| 1352 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1353 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1354 | /* |
| 1355 | * Compute the total number of frames this command consumes. FW uses |
| 1356 | * this number to pull sufficient number of frames from host memory. |
| 1357 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1358 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1359 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1360 | |
| 1361 | return cmd->frame_count; |
| 1362 | } |
| 1363 | |
| 1364 | /** |
| 1365 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1366 | * @instance: Adapter soft state |
| 1367 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1368 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1369 | * |
| 1370 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1371 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1372 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1373 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1374 | struct megasas_cmd *cmd) |
| 1375 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1376 | u32 device_id; |
| 1377 | u8 sc = scp->cmnd[0]; |
| 1378 | u16 flags = 0; |
| 1379 | struct megasas_io_frame *ldio; |
| 1380 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1381 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1382 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1383 | |
| 1384 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1385 | flags = MFI_FRAME_DIR_WRITE; |
| 1386 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1387 | flags = MFI_FRAME_DIR_READ; |
| 1388 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1389 | if (instance->flag_ieee == 1) { |
| 1390 | flags |= MFI_FRAME_IEEE; |
| 1391 | } |
| 1392 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1393 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1394 | * 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] | 1395 | */ |
| 1396 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1397 | ldio->cmd_status = 0x0; |
| 1398 | ldio->scsi_status = 0x0; |
| 1399 | ldio->target_id = device_id; |
| 1400 | ldio->timeout = 0; |
| 1401 | ldio->reserved_0 = 0; |
| 1402 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1403 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1404 | ldio->start_lba_hi = 0; |
| 1405 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1406 | |
| 1407 | /* |
| 1408 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1409 | */ |
| 1410 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1411 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1412 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1413 | ((u32) scp->cmnd[2] << 8) | |
| 1414 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1415 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1416 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /* |
| 1420 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1421 | */ |
| 1422 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1423 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1424 | ((u32) scp->cmnd[7] << 8)); |
| 1425 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1426 | ((u32) scp->cmnd[3] << 16) | |
| 1427 | ((u32) scp->cmnd[4] << 8) | |
| 1428 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | /* |
| 1432 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1433 | */ |
| 1434 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1435 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1436 | ((u32) scp->cmnd[7] << 16) | |
| 1437 | ((u32) scp->cmnd[8] << 8) | |
| 1438 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1439 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1440 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1441 | ((u32) scp->cmnd[3] << 16) | |
| 1442 | ((u32) scp->cmnd[4] << 8) | |
| 1443 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1448 | */ |
| 1449 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1450 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1451 | ((u32) scp->cmnd[11] << 16) | |
| 1452 | ((u32) scp->cmnd[12] << 8) | |
| 1453 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1454 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1455 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1456 | ((u32) scp->cmnd[7] << 16) | |
| 1457 | ((u32) scp->cmnd[8] << 8) | |
| 1458 | (u32) scp->cmnd[9]); |
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_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1461 | ((u32) scp->cmnd[3] << 16) | |
| 1462 | ((u32) scp->cmnd[4] << 8) | |
| 1463 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1464 | |
| 1465 | } |
| 1466 | |
| 1467 | /* |
| 1468 | * Construct SGL |
| 1469 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1470 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1471 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1472 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1473 | &ldio->sgl); |
| 1474 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1475 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1476 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1477 | } else |
| 1478 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1479 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1480 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1481 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1482 | ldio->sge_count); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1486 | /* |
| 1487 | * Sense info specific |
| 1488 | */ |
| 1489 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1490 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1491 | 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] | 1492 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1493 | /* |
| 1494 | * Compute the total number of frames this command consumes. FW uses |
| 1495 | * this number to pull sufficient number of frames from host memory. |
| 1496 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1497 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1498 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1499 | |
| 1500 | return cmd->frame_count; |
| 1501 | } |
| 1502 | |
| 1503 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1504 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1505 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1506 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1507 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1508 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1509 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1510 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1511 | int ret; |
| 1512 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1513 | switch (cmd->cmnd[0]) { |
| 1514 | case READ_10: |
| 1515 | case WRITE_10: |
| 1516 | case READ_12: |
| 1517 | case WRITE_12: |
| 1518 | case READ_6: |
| 1519 | case WRITE_6: |
| 1520 | case READ_16: |
| 1521 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1522 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1523 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1524 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1525 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1526 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1527 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1528 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1529 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1532 | /** |
| 1533 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1534 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1535 | * @instance: Adapter soft state |
| 1536 | */ |
| 1537 | static inline void |
| 1538 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1539 | { |
| 1540 | struct megasas_cmd *cmd; |
| 1541 | int i,n; |
| 1542 | union megasas_sgl *mfi_sgl; |
| 1543 | struct megasas_io_frame *ldio; |
| 1544 | struct megasas_pthru_frame *pthru; |
| 1545 | u32 sgcount; |
| 1546 | u32 max_cmd = instance->max_fw_cmds; |
| 1547 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1548 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1549 | 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] | 1550 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1551 | 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] | 1552 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1553 | 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] | 1554 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1555 | 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] | 1556 | for (i = 0; i < max_cmd; i++) { |
| 1557 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1558 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1559 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1560 | 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] | 1561 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1562 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1563 | mfi_sgl = &ldio->sgl; |
| 1564 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1565 | 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] | 1566 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1567 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1568 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1569 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1570 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1571 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1572 | mfi_sgl = &pthru->sgl; |
| 1573 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1574 | 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] | 1575 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1576 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1577 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1578 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1579 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1580 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1581 | for (n = 0; n < sgcount; n++) { |
| 1582 | if (IS_DMA64) |
| 1583 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1584 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1585 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1586 | else |
| 1587 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1588 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1589 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1590 | } |
| 1591 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1592 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1593 | 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] | 1594 | for (i = 0; i < max_cmd; i++) { |
| 1595 | |
| 1596 | cmd = instance->cmd_list[i]; |
| 1597 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1598 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1599 | 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] | 1600 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1601 | 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] | 1602 | } |
| 1603 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1604 | u32 |
| 1605 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1606 | struct scsi_cmnd *scmd) |
| 1607 | { |
| 1608 | struct megasas_cmd *cmd; |
| 1609 | u32 frame_count; |
| 1610 | |
| 1611 | cmd = megasas_get_cmd(instance); |
| 1612 | if (!cmd) |
| 1613 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1614 | |
| 1615 | /* |
| 1616 | * Logical drive command |
| 1617 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1618 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1619 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1620 | else |
| 1621 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1622 | |
| 1623 | if (!frame_count) |
| 1624 | goto out_return_cmd; |
| 1625 | |
| 1626 | cmd->scmd = scmd; |
| 1627 | scmd->SCp.ptr = (char *)cmd; |
| 1628 | |
| 1629 | /* |
| 1630 | * Issue the command to the FW |
| 1631 | */ |
| 1632 | atomic_inc(&instance->fw_outstanding); |
| 1633 | |
| 1634 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1635 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1636 | |
| 1637 | return 0; |
| 1638 | out_return_cmd: |
| 1639 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1640 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1644 | /** |
| 1645 | * megasas_queue_command - Queue entry point |
| 1646 | * @scmd: SCSI command to be queued |
| 1647 | * @done: Callback entry point |
| 1648 | */ |
| 1649 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1650 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1651 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1652 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1653 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1654 | |
| 1655 | instance = (struct megasas_instance *) |
| 1656 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1657 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1658 | if (instance->unload == 1) { |
| 1659 | scmd->result = DID_NO_CONNECT << 16; |
| 1660 | scmd->scsi_done(scmd); |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1664 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1665 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1666 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1667 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1668 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1669 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1670 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame^] | 1671 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1672 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1673 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1674 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1675 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1676 | return 0; |
| 1677 | } |
| 1678 | } |
| 1679 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1680 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1681 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1682 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
| 1685 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1686 | mr_device_priv_data = scmd->device->hostdata; |
| 1687 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1688 | scmd->result = DID_NO_CONNECT << 16; |
| 1689 | scmd->scsi_done(scmd); |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1693 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1694 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1695 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1696 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1697 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1698 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1699 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1700 | scmd->result = 0; |
| 1701 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1702 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1703 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1704 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1705 | scmd->result = DID_BAD_TARGET << 16; |
| 1706 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1707 | } |
| 1708 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1709 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1710 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1711 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1712 | scmd->result = DID_OK << 16; |
| 1713 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1714 | } |
| 1715 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1716 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1717 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1718 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1719 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1720 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1723 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1724 | { |
| 1725 | int i; |
| 1726 | |
| 1727 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1728 | |
| 1729 | if ((megasas_mgmt_info.instance[i]) && |
| 1730 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1731 | return megasas_mgmt_info.instance[i]; |
| 1732 | } |
| 1733 | |
| 1734 | return NULL; |
| 1735 | } |
| 1736 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1737 | /* |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1738 | * megasas_update_sdev_properties - Update sdev structure based on controller's FW capabilities |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1739 | * |
| 1740 | * @sdev: OS provided scsi device |
| 1741 | * |
| 1742 | * Returns void |
| 1743 | */ |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1744 | void megasas_update_sdev_properties(struct scsi_device *sdev) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1745 | { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1746 | u16 pd_index = 0; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1747 | u32 device_id, ld; |
| 1748 | struct megasas_instance *instance; |
| 1749 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1750 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1751 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1752 | struct MR_LD_RAID *raid; |
| 1753 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1754 | |
| 1755 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1756 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1757 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1758 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1759 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1760 | return; |
| 1761 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1762 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1763 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1764 | + sdev->id; |
| 1765 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1766 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1767 | if (ld >= instance->fw_supported_vd_count) |
| 1768 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1769 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1770 | |
| 1771 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1772 | blk_queue_update_dma_alignment(sdev->request_queue, |
| 1773 | 0x7); |
| 1774 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1775 | mr_device_priv_data->is_tm_capable = |
| 1776 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1777 | } else if (instance->use_seqnum_jbod_fp) { |
| 1778 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1779 | sdev->id; |
| 1780 | pd_sync = (void *)fusion->pd_seq_sync |
| 1781 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1782 | mr_device_priv_data->is_tm_capable = |
| 1783 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1784 | } |
| 1785 | } |
| 1786 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1787 | static void megasas_set_device_queue_depth(struct scsi_device *sdev) |
| 1788 | { |
| 1789 | u16 pd_index = 0; |
| 1790 | int ret = DCMD_FAILED; |
| 1791 | struct megasas_instance *instance; |
| 1792 | |
| 1793 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1794 | |
| 1795 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) { |
| 1796 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
| 1797 | |
| 1798 | if (instance->pd_info) { |
| 1799 | mutex_lock(&instance->hba_mutex); |
| 1800 | ret = megasas_get_pd_info(instance, pd_index); |
| 1801 | mutex_unlock(&instance->hba_mutex); |
| 1802 | } |
| 1803 | |
| 1804 | if (ret != DCMD_SUCCESS) |
| 1805 | return; |
| 1806 | |
| 1807 | if (instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) { |
| 1808 | |
| 1809 | switch (instance->pd_list[pd_index].interface) { |
| 1810 | case SAS_PD: |
| 1811 | scsi_change_queue_depth(sdev, MEGASAS_SAS_QD); |
| 1812 | break; |
| 1813 | |
| 1814 | case SATA_PD: |
| 1815 | scsi_change_queue_depth(sdev, MEGASAS_SATA_QD); |
| 1816 | break; |
| 1817 | |
| 1818 | default: |
| 1819 | scsi_change_queue_depth(sdev, MEGASAS_DEFAULT_PD_QD); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1825 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1826 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1827 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1828 | u16 pd_index = 0; |
| 1829 | struct megasas_instance *instance; |
| 1830 | |
| 1831 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1832 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1833 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1834 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1835 | sdev->id; |
| 1836 | if (instance->pd_list[pd_index].driveState != |
| 1837 | MR_PD_STATE_SYSTEM) |
| 1838 | return -ENXIO; |
| 1839 | } |
| 1840 | } |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1841 | megasas_set_device_queue_depth(sdev); |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1842 | megasas_update_sdev_properties(sdev); |
| 1843 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1844 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1845 | * The RAID firmware may require extended timeouts. |
| 1846 | */ |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1847 | blk_queue_rq_timeout(sdev->request_queue, |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 1848 | scmd_timeout * HZ); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1849 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1850 | return 0; |
| 1851 | } |
| 1852 | |
| 1853 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1854 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1855 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1856 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1857 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1858 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1859 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1860 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1861 | /* |
| 1862 | * Open the OS scan to the SYSTEM PD |
| 1863 | */ |
| 1864 | pd_index = |
| 1865 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1866 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1867 | if ((instance->pd_list_not_supported || |
| 1868 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1869 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1870 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1871 | } |
| 1872 | return -ENXIO; |
| 1873 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1874 | |
| 1875 | scan_target: |
| 1876 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 1877 | GFP_KERNEL); |
| 1878 | if (!mr_device_priv_data) |
| 1879 | return -ENOMEM; |
| 1880 | sdev->hostdata = mr_device_priv_data; |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1881 | return 0; |
| 1882 | } |
| 1883 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1884 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 1885 | { |
| 1886 | kfree(sdev->hostdata); |
| 1887 | sdev->hostdata = NULL; |
| 1888 | } |
| 1889 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1890 | /* |
| 1891 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 1892 | * kill adapter |
| 1893 | * @instance: Adapter soft state |
| 1894 | * |
| 1895 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 1896 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1897 | { |
| 1898 | int i; |
| 1899 | struct megasas_cmd *cmd_mfi; |
| 1900 | struct megasas_cmd_fusion *cmd_fusion; |
| 1901 | struct fusion_context *fusion = instance->ctrl_context; |
| 1902 | |
| 1903 | /* Find all outstanding ioctls */ |
| 1904 | if (fusion) { |
| 1905 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1906 | cmd_fusion = fusion->cmd_list[i]; |
| 1907 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 1908 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 1909 | if (cmd_mfi->sync_cmd && |
| 1910 | cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT) |
| 1911 | megasas_complete_cmd(instance, |
| 1912 | cmd_mfi, DID_OK); |
| 1913 | } |
| 1914 | } |
| 1915 | } else { |
| 1916 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1917 | cmd_mfi = instance->cmd_list[i]; |
| 1918 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 1919 | MFI_CMD_ABORT) |
| 1920 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 1921 | } |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1926 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1927 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1928 | /* 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] | 1929 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1930 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 1931 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1932 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1933 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 1934 | (instance->ctrl_context)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1935 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1936 | /* Flush */ |
| 1937 | readl(&instance->reg_set->doorbell); |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 1938 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1939 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1940 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1941 | writel(MFI_STOP_ADP, |
| 1942 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1943 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1944 | /* Complete outstanding ioctls when adapter is killed */ |
| 1945 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 1950 | * restored to max value |
| 1951 | * @instance: Adapter soft state |
| 1952 | * |
| 1953 | */ |
| 1954 | void |
| 1955 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 1956 | { |
| 1957 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 1958 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1959 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 1960 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 1961 | && atomic_read(&instance->fw_outstanding) < |
| 1962 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1963 | |
| 1964 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 1965 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1966 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 1967 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1968 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1969 | } |
| 1970 | } |
| 1971 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1972 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1973 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 1974 | * @instance_addr: Address of adapter soft state |
| 1975 | * |
| 1976 | * Tasklet to complete cmds |
| 1977 | */ |
| 1978 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 1979 | { |
| 1980 | u32 producer; |
| 1981 | u32 consumer; |
| 1982 | u32 context; |
| 1983 | struct megasas_cmd *cmd; |
| 1984 | struct megasas_instance *instance = |
| 1985 | (struct megasas_instance *)instance_addr; |
| 1986 | unsigned long flags; |
| 1987 | |
| 1988 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1989 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1990 | return; |
| 1991 | |
| 1992 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 1993 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1994 | producer = le32_to_cpu(*instance->producer); |
| 1995 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1996 | |
| 1997 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1998 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1999 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2000 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2001 | context); |
| 2002 | BUG(); |
| 2003 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2004 | |
| 2005 | cmd = instance->cmd_list[context]; |
| 2006 | |
| 2007 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2008 | |
| 2009 | consumer++; |
| 2010 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2011 | consumer = 0; |
| 2012 | } |
| 2013 | } |
| 2014 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2015 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2016 | |
| 2017 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2018 | |
| 2019 | /* |
| 2020 | * Check if we can restore can_queue |
| 2021 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2022 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2023 | } |
| 2024 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2025 | /** |
| 2026 | * megasas_start_timer - Initializes a timer object |
| 2027 | * @instance: Adapter soft state |
| 2028 | * @timer: timer object to be initialized |
| 2029 | * @fn: timer function |
| 2030 | * @interval: time interval between timer function call |
| 2031 | * |
| 2032 | */ |
| 2033 | void megasas_start_timer(struct megasas_instance *instance, |
| 2034 | struct timer_list *timer, |
| 2035 | void *fn, unsigned long interval) |
| 2036 | { |
| 2037 | init_timer(timer); |
| 2038 | timer->expires = jiffies + interval; |
| 2039 | timer->data = (unsigned long)instance; |
| 2040 | timer->function = fn; |
| 2041 | add_timer(timer); |
| 2042 | } |
| 2043 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2044 | static void |
| 2045 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2046 | |
| 2047 | static void |
| 2048 | process_fw_state_change_wq(struct work_struct *work); |
| 2049 | |
| 2050 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2051 | { |
| 2052 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2053 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2054 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2055 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2056 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2057 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2058 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2059 | instance->issuepend_done = 0; |
| 2060 | |
| 2061 | atomic_set(&instance->fw_outstanding, 0); |
| 2062 | megasas_internal_reset_defer_cmds(instance); |
| 2063 | process_fw_state_change_wq(&instance->work_init); |
| 2064 | } |
| 2065 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2066 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2067 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2068 | { |
| 2069 | struct megasas_cmd *cmd; |
| 2070 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2071 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2072 | dma_addr_t new_affiliation_111_h; |
| 2073 | int ld, retval = 0; |
| 2074 | u8 thisVf; |
| 2075 | |
| 2076 | cmd = megasas_get_cmd(instance); |
| 2077 | |
| 2078 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2079 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2080 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2081 | instance->host->host_no); |
| 2082 | return -ENOMEM; |
| 2083 | } |
| 2084 | |
| 2085 | dcmd = &cmd->frame->dcmd; |
| 2086 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2087 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2088 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2089 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2090 | megasas_return_cmd(instance, cmd); |
| 2091 | return -ENOMEM; |
| 2092 | } |
| 2093 | |
| 2094 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2095 | memset(instance->vf_affiliation_111, 0, |
| 2096 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2097 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2098 | new_affiliation_111 = |
| 2099 | pci_alloc_consistent(instance->pdev, |
| 2100 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2101 | &new_affiliation_111_h); |
| 2102 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2103 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2104 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2105 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2106 | megasas_return_cmd(instance, cmd); |
| 2107 | return -ENOMEM; |
| 2108 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2109 | memset(new_affiliation_111, 0, |
| 2110 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2114 | |
| 2115 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2116 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2117 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2118 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2119 | dcmd->timeout = 0; |
| 2120 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2121 | dcmd->data_xfer_len = |
| 2122 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2123 | 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] | 2124 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2125 | if (initial) |
| 2126 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2127 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2128 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2129 | dcmd->sgl.sge32[0].phys_addr = |
| 2130 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2131 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2132 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2133 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2134 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2135 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2136 | "scsi%d\n", instance->host->host_no); |
| 2137 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2138 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2139 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2140 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2141 | dcmd->cmd_status, instance->host->host_no); |
| 2142 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2143 | goto out; |
| 2144 | } |
| 2145 | |
| 2146 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2147 | thisVf = new_affiliation_111->thisVf; |
| 2148 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2149 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2150 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2151 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2152 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2153 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2154 | memcpy(instance->vf_affiliation_111, |
| 2155 | new_affiliation_111, |
| 2156 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2157 | retval = 1; |
| 2158 | goto out; |
| 2159 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2160 | } |
| 2161 | out: |
| 2162 | if (new_affiliation_111) { |
| 2163 | pci_free_consistent(instance->pdev, |
| 2164 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2165 | new_affiliation_111, |
| 2166 | new_affiliation_111_h); |
| 2167 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2168 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2169 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2170 | |
| 2171 | return retval; |
| 2172 | } |
| 2173 | |
| 2174 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2175 | int initial) |
| 2176 | { |
| 2177 | struct megasas_cmd *cmd; |
| 2178 | struct megasas_dcmd_frame *dcmd; |
| 2179 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2180 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2181 | dma_addr_t new_affiliation_h; |
| 2182 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2183 | u8 thisVf; |
| 2184 | |
| 2185 | cmd = megasas_get_cmd(instance); |
| 2186 | |
| 2187 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2188 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2189 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2190 | instance->host->host_no); |
| 2191 | return -ENOMEM; |
| 2192 | } |
| 2193 | |
| 2194 | dcmd = &cmd->frame->dcmd; |
| 2195 | |
| 2196 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2197 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2198 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2199 | megasas_return_cmd(instance, cmd); |
| 2200 | return -ENOMEM; |
| 2201 | } |
| 2202 | |
| 2203 | if (initial) |
| 2204 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2205 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2206 | else { |
| 2207 | new_affiliation = |
| 2208 | pci_alloc_consistent(instance->pdev, |
| 2209 | (MAX_LOGICAL_DRIVES + 1) * |
| 2210 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2211 | &new_affiliation_h); |
| 2212 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2213 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2214 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2215 | instance->host->host_no); |
| 2216 | megasas_return_cmd(instance, cmd); |
| 2217 | return -ENOMEM; |
| 2218 | } |
| 2219 | memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2220 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2221 | } |
| 2222 | |
| 2223 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2224 | |
| 2225 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2226 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2227 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2228 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2229 | dcmd->timeout = 0; |
| 2230 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2231 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2232 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2233 | 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] | 2234 | |
| 2235 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2236 | dcmd->sgl.sge32[0].phys_addr = |
| 2237 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2238 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2239 | dcmd->sgl.sge32[0].phys_addr = |
| 2240 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2241 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2242 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2243 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2244 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2245 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2246 | "scsi%d\n", instance->host->host_no); |
| 2247 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2248 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2249 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2250 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2251 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2252 | dcmd->cmd_status, instance->host->host_no); |
| 2253 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2254 | goto out; |
| 2255 | } |
| 2256 | |
| 2257 | if (!initial) { |
| 2258 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2259 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2260 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2261 | instance->host->host_no); |
| 2262 | retval = 1; |
| 2263 | goto out; |
| 2264 | } |
| 2265 | newmap = new_affiliation->map; |
| 2266 | savedmap = instance->vf_affiliation->map; |
| 2267 | thisVf = new_affiliation->thisVf; |
| 2268 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2269 | found = 0; |
| 2270 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2271 | j++) { |
| 2272 | if (newmap->ref.targetId == |
| 2273 | savedmap->ref.targetId) { |
| 2274 | found = 1; |
| 2275 | if (newmap->policy[thisVf] != |
| 2276 | savedmap->policy[thisVf]) { |
| 2277 | doscan = 1; |
| 2278 | goto out; |
| 2279 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2280 | } |
| 2281 | savedmap = (struct MR_LD_VF_MAP *) |
| 2282 | ((unsigned char *)savedmap + |
| 2283 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2284 | } |
| 2285 | if (!found && newmap->policy[thisVf] != |
| 2286 | MR_LD_ACCESS_HIDDEN) { |
| 2287 | doscan = 1; |
| 2288 | goto out; |
| 2289 | } |
| 2290 | newmap = (struct MR_LD_VF_MAP *) |
| 2291 | ((unsigned char *)newmap + newmap->size); |
| 2292 | } |
| 2293 | |
| 2294 | newmap = new_affiliation->map; |
| 2295 | savedmap = instance->vf_affiliation->map; |
| 2296 | |
| 2297 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2298 | found = 0; |
| 2299 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2300 | if (savedmap->ref.targetId == |
| 2301 | newmap->ref.targetId) { |
| 2302 | found = 1; |
| 2303 | if (savedmap->policy[thisVf] != |
| 2304 | newmap->policy[thisVf]) { |
| 2305 | doscan = 1; |
| 2306 | goto out; |
| 2307 | } |
| 2308 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2309 | newmap = (struct MR_LD_VF_MAP *) |
| 2310 | ((unsigned char *)newmap + |
| 2311 | newmap->size); |
| 2312 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2313 | if (!found && savedmap->policy[thisVf] != |
| 2314 | MR_LD_ACCESS_HIDDEN) { |
| 2315 | doscan = 1; |
| 2316 | goto out; |
| 2317 | } |
| 2318 | savedmap = (struct MR_LD_VF_MAP *) |
| 2319 | ((unsigned char *)savedmap + |
| 2320 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2321 | } |
| 2322 | } |
| 2323 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2324 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2325 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2326 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2327 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2328 | new_affiliation->size); |
| 2329 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2330 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2331 | |
| 2332 | if (new_affiliation) |
| 2333 | pci_free_consistent(instance->pdev, |
| 2334 | (MAX_LOGICAL_DRIVES + 1) * |
| 2335 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2336 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2337 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2338 | |
| 2339 | return retval; |
| 2340 | } |
| 2341 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2342 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2343 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2344 | int initial) |
| 2345 | { |
| 2346 | int retval; |
| 2347 | |
| 2348 | if (instance->PlasmaFW111) |
| 2349 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2350 | else |
| 2351 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2352 | return retval; |
| 2353 | } |
| 2354 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2355 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2356 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2357 | int initial) |
| 2358 | { |
| 2359 | struct megasas_cmd *cmd; |
| 2360 | struct megasas_dcmd_frame *dcmd; |
| 2361 | int retval = 0; |
| 2362 | |
| 2363 | cmd = megasas_get_cmd(instance); |
| 2364 | |
| 2365 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2366 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2367 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2368 | instance->host->host_no); |
| 2369 | return -ENOMEM; |
| 2370 | } |
| 2371 | |
| 2372 | dcmd = &cmd->frame->dcmd; |
| 2373 | |
| 2374 | if (initial) { |
| 2375 | instance->hb_host_mem = |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 2376 | pci_zalloc_consistent(instance->pdev, |
| 2377 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2378 | &instance->hb_host_mem_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2379 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2380 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2381 | " memory for heartbeat host memory for scsi%d\n", |
| 2382 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2383 | retval = -ENOMEM; |
| 2384 | goto out; |
| 2385 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2389 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2390 | 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] | 2391 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2392 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2393 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2394 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2395 | dcmd->timeout = 0; |
| 2396 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2397 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2398 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
| 2399 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->hb_host_mem_h); |
| 2400 | 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] | 2401 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2402 | 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] | 2403 | instance->host->host_no); |
| 2404 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2405 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 2406 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2407 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2408 | else |
| 2409 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2410 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2411 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2412 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2413 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2414 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2415 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2416 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | out: |
| 2420 | megasas_return_cmd(instance, cmd); |
| 2421 | |
| 2422 | return retval; |
| 2423 | } |
| 2424 | |
| 2425 | /* Handler for SR-IOV heartbeat */ |
| 2426 | void megasas_sriov_heartbeat_handler(unsigned long instance_addr) |
| 2427 | { |
| 2428 | struct megasas_instance *instance = |
| 2429 | (struct megasas_instance *)instance_addr; |
| 2430 | |
| 2431 | if (instance->hb_host_mem->HB.fwCounter != |
| 2432 | instance->hb_host_mem->HB.driverCounter) { |
| 2433 | instance->hb_host_mem->HB.driverCounter = |
| 2434 | instance->hb_host_mem->HB.fwCounter; |
| 2435 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2436 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2437 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2438 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2439 | "completed for scsi%d\n", instance->host->host_no); |
| 2440 | schedule_work(&instance->work_init); |
| 2441 | } |
| 2442 | } |
| 2443 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2444 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2445 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2446 | * @instance: Adapter soft state |
| 2447 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2448 | * 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] | 2449 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2450 | * are pending after this time period. It also marks the controller dead. |
| 2451 | */ |
| 2452 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2453 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2454 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2455 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2456 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2457 | unsigned long flags; |
| 2458 | struct list_head clist_local; |
| 2459 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2460 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2461 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2462 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2463 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2464 | __func__, __LINE__); |
| 2465 | return FAILED; |
| 2466 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2467 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2468 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2469 | |
| 2470 | INIT_LIST_HEAD(&clist_local); |
| 2471 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2472 | list_splice_init(&instance->internal_reset_pending_q, |
| 2473 | &clist_local); |
| 2474 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2475 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2476 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2477 | for (i = 0; i < wait_time; i++) { |
| 2478 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2479 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2480 | break; |
| 2481 | } |
| 2482 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2483 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2484 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2485 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2486 | return FAILED; |
| 2487 | } |
| 2488 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2489 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2490 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2491 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2492 | struct megasas_cmd, list); |
| 2493 | list_del_init(&reset_cmd->list); |
| 2494 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame^] | 2495 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2496 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2497 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2498 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2499 | |
| 2500 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2501 | megasas_return_cmd(instance, reset_cmd); |
| 2502 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2503 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2504 | "reset queue\n", |
| 2505 | reset_cmd); |
| 2506 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2507 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2508 | instance->instancet->fire_cmd(instance, |
| 2509 | reset_cmd->frame_phys_addr, |
| 2510 | 0, instance->reg_set); |
| 2511 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2512 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2513 | "cmds lst\n", |
| 2514 | reset_cmd); |
| 2515 | } |
| 2516 | reset_index++; |
| 2517 | } |
| 2518 | |
| 2519 | return SUCCESS; |
| 2520 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2521 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2522 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2523 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2524 | |
| 2525 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2526 | break; |
| 2527 | |
| 2528 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2529 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2530 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2531 | /* |
| 2532 | * Call cmd completion routine. Cmd to be |
| 2533 | * be completed directly without depending on isr. |
| 2534 | */ |
| 2535 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | msleep(1000); |
| 2539 | } |
| 2540 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2541 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2542 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2543 | 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] | 2544 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2545 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2546 | goto no_outstanding; |
| 2547 | |
| 2548 | if (instance->disableOnlineCtrlReset) |
| 2549 | goto kill_hba_and_failed; |
| 2550 | do { |
| 2551 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2552 | dev_info(&instance->pdev->dev, |
| 2553 | "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, oustanding 0x%x\n", |
| 2554 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2555 | if (i == 3) |
| 2556 | goto kill_hba_and_failed; |
| 2557 | megasas_do_ocr(instance); |
| 2558 | |
| 2559 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2560 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2561 | __func__, __LINE__); |
| 2562 | return FAILED; |
| 2563 | } |
| 2564 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2565 | __func__, __LINE__); |
| 2566 | |
| 2567 | for (sl = 0; sl < 10; sl++) |
| 2568 | msleep(500); |
| 2569 | |
| 2570 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2571 | |
| 2572 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
| 2573 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2574 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2575 | } |
| 2576 | i++; |
| 2577 | } while (i <= 3); |
| 2578 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2579 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2580 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2581 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2582 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2583 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2584 | |
| 2585 | kill_hba_and_failed: |
| 2586 | |
| 2587 | /* Reset not supported, kill adapter */ |
| 2588 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2589 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2590 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2591 | atomic_read(&instance->fw_outstanding)); |
| 2592 | megasas_dump_pending_frames(instance); |
| 2593 | megaraid_sas_kill_hba(instance); |
| 2594 | |
| 2595 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | /** |
| 2599 | * megasas_generic_reset - Generic reset routine |
| 2600 | * @scmd: Mid-layer SCSI command |
| 2601 | * |
| 2602 | * This routine implements a generic reset handler for device, bus and host |
| 2603 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2604 | * function after they do their specific tasks. |
| 2605 | */ |
| 2606 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2607 | { |
| 2608 | int ret_val; |
| 2609 | struct megasas_instance *instance; |
| 2610 | |
| 2611 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2612 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2613 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2614 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2615 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2616 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2617 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2618 | return FAILED; |
| 2619 | } |
| 2620 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2621 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2622 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2623 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2624 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2625 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2626 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2627 | return ret_val; |
| 2628 | } |
| 2629 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2630 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2631 | * megasas_reset_timer - quiesce the adapter if required |
| 2632 | * @scmd: scsi cmnd |
| 2633 | * |
| 2634 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2635 | * cmd has not been completed within the timeout period. |
| 2636 | */ |
| 2637 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2638 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2639 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2640 | struct megasas_instance *instance; |
| 2641 | unsigned long flags; |
| 2642 | |
| 2643 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2644 | (scmd_timeout * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2645 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2648 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2649 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2650 | /* FW is busy, throttle IO */ |
| 2651 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2652 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2653 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2654 | instance->last_time = jiffies; |
| 2655 | instance->flag |= MEGASAS_FW_BUSY; |
| 2656 | |
| 2657 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2658 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2659 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2663 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2664 | */ |
| 2665 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2666 | { |
| 2667 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2668 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2669 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2670 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2671 | |
| 2672 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2673 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2674 | */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 2675 | if (instance->ctrl_context) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2676 | ret = megasas_reset_fusion(scmd->device->host, 1); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2677 | else |
| 2678 | ret = megasas_generic_reset(scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2679 | |
| 2680 | return ret; |
| 2681 | } |
| 2682 | |
| 2683 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2684 | * megasas_task_abort - Issues task abort request to firmware |
| 2685 | * (supported only for fusion adapters) |
| 2686 | * @scmd: SCSI command pointer |
| 2687 | */ |
| 2688 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 2689 | { |
| 2690 | int ret; |
| 2691 | struct megasas_instance *instance; |
| 2692 | |
| 2693 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2694 | |
| 2695 | if (instance->ctrl_context) |
| 2696 | ret = megasas_task_abort_fusion(scmd); |
| 2697 | else { |
| 2698 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 2699 | ret = FAILED; |
| 2700 | } |
| 2701 | |
| 2702 | return ret; |
| 2703 | } |
| 2704 | |
| 2705 | /** |
| 2706 | * megasas_reset_target: Issues target reset request to firmware |
| 2707 | * (supported only for fusion adapters) |
| 2708 | * @scmd: SCSI command pointer |
| 2709 | */ |
| 2710 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 2711 | { |
| 2712 | int ret; |
| 2713 | struct megasas_instance *instance; |
| 2714 | |
| 2715 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2716 | |
| 2717 | if (instance->ctrl_context) |
| 2718 | ret = megasas_reset_target_fusion(scmd); |
| 2719 | else { |
| 2720 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 2721 | ret = FAILED; |
| 2722 | } |
| 2723 | |
| 2724 | return ret; |
| 2725 | } |
| 2726 | |
| 2727 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2728 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2729 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2730 | * @bdev: block device |
| 2731 | * @capacity: drive capacity |
| 2732 | * @geom: geometry parameters |
| 2733 | */ |
| 2734 | static int |
| 2735 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2736 | sector_t capacity, int geom[]) |
| 2737 | { |
| 2738 | int heads; |
| 2739 | int sectors; |
| 2740 | sector_t cylinders; |
| 2741 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2742 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2743 | /* Default heads (64) & sectors (32) */ |
| 2744 | heads = 64; |
| 2745 | sectors = 32; |
| 2746 | |
| 2747 | tmp = heads * sectors; |
| 2748 | cylinders = capacity; |
| 2749 | |
| 2750 | sector_div(cylinders, tmp); |
| 2751 | |
| 2752 | /* |
| 2753 | * Handle extended translation size for logical drives > 1Gb |
| 2754 | */ |
| 2755 | |
| 2756 | if (capacity >= 0x200000) { |
| 2757 | heads = 255; |
| 2758 | sectors = 63; |
| 2759 | tmp = heads*sectors; |
| 2760 | cylinders = capacity; |
| 2761 | sector_div(cylinders, tmp); |
| 2762 | } |
| 2763 | |
| 2764 | geom[0] = heads; |
| 2765 | geom[1] = sectors; |
| 2766 | geom[2] = cylinders; |
| 2767 | |
| 2768 | return 0; |
| 2769 | } |
| 2770 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2771 | static void megasas_aen_polling(struct work_struct *work); |
| 2772 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2773 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2774 | * megasas_service_aen - Processes an event notification |
| 2775 | * @instance: Adapter soft state |
| 2776 | * @cmd: AEN command completed by the ISR |
| 2777 | * |
| 2778 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2779 | * event occurs. When an event of interest occurs, FW completes the command |
| 2780 | * that it was previously holding. |
| 2781 | * |
| 2782 | * This routines sends SIGIO signal to processes that have registered with the |
| 2783 | * driver for AEN. |
| 2784 | */ |
| 2785 | static void |
| 2786 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2787 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2788 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2789 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2790 | /* |
| 2791 | * Don't signal app if it is just an aborted previously registered aen |
| 2792 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2793 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2794 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2795 | megasas_poll_wait_aen = 1; |
| 2796 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2797 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2798 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2799 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2800 | else |
| 2801 | cmd->abort_aen = 0; |
| 2802 | |
| 2803 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2804 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2805 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2806 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2807 | if ((instance->unload == 0) && |
| 2808 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2809 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2810 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2811 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2812 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2813 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2814 | } else { |
| 2815 | ev->instance = instance; |
| 2816 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2817 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2818 | megasas_aen_polling); |
| 2819 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2820 | } |
| 2821 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2822 | } |
| 2823 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2824 | static ssize_t |
| 2825 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 2826 | struct device_attribute *attr, const char *buf, size_t count) |
| 2827 | { |
| 2828 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2829 | struct megasas_instance *instance = |
| 2830 | (struct megasas_instance *) shost->hostdata; |
| 2831 | int val = 0; |
| 2832 | unsigned long flags; |
| 2833 | |
| 2834 | if (kstrtoint(buf, 0, &val) != 0) |
| 2835 | return -EINVAL; |
| 2836 | |
| 2837 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2838 | instance->fw_crash_buffer_offset = val; |
| 2839 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2840 | return strlen(buf); |
| 2841 | } |
| 2842 | |
| 2843 | static ssize_t |
| 2844 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 2845 | struct device_attribute *attr, char *buf) |
| 2846 | { |
| 2847 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2848 | struct megasas_instance *instance = |
| 2849 | (struct megasas_instance *) shost->hostdata; |
| 2850 | u32 size; |
| 2851 | unsigned long buff_addr; |
| 2852 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 2853 | unsigned long src_addr; |
| 2854 | unsigned long flags; |
| 2855 | u32 buff_offset; |
| 2856 | |
| 2857 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2858 | buff_offset = instance->fw_crash_buffer_offset; |
| 2859 | if (!instance->crash_dump_buf && |
| 2860 | !((instance->fw_crash_state == AVAILABLE) || |
| 2861 | (instance->fw_crash_state == COPYING))) { |
| 2862 | dev_err(&instance->pdev->dev, |
| 2863 | "Firmware crash dump is not available\n"); |
| 2864 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2865 | return -EINVAL; |
| 2866 | } |
| 2867 | |
| 2868 | buff_addr = (unsigned long) buf; |
| 2869 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2870 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2871 | dev_err(&instance->pdev->dev, |
| 2872 | "Firmware crash dump offset is out of range\n"); |
| 2873 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2874 | return 0; |
| 2875 | } |
| 2876 | |
| 2877 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 2878 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 2879 | |
| 2880 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 2881 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2882 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2883 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2884 | |
| 2885 | return size; |
| 2886 | } |
| 2887 | |
| 2888 | static ssize_t |
| 2889 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 2890 | struct device_attribute *attr, char *buf) |
| 2891 | { |
| 2892 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2893 | struct megasas_instance *instance = |
| 2894 | (struct megasas_instance *) shost->hostdata; |
| 2895 | |
| 2896 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 2897 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 2898 | } |
| 2899 | |
| 2900 | static ssize_t |
| 2901 | megasas_fw_crash_state_store(struct device *cdev, |
| 2902 | struct device_attribute *attr, const char *buf, size_t count) |
| 2903 | { |
| 2904 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2905 | struct megasas_instance *instance = |
| 2906 | (struct megasas_instance *) shost->hostdata; |
| 2907 | int val = 0; |
| 2908 | unsigned long flags; |
| 2909 | |
| 2910 | if (kstrtoint(buf, 0, &val) != 0) |
| 2911 | return -EINVAL; |
| 2912 | |
| 2913 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 2914 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 2915 | "firmware crash state\n"); |
| 2916 | return -EINVAL; |
| 2917 | } |
| 2918 | |
| 2919 | instance->fw_crash_state = val; |
| 2920 | |
| 2921 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 2922 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2923 | megasas_free_host_crash_buffer(instance); |
| 2924 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2925 | if (val == COPY_ERROR) |
| 2926 | dev_info(&instance->pdev->dev, "application failed to " |
| 2927 | "copy Firmware crash dump\n"); |
| 2928 | else |
| 2929 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 2930 | "copied successfully\n"); |
| 2931 | } |
| 2932 | return strlen(buf); |
| 2933 | } |
| 2934 | |
| 2935 | static ssize_t |
| 2936 | megasas_fw_crash_state_show(struct device *cdev, |
| 2937 | struct device_attribute *attr, char *buf) |
| 2938 | { |
| 2939 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2940 | struct megasas_instance *instance = |
| 2941 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2942 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2943 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 2944 | } |
| 2945 | |
| 2946 | static ssize_t |
| 2947 | megasas_page_size_show(struct device *cdev, |
| 2948 | struct device_attribute *attr, char *buf) |
| 2949 | { |
| 2950 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 2951 | } |
| 2952 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2953 | static ssize_t |
| 2954 | megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
| 2955 | char *buf) |
| 2956 | { |
| 2957 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2958 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 2959 | |
| 2960 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 2961 | } |
| 2962 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2963 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 2964 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 2965 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 2966 | megasas_fw_crash_buffer_size_show, NULL); |
| 2967 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 2968 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 2969 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 2970 | megasas_page_size_show, NULL); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2971 | static DEVICE_ATTR(ldio_outstanding, S_IRUGO, |
| 2972 | megasas_ldio_outstanding_show, NULL); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2973 | |
| 2974 | struct device_attribute *megaraid_host_attrs[] = { |
| 2975 | &dev_attr_fw_crash_buffer_size, |
| 2976 | &dev_attr_fw_crash_buffer, |
| 2977 | &dev_attr_fw_crash_state, |
| 2978 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2979 | &dev_attr_ldio_outstanding, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2980 | NULL, |
| 2981 | }; |
| 2982 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2983 | /* |
| 2984 | * Scsi host template for megaraid_sas driver |
| 2985 | */ |
| 2986 | static struct scsi_host_template megasas_template = { |
| 2987 | |
| 2988 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 2989 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2990 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2991 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2992 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2993 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2994 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2995 | .eh_target_reset_handler = megasas_reset_target, |
| 2996 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2997 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2998 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2999 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3000 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3001 | .use_clustering = ENABLE_CLUSTERING, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3002 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3003 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3004 | }; |
| 3005 | |
| 3006 | /** |
| 3007 | * megasas_complete_int_cmd - Completes an internal command |
| 3008 | * @instance: Adapter soft state |
| 3009 | * @cmd: Command to be completed |
| 3010 | * |
| 3011 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3012 | * after it issues a command. This function wakes up that waiting routine by |
| 3013 | * calling wake_up() on the wait queue. |
| 3014 | */ |
| 3015 | static void |
| 3016 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3017 | struct megasas_cmd *cmd) |
| 3018 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3019 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3020 | wake_up(&instance->int_cmd_wait_q); |
| 3021 | } |
| 3022 | |
| 3023 | /** |
| 3024 | * megasas_complete_abort - Completes aborting a command |
| 3025 | * @instance: Adapter soft state |
| 3026 | * @cmd: Cmd that was issued to abort another cmd |
| 3027 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3028 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3029 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3030 | * wakes up all functions waiting on the same wait queue. |
| 3031 | */ |
| 3032 | static void |
| 3033 | megasas_complete_abort(struct megasas_instance *instance, |
| 3034 | struct megasas_cmd *cmd) |
| 3035 | { |
| 3036 | if (cmd->sync_cmd) { |
| 3037 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3038 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3039 | wake_up(&instance->abort_cmd_wait_q); |
| 3040 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3044 | * megasas_complete_cmd - Completes a command |
| 3045 | * @instance: Adapter soft state |
| 3046 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3047 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3048 | * SCSI mid-layer instead of the value returned |
| 3049 | * by the FW. This should be used if caller wants |
| 3050 | * an alternate status (as in the case of aborted |
| 3051 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3052 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3053 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3054 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3055 | u8 alt_status) |
| 3056 | { |
| 3057 | int exception = 0; |
| 3058 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3059 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3060 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3061 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3062 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3063 | /* flag for the retry reset */ |
| 3064 | cmd->retry_for_fw_reset = 0; |
| 3065 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3066 | if (cmd->scmd) |
| 3067 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3068 | |
| 3069 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3070 | case MFI_CMD_INVALID: |
| 3071 | /* Some older 1068 controller FW may keep a pended |
| 3072 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3073 | when booting the kdump kernel. Ignore this command to |
| 3074 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3075 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3076 | "completed\n"); |
| 3077 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3078 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3079 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3080 | case MFI_CMD_PD_SCSI_IO: |
| 3081 | case MFI_CMD_LD_SCSI_IO: |
| 3082 | |
| 3083 | /* |
| 3084 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3085 | * issued either through an IO path or an IOCTL path. If it |
| 3086 | * was via IOCTL, we will send it to internal completion. |
| 3087 | */ |
| 3088 | if (cmd->sync_cmd) { |
| 3089 | cmd->sync_cmd = 0; |
| 3090 | megasas_complete_int_cmd(instance, cmd); |
| 3091 | break; |
| 3092 | } |
| 3093 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3094 | case MFI_CMD_LD_READ: |
| 3095 | case MFI_CMD_LD_WRITE: |
| 3096 | |
| 3097 | if (alt_status) { |
| 3098 | cmd->scmd->result = alt_status << 16; |
| 3099 | exception = 1; |
| 3100 | } |
| 3101 | |
| 3102 | if (exception) { |
| 3103 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3104 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3105 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3106 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3107 | cmd->scmd->scsi_done(cmd->scmd); |
| 3108 | megasas_return_cmd(instance, cmd); |
| 3109 | |
| 3110 | break; |
| 3111 | } |
| 3112 | |
| 3113 | switch (hdr->cmd_status) { |
| 3114 | |
| 3115 | case MFI_STAT_OK: |
| 3116 | cmd->scmd->result = DID_OK << 16; |
| 3117 | break; |
| 3118 | |
| 3119 | case MFI_STAT_SCSI_IO_FAILED: |
| 3120 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3121 | cmd->scmd->result = |
| 3122 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3123 | break; |
| 3124 | |
| 3125 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3126 | |
| 3127 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3128 | |
| 3129 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3130 | memset(cmd->scmd->sense_buffer, 0, |
| 3131 | SCSI_SENSE_BUFFERSIZE); |
| 3132 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3133 | hdr->sense_len); |
| 3134 | |
| 3135 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3136 | } |
| 3137 | |
| 3138 | break; |
| 3139 | |
| 3140 | case MFI_STAT_LD_OFFLINE: |
| 3141 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3142 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3143 | break; |
| 3144 | |
| 3145 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3146 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3147 | hdr->cmd_status); |
| 3148 | cmd->scmd->result = DID_ERROR << 16; |
| 3149 | break; |
| 3150 | } |
| 3151 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3152 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3153 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3154 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3155 | cmd->scmd->scsi_done(cmd->scmd); |
| 3156 | megasas_return_cmd(instance, cmd); |
| 3157 | |
| 3158 | break; |
| 3159 | |
| 3160 | case MFI_CMD_SMP: |
| 3161 | case MFI_CMD_STP: |
| 3162 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3163 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3164 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3165 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3166 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3167 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3168 | spin_lock_irqsave(instance->host->host_lock, flags); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3169 | instance->map_update_cmd = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3170 | if (cmd->frame->hdr.cmd_status != 0) { |
| 3171 | if (cmd->frame->hdr.cmd_status != |
| 3172 | MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3173 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3174 | cmd->frame->hdr.cmd_status); |
| 3175 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3176 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3177 | spin_unlock_irqrestore( |
| 3178 | instance->host->host_lock, |
| 3179 | flags); |
| 3180 | break; |
| 3181 | } |
| 3182 | } else |
| 3183 | instance->map_id++; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3184 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3185 | |
| 3186 | /* |
| 3187 | * Set fast path IO to ZERO. |
| 3188 | * Validate Map will set proper value. |
| 3189 | * Meanwhile all IOs will go as LD IO. |
| 3190 | */ |
| 3191 | if (MR_ValidateMapInfo(instance)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3192 | fusion->fast_path_io = 1; |
| 3193 | else |
| 3194 | fusion->fast_path_io = 0; |
| 3195 | megasas_sync_map_info(instance); |
| 3196 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3197 | flags); |
| 3198 | break; |
| 3199 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3200 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3201 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3202 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3203 | megasas_poll_wait_aen = 0; |
| 3204 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3205 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3206 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3207 | /* FW has an updated PD sequence */ |
| 3208 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3209 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3210 | |
| 3211 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3212 | status = cmd->frame->hdr.cmd_status; |
| 3213 | instance->jbod_seq_cmd = NULL; |
| 3214 | megasas_return_cmd(instance, cmd); |
| 3215 | |
| 3216 | if (status == MFI_STAT_OK) { |
| 3217 | instance->pd_seq_map_id++; |
| 3218 | /* Re-register a pd sync seq num cmd */ |
| 3219 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3220 | instance->use_seqnum_jbod_fp = false; |
| 3221 | } else |
| 3222 | instance->use_seqnum_jbod_fp = false; |
| 3223 | |
| 3224 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3225 | break; |
| 3226 | } |
| 3227 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3228 | /* |
| 3229 | * See if got an event notification |
| 3230 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3231 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3232 | megasas_service_aen(instance, cmd); |
| 3233 | else |
| 3234 | megasas_complete_int_cmd(instance, cmd); |
| 3235 | |
| 3236 | break; |
| 3237 | |
| 3238 | case MFI_CMD_ABORT: |
| 3239 | /* |
| 3240 | * Cmd issued to abort another cmd returned |
| 3241 | */ |
| 3242 | megasas_complete_abort(instance, cmd); |
| 3243 | break; |
| 3244 | |
| 3245 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3246 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3247 | hdr->cmd); |
| 3248 | break; |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3253 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3254 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3255 | * @instance: Adapter soft state |
| 3256 | */ |
| 3257 | static inline void |
| 3258 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3259 | { |
| 3260 | struct megasas_cmd *cmd; |
| 3261 | struct list_head clist_local; |
| 3262 | union megasas_evt_class_locale class_locale; |
| 3263 | unsigned long flags; |
| 3264 | u32 seq_num; |
| 3265 | |
| 3266 | INIT_LIST_HEAD(&clist_local); |
| 3267 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3268 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3269 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3270 | |
| 3271 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3272 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3273 | struct megasas_cmd, list); |
| 3274 | list_del_init(&cmd->list); |
| 3275 | |
| 3276 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3277 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3278 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3279 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3280 | |
| 3281 | cmd->retry_for_fw_reset++; |
| 3282 | |
| 3283 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3284 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3285 | "was tried multiple times during reset." |
| 3286 | "Shutting down the HBA\n", |
| 3287 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3288 | instance->instancet->disable_intr(instance); |
| 3289 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3290 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3291 | return; |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | if (cmd->sync_cmd == 1) { |
| 3296 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3297 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3298 | "cmd attached to internal command!\n"); |
| 3299 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3300 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3301 | "on the internal reset queue," |
| 3302 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3303 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3304 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3305 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3306 | 0, instance->reg_set); |
| 3307 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3308 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3309 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3310 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3311 | |
| 3312 | atomic_inc(&instance->fw_outstanding); |
| 3313 | instance->instancet->fire_cmd(instance, |
| 3314 | cmd->frame_phys_addr, |
| 3315 | cmd->frame_count-1, instance->reg_set); |
| 3316 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3317 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3318 | "internal reset defer list while re-issue!!\n", |
| 3319 | cmd); |
| 3320 | } |
| 3321 | } |
| 3322 | |
| 3323 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3324 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3325 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3326 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3327 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3331 | * Initiate AEN (Asynchronous Event Notification) |
| 3332 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3333 | seq_num = instance->last_seq_num; |
| 3334 | class_locale.members.reserved = 0; |
| 3335 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3336 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3337 | |
| 3338 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3339 | } |
| 3340 | |
| 3341 | /** |
| 3342 | * Move the internal reset pending commands to a deferred queue. |
| 3343 | * |
| 3344 | * We move the commands pending at internal reset time to a |
| 3345 | * pending queue. This queue would be flushed after successful |
| 3346 | * completion of the internal reset sequence. if the internal reset |
| 3347 | * did not complete in time, the kernel reset handler would flush |
| 3348 | * these commands. |
| 3349 | **/ |
| 3350 | static void |
| 3351 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3352 | { |
| 3353 | struct megasas_cmd *cmd; |
| 3354 | int i; |
| 3355 | u32 max_cmd = instance->max_fw_cmds; |
| 3356 | u32 defer_index; |
| 3357 | unsigned long flags; |
| 3358 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3359 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3360 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3361 | for (i = 0; i < max_cmd; i++) { |
| 3362 | cmd = instance->cmd_list[i]; |
| 3363 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3364 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3365 | "on the defer queue as internal\n", |
| 3366 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3367 | |
| 3368 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3369 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3370 | " moving this cmd:%p, %d %p, it was" |
| 3371 | "discovered on some list?\n", |
| 3372 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3373 | |
| 3374 | list_del_init(&cmd->list); |
| 3375 | } |
| 3376 | defer_index++; |
| 3377 | list_add_tail(&cmd->list, |
| 3378 | &instance->internal_reset_pending_q); |
| 3379 | } |
| 3380 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3381 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | |
| 3385 | static void |
| 3386 | process_fw_state_change_wq(struct work_struct *work) |
| 3387 | { |
| 3388 | struct megasas_instance *instance = |
| 3389 | container_of(work, struct megasas_instance, work_init); |
| 3390 | u32 wait; |
| 3391 | unsigned long flags; |
| 3392 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3393 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3394 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3395 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3396 | return ; |
| 3397 | } |
| 3398 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3399 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3400 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3401 | "state, restarting it...\n"); |
| 3402 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3403 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3404 | atomic_set(&instance->fw_outstanding, 0); |
| 3405 | |
| 3406 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3407 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3408 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3409 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3410 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3411 | "initiating next stage...\n"); |
| 3412 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3413 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3414 | "state 2 starting...\n"); |
| 3415 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3416 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3417 | for (wait = 0; wait < 30; wait++) { |
| 3418 | msleep(1000); |
| 3419 | } |
| 3420 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3421 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3422 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3423 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3424 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3425 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3426 | return ; |
| 3427 | } |
| 3428 | |
| 3429 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3430 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3431 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3432 | ) { |
| 3433 | *instance->consumer = *instance->producer; |
| 3434 | } else { |
| 3435 | *instance->consumer = 0; |
| 3436 | *instance->producer = 0; |
| 3437 | } |
| 3438 | |
| 3439 | megasas_issue_init_mfi(instance); |
| 3440 | |
| 3441 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3442 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3443 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3444 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3445 | |
| 3446 | megasas_issue_pending_cmds_again(instance); |
| 3447 | instance->issuepend_done = 1; |
| 3448 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3452 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3453 | * @instance: Adapter soft state |
| 3454 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3455 | * SCSI mid-layer instead of the status |
| 3456 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3457 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3458 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3459 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3460 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3461 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3462 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3463 | u32 mfiStatus; |
| 3464 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3465 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3466 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3467 | instance->reg_set)) == 1) { |
| 3468 | return IRQ_HANDLED; |
| 3469 | } |
| 3470 | |
| 3471 | if ((mfiStatus = instance->instancet->clear_intr( |
| 3472 | instance->reg_set) |
| 3473 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3474 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3475 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3476 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | instance->mfiStatus = mfiStatus; |
| 3480 | |
| 3481 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3482 | fw_state = instance->instancet->read_fw_status_reg( |
| 3483 | instance->reg_set) & MFI_STATE_MASK; |
| 3484 | |
| 3485 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3486 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3487 | fw_state); |
| 3488 | } |
| 3489 | |
| 3490 | if ((fw_state == MFI_STATE_FAULT) && |
| 3491 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3492 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3493 | |
| 3494 | if ((instance->pdev->device == |
| 3495 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3496 | (instance->pdev->device == |
| 3497 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3498 | (instance->pdev->device == |
| 3499 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3500 | |
| 3501 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3502 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3506 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3507 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3508 | instance->issuepend_done = 0; |
| 3509 | |
| 3510 | atomic_set(&instance->fw_outstanding, 0); |
| 3511 | megasas_internal_reset_defer_cmds(instance); |
| 3512 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3513 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3514 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3515 | |
| 3516 | schedule_work(&instance->work_init); |
| 3517 | return IRQ_HANDLED; |
| 3518 | |
| 3519 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3520 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3521 | fw_state, instance->disableOnlineCtrlReset); |
| 3522 | } |
| 3523 | } |
| 3524 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3525 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3526 | return IRQ_HANDLED; |
| 3527 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3528 | /** |
| 3529 | * megasas_isr - isr entry point |
| 3530 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3531 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3532 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3533 | struct megasas_irq_context *irq_context = devp; |
| 3534 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3535 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3536 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3537 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3538 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3539 | return IRQ_HANDLED; |
| 3540 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3541 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3542 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3543 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3544 | |
| 3545 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | /** |
| 3549 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3550 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3551 | * |
| 3552 | * During the initialization, FW passes can potentially be in any one of |
| 3553 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3554 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3555 | * has to wait for the ready state. |
| 3556 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3557 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3558 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3559 | { |
| 3560 | int i; |
| 3561 | u8 max_wait; |
| 3562 | u32 fw_state; |
| 3563 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3564 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3565 | |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3566 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3567 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3568 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3569 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3570 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3571 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3572 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3573 | while (fw_state != MFI_STATE_READY) { |
| 3574 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3575 | switch (fw_state) { |
| 3576 | |
| 3577 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3578 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3579 | if (ocr) { |
| 3580 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3581 | cur_state = MFI_STATE_FAULT; |
| 3582 | break; |
| 3583 | } else |
| 3584 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3585 | |
| 3586 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3587 | /* |
| 3588 | * Set the CLR bit in inbound doorbell |
| 3589 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3590 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3591 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3592 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3593 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3594 | (instance->ctrl_context)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3595 | writel( |
| 3596 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3597 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3598 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3599 | writel( |
| 3600 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3601 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3602 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3603 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3604 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3605 | break; |
| 3606 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3607 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3608 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3609 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3610 | (instance->pdev->device == |
| 3611 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3612 | (instance->ctrl_context)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3613 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3614 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3615 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3616 | writel(MFI_INIT_HOTPLUG, |
| 3617 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3618 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3619 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3620 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3621 | break; |
| 3622 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3623 | case MFI_STATE_OPERATIONAL: |
| 3624 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3625 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3626 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3627 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3628 | if ((instance->pdev->device == |
| 3629 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3630 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3631 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3632 | (instance->ctrl_context)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3633 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3634 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3635 | |
| 3636 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3637 | for (i = 0; i < (10 * 1000); i += 20) { |
| 3638 | if (readl( |
| 3639 | &instance-> |
| 3640 | reg_set-> |
| 3641 | doorbell) & 1) |
| 3642 | msleep(20); |
| 3643 | else |
| 3644 | break; |
| 3645 | } |
| 3646 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3647 | } else |
| 3648 | writel(MFI_RESET_FLAGS, |
| 3649 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3650 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3651 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3652 | cur_state = MFI_STATE_OPERATIONAL; |
| 3653 | break; |
| 3654 | |
| 3655 | case MFI_STATE_UNDEFINED: |
| 3656 | /* |
| 3657 | * This state should not last for more than 2 seconds |
| 3658 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3659 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3660 | cur_state = MFI_STATE_UNDEFINED; |
| 3661 | break; |
| 3662 | |
| 3663 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3664 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3665 | cur_state = MFI_STATE_BB_INIT; |
| 3666 | break; |
| 3667 | |
| 3668 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3669 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3670 | cur_state = MFI_STATE_FW_INIT; |
| 3671 | break; |
| 3672 | |
| 3673 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3674 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3675 | cur_state = MFI_STATE_FW_INIT_2; |
| 3676 | break; |
| 3677 | |
| 3678 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3679 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3680 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3681 | break; |
| 3682 | |
| 3683 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3684 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3685 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3686 | break; |
| 3687 | |
| 3688 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3689 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3690 | fw_state); |
| 3691 | return -ENODEV; |
| 3692 | } |
| 3693 | |
| 3694 | /* |
| 3695 | * The cur_state should not last for more than max_wait secs |
| 3696 | */ |
| 3697 | for (i = 0; i < (max_wait * 1000); i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3698 | curr_abs_state = instance->instancet-> |
| 3699 | read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3700 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3701 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3702 | msleep(1); |
| 3703 | } else |
| 3704 | break; |
| 3705 | } |
| 3706 | |
| 3707 | /* |
| 3708 | * Return error if fw_state hasn't changed after max_wait |
| 3709 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3710 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3711 | 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] | 3712 | "in %d secs\n", fw_state, max_wait); |
| 3713 | return -ENODEV; |
| 3714 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3715 | |
| 3716 | abs_state = curr_abs_state; |
| 3717 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3718 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3719 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3720 | |
| 3721 | return 0; |
| 3722 | } |
| 3723 | |
| 3724 | /** |
| 3725 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3726 | * @instance: Adapter soft state |
| 3727 | */ |
| 3728 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3729 | { |
| 3730 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3731 | u32 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3732 | struct megasas_cmd *cmd; |
| 3733 | |
| 3734 | if (!instance->frame_dma_pool) |
| 3735 | return; |
| 3736 | |
| 3737 | /* |
| 3738 | * Return all frames to pool |
| 3739 | */ |
| 3740 | for (i = 0; i < max_cmd; i++) { |
| 3741 | |
| 3742 | cmd = instance->cmd_list[i]; |
| 3743 | |
| 3744 | if (cmd->frame) |
| 3745 | pci_pool_free(instance->frame_dma_pool, cmd->frame, |
| 3746 | cmd->frame_phys_addr); |
| 3747 | |
| 3748 | if (cmd->sense) |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3749 | pci_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3750 | cmd->sense_phys_addr); |
| 3751 | } |
| 3752 | |
| 3753 | /* |
| 3754 | * Now destroy the pool itself |
| 3755 | */ |
| 3756 | pci_pool_destroy(instance->frame_dma_pool); |
| 3757 | pci_pool_destroy(instance->sense_dma_pool); |
| 3758 | |
| 3759 | instance->frame_dma_pool = NULL; |
| 3760 | instance->sense_dma_pool = NULL; |
| 3761 | } |
| 3762 | |
| 3763 | /** |
| 3764 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3765 | * @instance: Adapter soft state |
| 3766 | * |
| 3767 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3768 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3769 | * function creates those DMA memory buffers for each command packet by using |
| 3770 | * PCI pool facility. |
| 3771 | */ |
| 3772 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3773 | { |
| 3774 | int i; |
| 3775 | u32 max_cmd; |
| 3776 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3777 | u32 total_sz; |
| 3778 | u32 frame_count; |
| 3779 | struct megasas_cmd *cmd; |
| 3780 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3781 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3782 | |
| 3783 | /* |
| 3784 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 3785 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 3786 | */ |
| 3787 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 3788 | sizeof(struct megasas_sge32); |
| 3789 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3790 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3791 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3792 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3793 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3794 | * For MFI controllers. |
| 3795 | * max_num_sge = 60 |
| 3796 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 3797 | * Total 960 byte (15 MFI frame of 64 byte) |
| 3798 | * |
| 3799 | * Fusion adapter require only 3 extra frame. |
| 3800 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 3801 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 3802 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3803 | */ |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3804 | frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3805 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; |
| 3806 | /* |
| 3807 | * Use DMA pool facility provided by PCI layer |
| 3808 | */ |
| 3809 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3810 | instance->pdev, total_sz, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3811 | |
| 3812 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3813 | 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] | 3814 | return -ENOMEM; |
| 3815 | } |
| 3816 | |
| 3817 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", |
| 3818 | instance->pdev, 128, 4, 0); |
| 3819 | |
| 3820 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3821 | 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] | 3822 | |
| 3823 | pci_pool_destroy(instance->frame_dma_pool); |
| 3824 | instance->frame_dma_pool = NULL; |
| 3825 | |
| 3826 | return -ENOMEM; |
| 3827 | } |
| 3828 | |
| 3829 | /* |
| 3830 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 3831 | * By making cmd->index as the context instead of the &cmd, we can |
| 3832 | * always use 32bit context regardless of the architecture |
| 3833 | */ |
| 3834 | for (i = 0; i < max_cmd; i++) { |
| 3835 | |
| 3836 | cmd = instance->cmd_list[i]; |
| 3837 | |
| 3838 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, |
| 3839 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 3840 | |
| 3841 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, |
| 3842 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 3843 | |
| 3844 | /* |
| 3845 | * megasas_teardown_frame_pool() takes care of freeing |
| 3846 | * whatever has been allocated |
| 3847 | */ |
| 3848 | if (!cmd->frame || !cmd->sense) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3849 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "pci_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3850 | megasas_teardown_frame_pool(instance); |
| 3851 | return -ENOMEM; |
| 3852 | } |
| 3853 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 3854 | memset(cmd->frame, 0, total_sz); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3855 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3856 | cmd->frame->io.pad_0 = 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3857 | if (!instance->ctrl_context && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3858 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | return 0; |
| 3862 | } |
| 3863 | |
| 3864 | /** |
| 3865 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 3866 | * @instance: Adapter soft state |
| 3867 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3868 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3869 | { |
| 3870 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3871 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3872 | /* First free the MFI frame pool */ |
| 3873 | megasas_teardown_frame_pool(instance); |
| 3874 | |
| 3875 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3876 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 3877 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3878 | kfree(instance->cmd_list[i]); |
| 3879 | |
| 3880 | /* Free the cmd_list buffer itself */ |
| 3881 | kfree(instance->cmd_list); |
| 3882 | instance->cmd_list = NULL; |
| 3883 | |
| 3884 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 3885 | } |
| 3886 | |
| 3887 | /** |
| 3888 | * megasas_alloc_cmds - Allocates the command packets |
| 3889 | * @instance: Adapter soft state |
| 3890 | * |
| 3891 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 3892 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 3893 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 3894 | * the FW. |
| 3895 | * |
| 3896 | * Each frame has a 32-bit field called context (tag). This context is used |
| 3897 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 3898 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 3899 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 3900 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 3901 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 3902 | * This array is used only to look up the megasas_cmd given the context. The |
| 3903 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 3904 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3905 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3906 | { |
| 3907 | int i; |
| 3908 | int j; |
| 3909 | u32 max_cmd; |
| 3910 | struct megasas_cmd *cmd; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3911 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3912 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3913 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3914 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3915 | |
| 3916 | /* |
| 3917 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 3918 | * Allocate the dynamic array first and then allocate individual |
| 3919 | * commands. |
| 3920 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 3921 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3922 | |
| 3923 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3924 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3925 | return -ENOMEM; |
| 3926 | } |
| 3927 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3928 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3929 | |
| 3930 | for (i = 0; i < max_cmd; i++) { |
| 3931 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 3932 | GFP_KERNEL); |
| 3933 | |
| 3934 | if (!instance->cmd_list[i]) { |
| 3935 | |
| 3936 | for (j = 0; j < i; j++) |
| 3937 | kfree(instance->cmd_list[j]); |
| 3938 | |
| 3939 | kfree(instance->cmd_list); |
| 3940 | instance->cmd_list = NULL; |
| 3941 | |
| 3942 | return -ENOMEM; |
| 3943 | } |
| 3944 | } |
| 3945 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3946 | for (i = 0; i < max_cmd; i++) { |
| 3947 | cmd = instance->cmd_list[i]; |
| 3948 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 3949 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3950 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3951 | cmd->instance = instance; |
| 3952 | |
| 3953 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 3954 | } |
| 3955 | |
| 3956 | /* |
| 3957 | * Create a frame pool and assign one frame to each cmd |
| 3958 | */ |
| 3959 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3960 | 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] | 3961 | megasas_free_cmds(instance); |
| 3962 | } |
| 3963 | |
| 3964 | return 0; |
| 3965 | } |
| 3966 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3967 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3968 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 3969 | * @instance: Adapter soft state |
| 3970 | * |
| 3971 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 3972 | * or FW is not under OCR. |
| 3973 | */ |
| 3974 | inline int |
| 3975 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 3976 | |
| 3977 | if (!instance->ctrl_context) |
| 3978 | return KILL_ADAPTER; |
| 3979 | else if (instance->unload || |
| 3980 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 3981 | return IGNORE_TIMEOUT; |
| 3982 | else |
| 3983 | return INITIATE_OCR; |
| 3984 | } |
| 3985 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 3986 | static int |
| 3987 | megasas_get_pd_info(struct megasas_instance *instance, u16 device_id) |
| 3988 | { |
| 3989 | int ret; |
| 3990 | struct megasas_cmd *cmd; |
| 3991 | struct megasas_dcmd_frame *dcmd; |
| 3992 | |
| 3993 | cmd = megasas_get_cmd(instance); |
| 3994 | |
| 3995 | if (!cmd) { |
| 3996 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
| 3997 | return -ENOMEM; |
| 3998 | } |
| 3999 | |
| 4000 | dcmd = &cmd->frame->dcmd; |
| 4001 | |
| 4002 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4003 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4004 | |
| 4005 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4006 | dcmd->cmd = MFI_CMD_DCMD; |
| 4007 | dcmd->cmd_status = 0xFF; |
| 4008 | dcmd->sge_count = 1; |
| 4009 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 4010 | dcmd->timeout = 0; |
| 4011 | dcmd->pad_0 = 0; |
| 4012 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4013 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
| 4014 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->pd_info_h); |
| 4015 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4016 | |
| 4017 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4018 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4019 | else |
| 4020 | ret = megasas_issue_polled(instance, cmd); |
| 4021 | |
| 4022 | switch (ret) { |
| 4023 | case DCMD_SUCCESS: |
| 4024 | instance->pd_list[device_id].interface = |
| 4025 | instance->pd_info->state.ddf.pdType.intf; |
| 4026 | break; |
| 4027 | |
| 4028 | case DCMD_TIMEOUT: |
| 4029 | |
| 4030 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4031 | case INITIATE_OCR: |
| 4032 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4033 | megasas_reset_fusion(instance->host, |
| 4034 | MFI_IO_TIMEOUT_OCR); |
| 4035 | break; |
| 4036 | case KILL_ADAPTER: |
| 4037 | megaraid_sas_kill_hba(instance); |
| 4038 | break; |
| 4039 | case IGNORE_TIMEOUT: |
| 4040 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4041 | __func__, __LINE__); |
| 4042 | break; |
| 4043 | } |
| 4044 | |
| 4045 | break; |
| 4046 | } |
| 4047 | |
| 4048 | if (ret != DCMD_TIMEOUT) |
| 4049 | megasas_return_cmd(instance, cmd); |
| 4050 | |
| 4051 | return ret; |
| 4052 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4053 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4054 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4055 | * @instance: Adapter soft state |
| 4056 | * @pd_list: pd_list structure |
| 4057 | * |
| 4058 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4059 | * list structure. This information is mainly used to find out SYSTEM |
| 4060 | * supported by the FW. |
| 4061 | */ |
| 4062 | static int |
| 4063 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4064 | { |
| 4065 | int ret = 0, pd_index = 0; |
| 4066 | struct megasas_cmd *cmd; |
| 4067 | struct megasas_dcmd_frame *dcmd; |
| 4068 | struct MR_PD_LIST *ci; |
| 4069 | struct MR_PD_ADDRESS *pd_addr; |
| 4070 | dma_addr_t ci_h = 0; |
| 4071 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4072 | if (instance->pd_list_not_supported) { |
| 4073 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4074 | "not supported by firmware\n"); |
| 4075 | return ret; |
| 4076 | } |
| 4077 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4078 | cmd = megasas_get_cmd(instance); |
| 4079 | |
| 4080 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4081 | 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] | 4082 | return -ENOMEM; |
| 4083 | } |
| 4084 | |
| 4085 | dcmd = &cmd->frame->dcmd; |
| 4086 | |
| 4087 | ci = pci_alloc_consistent(instance->pdev, |
| 4088 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h); |
| 4089 | |
| 4090 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4091 | 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] | 4092 | megasas_return_cmd(instance, cmd); |
| 4093 | return -ENOMEM; |
| 4094 | } |
| 4095 | |
| 4096 | memset(ci, 0, sizeof(*ci)); |
| 4097 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4098 | |
| 4099 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4100 | dcmd->mbox.b[1] = 0; |
| 4101 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4102 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4103 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4104 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4105 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4106 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4107 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4108 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
| 4109 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4110 | 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] | 4111 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4112 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4113 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4114 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4115 | else |
| 4116 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4117 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4118 | switch (ret) { |
| 4119 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4120 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4121 | "failed/not supported by firmware\n"); |
| 4122 | |
| 4123 | if (instance->ctrl_context) |
| 4124 | megaraid_sas_kill_hba(instance); |
| 4125 | else |
| 4126 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4127 | break; |
| 4128 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4129 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4130 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4131 | case INITIATE_OCR: |
| 4132 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4133 | /* |
| 4134 | * DCMD failed from AEN path. |
| 4135 | * AEN path already hold reset_mutex to avoid PCI access |
| 4136 | * while OCR is in progress. |
| 4137 | */ |
| 4138 | mutex_unlock(&instance->reset_mutex); |
| 4139 | megasas_reset_fusion(instance->host, |
| 4140 | MFI_IO_TIMEOUT_OCR); |
| 4141 | mutex_lock(&instance->reset_mutex); |
| 4142 | break; |
| 4143 | case KILL_ADAPTER: |
| 4144 | megaraid_sas_kill_hba(instance); |
| 4145 | break; |
| 4146 | case IGNORE_TIMEOUT: |
| 4147 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4148 | __func__, __LINE__); |
| 4149 | break; |
| 4150 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4151 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4152 | break; |
| 4153 | |
| 4154 | case DCMD_SUCCESS: |
| 4155 | pd_addr = ci->addr; |
| 4156 | |
| 4157 | if ((le32_to_cpu(ci->count) > |
| 4158 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4159 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4160 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4161 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4162 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4163 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4164 | 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] | 4165 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4166 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4167 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4168 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4169 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4170 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4171 | pd_addr++; |
| 4172 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4173 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4174 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4175 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4176 | break; |
| 4177 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | pci_free_consistent(instance->pdev, |
| 4181 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 4182 | ci, ci_h); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4183 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4184 | if (ret != DCMD_TIMEOUT) |
| 4185 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4186 | |
| 4187 | return ret; |
| 4188 | } |
| 4189 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4190 | /* |
| 4191 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4192 | * @instance: Adapter soft state |
| 4193 | * @ld_list: ld_list structure |
| 4194 | * |
| 4195 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4196 | * list structure. This information is mainly used to find out SYSTEM |
| 4197 | * supported by the FW. |
| 4198 | */ |
| 4199 | static int |
| 4200 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4201 | { |
| 4202 | int ret = 0, ld_index = 0, ids = 0; |
| 4203 | struct megasas_cmd *cmd; |
| 4204 | struct megasas_dcmd_frame *dcmd; |
| 4205 | struct MR_LD_LIST *ci; |
| 4206 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4207 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4208 | |
| 4209 | cmd = megasas_get_cmd(instance); |
| 4210 | |
| 4211 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4212 | 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] | 4213 | return -ENOMEM; |
| 4214 | } |
| 4215 | |
| 4216 | dcmd = &cmd->frame->dcmd; |
| 4217 | |
| 4218 | ci = pci_alloc_consistent(instance->pdev, |
| 4219 | sizeof(struct MR_LD_LIST), |
| 4220 | &ci_h); |
| 4221 | |
| 4222 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4223 | 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] | 4224 | megasas_return_cmd(instance, cmd); |
| 4225 | return -ENOMEM; |
| 4226 | } |
| 4227 | |
| 4228 | memset(ci, 0, sizeof(*ci)); |
| 4229 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4230 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4231 | if (instance->supportmax256vd) |
| 4232 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4233 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4234 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4235 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4236 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4237 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4238 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4239 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
| 4240 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4241 | 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] | 4242 | dcmd->pad_0 = 0; |
| 4243 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4244 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4245 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4246 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4247 | else |
| 4248 | ret = megasas_issue_polled(instance, cmd); |
| 4249 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4250 | ld_count = le32_to_cpu(ci->ldCount); |
| 4251 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4252 | switch (ret) { |
| 4253 | case DCMD_FAILED: |
| 4254 | megaraid_sas_kill_hba(instance); |
| 4255 | break; |
| 4256 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4257 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4258 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4259 | case INITIATE_OCR: |
| 4260 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4261 | /* |
| 4262 | * DCMD failed from AEN path. |
| 4263 | * AEN path already hold reset_mutex to avoid PCI access |
| 4264 | * while OCR is in progress. |
| 4265 | */ |
| 4266 | mutex_unlock(&instance->reset_mutex); |
| 4267 | megasas_reset_fusion(instance->host, |
| 4268 | MFI_IO_TIMEOUT_OCR); |
| 4269 | mutex_lock(&instance->reset_mutex); |
| 4270 | break; |
| 4271 | case KILL_ADAPTER: |
| 4272 | megaraid_sas_kill_hba(instance); |
| 4273 | break; |
| 4274 | case IGNORE_TIMEOUT: |
| 4275 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4276 | __func__, __LINE__); |
| 4277 | break; |
| 4278 | } |
| 4279 | |
| 4280 | break; |
| 4281 | |
| 4282 | case DCMD_SUCCESS: |
| 4283 | if (ld_count > instance->fw_supported_vd_count) |
| 4284 | break; |
| 4285 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4286 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4287 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4288 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4289 | if (ci->ldList[ld_index].state != 0) { |
| 4290 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4291 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4292 | } |
| 4293 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4294 | |
| 4295 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4298 | 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] | 4299 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4300 | if (ret != DCMD_TIMEOUT) |
| 4301 | megasas_return_cmd(instance, cmd); |
| 4302 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4303 | return ret; |
| 4304 | } |
| 4305 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4306 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4307 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4308 | * @instance: Adapter soft state |
| 4309 | * @ld_list: ld_list structure |
| 4310 | * |
| 4311 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4312 | * list structure. This information is mainly used to find out SYSTEM |
| 4313 | * supported by the FW. |
| 4314 | */ |
| 4315 | static int |
| 4316 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4317 | { |
| 4318 | int ret = 0, ld_index = 0, ids = 0; |
| 4319 | struct megasas_cmd *cmd; |
| 4320 | struct megasas_dcmd_frame *dcmd; |
| 4321 | struct MR_LD_TARGETID_LIST *ci; |
| 4322 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4323 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4324 | |
| 4325 | cmd = megasas_get_cmd(instance); |
| 4326 | |
| 4327 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4328 | dev_warn(&instance->pdev->dev, |
| 4329 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4330 | return -ENOMEM; |
| 4331 | } |
| 4332 | |
| 4333 | dcmd = &cmd->frame->dcmd; |
| 4334 | |
| 4335 | ci = pci_alloc_consistent(instance->pdev, |
| 4336 | sizeof(struct MR_LD_TARGETID_LIST), &ci_h); |
| 4337 | |
| 4338 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4339 | dev_warn(&instance->pdev->dev, |
| 4340 | "Failed to alloc mem for ld_list_query\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4341 | megasas_return_cmd(instance, cmd); |
| 4342 | return -ENOMEM; |
| 4343 | } |
| 4344 | |
| 4345 | memset(ci, 0, sizeof(*ci)); |
| 4346 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4347 | |
| 4348 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4349 | if (instance->supportmax256vd) |
| 4350 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4351 | |
| 4352 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4353 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4354 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4355 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4356 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4357 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4358 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
| 4359 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4360 | 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] | 4361 | dcmd->pad_0 = 0; |
| 4362 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4363 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4364 | 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] | 4365 | else |
| 4366 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4367 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4368 | switch (ret) { |
| 4369 | case DCMD_FAILED: |
| 4370 | dev_info(&instance->pdev->dev, |
| 4371 | "DCMD not supported by firmware - %s %d\n", |
| 4372 | __func__, __LINE__); |
| 4373 | ret = megasas_get_ld_list(instance); |
| 4374 | break; |
| 4375 | case DCMD_TIMEOUT: |
| 4376 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4377 | case INITIATE_OCR: |
| 4378 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4379 | /* |
| 4380 | * DCMD failed from AEN path. |
| 4381 | * AEN path already hold reset_mutex to avoid PCI access |
| 4382 | * while OCR is in progress. |
| 4383 | */ |
| 4384 | mutex_unlock(&instance->reset_mutex); |
| 4385 | megasas_reset_fusion(instance->host, |
| 4386 | MFI_IO_TIMEOUT_OCR); |
| 4387 | mutex_lock(&instance->reset_mutex); |
| 4388 | break; |
| 4389 | case KILL_ADAPTER: |
| 4390 | megaraid_sas_kill_hba(instance); |
| 4391 | break; |
| 4392 | case IGNORE_TIMEOUT: |
| 4393 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4394 | __func__, __LINE__); |
| 4395 | break; |
| 4396 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4397 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4398 | break; |
| 4399 | case DCMD_SUCCESS: |
| 4400 | tgtid_count = le32_to_cpu(ci->count); |
| 4401 | |
| 4402 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4403 | break; |
| 4404 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4405 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4406 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4407 | ids = ci->targetId[ld_index]; |
| 4408 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4409 | } |
| 4410 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4411 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_TARGETID_LIST), |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4415 | ci, ci_h); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4416 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4417 | if (ret != DCMD_TIMEOUT) |
| 4418 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4419 | |
| 4420 | return ret; |
| 4421 | } |
| 4422 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4423 | /* |
| 4424 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4425 | * instance : Controller's instance |
| 4426 | */ |
| 4427 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4428 | { |
| 4429 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4430 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4431 | |
| 4432 | fusion = instance->ctrl_context; |
| 4433 | /* For MFI based controllers return dummy success */ |
| 4434 | if (!fusion) |
| 4435 | return; |
| 4436 | |
| 4437 | instance->supportmax256vd = |
| 4438 | instance->ctrl_info->adapterOperations3.supportMaxExtLDs; |
| 4439 | /* Below is additional check to address future FW enhancement */ |
| 4440 | if (instance->ctrl_info->max_lds > 64) |
| 4441 | instance->supportmax256vd = 1; |
| 4442 | |
| 4443 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4444 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4445 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4446 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4447 | if (instance->supportmax256vd) { |
| 4448 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4449 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4450 | } else { |
| 4451 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4452 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4453 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4454 | |
| 4455 | dev_info(&instance->pdev->dev, |
| 4456 | "firmware type\t: %s\n", |
| 4457 | instance->supportmax256vd ? "Extended VD(240 VD)firmware" : |
| 4458 | "Legacy(64 VD) firmware"); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4459 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4460 | if (instance->max_raid_mapsize) { |
| 4461 | ventura_map_sz = instance->max_raid_mapsize * |
| 4462 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4463 | fusion->current_map_sz = ventura_map_sz; |
| 4464 | fusion->max_map_sz = ventura_map_sz; |
| 4465 | } else { |
| 4466 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4467 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4468 | (instance->fw_supported_vd_count - 1)); |
| 4469 | 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] | 4470 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4471 | fusion->max_map_sz = |
| 4472 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4473 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4474 | if (instance->supportmax256vd) |
| 4475 | fusion->current_map_sz = fusion->new_map_sz; |
| 4476 | else |
| 4477 | fusion->current_map_sz = fusion->old_map_sz; |
| 4478 | } |
| 4479 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4480 | 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] | 4481 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4482 | #if VD_EXT_DEBUG |
| 4483 | dev_info(&instance->pdev->dev, "instance->max_raid_mapsize 0x%x\n ", |
| 4484 | instance->max_raid_mapsize); |
| 4485 | dev_info(&instance->pdev->dev, "new_map_sz = 0x%x, old_map_sz = 0x%x\n", |
| 4486 | fusion->new_map_sz, fusion->old_map_sz); |
| 4487 | dev_info(&instance->pdev->dev, "ventura_map_sz = 0x%x, current_map_sz = 0x%x\n", |
| 4488 | ventura_map_sz, fusion->current_map_sz); |
| 4489 | dev_info(&instance->pdev->dev, "fusion->drv_map_sz =0x%x, size of driver raid map 0x%lx\n", |
| 4490 | fusion->drv_map_sz, sizeof(struct MR_DRV_RAID_MAP_ALL)); |
| 4491 | #endif |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4492 | } |
| 4493 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4494 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4495 | * megasas_get_controller_info - Returns FW's controller structure |
| 4496 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4497 | * |
| 4498 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4499 | * This information is mainly used to find out the maximum IO transfer per |
| 4500 | * command supported by the FW. |
| 4501 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4502 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4503 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4504 | { |
| 4505 | int ret = 0; |
| 4506 | struct megasas_cmd *cmd; |
| 4507 | struct megasas_dcmd_frame *dcmd; |
| 4508 | struct megasas_ctrl_info *ci; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4509 | struct megasas_ctrl_info *ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4510 | dma_addr_t ci_h = 0; |
| 4511 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4512 | ctrl_info = instance->ctrl_info; |
| 4513 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4514 | cmd = megasas_get_cmd(instance); |
| 4515 | |
| 4516 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4517 | 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] | 4518 | return -ENOMEM; |
| 4519 | } |
| 4520 | |
| 4521 | dcmd = &cmd->frame->dcmd; |
| 4522 | |
| 4523 | ci = pci_alloc_consistent(instance->pdev, |
| 4524 | sizeof(struct megasas_ctrl_info), &ci_h); |
| 4525 | |
| 4526 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4527 | 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] | 4528 | megasas_return_cmd(instance, cmd); |
| 4529 | return -ENOMEM; |
| 4530 | } |
| 4531 | |
| 4532 | memset(ci, 0, sizeof(*ci)); |
| 4533 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4534 | |
| 4535 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4536 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4537 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4538 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4539 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4540 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4541 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4542 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
| 4543 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4544 | 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] | 4545 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4546 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4547 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4548 | 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] | 4549 | else |
| 4550 | ret = megasas_issue_polled(instance, cmd); |
| 4551 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4552 | switch (ret) { |
| 4553 | case DCMD_SUCCESS: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4554 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4555 | /* Save required controller information in |
| 4556 | * CPU endianness format. |
| 4557 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4558 | le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties); |
| 4559 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations2); |
| 4560 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations3); |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4561 | le16_to_cpus((u16 *)&ctrl_info->adapter_operations4); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4562 | |
| 4563 | /* Update the latest Ext VD info. |
| 4564 | * From Init path, store current firmware details. |
| 4565 | * From OCR path, detect any firmware properties changes. |
| 4566 | * in case of Firmware upgrade without system reboot. |
| 4567 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4568 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4569 | instance->use_seqnum_jbod_fp = |
| 4570 | ctrl_info->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4571 | instance->support_morethan256jbod = |
| 4572 | ctrl_info->adapter_operations4.support_pd_map_target_id; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4573 | |
| 4574 | /*Check whether controller is iMR or MR */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4575 | instance->is_imr = (ctrl_info->memory_size ? 0 : 1); |
| 4576 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4577 | "controller type\t: %s(%dMB)\n", |
| 4578 | instance->is_imr ? "iMR" : "MR", |
| 4579 | le16_to_cpu(ctrl_info->memory_size)); |
| 4580 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 4581 | instance->disableOnlineCtrlReset = |
| 4582 | ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4583 | instance->secure_jbod_support = |
| 4584 | ctrl_info->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4585 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 4586 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4587 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 4588 | instance->secure_jbod_support ? "Yes" : "No"); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4589 | break; |
| 4590 | |
| 4591 | case DCMD_TIMEOUT: |
| 4592 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4593 | case INITIATE_OCR: |
| 4594 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4595 | megasas_reset_fusion(instance->host, |
| 4596 | MFI_IO_TIMEOUT_OCR); |
| 4597 | break; |
| 4598 | case KILL_ADAPTER: |
| 4599 | megaraid_sas_kill_hba(instance); |
| 4600 | break; |
| 4601 | case IGNORE_TIMEOUT: |
| 4602 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4603 | __func__, __LINE__); |
| 4604 | break; |
| 4605 | } |
| 4606 | case DCMD_FAILED: |
| 4607 | megaraid_sas_kill_hba(instance); |
| 4608 | break; |
| 4609 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4610 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4611 | |
| 4612 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), |
| 4613 | ci, ci_h); |
| 4614 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4615 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4616 | |
| 4617 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4618 | return ret; |
| 4619 | } |
| 4620 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4621 | /* |
| 4622 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 4623 | * to firmware |
| 4624 | * |
| 4625 | * @instance: Adapter soft state |
| 4626 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 4627 | MR_CRASH_BUF_TURN_OFF = 0 |
| 4628 | MR_CRASH_BUF_TURN_ON = 1 |
| 4629 | * @return 0 on success non-zero on failure. |
| 4630 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 4631 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 4632 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 4633 | * crash dump feature is supported by the FW. |
| 4634 | * |
| 4635 | */ |
| 4636 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 4637 | u8 crash_buf_state) |
| 4638 | { |
| 4639 | int ret = 0; |
| 4640 | struct megasas_cmd *cmd; |
| 4641 | struct megasas_dcmd_frame *dcmd; |
| 4642 | |
| 4643 | cmd = megasas_get_cmd(instance); |
| 4644 | |
| 4645 | if (!cmd) { |
| 4646 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4647 | return -ENOMEM; |
| 4648 | } |
| 4649 | |
| 4650 | |
| 4651 | dcmd = &cmd->frame->dcmd; |
| 4652 | |
| 4653 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4654 | dcmd->mbox.b[0] = crash_buf_state; |
| 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; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4657 | dcmd->sge_count = 1; |
| 4658 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
| 4659 | dcmd->timeout = 0; |
| 4660 | dcmd->pad_0 = 0; |
| 4661 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4662 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
| 4663 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h); |
| 4664 | dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4665 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4666 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4667 | 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] | 4668 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4669 | ret = megasas_issue_polled(instance, cmd); |
| 4670 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4671 | if (ret == DCMD_TIMEOUT) { |
| 4672 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4673 | case INITIATE_OCR: |
| 4674 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4675 | megasas_reset_fusion(instance->host, |
| 4676 | MFI_IO_TIMEOUT_OCR); |
| 4677 | break; |
| 4678 | case KILL_ADAPTER: |
| 4679 | megaraid_sas_kill_hba(instance); |
| 4680 | break; |
| 4681 | case IGNORE_TIMEOUT: |
| 4682 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4683 | __func__, __LINE__); |
| 4684 | break; |
| 4685 | } |
| 4686 | } else |
| 4687 | megasas_return_cmd(instance, cmd); |
| 4688 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4689 | return ret; |
| 4690 | } |
| 4691 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4692 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4693 | * megasas_issue_init_mfi - Initializes the FW |
| 4694 | * @instance: Adapter soft state |
| 4695 | * |
| 4696 | * Issues the INIT MFI cmd |
| 4697 | */ |
| 4698 | static int |
| 4699 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 4700 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 4701 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4702 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4703 | struct megasas_init_frame *init_frame; |
| 4704 | struct megasas_init_queue_info *initq_info; |
| 4705 | dma_addr_t init_frame_h; |
| 4706 | dma_addr_t initq_info_h; |
| 4707 | |
| 4708 | /* |
| 4709 | * Prepare a init frame. Note the init frame points to queue info |
| 4710 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 4711 | * this frame - since we don't need any SGL - we use SGL's space as |
| 4712 | * queue info structure |
| 4713 | * |
| 4714 | * We will not get a NULL command below. We just created the pool. |
| 4715 | */ |
| 4716 | cmd = megasas_get_cmd(instance); |
| 4717 | |
| 4718 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 4719 | initq_info = (struct megasas_init_queue_info *) |
| 4720 | ((unsigned long)init_frame + 64); |
| 4721 | |
| 4722 | init_frame_h = cmd->frame_phys_addr; |
| 4723 | initq_info_h = init_frame_h + 64; |
| 4724 | |
| 4725 | context = init_frame->context; |
| 4726 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 4727 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 4728 | init_frame->context = context; |
| 4729 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4730 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 4731 | 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] | 4732 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4733 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 4734 | 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] | 4735 | |
| 4736 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4737 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4738 | init_frame->queue_info_new_phys_addr_lo = |
| 4739 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 4740 | init_frame->queue_info_new_phys_addr_hi = |
| 4741 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4742 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4743 | 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] | 4744 | |
| 4745 | /* |
| 4746 | * disable the intr before firing the init frame to FW |
| 4747 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4748 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4749 | |
| 4750 | /* |
| 4751 | * Issue the init frame in polled mode |
| 4752 | */ |
| 4753 | |
| 4754 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4755 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4756 | megasas_return_cmd(instance, cmd); |
| 4757 | goto fail_fw_init; |
| 4758 | } |
| 4759 | |
| 4760 | megasas_return_cmd(instance, cmd); |
| 4761 | |
| 4762 | return 0; |
| 4763 | |
| 4764 | fail_fw_init: |
| 4765 | return -EINVAL; |
| 4766 | } |
| 4767 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4768 | static u32 |
| 4769 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4770 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4771 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4772 | u32 context_sz; |
| 4773 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4774 | |
| 4775 | reg_set = instance->reg_set; |
| 4776 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4777 | /* |
| 4778 | * Get various operational parameters from status register |
| 4779 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4780 | 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] | 4781 | /* |
| 4782 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 4783 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 4784 | * does not exceed max cmds that the FW can support |
| 4785 | */ |
| 4786 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4787 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4788 | 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] | 4789 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4790 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4791 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 4792 | * are reserved for IOCTL + driver's internal DCMDs. |
| 4793 | */ |
| 4794 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 4795 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 4796 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4797 | MEGASAS_SKINNY_INT_CMDS); |
| 4798 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 4799 | } else { |
| 4800 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4801 | MEGASAS_INT_CMDS); |
| 4802 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 4803 | } |
| 4804 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 4805 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4806 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4807 | * Create a pool of commands |
| 4808 | */ |
| 4809 | if (megasas_alloc_cmds(instance)) |
| 4810 | goto fail_alloc_cmds; |
| 4811 | |
| 4812 | /* |
| 4813 | * Allocate memory for reply queue. Length of reply queue should |
| 4814 | * be _one_ more than the maximum commands handled by the firmware. |
| 4815 | * |
| 4816 | * Note: When FW completes commands, it places corresponding contex |
| 4817 | * values in this circular reply queue. This circular queue is a fairly |
| 4818 | * typical producer-consumer queue. FW is the producer (of completed |
| 4819 | * commands) and the driver is the consumer. |
| 4820 | */ |
| 4821 | context_sz = sizeof(u32); |
| 4822 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 4823 | |
| 4824 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 4825 | reply_q_sz, |
| 4826 | &instance->reply_queue_h); |
| 4827 | |
| 4828 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4829 | 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] | 4830 | goto fail_reply_queue; |
| 4831 | } |
| 4832 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4833 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4834 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4835 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4836 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4837 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 4838 | "Fail from %s %d\n", instance->unique_id, |
| 4839 | __func__, __LINE__); |
| 4840 | goto fail_fw_init; |
| 4841 | } |
| 4842 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4843 | instance->fw_support_ieee = 0; |
| 4844 | instance->fw_support_ieee = |
| 4845 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 4846 | 0x04000000); |
| 4847 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4848 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4849 | instance->fw_support_ieee); |
| 4850 | |
| 4851 | if (instance->fw_support_ieee) |
| 4852 | instance->flag_ieee = 1; |
| 4853 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4854 | return 0; |
| 4855 | |
| 4856 | fail_fw_init: |
| 4857 | |
| 4858 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 4859 | instance->reply_queue, instance->reply_queue_h); |
| 4860 | fail_reply_queue: |
| 4861 | megasas_free_cmds(instance); |
| 4862 | |
| 4863 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4864 | return 1; |
| 4865 | } |
| 4866 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4867 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4868 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4869 | * @instance: Adapter soft state |
| 4870 | * |
| 4871 | * Do not enable interrupt, only setup ISRs. |
| 4872 | * |
| 4873 | * Return 0 on success. |
| 4874 | */ |
| 4875 | static int |
| 4876 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 4877 | { |
| 4878 | struct pci_dev *pdev; |
| 4879 | |
| 4880 | pdev = instance->pdev; |
| 4881 | instance->irq_context[0].instance = instance; |
| 4882 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4883 | if (request_irq(pci_irq_vector(pdev, 0), |
| 4884 | instance->instancet->service_isr, IRQF_SHARED, |
| 4885 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4886 | dev_err(&instance->pdev->dev, |
| 4887 | "Failed to register IRQ from %s %d\n", |
| 4888 | __func__, __LINE__); |
| 4889 | return -1; |
| 4890 | } |
| 4891 | return 0; |
| 4892 | } |
| 4893 | |
| 4894 | /** |
| 4895 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 4896 | * @instance: Adapter soft state |
| 4897 | * @is_probe: Driver probe check |
| 4898 | * |
| 4899 | * Do not enable interrupt, only setup ISRs. |
| 4900 | * |
| 4901 | * Return 0 on success. |
| 4902 | */ |
| 4903 | static int |
| 4904 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 4905 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4906 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4907 | struct pci_dev *pdev; |
| 4908 | |
| 4909 | pdev = instance->pdev; |
| 4910 | |
| 4911 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4912 | for (i = 0; i < instance->msix_vectors; i++) { |
| 4913 | instance->irq_context[i].instance = instance; |
| 4914 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4915 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4916 | instance->instancet->service_isr, 0, "megasas", |
| 4917 | &instance->irq_context[i])) { |
| 4918 | dev_err(&instance->pdev->dev, |
| 4919 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4920 | for (j = 0; j < i; j++) |
| 4921 | free_irq(pci_irq_vector(pdev, j), |
| 4922 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4923 | /* Retry irq register for IO_APIC*/ |
| 4924 | instance->msix_vectors = 0; |
| 4925 | if (is_probe) |
| 4926 | return megasas_setup_irqs_ioapic(instance); |
| 4927 | else |
| 4928 | return -1; |
| 4929 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4930 | } |
| 4931 | return 0; |
| 4932 | } |
| 4933 | |
| 4934 | /* |
| 4935 | * megasas_destroy_irqs- unregister interrupts. |
| 4936 | * @instance: Adapter soft state |
| 4937 | * return: void |
| 4938 | */ |
| 4939 | static void |
| 4940 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 4941 | |
| 4942 | int i; |
| 4943 | |
| 4944 | if (instance->msix_vectors) |
| 4945 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4946 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4947 | &instance->irq_context[i]); |
| 4948 | } |
| 4949 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4950 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 4951 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4952 | } |
| 4953 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4954 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4955 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 4956 | * @instance: Adapter soft state |
| 4957 | * @is_probe: Driver probe check |
| 4958 | * |
| 4959 | * Return 0 on success. |
| 4960 | */ |
| 4961 | void |
| 4962 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 4963 | { |
| 4964 | int i; |
| 4965 | struct fusion_context *fusion = instance->ctrl_context; |
| 4966 | u32 pd_seq_map_sz; |
| 4967 | |
| 4968 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 4969 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 4970 | |
| 4971 | if (reset_devices || !fusion || |
| 4972 | !instance->ctrl_info->adapterOperations3.useSeqNumJbodFP) { |
| 4973 | dev_info(&instance->pdev->dev, |
| 4974 | "Jbod map is not supported %s %d\n", |
| 4975 | __func__, __LINE__); |
| 4976 | instance->use_seqnum_jbod_fp = false; |
| 4977 | return; |
| 4978 | } |
| 4979 | |
| 4980 | if (fusion->pd_seq_sync[0]) |
| 4981 | goto skip_alloc; |
| 4982 | |
| 4983 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 4984 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 4985 | (&instance->pdev->dev, pd_seq_map_sz, |
| 4986 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 4987 | if (!fusion->pd_seq_sync[i]) { |
| 4988 | dev_err(&instance->pdev->dev, |
| 4989 | "Failed to allocate memory from %s %d\n", |
| 4990 | __func__, __LINE__); |
| 4991 | if (i == 1) { |
| 4992 | dma_free_coherent(&instance->pdev->dev, |
| 4993 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 4994 | fusion->pd_seq_phys[0]); |
| 4995 | fusion->pd_seq_sync[0] = NULL; |
| 4996 | } |
| 4997 | instance->use_seqnum_jbod_fp = false; |
| 4998 | return; |
| 4999 | } |
| 5000 | } |
| 5001 | |
| 5002 | skip_alloc: |
| 5003 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5004 | !megasas_sync_pd_seq_num(instance, true)) |
| 5005 | instance->use_seqnum_jbod_fp = true; |
| 5006 | else |
| 5007 | instance->use_seqnum_jbod_fp = false; |
| 5008 | } |
| 5009 | |
| 5010 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5011 | * megasas_init_fw - Initializes the FW |
| 5012 | * @instance: Adapter soft state |
| 5013 | * |
| 5014 | * This is the main function for initializing firmware |
| 5015 | */ |
| 5016 | |
| 5017 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5018 | { |
| 5019 | u32 max_sectors_1; |
| 5020 | u32 max_sectors_2; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5021 | u32 tmp_sectors, msix_enable, scratch_pad_2, scratch_pad_3; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5022 | resource_size_t base_addr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5023 | struct megasas_register_set __iomem *reg_set; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5024 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5025 | unsigned long bar_list; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5026 | int i, j, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5027 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5028 | struct fusion_context *fusion; |
| 5029 | |
| 5030 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5031 | |
| 5032 | /* Find first memory bar */ |
| 5033 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5034 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5035 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5036 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5037 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5038 | return -EBUSY; |
| 5039 | } |
| 5040 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5041 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5042 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5043 | |
| 5044 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5045 | 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] | 5046 | goto fail_ioremap; |
| 5047 | } |
| 5048 | |
| 5049 | reg_set = instance->reg_set; |
| 5050 | |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5051 | if (fusion) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5052 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5053 | else { |
| 5054 | switch (instance->pdev->device) { |
| 5055 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5056 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5057 | instance->instancet = &megasas_instance_template_ppc; |
| 5058 | break; |
| 5059 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5060 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5061 | instance->instancet = &megasas_instance_template_gen2; |
| 5062 | break; |
| 5063 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5064 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5065 | instance->instancet = &megasas_instance_template_skinny; |
| 5066 | break; |
| 5067 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5068 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5069 | default: |
| 5070 | instance->instancet = &megasas_instance_template_xscale; |
| 5071 | instance->pd_list_not_supported = 1; |
| 5072 | break; |
| 5073 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5076 | if (megasas_transition_to_ready(instance, 0)) { |
| 5077 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5078 | instance->instancet->adp_reset |
| 5079 | (instance, instance->reg_set); |
| 5080 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 5081 | dev_info(&instance->pdev->dev, |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5082 | "FW restarted successfully from %s!\n", |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5083 | __func__); |
| 5084 | |
| 5085 | /*waitting for about 30 second before retry*/ |
| 5086 | ssleep(30); |
| 5087 | |
| 5088 | if (megasas_transition_to_ready(instance, 0)) |
| 5089 | goto fail_ready_state; |
| 5090 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5091 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5092 | if (instance->is_ventura) { |
| 5093 | scratch_pad_3 = |
| 5094 | readl(&instance->reg_set->outbound_scratch_pad_3); |
| 5095 | #if VD_EXT_DEBUG |
| 5096 | dev_info(&instance->pdev->dev, "scratch_pad3 0x%x\n", |
| 5097 | scratch_pad_3); |
| 5098 | #endif |
| 5099 | instance->max_raid_mapsize = ((scratch_pad_3 >> |
| 5100 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5101 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5102 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5103 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5104 | /* Check if MSI-X is supported while in ready state */ |
| 5105 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 5106 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5107 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5108 | int irq_flags = PCI_IRQ_MSIX; |
| 5109 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5110 | scratch_pad_2 = readl |
| 5111 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5112 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5113 | if (fusion) { |
| 5114 | if (fusion->adapter_type == THUNDERBOLT_SERIES) { /* Thunderbolt Series*/ |
| 5115 | instance->msix_vectors = (scratch_pad_2 |
| 5116 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 5117 | fw_msix_count = instance->msix_vectors; |
| 5118 | } else { /* Invader series supports more than 8 MSI-x vectors*/ |
| 5119 | instance->msix_vectors = ((scratch_pad_2 |
| 5120 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5121 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5122 | if (instance->msix_vectors > 16) |
| 5123 | instance->msix_combined = true; |
| 5124 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5125 | if (rdpq_enable) |
| 5126 | instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? |
| 5127 | 1 : 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5128 | fw_msix_count = instance->msix_vectors; |
| 5129 | /* Save 1-15 reply post index address to local memory |
| 5130 | * Index 0 is already saved from reg offset |
| 5131 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5132 | */ |
| 5133 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5134 | instance->reply_post_host_index_addr[loop] = |
| 5135 | (u32 __iomem *) |
| 5136 | ((u8 __iomem *)instance->reg_set + |
| 5137 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5138 | + (loop * 0x10)); |
| 5139 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5140 | } |
| 5141 | if (msix_vectors) |
| 5142 | instance->msix_vectors = min(msix_vectors, |
| 5143 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5144 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5145 | instance->msix_vectors = 1; |
| 5146 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 5147 | instance->msix_vectors = min(instance->msix_vectors, |
| 5148 | (unsigned int)num_online_cpus()); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5149 | if (smp_affinity_enable) |
| 5150 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5151 | i = pci_alloc_irq_vectors(instance->pdev, 1, |
| 5152 | instance->msix_vectors, irq_flags); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 5153 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5154 | instance->msix_vectors = i; |
| 5155 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5156 | instance->msix_vectors = 0; |
| 5157 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5158 | /* |
| 5159 | * MSI-X host index 0 is common for all adapter. |
| 5160 | * It is used for all MPT based Adapters. |
| 5161 | */ |
| 5162 | if (instance->msix_combined) { |
| 5163 | instance->reply_post_host_index_addr[0] = |
| 5164 | (u32 *)((u8 *)instance->reg_set + |
| 5165 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 5166 | } else { |
| 5167 | instance->reply_post_host_index_addr[0] = |
| 5168 | (u32 *)((u8 *)instance->reg_set + |
| 5169 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 5170 | } |
| 5171 | |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5172 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 5173 | if (i < 0) |
| 5174 | goto fail_setup_irqs; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5175 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5176 | dev_info(&instance->pdev->dev, |
| 5177 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5178 | dev_info(&instance->pdev->dev, |
| 5179 | "current msix/online cpus\t: (%d/%d)\n", |
| 5180 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5181 | dev_info(&instance->pdev->dev, |
| 5182 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5183 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5184 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5185 | (unsigned long)instance); |
| 5186 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5187 | instance->ctrl_info = kzalloc(sizeof(struct megasas_ctrl_info), |
| 5188 | GFP_KERNEL); |
| 5189 | if (instance->ctrl_info == NULL) |
| 5190 | goto fail_init_adapter; |
| 5191 | |
| 5192 | /* |
| 5193 | * Below are default value for legacy Firmware. |
| 5194 | * non-fusion based controllers |
| 5195 | */ |
| 5196 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5197 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5198 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5199 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5200 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5201 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5202 | if (instance->msix_vectors ? |
| 5203 | megasas_setup_irqs_msix(instance, 1) : |
| 5204 | megasas_setup_irqs_ioapic(instance)) |
| 5205 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5206 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5207 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5208 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 5209 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5210 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5211 | megasas_setup_jbod_map(instance); |
| 5212 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5213 | /** for passthrough |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5214 | * the following function will get the PD LIST. |
| 5215 | */ |
| 5216 | memset(instance->pd_list, 0, |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5217 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5218 | if (megasas_get_pd_list(instance) < 0) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5219 | 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] | 5220 | goto fail_get_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5221 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5222 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5223 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5224 | |
| 5225 | /* stream detection initialization */ |
| 5226 | if (instance->is_ventura) { |
| 5227 | fusion->stream_detect_by_ld = |
| 5228 | kzalloc(sizeof(struct LD_STREAM_DETECT *) |
| 5229 | * MAX_LOGICAL_DRIVES_EXT, |
| 5230 | GFP_KERNEL); |
| 5231 | if (!fusion->stream_detect_by_ld) { |
| 5232 | dev_err(&instance->pdev->dev, |
| 5233 | "unable to allocate stream detection for pool of LDs\n"); |
| 5234 | goto fail_get_ld_pd_list; |
| 5235 | } |
| 5236 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 5237 | fusion->stream_detect_by_ld[i] = |
| 5238 | kmalloc(sizeof(struct LD_STREAM_DETECT), |
| 5239 | GFP_KERNEL); |
| 5240 | if (!fusion->stream_detect_by_ld[i]) { |
| 5241 | dev_err(&instance->pdev->dev, |
| 5242 | "unable to allocate stream detect by LD\n "); |
| 5243 | for (j = 0; j < i; ++j) |
| 5244 | kfree(fusion->stream_detect_by_ld[j]); |
| 5245 | kfree(fusion->stream_detect_by_ld); |
| 5246 | fusion->stream_detect_by_ld = NULL; |
| 5247 | goto fail_get_ld_pd_list; |
| 5248 | } |
| 5249 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 5250 | = MR_STREAM_BITMAP; |
| 5251 | } |
| 5252 | } |
| 5253 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5254 | if (megasas_ld_list_query(instance, |
| 5255 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 5256 | megasas_get_ld_list(instance); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5257 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5258 | /* |
| 5259 | * Compute the max allowed sectors per IO: The controller info has two |
| 5260 | * limits on max sectors. Driver should use the minimum of these two. |
| 5261 | * |
| 5262 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5263 | * |
| 5264 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5265 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5266 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5267 | tmp_sectors = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5268 | ctrl_info = instance->ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5269 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5270 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5271 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5272 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5273 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5274 | 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] | 5275 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 5276 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 5277 | instance->passive = ctrl_info->cluster.passive; |
| 5278 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5279 | instance->UnevenSpanSupport = |
| 5280 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5281 | if (instance->UnevenSpanSupport) { |
| 5282 | struct fusion_context *fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5283 | if (MR_ValidateMapInfo(instance)) |
| 5284 | fusion->fast_path_io = 1; |
| 5285 | else |
| 5286 | fusion->fast_path_io = 0; |
| 5287 | |
| 5288 | } |
| 5289 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5290 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5291 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5292 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5293 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5294 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5295 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5296 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5297 | |
| 5298 | if (instance->PlasmaFW111) { |
| 5299 | iovPtr = (struct IOV_111 *) |
| 5300 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5301 | instance->requestorId = iovPtr->requestorId; |
| 5302 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5303 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5304 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5305 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5306 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5307 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5308 | instance->crash_dump_fw_support = |
| 5309 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5310 | instance->crash_dump_drv_support = |
| 5311 | (instance->crash_dump_fw_support && |
| 5312 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5313 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5314 | megasas_set_crash_dump_params(instance, |
| 5315 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5316 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5317 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5318 | if (instance->crash_dump_buf) |
| 5319 | pci_free_consistent(instance->pdev, |
| 5320 | CRASH_DMA_BUF_SIZE, |
| 5321 | instance->crash_dump_buf, |
| 5322 | instance->crash_dump_h); |
| 5323 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5324 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5325 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5326 | |
| 5327 | dev_info(&instance->pdev->dev, |
| 5328 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5329 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5330 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5331 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5332 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5333 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 5334 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5335 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 5336 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5337 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 5338 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5339 | |
| 5340 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5341 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 5342 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5343 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 5344 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5345 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5346 | /* Check for valid throttlequeuedepth module parameter */ |
| 5347 | if (throttlequeuedepth && |
| 5348 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 5349 | instance->throttlequeuedepth = throttlequeuedepth; |
| 5350 | else |
| 5351 | instance->throttlequeuedepth = |
| 5352 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 5353 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 5354 | if (resetwaittime > MEGASAS_RESET_WAIT_TIME) |
| 5355 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 5356 | |
| 5357 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 5358 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5359 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5360 | /* Launch SR-IOV heartbeat timer */ |
| 5361 | if (instance->requestorId) { |
| 5362 | if (!megasas_sriov_start_heartbeat(instance, 1)) |
| 5363 | megasas_start_timer(instance, |
| 5364 | &instance->sriov_heartbeat_timer, |
| 5365 | megasas_sriov_heartbeat_handler, |
| 5366 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 5367 | else |
| 5368 | instance->skip_heartbeat_timer_del = 1; |
| 5369 | } |
| 5370 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5371 | return 0; |
| 5372 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5373 | fail_get_ld_pd_list: |
| 5374 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5375 | fail_get_pd_list: |
| 5376 | instance->instancet->disable_intr(instance); |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5377 | fail_init_adapter: |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5378 | megasas_destroy_irqs(instance); |
| 5379 | fail_setup_irqs: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5380 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5381 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5382 | instance->msix_vectors = 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5383 | fail_ready_state: |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5384 | kfree(instance->ctrl_info); |
| 5385 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5386 | iounmap(instance->reg_set); |
| 5387 | |
| 5388 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5389 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5390 | |
| 5391 | return -EINVAL; |
| 5392 | } |
| 5393 | |
| 5394 | /** |
| 5395 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 5396 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5397 | */ |
| 5398 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 5399 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5400 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5401 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5402 | if (instance->reply_queue) |
| 5403 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5404 | instance->reply_queue, instance->reply_queue_h); |
| 5405 | |
| 5406 | megasas_free_cmds(instance); |
| 5407 | |
| 5408 | iounmap(instance->reg_set); |
| 5409 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5410 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | /** |
| 5414 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 5415 | * @instance: Adapter soft state |
| 5416 | * @eli: FW event log sequence numbers information |
| 5417 | * |
| 5418 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 5419 | * usually find out the latest sequence number of the events, the seq number at |
| 5420 | * the boot etc. They would "read" all the events below the latest seq number |
| 5421 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 5422 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 5423 | * wait for the events to happen. |
| 5424 | */ |
| 5425 | static int |
| 5426 | megasas_get_seq_num(struct megasas_instance *instance, |
| 5427 | struct megasas_evt_log_info *eli) |
| 5428 | { |
| 5429 | struct megasas_cmd *cmd; |
| 5430 | struct megasas_dcmd_frame *dcmd; |
| 5431 | struct megasas_evt_log_info *el_info; |
| 5432 | dma_addr_t el_info_h = 0; |
| 5433 | |
| 5434 | cmd = megasas_get_cmd(instance); |
| 5435 | |
| 5436 | if (!cmd) { |
| 5437 | return -ENOMEM; |
| 5438 | } |
| 5439 | |
| 5440 | dcmd = &cmd->frame->dcmd; |
| 5441 | el_info = pci_alloc_consistent(instance->pdev, |
| 5442 | sizeof(struct megasas_evt_log_info), |
| 5443 | &el_info_h); |
| 5444 | |
| 5445 | if (!el_info) { |
| 5446 | megasas_return_cmd(instance, cmd); |
| 5447 | return -ENOMEM; |
| 5448 | } |
| 5449 | |
| 5450 | memset(el_info, 0, sizeof(*el_info)); |
| 5451 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5452 | |
| 5453 | dcmd->cmd = MFI_CMD_DCMD; |
| 5454 | dcmd->cmd_status = 0x0; |
| 5455 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5456 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5457 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5458 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5459 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 5460 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
| 5461 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(el_info_h); |
| 5462 | 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] | 5463 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5464 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) == |
| 5465 | DCMD_SUCCESS) { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5466 | /* |
| 5467 | * Copy the data back into callers buffer |
| 5468 | */ |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5469 | eli->newest_seq_num = el_info->newest_seq_num; |
| 5470 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 5471 | eli->clear_seq_num = el_info->clear_seq_num; |
| 5472 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 5473 | eli->boot_seq_num = el_info->boot_seq_num; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5474 | } else |
| 5475 | dev_err(&instance->pdev->dev, "DCMD failed " |
| 5476 | "from %s\n", __func__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5477 | |
| 5478 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 5479 | el_info, el_info_h); |
| 5480 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5481 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5482 | |
| 5483 | return 0; |
| 5484 | } |
| 5485 | |
| 5486 | /** |
| 5487 | * megasas_register_aen - Registers for asynchronous event notification |
| 5488 | * @instance: Adapter soft state |
| 5489 | * @seq_num: The starting sequence number |
| 5490 | * @class_locale: Class of the event |
| 5491 | * |
| 5492 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 5493 | * to be notified if and only if the event is of type @class_locale |
| 5494 | */ |
| 5495 | static int |
| 5496 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 5497 | u32 class_locale_word) |
| 5498 | { |
| 5499 | int ret_val; |
| 5500 | struct megasas_cmd *cmd; |
| 5501 | struct megasas_dcmd_frame *dcmd; |
| 5502 | union megasas_evt_class_locale curr_aen; |
| 5503 | union megasas_evt_class_locale prev_aen; |
| 5504 | |
| 5505 | /* |
| 5506 | * If there an AEN pending already (aen_cmd), check if the |
| 5507 | * class_locale of that pending AEN is inclusive of the new |
| 5508 | * AEN request we currently have. If it is, then we don't have |
| 5509 | * to do anything. In other words, whichever events the current |
| 5510 | * AEN request is subscribing to, have already been subscribed |
| 5511 | * to. |
| 5512 | * |
| 5513 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 5514 | * that command, form a class_locale that is superset of both |
| 5515 | * old and current and re-issue to the FW |
| 5516 | */ |
| 5517 | |
| 5518 | curr_aen.word = class_locale_word; |
| 5519 | |
| 5520 | if (instance->aen_cmd) { |
| 5521 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 5522 | prev_aen.word = |
| 5523 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5524 | |
| 5525 | /* |
| 5526 | * A class whose enum value is smaller is inclusive of all |
| 5527 | * higher values. If a PROGRESS (= -1) was previously |
| 5528 | * registered, then a new registration requests for higher |
| 5529 | * classes need not be sent to FW. They are automatically |
| 5530 | * included. |
| 5531 | * |
| 5532 | * Locale numbers don't have such hierarchy. They are bitmap |
| 5533 | * values |
| 5534 | */ |
| 5535 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5536 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5537 | curr_aen.members.locale)) { |
| 5538 | /* |
| 5539 | * Previously issued event registration includes |
| 5540 | * current request. Nothing to do. |
| 5541 | */ |
| 5542 | return 0; |
| 5543 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5544 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5545 | |
| 5546 | if (prev_aen.members.class < curr_aen.members.class) |
| 5547 | curr_aen.members.class = prev_aen.members.class; |
| 5548 | |
| 5549 | instance->aen_cmd->abort_aen = 1; |
| 5550 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 5551 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5552 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5553 | |
| 5554 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5555 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5556 | "previous AEN command\n"); |
| 5557 | return ret_val; |
| 5558 | } |
| 5559 | } |
| 5560 | } |
| 5561 | |
| 5562 | cmd = megasas_get_cmd(instance); |
| 5563 | |
| 5564 | if (!cmd) |
| 5565 | return -ENOMEM; |
| 5566 | |
| 5567 | dcmd = &cmd->frame->dcmd; |
| 5568 | |
| 5569 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 5570 | |
| 5571 | /* |
| 5572 | * Prepare DCMD for aen registration |
| 5573 | */ |
| 5574 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5575 | |
| 5576 | dcmd->cmd = MFI_CMD_DCMD; |
| 5577 | dcmd->cmd_status = 0x0; |
| 5578 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5579 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5580 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5581 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5582 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 5583 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 5584 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5585 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5586 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
| 5587 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->evt_detail_h); |
| 5588 | 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] | 5589 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5590 | if (instance->aen_cmd != NULL) { |
| 5591 | megasas_return_cmd(instance, cmd); |
| 5592 | return 0; |
| 5593 | } |
| 5594 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5595 | /* |
| 5596 | * Store reference to the cmd used to register for AEN. When an |
| 5597 | * application wants us to register for AEN, we have to abort this |
| 5598 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 5599 | */ |
| 5600 | instance->aen_cmd = cmd; |
| 5601 | |
| 5602 | /* |
| 5603 | * Issue the aen registration frame |
| 5604 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5605 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5606 | |
| 5607 | return 0; |
| 5608 | } |
| 5609 | |
| 5610 | /** |
| 5611 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 5612 | * @instance: Adapter soft state |
| 5613 | */ |
| 5614 | static int megasas_start_aen(struct megasas_instance *instance) |
| 5615 | { |
| 5616 | struct megasas_evt_log_info eli; |
| 5617 | union megasas_evt_class_locale class_locale; |
| 5618 | |
| 5619 | /* |
| 5620 | * Get the latest sequence number from FW |
| 5621 | */ |
| 5622 | memset(&eli, 0, sizeof(eli)); |
| 5623 | |
| 5624 | if (megasas_get_seq_num(instance, &eli)) |
| 5625 | return -1; |
| 5626 | |
| 5627 | /* |
| 5628 | * Register AEN with FW for latest sequence number plus 1 |
| 5629 | */ |
| 5630 | class_locale.members.reserved = 0; |
| 5631 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 5632 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 5633 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5634 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5635 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5636 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | /** |
| 5640 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 5641 | * @instance: Adapter soft state |
| 5642 | */ |
| 5643 | static int megasas_io_attach(struct megasas_instance *instance) |
| 5644 | { |
| 5645 | struct Scsi_Host *host = instance->host; |
| 5646 | |
| 5647 | /* |
| 5648 | * Export parameters required by SCSI mid-layer |
| 5649 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5650 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5651 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5652 | host->this_id = instance->init_id; |
| 5653 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 5654 | |
| 5655 | if (instance->fw_support_ieee) |
| 5656 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 5657 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5658 | /* |
| 5659 | * Check if the module parameter value for max_sectors can be used |
| 5660 | */ |
| 5661 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 5662 | instance->max_sectors_per_req = max_sectors; |
| 5663 | else { |
| 5664 | if (max_sectors) { |
| 5665 | if (((instance->pdev->device == |
| 5666 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 5667 | (instance->pdev->device == |
| 5668 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 5669 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 5670 | instance->max_sectors_per_req = max_sectors; |
| 5671 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5672 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5673 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 5674 | instance->max_sectors_per_req); |
| 5675 | } |
| 5676 | } |
| 5677 | } |
| 5678 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5679 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5680 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5681 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 5682 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5683 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 5684 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5685 | |
| 5686 | /* |
| 5687 | * Notify the mid-layer about the new controller |
| 5688 | */ |
| 5689 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5690 | dev_err(&instance->pdev->dev, |
| 5691 | "Failed to add host from %s %d\n", |
| 5692 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5693 | return -ENODEV; |
| 5694 | } |
| 5695 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5696 | return 0; |
| 5697 | } |
| 5698 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5699 | static int |
| 5700 | megasas_set_dma_mask(struct pci_dev *pdev) |
| 5701 | { |
| 5702 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5703 | * All our controllers are capable of performing 64-bit DMA |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5704 | */ |
| 5705 | if (IS_DMA64) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5706 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5707 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5708 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5709 | goto fail_set_dma_mask; |
| 5710 | } |
| 5711 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5712 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5713 | goto fail_set_dma_mask; |
| 5714 | } |
Sumit.Saxena@lsi.com | 46de63e2 | 2014-02-12 23:38:44 +0530 | [diff] [blame] | 5715 | /* |
| 5716 | * Ensure that all data structures are allocated in 32-bit |
| 5717 | * memory. |
| 5718 | */ |
| 5719 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
| 5720 | /* Try 32bit DMA mask and 32 bit Consistent dma mask */ |
| 5721 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 5722 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 5723 | dev_info(&pdev->dev, "set 32bit DMA mask" |
| 5724 | "and 32 bit consistent mask\n"); |
| 5725 | else |
| 5726 | goto fail_set_dma_mask; |
| 5727 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5728 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5729 | return 0; |
| 5730 | |
| 5731 | fail_set_dma_mask: |
| 5732 | return 1; |
| 5733 | } |
| 5734 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5735 | /** |
| 5736 | * megasas_probe_one - PCI hotplug entry point |
| 5737 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 5738 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5739 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5740 | static int megasas_probe_one(struct pci_dev *pdev, |
| 5741 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5742 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5743 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5744 | struct Scsi_Host *host; |
| 5745 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5746 | u16 control = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5747 | struct fusion_context *fusion = NULL; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5748 | |
| 5749 | /* Reset MSI-X in the kdump kernel */ |
| 5750 | if (reset_devices) { |
| 5751 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 5752 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5753 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5754 | &control); |
| 5755 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 5756 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 5757 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5758 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5759 | control & |
| 5760 | ~PCI_MSIX_FLAGS_ENABLE); |
| 5761 | } |
| 5762 | } |
| 5763 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5764 | |
| 5765 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5766 | * PCI prepping: enable device set bus mastering and dma mask |
| 5767 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 5768 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5769 | |
| 5770 | if (rval) { |
| 5771 | return rval; |
| 5772 | } |
| 5773 | |
| 5774 | pci_set_master(pdev); |
| 5775 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5776 | if (megasas_set_dma_mask(pdev)) |
| 5777 | goto fail_set_dma_mask; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5778 | |
| 5779 | host = scsi_host_alloc(&megasas_template, |
| 5780 | sizeof(struct megasas_instance)); |
| 5781 | |
| 5782 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5783 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5784 | goto fail_alloc_instance; |
| 5785 | } |
| 5786 | |
| 5787 | instance = (struct megasas_instance *)host->hostdata; |
| 5788 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5789 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5790 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5791 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5792 | switch (instance->pdev->device) { |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 5793 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 5794 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 5795 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 5796 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 5797 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 5798 | instance->is_ventura = true; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5799 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5800 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5801 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5802 | case PCI_DEVICE_ID_LSI_FURY: |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 5803 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 5804 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 5805 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 5806 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5807 | { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5808 | instance->ctrl_context_pages = |
| 5809 | get_order(sizeof(struct fusion_context)); |
| 5810 | instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL, |
| 5811 | instance->ctrl_context_pages); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5812 | if (!instance->ctrl_context) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5813 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5814 | "memory for Fusion context info\n"); |
| 5815 | goto fail_alloc_dma_buf; |
| 5816 | } |
| 5817 | fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5818 | memset(fusion, 0, |
| 5819 | ((1 << PAGE_SHIFT) << instance->ctrl_context_pages)); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5820 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
| 5821 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA)) |
| 5822 | fusion->adapter_type = THUNDERBOLT_SERIES; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5823 | else if (instance->is_ventura) |
| 5824 | fusion->adapter_type = VENTURA_SERIES; |
| 5825 | else |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5826 | fusion->adapter_type = INVADER_SERIES; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5827 | } |
| 5828 | break; |
| 5829 | default: /* For all other supported controllers */ |
| 5830 | |
| 5831 | instance->producer = |
| 5832 | pci_alloc_consistent(pdev, sizeof(u32), |
| 5833 | &instance->producer_h); |
| 5834 | instance->consumer = |
| 5835 | pci_alloc_consistent(pdev, sizeof(u32), |
| 5836 | &instance->consumer_h); |
| 5837 | |
| 5838 | if (!instance->producer || !instance->consumer) { |
Colin Ian King | 4086eae5 | 2016-09-12 13:42:12 +0100 | [diff] [blame] | 5839 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5840 | "memory for producer, consumer\n"); |
| 5841 | goto fail_alloc_dma_buf; |
| 5842 | } |
| 5843 | |
| 5844 | *instance->producer = 0; |
| 5845 | *instance->consumer = 0; |
| 5846 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5847 | } |
| 5848 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5849 | /* Crash dump feature related initialisation*/ |
| 5850 | instance->drv_buf_index = 0; |
| 5851 | instance->drv_buf_alloc = 0; |
| 5852 | instance->crash_dump_fw_support = 0; |
| 5853 | instance->crash_dump_app_support = 0; |
| 5854 | instance->fw_crash_state = UNAVAILABLE; |
| 5855 | spin_lock_init(&instance->crashdump_lock); |
| 5856 | instance->crash_dump_buf = NULL; |
| 5857 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5858 | megasas_poll_wait_aen = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5859 | instance->flag_ieee = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5860 | instance->ev = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5861 | instance->issuepend_done = 1; |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 5862 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5863 | instance->is_imr = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5864 | |
| 5865 | instance->evt_detail = pci_alloc_consistent(pdev, |
| 5866 | sizeof(struct |
| 5867 | megasas_evt_detail), |
| 5868 | &instance->evt_detail_h); |
| 5869 | |
| 5870 | if (!instance->evt_detail) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5871 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate memory for " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5872 | "event detail structure\n"); |
| 5873 | goto fail_alloc_dma_buf; |
| 5874 | } |
| 5875 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 5876 | if (!reset_devices) { |
| 5877 | instance->system_info_buf = pci_zalloc_consistent(pdev, |
| 5878 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 5879 | &instance->system_info_h); |
| 5880 | if (!instance->system_info_buf) |
| 5881 | dev_info(&instance->pdev->dev, "Can't allocate system info buffer\n"); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 5882 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 5883 | instance->pd_info = pci_alloc_consistent(pdev, |
| 5884 | sizeof(struct MR_PD_INFO), &instance->pd_info_h); |
| 5885 | |
| 5886 | if (!instance->pd_info) |
| 5887 | dev_err(&instance->pdev->dev, "Failed to alloc mem for pd_info\n"); |
| 5888 | |
| 5889 | instance->crash_dump_buf = pci_alloc_consistent(pdev, |
| 5890 | CRASH_DMA_BUF_SIZE, |
| 5891 | &instance->crash_dump_h); |
| 5892 | if (!instance->crash_dump_buf) |
| 5893 | dev_err(&pdev->dev, "Can't allocate Firmware " |
| 5894 | "crash dump DMA buffer\n"); |
| 5895 | } |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 5896 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5897 | /* |
| 5898 | * Initialize locks and queues |
| 5899 | */ |
| 5900 | INIT_LIST_HEAD(&instance->cmd_pool); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5901 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5902 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 5903 | atomic_set(&instance->fw_outstanding,0); |
| 5904 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5905 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 5906 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 5907 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5908 | spin_lock_init(&instance->mfi_pool_lock); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5909 | spin_lock_init(&instance->hba_lock); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5910 | spin_lock_init(&instance->stream_lock); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 5911 | spin_lock_init(&instance->completion_lock); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5912 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5913 | mutex_init(&instance->reset_mutex); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 5914 | mutex_init(&instance->hba_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5915 | |
| 5916 | /* |
| 5917 | * Initialize PCI related and misc parameters |
| 5918 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5919 | instance->host = host; |
| 5920 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 5921 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5922 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5923 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5924 | |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5925 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5926 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5927 | instance->flag_ieee = 1; |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5928 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5929 | megasas_dbg_lvl = 0; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 5930 | instance->flag = 0; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5931 | instance->unload = 1; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 5932 | instance->last_time = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5933 | instance->disableOnlineCtrlReset = 1; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5934 | instance->UnevenSpanSupport = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5935 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5936 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5937 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5938 | INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq); |
| 5939 | } else |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5940 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5941 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5942 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 5943 | * Initialize MFI Firmware |
| 5944 | */ |
| 5945 | if (megasas_init_fw(instance)) |
| 5946 | goto fail_init_mfi; |
| 5947 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5948 | if (instance->requestorId) { |
| 5949 | if (instance->PlasmaFW111) { |
| 5950 | instance->vf_affiliation_111 = |
| 5951 | pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 5952 | &instance->vf_affiliation_111_h); |
| 5953 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5954 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5955 | "memory for VF affiliation buffer\n"); |
| 5956 | } else { |
| 5957 | instance->vf_affiliation = |
| 5958 | pci_alloc_consistent(pdev, |
| 5959 | (MAX_LOGICAL_DRIVES + 1) * |
| 5960 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 5961 | &instance->vf_affiliation_h); |
| 5962 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5963 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5964 | "memory for VF affiliation buffer\n"); |
| 5965 | } |
| 5966 | } |
| 5967 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5968 | /* |
| 5969 | * Store instance in PCI softstate |
| 5970 | */ |
| 5971 | pci_set_drvdata(pdev, instance); |
| 5972 | |
| 5973 | /* |
| 5974 | * Add this controller to megasas_mgmt_info structure so that it |
| 5975 | * can be exported to management applications |
| 5976 | */ |
| 5977 | megasas_mgmt_info.count++; |
| 5978 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 5979 | megasas_mgmt_info.max_index++; |
| 5980 | |
| 5981 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 5982 | * Register with SCSI mid-layer |
| 5983 | */ |
| 5984 | if (megasas_io_attach(instance)) |
| 5985 | goto fail_io_attach; |
| 5986 | |
| 5987 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 5988 | /* |
| 5989 | * Trigger SCSI to scan our drives |
| 5990 | */ |
| 5991 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 5992 | |
| 5993 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5994 | * Initiate AEN (Asynchronous Event Notification) |
| 5995 | */ |
| 5996 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5997 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5998 | goto fail_start_aen; |
| 5999 | } |
| 6000 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 6001 | /* Get current SR-IOV LD/VF affiliation */ |
| 6002 | if (instance->requestorId) |
| 6003 | megasas_get_ld_vf_affiliation(instance, 1); |
| 6004 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6005 | return 0; |
| 6006 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6007 | fail_start_aen: |
| 6008 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6009 | megasas_mgmt_info.count--; |
| 6010 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
| 6011 | megasas_mgmt_info.max_index--; |
| 6012 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6013 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6014 | megasas_destroy_irqs(instance); |
| 6015 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6016 | if (instance->ctrl_context) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6017 | megasas_release_fusion(instance); |
| 6018 | else |
| 6019 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6020 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6021 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6022 | fail_init_mfi: |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6023 | fail_alloc_dma_buf: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6024 | if (instance->evt_detail) |
| 6025 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6026 | instance->evt_detail, |
| 6027 | instance->evt_detail_h); |
| 6028 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6029 | if (instance->pd_info) |
| 6030 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6031 | instance->pd_info, |
| 6032 | instance->pd_info_h); |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6033 | if (instance->producer) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6034 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6035 | instance->producer_h); |
| 6036 | if (instance->consumer) |
| 6037 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6038 | instance->consumer_h); |
| 6039 | scsi_host_put(host); |
| 6040 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6041 | fail_alloc_instance: |
| 6042 | fail_set_dma_mask: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6043 | pci_disable_device(pdev); |
| 6044 | |
| 6045 | return -ENODEV; |
| 6046 | } |
| 6047 | |
| 6048 | /** |
| 6049 | * megasas_flush_cache - Requests FW to flush all its caches |
| 6050 | * @instance: Adapter soft state |
| 6051 | */ |
| 6052 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 6053 | { |
| 6054 | struct megasas_cmd *cmd; |
| 6055 | struct megasas_dcmd_frame *dcmd; |
| 6056 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6057 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6058 | return; |
| 6059 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6060 | cmd = megasas_get_cmd(instance); |
| 6061 | |
| 6062 | if (!cmd) |
| 6063 | return; |
| 6064 | |
| 6065 | dcmd = &cmd->frame->dcmd; |
| 6066 | |
| 6067 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6068 | |
| 6069 | dcmd->cmd = MFI_CMD_DCMD; |
| 6070 | dcmd->cmd_status = 0x0; |
| 6071 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6072 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6073 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6074 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6075 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6076 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6077 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 6078 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6079 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6080 | != DCMD_SUCCESS) { |
| 6081 | dev_err(&instance->pdev->dev, |
| 6082 | "return from %s %d\n", __func__, __LINE__); |
| 6083 | return; |
| 6084 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6085 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6086 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | /** |
| 6090 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 6091 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6092 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6093 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6094 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 6095 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6096 | { |
| 6097 | struct megasas_cmd *cmd; |
| 6098 | struct megasas_dcmd_frame *dcmd; |
| 6099 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6100 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6101 | return; |
| 6102 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6103 | cmd = megasas_get_cmd(instance); |
| 6104 | |
| 6105 | if (!cmd) |
| 6106 | return; |
| 6107 | |
| 6108 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6109 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6110 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6111 | if (instance->map_update_cmd) |
| 6112 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6113 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6114 | if (instance->jbod_seq_cmd) |
| 6115 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6116 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6117 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6118 | dcmd = &cmd->frame->dcmd; |
| 6119 | |
| 6120 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6121 | |
| 6122 | dcmd->cmd = MFI_CMD_DCMD; |
| 6123 | dcmd->cmd_status = 0x0; |
| 6124 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6125 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6126 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6127 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6128 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6129 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6130 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6131 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6132 | != DCMD_SUCCESS) { |
| 6133 | dev_err(&instance->pdev->dev, |
| 6134 | "return from %s %d\n", __func__, __LINE__); |
| 6135 | return; |
| 6136 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6137 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6138 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6139 | } |
| 6140 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6141 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6142 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6143 | * megasas_suspend - driver suspend entry point |
| 6144 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6145 | * @state: PCI power state to suspend routine |
| 6146 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6147 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6148 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6149 | { |
| 6150 | struct Scsi_Host *host; |
| 6151 | struct megasas_instance *instance; |
| 6152 | |
| 6153 | instance = pci_get_drvdata(pdev); |
| 6154 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6155 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6156 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6157 | /* Shutdown SR-IOV heartbeat timer */ |
| 6158 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6159 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6160 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6161 | megasas_flush_cache(instance); |
| 6162 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6163 | |
| 6164 | /* cancel the delayed work if this work still in queue */ |
| 6165 | if (instance->ev != NULL) { |
| 6166 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6167 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6168 | instance->ev = NULL; |
| 6169 | } |
| 6170 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6171 | tasklet_kill(&instance->isr_tasklet); |
| 6172 | |
| 6173 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6174 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6175 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6176 | megasas_destroy_irqs(instance); |
| 6177 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6178 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6179 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6180 | |
| 6181 | pci_save_state(pdev); |
| 6182 | pci_disable_device(pdev); |
| 6183 | |
| 6184 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 6185 | |
| 6186 | return 0; |
| 6187 | } |
| 6188 | |
| 6189 | /** |
| 6190 | * megasas_resume- driver resume entry point |
| 6191 | * @pdev: PCI device structure |
| 6192 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6193 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6194 | megasas_resume(struct pci_dev *pdev) |
| 6195 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6196 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6197 | struct Scsi_Host *host; |
| 6198 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6199 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6200 | |
| 6201 | instance = pci_get_drvdata(pdev); |
| 6202 | host = instance->host; |
| 6203 | pci_set_power_state(pdev, PCI_D0); |
| 6204 | pci_enable_wake(pdev, PCI_D0, 0); |
| 6205 | pci_restore_state(pdev); |
| 6206 | |
| 6207 | /* |
| 6208 | * PCI prepping: enable device set bus mastering and dma mask |
| 6209 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6210 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6211 | |
| 6212 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6213 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6214 | return rval; |
| 6215 | } |
| 6216 | |
| 6217 | pci_set_master(pdev); |
| 6218 | |
| 6219 | if (megasas_set_dma_mask(pdev)) |
| 6220 | goto fail_set_dma_mask; |
| 6221 | |
| 6222 | /* |
| 6223 | * Initialize MFI Firmware |
| 6224 | */ |
| 6225 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6226 | atomic_set(&instance->fw_outstanding, 0); |
| 6227 | |
| 6228 | /* |
| 6229 | * We expect the FW state to be READY |
| 6230 | */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 6231 | if (megasas_transition_to_ready(instance, 0)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6232 | goto fail_ready_state; |
| 6233 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6234 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6235 | if (instance->msix_vectors) { |
| 6236 | irq_flags = PCI_IRQ_MSIX; |
| 6237 | if (smp_affinity_enable) |
| 6238 | irq_flags |= PCI_IRQ_AFFINITY; |
| 6239 | } |
| 6240 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 6241 | instance->msix_vectors ? |
| 6242 | instance->msix_vectors : 1, irq_flags); |
| 6243 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6244 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6245 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6246 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6247 | megasas_reset_reply_desc(instance); |
| 6248 | if (megasas_ioc_init_fusion(instance)) { |
| 6249 | megasas_free_cmds(instance); |
| 6250 | megasas_free_cmds_fusion(instance); |
| 6251 | goto fail_init_mfi; |
| 6252 | } |
| 6253 | if (!megasas_get_map_info(instance)) |
| 6254 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6255 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6256 | *instance->producer = 0; |
| 6257 | *instance->consumer = 0; |
| 6258 | if (megasas_issue_init_mfi(instance)) |
| 6259 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6260 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6261 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6262 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 6263 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6264 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6265 | if (instance->msix_vectors ? |
| 6266 | megasas_setup_irqs_msix(instance, 0) : |
| 6267 | megasas_setup_irqs_ioapic(instance)) |
| 6268 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6269 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6270 | /* Re-launch SR-IOV heartbeat timer */ |
| 6271 | if (instance->requestorId) { |
| 6272 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 6273 | megasas_start_timer(instance, |
| 6274 | &instance->sriov_heartbeat_timer, |
| 6275 | megasas_sriov_heartbeat_handler, |
| 6276 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6277 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6278 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6279 | goto fail_init_mfi; |
| 6280 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6281 | } |
| 6282 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6283 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6284 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6285 | instance->unload = 0; |
| 6286 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6287 | /* |
| 6288 | * Initiate AEN (Asynchronous Event Notification) |
| 6289 | */ |
| 6290 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6291 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6292 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6293 | return 0; |
| 6294 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6295 | fail_init_mfi: |
| 6296 | if (instance->evt_detail) |
| 6297 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6298 | instance->evt_detail, |
| 6299 | instance->evt_detail_h); |
| 6300 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6301 | if (instance->pd_info) |
| 6302 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6303 | instance->pd_info, |
| 6304 | instance->pd_info_h); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6305 | if (instance->producer) |
| 6306 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6307 | instance->producer_h); |
| 6308 | if (instance->consumer) |
| 6309 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6310 | instance->consumer_h); |
| 6311 | scsi_host_put(host); |
| 6312 | |
| 6313 | fail_set_dma_mask: |
| 6314 | fail_ready_state: |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6315 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6316 | |
| 6317 | pci_disable_device(pdev); |
| 6318 | |
| 6319 | return -ENODEV; |
| 6320 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6321 | #else |
| 6322 | #define megasas_suspend NULL |
| 6323 | #define megasas_resume NULL |
| 6324 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6325 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6326 | static inline int |
| 6327 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 6328 | { |
| 6329 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 6330 | int i; |
| 6331 | |
| 6332 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
| 6333 | return 1; |
| 6334 | |
| 6335 | for (i = 0; i < wait_time; i++) { |
| 6336 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
| 6337 | break; |
| 6338 | |
| 6339 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 6340 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 6341 | |
| 6342 | msleep(1000); |
| 6343 | } |
| 6344 | |
| 6345 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
| 6346 | dev_info(&instance->pdev->dev, "%s timed out while waiting for HBA to recover.\n", |
| 6347 | __func__); |
| 6348 | return 1; |
| 6349 | } |
| 6350 | |
| 6351 | return 0; |
| 6352 | } |
| 6353 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6354 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6355 | * megasas_detach_one - PCI hot"un"plug entry point |
| 6356 | * @pdev: PCI device structure |
| 6357 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6358 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6359 | { |
| 6360 | int i; |
| 6361 | struct Scsi_Host *host; |
| 6362 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6363 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6364 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6365 | |
| 6366 | instance = pci_get_drvdata(pdev); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6367 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6368 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6369 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6370 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6371 | /* Shutdown SR-IOV heartbeat timer */ |
| 6372 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6373 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6374 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6375 | if (instance->fw_crash_state != UNAVAILABLE) |
| 6376 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6377 | scsi_remove_host(instance->host); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6378 | |
| 6379 | if (megasas_wait_for_adapter_operational(instance)) |
| 6380 | goto skip_firing_dcmds; |
| 6381 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6382 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6383 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6384 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6385 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6386 | /* cancel the delayed work if this work still in queue*/ |
| 6387 | if (instance->ev != NULL) { |
| 6388 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6389 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6390 | instance->ev = NULL; |
| 6391 | } |
| 6392 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6393 | /* cancel all wait events */ |
| 6394 | wake_up_all(&instance->int_cmd_wait_q); |
| 6395 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 6396 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6397 | |
| 6398 | /* |
| 6399 | * Take the instance off the instance array. Note that we will not |
| 6400 | * decrement the max_index. We let this array be sparse array |
| 6401 | */ |
| 6402 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6403 | if (megasas_mgmt_info.instance[i] == instance) { |
| 6404 | megasas_mgmt_info.count--; |
| 6405 | megasas_mgmt_info.instance[i] = NULL; |
| 6406 | |
| 6407 | break; |
| 6408 | } |
| 6409 | } |
| 6410 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6411 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6412 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6413 | megasas_destroy_irqs(instance); |
| 6414 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6415 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6416 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6417 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6418 | if (instance->is_ventura) { |
| 6419 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 6420 | kfree(fusion->stream_detect_by_ld[i]); |
| 6421 | kfree(fusion->stream_detect_by_ld); |
| 6422 | fusion->stream_detect_by_ld = NULL; |
| 6423 | } |
| 6424 | |
| 6425 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6426 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6427 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6428 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 6429 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 6430 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6431 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6432 | if (fusion->ld_map[i]) |
| 6433 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6434 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6435 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6436 | fusion->ld_map_phys[i]); |
| 6437 | if (fusion->ld_drv_map[i]) |
| 6438 | free_pages((ulong)fusion->ld_drv_map[i], |
| 6439 | fusion->drv_map_pages); |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 6440 | if (fusion->pd_seq_sync[i]) |
| 6441 | dma_free_coherent(&instance->pdev->dev, |
| 6442 | pd_seq_map_sz, |
| 6443 | fusion->pd_seq_sync[i], |
| 6444 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6445 | } |
| 6446 | free_pages((ulong)instance->ctrl_context, |
| 6447 | instance->ctrl_context_pages); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6448 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6449 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6450 | pci_free_consistent(pdev, sizeof(u32), |
| 6451 | instance->producer, |
| 6452 | instance->producer_h); |
| 6453 | pci_free_consistent(pdev, sizeof(u32), |
| 6454 | instance->consumer, |
| 6455 | instance->consumer_h); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6456 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6457 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6458 | kfree(instance->ctrl_info); |
| 6459 | |
Sumit.Saxena@lsi.com | 105900d | 2013-05-22 12:30:54 +0530 | [diff] [blame] | 6460 | if (instance->evt_detail) |
| 6461 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6462 | instance->evt_detail, instance->evt_detail_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6463 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6464 | if (instance->pd_info) |
| 6465 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6466 | instance->pd_info, |
| 6467 | instance->pd_info_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6468 | if (instance->vf_affiliation) |
| 6469 | pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) * |
| 6470 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6471 | instance->vf_affiliation, |
| 6472 | instance->vf_affiliation_h); |
| 6473 | |
| 6474 | if (instance->vf_affiliation_111) |
| 6475 | pci_free_consistent(pdev, |
| 6476 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6477 | instance->vf_affiliation_111, |
| 6478 | instance->vf_affiliation_111_h); |
| 6479 | |
| 6480 | if (instance->hb_host_mem) |
| 6481 | pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 6482 | instance->hb_host_mem, |
| 6483 | instance->hb_host_mem_h); |
| 6484 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6485 | if (instance->crash_dump_buf) |
| 6486 | pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE, |
| 6487 | instance->crash_dump_buf, instance->crash_dump_h); |
| 6488 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6489 | if (instance->system_info_buf) |
| 6490 | pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6491 | instance->system_info_buf, instance->system_info_h); |
| 6492 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6493 | scsi_host_put(host); |
| 6494 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6495 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6496 | } |
| 6497 | |
| 6498 | /** |
| 6499 | * megasas_shutdown - Shutdown entry point |
| 6500 | * @device: Generic device structure |
| 6501 | */ |
| 6502 | static void megasas_shutdown(struct pci_dev *pdev) |
| 6503 | { |
| 6504 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6505 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6506 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6507 | |
| 6508 | if (megasas_wait_for_adapter_operational(instance)) |
| 6509 | goto skip_firing_dcmds; |
| 6510 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6511 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 6512 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6513 | |
| 6514 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6515 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6516 | megasas_destroy_irqs(instance); |
| 6517 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6518 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6519 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6520 | } |
| 6521 | |
| 6522 | /** |
| 6523 | * megasas_mgmt_open - char node "open" entry point |
| 6524 | */ |
| 6525 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 6526 | { |
| 6527 | /* |
| 6528 | * Allow only those users with admin rights |
| 6529 | */ |
| 6530 | if (!capable(CAP_SYS_ADMIN)) |
| 6531 | return -EACCES; |
| 6532 | |
| 6533 | return 0; |
| 6534 | } |
| 6535 | |
| 6536 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6537 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 6538 | * |
| 6539 | * This function adds the calling process to a driver global queue. When an |
| 6540 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 6541 | */ |
| 6542 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 6543 | { |
| 6544 | int rc; |
| 6545 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6546 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6547 | |
| 6548 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 6549 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6550 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6551 | |
| 6552 | if (rc >= 0) { |
| 6553 | /* For sanity check when we get ioctl */ |
| 6554 | filep->private_data = filep; |
| 6555 | return 0; |
| 6556 | } |
| 6557 | |
| 6558 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 6559 | |
| 6560 | return rc; |
| 6561 | } |
| 6562 | |
| 6563 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6564 | * megasas_mgmt_poll - char node "poll" entry point |
| 6565 | * */ |
| 6566 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 6567 | { |
| 6568 | unsigned int mask; |
| 6569 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6570 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6571 | poll_wait(file, &megasas_poll_wait, wait); |
| 6572 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 6573 | if (megasas_poll_wait_aen) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6574 | mask = (POLLIN | POLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6575 | else |
| 6576 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6577 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6578 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 6579 | return mask; |
| 6580 | } |
| 6581 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6582 | /* |
| 6583 | * megasas_set_crash_dump_params_ioctl: |
| 6584 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 6585 | * @cmd: MFI command frame |
| 6586 | */ |
| 6587 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6588 | 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] | 6589 | { |
| 6590 | struct megasas_instance *local_instance; |
| 6591 | int i, error = 0; |
| 6592 | int crash_support; |
| 6593 | |
| 6594 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 6595 | |
| 6596 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6597 | local_instance = megasas_mgmt_info.instance[i]; |
| 6598 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6599 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6600 | MEGASAS_HBA_OPERATIONAL) && |
| 6601 | !megasas_set_crash_dump_params(local_instance, |
| 6602 | crash_support)) { |
| 6603 | local_instance->crash_dump_app_support = |
| 6604 | crash_support; |
| 6605 | dev_info(&local_instance->pdev->dev, |
| 6606 | "Application firmware crash " |
| 6607 | "dump mode set success\n"); |
| 6608 | error = 0; |
| 6609 | } else { |
| 6610 | dev_info(&local_instance->pdev->dev, |
| 6611 | "Application firmware crash " |
| 6612 | "dump mode set failed\n"); |
| 6613 | error = -1; |
| 6614 | } |
| 6615 | } |
| 6616 | } |
| 6617 | return error; |
| 6618 | } |
| 6619 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6620 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6621 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 6622 | * @instance: Adapter soft state |
| 6623 | * @argp: User's ioctl packet |
| 6624 | */ |
| 6625 | static int |
| 6626 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 6627 | struct megasas_iocpacket __user * user_ioc, |
| 6628 | struct megasas_iocpacket *ioc) |
| 6629 | { |
| 6630 | struct megasas_sge32 *kern_sge32; |
| 6631 | struct megasas_cmd *cmd; |
| 6632 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 6633 | dma_addr_t buf_handle = 0; |
| 6634 | int error = 0, i; |
| 6635 | void *sense = NULL; |
| 6636 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6637 | unsigned long *sense_ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6638 | |
| 6639 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 6640 | |
| 6641 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6642 | 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] | 6643 | ioc->sge_count, MAX_IOCTL_SGE); |
| 6644 | return -EINVAL; |
| 6645 | } |
| 6646 | |
| 6647 | cmd = megasas_get_cmd(instance); |
| 6648 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6649 | 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] | 6650 | return -ENOMEM; |
| 6651 | } |
| 6652 | |
| 6653 | /* |
| 6654 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 6655 | * frames into our cmd's frames. cmd->frame's context will get |
| 6656 | * overwritten when we copy from user's frames. So set that value |
| 6657 | * alone separately |
| 6658 | */ |
| 6659 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6660 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6661 | cmd->frame->hdr.pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6662 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE | |
| 6663 | MFI_FRAME_SGL64 | |
| 6664 | MFI_FRAME_SENSE64)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6665 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6666 | if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
| 6667 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 6668 | megasas_return_cmd(instance, cmd); |
| 6669 | return error; |
| 6670 | } |
| 6671 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6672 | /* |
| 6673 | * The management interface between applications and the fw uses |
| 6674 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 6675 | * etc are accomplishes through different kinds of MFI frames. The |
| 6676 | * driver needs to care only about substituting user buffers with |
| 6677 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 6678 | * struct iocpacket itself. |
| 6679 | */ |
| 6680 | kern_sge32 = (struct megasas_sge32 *) |
| 6681 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 6682 | |
| 6683 | /* |
| 6684 | * For each user buffer, create a mirror buffer and copy in |
| 6685 | */ |
| 6686 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 6687 | if (!ioc->sgl[i].iov_len) |
| 6688 | continue; |
| 6689 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6690 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6691 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6692 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6693 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6694 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 6695 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6696 | error = -ENOMEM; |
| 6697 | goto out; |
| 6698 | } |
| 6699 | |
| 6700 | /* |
| 6701 | * We don't change the dma_coherent_mask, so |
| 6702 | * pci_alloc_consistent only returns 32bit addresses |
| 6703 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6704 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 6705 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6706 | |
| 6707 | /* |
| 6708 | * We created a kernel buffer corresponding to the |
| 6709 | * user buffer. Now copy in from the user buffer |
| 6710 | */ |
| 6711 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 6712 | (u32) (ioc->sgl[i].iov_len))) { |
| 6713 | error = -EFAULT; |
| 6714 | goto out; |
| 6715 | } |
| 6716 | } |
| 6717 | |
| 6718 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6719 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 6720 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6721 | if (!sense) { |
| 6722 | error = -ENOMEM; |
| 6723 | goto out; |
| 6724 | } |
| 6725 | |
| 6726 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6727 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6728 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6729 | } |
| 6730 | |
| 6731 | /* |
| 6732 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 6733 | * cmd to the SCSI mid-layer |
| 6734 | */ |
| 6735 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6736 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 6737 | cmd->sync_cmd = 0; |
| 6738 | dev_err(&instance->pdev->dev, |
| 6739 | "return -EBUSY from %s %d opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 6740 | __func__, __LINE__, cmd->frame->dcmd.opcode, |
| 6741 | cmd->cmd_status_drv); |
| 6742 | return -EBUSY; |
| 6743 | } |
| 6744 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6745 | cmd->sync_cmd = 0; |
| 6746 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6747 | if (instance->unload == 1) { |
| 6748 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 6749 | "don't submit data to application\n"); |
| 6750 | goto out; |
| 6751 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6752 | /* |
| 6753 | * copy out the kernel buffers to user buffers |
| 6754 | */ |
| 6755 | for (i = 0; i < ioc->sge_count; i++) { |
| 6756 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 6757 | ioc->sgl[i].iov_len)) { |
| 6758 | error = -EFAULT; |
| 6759 | goto out; |
| 6760 | } |
| 6761 | } |
| 6762 | |
| 6763 | /* |
| 6764 | * copy out the sense |
| 6765 | */ |
| 6766 | if (ioc->sense_len) { |
| 6767 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 6768 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6769 | * sense buffer address |
| 6770 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6771 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 6772 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6773 | |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 6774 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), |
| 6775 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6776 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 6777 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6778 | error = -EFAULT; |
| 6779 | goto out; |
| 6780 | } |
| 6781 | } |
| 6782 | |
| 6783 | /* |
| 6784 | * copy the status codes returned by the fw |
| 6785 | */ |
| 6786 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 6787 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6788 | 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] | 6789 | error = -EFAULT; |
| 6790 | } |
| 6791 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6792 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6793 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6794 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6795 | sense, sense_handle); |
| 6796 | } |
| 6797 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6798 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 6799 | if (kbuff_arr[i]) { |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6800 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6801 | le32_to_cpu(kern_sge32[i].length), |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6802 | kbuff_arr[i], |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6803 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 6804 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 6805 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6806 | } |
| 6807 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6808 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6809 | return error; |
| 6810 | } |
| 6811 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6812 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 6813 | { |
| 6814 | struct megasas_iocpacket __user *user_ioc = |
| 6815 | (struct megasas_iocpacket __user *)arg; |
| 6816 | struct megasas_iocpacket *ioc; |
| 6817 | struct megasas_instance *instance; |
| 6818 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6819 | int i; |
| 6820 | unsigned long flags; |
| 6821 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6822 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 6823 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 6824 | if (IS_ERR(ioc)) |
| 6825 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6826 | |
| 6827 | instance = megasas_lookup_instance(ioc->host_no); |
| 6828 | if (!instance) { |
| 6829 | error = -ENODEV; |
| 6830 | goto out_kfree_ioc; |
| 6831 | } |
| 6832 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6833 | /* Adjust ioctl wait time for VF mode */ |
| 6834 | if (instance->requestorId) |
| 6835 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 6836 | |
| 6837 | /* Block ioctls in VF mode */ |
| 6838 | if (instance->requestorId && !allow_vf_ioctls) { |
| 6839 | error = -ENODEV; |
| 6840 | goto out_kfree_ioc; |
| 6841 | } |
| 6842 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6843 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6844 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6845 | error = -ENODEV; |
| 6846 | goto out_kfree_ioc; |
| 6847 | } |
| 6848 | |
| 6849 | if (instance->unload == 1) { |
| 6850 | error = -ENODEV; |
| 6851 | goto out_kfree_ioc; |
| 6852 | } |
| 6853 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6854 | if (down_interruptible(&instance->ioctl_sem)) { |
| 6855 | error = -ERESTARTSYS; |
| 6856 | goto out_kfree_ioc; |
| 6857 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6858 | |
| 6859 | for (i = 0; i < wait_time; i++) { |
| 6860 | |
| 6861 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6862 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6863 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6864 | break; |
| 6865 | } |
| 6866 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6867 | |
| 6868 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6869 | dev_notice(&instance->pdev->dev, "waiting" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6870 | "for controller reset to finish\n"); |
| 6871 | } |
| 6872 | |
| 6873 | msleep(1000); |
| 6874 | } |
| 6875 | |
| 6876 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6877 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6878 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6879 | |
Colin Ian King | 644da3c | 2016-11-12 16:25:24 +0000 | [diff] [blame] | 6880 | 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] | 6881 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 6882 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6883 | } |
| 6884 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6885 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6886 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6887 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6888 | up(&instance->ioctl_sem); |
| 6889 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6890 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6891 | kfree(ioc); |
| 6892 | return error; |
| 6893 | } |
| 6894 | |
| 6895 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 6896 | { |
| 6897 | struct megasas_instance *instance; |
| 6898 | struct megasas_aen aen; |
| 6899 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6900 | int i; |
| 6901 | unsigned long flags; |
| 6902 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6903 | |
| 6904 | if (file->private_data != file) { |
| 6905 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 6906 | "called first\n"); |
| 6907 | return -EINVAL; |
| 6908 | } |
| 6909 | |
| 6910 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 6911 | return -EFAULT; |
| 6912 | |
| 6913 | instance = megasas_lookup_instance(aen.host_no); |
| 6914 | |
| 6915 | if (!instance) |
| 6916 | return -ENODEV; |
| 6917 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6918 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6919 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6920 | } |
| 6921 | |
| 6922 | if (instance->unload == 1) { |
| 6923 | return -ENODEV; |
| 6924 | } |
| 6925 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6926 | for (i = 0; i < wait_time; i++) { |
| 6927 | |
| 6928 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6929 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6930 | spin_unlock_irqrestore(&instance->hba_lock, |
| 6931 | flags); |
| 6932 | break; |
| 6933 | } |
| 6934 | |
| 6935 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6936 | |
| 6937 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6938 | dev_notice(&instance->pdev->dev, "waiting for" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6939 | "controller reset to finish\n"); |
| 6940 | } |
| 6941 | |
| 6942 | msleep(1000); |
| 6943 | } |
| 6944 | |
| 6945 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6946 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6947 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Colin Ian King | 644da3c | 2016-11-12 16:25:24 +0000 | [diff] [blame] | 6948 | 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] | 6949 | return -ENODEV; |
| 6950 | } |
| 6951 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6952 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6953 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6954 | error = megasas_register_aen(instance, aen.seq_num, |
| 6955 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6956 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6957 | return error; |
| 6958 | } |
| 6959 | |
| 6960 | /** |
| 6961 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 6962 | */ |
| 6963 | static long |
| 6964 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 6965 | { |
| 6966 | switch (cmd) { |
| 6967 | case MEGASAS_IOC_FIRMWARE: |
| 6968 | return megasas_mgmt_ioctl_fw(file, arg); |
| 6969 | |
| 6970 | case MEGASAS_IOC_GET_AEN: |
| 6971 | return megasas_mgmt_ioctl_aen(file, arg); |
| 6972 | } |
| 6973 | |
| 6974 | return -ENOTTY; |
| 6975 | } |
| 6976 | |
| 6977 | #ifdef CONFIG_COMPAT |
| 6978 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 6979 | { |
| 6980 | struct compat_megasas_iocpacket __user *cioc = |
| 6981 | (struct compat_megasas_iocpacket __user *)arg; |
| 6982 | struct megasas_iocpacket __user *ioc = |
| 6983 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 6984 | int i; |
| 6985 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6986 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 6987 | u32 local_sense_off; |
| 6988 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 6989 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6990 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6991 | if (clear_user(ioc, sizeof(*ioc))) |
| 6992 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6993 | |
| 6994 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 6995 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 6996 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 6997 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 6998 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 6999 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 7000 | return -EFAULT; |
| 7001 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7002 | /* |
| 7003 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 7004 | * sense_len is not null, so prepare the 64bit value under |
| 7005 | * the same condition. |
| 7006 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7007 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 7008 | get_user(local_sense_len, &ioc->sense_len) || |
| 7009 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7010 | return -EFAULT; |
| 7011 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7012 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7013 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7014 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7015 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7016 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7017 | if (get_user(ptr, sense_cioc_ptr) || |
| 7018 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 7019 | return -EFAULT; |
| 7020 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7021 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7022 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7023 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 7024 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 7025 | copy_in_user(&ioc->sgl[i].iov_len, |
| 7026 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 7027 | return -EFAULT; |
| 7028 | } |
| 7029 | |
| 7030 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 7031 | |
| 7032 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 7033 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 7034 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 7035 | return -EFAULT; |
| 7036 | } |
| 7037 | return error; |
| 7038 | } |
| 7039 | |
| 7040 | static long |
| 7041 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 7042 | unsigned long arg) |
| 7043 | { |
| 7044 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 7045 | case MEGASAS_IOC_FIRMWARE32: |
| 7046 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7047 | case MEGASAS_IOC_GET_AEN: |
| 7048 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7049 | } |
| 7050 | |
| 7051 | return -ENOTTY; |
| 7052 | } |
| 7053 | #endif |
| 7054 | |
| 7055 | /* |
| 7056 | * File operations structure for management interface |
| 7057 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 7058 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7059 | .owner = THIS_MODULE, |
| 7060 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7061 | .fasync = megasas_mgmt_fasync, |
| 7062 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7063 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7064 | #ifdef CONFIG_COMPAT |
| 7065 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 7066 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 7067 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7068 | }; |
| 7069 | |
| 7070 | /* |
| 7071 | * PCI hotplug support registration structure |
| 7072 | */ |
| 7073 | static struct pci_driver megasas_pci_driver = { |
| 7074 | |
| 7075 | .name = "megaraid_sas", |
| 7076 | .id_table = megasas_pci_table, |
| 7077 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7078 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7079 | .suspend = megasas_suspend, |
| 7080 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7081 | .shutdown = megasas_shutdown, |
| 7082 | }; |
| 7083 | |
| 7084 | /* |
| 7085 | * Sysfs driver attributes |
| 7086 | */ |
| 7087 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) |
| 7088 | { |
| 7089 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 7090 | MEGASAS_VERSION); |
| 7091 | } |
| 7092 | |
| 7093 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); |
| 7094 | |
| 7095 | static ssize_t |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7096 | megasas_sysfs_show_release_date(struct device_driver *dd, char *buf) |
| 7097 | { |
| 7098 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 7099 | MEGASAS_RELDATE); |
| 7100 | } |
| 7101 | |
| 7102 | static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, NULL); |
| 7103 | |
| 7104 | static ssize_t |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7105 | megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) |
| 7106 | { |
| 7107 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 7108 | } |
| 7109 | |
| 7110 | static DRIVER_ATTR(support_poll_for_event, S_IRUGO, |
| 7111 | megasas_sysfs_show_support_poll_for_event, NULL); |
| 7112 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7113 | static ssize_t |
| 7114 | megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf) |
| 7115 | { |
| 7116 | return sprintf(buf, "%u\n", support_device_change); |
| 7117 | } |
| 7118 | |
| 7119 | static DRIVER_ATTR(support_device_change, S_IRUGO, |
| 7120 | megasas_sysfs_show_support_device_change, NULL); |
| 7121 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7122 | static ssize_t |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7123 | megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) |
| 7124 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7125 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | static ssize_t |
| 7129 | megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count) |
| 7130 | { |
| 7131 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7132 | |
| 7133 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7134 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 7135 | retval = -EINVAL; |
| 7136 | } |
| 7137 | return retval; |
| 7138 | } |
| 7139 | |
Joe Malicki | 66dca9b | 2008-08-14 17:14:48 -0400 | [diff] [blame] | 7140 | 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] | 7141 | megasas_sysfs_set_dbg_lvl); |
| 7142 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7143 | static void |
| 7144 | megasas_aen_polling(struct work_struct *work) |
| 7145 | { |
| 7146 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7147 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7148 | struct megasas_instance *instance = ev->instance; |
| 7149 | union megasas_evt_class_locale class_locale; |
| 7150 | struct Scsi_Host *host; |
| 7151 | struct scsi_device *sdev1; |
| 7152 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7153 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7154 | int i, j, doscan = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7155 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7156 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7157 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7158 | |
| 7159 | if (!instance) { |
| 7160 | printk(KERN_ERR "invalid instance!\n"); |
| 7161 | kfree(ev); |
| 7162 | return; |
| 7163 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7164 | |
| 7165 | /* Adjust event workqueue thread wait time for VF mode */ |
| 7166 | if (instance->requestorId) |
| 7167 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 7168 | |
| 7169 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7170 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7171 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7172 | instance->ev = NULL; |
| 7173 | host = instance->host; |
| 7174 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 7175 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7176 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7177 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7178 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7179 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7180 | case MR_EVT_PD_REMOVED: |
| 7181 | dcmd_ret = megasas_get_pd_list(instance); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7182 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7183 | doscan = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7184 | break; |
| 7185 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7186 | case MR_EVT_LD_OFFLINE: |
| 7187 | case MR_EVT_CFG_CLEARED: |
| 7188 | case MR_EVT_LD_DELETED: |
| 7189 | case MR_EVT_LD_CREATED: |
| 7190 | if (!instance->requestorId || |
| 7191 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7192 | 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] | 7193 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7194 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7195 | doscan = SCAN_VD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7196 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7197 | break; |
| 7198 | |
| 7199 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 7200 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 7201 | case MR_EVT_LD_STATE_CHANGE: |
| 7202 | dcmd_ret = megasas_get_pd_list(instance); |
| 7203 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7204 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7205 | break; |
| 7206 | |
| 7207 | if (!instance->requestorId || |
| 7208 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7209 | dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 7210 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7211 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7212 | break; |
| 7213 | |
| 7214 | doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL; |
| 7215 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 7216 | instance->host->host_no); |
| 7217 | break; |
| 7218 | |
| 7219 | case MR_EVT_CTRL_PROP_CHANGED: |
| 7220 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 7221 | break; |
| 7222 | default: |
| 7223 | doscan = 0; |
| 7224 | break; |
| 7225 | } |
| 7226 | } else { |
| 7227 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 7228 | mutex_unlock(&instance->reset_mutex); |
| 7229 | kfree(ev); |
| 7230 | return; |
| 7231 | } |
| 7232 | |
| 7233 | mutex_unlock(&instance->reset_mutex); |
| 7234 | |
| 7235 | if (doscan & SCAN_PD_CHANNEL) { |
| 7236 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 7237 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7238 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7239 | sdev1 = scsi_device_lookup(host, i, j, 0); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7240 | if (instance->pd_list[pd_index].driveState == |
| 7241 | MR_PD_STATE_SYSTEM) { |
| 7242 | if (!sdev1) |
| 7243 | scsi_add_device(host, i, j, 0); |
| 7244 | else |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7245 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7246 | } else { |
| 7247 | if (sdev1) { |
| 7248 | scsi_remove_device(sdev1); |
| 7249 | scsi_device_put(sdev1); |
| 7250 | } |
| 7251 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7252 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7253 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7254 | } |
| 7255 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7256 | if (doscan & SCAN_VD_CHANNEL) { |
| 7257 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 7258 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7259 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 7260 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7261 | if (instance->ld_ids[ld_index] != 0xff) { |
| 7262 | if (!sdev1) |
| 7263 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7264 | else |
| 7265 | scsi_device_put(sdev1); |
| 7266 | } else { |
| 7267 | if (sdev1) { |
| 7268 | scsi_remove_device(sdev1); |
| 7269 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7270 | } |
| 7271 | } |
| 7272 | } |
| 7273 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7274 | } |
| 7275 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7276 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7277 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 7278 | else |
| 7279 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7280 | |
| 7281 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 7282 | class_locale.members.reserved = 0; |
| 7283 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 7284 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7285 | |
| 7286 | if (instance->aen_cmd != NULL) { |
| 7287 | kfree(ev); |
| 7288 | return; |
| 7289 | } |
| 7290 | |
| 7291 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7292 | error = megasas_register_aen(instance, seq_num, |
| 7293 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7294 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7295 | dev_err(&instance->pdev->dev, |
| 7296 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7297 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7298 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7299 | kfree(ev); |
| 7300 | } |
| 7301 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7302 | /** |
| 7303 | * megasas_init - Driver load entry point |
| 7304 | */ |
| 7305 | static int __init megasas_init(void) |
| 7306 | { |
| 7307 | int rval; |
| 7308 | |
| 7309 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 7310 | * Booted in kdump kernel, minimize memory footprints by |
| 7311 | * disabling few features |
| 7312 | */ |
| 7313 | if (reset_devices) { |
| 7314 | msix_vectors = 1; |
| 7315 | rdpq_enable = 0; |
| 7316 | dual_qdepth_disable = 1; |
| 7317 | } |
| 7318 | |
| 7319 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7320 | * Announce driver version and other information |
| 7321 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 7322 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7323 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 7324 | spin_lock_init(&poll_aen_lock); |
| 7325 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7326 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7327 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7328 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7329 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 7330 | |
| 7331 | /* |
| 7332 | * Register character device node |
| 7333 | */ |
| 7334 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 7335 | |
| 7336 | if (rval < 0) { |
| 7337 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 7338 | return rval; |
| 7339 | } |
| 7340 | |
| 7341 | megasas_mgmt_majorno = rval; |
| 7342 | |
| 7343 | /* |
| 7344 | * Register ourselves as PCI hotplug module |
| 7345 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 7346 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7347 | |
| 7348 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 7349 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7350 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7351 | } |
| 7352 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7353 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7354 | &driver_attr_version); |
| 7355 | if (rval) |
| 7356 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7357 | |
| 7358 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7359 | &driver_attr_release_date); |
| 7360 | if (rval) |
| 7361 | goto err_dcf_rel_date; |
| 7362 | |
| 7363 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7364 | &driver_attr_support_poll_for_event); |
| 7365 | if (rval) |
| 7366 | goto err_dcf_support_poll_for_event; |
| 7367 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7368 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7369 | &driver_attr_dbg_lvl); |
| 7370 | if (rval) |
| 7371 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7372 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7373 | &driver_attr_support_device_change); |
| 7374 | if (rval) |
| 7375 | goto err_dcf_support_device_change; |
| 7376 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7377 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7378 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7379 | err_dcf_support_device_change: |
| 7380 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7381 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7382 | err_dcf_dbg_lvl: |
| 7383 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7384 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7385 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7386 | driver_remove_file(&megasas_pci_driver.driver, |
| 7387 | &driver_attr_release_date); |
| 7388 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7389 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 7390 | err_dcf_attr_ver: |
| 7391 | pci_unregister_driver(&megasas_pci_driver); |
| 7392 | err_pcidrv: |
| 7393 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 7394 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7395 | } |
| 7396 | |
| 7397 | /** |
| 7398 | * megasas_exit - Driver unload entry point |
| 7399 | */ |
| 7400 | static void __exit megasas_exit(void) |
| 7401 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7402 | driver_remove_file(&megasas_pci_driver.driver, |
| 7403 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7404 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7405 | &driver_attr_support_poll_for_event); |
| 7406 | driver_remove_file(&megasas_pci_driver.driver, |
| 7407 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7408 | driver_remove_file(&megasas_pci_driver.driver, |
| 7409 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7410 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7411 | |
| 7412 | pci_unregister_driver(&megasas_pci_driver); |
| 7413 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 7414 | } |
| 7415 | |
| 7416 | module_init(megasas_init); |
| 7417 | module_exit(megasas_exit); |