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> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 45 | #include <asm/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 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 86 | int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 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 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 95 | MODULE_LICENSE("GPL"); |
| 96 | MODULE_VERSION(MEGASAS_VERSION); |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 97 | MODULE_AUTHOR("megaraidlinux.pdl@avagotech.com"); |
| 98 | MODULE_DESCRIPTION("Avago MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 99 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 100 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 101 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 102 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 103 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 104 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 105 | static int megasas_register_aen(struct megasas_instance *instance, |
| 106 | u32 seq_num, u32 class_locale_word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 107 | /* |
| 108 | * PCI ID table for all supported controllers |
| 109 | */ |
| 110 | static struct pci_device_id megasas_pci_table[] = { |
| 111 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 112 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 113 | /* xscale IOP */ |
| 114 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 115 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 116 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 117 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 118 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 119 | /* gen2*/ |
| 120 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 121 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 122 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 123 | /* skinny*/ |
| 124 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 125 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 126 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 127 | /* xscale IOP, vega */ |
| 128 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 129 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 130 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 131 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 132 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 133 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 134 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 135 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 136 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 137 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 138 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 139 | /* Intruder */ |
| 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 141 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 142 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 143 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_53)}, |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 144 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 148 | |
| 149 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 150 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 151 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 152 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 153 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 154 | static int megasas_poll_wait_aen; |
| 155 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 156 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 157 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 158 | static u32 support_device_change; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 159 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 160 | /* define lock for aen poll */ |
| 161 | spinlock_t poll_aen_lock; |
| 162 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 163 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 164 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 165 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 166 | static u32 |
| 167 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs); |
| 168 | static int |
| 169 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 170 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 171 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 172 | static u32 |
| 173 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 174 | u32 |
| 175 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 176 | struct scsi_cmnd *scmd); |
| 177 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 178 | void |
| 179 | megasas_release_fusion(struct megasas_instance *instance); |
| 180 | int |
| 181 | megasas_ioc_init_fusion(struct megasas_instance *instance); |
| 182 | void |
| 183 | megasas_free_cmds_fusion(struct megasas_instance *instance); |
| 184 | u8 |
| 185 | megasas_get_map_info(struct megasas_instance *instance); |
| 186 | int |
| 187 | megasas_sync_map_info(struct megasas_instance *instance); |
| 188 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 189 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 190 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 191 | void megasas_reset_reply_desc(struct megasas_instance *instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 192 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 193 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 194 | int initial); |
| 195 | int megasas_check_mpio_paths(struct megasas_instance *instance, |
| 196 | struct scsi_cmnd *scmd); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 197 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 198 | int |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 199 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 200 | { |
| 201 | instance->instancet->fire_cmd(instance, |
| 202 | cmd->frame_phys_addr, 0, instance->reg_set); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 203 | return 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 204 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 205 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 206 | /** |
| 207 | * megasas_get_cmd - Get a command from the free pool |
| 208 | * @instance: Adapter soft state |
| 209 | * |
| 210 | * Returns a free command from the pool |
| 211 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 212 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 213 | *instance) |
| 214 | { |
| 215 | unsigned long flags; |
| 216 | struct megasas_cmd *cmd = NULL; |
| 217 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 218 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 219 | |
| 220 | if (!list_empty(&instance->cmd_pool)) { |
| 221 | cmd = list_entry((&instance->cmd_pool)->next, |
| 222 | struct megasas_cmd, list); |
| 223 | list_del_init(&cmd->list); |
| 224 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 225 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 228 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 229 | return cmd; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * megasas_return_cmd - Return a cmd to free command pool |
| 234 | * @instance: Adapter soft state |
| 235 | * @cmd: Command packet to be returned to free command pool |
| 236 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 237 | inline void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 238 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 239 | { |
| 240 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 241 | u32 blk_tags; |
| 242 | struct megasas_cmd_fusion *cmd_fusion; |
| 243 | struct fusion_context *fusion = instance->ctrl_context; |
| 244 | |
| 245 | /* This flag is used only for fusion adapter. |
| 246 | * Wait for Interrupt for Polled mode DCMD |
| 247 | */ |
| 248 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 249 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 250 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 251 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 252 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 253 | if (fusion) { |
| 254 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 255 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 256 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 257 | } |
| 258 | cmd->scmd = NULL; |
| 259 | cmd->frame_count = 0; |
| 260 | cmd->flags = 0; |
| 261 | if (!fusion && reset_devices) |
| 262 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 263 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 264 | |
| 265 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 266 | |
| 267 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 268 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 269 | static const char * |
| 270 | format_timestamp(uint32_t timestamp) |
| 271 | { |
| 272 | static char buffer[32]; |
| 273 | |
| 274 | if ((timestamp & 0xff000000) == 0xff000000) |
| 275 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 276 | 0x00ffffff); |
| 277 | else |
| 278 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 279 | return buffer; |
| 280 | } |
| 281 | |
| 282 | static const char * |
| 283 | format_class(int8_t class) |
| 284 | { |
| 285 | static char buffer[6]; |
| 286 | |
| 287 | switch (class) { |
| 288 | case MFI_EVT_CLASS_DEBUG: |
| 289 | return "debug"; |
| 290 | case MFI_EVT_CLASS_PROGRESS: |
| 291 | return "progress"; |
| 292 | case MFI_EVT_CLASS_INFO: |
| 293 | return "info"; |
| 294 | case MFI_EVT_CLASS_WARNING: |
| 295 | return "WARN"; |
| 296 | case MFI_EVT_CLASS_CRITICAL: |
| 297 | return "CRIT"; |
| 298 | case MFI_EVT_CLASS_FATAL: |
| 299 | return "FATAL"; |
| 300 | case MFI_EVT_CLASS_DEAD: |
| 301 | return "DEAD"; |
| 302 | default: |
| 303 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 304 | return buffer; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 310 | * for information. |
| 311 | * @instance: Adapter soft state |
| 312 | */ |
| 313 | static void |
| 314 | megasas_decode_evt(struct megasas_instance *instance) |
| 315 | { |
| 316 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 317 | union megasas_evt_class_locale class_locale; |
| 318 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 319 | |
| 320 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 321 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 322 | le32_to_cpu(evt_detail->seq_num), |
| 323 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 324 | (class_locale.members.locale), |
| 325 | format_class(class_locale.members.class), |
| 326 | evt_detail->description); |
| 327 | } |
| 328 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 329 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 330 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 331 | * (deviceid : 1064R, PERC5) controllers |
| 332 | */ |
| 333 | |
| 334 | /** |
| 335 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 336 | * @regs: MFI register set |
| 337 | */ |
| 338 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 339 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 340 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 341 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 342 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 343 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 344 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 345 | |
| 346 | /* Dummy readl to force pci flush */ |
| 347 | readl(®s->outbound_intr_mask); |
| 348 | } |
| 349 | |
| 350 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 351 | * megasas_disable_intr_xscale -Disables interrupt |
| 352 | * @regs: MFI register set |
| 353 | */ |
| 354 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 355 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 356 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 357 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 358 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 359 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 360 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 361 | writel(mask, ®s->outbound_intr_mask); |
| 362 | /* Dummy readl to force pci flush */ |
| 363 | readl(®s->outbound_intr_mask); |
| 364 | } |
| 365 | |
| 366 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 367 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 368 | * @regs: MFI register set |
| 369 | */ |
| 370 | static u32 |
| 371 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 372 | { |
| 373 | return readl(&(regs)->outbound_msg_0); |
| 374 | } |
| 375 | /** |
| 376 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 377 | * @regs: MFI register set |
| 378 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 379 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 380 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 381 | { |
| 382 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 383 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 384 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 385 | /* |
| 386 | * Check if it is our interrupt |
| 387 | */ |
| 388 | status = readl(®s->outbound_intr_status); |
| 389 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 390 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 391 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 392 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 393 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 394 | |
| 395 | /* |
| 396 | * Clear the interrupt by writing back the same value |
| 397 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 398 | if (mfiStatus) |
| 399 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 400 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 401 | /* Dummy readl to force pci flush */ |
| 402 | readl(®s->outbound_intr_status); |
| 403 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 404 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /** |
| 408 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 409 | * @frame_phys_addr : Physical address of cmd |
| 410 | * @frame_count : Number of frames for the command |
| 411 | * @regs : MFI register set |
| 412 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 413 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 414 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 415 | dma_addr_t frame_phys_addr, |
| 416 | u32 frame_count, |
| 417 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 418 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 419 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 420 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 421 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 422 | writel((frame_phys_addr >> 3)|(frame_count), |
| 423 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 424 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * megasas_adp_reset_xscale - For controller reset |
| 429 | * @regs: MFI register set |
| 430 | */ |
| 431 | static int |
| 432 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 433 | struct megasas_register_set __iomem *regs) |
| 434 | { |
| 435 | u32 i; |
| 436 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 437 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 438 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 439 | |
| 440 | for (i = 0; i < 3; i++) |
| 441 | msleep(1000); /* sleep for 3 secs */ |
| 442 | pcidata = 0; |
| 443 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 444 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 445 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 446 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 447 | pcidata &= ~0x2; |
| 448 | pci_write_config_dword(instance->pdev, |
| 449 | MFI_1068_PCSR_OFFSET, pcidata); |
| 450 | |
| 451 | for (i = 0; i < 2; i++) |
| 452 | msleep(1000); /* need to wait 2 secs again */ |
| 453 | |
| 454 | pcidata = 0; |
| 455 | pci_read_config_dword(instance->pdev, |
| 456 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 457 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 458 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 459 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 460 | pcidata = 0; |
| 461 | pci_write_config_dword(instance->pdev, |
| 462 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 463 | } |
| 464 | } |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * megasas_check_reset_xscale - For controller reset check |
| 470 | * @regs: MFI register set |
| 471 | */ |
| 472 | static int |
| 473 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 474 | struct megasas_register_set __iomem *regs) |
| 475 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 476 | if ((instance->adprecovery != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 477 | (le32_to_cpu(*instance->consumer) == |
| 478 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 479 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 480 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 484 | |
| 485 | .fire_cmd = megasas_fire_cmd_xscale, |
| 486 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 487 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 488 | .clear_intr = megasas_clear_intr_xscale, |
| 489 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 490 | .adp_reset = megasas_adp_reset_xscale, |
| 491 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 492 | .service_isr = megasas_isr, |
| 493 | .tasklet = megasas_complete_cmd_dpc, |
| 494 | .init_adapter = megasas_init_adapter_mfi, |
| 495 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 496 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 500 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 501 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 502 | */ |
| 503 | |
| 504 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 505 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 506 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 507 | */ |
| 508 | |
| 509 | /** |
| 510 | * megasas_enable_intr_ppc - Enables interrupts |
| 511 | * @regs: MFI register set |
| 512 | */ |
| 513 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 514 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 515 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 516 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 517 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 518 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 519 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 520 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 521 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 522 | |
| 523 | /* Dummy readl to force pci flush */ |
| 524 | readl(®s->outbound_intr_mask); |
| 525 | } |
| 526 | |
| 527 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 528 | * megasas_disable_intr_ppc - Disable interrupt |
| 529 | * @regs: MFI register set |
| 530 | */ |
| 531 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 532 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 533 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 534 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 535 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 536 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 537 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 538 | writel(mask, ®s->outbound_intr_mask); |
| 539 | /* Dummy readl to force pci flush */ |
| 540 | readl(®s->outbound_intr_mask); |
| 541 | } |
| 542 | |
| 543 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 544 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 545 | * @regs: MFI register set |
| 546 | */ |
| 547 | static u32 |
| 548 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 549 | { |
| 550 | return readl(&(regs)->outbound_scratch_pad); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 555 | * @regs: MFI register set |
| 556 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 557 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 558 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 559 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 560 | u32 status, mfiStatus = 0; |
| 561 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 562 | /* |
| 563 | * Check if it is our interrupt |
| 564 | */ |
| 565 | status = readl(®s->outbound_intr_status); |
| 566 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 567 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 568 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 569 | |
| 570 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 571 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 572 | |
| 573 | /* |
| 574 | * Clear the interrupt by writing back the same value |
| 575 | */ |
| 576 | writel(status, ®s->outbound_doorbell_clear); |
| 577 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 578 | /* Dummy readl to force pci flush */ |
| 579 | readl(®s->outbound_doorbell_clear); |
| 580 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 581 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 582 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 583 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 584 | /** |
| 585 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 586 | * @frame_phys_addr : Physical address of cmd |
| 587 | * @frame_count : Number of frames for the command |
| 588 | * @regs : MFI register set |
| 589 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 590 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 591 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 592 | dma_addr_t frame_phys_addr, |
| 593 | u32 frame_count, |
| 594 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 595 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 596 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 597 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 598 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 599 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 600 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 601 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 602 | } |
| 603 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 604 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 605 | * megasas_check_reset_ppc - For controller reset check |
| 606 | * @regs: MFI register set |
| 607 | */ |
| 608 | static int |
| 609 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 610 | struct megasas_register_set __iomem *regs) |
| 611 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 612 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) |
| 613 | return 1; |
| 614 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 615 | return 0; |
| 616 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 617 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 618 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 619 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 620 | .fire_cmd = megasas_fire_cmd_ppc, |
| 621 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 622 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 623 | .clear_intr = megasas_clear_intr_ppc, |
| 624 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 625 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 626 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 627 | .service_isr = megasas_isr, |
| 628 | .tasklet = megasas_complete_cmd_dpc, |
| 629 | .init_adapter = megasas_init_adapter_mfi, |
| 630 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 631 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 635 | * megasas_enable_intr_skinny - Enables interrupts |
| 636 | * @regs: MFI register set |
| 637 | */ |
| 638 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 639 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 640 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 641 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 642 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 643 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 644 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 645 | |
| 646 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 647 | |
| 648 | /* Dummy readl to force pci flush */ |
| 649 | readl(®s->outbound_intr_mask); |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * megasas_disable_intr_skinny - Disables interrupt |
| 654 | * @regs: MFI register set |
| 655 | */ |
| 656 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 657 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 658 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 659 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 660 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 661 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 662 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 663 | writel(mask, ®s->outbound_intr_mask); |
| 664 | /* Dummy readl to force pci flush */ |
| 665 | readl(®s->outbound_intr_mask); |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 670 | * @regs: MFI register set |
| 671 | */ |
| 672 | static u32 |
| 673 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 674 | { |
| 675 | return readl(&(regs)->outbound_scratch_pad); |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 680 | * @regs: MFI register set |
| 681 | */ |
| 682 | static int |
| 683 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 684 | { |
| 685 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 686 | u32 mfiStatus = 0; |
| 687 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 688 | /* |
| 689 | * Check if it is our interrupt |
| 690 | */ |
| 691 | status = readl(®s->outbound_intr_status); |
| 692 | |
| 693 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 694 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 698 | * Check if it is our interrupt |
| 699 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 700 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 701 | MFI_STATE_FAULT) { |
| 702 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 703 | } else |
| 704 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 705 | |
| 706 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 707 | * Clear the interrupt by writing back the same value |
| 708 | */ |
| 709 | writel(status, ®s->outbound_intr_status); |
| 710 | |
| 711 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 712 | * dummy read to flush PCI |
| 713 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 714 | readl(®s->outbound_intr_status); |
| 715 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 716 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
| 720 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 721 | * @frame_phys_addr : Physical address of cmd |
| 722 | * @frame_count : Number of frames for the command |
| 723 | * @regs : MFI register set |
| 724 | */ |
| 725 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 726 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 727 | dma_addr_t frame_phys_addr, |
| 728 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 729 | struct megasas_register_set __iomem *regs) |
| 730 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 731 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 732 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 733 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 734 | writel(upper_32_bits(frame_phys_addr), |
| 735 | &(regs)->inbound_high_queue_port); |
| 736 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 737 | &(regs)->inbound_low_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 738 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 739 | } |
| 740 | |
| 741 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 742 | * megasas_check_reset_skinny - For controller reset check |
| 743 | * @regs: MFI register set |
| 744 | */ |
| 745 | static int |
| 746 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 747 | struct megasas_register_set __iomem *regs) |
| 748 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 749 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) |
| 750 | return 1; |
| 751 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 752 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 756 | |
| 757 | .fire_cmd = megasas_fire_cmd_skinny, |
| 758 | .enable_intr = megasas_enable_intr_skinny, |
| 759 | .disable_intr = megasas_disable_intr_skinny, |
| 760 | .clear_intr = megasas_clear_intr_skinny, |
| 761 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 762 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 763 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 764 | .service_isr = megasas_isr, |
| 765 | .tasklet = megasas_complete_cmd_dpc, |
| 766 | .init_adapter = megasas_init_adapter_mfi, |
| 767 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 768 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 769 | }; |
| 770 | |
| 771 | |
| 772 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 773 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 774 | * controllers |
| 775 | */ |
| 776 | |
| 777 | /** |
| 778 | * megasas_enable_intr_gen2 - Enables interrupts |
| 779 | * @regs: MFI register set |
| 780 | */ |
| 781 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 782 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 783 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 784 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 785 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 786 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 787 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 788 | |
| 789 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 790 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 791 | |
| 792 | /* Dummy readl to force pci flush */ |
| 793 | readl(®s->outbound_intr_mask); |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * megasas_disable_intr_gen2 - Disables interrupt |
| 798 | * @regs: MFI register set |
| 799 | */ |
| 800 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 801 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 802 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 803 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 804 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 805 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 806 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 807 | writel(mask, ®s->outbound_intr_mask); |
| 808 | /* Dummy readl to force pci flush */ |
| 809 | readl(®s->outbound_intr_mask); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 814 | * @regs: MFI register set |
| 815 | */ |
| 816 | static u32 |
| 817 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 818 | { |
| 819 | return readl(&(regs)->outbound_scratch_pad); |
| 820 | } |
| 821 | |
| 822 | /** |
| 823 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 824 | * @regs: MFI register set |
| 825 | */ |
| 826 | static int |
| 827 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 828 | { |
| 829 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 830 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 831 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 832 | /* |
| 833 | * Check if it is our interrupt |
| 834 | */ |
| 835 | status = readl(®s->outbound_intr_status); |
| 836 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 837 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 838 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 839 | } |
| 840 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 841 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 842 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * Clear the interrupt by writing back the same value |
| 846 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 847 | if (mfiStatus) |
| 848 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 849 | |
| 850 | /* Dummy readl to force pci flush */ |
| 851 | readl(®s->outbound_intr_status); |
| 852 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 853 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 854 | } |
| 855 | /** |
| 856 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 857 | * @frame_phys_addr : Physical address of cmd |
| 858 | * @frame_count : Number of frames for the command |
| 859 | * @regs : MFI register set |
| 860 | */ |
| 861 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 862 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 863 | dma_addr_t frame_phys_addr, |
| 864 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 865 | struct megasas_register_set __iomem *regs) |
| 866 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 867 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 868 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 869 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 870 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 871 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 872 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * megasas_adp_reset_gen2 - For controller reset |
| 877 | * @regs: MFI register set |
| 878 | */ |
| 879 | static int |
| 880 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 881 | struct megasas_register_set __iomem *reg_set) |
| 882 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 883 | u32 retry = 0 ; |
| 884 | u32 HostDiag; |
| 885 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 886 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 887 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 888 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 889 | seq_offset = ®_set->fusion_seq_offset; |
| 890 | hostdiag_offset = ®_set->fusion_host_diag; |
| 891 | } |
| 892 | |
| 893 | writel(0, seq_offset); |
| 894 | writel(4, seq_offset); |
| 895 | writel(0xb, seq_offset); |
| 896 | writel(2, seq_offset); |
| 897 | writel(7, seq_offset); |
| 898 | writel(0xd, seq_offset); |
| 899 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 900 | msleep(1000); |
| 901 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 902 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 903 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 904 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 905 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 906 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 907 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 908 | retry, HostDiag); |
| 909 | |
| 910 | if (retry++ >= 100) |
| 911 | return 1; |
| 912 | |
| 913 | } |
| 914 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 915 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 916 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 917 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 918 | |
| 919 | ssleep(10); |
| 920 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 921 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 922 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 923 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 924 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 925 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 926 | retry, HostDiag); |
| 927 | |
| 928 | if (retry++ >= 1000) |
| 929 | return 1; |
| 930 | |
| 931 | } |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * megasas_check_reset_gen2 - For controller reset check |
| 937 | * @regs: MFI register set |
| 938 | */ |
| 939 | static int |
| 940 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 941 | struct megasas_register_set __iomem *regs) |
| 942 | { |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 943 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 944 | return 1; |
| 945 | } |
| 946 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 947 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 951 | |
| 952 | .fire_cmd = megasas_fire_cmd_gen2, |
| 953 | .enable_intr = megasas_enable_intr_gen2, |
| 954 | .disable_intr = megasas_disable_intr_gen2, |
| 955 | .clear_intr = megasas_clear_intr_gen2, |
| 956 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 957 | .adp_reset = megasas_adp_reset_gen2, |
| 958 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 959 | .service_isr = megasas_isr, |
| 960 | .tasklet = megasas_complete_cmd_dpc, |
| 961 | .init_adapter = megasas_init_adapter_mfi, |
| 962 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 963 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 964 | }; |
| 965 | |
| 966 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 967 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 968 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 969 | */ |
| 970 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 971 | /* |
| 972 | * Template added for TB (Fusion) |
| 973 | */ |
| 974 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 975 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 976 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 977 | * megasas_issue_polled - Issues a polling command |
| 978 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 979 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 980 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 981 | * 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] | 982 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 983 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 984 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 985 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 986 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 987 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 988 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 989 | 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] | 990 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 991 | if ((instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) || |
| 992 | (instance->instancet->issue_dcmd(instance, cmd))) { |
| 993 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 994 | __func__, __LINE__); |
| 995 | return DCMD_NOT_FIRED; |
| 996 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 997 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 998 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 999 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | /** |
| 1003 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1004 | * @instance: Adapter soft state |
| 1005 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1006 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1007 | * |
| 1008 | * 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] | 1009 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1010 | * Used to issue ioctl commands. |
| 1011 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1012 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1013 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1014 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1015 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1016 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1017 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1018 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1019 | if ((instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) || |
| 1020 | (instance->instancet->issue_dcmd(instance, cmd))) { |
| 1021 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1022 | __func__, __LINE__); |
| 1023 | return DCMD_NOT_FIRED; |
| 1024 | } |
| 1025 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1026 | if (timeout) { |
| 1027 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1028 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1029 | if (!ret) { |
| 1030 | dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n", |
| 1031 | __func__, __LINE__); |
| 1032 | return DCMD_TIMEOUT; |
| 1033 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1034 | } else |
| 1035 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1036 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1037 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1038 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1039 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1044 | * @instance: Adapter soft state |
| 1045 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1046 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1047 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1048 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1049 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1050 | * cmd and waits for return status. |
| 1051 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1052 | */ |
| 1053 | static int |
| 1054 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1055 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1056 | { |
| 1057 | struct megasas_cmd *cmd; |
| 1058 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1059 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1060 | |
| 1061 | cmd = megasas_get_cmd(instance); |
| 1062 | |
| 1063 | if (!cmd) |
| 1064 | return -1; |
| 1065 | |
| 1066 | abort_fr = &cmd->frame->abort; |
| 1067 | |
| 1068 | /* |
| 1069 | * Prepare and issue the abort frame |
| 1070 | */ |
| 1071 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1072 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1073 | abort_fr->flags = cpu_to_le16(0); |
| 1074 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1075 | abort_fr->abort_mfi_phys_addr_lo = |
| 1076 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1077 | abort_fr->abort_mfi_phys_addr_hi = |
| 1078 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1079 | |
| 1080 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1081 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1082 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1083 | if ((instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) || |
| 1084 | (instance->instancet->issue_dcmd(instance, cmd))) { |
| 1085 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1086 | __func__, __LINE__); |
| 1087 | return DCMD_NOT_FIRED; |
| 1088 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1089 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1090 | if (timeout) { |
| 1091 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1092 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1093 | if (!ret) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1094 | dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n", |
| 1095 | __func__, __LINE__); |
| 1096 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1097 | } |
| 1098 | } else |
| 1099 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1100 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1101 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1102 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1103 | |
| 1104 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1105 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1106 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1111 | * @instance: Adapter soft state |
| 1112 | * @scp: SCSI command from the mid-layer |
| 1113 | * @mfi_sgl: SGL to be filled in |
| 1114 | * |
| 1115 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1116 | * it returnes -1. |
| 1117 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1118 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1119 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1120 | union megasas_sgl *mfi_sgl) |
| 1121 | { |
| 1122 | int i; |
| 1123 | int sge_count; |
| 1124 | struct scatterlist *os_sgl; |
| 1125 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1126 | sge_count = scsi_dma_map(scp); |
| 1127 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1128 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1129 | if (sge_count) { |
| 1130 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1131 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1132 | 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] | 1133 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1134 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1135 | return sge_count; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1140 | * @instance: Adapter soft state |
| 1141 | * @scp: SCSI command from the mid-layer |
| 1142 | * @mfi_sgl: SGL to be filled in |
| 1143 | * |
| 1144 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1145 | * it returnes -1. |
| 1146 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1147 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1148 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1149 | union megasas_sgl *mfi_sgl) |
| 1150 | { |
| 1151 | int i; |
| 1152 | int sge_count; |
| 1153 | struct scatterlist *os_sgl; |
| 1154 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1155 | sge_count = scsi_dma_map(scp); |
| 1156 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1157 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1158 | if (sge_count) { |
| 1159 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1160 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1161 | 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] | 1162 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1163 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1164 | return sge_count; |
| 1165 | } |
| 1166 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1167 | /** |
| 1168 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1169 | * @instance: Adapter soft state |
| 1170 | * @scp: SCSI command from the mid-layer |
| 1171 | * @mfi_sgl: SGL to be filled in |
| 1172 | * |
| 1173 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1174 | * it returnes -1. |
| 1175 | */ |
| 1176 | static int |
| 1177 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1178 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1179 | { |
| 1180 | int i; |
| 1181 | int sge_count; |
| 1182 | struct scatterlist *os_sgl; |
| 1183 | |
| 1184 | sge_count = scsi_dma_map(scp); |
| 1185 | |
| 1186 | if (sge_count) { |
| 1187 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1188 | mfi_sgl->sge_skinny[i].length = |
| 1189 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1190 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1191 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1192 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | return sge_count; |
| 1196 | } |
| 1197 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1198 | /** |
| 1199 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1200 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1201 | * @sge_count : number of sg elements |
| 1202 | * |
| 1203 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1204 | */ |
| 1205 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1206 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1207 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1208 | { |
| 1209 | int num_cnt; |
| 1210 | int sge_bytes; |
| 1211 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1212 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1213 | |
| 1214 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1215 | sizeof(struct megasas_sge32); |
| 1216 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1217 | if (instance->flag_ieee) { |
| 1218 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1219 | } |
| 1220 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1221 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1222 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1223 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1224 | * 1 SGEs for 64-bit SGLs and |
| 1225 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1226 | */ |
| 1227 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1228 | if (instance->flag_ieee == 1) { |
| 1229 | num_cnt = sge_count - 1; |
| 1230 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1231 | num_cnt = sge_count - 1; |
| 1232 | else |
| 1233 | num_cnt = sge_count - 2; |
| 1234 | } else { |
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 - 2; |
| 1239 | else |
| 1240 | num_cnt = sge_count - 3; |
| 1241 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1242 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1243 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1244 | sge_bytes = sge_sz * num_cnt; |
| 1245 | |
| 1246 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1247 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1248 | } |
| 1249 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1250 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1251 | |
| 1252 | if (frame_count > 7) |
| 1253 | frame_count = 8; |
| 1254 | return frame_count; |
| 1255 | } |
| 1256 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1257 | /** |
| 1258 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1259 | * @instance: Adapter soft state |
| 1260 | * @scp: SCSI command |
| 1261 | * @cmd: Command to be prepared in |
| 1262 | * |
| 1263 | * This function prepares CDB commands. These are typcially pass-through |
| 1264 | * commands to the devices. |
| 1265 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1266 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1267 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1268 | struct megasas_cmd *cmd) |
| 1269 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1270 | u32 is_logical; |
| 1271 | u32 device_id; |
| 1272 | u16 flags = 0; |
| 1273 | struct megasas_pthru_frame *pthru; |
| 1274 | |
| 1275 | is_logical = MEGASAS_IS_LOGICAL(scp); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1276 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1277 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1278 | |
| 1279 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1280 | flags = MFI_FRAME_DIR_WRITE; |
| 1281 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1282 | flags = MFI_FRAME_DIR_READ; |
| 1283 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1284 | flags = MFI_FRAME_DIR_NONE; |
| 1285 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1286 | if (instance->flag_ieee == 1) { |
| 1287 | flags |= MFI_FRAME_IEEE; |
| 1288 | } |
| 1289 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1290 | /* |
| 1291 | * Prepare the DCDB frame |
| 1292 | */ |
| 1293 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1294 | pthru->cmd_status = 0x0; |
| 1295 | pthru->scsi_status = 0x0; |
| 1296 | pthru->target_id = device_id; |
| 1297 | pthru->lun = scp->device->lun; |
| 1298 | pthru->cdb_len = scp->cmd_len; |
| 1299 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1300 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1301 | pthru->flags = cpu_to_le16(flags); |
| 1302 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1303 | |
| 1304 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1305 | |
| 1306 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1307 | * If the command is for the tape device, set the |
| 1308 | * pthru timeout to the os layer timeout value. |
| 1309 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1310 | if (scp->device->type == TYPE_TAPE) { |
| 1311 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1312 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1313 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1314 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1318 | * Construct SGL |
| 1319 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1320 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1321 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1322 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1323 | &pthru->sgl); |
| 1324 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1325 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1326 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1327 | &pthru->sgl); |
| 1328 | } else |
| 1329 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1330 | &pthru->sgl); |
| 1331 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1332 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1333 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1334 | pthru->sge_count); |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1338 | /* |
| 1339 | * Sense info specific |
| 1340 | */ |
| 1341 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1342 | pthru->sense_buf_phys_addr_hi = |
| 1343 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1344 | pthru->sense_buf_phys_addr_lo = |
| 1345 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1346 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1347 | /* |
| 1348 | * Compute the total number of frames this command consumes. FW uses |
| 1349 | * this number to pull sufficient number of frames from host memory. |
| 1350 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1351 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1352 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1353 | |
| 1354 | return cmd->frame_count; |
| 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1359 | * @instance: Adapter soft state |
| 1360 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1361 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1362 | * |
| 1363 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1364 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1365 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1366 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1367 | struct megasas_cmd *cmd) |
| 1368 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1369 | u32 device_id; |
| 1370 | u8 sc = scp->cmnd[0]; |
| 1371 | u16 flags = 0; |
| 1372 | struct megasas_io_frame *ldio; |
| 1373 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1374 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1375 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1376 | |
| 1377 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1378 | flags = MFI_FRAME_DIR_WRITE; |
| 1379 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1380 | flags = MFI_FRAME_DIR_READ; |
| 1381 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1382 | if (instance->flag_ieee == 1) { |
| 1383 | flags |= MFI_FRAME_IEEE; |
| 1384 | } |
| 1385 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1386 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1387 | * 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] | 1388 | */ |
| 1389 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1390 | ldio->cmd_status = 0x0; |
| 1391 | ldio->scsi_status = 0x0; |
| 1392 | ldio->target_id = device_id; |
| 1393 | ldio->timeout = 0; |
| 1394 | ldio->reserved_0 = 0; |
| 1395 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1396 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1397 | ldio->start_lba_hi = 0; |
| 1398 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1399 | |
| 1400 | /* |
| 1401 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1402 | */ |
| 1403 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1404 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1405 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1406 | ((u32) scp->cmnd[2] << 8) | |
| 1407 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1408 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1409 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /* |
| 1413 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1414 | */ |
| 1415 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1416 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1417 | ((u32) scp->cmnd[7] << 8)); |
| 1418 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1419 | ((u32) scp->cmnd[3] << 16) | |
| 1420 | ((u32) scp->cmnd[4] << 8) | |
| 1421 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1426 | */ |
| 1427 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1428 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1429 | ((u32) scp->cmnd[7] << 16) | |
| 1430 | ((u32) scp->cmnd[8] << 8) | |
| 1431 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1432 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1433 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1434 | ((u32) scp->cmnd[3] << 16) | |
| 1435 | ((u32) scp->cmnd[4] << 8) | |
| 1436 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | /* |
| 1440 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1441 | */ |
| 1442 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1443 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1444 | ((u32) scp->cmnd[11] << 16) | |
| 1445 | ((u32) scp->cmnd[12] << 8) | |
| 1446 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1447 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1448 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1449 | ((u32) scp->cmnd[7] << 16) | |
| 1450 | ((u32) scp->cmnd[8] << 8) | |
| 1451 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1452 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1453 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1454 | ((u32) scp->cmnd[3] << 16) | |
| 1455 | ((u32) scp->cmnd[4] << 8) | |
| 1456 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1457 | |
| 1458 | } |
| 1459 | |
| 1460 | /* |
| 1461 | * Construct SGL |
| 1462 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1463 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1464 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1465 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1466 | &ldio->sgl); |
| 1467 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1468 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1469 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1470 | } else |
| 1471 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1472 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1473 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1474 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1475 | ldio->sge_count); |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1479 | /* |
| 1480 | * Sense info specific |
| 1481 | */ |
| 1482 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1483 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1484 | 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] | 1485 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1486 | /* |
| 1487 | * Compute the total number of frames this command consumes. FW uses |
| 1488 | * this number to pull sufficient number of frames from host memory. |
| 1489 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1490 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1491 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1492 | |
| 1493 | return cmd->frame_count; |
| 1494 | } |
| 1495 | |
| 1496 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1497 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1498 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1499 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1500 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1501 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1502 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1503 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1504 | int ret; |
| 1505 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1506 | switch (cmd->cmnd[0]) { |
| 1507 | case READ_10: |
| 1508 | case WRITE_10: |
| 1509 | case READ_12: |
| 1510 | case WRITE_12: |
| 1511 | case READ_6: |
| 1512 | case WRITE_6: |
| 1513 | case READ_16: |
| 1514 | case WRITE_16: |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1515 | ret = (MEGASAS_IS_LOGICAL(cmd)) ? |
| 1516 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1517 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1518 | default: |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1519 | ret = (MEGASAS_IS_LOGICAL(cmd)) ? |
| 1520 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1521 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1522 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1525 | /** |
| 1526 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1527 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1528 | * @instance: Adapter soft state |
| 1529 | */ |
| 1530 | static inline void |
| 1531 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1532 | { |
| 1533 | struct megasas_cmd *cmd; |
| 1534 | int i,n; |
| 1535 | union megasas_sgl *mfi_sgl; |
| 1536 | struct megasas_io_frame *ldio; |
| 1537 | struct megasas_pthru_frame *pthru; |
| 1538 | u32 sgcount; |
| 1539 | u32 max_cmd = instance->max_fw_cmds; |
| 1540 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1541 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1542 | 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] | 1543 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1544 | 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] | 1545 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1546 | 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] | 1547 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1548 | 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] | 1549 | for (i = 0; i < max_cmd; i++) { |
| 1550 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1551 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1552 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1553 | 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] | 1554 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1555 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1556 | mfi_sgl = &ldio->sgl; |
| 1557 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1558 | 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] | 1559 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1560 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1561 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1562 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1563 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1564 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1565 | mfi_sgl = &pthru->sgl; |
| 1566 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1567 | 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] | 1568 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1569 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1570 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1571 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1572 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1573 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1574 | for (n = 0; n < sgcount; n++) { |
| 1575 | if (IS_DMA64) |
| 1576 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1577 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1578 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1579 | else |
| 1580 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1581 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1582 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1583 | } |
| 1584 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1585 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1586 | 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] | 1587 | for (i = 0; i < max_cmd; i++) { |
| 1588 | |
| 1589 | cmd = instance->cmd_list[i]; |
| 1590 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1591 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1592 | 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] | 1593 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1594 | 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] | 1595 | } |
| 1596 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1597 | u32 |
| 1598 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1599 | struct scsi_cmnd *scmd) |
| 1600 | { |
| 1601 | struct megasas_cmd *cmd; |
| 1602 | u32 frame_count; |
| 1603 | |
| 1604 | cmd = megasas_get_cmd(instance); |
| 1605 | if (!cmd) |
| 1606 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1607 | |
| 1608 | /* |
| 1609 | * Logical drive command |
| 1610 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1611 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1612 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1613 | else |
| 1614 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1615 | |
| 1616 | if (!frame_count) |
| 1617 | goto out_return_cmd; |
| 1618 | |
| 1619 | cmd->scmd = scmd; |
| 1620 | scmd->SCp.ptr = (char *)cmd; |
| 1621 | |
| 1622 | /* |
| 1623 | * Issue the command to the FW |
| 1624 | */ |
| 1625 | atomic_inc(&instance->fw_outstanding); |
| 1626 | |
| 1627 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1628 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1629 | |
| 1630 | return 0; |
| 1631 | out_return_cmd: |
| 1632 | megasas_return_cmd(instance, cmd); |
| 1633 | return 1; |
| 1634 | } |
| 1635 | |
| 1636 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1637 | /** |
| 1638 | * megasas_queue_command - Queue entry point |
| 1639 | * @scmd: SCSI command to be queued |
| 1640 | * @done: Callback entry point |
| 1641 | */ |
| 1642 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1643 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1644 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1645 | struct megasas_instance *instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1646 | unsigned long flags; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1647 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1648 | |
| 1649 | instance = (struct megasas_instance *) |
| 1650 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1651 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1652 | if (instance->unload == 1) { |
| 1653 | scmd->result = DID_NO_CONNECT << 16; |
| 1654 | scmd->scsi_done(scmd); |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1658 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1659 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1660 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1661 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1662 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1663 | /* Check for an mpio path and adjust behavior */ |
| 1664 | if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) { |
| 1665 | if (megasas_check_mpio_paths(instance, scmd) == |
| 1666 | (DID_RESET << 16)) { |
| 1667 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1668 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1669 | } else { |
| 1670 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1671 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1672 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1673 | return 0; |
| 1674 | } |
| 1675 | } |
| 1676 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1677 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 1678 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1679 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1680 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1681 | return 0; |
| 1682 | } |
| 1683 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1684 | mr_device_priv_data = scmd->device->hostdata; |
| 1685 | if (!mr_device_priv_data) { |
| 1686 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1687 | scmd->result = DID_NO_CONNECT << 16; |
| 1688 | scmd->scsi_done(scmd); |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1692 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 1693 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1694 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1695 | } |
| 1696 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1697 | if (mr_device_priv_data->tm_busy) { |
| 1698 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1699 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 1700 | } |
| 1701 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1702 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1703 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1704 | scmd->result = 0; |
| 1705 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1706 | if (MEGASAS_IS_LOGICAL(scmd) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1707 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1708 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1709 | scmd->result = DID_BAD_TARGET << 16; |
| 1710 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1711 | } |
| 1712 | |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1713 | switch (scmd->cmnd[0]) { |
| 1714 | case SYNCHRONIZE_CACHE: |
| 1715 | /* |
| 1716 | * FW takes care of flush cache on its own |
| 1717 | * No need to send it down |
| 1718 | */ |
| 1719 | scmd->result = DID_OK << 16; |
| 1720 | goto out_done; |
| 1721 | default: |
| 1722 | break; |
| 1723 | } |
| 1724 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1725 | if (instance->instancet->build_and_issue_cmd(instance, scmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1726 | dev_err(&instance->pdev->dev, "Err returned from build_and_issue_cmd\n"); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1727 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1728 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1729 | |
| 1730 | return 0; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1731 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1732 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1733 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1734 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1735 | } |
| 1736 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1737 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1738 | { |
| 1739 | int i; |
| 1740 | |
| 1741 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1742 | |
| 1743 | if ((megasas_mgmt_info.instance[i]) && |
| 1744 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1745 | return megasas_mgmt_info.instance[i]; |
| 1746 | } |
| 1747 | |
| 1748 | return NULL; |
| 1749 | } |
| 1750 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1751 | /* |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1752 | * 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] | 1753 | * |
| 1754 | * @sdev: OS provided scsi device |
| 1755 | * |
| 1756 | * Returns void |
| 1757 | */ |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1758 | void megasas_update_sdev_properties(struct scsi_device *sdev) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1759 | { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1760 | u16 pd_index = 0; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1761 | u32 device_id, ld; |
| 1762 | struct megasas_instance *instance; |
| 1763 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1764 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1765 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1766 | struct MR_LD_RAID *raid; |
| 1767 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1768 | |
| 1769 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1770 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1771 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1772 | |
| 1773 | if (!fusion) |
| 1774 | return; |
| 1775 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1776 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && |
| 1777 | 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; |
| 1784 | } else { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1785 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1786 | + sdev->id; |
| 1787 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1788 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
| 1789 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1790 | |
| 1791 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1792 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
| 1793 | mr_device_priv_data->is_tm_capable = |
| 1794 | raid->capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1798 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1799 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1800 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1801 | u16 pd_index = 0; |
| 1802 | struct megasas_instance *instance; |
| 1803 | |
| 1804 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1805 | if (instance->allow_fw_scan) { |
| 1806 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && |
| 1807 | sdev->type == TYPE_DISK) { |
| 1808 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1809 | sdev->id; |
| 1810 | if (instance->pd_list[pd_index].driveState != |
| 1811 | MR_PD_STATE_SYSTEM) |
| 1812 | return -ENXIO; |
| 1813 | } |
| 1814 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1815 | megasas_update_sdev_properties(sdev); |
| 1816 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1817 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1818 | * The RAID firmware may require extended timeouts. |
| 1819 | */ |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1820 | blk_queue_rq_timeout(sdev->request_queue, |
| 1821 | MEGASAS_DEFAULT_CMD_TIMEOUT * HZ); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1822 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1823 | return 0; |
| 1824 | } |
| 1825 | |
| 1826 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1827 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1828 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1829 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1830 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1831 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1832 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1833 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1834 | /* |
| 1835 | * Open the OS scan to the SYSTEM PD |
| 1836 | */ |
| 1837 | pd_index = |
| 1838 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1839 | sdev->id; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1840 | if ((instance->allow_fw_scan || instance->pd_list[pd_index].driveState == |
| 1841 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1842 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1843 | } |
| 1844 | return -ENXIO; |
| 1845 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1846 | |
| 1847 | scan_target: |
| 1848 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 1849 | GFP_KERNEL); |
| 1850 | if (!mr_device_priv_data) |
| 1851 | return -ENOMEM; |
| 1852 | sdev->hostdata = mr_device_priv_data; |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1853 | return 0; |
| 1854 | } |
| 1855 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 1856 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 1857 | { |
| 1858 | kfree(sdev->hostdata); |
| 1859 | sdev->hostdata = NULL; |
| 1860 | } |
| 1861 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1862 | /* |
| 1863 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 1864 | * kill adapter |
| 1865 | * @instance: Adapter soft state |
| 1866 | * |
| 1867 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 1868 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1869 | { |
| 1870 | int i; |
| 1871 | struct megasas_cmd *cmd_mfi; |
| 1872 | struct megasas_cmd_fusion *cmd_fusion; |
| 1873 | struct fusion_context *fusion = instance->ctrl_context; |
| 1874 | |
| 1875 | /* Find all outstanding ioctls */ |
| 1876 | if (fusion) { |
| 1877 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1878 | cmd_fusion = fusion->cmd_list[i]; |
| 1879 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 1880 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 1881 | if (cmd_mfi->sync_cmd && |
| 1882 | cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT) |
| 1883 | megasas_complete_cmd(instance, |
| 1884 | cmd_mfi, DID_OK); |
| 1885 | } |
| 1886 | } |
| 1887 | } else { |
| 1888 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1889 | cmd_mfi = instance->cmd_list[i]; |
| 1890 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 1891 | MFI_CMD_ABORT) |
| 1892 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 1893 | } |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1898 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1899 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1900 | /* Set critical error to block I/O & ioctls in case caller didn't */ |
| 1901 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 1902 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 1903 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1904 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1905 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 1906 | (instance->ctrl_context)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1907 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1908 | /* Flush */ |
| 1909 | readl(&instance->reg_set->doorbell); |
| 1910 | if (instance->mpio && instance->requestorId) |
| 1911 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1912 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1913 | writel(MFI_STOP_ADP, |
| 1914 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1915 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1916 | /* Complete outstanding ioctls when adapter is killed */ |
| 1917 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 1922 | * restored to max value |
| 1923 | * @instance: Adapter soft state |
| 1924 | * |
| 1925 | */ |
| 1926 | void |
| 1927 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 1928 | { |
| 1929 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 1930 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1931 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 1932 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 1933 | && atomic_read(&instance->fw_outstanding) < |
| 1934 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1935 | |
| 1936 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 1937 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1938 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 1939 | instance->host->can_queue = instance->max_scsi_cmds; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1940 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1944 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1945 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 1946 | * @instance_addr: Address of adapter soft state |
| 1947 | * |
| 1948 | * Tasklet to complete cmds |
| 1949 | */ |
| 1950 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 1951 | { |
| 1952 | u32 producer; |
| 1953 | u32 consumer; |
| 1954 | u32 context; |
| 1955 | struct megasas_cmd *cmd; |
| 1956 | struct megasas_instance *instance = |
| 1957 | (struct megasas_instance *)instance_addr; |
| 1958 | unsigned long flags; |
| 1959 | |
| 1960 | /* If we have already declared adapter dead, donot complete cmds */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1961 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1962 | return; |
| 1963 | |
| 1964 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 1965 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1966 | producer = le32_to_cpu(*instance->producer); |
| 1967 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1968 | |
| 1969 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1970 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1971 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1972 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1973 | context); |
| 1974 | BUG(); |
| 1975 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1976 | |
| 1977 | cmd = instance->cmd_list[context]; |
| 1978 | |
| 1979 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 1980 | |
| 1981 | consumer++; |
| 1982 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 1983 | consumer = 0; |
| 1984 | } |
| 1985 | } |
| 1986 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1987 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1988 | |
| 1989 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 1990 | |
| 1991 | /* |
| 1992 | * Check if we can restore can_queue |
| 1993 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1994 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1995 | } |
| 1996 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1997 | /** |
| 1998 | * megasas_start_timer - Initializes a timer object |
| 1999 | * @instance: Adapter soft state |
| 2000 | * @timer: timer object to be initialized |
| 2001 | * @fn: timer function |
| 2002 | * @interval: time interval between timer function call |
| 2003 | * |
| 2004 | */ |
| 2005 | void megasas_start_timer(struct megasas_instance *instance, |
| 2006 | struct timer_list *timer, |
| 2007 | void *fn, unsigned long interval) |
| 2008 | { |
| 2009 | init_timer(timer); |
| 2010 | timer->expires = jiffies + interval; |
| 2011 | timer->data = (unsigned long)instance; |
| 2012 | timer->function = fn; |
| 2013 | add_timer(timer); |
| 2014 | } |
| 2015 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2016 | static void |
| 2017 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2018 | |
| 2019 | static void |
| 2020 | process_fw_state_change_wq(struct work_struct *work); |
| 2021 | |
| 2022 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2023 | { |
| 2024 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2025 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2026 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2027 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2028 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2029 | instance->instancet->disable_intr(instance); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2030 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 2031 | instance->issuepend_done = 0; |
| 2032 | |
| 2033 | atomic_set(&instance->fw_outstanding, 0); |
| 2034 | megasas_internal_reset_defer_cmds(instance); |
| 2035 | process_fw_state_change_wq(&instance->work_init); |
| 2036 | } |
| 2037 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2038 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2039 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2040 | { |
| 2041 | struct megasas_cmd *cmd; |
| 2042 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2043 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2044 | dma_addr_t new_affiliation_111_h; |
| 2045 | int ld, retval = 0; |
| 2046 | u8 thisVf; |
| 2047 | |
| 2048 | cmd = megasas_get_cmd(instance); |
| 2049 | |
| 2050 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2051 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2052 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2053 | instance->host->host_no); |
| 2054 | return -ENOMEM; |
| 2055 | } |
| 2056 | |
| 2057 | dcmd = &cmd->frame->dcmd; |
| 2058 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2059 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2060 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2061 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2062 | megasas_return_cmd(instance, cmd); |
| 2063 | return -ENOMEM; |
| 2064 | } |
| 2065 | |
| 2066 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2067 | memset(instance->vf_affiliation_111, 0, |
| 2068 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2069 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2070 | new_affiliation_111 = |
| 2071 | pci_alloc_consistent(instance->pdev, |
| 2072 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2073 | &new_affiliation_111_h); |
| 2074 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2075 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2076 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2077 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2078 | megasas_return_cmd(instance, cmd); |
| 2079 | return -ENOMEM; |
| 2080 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2081 | memset(new_affiliation_111, 0, |
| 2082 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2086 | |
| 2087 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2088 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2089 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2090 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2091 | dcmd->timeout = 0; |
| 2092 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2093 | dcmd->data_xfer_len = |
| 2094 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2095 | 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] | 2096 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2097 | if (initial) |
| 2098 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2099 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2100 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2101 | dcmd->sgl.sge32[0].phys_addr = |
| 2102 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2103 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2104 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2105 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2106 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2107 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2108 | "scsi%d\n", instance->host->host_no); |
| 2109 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2110 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2111 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2112 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2113 | dcmd->cmd_status, instance->host->host_no); |
| 2114 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2115 | goto out; |
| 2116 | } |
| 2117 | |
| 2118 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2119 | thisVf = new_affiliation_111->thisVf; |
| 2120 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2121 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2122 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2123 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2124 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2125 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2126 | memcpy(instance->vf_affiliation_111, |
| 2127 | new_affiliation_111, |
| 2128 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2129 | retval = 1; |
| 2130 | goto out; |
| 2131 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2132 | } |
| 2133 | out: |
| 2134 | if (new_affiliation_111) { |
| 2135 | pci_free_consistent(instance->pdev, |
| 2136 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2137 | new_affiliation_111, |
| 2138 | new_affiliation_111_h); |
| 2139 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2140 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2141 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2142 | |
| 2143 | return retval; |
| 2144 | } |
| 2145 | |
| 2146 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2147 | int initial) |
| 2148 | { |
| 2149 | struct megasas_cmd *cmd; |
| 2150 | struct megasas_dcmd_frame *dcmd; |
| 2151 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2152 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2153 | dma_addr_t new_affiliation_h; |
| 2154 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2155 | u8 thisVf; |
| 2156 | |
| 2157 | cmd = megasas_get_cmd(instance); |
| 2158 | |
| 2159 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2160 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2161 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2162 | instance->host->host_no); |
| 2163 | return -ENOMEM; |
| 2164 | } |
| 2165 | |
| 2166 | dcmd = &cmd->frame->dcmd; |
| 2167 | |
| 2168 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2169 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2170 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2171 | megasas_return_cmd(instance, cmd); |
| 2172 | return -ENOMEM; |
| 2173 | } |
| 2174 | |
| 2175 | if (initial) |
| 2176 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2177 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2178 | else { |
| 2179 | new_affiliation = |
| 2180 | pci_alloc_consistent(instance->pdev, |
| 2181 | (MAX_LOGICAL_DRIVES + 1) * |
| 2182 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2183 | &new_affiliation_h); |
| 2184 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2185 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2186 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2187 | instance->host->host_no); |
| 2188 | megasas_return_cmd(instance, cmd); |
| 2189 | return -ENOMEM; |
| 2190 | } |
| 2191 | memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2192 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2193 | } |
| 2194 | |
| 2195 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2196 | |
| 2197 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2198 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2199 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2200 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2201 | dcmd->timeout = 0; |
| 2202 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2203 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2204 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2205 | 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] | 2206 | |
| 2207 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2208 | dcmd->sgl.sge32[0].phys_addr = |
| 2209 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2210 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2211 | dcmd->sgl.sge32[0].phys_addr = |
| 2212 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2213 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2214 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2215 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2216 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2217 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2218 | "scsi%d\n", instance->host->host_no); |
| 2219 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2220 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2221 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2222 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2223 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2224 | dcmd->cmd_status, instance->host->host_no); |
| 2225 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2226 | goto out; |
| 2227 | } |
| 2228 | |
| 2229 | if (!initial) { |
| 2230 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2231 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2232 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2233 | instance->host->host_no); |
| 2234 | retval = 1; |
| 2235 | goto out; |
| 2236 | } |
| 2237 | newmap = new_affiliation->map; |
| 2238 | savedmap = instance->vf_affiliation->map; |
| 2239 | thisVf = new_affiliation->thisVf; |
| 2240 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2241 | found = 0; |
| 2242 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2243 | j++) { |
| 2244 | if (newmap->ref.targetId == |
| 2245 | savedmap->ref.targetId) { |
| 2246 | found = 1; |
| 2247 | if (newmap->policy[thisVf] != |
| 2248 | savedmap->policy[thisVf]) { |
| 2249 | doscan = 1; |
| 2250 | goto out; |
| 2251 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2252 | } |
| 2253 | savedmap = (struct MR_LD_VF_MAP *) |
| 2254 | ((unsigned char *)savedmap + |
| 2255 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2256 | } |
| 2257 | if (!found && newmap->policy[thisVf] != |
| 2258 | MR_LD_ACCESS_HIDDEN) { |
| 2259 | doscan = 1; |
| 2260 | goto out; |
| 2261 | } |
| 2262 | newmap = (struct MR_LD_VF_MAP *) |
| 2263 | ((unsigned char *)newmap + newmap->size); |
| 2264 | } |
| 2265 | |
| 2266 | newmap = new_affiliation->map; |
| 2267 | savedmap = instance->vf_affiliation->map; |
| 2268 | |
| 2269 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2270 | found = 0; |
| 2271 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2272 | if (savedmap->ref.targetId == |
| 2273 | newmap->ref.targetId) { |
| 2274 | found = 1; |
| 2275 | if (savedmap->policy[thisVf] != |
| 2276 | newmap->policy[thisVf]) { |
| 2277 | doscan = 1; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2281 | newmap = (struct MR_LD_VF_MAP *) |
| 2282 | ((unsigned char *)newmap + |
| 2283 | newmap->size); |
| 2284 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2285 | if (!found && savedmap->policy[thisVf] != |
| 2286 | MR_LD_ACCESS_HIDDEN) { |
| 2287 | doscan = 1; |
| 2288 | goto out; |
| 2289 | } |
| 2290 | savedmap = (struct MR_LD_VF_MAP *) |
| 2291 | ((unsigned char *)savedmap + |
| 2292 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2293 | } |
| 2294 | } |
| 2295 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2296 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2297 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2298 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2299 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2300 | new_affiliation->size); |
| 2301 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2302 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2303 | |
| 2304 | if (new_affiliation) |
| 2305 | pci_free_consistent(instance->pdev, |
| 2306 | (MAX_LOGICAL_DRIVES + 1) * |
| 2307 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2308 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2309 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2310 | |
| 2311 | return retval; |
| 2312 | } |
| 2313 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2314 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2315 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2316 | int initial) |
| 2317 | { |
| 2318 | int retval; |
| 2319 | |
| 2320 | if (instance->PlasmaFW111) |
| 2321 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2322 | else |
| 2323 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2324 | return retval; |
| 2325 | } |
| 2326 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2327 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2328 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2329 | int initial) |
| 2330 | { |
| 2331 | struct megasas_cmd *cmd; |
| 2332 | struct megasas_dcmd_frame *dcmd; |
| 2333 | int retval = 0; |
| 2334 | |
| 2335 | cmd = megasas_get_cmd(instance); |
| 2336 | |
| 2337 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2338 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2339 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2340 | instance->host->host_no); |
| 2341 | return -ENOMEM; |
| 2342 | } |
| 2343 | |
| 2344 | dcmd = &cmd->frame->dcmd; |
| 2345 | |
| 2346 | if (initial) { |
| 2347 | instance->hb_host_mem = |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 2348 | pci_zalloc_consistent(instance->pdev, |
| 2349 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2350 | &instance->hb_host_mem_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2351 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2352 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2353 | " memory for heartbeat host memory for scsi%d\n", |
| 2354 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2355 | retval = -ENOMEM; |
| 2356 | goto out; |
| 2357 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2361 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2362 | 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] | 2363 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2364 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2365 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2366 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2367 | dcmd->timeout = 0; |
| 2368 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2369 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2370 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
| 2371 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->hb_host_mem_h); |
| 2372 | 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] | 2373 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2374 | 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] | 2375 | instance->host->host_no); |
| 2376 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2377 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 2378 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2379 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2380 | else |
| 2381 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2382 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2383 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2384 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2385 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2386 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2387 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2388 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | out: |
| 2392 | megasas_return_cmd(instance, cmd); |
| 2393 | |
| 2394 | return retval; |
| 2395 | } |
| 2396 | |
| 2397 | /* Handler for SR-IOV heartbeat */ |
| 2398 | void megasas_sriov_heartbeat_handler(unsigned long instance_addr) |
| 2399 | { |
| 2400 | struct megasas_instance *instance = |
| 2401 | (struct megasas_instance *)instance_addr; |
| 2402 | |
| 2403 | if (instance->hb_host_mem->HB.fwCounter != |
| 2404 | instance->hb_host_mem->HB.driverCounter) { |
| 2405 | instance->hb_host_mem->HB.driverCounter = |
| 2406 | instance->hb_host_mem->HB.fwCounter; |
| 2407 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2408 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2409 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2410 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2411 | "completed for scsi%d\n", instance->host->host_no); |
| 2412 | schedule_work(&instance->work_init); |
| 2413 | } |
| 2414 | } |
| 2415 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2416 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2417 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2418 | * @instance: Adapter soft state |
| 2419 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2420 | * 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] | 2421 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2422 | * are pending after this time period. It also marks the controller dead. |
| 2423 | */ |
| 2424 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2425 | { |
| 2426 | int i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2427 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2428 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2429 | u8 adprecovery; |
| 2430 | unsigned long flags; |
| 2431 | struct list_head clist_local; |
| 2432 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2433 | u32 fw_state; |
| 2434 | u8 kill_adapter_flag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2435 | |
| 2436 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2437 | adprecovery = instance->adprecovery; |
| 2438 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2439 | |
| 2440 | if (adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 2441 | |
| 2442 | INIT_LIST_HEAD(&clist_local); |
| 2443 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2444 | list_splice_init(&instance->internal_reset_pending_q, |
| 2445 | &clist_local); |
| 2446 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2447 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2448 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2449 | for (i = 0; i < wait_time; i++) { |
| 2450 | msleep(1000); |
| 2451 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2452 | adprecovery = instance->adprecovery; |
| 2453 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2454 | if (adprecovery == MEGASAS_HBA_OPERATIONAL) |
| 2455 | break; |
| 2456 | } |
| 2457 | |
| 2458 | if (adprecovery != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2459 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2460 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2461 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2462 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2463 | return FAILED; |
| 2464 | } |
| 2465 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2466 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2467 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2468 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2469 | struct megasas_cmd, list); |
| 2470 | list_del_init(&reset_cmd->list); |
| 2471 | if (reset_cmd->scmd) { |
| 2472 | reset_cmd->scmd->result = DID_RESET << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2473 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2474 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2475 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2476 | |
| 2477 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2478 | megasas_return_cmd(instance, reset_cmd); |
| 2479 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2480 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2481 | "reset queue\n", |
| 2482 | reset_cmd); |
| 2483 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2484 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2485 | instance->instancet->fire_cmd(instance, |
| 2486 | reset_cmd->frame_phys_addr, |
| 2487 | 0, instance->reg_set); |
| 2488 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2489 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2490 | "cmds lst\n", |
| 2491 | reset_cmd); |
| 2492 | } |
| 2493 | reset_index++; |
| 2494 | } |
| 2495 | |
| 2496 | return SUCCESS; |
| 2497 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2498 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2499 | for (i = 0; i < resetwaittime; i++) { |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2500 | int outstanding = atomic_read(&instance->fw_outstanding); |
| 2501 | |
| 2502 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2503 | break; |
| 2504 | |
| 2505 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2506 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2507 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2508 | /* |
| 2509 | * Call cmd completion routine. Cmd to be |
| 2510 | * be completed directly without depending on isr. |
| 2511 | */ |
| 2512 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | msleep(1000); |
| 2516 | } |
| 2517 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2518 | i = 0; |
| 2519 | kill_adapter_flag = 0; |
| 2520 | do { |
| 2521 | fw_state = instance->instancet->read_fw_status_reg( |
| 2522 | instance->reg_set) & MFI_STATE_MASK; |
| 2523 | if ((fw_state == MFI_STATE_FAULT) && |
| 2524 | (instance->disableOnlineCtrlReset == 0)) { |
| 2525 | if (i == 3) { |
| 2526 | kill_adapter_flag = 2; |
| 2527 | break; |
| 2528 | } |
| 2529 | megasas_do_ocr(instance); |
| 2530 | kill_adapter_flag = 1; |
| 2531 | |
| 2532 | /* wait for 1 secs to let FW finish the pending cmds */ |
| 2533 | msleep(1000); |
| 2534 | } |
| 2535 | i++; |
| 2536 | } while (i <= 3); |
| 2537 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2538 | if (atomic_read(&instance->fw_outstanding) && !kill_adapter_flag) { |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2539 | if (instance->disableOnlineCtrlReset == 0) { |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2540 | megasas_do_ocr(instance); |
| 2541 | |
| 2542 | /* wait for 5 secs to let FW finish the pending cmds */ |
| 2543 | for (i = 0; i < wait_time; i++) { |
| 2544 | int outstanding = |
| 2545 | atomic_read(&instance->fw_outstanding); |
| 2546 | if (!outstanding) |
| 2547 | return SUCCESS; |
| 2548 | msleep(1000); |
| 2549 | } |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | if (atomic_read(&instance->fw_outstanding) || |
| 2554 | (kill_adapter_flag == 2)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2555 | dev_notice(&instance->pdev->dev, "pending cmds after reset\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2556 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2557 | * Send signal to FW to stop processing any pending cmds. |
| 2558 | * The controller will be taken offline by the OS now. |
| 2559 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2560 | if ((instance->pdev->device == |
| 2561 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 2562 | (instance->pdev->device == |
| 2563 | PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 2564 | writel(MFI_STOP_ADP, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2565 | &instance->reg_set->doorbell); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2566 | } else { |
| 2567 | writel(MFI_STOP_ADP, |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2568 | &instance->reg_set->inbound_doorbell); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2569 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 2570 | megasas_dump_pending_frames(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2571 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2572 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2573 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2574 | return FAILED; |
| 2575 | } |
| 2576 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2577 | dev_notice(&instance->pdev->dev, "no pending cmds after reset\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2578 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2579 | return SUCCESS; |
| 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * megasas_generic_reset - Generic reset routine |
| 2584 | * @scmd: Mid-layer SCSI command |
| 2585 | * |
| 2586 | * This routine implements a generic reset handler for device, bus and host |
| 2587 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2588 | * function after they do their specific tasks. |
| 2589 | */ |
| 2590 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2591 | { |
| 2592 | int ret_val; |
| 2593 | struct megasas_instance *instance; |
| 2594 | |
| 2595 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2596 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2597 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2598 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2599 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2600 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2601 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2602 | return FAILED; |
| 2603 | } |
| 2604 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2605 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2606 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2607 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2608 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2609 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2610 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2611 | return ret_val; |
| 2612 | } |
| 2613 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2614 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2615 | * megasas_reset_timer - quiesce the adapter if required |
| 2616 | * @scmd: scsi cmnd |
| 2617 | * |
| 2618 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2619 | * cmd has not been completed within the timeout period. |
| 2620 | */ |
| 2621 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2622 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2623 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2624 | struct megasas_instance *instance; |
| 2625 | unsigned long flags; |
| 2626 | |
| 2627 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
| 2628 | (MEGASAS_DEFAULT_CMD_TIMEOUT * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2629 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2632 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2633 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2634 | /* FW is busy, throttle IO */ |
| 2635 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2636 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2637 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2638 | instance->last_time = jiffies; |
| 2639 | instance->flag |= MEGASAS_FW_BUSY; |
| 2640 | |
| 2641 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2642 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2643 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2647 | * megasas_reset_device - Device reset handler entry point |
| 2648 | */ |
| 2649 | static int megasas_reset_device(struct scsi_cmnd *scmd) |
| 2650 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2651 | /* |
| 2652 | * First wait for all commands to complete |
| 2653 | */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2654 | return megasas_generic_reset(scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | /** |
| 2658 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2659 | */ |
| 2660 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2661 | { |
| 2662 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2663 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2664 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2665 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2666 | |
| 2667 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2668 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2669 | */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 2670 | if (instance->ctrl_context) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2671 | ret = megasas_reset_fusion(scmd->device->host, 1); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2672 | else |
| 2673 | ret = megasas_generic_reset(scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2674 | |
| 2675 | return ret; |
| 2676 | } |
| 2677 | |
| 2678 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2679 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2680 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2681 | * @bdev: block device |
| 2682 | * @capacity: drive capacity |
| 2683 | * @geom: geometry parameters |
| 2684 | */ |
| 2685 | static int |
| 2686 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2687 | sector_t capacity, int geom[]) |
| 2688 | { |
| 2689 | int heads; |
| 2690 | int sectors; |
| 2691 | sector_t cylinders; |
| 2692 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2693 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2694 | /* Default heads (64) & sectors (32) */ |
| 2695 | heads = 64; |
| 2696 | sectors = 32; |
| 2697 | |
| 2698 | tmp = heads * sectors; |
| 2699 | cylinders = capacity; |
| 2700 | |
| 2701 | sector_div(cylinders, tmp); |
| 2702 | |
| 2703 | /* |
| 2704 | * Handle extended translation size for logical drives > 1Gb |
| 2705 | */ |
| 2706 | |
| 2707 | if (capacity >= 0x200000) { |
| 2708 | heads = 255; |
| 2709 | sectors = 63; |
| 2710 | tmp = heads*sectors; |
| 2711 | cylinders = capacity; |
| 2712 | sector_div(cylinders, tmp); |
| 2713 | } |
| 2714 | |
| 2715 | geom[0] = heads; |
| 2716 | geom[1] = sectors; |
| 2717 | geom[2] = cylinders; |
| 2718 | |
| 2719 | return 0; |
| 2720 | } |
| 2721 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2722 | static void megasas_aen_polling(struct work_struct *work); |
| 2723 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2724 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2725 | * megasas_service_aen - Processes an event notification |
| 2726 | * @instance: Adapter soft state |
| 2727 | * @cmd: AEN command completed by the ISR |
| 2728 | * |
| 2729 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2730 | * event occurs. When an event of interest occurs, FW completes the command |
| 2731 | * that it was previously holding. |
| 2732 | * |
| 2733 | * This routines sends SIGIO signal to processes that have registered with the |
| 2734 | * driver for AEN. |
| 2735 | */ |
| 2736 | static void |
| 2737 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2738 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2739 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2740 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2741 | /* |
| 2742 | * Don't signal app if it is just an aborted previously registered aen |
| 2743 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2744 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2745 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2746 | megasas_poll_wait_aen = 1; |
| 2747 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2748 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2749 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2750 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2751 | else |
| 2752 | cmd->abort_aen = 0; |
| 2753 | |
| 2754 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2755 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2756 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2757 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2758 | if ((instance->unload == 0) && |
| 2759 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2760 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2761 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2762 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2763 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2764 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2765 | } else { |
| 2766 | ev->instance = instance; |
| 2767 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2768 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2769 | megasas_aen_polling); |
| 2770 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2771 | } |
| 2772 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2773 | } |
| 2774 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2775 | static ssize_t |
| 2776 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 2777 | struct device_attribute *attr, const char *buf, size_t count) |
| 2778 | { |
| 2779 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2780 | struct megasas_instance *instance = |
| 2781 | (struct megasas_instance *) shost->hostdata; |
| 2782 | int val = 0; |
| 2783 | unsigned long flags; |
| 2784 | |
| 2785 | if (kstrtoint(buf, 0, &val) != 0) |
| 2786 | return -EINVAL; |
| 2787 | |
| 2788 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2789 | instance->fw_crash_buffer_offset = val; |
| 2790 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2791 | return strlen(buf); |
| 2792 | } |
| 2793 | |
| 2794 | static ssize_t |
| 2795 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 2796 | struct device_attribute *attr, char *buf) |
| 2797 | { |
| 2798 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2799 | struct megasas_instance *instance = |
| 2800 | (struct megasas_instance *) shost->hostdata; |
| 2801 | u32 size; |
| 2802 | unsigned long buff_addr; |
| 2803 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 2804 | unsigned long src_addr; |
| 2805 | unsigned long flags; |
| 2806 | u32 buff_offset; |
| 2807 | |
| 2808 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2809 | buff_offset = instance->fw_crash_buffer_offset; |
| 2810 | if (!instance->crash_dump_buf && |
| 2811 | !((instance->fw_crash_state == AVAILABLE) || |
| 2812 | (instance->fw_crash_state == COPYING))) { |
| 2813 | dev_err(&instance->pdev->dev, |
| 2814 | "Firmware crash dump is not available\n"); |
| 2815 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2816 | return -EINVAL; |
| 2817 | } |
| 2818 | |
| 2819 | buff_addr = (unsigned long) buf; |
| 2820 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2821 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2822 | dev_err(&instance->pdev->dev, |
| 2823 | "Firmware crash dump offset is out of range\n"); |
| 2824 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2825 | return 0; |
| 2826 | } |
| 2827 | |
| 2828 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 2829 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 2830 | |
| 2831 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 2832 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2833 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2834 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2835 | |
| 2836 | return size; |
| 2837 | } |
| 2838 | |
| 2839 | static ssize_t |
| 2840 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 2841 | struct device_attribute *attr, char *buf) |
| 2842 | { |
| 2843 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2844 | struct megasas_instance *instance = |
| 2845 | (struct megasas_instance *) shost->hostdata; |
| 2846 | |
| 2847 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 2848 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 2849 | } |
| 2850 | |
| 2851 | static ssize_t |
| 2852 | megasas_fw_crash_state_store(struct device *cdev, |
| 2853 | struct device_attribute *attr, const char *buf, size_t count) |
| 2854 | { |
| 2855 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2856 | struct megasas_instance *instance = |
| 2857 | (struct megasas_instance *) shost->hostdata; |
| 2858 | int val = 0; |
| 2859 | unsigned long flags; |
| 2860 | |
| 2861 | if (kstrtoint(buf, 0, &val) != 0) |
| 2862 | return -EINVAL; |
| 2863 | |
| 2864 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 2865 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 2866 | "firmware crash state\n"); |
| 2867 | return -EINVAL; |
| 2868 | } |
| 2869 | |
| 2870 | instance->fw_crash_state = val; |
| 2871 | |
| 2872 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 2873 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2874 | megasas_free_host_crash_buffer(instance); |
| 2875 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2876 | if (val == COPY_ERROR) |
| 2877 | dev_info(&instance->pdev->dev, "application failed to " |
| 2878 | "copy Firmware crash dump\n"); |
| 2879 | else |
| 2880 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 2881 | "copied successfully\n"); |
| 2882 | } |
| 2883 | return strlen(buf); |
| 2884 | } |
| 2885 | |
| 2886 | static ssize_t |
| 2887 | megasas_fw_crash_state_show(struct device *cdev, |
| 2888 | struct device_attribute *attr, char *buf) |
| 2889 | { |
| 2890 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2891 | struct megasas_instance *instance = |
| 2892 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2893 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2894 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 2895 | } |
| 2896 | |
| 2897 | static ssize_t |
| 2898 | megasas_page_size_show(struct device *cdev, |
| 2899 | struct device_attribute *attr, char *buf) |
| 2900 | { |
| 2901 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 2902 | } |
| 2903 | |
| 2904 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 2905 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 2906 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 2907 | megasas_fw_crash_buffer_size_show, NULL); |
| 2908 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 2909 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 2910 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 2911 | megasas_page_size_show, NULL); |
| 2912 | |
| 2913 | struct device_attribute *megaraid_host_attrs[] = { |
| 2914 | &dev_attr_fw_crash_buffer_size, |
| 2915 | &dev_attr_fw_crash_buffer, |
| 2916 | &dev_attr_fw_crash_state, |
| 2917 | &dev_attr_page_size, |
| 2918 | NULL, |
| 2919 | }; |
| 2920 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2921 | /* |
| 2922 | * Scsi host template for megaraid_sas driver |
| 2923 | */ |
| 2924 | static struct scsi_host_template megasas_template = { |
| 2925 | |
| 2926 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 2927 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2928 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2929 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2930 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 2931 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2932 | .queuecommand = megasas_queue_command, |
| 2933 | .eh_device_reset_handler = megasas_reset_device, |
| 2934 | .eh_bus_reset_handler = megasas_reset_bus_host, |
| 2935 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2936 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2937 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2938 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2939 | .use_clustering = ENABLE_CLUSTERING, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 2940 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 2941 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2942 | }; |
| 2943 | |
| 2944 | /** |
| 2945 | * megasas_complete_int_cmd - Completes an internal command |
| 2946 | * @instance: Adapter soft state |
| 2947 | * @cmd: Command to be completed |
| 2948 | * |
| 2949 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 2950 | * after it issues a command. This function wakes up that waiting routine by |
| 2951 | * calling wake_up() on the wait queue. |
| 2952 | */ |
| 2953 | static void |
| 2954 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 2955 | struct megasas_cmd *cmd) |
| 2956 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2957 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2958 | wake_up(&instance->int_cmd_wait_q); |
| 2959 | } |
| 2960 | |
| 2961 | /** |
| 2962 | * megasas_complete_abort - Completes aborting a command |
| 2963 | * @instance: Adapter soft state |
| 2964 | * @cmd: Cmd that was issued to abort another cmd |
| 2965 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2966 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 2967 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2968 | * wakes up all functions waiting on the same wait queue. |
| 2969 | */ |
| 2970 | static void |
| 2971 | megasas_complete_abort(struct megasas_instance *instance, |
| 2972 | struct megasas_cmd *cmd) |
| 2973 | { |
| 2974 | if (cmd->sync_cmd) { |
| 2975 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2976 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2977 | wake_up(&instance->abort_cmd_wait_q); |
| 2978 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2982 | * megasas_complete_cmd - Completes a command |
| 2983 | * @instance: Adapter soft state |
| 2984 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2985 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2986 | * SCSI mid-layer instead of the value returned |
| 2987 | * by the FW. This should be used if caller wants |
| 2988 | * an alternate status (as in the case of aborted |
| 2989 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2990 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2991 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2992 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 2993 | u8 alt_status) |
| 2994 | { |
| 2995 | int exception = 0; |
| 2996 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2997 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2998 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2999 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3000 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3001 | /* flag for the retry reset */ |
| 3002 | cmd->retry_for_fw_reset = 0; |
| 3003 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3004 | if (cmd->scmd) |
| 3005 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3006 | |
| 3007 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3008 | case MFI_CMD_INVALID: |
| 3009 | /* Some older 1068 controller FW may keep a pended |
| 3010 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3011 | when booting the kdump kernel. Ignore this command to |
| 3012 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3013 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3014 | "completed\n"); |
| 3015 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3016 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3017 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3018 | case MFI_CMD_PD_SCSI_IO: |
| 3019 | case MFI_CMD_LD_SCSI_IO: |
| 3020 | |
| 3021 | /* |
| 3022 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3023 | * issued either through an IO path or an IOCTL path. If it |
| 3024 | * was via IOCTL, we will send it to internal completion. |
| 3025 | */ |
| 3026 | if (cmd->sync_cmd) { |
| 3027 | cmd->sync_cmd = 0; |
| 3028 | megasas_complete_int_cmd(instance, cmd); |
| 3029 | break; |
| 3030 | } |
| 3031 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3032 | case MFI_CMD_LD_READ: |
| 3033 | case MFI_CMD_LD_WRITE: |
| 3034 | |
| 3035 | if (alt_status) { |
| 3036 | cmd->scmd->result = alt_status << 16; |
| 3037 | exception = 1; |
| 3038 | } |
| 3039 | |
| 3040 | if (exception) { |
| 3041 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3042 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3043 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3044 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3045 | cmd->scmd->scsi_done(cmd->scmd); |
| 3046 | megasas_return_cmd(instance, cmd); |
| 3047 | |
| 3048 | break; |
| 3049 | } |
| 3050 | |
| 3051 | switch (hdr->cmd_status) { |
| 3052 | |
| 3053 | case MFI_STAT_OK: |
| 3054 | cmd->scmd->result = DID_OK << 16; |
| 3055 | break; |
| 3056 | |
| 3057 | case MFI_STAT_SCSI_IO_FAILED: |
| 3058 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3059 | cmd->scmd->result = |
| 3060 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3061 | break; |
| 3062 | |
| 3063 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3064 | |
| 3065 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3066 | |
| 3067 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3068 | memset(cmd->scmd->sense_buffer, 0, |
| 3069 | SCSI_SENSE_BUFFERSIZE); |
| 3070 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3071 | hdr->sense_len); |
| 3072 | |
| 3073 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3074 | } |
| 3075 | |
| 3076 | break; |
| 3077 | |
| 3078 | case MFI_STAT_LD_OFFLINE: |
| 3079 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3080 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3081 | break; |
| 3082 | |
| 3083 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3084 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3085 | hdr->cmd_status); |
| 3086 | cmd->scmd->result = DID_ERROR << 16; |
| 3087 | break; |
| 3088 | } |
| 3089 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3090 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3091 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3092 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3093 | cmd->scmd->scsi_done(cmd->scmd); |
| 3094 | megasas_return_cmd(instance, cmd); |
| 3095 | |
| 3096 | break; |
| 3097 | |
| 3098 | case MFI_CMD_SMP: |
| 3099 | case MFI_CMD_STP: |
| 3100 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3101 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3102 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3103 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3104 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3105 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3106 | spin_lock_irqsave(instance->host->host_lock, flags); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3107 | instance->map_update_cmd = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3108 | if (cmd->frame->hdr.cmd_status != 0) { |
| 3109 | if (cmd->frame->hdr.cmd_status != |
| 3110 | MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3111 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3112 | cmd->frame->hdr.cmd_status); |
| 3113 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3114 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3115 | spin_unlock_irqrestore( |
| 3116 | instance->host->host_lock, |
| 3117 | flags); |
| 3118 | break; |
| 3119 | } |
| 3120 | } else |
| 3121 | instance->map_id++; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3122 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3123 | |
| 3124 | /* |
| 3125 | * Set fast path IO to ZERO. |
| 3126 | * Validate Map will set proper value. |
| 3127 | * Meanwhile all IOs will go as LD IO. |
| 3128 | */ |
| 3129 | if (MR_ValidateMapInfo(instance)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3130 | fusion->fast_path_io = 1; |
| 3131 | else |
| 3132 | fusion->fast_path_io = 0; |
| 3133 | megasas_sync_map_info(instance); |
| 3134 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3135 | flags); |
| 3136 | break; |
| 3137 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3138 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3139 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3140 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3141 | megasas_poll_wait_aen = 0; |
| 3142 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3143 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3144 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3145 | /* FW has an updated PD sequence */ |
| 3146 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3147 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3148 | |
| 3149 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3150 | status = cmd->frame->hdr.cmd_status; |
| 3151 | instance->jbod_seq_cmd = NULL; |
| 3152 | megasas_return_cmd(instance, cmd); |
| 3153 | |
| 3154 | if (status == MFI_STAT_OK) { |
| 3155 | instance->pd_seq_map_id++; |
| 3156 | /* Re-register a pd sync seq num cmd */ |
| 3157 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3158 | instance->use_seqnum_jbod_fp = false; |
| 3159 | } else |
| 3160 | instance->use_seqnum_jbod_fp = false; |
| 3161 | |
| 3162 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3163 | break; |
| 3164 | } |
| 3165 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3166 | /* |
| 3167 | * See if got an event notification |
| 3168 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3169 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3170 | megasas_service_aen(instance, cmd); |
| 3171 | else |
| 3172 | megasas_complete_int_cmd(instance, cmd); |
| 3173 | |
| 3174 | break; |
| 3175 | |
| 3176 | case MFI_CMD_ABORT: |
| 3177 | /* |
| 3178 | * Cmd issued to abort another cmd returned |
| 3179 | */ |
| 3180 | megasas_complete_abort(instance, cmd); |
| 3181 | break; |
| 3182 | |
| 3183 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3184 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3185 | hdr->cmd); |
| 3186 | break; |
| 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3191 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3192 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3193 | * @instance: Adapter soft state |
| 3194 | */ |
| 3195 | static inline void |
| 3196 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3197 | { |
| 3198 | struct megasas_cmd *cmd; |
| 3199 | struct list_head clist_local; |
| 3200 | union megasas_evt_class_locale class_locale; |
| 3201 | unsigned long flags; |
| 3202 | u32 seq_num; |
| 3203 | |
| 3204 | INIT_LIST_HEAD(&clist_local); |
| 3205 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3206 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3207 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3208 | |
| 3209 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3210 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3211 | struct megasas_cmd, list); |
| 3212 | list_del_init(&cmd->list); |
| 3213 | |
| 3214 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3215 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3216 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3217 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3218 | |
| 3219 | cmd->retry_for_fw_reset++; |
| 3220 | |
| 3221 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3222 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3223 | "was tried multiple times during reset." |
| 3224 | "Shutting down the HBA\n", |
| 3225 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3226 | instance->instancet->disable_intr(instance); |
| 3227 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3228 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3229 | return; |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | if (cmd->sync_cmd == 1) { |
| 3234 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3235 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3236 | "cmd attached to internal command!\n"); |
| 3237 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3238 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3239 | "on the internal reset queue," |
| 3240 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3241 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3242 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3243 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3244 | 0, instance->reg_set); |
| 3245 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3246 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3247 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3248 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3249 | |
| 3250 | atomic_inc(&instance->fw_outstanding); |
| 3251 | instance->instancet->fire_cmd(instance, |
| 3252 | cmd->frame_phys_addr, |
| 3253 | cmd->frame_count-1, instance->reg_set); |
| 3254 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3255 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3256 | "internal reset defer list while re-issue!!\n", |
| 3257 | cmd); |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3262 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3263 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3264 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3265 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3269 | * Initiate AEN (Asynchronous Event Notification) |
| 3270 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3271 | seq_num = instance->last_seq_num; |
| 3272 | class_locale.members.reserved = 0; |
| 3273 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3274 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3275 | |
| 3276 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3277 | } |
| 3278 | |
| 3279 | /** |
| 3280 | * Move the internal reset pending commands to a deferred queue. |
| 3281 | * |
| 3282 | * We move the commands pending at internal reset time to a |
| 3283 | * pending queue. This queue would be flushed after successful |
| 3284 | * completion of the internal reset sequence. if the internal reset |
| 3285 | * did not complete in time, the kernel reset handler would flush |
| 3286 | * these commands. |
| 3287 | **/ |
| 3288 | static void |
| 3289 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3290 | { |
| 3291 | struct megasas_cmd *cmd; |
| 3292 | int i; |
| 3293 | u32 max_cmd = instance->max_fw_cmds; |
| 3294 | u32 defer_index; |
| 3295 | unsigned long flags; |
| 3296 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3297 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3298 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3299 | for (i = 0; i < max_cmd; i++) { |
| 3300 | cmd = instance->cmd_list[i]; |
| 3301 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3302 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3303 | "on the defer queue as internal\n", |
| 3304 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3305 | |
| 3306 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3307 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3308 | " moving this cmd:%p, %d %p, it was" |
| 3309 | "discovered on some list?\n", |
| 3310 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3311 | |
| 3312 | list_del_init(&cmd->list); |
| 3313 | } |
| 3314 | defer_index++; |
| 3315 | list_add_tail(&cmd->list, |
| 3316 | &instance->internal_reset_pending_q); |
| 3317 | } |
| 3318 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3319 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | |
| 3323 | static void |
| 3324 | process_fw_state_change_wq(struct work_struct *work) |
| 3325 | { |
| 3326 | struct megasas_instance *instance = |
| 3327 | container_of(work, struct megasas_instance, work_init); |
| 3328 | u32 wait; |
| 3329 | unsigned long flags; |
| 3330 | |
| 3331 | if (instance->adprecovery != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3332 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3333 | instance->adprecovery); |
| 3334 | return ; |
| 3335 | } |
| 3336 | |
| 3337 | if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3338 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3339 | "state, restarting it...\n"); |
| 3340 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3341 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3342 | atomic_set(&instance->fw_outstanding, 0); |
| 3343 | |
| 3344 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3345 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3346 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3347 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3348 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3349 | "initiating next stage...\n"); |
| 3350 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3351 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3352 | "state 2 starting...\n"); |
| 3353 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3354 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3355 | for (wait = 0; wait < 30; wait++) { |
| 3356 | msleep(1000); |
| 3357 | } |
| 3358 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3359 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3360 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3361 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3362 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3363 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3364 | return ; |
| 3365 | } |
| 3366 | |
| 3367 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3368 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3369 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3370 | ) { |
| 3371 | *instance->consumer = *instance->producer; |
| 3372 | } else { |
| 3373 | *instance->consumer = 0; |
| 3374 | *instance->producer = 0; |
| 3375 | } |
| 3376 | |
| 3377 | megasas_issue_init_mfi(instance); |
| 3378 | |
| 3379 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3380 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 3381 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3382 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3383 | |
| 3384 | megasas_issue_pending_cmds_again(instance); |
| 3385 | instance->issuepend_done = 1; |
| 3386 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3390 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3391 | * @instance: Adapter soft state |
| 3392 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3393 | * SCSI mid-layer instead of the status |
| 3394 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3395 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3396 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3397 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3398 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3399 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3400 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3401 | u32 mfiStatus; |
| 3402 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3403 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3404 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3405 | instance->reg_set)) == 1) { |
| 3406 | return IRQ_HANDLED; |
| 3407 | } |
| 3408 | |
| 3409 | if ((mfiStatus = instance->instancet->clear_intr( |
| 3410 | instance->reg_set) |
| 3411 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3412 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3413 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3414 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | instance->mfiStatus = mfiStatus; |
| 3418 | |
| 3419 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3420 | fw_state = instance->instancet->read_fw_status_reg( |
| 3421 | instance->reg_set) & MFI_STATE_MASK; |
| 3422 | |
| 3423 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3424 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3425 | fw_state); |
| 3426 | } |
| 3427 | |
| 3428 | if ((fw_state == MFI_STATE_FAULT) && |
| 3429 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3430 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3431 | |
| 3432 | if ((instance->pdev->device == |
| 3433 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3434 | (instance->pdev->device == |
| 3435 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3436 | (instance->pdev->device == |
| 3437 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3438 | |
| 3439 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3440 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3444 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3445 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 3446 | instance->issuepend_done = 0; |
| 3447 | |
| 3448 | atomic_set(&instance->fw_outstanding, 0); |
| 3449 | megasas_internal_reset_defer_cmds(instance); |
| 3450 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3451 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3452 | fw_state, instance->adprecovery); |
| 3453 | |
| 3454 | schedule_work(&instance->work_init); |
| 3455 | return IRQ_HANDLED; |
| 3456 | |
| 3457 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3458 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3459 | fw_state, instance->disableOnlineCtrlReset); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3463 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3464 | return IRQ_HANDLED; |
| 3465 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3466 | /** |
| 3467 | * megasas_isr - isr entry point |
| 3468 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3469 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3470 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3471 | struct megasas_irq_context *irq_context = devp; |
| 3472 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3473 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3474 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3475 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3476 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3477 | return IRQ_HANDLED; |
| 3478 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3479 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3480 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3481 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3482 | |
| 3483 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | /** |
| 3487 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3488 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3489 | * |
| 3490 | * During the initialization, FW passes can potentially be in any one of |
| 3491 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3492 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3493 | * has to wait for the ready state. |
| 3494 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3495 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3496 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3497 | { |
| 3498 | int i; |
| 3499 | u8 max_wait; |
| 3500 | u32 fw_state; |
| 3501 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3502 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3503 | |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3504 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3505 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3506 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3507 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3508 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3509 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3510 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3511 | while (fw_state != MFI_STATE_READY) { |
| 3512 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3513 | switch (fw_state) { |
| 3514 | |
| 3515 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3516 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3517 | if (ocr) { |
| 3518 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3519 | cur_state = MFI_STATE_FAULT; |
| 3520 | break; |
| 3521 | } else |
| 3522 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3523 | |
| 3524 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3525 | /* |
| 3526 | * Set the CLR bit in inbound doorbell |
| 3527 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3528 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3529 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3530 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3531 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3532 | (instance->ctrl_context)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3533 | writel( |
| 3534 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3535 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3536 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3537 | writel( |
| 3538 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3539 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3540 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3541 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3542 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3543 | break; |
| 3544 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3545 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3546 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3547 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3548 | (instance->pdev->device == |
| 3549 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3550 | (instance->ctrl_context)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3551 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3552 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3553 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3554 | writel(MFI_INIT_HOTPLUG, |
| 3555 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3556 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3557 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3558 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3559 | break; |
| 3560 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3561 | case MFI_STATE_OPERATIONAL: |
| 3562 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3563 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3564 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3565 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3566 | if ((instance->pdev->device == |
| 3567 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3568 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3569 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3570 | (instance->ctrl_context)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3571 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3572 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3573 | |
| 3574 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3575 | for (i = 0; i < (10 * 1000); i += 20) { |
| 3576 | if (readl( |
| 3577 | &instance-> |
| 3578 | reg_set-> |
| 3579 | doorbell) & 1) |
| 3580 | msleep(20); |
| 3581 | else |
| 3582 | break; |
| 3583 | } |
| 3584 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3585 | } else |
| 3586 | writel(MFI_RESET_FLAGS, |
| 3587 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3588 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3589 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3590 | cur_state = MFI_STATE_OPERATIONAL; |
| 3591 | break; |
| 3592 | |
| 3593 | case MFI_STATE_UNDEFINED: |
| 3594 | /* |
| 3595 | * This state should not last for more than 2 seconds |
| 3596 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3597 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3598 | cur_state = MFI_STATE_UNDEFINED; |
| 3599 | break; |
| 3600 | |
| 3601 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3602 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3603 | cur_state = MFI_STATE_BB_INIT; |
| 3604 | break; |
| 3605 | |
| 3606 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3607 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3608 | cur_state = MFI_STATE_FW_INIT; |
| 3609 | break; |
| 3610 | |
| 3611 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3612 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3613 | cur_state = MFI_STATE_FW_INIT_2; |
| 3614 | break; |
| 3615 | |
| 3616 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3617 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3618 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3619 | break; |
| 3620 | |
| 3621 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3622 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3623 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3624 | break; |
| 3625 | |
| 3626 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3627 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3628 | fw_state); |
| 3629 | return -ENODEV; |
| 3630 | } |
| 3631 | |
| 3632 | /* |
| 3633 | * The cur_state should not last for more than max_wait secs |
| 3634 | */ |
| 3635 | for (i = 0; i < (max_wait * 1000); i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3636 | curr_abs_state = instance->instancet-> |
| 3637 | read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3638 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3639 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3640 | msleep(1); |
| 3641 | } else |
| 3642 | break; |
| 3643 | } |
| 3644 | |
| 3645 | /* |
| 3646 | * Return error if fw_state hasn't changed after max_wait |
| 3647 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3648 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3649 | 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] | 3650 | "in %d secs\n", fw_state, max_wait); |
| 3651 | return -ENODEV; |
| 3652 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3653 | |
| 3654 | abs_state = curr_abs_state; |
| 3655 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3656 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3657 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3658 | |
| 3659 | return 0; |
| 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3664 | * @instance: Adapter soft state |
| 3665 | */ |
| 3666 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3667 | { |
| 3668 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3669 | u32 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3670 | struct megasas_cmd *cmd; |
| 3671 | |
| 3672 | if (!instance->frame_dma_pool) |
| 3673 | return; |
| 3674 | |
| 3675 | /* |
| 3676 | * Return all frames to pool |
| 3677 | */ |
| 3678 | for (i = 0; i < max_cmd; i++) { |
| 3679 | |
| 3680 | cmd = instance->cmd_list[i]; |
| 3681 | |
| 3682 | if (cmd->frame) |
| 3683 | pci_pool_free(instance->frame_dma_pool, cmd->frame, |
| 3684 | cmd->frame_phys_addr); |
| 3685 | |
| 3686 | if (cmd->sense) |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3687 | pci_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3688 | cmd->sense_phys_addr); |
| 3689 | } |
| 3690 | |
| 3691 | /* |
| 3692 | * Now destroy the pool itself |
| 3693 | */ |
| 3694 | pci_pool_destroy(instance->frame_dma_pool); |
| 3695 | pci_pool_destroy(instance->sense_dma_pool); |
| 3696 | |
| 3697 | instance->frame_dma_pool = NULL; |
| 3698 | instance->sense_dma_pool = NULL; |
| 3699 | } |
| 3700 | |
| 3701 | /** |
| 3702 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3703 | * @instance: Adapter soft state |
| 3704 | * |
| 3705 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3706 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3707 | * function creates those DMA memory buffers for each command packet by using |
| 3708 | * PCI pool facility. |
| 3709 | */ |
| 3710 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3711 | { |
| 3712 | int i; |
| 3713 | u32 max_cmd; |
| 3714 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3715 | u32 total_sz; |
| 3716 | u32 frame_count; |
| 3717 | struct megasas_cmd *cmd; |
| 3718 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3719 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3720 | |
| 3721 | /* |
| 3722 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 3723 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 3724 | */ |
| 3725 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 3726 | sizeof(struct megasas_sge32); |
| 3727 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3728 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3729 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3730 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3731 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3732 | * For MFI controllers. |
| 3733 | * max_num_sge = 60 |
| 3734 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 3735 | * Total 960 byte (15 MFI frame of 64 byte) |
| 3736 | * |
| 3737 | * Fusion adapter require only 3 extra frame. |
| 3738 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 3739 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 3740 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3741 | */ |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3742 | frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3743 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; |
| 3744 | /* |
| 3745 | * Use DMA pool facility provided by PCI layer |
| 3746 | */ |
| 3747 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3748 | instance->pdev, total_sz, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3749 | |
| 3750 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3751 | 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] | 3752 | return -ENOMEM; |
| 3753 | } |
| 3754 | |
| 3755 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", |
| 3756 | instance->pdev, 128, 4, 0); |
| 3757 | |
| 3758 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3759 | 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] | 3760 | |
| 3761 | pci_pool_destroy(instance->frame_dma_pool); |
| 3762 | instance->frame_dma_pool = NULL; |
| 3763 | |
| 3764 | return -ENOMEM; |
| 3765 | } |
| 3766 | |
| 3767 | /* |
| 3768 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 3769 | * By making cmd->index as the context instead of the &cmd, we can |
| 3770 | * always use 32bit context regardless of the architecture |
| 3771 | */ |
| 3772 | for (i = 0; i < max_cmd; i++) { |
| 3773 | |
| 3774 | cmd = instance->cmd_list[i]; |
| 3775 | |
| 3776 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, |
| 3777 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 3778 | |
| 3779 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, |
| 3780 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 3781 | |
| 3782 | /* |
| 3783 | * megasas_teardown_frame_pool() takes care of freeing |
| 3784 | * whatever has been allocated |
| 3785 | */ |
| 3786 | if (!cmd->frame || !cmd->sense) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3787 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "pci_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3788 | megasas_teardown_frame_pool(instance); |
| 3789 | return -ENOMEM; |
| 3790 | } |
| 3791 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 3792 | memset(cmd->frame, 0, total_sz); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3793 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3794 | cmd->frame->io.pad_0 = 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3795 | if (!instance->ctrl_context && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3796 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | return 0; |
| 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 3804 | * @instance: Adapter soft state |
| 3805 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3806 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3807 | { |
| 3808 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3809 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3810 | /* First free the MFI frame pool */ |
| 3811 | megasas_teardown_frame_pool(instance); |
| 3812 | |
| 3813 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3814 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 3815 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3816 | kfree(instance->cmd_list[i]); |
| 3817 | |
| 3818 | /* Free the cmd_list buffer itself */ |
| 3819 | kfree(instance->cmd_list); |
| 3820 | instance->cmd_list = NULL; |
| 3821 | |
| 3822 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * megasas_alloc_cmds - Allocates the command packets |
| 3827 | * @instance: Adapter soft state |
| 3828 | * |
| 3829 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 3830 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 3831 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 3832 | * the FW. |
| 3833 | * |
| 3834 | * Each frame has a 32-bit field called context (tag). This context is used |
| 3835 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 3836 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 3837 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 3838 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 3839 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 3840 | * This array is used only to look up the megasas_cmd given the context. The |
| 3841 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 3842 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3843 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3844 | { |
| 3845 | int i; |
| 3846 | int j; |
| 3847 | u32 max_cmd; |
| 3848 | struct megasas_cmd *cmd; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3849 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3850 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3851 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3852 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3853 | |
| 3854 | /* |
| 3855 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 3856 | * Allocate the dynamic array first and then allocate individual |
| 3857 | * commands. |
| 3858 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 3859 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3860 | |
| 3861 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3862 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3863 | return -ENOMEM; |
| 3864 | } |
| 3865 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3866 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3867 | |
| 3868 | for (i = 0; i < max_cmd; i++) { |
| 3869 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 3870 | GFP_KERNEL); |
| 3871 | |
| 3872 | if (!instance->cmd_list[i]) { |
| 3873 | |
| 3874 | for (j = 0; j < i; j++) |
| 3875 | kfree(instance->cmd_list[j]); |
| 3876 | |
| 3877 | kfree(instance->cmd_list); |
| 3878 | instance->cmd_list = NULL; |
| 3879 | |
| 3880 | return -ENOMEM; |
| 3881 | } |
| 3882 | } |
| 3883 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3884 | for (i = 0; i < max_cmd; i++) { |
| 3885 | cmd = instance->cmd_list[i]; |
| 3886 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 3887 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3888 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3889 | cmd->instance = instance; |
| 3890 | |
| 3891 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 3892 | } |
| 3893 | |
| 3894 | /* |
| 3895 | * Create a frame pool and assign one frame to each cmd |
| 3896 | */ |
| 3897 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3898 | 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] | 3899 | megasas_free_cmds(instance); |
| 3900 | } |
| 3901 | |
| 3902 | return 0; |
| 3903 | } |
| 3904 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3905 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3906 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 3907 | * @instance: Adapter soft state |
| 3908 | * |
| 3909 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 3910 | * or FW is not under OCR. |
| 3911 | */ |
| 3912 | inline int |
| 3913 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 3914 | |
| 3915 | if (!instance->ctrl_context) |
| 3916 | return KILL_ADAPTER; |
| 3917 | else if (instance->unload || |
| 3918 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 3919 | return IGNORE_TIMEOUT; |
| 3920 | else |
| 3921 | return INITIATE_OCR; |
| 3922 | } |
| 3923 | |
| 3924 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3925 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 3926 | * @instance: Adapter soft state |
| 3927 | * @pd_list: pd_list structure |
| 3928 | * |
| 3929 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 3930 | * list structure. This information is mainly used to find out SYSTEM |
| 3931 | * supported by the FW. |
| 3932 | */ |
| 3933 | static int |
| 3934 | megasas_get_pd_list(struct megasas_instance *instance) |
| 3935 | { |
| 3936 | int ret = 0, pd_index = 0; |
| 3937 | struct megasas_cmd *cmd; |
| 3938 | struct megasas_dcmd_frame *dcmd; |
| 3939 | struct MR_PD_LIST *ci; |
| 3940 | struct MR_PD_ADDRESS *pd_addr; |
| 3941 | dma_addr_t ci_h = 0; |
| 3942 | |
| 3943 | cmd = megasas_get_cmd(instance); |
| 3944 | |
| 3945 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3946 | 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] | 3947 | return -ENOMEM; |
| 3948 | } |
| 3949 | |
| 3950 | dcmd = &cmd->frame->dcmd; |
| 3951 | |
| 3952 | ci = pci_alloc_consistent(instance->pdev, |
| 3953 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h); |
| 3954 | |
| 3955 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3956 | 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] | 3957 | megasas_return_cmd(instance, cmd); |
| 3958 | return -ENOMEM; |
| 3959 | } |
| 3960 | |
| 3961 | memset(ci, 0, sizeof(*ci)); |
| 3962 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3963 | |
| 3964 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 3965 | dcmd->mbox.b[1] = 0; |
| 3966 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3967 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3968 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3969 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3970 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 3971 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3972 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 3973 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
| 3974 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 3975 | 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] | 3976 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3977 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 3978 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3979 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3980 | else |
| 3981 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3982 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3983 | switch (ret) { |
| 3984 | case DCMD_FAILED: |
| 3985 | megaraid_sas_kill_hba(instance); |
| 3986 | break; |
| 3987 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3988 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3989 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 3990 | case INITIATE_OCR: |
| 3991 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 3992 | /* |
| 3993 | * DCMD failed from AEN path. |
| 3994 | * AEN path already hold reset_mutex to avoid PCI access |
| 3995 | * while OCR is in progress. |
| 3996 | */ |
| 3997 | mutex_unlock(&instance->reset_mutex); |
| 3998 | megasas_reset_fusion(instance->host, |
| 3999 | MFI_IO_TIMEOUT_OCR); |
| 4000 | mutex_lock(&instance->reset_mutex); |
| 4001 | break; |
| 4002 | case KILL_ADAPTER: |
| 4003 | megaraid_sas_kill_hba(instance); |
| 4004 | break; |
| 4005 | case IGNORE_TIMEOUT: |
| 4006 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4007 | __func__, __LINE__); |
| 4008 | break; |
| 4009 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4010 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4011 | break; |
| 4012 | |
| 4013 | case DCMD_SUCCESS: |
| 4014 | pd_addr = ci->addr; |
| 4015 | |
| 4016 | if ((le32_to_cpu(ci->count) > |
| 4017 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4018 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4019 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4020 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4021 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4022 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4023 | 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] | 4024 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4025 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4026 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4027 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4028 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4029 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4030 | pd_addr++; |
| 4031 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4032 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4033 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4034 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4035 | break; |
| 4036 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | pci_free_consistent(instance->pdev, |
| 4040 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 4041 | ci, ci_h); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4042 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4043 | if (ret != DCMD_TIMEOUT) |
| 4044 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4045 | |
| 4046 | return ret; |
| 4047 | } |
| 4048 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4049 | /* |
| 4050 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4051 | * @instance: Adapter soft state |
| 4052 | * @ld_list: ld_list structure |
| 4053 | * |
| 4054 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4055 | * list structure. This information is mainly used to find out SYSTEM |
| 4056 | * supported by the FW. |
| 4057 | */ |
| 4058 | static int |
| 4059 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4060 | { |
| 4061 | int ret = 0, ld_index = 0, ids = 0; |
| 4062 | struct megasas_cmd *cmd; |
| 4063 | struct megasas_dcmd_frame *dcmd; |
| 4064 | struct MR_LD_LIST *ci; |
| 4065 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4066 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4067 | |
| 4068 | cmd = megasas_get_cmd(instance); |
| 4069 | |
| 4070 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4071 | 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] | 4072 | return -ENOMEM; |
| 4073 | } |
| 4074 | |
| 4075 | dcmd = &cmd->frame->dcmd; |
| 4076 | |
| 4077 | ci = pci_alloc_consistent(instance->pdev, |
| 4078 | sizeof(struct MR_LD_LIST), |
| 4079 | &ci_h); |
| 4080 | |
| 4081 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4082 | 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] | 4083 | megasas_return_cmd(instance, cmd); |
| 4084 | return -ENOMEM; |
| 4085 | } |
| 4086 | |
| 4087 | memset(ci, 0, sizeof(*ci)); |
| 4088 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4089 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4090 | if (instance->supportmax256vd) |
| 4091 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4092 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4093 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4094 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4095 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4096 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4097 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4098 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
| 4099 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4100 | 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] | 4101 | dcmd->pad_0 = 0; |
| 4102 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4103 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4104 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4105 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4106 | else |
| 4107 | ret = megasas_issue_polled(instance, cmd); |
| 4108 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4109 | ld_count = le32_to_cpu(ci->ldCount); |
| 4110 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4111 | switch (ret) { |
| 4112 | case DCMD_FAILED: |
| 4113 | megaraid_sas_kill_hba(instance); |
| 4114 | break; |
| 4115 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4116 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4117 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4118 | case INITIATE_OCR: |
| 4119 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4120 | /* |
| 4121 | * DCMD failed from AEN path. |
| 4122 | * AEN path already hold reset_mutex to avoid PCI access |
| 4123 | * while OCR is in progress. |
| 4124 | */ |
| 4125 | mutex_unlock(&instance->reset_mutex); |
| 4126 | megasas_reset_fusion(instance->host, |
| 4127 | MFI_IO_TIMEOUT_OCR); |
| 4128 | mutex_lock(&instance->reset_mutex); |
| 4129 | break; |
| 4130 | case KILL_ADAPTER: |
| 4131 | megaraid_sas_kill_hba(instance); |
| 4132 | break; |
| 4133 | case IGNORE_TIMEOUT: |
| 4134 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4135 | __func__, __LINE__); |
| 4136 | break; |
| 4137 | } |
| 4138 | |
| 4139 | break; |
| 4140 | |
| 4141 | case DCMD_SUCCESS: |
| 4142 | if (ld_count > instance->fw_supported_vd_count) |
| 4143 | break; |
| 4144 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4145 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4146 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4147 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4148 | if (ci->ldList[ld_index].state != 0) { |
| 4149 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4150 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4151 | } |
| 4152 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4153 | |
| 4154 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4157 | 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] | 4158 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4159 | if (ret != DCMD_TIMEOUT) |
| 4160 | megasas_return_cmd(instance, cmd); |
| 4161 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4162 | return ret; |
| 4163 | } |
| 4164 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4165 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4166 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4167 | * @instance: Adapter soft state |
| 4168 | * @ld_list: ld_list structure |
| 4169 | * |
| 4170 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4171 | * list structure. This information is mainly used to find out SYSTEM |
| 4172 | * supported by the FW. |
| 4173 | */ |
| 4174 | static int |
| 4175 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4176 | { |
| 4177 | int ret = 0, ld_index = 0, ids = 0; |
| 4178 | struct megasas_cmd *cmd; |
| 4179 | struct megasas_dcmd_frame *dcmd; |
| 4180 | struct MR_LD_TARGETID_LIST *ci; |
| 4181 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4182 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4183 | |
| 4184 | cmd = megasas_get_cmd(instance); |
| 4185 | |
| 4186 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4187 | dev_warn(&instance->pdev->dev, |
| 4188 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4189 | return -ENOMEM; |
| 4190 | } |
| 4191 | |
| 4192 | dcmd = &cmd->frame->dcmd; |
| 4193 | |
| 4194 | ci = pci_alloc_consistent(instance->pdev, |
| 4195 | sizeof(struct MR_LD_TARGETID_LIST), &ci_h); |
| 4196 | |
| 4197 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4198 | dev_warn(&instance->pdev->dev, |
| 4199 | "Failed to alloc mem for ld_list_query\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4200 | megasas_return_cmd(instance, cmd); |
| 4201 | return -ENOMEM; |
| 4202 | } |
| 4203 | |
| 4204 | memset(ci, 0, sizeof(*ci)); |
| 4205 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4206 | |
| 4207 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4208 | if (instance->supportmax256vd) |
| 4209 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4210 | |
| 4211 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4212 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4213 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4214 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4215 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4216 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4217 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
| 4218 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4219 | 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] | 4220 | dcmd->pad_0 = 0; |
| 4221 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4222 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4223 | 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] | 4224 | else |
| 4225 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4226 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4227 | switch (ret) { |
| 4228 | case DCMD_FAILED: |
| 4229 | dev_info(&instance->pdev->dev, |
| 4230 | "DCMD not supported by firmware - %s %d\n", |
| 4231 | __func__, __LINE__); |
| 4232 | ret = megasas_get_ld_list(instance); |
| 4233 | break; |
| 4234 | case DCMD_TIMEOUT: |
| 4235 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4236 | case INITIATE_OCR: |
| 4237 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4238 | /* |
| 4239 | * DCMD failed from AEN path. |
| 4240 | * AEN path already hold reset_mutex to avoid PCI access |
| 4241 | * while OCR is in progress. |
| 4242 | */ |
| 4243 | mutex_unlock(&instance->reset_mutex); |
| 4244 | megasas_reset_fusion(instance->host, |
| 4245 | MFI_IO_TIMEOUT_OCR); |
| 4246 | mutex_lock(&instance->reset_mutex); |
| 4247 | break; |
| 4248 | case KILL_ADAPTER: |
| 4249 | megaraid_sas_kill_hba(instance); |
| 4250 | break; |
| 4251 | case IGNORE_TIMEOUT: |
| 4252 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4253 | __func__, __LINE__); |
| 4254 | break; |
| 4255 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4256 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4257 | break; |
| 4258 | case DCMD_SUCCESS: |
| 4259 | tgtid_count = le32_to_cpu(ci->count); |
| 4260 | |
| 4261 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4262 | break; |
| 4263 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4264 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4265 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4266 | ids = ci->targetId[ld_index]; |
| 4267 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4268 | } |
| 4269 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4270 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_TARGETID_LIST), |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4274 | ci, ci_h); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4275 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4276 | if (ret != DCMD_TIMEOUT) |
| 4277 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4278 | |
| 4279 | return ret; |
| 4280 | } |
| 4281 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4282 | /* |
| 4283 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4284 | * instance : Controller's instance |
| 4285 | */ |
| 4286 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4287 | { |
| 4288 | struct fusion_context *fusion; |
| 4289 | u32 old_map_sz; |
| 4290 | u32 new_map_sz; |
| 4291 | |
| 4292 | fusion = instance->ctrl_context; |
| 4293 | /* For MFI based controllers return dummy success */ |
| 4294 | if (!fusion) |
| 4295 | return; |
| 4296 | |
| 4297 | instance->supportmax256vd = |
| 4298 | instance->ctrl_info->adapterOperations3.supportMaxExtLDs; |
| 4299 | /* Below is additional check to address future FW enhancement */ |
| 4300 | if (instance->ctrl_info->max_lds > 64) |
| 4301 | instance->supportmax256vd = 1; |
| 4302 | |
| 4303 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4304 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4305 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4306 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4307 | if (instance->supportmax256vd) { |
| 4308 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4309 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4310 | } else { |
| 4311 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4312 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4313 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4314 | |
| 4315 | dev_info(&instance->pdev->dev, |
| 4316 | "firmware type\t: %s\n", |
| 4317 | instance->supportmax256vd ? "Extended VD(240 VD)firmware" : |
| 4318 | "Legacy(64 VD) firmware"); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4319 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4320 | old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4321 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4322 | (instance->fw_supported_vd_count - 1)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4323 | new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT); |
| 4324 | fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) + |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4325 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4326 | (instance->drv_supported_vd_count - 1)); |
| 4327 | |
| 4328 | fusion->max_map_sz = max(old_map_sz, new_map_sz); |
| 4329 | |
| 4330 | |
| 4331 | if (instance->supportmax256vd) |
| 4332 | fusion->current_map_sz = new_map_sz; |
| 4333 | else |
| 4334 | fusion->current_map_sz = old_map_sz; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4335 | } |
| 4336 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4337 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4338 | * megasas_get_controller_info - Returns FW's controller structure |
| 4339 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4340 | * |
| 4341 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4342 | * This information is mainly used to find out the maximum IO transfer per |
| 4343 | * command supported by the FW. |
| 4344 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4345 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4346 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4347 | { |
| 4348 | int ret = 0; |
| 4349 | struct megasas_cmd *cmd; |
| 4350 | struct megasas_dcmd_frame *dcmd; |
| 4351 | struct megasas_ctrl_info *ci; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4352 | struct megasas_ctrl_info *ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4353 | dma_addr_t ci_h = 0; |
| 4354 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4355 | ctrl_info = instance->ctrl_info; |
| 4356 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4357 | cmd = megasas_get_cmd(instance); |
| 4358 | |
| 4359 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4360 | 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] | 4361 | return -ENOMEM; |
| 4362 | } |
| 4363 | |
| 4364 | dcmd = &cmd->frame->dcmd; |
| 4365 | |
| 4366 | ci = pci_alloc_consistent(instance->pdev, |
| 4367 | sizeof(struct megasas_ctrl_info), &ci_h); |
| 4368 | |
| 4369 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4370 | 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] | 4371 | megasas_return_cmd(instance, cmd); |
| 4372 | return -ENOMEM; |
| 4373 | } |
| 4374 | |
| 4375 | memset(ci, 0, sizeof(*ci)); |
| 4376 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4377 | |
| 4378 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4379 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4380 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4381 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4382 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4383 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4384 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4385 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
| 4386 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4387 | 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] | 4388 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4389 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4390 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4391 | 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] | 4392 | else |
| 4393 | ret = megasas_issue_polled(instance, cmd); |
| 4394 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4395 | switch (ret) { |
| 4396 | case DCMD_SUCCESS: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4397 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4398 | /* Save required controller information in |
| 4399 | * CPU endianness format. |
| 4400 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4401 | le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties); |
| 4402 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations2); |
| 4403 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations3); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4404 | |
| 4405 | /* Update the latest Ext VD info. |
| 4406 | * From Init path, store current firmware details. |
| 4407 | * From OCR path, detect any firmware properties changes. |
| 4408 | * in case of Firmware upgrade without system reboot. |
| 4409 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4410 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4411 | instance->use_seqnum_jbod_fp = |
| 4412 | ctrl_info->adapterOperations3.useSeqNumJbodFP; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4413 | |
| 4414 | /*Check whether controller is iMR or MR */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4415 | instance->is_imr = (ctrl_info->memory_size ? 0 : 1); |
| 4416 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4417 | "controller type\t: %s(%dMB)\n", |
| 4418 | instance->is_imr ? "iMR" : "MR", |
| 4419 | le16_to_cpu(ctrl_info->memory_size)); |
| 4420 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 4421 | instance->disableOnlineCtrlReset = |
| 4422 | ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4423 | instance->secure_jbod_support = |
| 4424 | ctrl_info->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4425 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 4426 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4427 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 4428 | instance->secure_jbod_support ? "Yes" : "No"); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4429 | break; |
| 4430 | |
| 4431 | case DCMD_TIMEOUT: |
| 4432 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4433 | case INITIATE_OCR: |
| 4434 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4435 | megasas_reset_fusion(instance->host, |
| 4436 | MFI_IO_TIMEOUT_OCR); |
| 4437 | break; |
| 4438 | case KILL_ADAPTER: |
| 4439 | megaraid_sas_kill_hba(instance); |
| 4440 | break; |
| 4441 | case IGNORE_TIMEOUT: |
| 4442 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4443 | __func__, __LINE__); |
| 4444 | break; |
| 4445 | } |
| 4446 | case DCMD_FAILED: |
| 4447 | megaraid_sas_kill_hba(instance); |
| 4448 | break; |
| 4449 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4450 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4451 | |
| 4452 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), |
| 4453 | ci, ci_h); |
| 4454 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4455 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4456 | |
| 4457 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4458 | return ret; |
| 4459 | } |
| 4460 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4461 | /* |
| 4462 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 4463 | * to firmware |
| 4464 | * |
| 4465 | * @instance: Adapter soft state |
| 4466 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 4467 | MR_CRASH_BUF_TURN_OFF = 0 |
| 4468 | MR_CRASH_BUF_TURN_ON = 1 |
| 4469 | * @return 0 on success non-zero on failure. |
| 4470 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 4471 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 4472 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 4473 | * crash dump feature is supported by the FW. |
| 4474 | * |
| 4475 | */ |
| 4476 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 4477 | u8 crash_buf_state) |
| 4478 | { |
| 4479 | int ret = 0; |
| 4480 | struct megasas_cmd *cmd; |
| 4481 | struct megasas_dcmd_frame *dcmd; |
| 4482 | |
| 4483 | cmd = megasas_get_cmd(instance); |
| 4484 | |
| 4485 | if (!cmd) { |
| 4486 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4487 | return -ENOMEM; |
| 4488 | } |
| 4489 | |
| 4490 | |
| 4491 | dcmd = &cmd->frame->dcmd; |
| 4492 | |
| 4493 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4494 | dcmd->mbox.b[0] = crash_buf_state; |
| 4495 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4496 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4497 | dcmd->sge_count = 1; |
| 4498 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
| 4499 | dcmd->timeout = 0; |
| 4500 | dcmd->pad_0 = 0; |
| 4501 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4502 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
| 4503 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h); |
| 4504 | dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4505 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4506 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4507 | 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] | 4508 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4509 | ret = megasas_issue_polled(instance, cmd); |
| 4510 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4511 | if (ret == DCMD_TIMEOUT) { |
| 4512 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4513 | case INITIATE_OCR: |
| 4514 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4515 | megasas_reset_fusion(instance->host, |
| 4516 | MFI_IO_TIMEOUT_OCR); |
| 4517 | break; |
| 4518 | case KILL_ADAPTER: |
| 4519 | megaraid_sas_kill_hba(instance); |
| 4520 | break; |
| 4521 | case IGNORE_TIMEOUT: |
| 4522 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4523 | __func__, __LINE__); |
| 4524 | break; |
| 4525 | } |
| 4526 | } else |
| 4527 | megasas_return_cmd(instance, cmd); |
| 4528 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4529 | return ret; |
| 4530 | } |
| 4531 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4532 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4533 | * megasas_issue_init_mfi - Initializes the FW |
| 4534 | * @instance: Adapter soft state |
| 4535 | * |
| 4536 | * Issues the INIT MFI cmd |
| 4537 | */ |
| 4538 | static int |
| 4539 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 4540 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 4541 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4542 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4543 | struct megasas_init_frame *init_frame; |
| 4544 | struct megasas_init_queue_info *initq_info; |
| 4545 | dma_addr_t init_frame_h; |
| 4546 | dma_addr_t initq_info_h; |
| 4547 | |
| 4548 | /* |
| 4549 | * Prepare a init frame. Note the init frame points to queue info |
| 4550 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 4551 | * this frame - since we don't need any SGL - we use SGL's space as |
| 4552 | * queue info structure |
| 4553 | * |
| 4554 | * We will not get a NULL command below. We just created the pool. |
| 4555 | */ |
| 4556 | cmd = megasas_get_cmd(instance); |
| 4557 | |
| 4558 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 4559 | initq_info = (struct megasas_init_queue_info *) |
| 4560 | ((unsigned long)init_frame + 64); |
| 4561 | |
| 4562 | init_frame_h = cmd->frame_phys_addr; |
| 4563 | initq_info_h = init_frame_h + 64; |
| 4564 | |
| 4565 | context = init_frame->context; |
| 4566 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 4567 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 4568 | init_frame->context = context; |
| 4569 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4570 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 4571 | 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] | 4572 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4573 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 4574 | 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] | 4575 | |
| 4576 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4577 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4578 | init_frame->queue_info_new_phys_addr_lo = |
| 4579 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 4580 | init_frame->queue_info_new_phys_addr_hi = |
| 4581 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4582 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4583 | 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] | 4584 | |
| 4585 | /* |
| 4586 | * disable the intr before firing the init frame to FW |
| 4587 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4588 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4589 | |
| 4590 | /* |
| 4591 | * Issue the init frame in polled mode |
| 4592 | */ |
| 4593 | |
| 4594 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4595 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4596 | megasas_return_cmd(instance, cmd); |
| 4597 | goto fail_fw_init; |
| 4598 | } |
| 4599 | |
| 4600 | megasas_return_cmd(instance, cmd); |
| 4601 | |
| 4602 | return 0; |
| 4603 | |
| 4604 | fail_fw_init: |
| 4605 | return -EINVAL; |
| 4606 | } |
| 4607 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4608 | static u32 |
| 4609 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4610 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4611 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4612 | u32 context_sz; |
| 4613 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4614 | |
| 4615 | reg_set = instance->reg_set; |
| 4616 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4617 | /* |
| 4618 | * Get various operational parameters from status register |
| 4619 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4620 | 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] | 4621 | /* |
| 4622 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 4623 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 4624 | * does not exceed max cmds that the FW can support |
| 4625 | */ |
| 4626 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4627 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4628 | 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] | 4629 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4630 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4631 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 4632 | * are reserved for IOCTL + driver's internal DCMDs. |
| 4633 | */ |
| 4634 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 4635 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 4636 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4637 | MEGASAS_SKINNY_INT_CMDS); |
| 4638 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 4639 | } else { |
| 4640 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4641 | MEGASAS_INT_CMDS); |
| 4642 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 4643 | } |
| 4644 | |
| 4645 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4646 | * Create a pool of commands |
| 4647 | */ |
| 4648 | if (megasas_alloc_cmds(instance)) |
| 4649 | goto fail_alloc_cmds; |
| 4650 | |
| 4651 | /* |
| 4652 | * Allocate memory for reply queue. Length of reply queue should |
| 4653 | * be _one_ more than the maximum commands handled by the firmware. |
| 4654 | * |
| 4655 | * Note: When FW completes commands, it places corresponding contex |
| 4656 | * values in this circular reply queue. This circular queue is a fairly |
| 4657 | * typical producer-consumer queue. FW is the producer (of completed |
| 4658 | * commands) and the driver is the consumer. |
| 4659 | */ |
| 4660 | context_sz = sizeof(u32); |
| 4661 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 4662 | |
| 4663 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 4664 | reply_q_sz, |
| 4665 | &instance->reply_queue_h); |
| 4666 | |
| 4667 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4668 | 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] | 4669 | goto fail_reply_queue; |
| 4670 | } |
| 4671 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4672 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4673 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4674 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4675 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4676 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 4677 | "Fail from %s %d\n", instance->unique_id, |
| 4678 | __func__, __LINE__); |
| 4679 | goto fail_fw_init; |
| 4680 | } |
| 4681 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4682 | instance->fw_support_ieee = 0; |
| 4683 | instance->fw_support_ieee = |
| 4684 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 4685 | 0x04000000); |
| 4686 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4687 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4688 | instance->fw_support_ieee); |
| 4689 | |
| 4690 | if (instance->fw_support_ieee) |
| 4691 | instance->flag_ieee = 1; |
| 4692 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4693 | return 0; |
| 4694 | |
| 4695 | fail_fw_init: |
| 4696 | |
| 4697 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 4698 | instance->reply_queue, instance->reply_queue_h); |
| 4699 | fail_reply_queue: |
| 4700 | megasas_free_cmds(instance); |
| 4701 | |
| 4702 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4703 | return 1; |
| 4704 | } |
| 4705 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4706 | /* |
| 4707 | * megasas_setup_irqs_msix - register legacy interrupts. |
| 4708 | * @instance: Adapter soft state |
| 4709 | * |
| 4710 | * Do not enable interrupt, only setup ISRs. |
| 4711 | * |
| 4712 | * Return 0 on success. |
| 4713 | */ |
| 4714 | static int |
| 4715 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 4716 | { |
| 4717 | struct pci_dev *pdev; |
| 4718 | |
| 4719 | pdev = instance->pdev; |
| 4720 | instance->irq_context[0].instance = instance; |
| 4721 | instance->irq_context[0].MSIxIndex = 0; |
| 4722 | if (request_irq(pdev->irq, instance->instancet->service_isr, |
| 4723 | IRQF_SHARED, "megasas", &instance->irq_context[0])) { |
| 4724 | dev_err(&instance->pdev->dev, |
| 4725 | "Failed to register IRQ from %s %d\n", |
| 4726 | __func__, __LINE__); |
| 4727 | return -1; |
| 4728 | } |
| 4729 | return 0; |
| 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 4734 | * @instance: Adapter soft state |
| 4735 | * @is_probe: Driver probe check |
| 4736 | * |
| 4737 | * Do not enable interrupt, only setup ISRs. |
| 4738 | * |
| 4739 | * Return 0 on success. |
| 4740 | */ |
| 4741 | static int |
| 4742 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 4743 | { |
| 4744 | int i, j, cpu; |
| 4745 | struct pci_dev *pdev; |
| 4746 | |
| 4747 | pdev = instance->pdev; |
| 4748 | |
| 4749 | /* Try MSI-x */ |
| 4750 | cpu = cpumask_first(cpu_online_mask); |
| 4751 | for (i = 0; i < instance->msix_vectors; i++) { |
| 4752 | instance->irq_context[i].instance = instance; |
| 4753 | instance->irq_context[i].MSIxIndex = i; |
| 4754 | if (request_irq(instance->msixentry[i].vector, |
| 4755 | instance->instancet->service_isr, 0, "megasas", |
| 4756 | &instance->irq_context[i])) { |
| 4757 | dev_err(&instance->pdev->dev, |
| 4758 | "Failed to register IRQ for vector %d.\n", i); |
| 4759 | for (j = 0; j < i; j++) { |
| 4760 | if (smp_affinity_enable) |
| 4761 | irq_set_affinity_hint( |
| 4762 | instance->msixentry[j].vector, NULL); |
| 4763 | free_irq(instance->msixentry[j].vector, |
| 4764 | &instance->irq_context[j]); |
| 4765 | } |
| 4766 | /* Retry irq register for IO_APIC*/ |
| 4767 | instance->msix_vectors = 0; |
| 4768 | if (is_probe) |
| 4769 | return megasas_setup_irqs_ioapic(instance); |
| 4770 | else |
| 4771 | return -1; |
| 4772 | } |
| 4773 | if (smp_affinity_enable) { |
| 4774 | if (irq_set_affinity_hint(instance->msixentry[i].vector, |
| 4775 | get_cpu_mask(cpu))) |
| 4776 | dev_err(&instance->pdev->dev, |
| 4777 | "Failed to set affinity hint" |
| 4778 | " for cpu %d\n", cpu); |
| 4779 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 4780 | } |
| 4781 | } |
| 4782 | return 0; |
| 4783 | } |
| 4784 | |
| 4785 | /* |
| 4786 | * megasas_destroy_irqs- unregister interrupts. |
| 4787 | * @instance: Adapter soft state |
| 4788 | * return: void |
| 4789 | */ |
| 4790 | static void |
| 4791 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 4792 | |
| 4793 | int i; |
| 4794 | |
| 4795 | if (instance->msix_vectors) |
| 4796 | for (i = 0; i < instance->msix_vectors; i++) { |
| 4797 | if (smp_affinity_enable) |
| 4798 | irq_set_affinity_hint( |
| 4799 | instance->msixentry[i].vector, NULL); |
| 4800 | free_irq(instance->msixentry[i].vector, |
| 4801 | &instance->irq_context[i]); |
| 4802 | } |
| 4803 | else |
| 4804 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 4805 | } |
| 4806 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4807 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4808 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 4809 | * @instance: Adapter soft state |
| 4810 | * @is_probe: Driver probe check |
| 4811 | * |
| 4812 | * Return 0 on success. |
| 4813 | */ |
| 4814 | void |
| 4815 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 4816 | { |
| 4817 | int i; |
| 4818 | struct fusion_context *fusion = instance->ctrl_context; |
| 4819 | u32 pd_seq_map_sz; |
| 4820 | |
| 4821 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 4822 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 4823 | |
| 4824 | if (reset_devices || !fusion || |
| 4825 | !instance->ctrl_info->adapterOperations3.useSeqNumJbodFP) { |
| 4826 | dev_info(&instance->pdev->dev, |
| 4827 | "Jbod map is not supported %s %d\n", |
| 4828 | __func__, __LINE__); |
| 4829 | instance->use_seqnum_jbod_fp = false; |
| 4830 | return; |
| 4831 | } |
| 4832 | |
| 4833 | if (fusion->pd_seq_sync[0]) |
| 4834 | goto skip_alloc; |
| 4835 | |
| 4836 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 4837 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 4838 | (&instance->pdev->dev, pd_seq_map_sz, |
| 4839 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 4840 | if (!fusion->pd_seq_sync[i]) { |
| 4841 | dev_err(&instance->pdev->dev, |
| 4842 | "Failed to allocate memory from %s %d\n", |
| 4843 | __func__, __LINE__); |
| 4844 | if (i == 1) { |
| 4845 | dma_free_coherent(&instance->pdev->dev, |
| 4846 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 4847 | fusion->pd_seq_phys[0]); |
| 4848 | fusion->pd_seq_sync[0] = NULL; |
| 4849 | } |
| 4850 | instance->use_seqnum_jbod_fp = false; |
| 4851 | return; |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | skip_alloc: |
| 4856 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 4857 | !megasas_sync_pd_seq_num(instance, true)) |
| 4858 | instance->use_seqnum_jbod_fp = true; |
| 4859 | else |
| 4860 | instance->use_seqnum_jbod_fp = false; |
| 4861 | } |
| 4862 | |
| 4863 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4864 | * megasas_init_fw - Initializes the FW |
| 4865 | * @instance: Adapter soft state |
| 4866 | * |
| 4867 | * This is the main function for initializing firmware |
| 4868 | */ |
| 4869 | |
| 4870 | static int megasas_init_fw(struct megasas_instance *instance) |
| 4871 | { |
| 4872 | u32 max_sectors_1; |
| 4873 | u32 max_sectors_2; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4874 | u32 tmp_sectors, msix_enable, scratch_pad_2; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 4875 | resource_size_t base_addr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4876 | struct megasas_register_set __iomem *reg_set; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4877 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4878 | unsigned long bar_list; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4879 | int i, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4880 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 4881 | struct fusion_context *fusion; |
| 4882 | |
| 4883 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4884 | |
| 4885 | /* Find first memory bar */ |
| 4886 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
| 4887 | instance->bar = find_first_bit(&bar_list, sizeof(unsigned long)); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4888 | if (pci_request_selected_regions(instance->pdev, instance->bar, |
| 4889 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4890 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4891 | return -EBUSY; |
| 4892 | } |
| 4893 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 4894 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 4895 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4896 | |
| 4897 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4898 | 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] | 4899 | goto fail_ioremap; |
| 4900 | } |
| 4901 | |
| 4902 | reg_set = instance->reg_set; |
| 4903 | |
| 4904 | switch (instance->pdev->device) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4905 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4906 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4907 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4908 | case PCI_DEVICE_ID_LSI_FURY: |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 4909 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 4910 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 4911 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 4912 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4913 | instance->instancet = &megasas_instance_template_fusion; |
| 4914 | break; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4915 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 4916 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 4917 | instance->instancet = &megasas_instance_template_ppc; |
| 4918 | break; |
| 4919 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 4920 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 4921 | instance->instancet = &megasas_instance_template_gen2; |
| 4922 | break; |
| 4923 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 4924 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 4925 | instance->instancet = &megasas_instance_template_skinny; |
| 4926 | break; |
| 4927 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 4928 | case PCI_DEVICE_ID_DELL_PERC5: |
| 4929 | default: |
| 4930 | instance->instancet = &megasas_instance_template_xscale; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 4931 | instance->allow_fw_scan = 1; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4932 | break; |
| 4933 | } |
| 4934 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 4935 | if (megasas_transition_to_ready(instance, 0)) { |
| 4936 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 4937 | instance->instancet->adp_reset |
| 4938 | (instance, instance->reg_set); |
| 4939 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 4940 | dev_info(&instance->pdev->dev, |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4941 | "FW restarted successfully from %s!\n", |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 4942 | __func__); |
| 4943 | |
| 4944 | /*waitting for about 30 second before retry*/ |
| 4945 | ssleep(30); |
| 4946 | |
| 4947 | if (megasas_transition_to_ready(instance, 0)) |
| 4948 | goto fail_ready_state; |
| 4949 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4950 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4951 | /* |
| 4952 | * MSI-X host index 0 is common for all adapter. |
| 4953 | * It is used for all MPT based Adapters. |
| 4954 | */ |
| 4955 | instance->reply_post_host_index_addr[0] = |
Christoph Hellwig | 8a232bb | 2015-04-23 16:32:39 +0530 | [diff] [blame] | 4956 | (u32 __iomem *)((u8 __iomem *)instance->reg_set + |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4957 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 4958 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 4959 | /* Check if MSI-X is supported while in ready state */ |
| 4960 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 4961 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4962 | if (msix_enable && !msix_disable) { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4963 | scratch_pad_2 = readl |
| 4964 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4965 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 4966 | if (fusion) { |
| 4967 | if (fusion->adapter_type == THUNDERBOLT_SERIES) { /* Thunderbolt Series*/ |
| 4968 | instance->msix_vectors = (scratch_pad_2 |
| 4969 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 4970 | fw_msix_count = instance->msix_vectors; |
| 4971 | } else { /* Invader series supports more than 8 MSI-x vectors*/ |
| 4972 | instance->msix_vectors = ((scratch_pad_2 |
| 4973 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 4974 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
| 4975 | fw_msix_count = instance->msix_vectors; |
| 4976 | /* Save 1-15 reply post index address to local memory |
| 4977 | * Index 0 is already saved from reg offset |
| 4978 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 4979 | */ |
| 4980 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 4981 | instance->reply_post_host_index_addr[loop] = |
| 4982 | (u32 __iomem *) |
| 4983 | ((u8 __iomem *)instance->reg_set + |
| 4984 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 4985 | + (loop * 0x10)); |
| 4986 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4987 | } |
| 4988 | if (msix_vectors) |
| 4989 | instance->msix_vectors = min(msix_vectors, |
| 4990 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 4991 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4992 | instance->msix_vectors = 1; |
| 4993 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 4994 | instance->msix_vectors = min(instance->msix_vectors, |
| 4995 | (unsigned int)num_online_cpus()); |
| 4996 | for (i = 0; i < instance->msix_vectors; i++) |
| 4997 | instance->msixentry[i].entry = i; |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 4998 | i = pci_enable_msix_range(instance->pdev, instance->msixentry, |
| 4999 | 1, instance->msix_vectors); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 5000 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5001 | instance->msix_vectors = i; |
| 5002 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5003 | instance->msix_vectors = 0; |
| 5004 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5005 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5006 | dev_info(&instance->pdev->dev, |
| 5007 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5008 | dev_info(&instance->pdev->dev, |
| 5009 | "current msix/online cpus\t: (%d/%d)\n", |
| 5010 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
| 5011 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5012 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5013 | (unsigned long)instance); |
| 5014 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5015 | if (instance->msix_vectors ? |
| 5016 | megasas_setup_irqs_msix(instance, 1) : |
| 5017 | megasas_setup_irqs_ioapic(instance)) |
| 5018 | goto fail_setup_irqs; |
| 5019 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5020 | instance->ctrl_info = kzalloc(sizeof(struct megasas_ctrl_info), |
| 5021 | GFP_KERNEL); |
| 5022 | if (instance->ctrl_info == NULL) |
| 5023 | goto fail_init_adapter; |
| 5024 | |
| 5025 | /* |
| 5026 | * Below are default value for legacy Firmware. |
| 5027 | * non-fusion based controllers |
| 5028 | */ |
| 5029 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5030 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5031 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5032 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5033 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5034 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5035 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5036 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5037 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5038 | dev_err(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5039 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5040 | megasas_setup_jbod_map(instance); |
| 5041 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5042 | /** for passthrough |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5043 | * the following function will get the PD LIST. |
| 5044 | */ |
| 5045 | memset(instance->pd_list, 0, |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5046 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5047 | if (megasas_get_pd_list(instance) < 0) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5048 | 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] | 5049 | goto fail_get_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5050 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5051 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5052 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5053 | if (megasas_ld_list_query(instance, |
| 5054 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 5055 | megasas_get_ld_list(instance); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5056 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5057 | /* |
| 5058 | * Compute the max allowed sectors per IO: The controller info has two |
| 5059 | * limits on max sectors. Driver should use the minimum of these two. |
| 5060 | * |
| 5061 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5062 | * |
| 5063 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5064 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5065 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5066 | tmp_sectors = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5067 | ctrl_info = instance->ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5068 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5069 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5070 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5071 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5072 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5073 | 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] | 5074 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5075 | instance->mpio = ctrl_info->adapterOperations2.mpio; |
| 5076 | instance->UnevenSpanSupport = |
| 5077 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5078 | if (instance->UnevenSpanSupport) { |
| 5079 | struct fusion_context *fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5080 | if (MR_ValidateMapInfo(instance)) |
| 5081 | fusion->fast_path_io = 1; |
| 5082 | else |
| 5083 | fusion->fast_path_io = 0; |
| 5084 | |
| 5085 | } |
| 5086 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5087 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5088 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5089 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5090 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5091 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5092 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5093 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5094 | |
| 5095 | if (instance->PlasmaFW111) { |
| 5096 | iovPtr = (struct IOV_111 *) |
| 5097 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5098 | instance->requestorId = iovPtr->requestorId; |
| 5099 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5100 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5101 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5102 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5103 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5104 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5105 | instance->crash_dump_fw_support = |
| 5106 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5107 | instance->crash_dump_drv_support = |
| 5108 | (instance->crash_dump_fw_support && |
| 5109 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5110 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5111 | megasas_set_crash_dump_params(instance, |
| 5112 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5113 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5114 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5115 | if (instance->crash_dump_buf) |
| 5116 | pci_free_consistent(instance->pdev, |
| 5117 | CRASH_DMA_BUF_SIZE, |
| 5118 | instance->crash_dump_buf, |
| 5119 | instance->crash_dump_h); |
| 5120 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5121 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5122 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5123 | |
| 5124 | dev_info(&instance->pdev->dev, |
| 5125 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5126 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5127 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5128 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5129 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5130 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 5131 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5132 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 5133 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5134 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 5135 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5136 | |
| 5137 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5138 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 5139 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5140 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 5141 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5142 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5143 | /* Check for valid throttlequeuedepth module parameter */ |
| 5144 | if (throttlequeuedepth && |
| 5145 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 5146 | instance->throttlequeuedepth = throttlequeuedepth; |
| 5147 | else |
| 5148 | instance->throttlequeuedepth = |
| 5149 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 5150 | |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5151 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5152 | /* Launch SR-IOV heartbeat timer */ |
| 5153 | if (instance->requestorId) { |
| 5154 | if (!megasas_sriov_start_heartbeat(instance, 1)) |
| 5155 | megasas_start_timer(instance, |
| 5156 | &instance->sriov_heartbeat_timer, |
| 5157 | megasas_sriov_heartbeat_handler, |
| 5158 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 5159 | else |
| 5160 | instance->skip_heartbeat_timer_del = 1; |
| 5161 | } |
| 5162 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5163 | return 0; |
| 5164 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5165 | fail_get_pd_list: |
| 5166 | instance->instancet->disable_intr(instance); |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5167 | fail_init_adapter: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5168 | megasas_destroy_irqs(instance); |
| 5169 | fail_setup_irqs: |
| 5170 | if (instance->msix_vectors) |
| 5171 | pci_disable_msix(instance->pdev); |
| 5172 | instance->msix_vectors = 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5173 | fail_ready_state: |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5174 | kfree(instance->ctrl_info); |
| 5175 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5176 | iounmap(instance->reg_set); |
| 5177 | |
| 5178 | fail_ioremap: |
adam radford | b6d5d88 | 2010-12-14 18:56:07 -0800 | [diff] [blame] | 5179 | pci_release_selected_regions(instance->pdev, instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5180 | |
| 5181 | return -EINVAL; |
| 5182 | } |
| 5183 | |
| 5184 | /** |
| 5185 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 5186 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5187 | */ |
| 5188 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 5189 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5190 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5191 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5192 | if (instance->reply_queue) |
| 5193 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5194 | instance->reply_queue, instance->reply_queue_h); |
| 5195 | |
| 5196 | megasas_free_cmds(instance); |
| 5197 | |
| 5198 | iounmap(instance->reg_set); |
| 5199 | |
adam radford | b6d5d88 | 2010-12-14 18:56:07 -0800 | [diff] [blame] | 5200 | pci_release_selected_regions(instance->pdev, instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | /** |
| 5204 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 5205 | * @instance: Adapter soft state |
| 5206 | * @eli: FW event log sequence numbers information |
| 5207 | * |
| 5208 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 5209 | * usually find out the latest sequence number of the events, the seq number at |
| 5210 | * the boot etc. They would "read" all the events below the latest seq number |
| 5211 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 5212 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 5213 | * wait for the events to happen. |
| 5214 | */ |
| 5215 | static int |
| 5216 | megasas_get_seq_num(struct megasas_instance *instance, |
| 5217 | struct megasas_evt_log_info *eli) |
| 5218 | { |
| 5219 | struct megasas_cmd *cmd; |
| 5220 | struct megasas_dcmd_frame *dcmd; |
| 5221 | struct megasas_evt_log_info *el_info; |
| 5222 | dma_addr_t el_info_h = 0; |
| 5223 | |
| 5224 | cmd = megasas_get_cmd(instance); |
| 5225 | |
| 5226 | if (!cmd) { |
| 5227 | return -ENOMEM; |
| 5228 | } |
| 5229 | |
| 5230 | dcmd = &cmd->frame->dcmd; |
| 5231 | el_info = pci_alloc_consistent(instance->pdev, |
| 5232 | sizeof(struct megasas_evt_log_info), |
| 5233 | &el_info_h); |
| 5234 | |
| 5235 | if (!el_info) { |
| 5236 | megasas_return_cmd(instance, cmd); |
| 5237 | return -ENOMEM; |
| 5238 | } |
| 5239 | |
| 5240 | memset(el_info, 0, sizeof(*el_info)); |
| 5241 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5242 | |
| 5243 | dcmd->cmd = MFI_CMD_DCMD; |
| 5244 | dcmd->cmd_status = 0x0; |
| 5245 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5246 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5247 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5248 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5249 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 5250 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
| 5251 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(el_info_h); |
| 5252 | 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] | 5253 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5254 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) == |
| 5255 | DCMD_SUCCESS) { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5256 | /* |
| 5257 | * Copy the data back into callers buffer |
| 5258 | */ |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5259 | eli->newest_seq_num = el_info->newest_seq_num; |
| 5260 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 5261 | eli->clear_seq_num = el_info->clear_seq_num; |
| 5262 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 5263 | eli->boot_seq_num = el_info->boot_seq_num; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5264 | } else |
| 5265 | dev_err(&instance->pdev->dev, "DCMD failed " |
| 5266 | "from %s\n", __func__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5267 | |
| 5268 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 5269 | el_info, el_info_h); |
| 5270 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5271 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5272 | |
| 5273 | return 0; |
| 5274 | } |
| 5275 | |
| 5276 | /** |
| 5277 | * megasas_register_aen - Registers for asynchronous event notification |
| 5278 | * @instance: Adapter soft state |
| 5279 | * @seq_num: The starting sequence number |
| 5280 | * @class_locale: Class of the event |
| 5281 | * |
| 5282 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 5283 | * to be notified if and only if the event is of type @class_locale |
| 5284 | */ |
| 5285 | static int |
| 5286 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 5287 | u32 class_locale_word) |
| 5288 | { |
| 5289 | int ret_val; |
| 5290 | struct megasas_cmd *cmd; |
| 5291 | struct megasas_dcmd_frame *dcmd; |
| 5292 | union megasas_evt_class_locale curr_aen; |
| 5293 | union megasas_evt_class_locale prev_aen; |
| 5294 | |
| 5295 | /* |
| 5296 | * If there an AEN pending already (aen_cmd), check if the |
| 5297 | * class_locale of that pending AEN is inclusive of the new |
| 5298 | * AEN request we currently have. If it is, then we don't have |
| 5299 | * to do anything. In other words, whichever events the current |
| 5300 | * AEN request is subscribing to, have already been subscribed |
| 5301 | * to. |
| 5302 | * |
| 5303 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 5304 | * that command, form a class_locale that is superset of both |
| 5305 | * old and current and re-issue to the FW |
| 5306 | */ |
| 5307 | |
| 5308 | curr_aen.word = class_locale_word; |
| 5309 | |
| 5310 | if (instance->aen_cmd) { |
| 5311 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 5312 | prev_aen.word = |
| 5313 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5314 | |
| 5315 | /* |
| 5316 | * A class whose enum value is smaller is inclusive of all |
| 5317 | * higher values. If a PROGRESS (= -1) was previously |
| 5318 | * registered, then a new registration requests for higher |
| 5319 | * classes need not be sent to FW. They are automatically |
| 5320 | * included. |
| 5321 | * |
| 5322 | * Locale numbers don't have such hierarchy. They are bitmap |
| 5323 | * values |
| 5324 | */ |
| 5325 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5326 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5327 | curr_aen.members.locale)) { |
| 5328 | /* |
| 5329 | * Previously issued event registration includes |
| 5330 | * current request. Nothing to do. |
| 5331 | */ |
| 5332 | return 0; |
| 5333 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5334 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5335 | |
| 5336 | if (prev_aen.members.class < curr_aen.members.class) |
| 5337 | curr_aen.members.class = prev_aen.members.class; |
| 5338 | |
| 5339 | instance->aen_cmd->abort_aen = 1; |
| 5340 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 5341 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5342 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5343 | |
| 5344 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5345 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5346 | "previous AEN command\n"); |
| 5347 | return ret_val; |
| 5348 | } |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | cmd = megasas_get_cmd(instance); |
| 5353 | |
| 5354 | if (!cmd) |
| 5355 | return -ENOMEM; |
| 5356 | |
| 5357 | dcmd = &cmd->frame->dcmd; |
| 5358 | |
| 5359 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 5360 | |
| 5361 | /* |
| 5362 | * Prepare DCMD for aen registration |
| 5363 | */ |
| 5364 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5365 | |
| 5366 | dcmd->cmd = MFI_CMD_DCMD; |
| 5367 | dcmd->cmd_status = 0x0; |
| 5368 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5369 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5370 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5371 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5372 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 5373 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 5374 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5375 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5376 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
| 5377 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->evt_detail_h); |
| 5378 | 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] | 5379 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5380 | if (instance->aen_cmd != NULL) { |
| 5381 | megasas_return_cmd(instance, cmd); |
| 5382 | return 0; |
| 5383 | } |
| 5384 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5385 | /* |
| 5386 | * Store reference to the cmd used to register for AEN. When an |
| 5387 | * application wants us to register for AEN, we have to abort this |
| 5388 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 5389 | */ |
| 5390 | instance->aen_cmd = cmd; |
| 5391 | |
| 5392 | /* |
| 5393 | * Issue the aen registration frame |
| 5394 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5395 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5396 | |
| 5397 | return 0; |
| 5398 | } |
| 5399 | |
| 5400 | /** |
| 5401 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 5402 | * @instance: Adapter soft state |
| 5403 | */ |
| 5404 | static int megasas_start_aen(struct megasas_instance *instance) |
| 5405 | { |
| 5406 | struct megasas_evt_log_info eli; |
| 5407 | union megasas_evt_class_locale class_locale; |
| 5408 | |
| 5409 | /* |
| 5410 | * Get the latest sequence number from FW |
| 5411 | */ |
| 5412 | memset(&eli, 0, sizeof(eli)); |
| 5413 | |
| 5414 | if (megasas_get_seq_num(instance, &eli)) |
| 5415 | return -1; |
| 5416 | |
| 5417 | /* |
| 5418 | * Register AEN with FW for latest sequence number plus 1 |
| 5419 | */ |
| 5420 | class_locale.members.reserved = 0; |
| 5421 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 5422 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 5423 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5424 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5425 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5426 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | /** |
| 5430 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 5431 | * @instance: Adapter soft state |
| 5432 | */ |
| 5433 | static int megasas_io_attach(struct megasas_instance *instance) |
| 5434 | { |
| 5435 | struct Scsi_Host *host = instance->host; |
| 5436 | |
| 5437 | /* |
| 5438 | * Export parameters required by SCSI mid-layer |
| 5439 | */ |
| 5440 | host->irq = instance->pdev->irq; |
| 5441 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5442 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5443 | host->this_id = instance->init_id; |
| 5444 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 5445 | |
| 5446 | if (instance->fw_support_ieee) |
| 5447 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 5448 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5449 | /* |
| 5450 | * Check if the module parameter value for max_sectors can be used |
| 5451 | */ |
| 5452 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 5453 | instance->max_sectors_per_req = max_sectors; |
| 5454 | else { |
| 5455 | if (max_sectors) { |
| 5456 | if (((instance->pdev->device == |
| 5457 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 5458 | (instance->pdev->device == |
| 5459 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 5460 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 5461 | instance->max_sectors_per_req = max_sectors; |
| 5462 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5463 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5464 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 5465 | instance->max_sectors_per_req); |
| 5466 | } |
| 5467 | } |
| 5468 | } |
| 5469 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5470 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5471 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5472 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 5473 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5474 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 5475 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5476 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5477 | /* Fusion only supports host reset */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5478 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5479 | host->hostt->eh_device_reset_handler = NULL; |
| 5480 | host->hostt->eh_bus_reset_handler = NULL; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame^] | 5481 | host->hostt->eh_target_reset_handler = megasas_reset_target_fusion; |
| 5482 | host->hostt->eh_abort_handler = megasas_task_abort_fusion; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5483 | } |
| 5484 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5485 | /* |
| 5486 | * Notify the mid-layer about the new controller |
| 5487 | */ |
| 5488 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5489 | dev_err(&instance->pdev->dev, |
| 5490 | "Failed to add host from %s %d\n", |
| 5491 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5492 | return -ENODEV; |
| 5493 | } |
| 5494 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5495 | return 0; |
| 5496 | } |
| 5497 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5498 | static int |
| 5499 | megasas_set_dma_mask(struct pci_dev *pdev) |
| 5500 | { |
| 5501 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5502 | * All our controllers are capable of performing 64-bit DMA |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5503 | */ |
| 5504 | if (IS_DMA64) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5505 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5506 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5507 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5508 | goto fail_set_dma_mask; |
| 5509 | } |
| 5510 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5511 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5512 | goto fail_set_dma_mask; |
| 5513 | } |
Sumit.Saxena@lsi.com | 46de63e2 | 2014-02-12 23:38:44 +0530 | [diff] [blame] | 5514 | /* |
| 5515 | * Ensure that all data structures are allocated in 32-bit |
| 5516 | * memory. |
| 5517 | */ |
| 5518 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
| 5519 | /* Try 32bit DMA mask and 32 bit Consistent dma mask */ |
| 5520 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 5521 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 5522 | dev_info(&pdev->dev, "set 32bit DMA mask" |
| 5523 | "and 32 bit consistent mask\n"); |
| 5524 | else |
| 5525 | goto fail_set_dma_mask; |
| 5526 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5527 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5528 | return 0; |
| 5529 | |
| 5530 | fail_set_dma_mask: |
| 5531 | return 1; |
| 5532 | } |
| 5533 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5534 | /** |
| 5535 | * megasas_probe_one - PCI hotplug entry point |
| 5536 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 5537 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5538 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5539 | static int megasas_probe_one(struct pci_dev *pdev, |
| 5540 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5541 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5542 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5543 | struct Scsi_Host *host; |
| 5544 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5545 | u16 control = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5546 | struct fusion_context *fusion = NULL; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5547 | |
| 5548 | /* Reset MSI-X in the kdump kernel */ |
| 5549 | if (reset_devices) { |
| 5550 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 5551 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5552 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5553 | &control); |
| 5554 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 5555 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 5556 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5557 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5558 | control & |
| 5559 | ~PCI_MSIX_FLAGS_ENABLE); |
| 5560 | } |
| 5561 | } |
| 5562 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5563 | |
| 5564 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5565 | * PCI prepping: enable device set bus mastering and dma mask |
| 5566 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 5567 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5568 | |
| 5569 | if (rval) { |
| 5570 | return rval; |
| 5571 | } |
| 5572 | |
| 5573 | pci_set_master(pdev); |
| 5574 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5575 | if (megasas_set_dma_mask(pdev)) |
| 5576 | goto fail_set_dma_mask; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5577 | |
| 5578 | host = scsi_host_alloc(&megasas_template, |
| 5579 | sizeof(struct megasas_instance)); |
| 5580 | |
| 5581 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5582 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5583 | goto fail_alloc_instance; |
| 5584 | } |
| 5585 | |
| 5586 | instance = (struct megasas_instance *)host->hostdata; |
| 5587 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5588 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5589 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5590 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5591 | switch (instance->pdev->device) { |
| 5592 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5593 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5594 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5595 | case PCI_DEVICE_ID_LSI_FURY: |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 5596 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 5597 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 5598 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 5599 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5600 | { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5601 | instance->ctrl_context_pages = |
| 5602 | get_order(sizeof(struct fusion_context)); |
| 5603 | instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL, |
| 5604 | instance->ctrl_context_pages); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5605 | if (!instance->ctrl_context) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5606 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5607 | "memory for Fusion context info\n"); |
| 5608 | goto fail_alloc_dma_buf; |
| 5609 | } |
| 5610 | fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5611 | memset(fusion, 0, |
| 5612 | ((1 << PAGE_SHIFT) << instance->ctrl_context_pages)); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5613 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
| 5614 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA)) |
| 5615 | fusion->adapter_type = THUNDERBOLT_SERIES; |
| 5616 | else |
| 5617 | fusion->adapter_type = INVADER_SERIES; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5618 | } |
| 5619 | break; |
| 5620 | default: /* For all other supported controllers */ |
| 5621 | |
| 5622 | instance->producer = |
| 5623 | pci_alloc_consistent(pdev, sizeof(u32), |
| 5624 | &instance->producer_h); |
| 5625 | instance->consumer = |
| 5626 | pci_alloc_consistent(pdev, sizeof(u32), |
| 5627 | &instance->consumer_h); |
| 5628 | |
| 5629 | if (!instance->producer || !instance->consumer) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5630 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate" |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5631 | "memory for producer, consumer\n"); |
| 5632 | goto fail_alloc_dma_buf; |
| 5633 | } |
| 5634 | |
| 5635 | *instance->producer = 0; |
| 5636 | *instance->consumer = 0; |
| 5637 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5638 | } |
| 5639 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 5640 | instance->system_info_buf = pci_zalloc_consistent(pdev, |
| 5641 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 5642 | &instance->system_info_h); |
| 5643 | |
| 5644 | if (!instance->system_info_buf) |
| 5645 | dev_info(&instance->pdev->dev, "Can't allocate system info buffer\n"); |
| 5646 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5647 | /* Crash dump feature related initialisation*/ |
| 5648 | instance->drv_buf_index = 0; |
| 5649 | instance->drv_buf_alloc = 0; |
| 5650 | instance->crash_dump_fw_support = 0; |
| 5651 | instance->crash_dump_app_support = 0; |
| 5652 | instance->fw_crash_state = UNAVAILABLE; |
| 5653 | spin_lock_init(&instance->crashdump_lock); |
| 5654 | instance->crash_dump_buf = NULL; |
| 5655 | |
| 5656 | if (!reset_devices) |
| 5657 | instance->crash_dump_buf = pci_alloc_consistent(pdev, |
| 5658 | CRASH_DMA_BUF_SIZE, |
| 5659 | &instance->crash_dump_h); |
| 5660 | if (!instance->crash_dump_buf) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5661 | dev_err(&pdev->dev, "Can't allocate Firmware " |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5662 | "crash dump DMA buffer\n"); |
| 5663 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5664 | megasas_poll_wait_aen = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5665 | instance->flag_ieee = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5666 | instance->ev = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5667 | instance->issuepend_done = 1; |
| 5668 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5669 | instance->is_imr = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5670 | |
| 5671 | instance->evt_detail = pci_alloc_consistent(pdev, |
| 5672 | sizeof(struct |
| 5673 | megasas_evt_detail), |
| 5674 | &instance->evt_detail_h); |
| 5675 | |
| 5676 | if (!instance->evt_detail) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5677 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate memory for " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5678 | "event detail structure\n"); |
| 5679 | goto fail_alloc_dma_buf; |
| 5680 | } |
| 5681 | |
| 5682 | /* |
| 5683 | * Initialize locks and queues |
| 5684 | */ |
| 5685 | INIT_LIST_HEAD(&instance->cmd_pool); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5686 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5687 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 5688 | atomic_set(&instance->fw_outstanding,0); |
| 5689 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5690 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 5691 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 5692 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5693 | spin_lock_init(&instance->mfi_pool_lock); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5694 | spin_lock_init(&instance->hba_lock); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 5695 | spin_lock_init(&instance->completion_lock); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5696 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5697 | mutex_init(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5698 | |
| 5699 | /* |
| 5700 | * Initialize PCI related and misc parameters |
| 5701 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5702 | instance->host = host; |
| 5703 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 5704 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5705 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5706 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5707 | |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5708 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5709 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5710 | instance->flag_ieee = 1; |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5711 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5712 | megasas_dbg_lvl = 0; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 5713 | instance->flag = 0; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5714 | instance->unload = 1; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 5715 | instance->last_time = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5716 | instance->disableOnlineCtrlReset = 1; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5717 | instance->UnevenSpanSupport = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5718 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5719 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5720 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5721 | INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq); |
| 5722 | } else |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5723 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5724 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5725 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 5726 | * Initialize MFI Firmware |
| 5727 | */ |
| 5728 | if (megasas_init_fw(instance)) |
| 5729 | goto fail_init_mfi; |
| 5730 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5731 | if (instance->requestorId) { |
| 5732 | if (instance->PlasmaFW111) { |
| 5733 | instance->vf_affiliation_111 = |
| 5734 | pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 5735 | &instance->vf_affiliation_111_h); |
| 5736 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5737 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5738 | "memory for VF affiliation buffer\n"); |
| 5739 | } else { |
| 5740 | instance->vf_affiliation = |
| 5741 | pci_alloc_consistent(pdev, |
| 5742 | (MAX_LOGICAL_DRIVES + 1) * |
| 5743 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 5744 | &instance->vf_affiliation_h); |
| 5745 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5746 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5747 | "memory for VF affiliation buffer\n"); |
| 5748 | } |
| 5749 | } |
| 5750 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5751 | /* |
| 5752 | * Store instance in PCI softstate |
| 5753 | */ |
| 5754 | pci_set_drvdata(pdev, instance); |
| 5755 | |
| 5756 | /* |
| 5757 | * Add this controller to megasas_mgmt_info structure so that it |
| 5758 | * can be exported to management applications |
| 5759 | */ |
| 5760 | megasas_mgmt_info.count++; |
| 5761 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 5762 | megasas_mgmt_info.max_index++; |
| 5763 | |
| 5764 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 5765 | * Register with SCSI mid-layer |
| 5766 | */ |
| 5767 | if (megasas_io_attach(instance)) |
| 5768 | goto fail_io_attach; |
| 5769 | |
| 5770 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 5771 | /* |
| 5772 | * Trigger SCSI to scan our drives |
| 5773 | */ |
| 5774 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 5775 | |
| 5776 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5777 | * Initiate AEN (Asynchronous Event Notification) |
| 5778 | */ |
| 5779 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5780 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5781 | goto fail_start_aen; |
| 5782 | } |
| 5783 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 5784 | /* Get current SR-IOV LD/VF affiliation */ |
| 5785 | if (instance->requestorId) |
| 5786 | megasas_get_ld_vf_affiliation(instance, 1); |
| 5787 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5788 | return 0; |
| 5789 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5790 | fail_start_aen: |
| 5791 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5792 | megasas_mgmt_info.count--; |
| 5793 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
| 5794 | megasas_mgmt_info.max_index--; |
| 5795 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5796 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5797 | megasas_destroy_irqs(instance); |
| 5798 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5799 | if (instance->ctrl_context) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5800 | megasas_release_fusion(instance); |
| 5801 | else |
| 5802 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5803 | if (instance->msix_vectors) |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 5804 | pci_disable_msix(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5805 | fail_init_mfi: |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5806 | fail_alloc_dma_buf: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5807 | if (instance->evt_detail) |
| 5808 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 5809 | instance->evt_detail, |
| 5810 | instance->evt_detail_h); |
| 5811 | |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5812 | if (instance->producer) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5813 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 5814 | instance->producer_h); |
| 5815 | if (instance->consumer) |
| 5816 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 5817 | instance->consumer_h); |
| 5818 | scsi_host_put(host); |
| 5819 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5820 | fail_alloc_instance: |
| 5821 | fail_set_dma_mask: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5822 | pci_disable_device(pdev); |
| 5823 | |
| 5824 | return -ENODEV; |
| 5825 | } |
| 5826 | |
| 5827 | /** |
| 5828 | * megasas_flush_cache - Requests FW to flush all its caches |
| 5829 | * @instance: Adapter soft state |
| 5830 | */ |
| 5831 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 5832 | { |
| 5833 | struct megasas_cmd *cmd; |
| 5834 | struct megasas_dcmd_frame *dcmd; |
| 5835 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5836 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 5837 | return; |
| 5838 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5839 | cmd = megasas_get_cmd(instance); |
| 5840 | |
| 5841 | if (!cmd) |
| 5842 | return; |
| 5843 | |
| 5844 | dcmd = &cmd->frame->dcmd; |
| 5845 | |
| 5846 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5847 | |
| 5848 | dcmd->cmd = MFI_CMD_DCMD; |
| 5849 | dcmd->cmd_status = 0x0; |
| 5850 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5851 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5852 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5853 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5854 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5855 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5856 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 5857 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5858 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 5859 | != DCMD_SUCCESS) { |
| 5860 | dev_err(&instance->pdev->dev, |
| 5861 | "return from %s %d\n", __func__, __LINE__); |
| 5862 | return; |
| 5863 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5864 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5865 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | /** |
| 5869 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 5870 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5871 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5872 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5873 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 5874 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5875 | { |
| 5876 | struct megasas_cmd *cmd; |
| 5877 | struct megasas_dcmd_frame *dcmd; |
| 5878 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5879 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 5880 | return; |
| 5881 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5882 | cmd = megasas_get_cmd(instance); |
| 5883 | |
| 5884 | if (!cmd) |
| 5885 | return; |
| 5886 | |
| 5887 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5888 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5889 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5890 | if (instance->map_update_cmd) |
| 5891 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5892 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5893 | if (instance->jbod_seq_cmd) |
| 5894 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5895 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5896 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5897 | dcmd = &cmd->frame->dcmd; |
| 5898 | |
| 5899 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5900 | |
| 5901 | dcmd->cmd = MFI_CMD_DCMD; |
| 5902 | dcmd->cmd_status = 0x0; |
| 5903 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5904 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5905 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5906 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5907 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5908 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5909 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5910 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 5911 | != DCMD_SUCCESS) { |
| 5912 | dev_err(&instance->pdev->dev, |
| 5913 | "return from %s %d\n", __func__, __LINE__); |
| 5914 | return; |
| 5915 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5916 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5917 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5918 | } |
| 5919 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5920 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5921 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5922 | * megasas_suspend - driver suspend entry point |
| 5923 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5924 | * @state: PCI power state to suspend routine |
| 5925 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5926 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5927 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5928 | { |
| 5929 | struct Scsi_Host *host; |
| 5930 | struct megasas_instance *instance; |
| 5931 | |
| 5932 | instance = pci_get_drvdata(pdev); |
| 5933 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5934 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5935 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5936 | /* Shutdown SR-IOV heartbeat timer */ |
| 5937 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 5938 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 5939 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5940 | megasas_flush_cache(instance); |
| 5941 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5942 | |
| 5943 | /* cancel the delayed work if this work still in queue */ |
| 5944 | if (instance->ev != NULL) { |
| 5945 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 5946 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5947 | instance->ev = NULL; |
| 5948 | } |
| 5949 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5950 | tasklet_kill(&instance->isr_tasklet); |
| 5951 | |
| 5952 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5953 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5954 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5955 | megasas_destroy_irqs(instance); |
| 5956 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5957 | if (instance->msix_vectors) |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 5958 | pci_disable_msix(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5959 | |
| 5960 | pci_save_state(pdev); |
| 5961 | pci_disable_device(pdev); |
| 5962 | |
| 5963 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 5964 | |
| 5965 | return 0; |
| 5966 | } |
| 5967 | |
| 5968 | /** |
| 5969 | * megasas_resume- driver resume entry point |
| 5970 | * @pdev: PCI device structure |
| 5971 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5972 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5973 | megasas_resume(struct pci_dev *pdev) |
| 5974 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5975 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5976 | struct Scsi_Host *host; |
| 5977 | struct megasas_instance *instance; |
| 5978 | |
| 5979 | instance = pci_get_drvdata(pdev); |
| 5980 | host = instance->host; |
| 5981 | pci_set_power_state(pdev, PCI_D0); |
| 5982 | pci_enable_wake(pdev, PCI_D0, 0); |
| 5983 | pci_restore_state(pdev); |
| 5984 | |
| 5985 | /* |
| 5986 | * PCI prepping: enable device set bus mastering and dma mask |
| 5987 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 5988 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5989 | |
| 5990 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5991 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5992 | return rval; |
| 5993 | } |
| 5994 | |
| 5995 | pci_set_master(pdev); |
| 5996 | |
| 5997 | if (megasas_set_dma_mask(pdev)) |
| 5998 | goto fail_set_dma_mask; |
| 5999 | |
| 6000 | /* |
| 6001 | * Initialize MFI Firmware |
| 6002 | */ |
| 6003 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6004 | atomic_set(&instance->fw_outstanding, 0); |
| 6005 | |
| 6006 | /* |
| 6007 | * We expect the FW state to be READY |
| 6008 | */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 6009 | if (megasas_transition_to_ready(instance, 0)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6010 | goto fail_ready_state; |
| 6011 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6012 | /* Now re-enable MSI-X */ |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6013 | if (instance->msix_vectors && |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 6014 | pci_enable_msix_exact(instance->pdev, instance->msixentry, |
| 6015 | instance->msix_vectors)) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6016 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6017 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6018 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6019 | megasas_reset_reply_desc(instance); |
| 6020 | if (megasas_ioc_init_fusion(instance)) { |
| 6021 | megasas_free_cmds(instance); |
| 6022 | megasas_free_cmds_fusion(instance); |
| 6023 | goto fail_init_mfi; |
| 6024 | } |
| 6025 | if (!megasas_get_map_info(instance)) |
| 6026 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6027 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6028 | *instance->producer = 0; |
| 6029 | *instance->consumer = 0; |
| 6030 | if (megasas_issue_init_mfi(instance)) |
| 6031 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6032 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6033 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6034 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 6035 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6036 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6037 | if (instance->msix_vectors ? |
| 6038 | megasas_setup_irqs_msix(instance, 0) : |
| 6039 | megasas_setup_irqs_ioapic(instance)) |
| 6040 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6041 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6042 | /* Re-launch SR-IOV heartbeat timer */ |
| 6043 | if (instance->requestorId) { |
| 6044 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 6045 | megasas_start_timer(instance, |
| 6046 | &instance->sriov_heartbeat_timer, |
| 6047 | megasas_sriov_heartbeat_handler, |
| 6048 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6049 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6050 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6051 | goto fail_init_mfi; |
| 6052 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6055 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6056 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6057 | instance->unload = 0; |
| 6058 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6059 | /* |
| 6060 | * Initiate AEN (Asynchronous Event Notification) |
| 6061 | */ |
| 6062 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6063 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6064 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6065 | return 0; |
| 6066 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6067 | fail_init_mfi: |
| 6068 | if (instance->evt_detail) |
| 6069 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6070 | instance->evt_detail, |
| 6071 | instance->evt_detail_h); |
| 6072 | |
| 6073 | if (instance->producer) |
| 6074 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6075 | instance->producer_h); |
| 6076 | if (instance->consumer) |
| 6077 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6078 | instance->consumer_h); |
| 6079 | scsi_host_put(host); |
| 6080 | |
| 6081 | fail_set_dma_mask: |
| 6082 | fail_ready_state: |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6083 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6084 | |
| 6085 | pci_disable_device(pdev); |
| 6086 | |
| 6087 | return -ENODEV; |
| 6088 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6089 | #else |
| 6090 | #define megasas_suspend NULL |
| 6091 | #define megasas_resume NULL |
| 6092 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6093 | |
| 6094 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6095 | * megasas_detach_one - PCI hot"un"plug entry point |
| 6096 | * @pdev: PCI device structure |
| 6097 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6098 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6099 | { |
| 6100 | int i; |
| 6101 | struct Scsi_Host *host; |
| 6102 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6103 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6104 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6105 | |
| 6106 | instance = pci_get_drvdata(pdev); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6107 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6108 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6109 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6110 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6111 | /* Shutdown SR-IOV heartbeat timer */ |
| 6112 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6113 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6114 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6115 | if (instance->fw_crash_state != UNAVAILABLE) |
| 6116 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6117 | scsi_remove_host(instance->host); |
| 6118 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6119 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6120 | |
| 6121 | /* cancel the delayed work if this work still in queue*/ |
| 6122 | if (instance->ev != NULL) { |
| 6123 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6124 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6125 | instance->ev = NULL; |
| 6126 | } |
| 6127 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6128 | /* cancel all wait events */ |
| 6129 | wake_up_all(&instance->int_cmd_wait_q); |
| 6130 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 6131 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6132 | |
| 6133 | /* |
| 6134 | * Take the instance off the instance array. Note that we will not |
| 6135 | * decrement the max_index. We let this array be sparse array |
| 6136 | */ |
| 6137 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6138 | if (megasas_mgmt_info.instance[i] == instance) { |
| 6139 | megasas_mgmt_info.count--; |
| 6140 | megasas_mgmt_info.instance[i] = NULL; |
| 6141 | |
| 6142 | break; |
| 6143 | } |
| 6144 | } |
| 6145 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6146 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6147 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6148 | megasas_destroy_irqs(instance); |
| 6149 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6150 | if (instance->msix_vectors) |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 6151 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6152 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6153 | if (instance->ctrl_context) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6154 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6155 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 6156 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 6157 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6158 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6159 | if (fusion->ld_map[i]) |
| 6160 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6161 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6162 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6163 | fusion->ld_map_phys[i]); |
| 6164 | if (fusion->ld_drv_map[i]) |
| 6165 | free_pages((ulong)fusion->ld_drv_map[i], |
| 6166 | fusion->drv_map_pages); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6167 | if (fusion->pd_seq_sync) |
| 6168 | dma_free_coherent(&instance->pdev->dev, |
| 6169 | pd_seq_map_sz, |
| 6170 | fusion->pd_seq_sync[i], |
| 6171 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6172 | } |
| 6173 | free_pages((ulong)instance->ctrl_context, |
| 6174 | instance->ctrl_context_pages); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6175 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6176 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6177 | pci_free_consistent(pdev, sizeof(u32), |
| 6178 | instance->producer, |
| 6179 | instance->producer_h); |
| 6180 | pci_free_consistent(pdev, sizeof(u32), |
| 6181 | instance->consumer, |
| 6182 | instance->consumer_h); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6183 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6184 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6185 | kfree(instance->ctrl_info); |
| 6186 | |
Sumit.Saxena@lsi.com | 105900d | 2013-05-22 12:30:54 +0530 | [diff] [blame] | 6187 | if (instance->evt_detail) |
| 6188 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6189 | instance->evt_detail, instance->evt_detail_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6190 | |
| 6191 | if (instance->vf_affiliation) |
| 6192 | pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) * |
| 6193 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6194 | instance->vf_affiliation, |
| 6195 | instance->vf_affiliation_h); |
| 6196 | |
| 6197 | if (instance->vf_affiliation_111) |
| 6198 | pci_free_consistent(pdev, |
| 6199 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6200 | instance->vf_affiliation_111, |
| 6201 | instance->vf_affiliation_111_h); |
| 6202 | |
| 6203 | if (instance->hb_host_mem) |
| 6204 | pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 6205 | instance->hb_host_mem, |
| 6206 | instance->hb_host_mem_h); |
| 6207 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6208 | if (instance->crash_dump_buf) |
| 6209 | pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE, |
| 6210 | instance->crash_dump_buf, instance->crash_dump_h); |
| 6211 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6212 | if (instance->system_info_buf) |
| 6213 | pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6214 | instance->system_info_buf, instance->system_info_h); |
| 6215 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6216 | scsi_host_put(host); |
| 6217 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6218 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | /** |
| 6222 | * megasas_shutdown - Shutdown entry point |
| 6223 | * @device: Generic device structure |
| 6224 | */ |
| 6225 | static void megasas_shutdown(struct pci_dev *pdev) |
| 6226 | { |
| 6227 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6228 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6229 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6230 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 6231 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6232 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6233 | megasas_destroy_irqs(instance); |
| 6234 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6235 | if (instance->msix_vectors) |
adam radford | 46fd256 | 2011-05-11 18:34:17 -0700 | [diff] [blame] | 6236 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6237 | } |
| 6238 | |
| 6239 | /** |
| 6240 | * megasas_mgmt_open - char node "open" entry point |
| 6241 | */ |
| 6242 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 6243 | { |
| 6244 | /* |
| 6245 | * Allow only those users with admin rights |
| 6246 | */ |
| 6247 | if (!capable(CAP_SYS_ADMIN)) |
| 6248 | return -EACCES; |
| 6249 | |
| 6250 | return 0; |
| 6251 | } |
| 6252 | |
| 6253 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6254 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 6255 | * |
| 6256 | * This function adds the calling process to a driver global queue. When an |
| 6257 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 6258 | */ |
| 6259 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 6260 | { |
| 6261 | int rc; |
| 6262 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6263 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6264 | |
| 6265 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 6266 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6267 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6268 | |
| 6269 | if (rc >= 0) { |
| 6270 | /* For sanity check when we get ioctl */ |
| 6271 | filep->private_data = filep; |
| 6272 | return 0; |
| 6273 | } |
| 6274 | |
| 6275 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 6276 | |
| 6277 | return rc; |
| 6278 | } |
| 6279 | |
| 6280 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6281 | * megasas_mgmt_poll - char node "poll" entry point |
| 6282 | * */ |
| 6283 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 6284 | { |
| 6285 | unsigned int mask; |
| 6286 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6287 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6288 | poll_wait(file, &megasas_poll_wait, wait); |
| 6289 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 6290 | if (megasas_poll_wait_aen) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6291 | mask = (POLLIN | POLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6292 | else |
| 6293 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6294 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6295 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 6296 | return mask; |
| 6297 | } |
| 6298 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6299 | /* |
| 6300 | * megasas_set_crash_dump_params_ioctl: |
| 6301 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 6302 | * @cmd: MFI command frame |
| 6303 | */ |
| 6304 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6305 | 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] | 6306 | { |
| 6307 | struct megasas_instance *local_instance; |
| 6308 | int i, error = 0; |
| 6309 | int crash_support; |
| 6310 | |
| 6311 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 6312 | |
| 6313 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6314 | local_instance = megasas_mgmt_info.instance[i]; |
| 6315 | if (local_instance && local_instance->crash_dump_drv_support) { |
| 6316 | if ((local_instance->adprecovery == |
| 6317 | MEGASAS_HBA_OPERATIONAL) && |
| 6318 | !megasas_set_crash_dump_params(local_instance, |
| 6319 | crash_support)) { |
| 6320 | local_instance->crash_dump_app_support = |
| 6321 | crash_support; |
| 6322 | dev_info(&local_instance->pdev->dev, |
| 6323 | "Application firmware crash " |
| 6324 | "dump mode set success\n"); |
| 6325 | error = 0; |
| 6326 | } else { |
| 6327 | dev_info(&local_instance->pdev->dev, |
| 6328 | "Application firmware crash " |
| 6329 | "dump mode set failed\n"); |
| 6330 | error = -1; |
| 6331 | } |
| 6332 | } |
| 6333 | } |
| 6334 | return error; |
| 6335 | } |
| 6336 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6337 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6338 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 6339 | * @instance: Adapter soft state |
| 6340 | * @argp: User's ioctl packet |
| 6341 | */ |
| 6342 | static int |
| 6343 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 6344 | struct megasas_iocpacket __user * user_ioc, |
| 6345 | struct megasas_iocpacket *ioc) |
| 6346 | { |
| 6347 | struct megasas_sge32 *kern_sge32; |
| 6348 | struct megasas_cmd *cmd; |
| 6349 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 6350 | dma_addr_t buf_handle = 0; |
| 6351 | int error = 0, i; |
| 6352 | void *sense = NULL; |
| 6353 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6354 | unsigned long *sense_ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6355 | |
| 6356 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 6357 | |
| 6358 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6359 | 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] | 6360 | ioc->sge_count, MAX_IOCTL_SGE); |
| 6361 | return -EINVAL; |
| 6362 | } |
| 6363 | |
| 6364 | cmd = megasas_get_cmd(instance); |
| 6365 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6366 | 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] | 6367 | return -ENOMEM; |
| 6368 | } |
| 6369 | |
| 6370 | /* |
| 6371 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 6372 | * frames into our cmd's frames. cmd->frame's context will get |
| 6373 | * overwritten when we copy from user's frames. So set that value |
| 6374 | * alone separately |
| 6375 | */ |
| 6376 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6377 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6378 | cmd->frame->hdr.pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6379 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE | |
| 6380 | MFI_FRAME_SGL64 | |
| 6381 | MFI_FRAME_SENSE64)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6382 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6383 | if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
| 6384 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 6385 | megasas_return_cmd(instance, cmd); |
| 6386 | return error; |
| 6387 | } |
| 6388 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6389 | /* |
| 6390 | * The management interface between applications and the fw uses |
| 6391 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 6392 | * etc are accomplishes through different kinds of MFI frames. The |
| 6393 | * driver needs to care only about substituting user buffers with |
| 6394 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 6395 | * struct iocpacket itself. |
| 6396 | */ |
| 6397 | kern_sge32 = (struct megasas_sge32 *) |
| 6398 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 6399 | |
| 6400 | /* |
| 6401 | * For each user buffer, create a mirror buffer and copy in |
| 6402 | */ |
| 6403 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 6404 | if (!ioc->sgl[i].iov_len) |
| 6405 | continue; |
| 6406 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6407 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6408 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6409 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6410 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6411 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 6412 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6413 | error = -ENOMEM; |
| 6414 | goto out; |
| 6415 | } |
| 6416 | |
| 6417 | /* |
| 6418 | * We don't change the dma_coherent_mask, so |
| 6419 | * pci_alloc_consistent only returns 32bit addresses |
| 6420 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6421 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 6422 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6423 | |
| 6424 | /* |
| 6425 | * We created a kernel buffer corresponding to the |
| 6426 | * user buffer. Now copy in from the user buffer |
| 6427 | */ |
| 6428 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 6429 | (u32) (ioc->sgl[i].iov_len))) { |
| 6430 | error = -EFAULT; |
| 6431 | goto out; |
| 6432 | } |
| 6433 | } |
| 6434 | |
| 6435 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6436 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 6437 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6438 | if (!sense) { |
| 6439 | error = -ENOMEM; |
| 6440 | goto out; |
| 6441 | } |
| 6442 | |
| 6443 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6444 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6445 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | /* |
| 6449 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 6450 | * cmd to the SCSI mid-layer |
| 6451 | */ |
| 6452 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6453 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 6454 | cmd->sync_cmd = 0; |
| 6455 | dev_err(&instance->pdev->dev, |
| 6456 | "return -EBUSY from %s %d opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 6457 | __func__, __LINE__, cmd->frame->dcmd.opcode, |
| 6458 | cmd->cmd_status_drv); |
| 6459 | return -EBUSY; |
| 6460 | } |
| 6461 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6462 | cmd->sync_cmd = 0; |
| 6463 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6464 | if (instance->unload == 1) { |
| 6465 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 6466 | "don't submit data to application\n"); |
| 6467 | goto out; |
| 6468 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6469 | /* |
| 6470 | * copy out the kernel buffers to user buffers |
| 6471 | */ |
| 6472 | for (i = 0; i < ioc->sge_count; i++) { |
| 6473 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 6474 | ioc->sgl[i].iov_len)) { |
| 6475 | error = -EFAULT; |
| 6476 | goto out; |
| 6477 | } |
| 6478 | } |
| 6479 | |
| 6480 | /* |
| 6481 | * copy out the sense |
| 6482 | */ |
| 6483 | if (ioc->sense_len) { |
| 6484 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 6485 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6486 | * sense buffer address |
| 6487 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6488 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 6489 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6490 | |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 6491 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), |
| 6492 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6493 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 6494 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6495 | error = -EFAULT; |
| 6496 | goto out; |
| 6497 | } |
| 6498 | } |
| 6499 | |
| 6500 | /* |
| 6501 | * copy the status codes returned by the fw |
| 6502 | */ |
| 6503 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 6504 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6505 | 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] | 6506 | error = -EFAULT; |
| 6507 | } |
| 6508 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6509 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6510 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6511 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6512 | sense, sense_handle); |
| 6513 | } |
| 6514 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6515 | for (i = 0; i < ioc->sge_count; i++) { |
| 6516 | if (kbuff_arr[i]) |
| 6517 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6518 | le32_to_cpu(kern_sge32[i].length), |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6519 | kbuff_arr[i], |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6520 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 6521 | kbuff_arr[i] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6522 | } |
| 6523 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6524 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6525 | return error; |
| 6526 | } |
| 6527 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6528 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 6529 | { |
| 6530 | struct megasas_iocpacket __user *user_ioc = |
| 6531 | (struct megasas_iocpacket __user *)arg; |
| 6532 | struct megasas_iocpacket *ioc; |
| 6533 | struct megasas_instance *instance; |
| 6534 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6535 | int i; |
| 6536 | unsigned long flags; |
| 6537 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6538 | |
| 6539 | ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 6540 | if (!ioc) |
| 6541 | return -ENOMEM; |
| 6542 | |
| 6543 | if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) { |
| 6544 | error = -EFAULT; |
| 6545 | goto out_kfree_ioc; |
| 6546 | } |
| 6547 | |
| 6548 | instance = megasas_lookup_instance(ioc->host_no); |
| 6549 | if (!instance) { |
| 6550 | error = -ENODEV; |
| 6551 | goto out_kfree_ioc; |
| 6552 | } |
| 6553 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6554 | /* Adjust ioctl wait time for VF mode */ |
| 6555 | if (instance->requestorId) |
| 6556 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 6557 | |
| 6558 | /* Block ioctls in VF mode */ |
| 6559 | if (instance->requestorId && !allow_vf_ioctls) { |
| 6560 | error = -ENODEV; |
| 6561 | goto out_kfree_ioc; |
| 6562 | } |
| 6563 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6564 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6565 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6566 | error = -ENODEV; |
| 6567 | goto out_kfree_ioc; |
| 6568 | } |
| 6569 | |
| 6570 | if (instance->unload == 1) { |
| 6571 | error = -ENODEV; |
| 6572 | goto out_kfree_ioc; |
| 6573 | } |
| 6574 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6575 | if (down_interruptible(&instance->ioctl_sem)) { |
| 6576 | error = -ERESTARTSYS; |
| 6577 | goto out_kfree_ioc; |
| 6578 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6579 | |
| 6580 | for (i = 0; i < wait_time; i++) { |
| 6581 | |
| 6582 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6583 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 6584 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6585 | break; |
| 6586 | } |
| 6587 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6588 | |
| 6589 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6590 | dev_notice(&instance->pdev->dev, "waiting" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6591 | "for controller reset to finish\n"); |
| 6592 | } |
| 6593 | |
| 6594 | msleep(1000); |
| 6595 | } |
| 6596 | |
| 6597 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6598 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 6599 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6600 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6601 | dev_err(&instance->pdev->dev, "timed out while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6602 | "waiting for HBA to recover\n"); |
| 6603 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 6604 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6605 | } |
| 6606 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6607 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6608 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6609 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6610 | up(&instance->ioctl_sem); |
| 6611 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6612 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6613 | kfree(ioc); |
| 6614 | return error; |
| 6615 | } |
| 6616 | |
| 6617 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 6618 | { |
| 6619 | struct megasas_instance *instance; |
| 6620 | struct megasas_aen aen; |
| 6621 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6622 | int i; |
| 6623 | unsigned long flags; |
| 6624 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6625 | |
| 6626 | if (file->private_data != file) { |
| 6627 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 6628 | "called first\n"); |
| 6629 | return -EINVAL; |
| 6630 | } |
| 6631 | |
| 6632 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 6633 | return -EFAULT; |
| 6634 | |
| 6635 | instance = megasas_lookup_instance(aen.host_no); |
| 6636 | |
| 6637 | if (!instance) |
| 6638 | return -ENODEV; |
| 6639 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6640 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 6641 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6642 | } |
| 6643 | |
| 6644 | if (instance->unload == 1) { |
| 6645 | return -ENODEV; |
| 6646 | } |
| 6647 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6648 | for (i = 0; i < wait_time; i++) { |
| 6649 | |
| 6650 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6651 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 6652 | spin_unlock_irqrestore(&instance->hba_lock, |
| 6653 | flags); |
| 6654 | break; |
| 6655 | } |
| 6656 | |
| 6657 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6658 | |
| 6659 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6660 | dev_notice(&instance->pdev->dev, "waiting for" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6661 | "controller reset to finish\n"); |
| 6662 | } |
| 6663 | |
| 6664 | msleep(1000); |
| 6665 | } |
| 6666 | |
| 6667 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6668 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 6669 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6670 | dev_err(&instance->pdev->dev, "timed out while waiting" |
| 6671 | "for HBA to recover\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6672 | return -ENODEV; |
| 6673 | } |
| 6674 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6675 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6676 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6677 | error = megasas_register_aen(instance, aen.seq_num, |
| 6678 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6679 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6680 | return error; |
| 6681 | } |
| 6682 | |
| 6683 | /** |
| 6684 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 6685 | */ |
| 6686 | static long |
| 6687 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 6688 | { |
| 6689 | switch (cmd) { |
| 6690 | case MEGASAS_IOC_FIRMWARE: |
| 6691 | return megasas_mgmt_ioctl_fw(file, arg); |
| 6692 | |
| 6693 | case MEGASAS_IOC_GET_AEN: |
| 6694 | return megasas_mgmt_ioctl_aen(file, arg); |
| 6695 | } |
| 6696 | |
| 6697 | return -ENOTTY; |
| 6698 | } |
| 6699 | |
| 6700 | #ifdef CONFIG_COMPAT |
| 6701 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 6702 | { |
| 6703 | struct compat_megasas_iocpacket __user *cioc = |
| 6704 | (struct compat_megasas_iocpacket __user *)arg; |
| 6705 | struct megasas_iocpacket __user *ioc = |
| 6706 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 6707 | int i; |
| 6708 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6709 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 6710 | unsigned long local_raw_ptr; |
| 6711 | u32 local_sense_off; |
| 6712 | u32 local_sense_len; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6713 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6714 | if (clear_user(ioc, sizeof(*ioc))) |
| 6715 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6716 | |
| 6717 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 6718 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 6719 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 6720 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 6721 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 6722 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 6723 | return -EFAULT; |
| 6724 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6725 | /* |
| 6726 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 6727 | * sense_len is not null, so prepare the 64bit value under |
| 6728 | * the same condition. |
| 6729 | */ |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 6730 | if (get_user(local_raw_ptr, ioc->frame.raw) || |
| 6731 | get_user(local_sense_off, &ioc->sense_off) || |
| 6732 | get_user(local_sense_len, &ioc->sense_len)) |
| 6733 | return -EFAULT; |
| 6734 | |
| 6735 | |
| 6736 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6737 | void __user **sense_ioc_ptr = |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 6738 | (void __user **)((u8*)local_raw_ptr + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6739 | compat_uptr_t *sense_cioc_ptr = |
| 6740 | (compat_uptr_t *)(cioc->frame.raw + cioc->sense_off); |
| 6741 | if (get_user(ptr, sense_cioc_ptr) || |
| 6742 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 6743 | return -EFAULT; |
| 6744 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6745 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6746 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6747 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 6748 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 6749 | copy_in_user(&ioc->sgl[i].iov_len, |
| 6750 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 6751 | return -EFAULT; |
| 6752 | } |
| 6753 | |
| 6754 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 6755 | |
| 6756 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 6757 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 6758 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 6759 | return -EFAULT; |
| 6760 | } |
| 6761 | return error; |
| 6762 | } |
| 6763 | |
| 6764 | static long |
| 6765 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 6766 | unsigned long arg) |
| 6767 | { |
| 6768 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 6769 | case MEGASAS_IOC_FIRMWARE32: |
| 6770 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6771 | case MEGASAS_IOC_GET_AEN: |
| 6772 | return megasas_mgmt_ioctl_aen(file, arg); |
| 6773 | } |
| 6774 | |
| 6775 | return -ENOTTY; |
| 6776 | } |
| 6777 | #endif |
| 6778 | |
| 6779 | /* |
| 6780 | * File operations structure for management interface |
| 6781 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 6782 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6783 | .owner = THIS_MODULE, |
| 6784 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6785 | .fasync = megasas_mgmt_fasync, |
| 6786 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6787 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6788 | #ifdef CONFIG_COMPAT |
| 6789 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 6790 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 6791 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6792 | }; |
| 6793 | |
| 6794 | /* |
| 6795 | * PCI hotplug support registration structure |
| 6796 | */ |
| 6797 | static struct pci_driver megasas_pci_driver = { |
| 6798 | |
| 6799 | .name = "megaraid_sas", |
| 6800 | .id_table = megasas_pci_table, |
| 6801 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6802 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6803 | .suspend = megasas_suspend, |
| 6804 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6805 | .shutdown = megasas_shutdown, |
| 6806 | }; |
| 6807 | |
| 6808 | /* |
| 6809 | * Sysfs driver attributes |
| 6810 | */ |
| 6811 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) |
| 6812 | { |
| 6813 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 6814 | MEGASAS_VERSION); |
| 6815 | } |
| 6816 | |
| 6817 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); |
| 6818 | |
| 6819 | static ssize_t |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 6820 | megasas_sysfs_show_release_date(struct device_driver *dd, char *buf) |
| 6821 | { |
| 6822 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 6823 | MEGASAS_RELDATE); |
| 6824 | } |
| 6825 | |
| 6826 | static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, NULL); |
| 6827 | |
| 6828 | static ssize_t |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6829 | megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) |
| 6830 | { |
| 6831 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 6832 | } |
| 6833 | |
| 6834 | static DRIVER_ATTR(support_poll_for_event, S_IRUGO, |
| 6835 | megasas_sysfs_show_support_poll_for_event, NULL); |
| 6836 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 6837 | static ssize_t |
| 6838 | megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf) |
| 6839 | { |
| 6840 | return sprintf(buf, "%u\n", support_device_change); |
| 6841 | } |
| 6842 | |
| 6843 | static DRIVER_ATTR(support_device_change, S_IRUGO, |
| 6844 | megasas_sysfs_show_support_device_change, NULL); |
| 6845 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6846 | static ssize_t |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6847 | megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) |
| 6848 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6849 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | static ssize_t |
| 6853 | megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count) |
| 6854 | { |
| 6855 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6856 | |
| 6857 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6858 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 6859 | retval = -EINVAL; |
| 6860 | } |
| 6861 | return retval; |
| 6862 | } |
| 6863 | |
Joe Malicki | 66dca9b | 2008-08-14 17:14:48 -0400 | [diff] [blame] | 6864 | 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] | 6865 | megasas_sysfs_set_dbg_lvl); |
| 6866 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6867 | static void |
| 6868 | megasas_aen_polling(struct work_struct *work) |
| 6869 | { |
| 6870 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6871 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6872 | struct megasas_instance *instance = ev->instance; |
| 6873 | union megasas_evt_class_locale class_locale; |
| 6874 | struct Scsi_Host *host; |
| 6875 | struct scsi_device *sdev1; |
| 6876 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6877 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6878 | int i, j, doscan = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6879 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6880 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6881 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6882 | |
| 6883 | if (!instance) { |
| 6884 | printk(KERN_ERR "invalid instance!\n"); |
| 6885 | kfree(ev); |
| 6886 | return; |
| 6887 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6888 | |
| 6889 | /* Adjust event workqueue thread wait time for VF mode */ |
| 6890 | if (instance->requestorId) |
| 6891 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 6892 | |
| 6893 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6894 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6895 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6896 | instance->ev = NULL; |
| 6897 | host = instance->host; |
| 6898 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 6899 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6900 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6901 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6902 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6903 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6904 | case MR_EVT_PD_REMOVED: |
| 6905 | dcmd_ret = megasas_get_pd_list(instance); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6906 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6907 | doscan = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6908 | break; |
| 6909 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6910 | case MR_EVT_LD_OFFLINE: |
| 6911 | case MR_EVT_CFG_CLEARED: |
| 6912 | case MR_EVT_LD_DELETED: |
| 6913 | case MR_EVT_LD_CREATED: |
| 6914 | if (!instance->requestorId || |
| 6915 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 6916 | 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] | 6917 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6918 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6919 | doscan = SCAN_VD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6920 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6921 | break; |
| 6922 | |
| 6923 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 6924 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 6925 | case MR_EVT_LD_STATE_CHANGE: |
| 6926 | dcmd_ret = megasas_get_pd_list(instance); |
| 6927 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6928 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6929 | break; |
| 6930 | |
| 6931 | if (!instance->requestorId || |
| 6932 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 6933 | dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 6934 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6935 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6936 | break; |
| 6937 | |
| 6938 | doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL; |
| 6939 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 6940 | instance->host->host_no); |
| 6941 | break; |
| 6942 | |
| 6943 | case MR_EVT_CTRL_PROP_CHANGED: |
| 6944 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 6945 | break; |
| 6946 | default: |
| 6947 | doscan = 0; |
| 6948 | break; |
| 6949 | } |
| 6950 | } else { |
| 6951 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 6952 | mutex_unlock(&instance->reset_mutex); |
| 6953 | kfree(ev); |
| 6954 | return; |
| 6955 | } |
| 6956 | |
| 6957 | mutex_unlock(&instance->reset_mutex); |
| 6958 | |
| 6959 | if (doscan & SCAN_PD_CHANNEL) { |
| 6960 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 6961 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 6962 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6963 | sdev1 = scsi_device_lookup(host, i, j, 0); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6964 | if (instance->pd_list[pd_index].driveState == |
| 6965 | MR_PD_STATE_SYSTEM) { |
| 6966 | if (!sdev1) |
| 6967 | scsi_add_device(host, i, j, 0); |
| 6968 | else |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6969 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6970 | } else { |
| 6971 | if (sdev1) { |
| 6972 | scsi_remove_device(sdev1); |
| 6973 | scsi_device_put(sdev1); |
| 6974 | } |
| 6975 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6976 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6977 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6978 | } |
| 6979 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 6980 | if (doscan & SCAN_VD_CHANNEL) { |
| 6981 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 6982 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 6983 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 6984 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 6985 | if (instance->ld_ids[ld_index] != 0xff) { |
| 6986 | if (!sdev1) |
| 6987 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 6988 | else |
| 6989 | scsi_device_put(sdev1); |
| 6990 | } else { |
| 6991 | if (sdev1) { |
| 6992 | scsi_remove_device(sdev1); |
| 6993 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6994 | } |
| 6995 | } |
| 6996 | } |
| 6997 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6998 | } |
| 6999 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7000 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7001 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 7002 | else |
| 7003 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7004 | |
| 7005 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 7006 | class_locale.members.reserved = 0; |
| 7007 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 7008 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7009 | |
| 7010 | if (instance->aen_cmd != NULL) { |
| 7011 | kfree(ev); |
| 7012 | return; |
| 7013 | } |
| 7014 | |
| 7015 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7016 | error = megasas_register_aen(instance, seq_num, |
| 7017 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7018 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7019 | dev_err(&instance->pdev->dev, |
| 7020 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7021 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7022 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7023 | kfree(ev); |
| 7024 | } |
| 7025 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7026 | /** |
| 7027 | * megasas_init - Driver load entry point |
| 7028 | */ |
| 7029 | static int __init megasas_init(void) |
| 7030 | { |
| 7031 | int rval; |
| 7032 | |
| 7033 | /* |
| 7034 | * Announce driver version and other information |
| 7035 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 7036 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7037 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 7038 | spin_lock_init(&poll_aen_lock); |
| 7039 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7040 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7041 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7042 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7043 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 7044 | |
| 7045 | /* |
| 7046 | * Register character device node |
| 7047 | */ |
| 7048 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 7049 | |
| 7050 | if (rval < 0) { |
| 7051 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 7052 | return rval; |
| 7053 | } |
| 7054 | |
| 7055 | megasas_mgmt_majorno = rval; |
| 7056 | |
| 7057 | /* |
| 7058 | * Register ourselves as PCI hotplug module |
| 7059 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 7060 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7061 | |
| 7062 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 7063 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7064 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7065 | } |
| 7066 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7067 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7068 | &driver_attr_version); |
| 7069 | if (rval) |
| 7070 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7071 | |
| 7072 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7073 | &driver_attr_release_date); |
| 7074 | if (rval) |
| 7075 | goto err_dcf_rel_date; |
| 7076 | |
| 7077 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7078 | &driver_attr_support_poll_for_event); |
| 7079 | if (rval) |
| 7080 | goto err_dcf_support_poll_for_event; |
| 7081 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7082 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7083 | &driver_attr_dbg_lvl); |
| 7084 | if (rval) |
| 7085 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7086 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7087 | &driver_attr_support_device_change); |
| 7088 | if (rval) |
| 7089 | goto err_dcf_support_device_change; |
| 7090 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7091 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7092 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7093 | err_dcf_support_device_change: |
| 7094 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7095 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7096 | err_dcf_dbg_lvl: |
| 7097 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7098 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7099 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7100 | driver_remove_file(&megasas_pci_driver.driver, |
| 7101 | &driver_attr_release_date); |
| 7102 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7103 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 7104 | err_dcf_attr_ver: |
| 7105 | pci_unregister_driver(&megasas_pci_driver); |
| 7106 | err_pcidrv: |
| 7107 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 7108 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | /** |
| 7112 | * megasas_exit - Driver unload entry point |
| 7113 | */ |
| 7114 | static void __exit megasas_exit(void) |
| 7115 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7116 | driver_remove_file(&megasas_pci_driver.driver, |
| 7117 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7118 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7119 | &driver_attr_support_poll_for_event); |
| 7120 | driver_remove_file(&megasas_pci_driver.driver, |
| 7121 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7122 | driver_remove_file(&megasas_pci_driver.driver, |
| 7123 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7124 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7125 | |
| 7126 | pci_unregister_driver(&megasas_pci_driver); |
| 7127 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 7128 | } |
| 7129 | |
| 7130 | module_init(megasas_init); |
| 7131 | module_exit(megasas_exit); |