Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1 | /* |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 2 | * Linux MegaRAID driver for SAS based RAID controllers |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 4 | * Copyright (c) 2003-2013 LSI Corporation |
| 5 | * Copyright (c) 2013-2014 Avago Technologies |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 11 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 16 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 19 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 20 | * Authors: Avago Technologies |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 21 | * Sreenivas Bagalkote |
| 22 | * Sumant Patro |
| 23 | * Bo Yang |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 24 | * Adam Radford |
| 25 | * Kashyap Desai <kashyap.desai@avagotech.com> |
| 26 | * Sumit Saxena <sumit.saxena@avagotech.com> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 27 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 28 | * Send feedback to: megaraidlinux.pdl@avagotech.com |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 29 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 30 | * Mail to: Avago Technologies, 350 West Trimble Road, Building 90, |
| 31 | * San Jose, California 95131 |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/types.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/list.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 38 | #include <linux/moduleparam.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/spinlock.h> |
| 41 | #include <linux/interrupt.h> |
| 42 | #include <linux/delay.h> |
| 43 | #include <linux/uio.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 45 | #include <linux/uaccess.h> |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 46 | #include <asm/unaligned.h> |
Al Viro | 4339923 | 2005-10-04 17:36:04 +0100 | [diff] [blame] | 47 | #include <linux/fs.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 48 | #include <linux/compat.h> |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 49 | #include <linux/blkdev.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 50 | #include <linux/mutex.h> |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 51 | #include <linux/poll.h> |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 52 | #include <linux/vmalloc.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 53 | |
| 54 | #include <scsi/scsi.h> |
| 55 | #include <scsi/scsi_cmnd.h> |
| 56 | #include <scsi/scsi_device.h> |
| 57 | #include <scsi/scsi_host.h> |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 58 | #include <scsi/scsi_tcq.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 59 | #include "megaraid_sas_fusion.h" |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 60 | #include "megaraid_sas.h" |
| 61 | |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 62 | /* |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 63 | * Number of sectors per IO command |
| 64 | * Will be set in megasas_init_mfi if user does not provide |
| 65 | */ |
| 66 | static unsigned int max_sectors; |
| 67 | module_param_named(max_sectors, max_sectors, int, 0); |
| 68 | MODULE_PARM_DESC(max_sectors, |
| 69 | "Maximum number of sectors per IO command"); |
| 70 | |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 71 | static int msix_disable; |
| 72 | module_param(msix_disable, int, S_IRUGO); |
| 73 | MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0"); |
| 74 | |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 75 | static unsigned int msix_vectors; |
| 76 | module_param(msix_vectors, int, S_IRUGO); |
| 77 | MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW"); |
| 78 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 79 | static int allow_vf_ioctls; |
| 80 | module_param(allow_vf_ioctls, int, S_IRUGO); |
| 81 | MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0"); |
| 82 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 83 | static unsigned int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH; |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 84 | module_param(throttlequeuedepth, int, S_IRUGO); |
| 85 | MODULE_PARM_DESC(throttlequeuedepth, |
| 86 | "Adapter queue depth when throttled due to I/O timeout. Default: 16"); |
| 87 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 88 | unsigned int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 89 | module_param(resetwaittime, int, S_IRUGO); |
| 90 | MODULE_PARM_DESC(resetwaittime, "Wait time in seconds after I/O timeout " |
| 91 | "before resetting adapter. Default: 180"); |
| 92 | |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 93 | int smp_affinity_enable = 1; |
| 94 | module_param(smp_affinity_enable, int, S_IRUGO); |
| 95 | MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disbale Default: enable(1)"); |
| 96 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 97 | int rdpq_enable = 1; |
| 98 | module_param(rdpq_enable, int, S_IRUGO); |
| 99 | MODULE_PARM_DESC(rdpq_enable, " Allocate reply queue in chunks for large queue depth enable/disable Default: disable(0)"); |
| 100 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 101 | unsigned int dual_qdepth_disable; |
| 102 | module_param(dual_qdepth_disable, int, S_IRUGO); |
| 103 | MODULE_PARM_DESC(dual_qdepth_disable, "Disable dual queue depth feature. Default: 0"); |
| 104 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 105 | unsigned int scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
| 106 | module_param(scmd_timeout, int, S_IRUGO); |
| 107 | MODULE_PARM_DESC(scmd_timeout, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer."); |
| 108 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 109 | MODULE_LICENSE("GPL"); |
| 110 | MODULE_VERSION(MEGASAS_VERSION); |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 111 | MODULE_AUTHOR("megaraidlinux.pdl@avagotech.com"); |
| 112 | MODULE_DESCRIPTION("Avago MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 113 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 114 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 115 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 116 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 117 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 118 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 119 | static int megasas_register_aen(struct megasas_instance *instance, |
| 120 | u32 seq_num, u32 class_locale_word); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 121 | static void megasas_get_pd_info(struct megasas_instance *instance, |
| 122 | struct scsi_device *sdev); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 123 | static int megasas_get_target_prop(struct megasas_instance *instance, |
| 124 | struct scsi_device *sdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 125 | /* |
| 126 | * PCI ID table for all supported controllers |
| 127 | */ |
| 128 | static struct pci_device_id megasas_pci_table[] = { |
| 129 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 130 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 131 | /* xscale IOP */ |
| 132 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 133 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 134 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 135 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 136 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 137 | /* gen2*/ |
| 138 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 139 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 141 | /* skinny*/ |
| 142 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 143 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 144 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 145 | /* xscale IOP, vega */ |
| 146 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 147 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 148 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 149 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 150 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 151 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 152 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 153 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 154 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 155 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 156 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 157 | /* Intruder */ |
| 158 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 159 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 160 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 161 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_53)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 162 | /* VENTURA */ |
| 163 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)}, |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 164 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 165 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)}, |
| 166 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)}, |
| 167 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)}, |
| 168 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER_4PORT)}, |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 169 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 173 | |
| 174 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 175 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 176 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 177 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 178 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 179 | static int megasas_poll_wait_aen; |
| 180 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 181 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 182 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 183 | static u32 support_device_change; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 184 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 185 | /* define lock for aen poll */ |
| 186 | spinlock_t poll_aen_lock; |
| 187 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 188 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 189 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 190 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 191 | static u32 |
| 192 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs); |
| 193 | static int |
| 194 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 195 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 196 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 197 | static u32 |
| 198 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 199 | u32 |
| 200 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 201 | struct scsi_cmnd *scmd); |
| 202 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 203 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 204 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 205 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 206 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 207 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 208 | int initial); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 209 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 210 | megasas_set_dma_mask(struct megasas_instance *instance); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 211 | static int |
| 212 | megasas_alloc_ctrl_mem(struct megasas_instance *instance); |
| 213 | static inline void |
| 214 | megasas_free_ctrl_mem(struct megasas_instance *instance); |
| 215 | static inline int |
| 216 | megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance); |
| 217 | static inline void |
| 218 | megasas_free_ctrl_dma_buffers(struct megasas_instance *instance); |
| 219 | static inline void |
| 220 | megasas_init_ctrl_params(struct megasas_instance *instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 221 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 222 | /** |
| 223 | * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs |
| 224 | * @instance: Adapter soft state |
| 225 | * @dcmd: DCMD frame inside MFI command |
| 226 | * @dma_addr: DMA address of buffer to be passed to FW |
| 227 | * @dma_len: Length of DMA buffer to be passed to FW |
| 228 | * @return: void |
| 229 | */ |
| 230 | void megasas_set_dma_settings(struct megasas_instance *instance, |
| 231 | struct megasas_dcmd_frame *dcmd, |
| 232 | dma_addr_t dma_addr, u32 dma_len) |
| 233 | { |
| 234 | if (instance->consistent_mask_64bit) { |
| 235 | dcmd->sgl.sge64[0].phys_addr = cpu_to_le64(dma_addr); |
| 236 | dcmd->sgl.sge64[0].length = cpu_to_le32(dma_len); |
| 237 | dcmd->flags = cpu_to_le16(dcmd->flags | MFI_FRAME_SGL64); |
| 238 | |
| 239 | } else { |
| 240 | dcmd->sgl.sge32[0].phys_addr = |
| 241 | cpu_to_le32(lower_32_bits(dma_addr)); |
| 242 | dcmd->sgl.sge32[0].length = cpu_to_le32(dma_len); |
| 243 | dcmd->flags = cpu_to_le16(dcmd->flags); |
| 244 | } |
| 245 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 246 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 247 | void |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 248 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 249 | { |
| 250 | instance->instancet->fire_cmd(instance, |
| 251 | cmd->frame_phys_addr, 0, instance->reg_set); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 252 | return; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 253 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 254 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 255 | /** |
| 256 | * megasas_get_cmd - Get a command from the free pool |
| 257 | * @instance: Adapter soft state |
| 258 | * |
| 259 | * Returns a free command from the pool |
| 260 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 261 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 262 | *instance) |
| 263 | { |
| 264 | unsigned long flags; |
| 265 | struct megasas_cmd *cmd = NULL; |
| 266 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 267 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 268 | |
| 269 | if (!list_empty(&instance->cmd_pool)) { |
| 270 | cmd = list_entry((&instance->cmd_pool)->next, |
| 271 | struct megasas_cmd, list); |
| 272 | list_del_init(&cmd->list); |
| 273 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 274 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 275 | } |
| 276 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 277 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 278 | return cmd; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * megasas_return_cmd - Return a cmd to free command pool |
| 283 | * @instance: Adapter soft state |
| 284 | * @cmd: Command packet to be returned to free command pool |
| 285 | */ |
Andi Kleen | 68b4374 | 2017-05-08 15:58:53 -0700 | [diff] [blame] | 286 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 287 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 288 | { |
| 289 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 290 | u32 blk_tags; |
| 291 | struct megasas_cmd_fusion *cmd_fusion; |
| 292 | struct fusion_context *fusion = instance->ctrl_context; |
| 293 | |
| 294 | /* This flag is used only for fusion adapter. |
| 295 | * Wait for Interrupt for Polled mode DCMD |
| 296 | */ |
| 297 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 298 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 299 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 300 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 301 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 302 | if (fusion) { |
| 303 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 304 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 305 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 306 | } |
| 307 | cmd->scmd = NULL; |
| 308 | cmd->frame_count = 0; |
| 309 | cmd->flags = 0; |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 310 | memset(cmd->frame, 0, instance->mfi_frame_size); |
| 311 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 312 | if (!fusion && reset_devices) |
| 313 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 314 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 315 | |
| 316 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 317 | |
| 318 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 319 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 320 | static const char * |
| 321 | format_timestamp(uint32_t timestamp) |
| 322 | { |
| 323 | static char buffer[32]; |
| 324 | |
| 325 | if ((timestamp & 0xff000000) == 0xff000000) |
| 326 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 327 | 0x00ffffff); |
| 328 | else |
| 329 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 330 | return buffer; |
| 331 | } |
| 332 | |
| 333 | static const char * |
| 334 | format_class(int8_t class) |
| 335 | { |
| 336 | static char buffer[6]; |
| 337 | |
| 338 | switch (class) { |
| 339 | case MFI_EVT_CLASS_DEBUG: |
| 340 | return "debug"; |
| 341 | case MFI_EVT_CLASS_PROGRESS: |
| 342 | return "progress"; |
| 343 | case MFI_EVT_CLASS_INFO: |
| 344 | return "info"; |
| 345 | case MFI_EVT_CLASS_WARNING: |
| 346 | return "WARN"; |
| 347 | case MFI_EVT_CLASS_CRITICAL: |
| 348 | return "CRIT"; |
| 349 | case MFI_EVT_CLASS_FATAL: |
| 350 | return "FATAL"; |
| 351 | case MFI_EVT_CLASS_DEAD: |
| 352 | return "DEAD"; |
| 353 | default: |
| 354 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 355 | return buffer; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 361 | * for information. |
| 362 | * @instance: Adapter soft state |
| 363 | */ |
| 364 | static void |
| 365 | megasas_decode_evt(struct megasas_instance *instance) |
| 366 | { |
| 367 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 368 | union megasas_evt_class_locale class_locale; |
| 369 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 370 | |
| 371 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 372 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 373 | le32_to_cpu(evt_detail->seq_num), |
| 374 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 375 | (class_locale.members.locale), |
| 376 | format_class(class_locale.members.class), |
| 377 | evt_detail->description); |
| 378 | } |
| 379 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 380 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 381 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 382 | * (deviceid : 1064R, PERC5) controllers |
| 383 | */ |
| 384 | |
| 385 | /** |
| 386 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 387 | * @regs: MFI register set |
| 388 | */ |
| 389 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 390 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 391 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 392 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 393 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 394 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 395 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 396 | |
| 397 | /* Dummy readl to force pci flush */ |
| 398 | readl(®s->outbound_intr_mask); |
| 399 | } |
| 400 | |
| 401 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 402 | * megasas_disable_intr_xscale -Disables interrupt |
| 403 | * @regs: MFI register set |
| 404 | */ |
| 405 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 406 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 407 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 408 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 409 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 410 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 411 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 412 | writel(mask, ®s->outbound_intr_mask); |
| 413 | /* Dummy readl to force pci flush */ |
| 414 | readl(®s->outbound_intr_mask); |
| 415 | } |
| 416 | |
| 417 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 418 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 419 | * @regs: MFI register set |
| 420 | */ |
| 421 | static u32 |
| 422 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 423 | { |
| 424 | return readl(&(regs)->outbound_msg_0); |
| 425 | } |
| 426 | /** |
| 427 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 428 | * @regs: MFI register set |
| 429 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 430 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 431 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 432 | { |
| 433 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 434 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 435 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 436 | /* |
| 437 | * Check if it is our interrupt |
| 438 | */ |
| 439 | status = readl(®s->outbound_intr_status); |
| 440 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 441 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 442 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 443 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 444 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * Clear the interrupt by writing back the same value |
| 448 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 449 | if (mfiStatus) |
| 450 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 451 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 452 | /* Dummy readl to force pci flush */ |
| 453 | readl(®s->outbound_intr_status); |
| 454 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 455 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /** |
| 459 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 460 | * @frame_phys_addr : Physical address of cmd |
| 461 | * @frame_count : Number of frames for the command |
| 462 | * @regs : MFI register set |
| 463 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 464 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 465 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 466 | dma_addr_t frame_phys_addr, |
| 467 | u32 frame_count, |
| 468 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 469 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 470 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 471 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 472 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 473 | writel((frame_phys_addr >> 3)|(frame_count), |
| 474 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 475 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * megasas_adp_reset_xscale - For controller reset |
| 480 | * @regs: MFI register set |
| 481 | */ |
| 482 | static int |
| 483 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 484 | struct megasas_register_set __iomem *regs) |
| 485 | { |
| 486 | u32 i; |
| 487 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 488 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 489 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 490 | |
| 491 | for (i = 0; i < 3; i++) |
| 492 | msleep(1000); /* sleep for 3 secs */ |
| 493 | pcidata = 0; |
| 494 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 495 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 496 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 497 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 498 | pcidata &= ~0x2; |
| 499 | pci_write_config_dword(instance->pdev, |
| 500 | MFI_1068_PCSR_OFFSET, pcidata); |
| 501 | |
| 502 | for (i = 0; i < 2; i++) |
| 503 | msleep(1000); /* need to wait 2 secs again */ |
| 504 | |
| 505 | pcidata = 0; |
| 506 | pci_read_config_dword(instance->pdev, |
| 507 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 508 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 509 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 510 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 511 | pcidata = 0; |
| 512 | pci_write_config_dword(instance->pdev, |
| 513 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 514 | } |
| 515 | } |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * megasas_check_reset_xscale - For controller reset check |
| 521 | * @regs: MFI register set |
| 522 | */ |
| 523 | static int |
| 524 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 525 | struct megasas_register_set __iomem *regs) |
| 526 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 527 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 528 | (le32_to_cpu(*instance->consumer) == |
| 529 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 530 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 531 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 535 | |
| 536 | .fire_cmd = megasas_fire_cmd_xscale, |
| 537 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 538 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 539 | .clear_intr = megasas_clear_intr_xscale, |
| 540 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 541 | .adp_reset = megasas_adp_reset_xscale, |
| 542 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 543 | .service_isr = megasas_isr, |
| 544 | .tasklet = megasas_complete_cmd_dpc, |
| 545 | .init_adapter = megasas_init_adapter_mfi, |
| 546 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 547 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 548 | }; |
| 549 | |
| 550 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 551 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 552 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 553 | */ |
| 554 | |
| 555 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 556 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 557 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 558 | */ |
| 559 | |
| 560 | /** |
| 561 | * megasas_enable_intr_ppc - Enables interrupts |
| 562 | * @regs: MFI register set |
| 563 | */ |
| 564 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 565 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 566 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 567 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 568 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 569 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 570 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 571 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 572 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 573 | |
| 574 | /* Dummy readl to force pci flush */ |
| 575 | readl(®s->outbound_intr_mask); |
| 576 | } |
| 577 | |
| 578 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 579 | * megasas_disable_intr_ppc - Disable interrupt |
| 580 | * @regs: MFI register set |
| 581 | */ |
| 582 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 583 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 584 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 585 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 586 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 587 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 588 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 589 | writel(mask, ®s->outbound_intr_mask); |
| 590 | /* Dummy readl to force pci flush */ |
| 591 | readl(®s->outbound_intr_mask); |
| 592 | } |
| 593 | |
| 594 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 595 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 596 | * @regs: MFI register set |
| 597 | */ |
| 598 | static u32 |
| 599 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 600 | { |
| 601 | return readl(&(regs)->outbound_scratch_pad); |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 606 | * @regs: MFI register set |
| 607 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 608 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 609 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 610 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 611 | u32 status, mfiStatus = 0; |
| 612 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 613 | /* |
| 614 | * Check if it is our interrupt |
| 615 | */ |
| 616 | status = readl(®s->outbound_intr_status); |
| 617 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 618 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 619 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 620 | |
| 621 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 622 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 623 | |
| 624 | /* |
| 625 | * Clear the interrupt by writing back the same value |
| 626 | */ |
| 627 | writel(status, ®s->outbound_doorbell_clear); |
| 628 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 629 | /* Dummy readl to force pci flush */ |
| 630 | readl(®s->outbound_doorbell_clear); |
| 631 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 632 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 633 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 634 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 635 | /** |
| 636 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 637 | * @frame_phys_addr : Physical address of cmd |
| 638 | * @frame_count : Number of frames for the command |
| 639 | * @regs : MFI register set |
| 640 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 641 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 642 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 643 | dma_addr_t frame_phys_addr, |
| 644 | u32 frame_count, |
| 645 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 646 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 647 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 648 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 649 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 650 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 651 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 652 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 653 | } |
| 654 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 655 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 656 | * megasas_check_reset_ppc - For controller reset check |
| 657 | * @regs: MFI register set |
| 658 | */ |
| 659 | static int |
| 660 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 661 | struct megasas_register_set __iomem *regs) |
| 662 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 663 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 664 | return 1; |
| 665 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 666 | return 0; |
| 667 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 668 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 669 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 670 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 671 | .fire_cmd = megasas_fire_cmd_ppc, |
| 672 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 673 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 674 | .clear_intr = megasas_clear_intr_ppc, |
| 675 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 676 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 677 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 678 | .service_isr = megasas_isr, |
| 679 | .tasklet = megasas_complete_cmd_dpc, |
| 680 | .init_adapter = megasas_init_adapter_mfi, |
| 681 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 682 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 683 | }; |
| 684 | |
| 685 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 686 | * megasas_enable_intr_skinny - Enables interrupts |
| 687 | * @regs: MFI register set |
| 688 | */ |
| 689 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 690 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 691 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 692 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 693 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 694 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 695 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 696 | |
| 697 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 698 | |
| 699 | /* Dummy readl to force pci flush */ |
| 700 | readl(®s->outbound_intr_mask); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * megasas_disable_intr_skinny - Disables interrupt |
| 705 | * @regs: MFI register set |
| 706 | */ |
| 707 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 708 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 709 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 710 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 711 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 712 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 713 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 714 | writel(mask, ®s->outbound_intr_mask); |
| 715 | /* Dummy readl to force pci flush */ |
| 716 | readl(®s->outbound_intr_mask); |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 721 | * @regs: MFI register set |
| 722 | */ |
| 723 | static u32 |
| 724 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 725 | { |
| 726 | return readl(&(regs)->outbound_scratch_pad); |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 731 | * @regs: MFI register set |
| 732 | */ |
| 733 | static int |
| 734 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 735 | { |
| 736 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 737 | u32 mfiStatus = 0; |
| 738 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 739 | /* |
| 740 | * Check if it is our interrupt |
| 741 | */ |
| 742 | status = readl(®s->outbound_intr_status); |
| 743 | |
| 744 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 745 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 749 | * Check if it is our interrupt |
| 750 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 751 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 752 | MFI_STATE_FAULT) { |
| 753 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 754 | } else |
| 755 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 756 | |
| 757 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 758 | * Clear the interrupt by writing back the same value |
| 759 | */ |
| 760 | writel(status, ®s->outbound_intr_status); |
| 761 | |
| 762 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 763 | * dummy read to flush PCI |
| 764 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 765 | readl(®s->outbound_intr_status); |
| 766 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 767 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /** |
| 771 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 772 | * @frame_phys_addr : Physical address of cmd |
| 773 | * @frame_count : Number of frames for the command |
| 774 | * @regs : MFI register set |
| 775 | */ |
| 776 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 777 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 778 | dma_addr_t frame_phys_addr, |
| 779 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 780 | struct megasas_register_set __iomem *regs) |
| 781 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 782 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 783 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 784 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 785 | writel(upper_32_bits(frame_phys_addr), |
| 786 | &(regs)->inbound_high_queue_port); |
| 787 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 788 | &(regs)->inbound_low_queue_port); |
Tomas Henzl | b99dbe5 | 2016-02-01 15:12:04 +0100 | [diff] [blame] | 789 | mmiowb(); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 790 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 791 | } |
| 792 | |
| 793 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 794 | * megasas_check_reset_skinny - For controller reset check |
| 795 | * @regs: MFI register set |
| 796 | */ |
| 797 | static int |
| 798 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 799 | struct megasas_register_set __iomem *regs) |
| 800 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 801 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 802 | return 1; |
| 803 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 804 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 808 | |
| 809 | .fire_cmd = megasas_fire_cmd_skinny, |
| 810 | .enable_intr = megasas_enable_intr_skinny, |
| 811 | .disable_intr = megasas_disable_intr_skinny, |
| 812 | .clear_intr = megasas_clear_intr_skinny, |
| 813 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 814 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 815 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 816 | .service_isr = megasas_isr, |
| 817 | .tasklet = megasas_complete_cmd_dpc, |
| 818 | .init_adapter = megasas_init_adapter_mfi, |
| 819 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 820 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 821 | }; |
| 822 | |
| 823 | |
| 824 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 825 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 826 | * controllers |
| 827 | */ |
| 828 | |
| 829 | /** |
| 830 | * megasas_enable_intr_gen2 - Enables interrupts |
| 831 | * @regs: MFI register set |
| 832 | */ |
| 833 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 834 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 835 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 836 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 837 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 838 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 839 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 840 | |
| 841 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 842 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 843 | |
| 844 | /* Dummy readl to force pci flush */ |
| 845 | readl(®s->outbound_intr_mask); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * megasas_disable_intr_gen2 - Disables interrupt |
| 850 | * @regs: MFI register set |
| 851 | */ |
| 852 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 853 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 854 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 855 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 856 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 857 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 858 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 859 | writel(mask, ®s->outbound_intr_mask); |
| 860 | /* Dummy readl to force pci flush */ |
| 861 | readl(®s->outbound_intr_mask); |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 866 | * @regs: MFI register set |
| 867 | */ |
| 868 | static u32 |
| 869 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 870 | { |
| 871 | return readl(&(regs)->outbound_scratch_pad); |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 876 | * @regs: MFI register set |
| 877 | */ |
| 878 | static int |
| 879 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 880 | { |
| 881 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 882 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 883 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 884 | /* |
| 885 | * Check if it is our interrupt |
| 886 | */ |
| 887 | status = readl(®s->outbound_intr_status); |
| 888 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 889 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 890 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 891 | } |
| 892 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 893 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 894 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 895 | |
| 896 | /* |
| 897 | * Clear the interrupt by writing back the same value |
| 898 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 899 | if (mfiStatus) |
| 900 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 901 | |
| 902 | /* Dummy readl to force pci flush */ |
| 903 | readl(®s->outbound_intr_status); |
| 904 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 905 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 906 | } |
| 907 | /** |
| 908 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 909 | * @frame_phys_addr : Physical address of cmd |
| 910 | * @frame_count : Number of frames for the command |
| 911 | * @regs : MFI register set |
| 912 | */ |
| 913 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 914 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 915 | dma_addr_t frame_phys_addr, |
| 916 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 917 | struct megasas_register_set __iomem *regs) |
| 918 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 919 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 920 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 921 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 922 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 923 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 924 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * megasas_adp_reset_gen2 - For controller reset |
| 929 | * @regs: MFI register set |
| 930 | */ |
| 931 | static int |
| 932 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 933 | struct megasas_register_set __iomem *reg_set) |
| 934 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 935 | u32 retry = 0 ; |
| 936 | u32 HostDiag; |
| 937 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 938 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 939 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 940 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 941 | seq_offset = ®_set->fusion_seq_offset; |
| 942 | hostdiag_offset = ®_set->fusion_host_diag; |
| 943 | } |
| 944 | |
| 945 | writel(0, seq_offset); |
| 946 | writel(4, seq_offset); |
| 947 | writel(0xb, seq_offset); |
| 948 | writel(2, seq_offset); |
| 949 | writel(7, seq_offset); |
| 950 | writel(0xd, seq_offset); |
| 951 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 952 | msleep(1000); |
| 953 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 954 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 955 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 956 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 957 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 958 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 959 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 960 | retry, HostDiag); |
| 961 | |
| 962 | if (retry++ >= 100) |
| 963 | return 1; |
| 964 | |
| 965 | } |
| 966 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 967 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 968 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 969 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 970 | |
| 971 | ssleep(10); |
| 972 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 973 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 974 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 975 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 976 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 977 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 978 | retry, HostDiag); |
| 979 | |
| 980 | if (retry++ >= 1000) |
| 981 | return 1; |
| 982 | |
| 983 | } |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | /** |
| 988 | * megasas_check_reset_gen2 - For controller reset check |
| 989 | * @regs: MFI register set |
| 990 | */ |
| 991 | static int |
| 992 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 993 | struct megasas_register_set __iomem *regs) |
| 994 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 995 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 996 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 997 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 998 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 1002 | |
| 1003 | .fire_cmd = megasas_fire_cmd_gen2, |
| 1004 | .enable_intr = megasas_enable_intr_gen2, |
| 1005 | .disable_intr = megasas_disable_intr_gen2, |
| 1006 | .clear_intr = megasas_clear_intr_gen2, |
| 1007 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1008 | .adp_reset = megasas_adp_reset_gen2, |
| 1009 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1010 | .service_isr = megasas_isr, |
| 1011 | .tasklet = megasas_complete_cmd_dpc, |
| 1012 | .init_adapter = megasas_init_adapter_mfi, |
| 1013 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 1014 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1015 | }; |
| 1016 | |
| 1017 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1018 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1019 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1020 | */ |
| 1021 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1022 | /* |
| 1023 | * Template added for TB (Fusion) |
| 1024 | */ |
| 1025 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 1026 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1027 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1028 | * megasas_issue_polled - Issues a polling command |
| 1029 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1030 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1031 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1032 | * 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] | 1033 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1034 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1035 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 1036 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1037 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 1038 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1039 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1040 | 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] | 1041 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1042 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1043 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1044 | __func__, __LINE__); |
| 1045 | return DCMD_NOT_FIRED; |
| 1046 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1047 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1048 | instance->instancet->issue_dcmd(instance, cmd); |
| 1049 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1050 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1051 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1056 | * @instance: Adapter soft state |
| 1057 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1058 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1059 | * |
| 1060 | * 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] | 1061 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1062 | * Used to issue ioctl commands. |
| 1063 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1064 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1065 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1066 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1067 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1068 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1069 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1070 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1071 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1072 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1073 | __func__, __LINE__); |
| 1074 | return DCMD_NOT_FIRED; |
| 1075 | } |
| 1076 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1077 | instance->instancet->issue_dcmd(instance, cmd); |
| 1078 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1079 | if (timeout) { |
| 1080 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1081 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1082 | if (!ret) { |
| 1083 | dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n", |
| 1084 | __func__, __LINE__); |
| 1085 | return DCMD_TIMEOUT; |
| 1086 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1087 | } else |
| 1088 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1089 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1090 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1091 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1092 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | /** |
| 1096 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1097 | * @instance: Adapter soft state |
| 1098 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1099 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1100 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1101 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1102 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1103 | * cmd and waits for return status. |
| 1104 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1105 | */ |
| 1106 | static int |
| 1107 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1108 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1109 | { |
| 1110 | struct megasas_cmd *cmd; |
| 1111 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1112 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1113 | |
| 1114 | cmd = megasas_get_cmd(instance); |
| 1115 | |
| 1116 | if (!cmd) |
| 1117 | return -1; |
| 1118 | |
| 1119 | abort_fr = &cmd->frame->abort; |
| 1120 | |
| 1121 | /* |
| 1122 | * Prepare and issue the abort frame |
| 1123 | */ |
| 1124 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1125 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1126 | abort_fr->flags = cpu_to_le16(0); |
| 1127 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1128 | abort_fr->abort_mfi_phys_addr_lo = |
| 1129 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1130 | abort_fr->abort_mfi_phys_addr_hi = |
| 1131 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1132 | |
| 1133 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1134 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1135 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1136 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1137 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1138 | __func__, __LINE__); |
| 1139 | return DCMD_NOT_FIRED; |
| 1140 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1141 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1142 | instance->instancet->issue_dcmd(instance, cmd); |
| 1143 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1144 | if (timeout) { |
| 1145 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1146 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1147 | if (!ret) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1148 | dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n", |
| 1149 | __func__, __LINE__); |
| 1150 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1151 | } |
| 1152 | } else |
| 1153 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1154 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1155 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1156 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1157 | |
| 1158 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1159 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1160 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /** |
| 1164 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1165 | * @instance: Adapter soft state |
| 1166 | * @scp: SCSI command from the mid-layer |
| 1167 | * @mfi_sgl: SGL to be filled in |
| 1168 | * |
| 1169 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1170 | * it returnes -1. |
| 1171 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1172 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1173 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1174 | union megasas_sgl *mfi_sgl) |
| 1175 | { |
| 1176 | int i; |
| 1177 | int sge_count; |
| 1178 | struct scatterlist *os_sgl; |
| 1179 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1180 | sge_count = scsi_dma_map(scp); |
| 1181 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1182 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1183 | if (sge_count) { |
| 1184 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1185 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1186 | 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] | 1187 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1188 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1189 | return sge_count; |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1194 | * @instance: Adapter soft state |
| 1195 | * @scp: SCSI command from the mid-layer |
| 1196 | * @mfi_sgl: SGL to be filled in |
| 1197 | * |
| 1198 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1199 | * it returnes -1. |
| 1200 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1201 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1202 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1203 | union megasas_sgl *mfi_sgl) |
| 1204 | { |
| 1205 | int i; |
| 1206 | int sge_count; |
| 1207 | struct scatterlist *os_sgl; |
| 1208 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1209 | sge_count = scsi_dma_map(scp); |
| 1210 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1211 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1212 | if (sge_count) { |
| 1213 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1214 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1215 | 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] | 1216 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1217 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1218 | return sge_count; |
| 1219 | } |
| 1220 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1221 | /** |
| 1222 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1223 | * @instance: Adapter soft state |
| 1224 | * @scp: SCSI command from the mid-layer |
| 1225 | * @mfi_sgl: SGL to be filled in |
| 1226 | * |
| 1227 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1228 | * it returnes -1. |
| 1229 | */ |
| 1230 | static int |
| 1231 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1232 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1233 | { |
| 1234 | int i; |
| 1235 | int sge_count; |
| 1236 | struct scatterlist *os_sgl; |
| 1237 | |
| 1238 | sge_count = scsi_dma_map(scp); |
| 1239 | |
| 1240 | if (sge_count) { |
| 1241 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1242 | mfi_sgl->sge_skinny[i].length = |
| 1243 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1244 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1245 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1246 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | return sge_count; |
| 1250 | } |
| 1251 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1252 | /** |
| 1253 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1254 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1255 | * @sge_count : number of sg elements |
| 1256 | * |
| 1257 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1258 | */ |
| 1259 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1260 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1261 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1262 | { |
| 1263 | int num_cnt; |
| 1264 | int sge_bytes; |
| 1265 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1266 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1267 | |
| 1268 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1269 | sizeof(struct megasas_sge32); |
| 1270 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1271 | if (instance->flag_ieee) { |
| 1272 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1273 | } |
| 1274 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1275 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1276 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1277 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1278 | * 1 SGEs for 64-bit SGLs and |
| 1279 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1280 | */ |
| 1281 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1282 | if (instance->flag_ieee == 1) { |
| 1283 | num_cnt = sge_count - 1; |
| 1284 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1285 | num_cnt = sge_count - 1; |
| 1286 | else |
| 1287 | num_cnt = sge_count - 2; |
| 1288 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1289 | if (instance->flag_ieee == 1) { |
| 1290 | num_cnt = sge_count - 1; |
| 1291 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1292 | num_cnt = sge_count - 2; |
| 1293 | else |
| 1294 | num_cnt = sge_count - 3; |
| 1295 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1296 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1297 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1298 | sge_bytes = sge_sz * num_cnt; |
| 1299 | |
| 1300 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1301 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1302 | } |
| 1303 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1304 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1305 | |
| 1306 | if (frame_count > 7) |
| 1307 | frame_count = 8; |
| 1308 | return frame_count; |
| 1309 | } |
| 1310 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1311 | /** |
| 1312 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1313 | * @instance: Adapter soft state |
| 1314 | * @scp: SCSI command |
| 1315 | * @cmd: Command to be prepared in |
| 1316 | * |
| 1317 | * This function prepares CDB commands. These are typcially pass-through |
| 1318 | * commands to the devices. |
| 1319 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1320 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1321 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1322 | struct megasas_cmd *cmd) |
| 1323 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1324 | u32 is_logical; |
| 1325 | u32 device_id; |
| 1326 | u16 flags = 0; |
| 1327 | struct megasas_pthru_frame *pthru; |
| 1328 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1329 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1330 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1331 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1332 | |
| 1333 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1334 | flags = MFI_FRAME_DIR_WRITE; |
| 1335 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1336 | flags = MFI_FRAME_DIR_READ; |
| 1337 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1338 | flags = MFI_FRAME_DIR_NONE; |
| 1339 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1340 | if (instance->flag_ieee == 1) { |
| 1341 | flags |= MFI_FRAME_IEEE; |
| 1342 | } |
| 1343 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1344 | /* |
| 1345 | * Prepare the DCDB frame |
| 1346 | */ |
| 1347 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1348 | pthru->cmd_status = 0x0; |
| 1349 | pthru->scsi_status = 0x0; |
| 1350 | pthru->target_id = device_id; |
| 1351 | pthru->lun = scp->device->lun; |
| 1352 | pthru->cdb_len = scp->cmd_len; |
| 1353 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1354 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1355 | pthru->flags = cpu_to_le16(flags); |
| 1356 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1357 | |
| 1358 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1359 | |
| 1360 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1361 | * If the command is for the tape device, set the |
| 1362 | * pthru timeout to the os layer timeout value. |
| 1363 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1364 | if (scp->device->type == TYPE_TAPE) { |
| 1365 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1366 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1367 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1368 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1372 | * Construct SGL |
| 1373 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1374 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1375 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1376 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1377 | &pthru->sgl); |
| 1378 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1379 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1380 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1381 | &pthru->sgl); |
| 1382 | } else |
| 1383 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1384 | &pthru->sgl); |
| 1385 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1386 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1387 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1388 | pthru->sge_count); |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1392 | /* |
| 1393 | * Sense info specific |
| 1394 | */ |
| 1395 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1396 | pthru->sense_buf_phys_addr_hi = |
| 1397 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1398 | pthru->sense_buf_phys_addr_lo = |
| 1399 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1400 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1401 | /* |
| 1402 | * Compute the total number of frames this command consumes. FW uses |
| 1403 | * this number to pull sufficient number of frames from host memory. |
| 1404 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1405 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1406 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1407 | |
| 1408 | return cmd->frame_count; |
| 1409 | } |
| 1410 | |
| 1411 | /** |
| 1412 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1413 | * @instance: Adapter soft state |
| 1414 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1415 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1416 | * |
| 1417 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1418 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1419 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1420 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1421 | struct megasas_cmd *cmd) |
| 1422 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1423 | u32 device_id; |
| 1424 | u8 sc = scp->cmnd[0]; |
| 1425 | u16 flags = 0; |
| 1426 | struct megasas_io_frame *ldio; |
| 1427 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1428 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1429 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1430 | |
| 1431 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1432 | flags = MFI_FRAME_DIR_WRITE; |
| 1433 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1434 | flags = MFI_FRAME_DIR_READ; |
| 1435 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1436 | if (instance->flag_ieee == 1) { |
| 1437 | flags |= MFI_FRAME_IEEE; |
| 1438 | } |
| 1439 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1440 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1441 | * 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] | 1442 | */ |
| 1443 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1444 | ldio->cmd_status = 0x0; |
| 1445 | ldio->scsi_status = 0x0; |
| 1446 | ldio->target_id = device_id; |
| 1447 | ldio->timeout = 0; |
| 1448 | ldio->reserved_0 = 0; |
| 1449 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1450 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1451 | ldio->start_lba_hi = 0; |
| 1452 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1453 | |
| 1454 | /* |
| 1455 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1456 | */ |
| 1457 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1458 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1459 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1460 | ((u32) scp->cmnd[2] << 8) | |
| 1461 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1462 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1463 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /* |
| 1467 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1468 | */ |
| 1469 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1470 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1471 | ((u32) scp->cmnd[7] << 8)); |
| 1472 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1473 | ((u32) scp->cmnd[3] << 16) | |
| 1474 | ((u32) scp->cmnd[4] << 8) | |
| 1475 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /* |
| 1479 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1480 | */ |
| 1481 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1482 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1483 | ((u32) scp->cmnd[7] << 16) | |
| 1484 | ((u32) scp->cmnd[8] << 8) | |
| 1485 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1486 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1487 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1488 | ((u32) scp->cmnd[3] << 16) | |
| 1489 | ((u32) scp->cmnd[4] << 8) | |
| 1490 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /* |
| 1494 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1495 | */ |
| 1496 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1497 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1498 | ((u32) scp->cmnd[11] << 16) | |
| 1499 | ((u32) scp->cmnd[12] << 8) | |
| 1500 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1501 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1502 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1503 | ((u32) scp->cmnd[7] << 16) | |
| 1504 | ((u32) scp->cmnd[8] << 8) | |
| 1505 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1506 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1507 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1508 | ((u32) scp->cmnd[3] << 16) | |
| 1509 | ((u32) scp->cmnd[4] << 8) | |
| 1510 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1511 | |
| 1512 | } |
| 1513 | |
| 1514 | /* |
| 1515 | * Construct SGL |
| 1516 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1517 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1518 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1519 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1520 | &ldio->sgl); |
| 1521 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1522 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1523 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1524 | } else |
| 1525 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1526 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1527 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1528 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1529 | ldio->sge_count); |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1533 | /* |
| 1534 | * Sense info specific |
| 1535 | */ |
| 1536 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1537 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1538 | 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] | 1539 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1540 | /* |
| 1541 | * Compute the total number of frames this command consumes. FW uses |
| 1542 | * this number to pull sufficient number of frames from host memory. |
| 1543 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1544 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1545 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1546 | |
| 1547 | return cmd->frame_count; |
| 1548 | } |
| 1549 | |
| 1550 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1551 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1552 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1553 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1554 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1555 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1556 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1557 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1558 | int ret; |
| 1559 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1560 | switch (cmd->cmnd[0]) { |
| 1561 | case READ_10: |
| 1562 | case WRITE_10: |
| 1563 | case READ_12: |
| 1564 | case WRITE_12: |
| 1565 | case READ_6: |
| 1566 | case WRITE_6: |
| 1567 | case READ_16: |
| 1568 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1569 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1570 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1571 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1572 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1573 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1574 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1575 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1576 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1577 | } |
| 1578 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1579 | /** |
| 1580 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1581 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1582 | * @instance: Adapter soft state |
| 1583 | */ |
| 1584 | static inline void |
| 1585 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1586 | { |
| 1587 | struct megasas_cmd *cmd; |
| 1588 | int i,n; |
| 1589 | union megasas_sgl *mfi_sgl; |
| 1590 | struct megasas_io_frame *ldio; |
| 1591 | struct megasas_pthru_frame *pthru; |
| 1592 | u32 sgcount; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 1593 | u16 max_cmd = instance->max_fw_cmds; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1594 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1595 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1596 | 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] | 1597 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1598 | 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] | 1599 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1600 | 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] | 1601 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1602 | 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] | 1603 | for (i = 0; i < max_cmd; i++) { |
| 1604 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1605 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1606 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1607 | 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] | 1608 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1609 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1610 | mfi_sgl = &ldio->sgl; |
| 1611 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1612 | 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] | 1613 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1614 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1615 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1616 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1617 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1618 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1619 | mfi_sgl = &pthru->sgl; |
| 1620 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1621 | 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] | 1622 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1623 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1624 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1625 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1626 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1627 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1628 | for (n = 0; n < sgcount; n++) { |
| 1629 | if (IS_DMA64) |
| 1630 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1631 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1632 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1633 | else |
| 1634 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1635 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1636 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1637 | } |
| 1638 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1639 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1640 | 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] | 1641 | for (i = 0; i < max_cmd; i++) { |
| 1642 | |
| 1643 | cmd = instance->cmd_list[i]; |
| 1644 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1645 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1646 | 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] | 1647 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1648 | 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] | 1649 | } |
| 1650 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1651 | u32 |
| 1652 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1653 | struct scsi_cmnd *scmd) |
| 1654 | { |
| 1655 | struct megasas_cmd *cmd; |
| 1656 | u32 frame_count; |
| 1657 | |
| 1658 | cmd = megasas_get_cmd(instance); |
| 1659 | if (!cmd) |
| 1660 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1661 | |
| 1662 | /* |
| 1663 | * Logical drive command |
| 1664 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1665 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1666 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1667 | else |
| 1668 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1669 | |
| 1670 | if (!frame_count) |
| 1671 | goto out_return_cmd; |
| 1672 | |
| 1673 | cmd->scmd = scmd; |
| 1674 | scmd->SCp.ptr = (char *)cmd; |
| 1675 | |
| 1676 | /* |
| 1677 | * Issue the command to the FW |
| 1678 | */ |
| 1679 | atomic_inc(&instance->fw_outstanding); |
| 1680 | |
| 1681 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1682 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1683 | |
| 1684 | return 0; |
| 1685 | out_return_cmd: |
| 1686 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1687 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1691 | /** |
| 1692 | * megasas_queue_command - Queue entry point |
| 1693 | * @scmd: SCSI command to be queued |
| 1694 | * @done: Callback entry point |
| 1695 | */ |
| 1696 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1697 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1698 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1699 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1700 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1701 | |
| 1702 | instance = (struct megasas_instance *) |
| 1703 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1704 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1705 | if (instance->unload == 1) { |
| 1706 | scmd->result = DID_NO_CONNECT << 16; |
| 1707 | scmd->scsi_done(scmd); |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1711 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1712 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1713 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1714 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1715 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1716 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1717 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 1718 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1719 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1720 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1721 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1722 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1723 | return 0; |
| 1724 | } |
| 1725 | } |
| 1726 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1727 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1728 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1729 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1730 | return 0; |
| 1731 | } |
| 1732 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1733 | mr_device_priv_data = scmd->device->hostdata; |
| 1734 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1735 | scmd->result = DID_NO_CONNECT << 16; |
| 1736 | scmd->scsi_done(scmd); |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1740 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1741 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1742 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1743 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1744 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1745 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1746 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1747 | scmd->result = 0; |
| 1748 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1749 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1750 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1751 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1752 | scmd->result = DID_BAD_TARGET << 16; |
| 1753 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1756 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1757 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1758 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1759 | scmd->result = DID_OK << 16; |
| 1760 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1761 | } |
| 1762 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1763 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1764 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1765 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1766 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1767 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1768 | } |
| 1769 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1770 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1771 | { |
| 1772 | int i; |
| 1773 | |
| 1774 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1775 | |
| 1776 | if ((megasas_mgmt_info.instance[i]) && |
| 1777 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1778 | return megasas_mgmt_info.instance[i]; |
| 1779 | } |
| 1780 | |
| 1781 | return NULL; |
| 1782 | } |
| 1783 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1784 | /* |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1785 | * megasas_set_dynamic_target_properties - |
| 1786 | * Device property set by driver may not be static and it is required to be |
| 1787 | * updated after OCR |
| 1788 | * |
| 1789 | * set tm_capable. |
| 1790 | * set dma alignment (only for eedp protection enable vd). |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1791 | * |
| 1792 | * @sdev: OS provided scsi device |
| 1793 | * |
| 1794 | * Returns void |
| 1795 | */ |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1796 | void megasas_set_dynamic_target_properties(struct scsi_device *sdev) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1797 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1798 | u16 pd_index = 0, ld; |
| 1799 | u32 device_id; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1800 | struct megasas_instance *instance; |
| 1801 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1802 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1803 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1804 | struct MR_LD_RAID *raid; |
| 1805 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1806 | |
| 1807 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1808 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1809 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1810 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1811 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1812 | return; |
| 1813 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1814 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1815 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1816 | + sdev->id; |
| 1817 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1818 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1819 | if (ld >= instance->fw_supported_vd_count) |
| 1820 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1821 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1822 | |
| 1823 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1824 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1825 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1826 | mr_device_priv_data->is_tm_capable = |
| 1827 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1828 | } else if (instance->use_seqnum_jbod_fp) { |
| 1829 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1830 | sdev->id; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1831 | pd_sync = (void *)fusion->pd_seq_sync |
| 1832 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1833 | mr_device_priv_data->is_tm_capable = |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1834 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1835 | } |
| 1836 | } |
| 1837 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1838 | /* |
| 1839 | * megasas_set_nvme_device_properties - |
| 1840 | * set nomerges=2 |
| 1841 | * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K). |
| 1842 | * set maximum io transfer = MDTS of NVME device provided by MR firmware. |
| 1843 | * |
| 1844 | * MR firmware provides value in KB. Caller of this function converts |
| 1845 | * kb into bytes. |
| 1846 | * |
| 1847 | * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size, |
| 1848 | * MR firmware provides value 128 as (32 * 4K) = 128K. |
| 1849 | * |
| 1850 | * @sdev: scsi device |
| 1851 | * @max_io_size: maximum io transfer size |
| 1852 | * |
| 1853 | */ |
| 1854 | static inline void |
| 1855 | megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1856 | { |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1857 | struct megasas_instance *instance; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1858 | u32 mr_nvme_pg_size; |
| 1859 | |
| 1860 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 1861 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1862 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1863 | |
| 1864 | blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512)); |
| 1865 | |
| 1866 | queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue); |
| 1867 | blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1); |
| 1868 | } |
| 1869 | |
| 1870 | |
| 1871 | /* |
| 1872 | * megasas_set_static_target_properties - |
| 1873 | * Device property set by driver are static and it is not required to be |
| 1874 | * updated after OCR. |
| 1875 | * |
| 1876 | * set io timeout |
| 1877 | * set device queue depth |
| 1878 | * set nvme device properties. see - megasas_set_nvme_device_properties |
| 1879 | * |
| 1880 | * @sdev: scsi device |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1881 | * @is_target_prop true, if fw provided target properties. |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1882 | */ |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1883 | static void megasas_set_static_target_properties(struct scsi_device *sdev, |
| 1884 | bool is_target_prop) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1885 | { |
| 1886 | u16 target_index = 0; |
| 1887 | u8 interface_type; |
| 1888 | u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN; |
| 1889 | u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1890 | u32 tgt_device_qd; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1891 | struct megasas_instance *instance; |
| 1892 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1893 | |
| 1894 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1895 | mr_device_priv_data = sdev->hostdata; |
| 1896 | interface_type = mr_device_priv_data->interface_type; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1897 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1898 | /* |
| 1899 | * The RAID firmware may require extended timeouts. |
| 1900 | */ |
| 1901 | blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1902 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1903 | target_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1904 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1905 | switch (interface_type) { |
| 1906 | case SAS_PD: |
| 1907 | device_qd = MEGASAS_SAS_QD; |
| 1908 | break; |
| 1909 | case SATA_PD: |
| 1910 | device_qd = MEGASAS_SATA_QD; |
| 1911 | break; |
| 1912 | case NVME_PD: |
| 1913 | device_qd = MEGASAS_NVME_QD; |
| 1914 | break; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1915 | } |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1916 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1917 | if (is_target_prop) { |
| 1918 | tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth); |
| 1919 | if (tgt_device_qd && |
| 1920 | (tgt_device_qd <= instance->host->can_queue)) |
| 1921 | device_qd = tgt_device_qd; |
| 1922 | |
| 1923 | /* max_io_size_kb will be set to non zero for |
| 1924 | * nvme based vd and syspd. |
| 1925 | */ |
| 1926 | max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb); |
| 1927 | } |
| 1928 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1929 | if (instance->nvme_page_size && max_io_size_kb) |
| 1930 | megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10)); |
| 1931 | |
| 1932 | scsi_change_queue_depth(sdev, device_qd); |
| 1933 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1934 | } |
| 1935 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1936 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1937 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1938 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1939 | u16 pd_index = 0; |
| 1940 | struct megasas_instance *instance; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1941 | int ret_target_prop = DCMD_FAILED; |
| 1942 | bool is_target_prop = false; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1943 | |
| 1944 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1945 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1946 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1947 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1948 | sdev->id; |
| 1949 | if (instance->pd_list[pd_index].driveState != |
| 1950 | MR_PD_STATE_SYSTEM) |
| 1951 | return -ENXIO; |
| 1952 | } |
| 1953 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1954 | |
Shivasharan S | 149c575 | 2018-01-05 05:27:42 -0800 | [diff] [blame] | 1955 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1956 | /* Send DCMD to Firmware and cache the information */ |
| 1957 | if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev)) |
| 1958 | megasas_get_pd_info(instance, sdev); |
| 1959 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1960 | /* Some ventura firmware may not have instance->nvme_page_size set. |
| 1961 | * Do not send MR_DCMD_DRV_GET_TARGET_PROP |
| 1962 | */ |
| 1963 | if ((instance->tgt_prop) && (instance->nvme_page_size)) |
| 1964 | ret_target_prop = megasas_get_target_prop(instance, sdev); |
| 1965 | |
| 1966 | is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false; |
| 1967 | megasas_set_static_target_properties(sdev, is_target_prop); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1968 | |
Shivasharan S | 149c575 | 2018-01-05 05:27:42 -0800 | [diff] [blame] | 1969 | mutex_unlock(&instance->reset_mutex); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1970 | |
| 1971 | /* This sdev property may change post OCR */ |
| 1972 | megasas_set_dynamic_target_properties(sdev); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1973 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1974 | return 0; |
| 1975 | } |
| 1976 | |
| 1977 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1978 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1979 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1980 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1981 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1982 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1983 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1984 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1985 | /* |
| 1986 | * Open the OS scan to the SYSTEM PD |
| 1987 | */ |
| 1988 | pd_index = |
| 1989 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1990 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1991 | if ((instance->pd_list_not_supported || |
| 1992 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1993 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1994 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1995 | } |
| 1996 | return -ENXIO; |
| 1997 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1998 | |
| 1999 | scan_target: |
| 2000 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 2001 | GFP_KERNEL); |
| 2002 | if (!mr_device_priv_data) |
| 2003 | return -ENOMEM; |
| 2004 | sdev->hostdata = mr_device_priv_data; |
Shivasharan S | 49524b3 | 2017-03-10 03:22:13 -0800 | [diff] [blame] | 2005 | |
| 2006 | atomic_set(&mr_device_priv_data->r1_ldio_hint, |
| 2007 | instance->r1_ldio_hint_default); |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2008 | return 0; |
| 2009 | } |
| 2010 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2011 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 2012 | { |
| 2013 | kfree(sdev->hostdata); |
| 2014 | sdev->hostdata = NULL; |
| 2015 | } |
| 2016 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2017 | /* |
| 2018 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 2019 | * kill adapter |
| 2020 | * @instance: Adapter soft state |
| 2021 | * |
| 2022 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 2023 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2024 | { |
| 2025 | int i; |
| 2026 | struct megasas_cmd *cmd_mfi; |
| 2027 | struct megasas_cmd_fusion *cmd_fusion; |
| 2028 | struct fusion_context *fusion = instance->ctrl_context; |
| 2029 | |
| 2030 | /* Find all outstanding ioctls */ |
| 2031 | if (fusion) { |
| 2032 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2033 | cmd_fusion = fusion->cmd_list[i]; |
| 2034 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 2035 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 2036 | if (cmd_mfi->sync_cmd && |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2037 | (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) { |
| 2038 | cmd_mfi->frame->hdr.cmd_status = |
| 2039 | MFI_STAT_WRONG_STATE; |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2040 | megasas_complete_cmd(instance, |
| 2041 | cmd_mfi, DID_OK); |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2042 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | } else { |
| 2046 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2047 | cmd_mfi = instance->cmd_list[i]; |
| 2048 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 2049 | MFI_CMD_ABORT) |
| 2050 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2056 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2057 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2058 | /* Set critical error to block I/O & ioctls in case caller didn't */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2059 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2060 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 2061 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2062 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2063 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2064 | (instance->adapter_type != MFI_SERIES)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2065 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2066 | /* Flush */ |
| 2067 | readl(&instance->reg_set->doorbell); |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 2068 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2069 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2070 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2071 | writel(MFI_STOP_ADP, |
| 2072 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2073 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2074 | /* Complete outstanding ioctls when adapter is killed */ |
| 2075 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | /** |
| 2079 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 2080 | * restored to max value |
| 2081 | * @instance: Adapter soft state |
| 2082 | * |
| 2083 | */ |
| 2084 | void |
| 2085 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 2086 | { |
| 2087 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 2088 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2089 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2090 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 2091 | && atomic_read(&instance->fw_outstanding) < |
| 2092 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2093 | |
| 2094 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2095 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2096 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2097 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2098 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2102 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2103 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 2104 | * @instance_addr: Address of adapter soft state |
| 2105 | * |
| 2106 | * Tasklet to complete cmds |
| 2107 | */ |
| 2108 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 2109 | { |
| 2110 | u32 producer; |
| 2111 | u32 consumer; |
| 2112 | u32 context; |
| 2113 | struct megasas_cmd *cmd; |
| 2114 | struct megasas_instance *instance = |
| 2115 | (struct megasas_instance *)instance_addr; |
| 2116 | unsigned long flags; |
| 2117 | |
| 2118 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2119 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2120 | return; |
| 2121 | |
| 2122 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 2123 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2124 | producer = le32_to_cpu(*instance->producer); |
| 2125 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2126 | |
| 2127 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2128 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2129 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2130 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2131 | context); |
| 2132 | BUG(); |
| 2133 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2134 | |
| 2135 | cmd = instance->cmd_list[context]; |
| 2136 | |
| 2137 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2138 | |
| 2139 | consumer++; |
| 2140 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2141 | consumer = 0; |
| 2142 | } |
| 2143 | } |
| 2144 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2145 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2146 | |
| 2147 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2148 | |
| 2149 | /* |
| 2150 | * Check if we can restore can_queue |
| 2151 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2152 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2153 | } |
| 2154 | |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2155 | static void megasas_sriov_heartbeat_handler(struct timer_list *t); |
| 2156 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2157 | /** |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2158 | * megasas_start_timer - Initializes sriov heartbeat timer object |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2159 | * @instance: Adapter soft state |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2160 | * |
| 2161 | */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2162 | void megasas_start_timer(struct megasas_instance *instance) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2163 | { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2164 | struct timer_list *timer = &instance->sriov_heartbeat_timer; |
| 2165 | |
| 2166 | timer_setup(timer, megasas_sriov_heartbeat_handler, 0); |
| 2167 | timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2168 | add_timer(timer); |
| 2169 | } |
| 2170 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2171 | static void |
| 2172 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2173 | |
| 2174 | static void |
| 2175 | process_fw_state_change_wq(struct work_struct *work); |
| 2176 | |
| 2177 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2178 | { |
| 2179 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2180 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2181 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2182 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2183 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2184 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2185 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2186 | instance->issuepend_done = 0; |
| 2187 | |
| 2188 | atomic_set(&instance->fw_outstanding, 0); |
| 2189 | megasas_internal_reset_defer_cmds(instance); |
| 2190 | process_fw_state_change_wq(&instance->work_init); |
| 2191 | } |
| 2192 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2193 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2194 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2195 | { |
| 2196 | struct megasas_cmd *cmd; |
| 2197 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2198 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2199 | dma_addr_t new_affiliation_111_h; |
| 2200 | int ld, retval = 0; |
| 2201 | u8 thisVf; |
| 2202 | |
| 2203 | cmd = megasas_get_cmd(instance); |
| 2204 | |
| 2205 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2206 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2207 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2208 | instance->host->host_no); |
| 2209 | return -ENOMEM; |
| 2210 | } |
| 2211 | |
| 2212 | dcmd = &cmd->frame->dcmd; |
| 2213 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2214 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2215 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2216 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2217 | megasas_return_cmd(instance, cmd); |
| 2218 | return -ENOMEM; |
| 2219 | } |
| 2220 | |
| 2221 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2222 | memset(instance->vf_affiliation_111, 0, |
| 2223 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2224 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2225 | new_affiliation_111 = |
| 2226 | pci_alloc_consistent(instance->pdev, |
| 2227 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2228 | &new_affiliation_111_h); |
| 2229 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2230 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2231 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2232 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2233 | megasas_return_cmd(instance, cmd); |
| 2234 | return -ENOMEM; |
| 2235 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2236 | memset(new_affiliation_111, 0, |
| 2237 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2241 | |
| 2242 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2243 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2244 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2245 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2246 | dcmd->timeout = 0; |
| 2247 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2248 | dcmd->data_xfer_len = |
| 2249 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2250 | 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] | 2251 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2252 | if (initial) |
| 2253 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2254 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2255 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2256 | dcmd->sgl.sge32[0].phys_addr = |
| 2257 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2258 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2259 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2260 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2261 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2262 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2263 | "scsi%d\n", instance->host->host_no); |
| 2264 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2265 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2266 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2267 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2268 | dcmd->cmd_status, instance->host->host_no); |
| 2269 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2270 | goto out; |
| 2271 | } |
| 2272 | |
| 2273 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2274 | thisVf = new_affiliation_111->thisVf; |
| 2275 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2276 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2277 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2278 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2279 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2280 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2281 | memcpy(instance->vf_affiliation_111, |
| 2282 | new_affiliation_111, |
| 2283 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2284 | retval = 1; |
| 2285 | goto out; |
| 2286 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2287 | } |
| 2288 | out: |
| 2289 | if (new_affiliation_111) { |
| 2290 | pci_free_consistent(instance->pdev, |
| 2291 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2292 | new_affiliation_111, |
| 2293 | new_affiliation_111_h); |
| 2294 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2295 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2296 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2297 | |
| 2298 | return retval; |
| 2299 | } |
| 2300 | |
| 2301 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2302 | int initial) |
| 2303 | { |
| 2304 | struct megasas_cmd *cmd; |
| 2305 | struct megasas_dcmd_frame *dcmd; |
| 2306 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2307 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2308 | dma_addr_t new_affiliation_h; |
| 2309 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2310 | u8 thisVf; |
| 2311 | |
| 2312 | cmd = megasas_get_cmd(instance); |
| 2313 | |
| 2314 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2315 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2316 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2317 | instance->host->host_no); |
| 2318 | return -ENOMEM; |
| 2319 | } |
| 2320 | |
| 2321 | dcmd = &cmd->frame->dcmd; |
| 2322 | |
| 2323 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2324 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2325 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2326 | megasas_return_cmd(instance, cmd); |
| 2327 | return -ENOMEM; |
| 2328 | } |
| 2329 | |
| 2330 | if (initial) |
| 2331 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2332 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2333 | else { |
| 2334 | new_affiliation = |
| 2335 | pci_alloc_consistent(instance->pdev, |
| 2336 | (MAX_LOGICAL_DRIVES + 1) * |
| 2337 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2338 | &new_affiliation_h); |
| 2339 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2340 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2341 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2342 | instance->host->host_no); |
| 2343 | megasas_return_cmd(instance, cmd); |
| 2344 | return -ENOMEM; |
| 2345 | } |
| 2346 | memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2347 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2348 | } |
| 2349 | |
| 2350 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2351 | |
| 2352 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2353 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2354 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2355 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2356 | dcmd->timeout = 0; |
| 2357 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2358 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2359 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2360 | 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] | 2361 | |
| 2362 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2363 | dcmd->sgl.sge32[0].phys_addr = |
| 2364 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2365 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2366 | dcmd->sgl.sge32[0].phys_addr = |
| 2367 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2368 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2369 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2370 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2371 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2372 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2373 | "scsi%d\n", instance->host->host_no); |
| 2374 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2375 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2376 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2377 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2378 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2379 | dcmd->cmd_status, instance->host->host_no); |
| 2380 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2381 | goto out; |
| 2382 | } |
| 2383 | |
| 2384 | if (!initial) { |
| 2385 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2386 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2387 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2388 | instance->host->host_no); |
| 2389 | retval = 1; |
| 2390 | goto out; |
| 2391 | } |
| 2392 | newmap = new_affiliation->map; |
| 2393 | savedmap = instance->vf_affiliation->map; |
| 2394 | thisVf = new_affiliation->thisVf; |
| 2395 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2396 | found = 0; |
| 2397 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2398 | j++) { |
| 2399 | if (newmap->ref.targetId == |
| 2400 | savedmap->ref.targetId) { |
| 2401 | found = 1; |
| 2402 | if (newmap->policy[thisVf] != |
| 2403 | savedmap->policy[thisVf]) { |
| 2404 | doscan = 1; |
| 2405 | goto out; |
| 2406 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2407 | } |
| 2408 | savedmap = (struct MR_LD_VF_MAP *) |
| 2409 | ((unsigned char *)savedmap + |
| 2410 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2411 | } |
| 2412 | if (!found && newmap->policy[thisVf] != |
| 2413 | MR_LD_ACCESS_HIDDEN) { |
| 2414 | doscan = 1; |
| 2415 | goto out; |
| 2416 | } |
| 2417 | newmap = (struct MR_LD_VF_MAP *) |
| 2418 | ((unsigned char *)newmap + newmap->size); |
| 2419 | } |
| 2420 | |
| 2421 | newmap = new_affiliation->map; |
| 2422 | savedmap = instance->vf_affiliation->map; |
| 2423 | |
| 2424 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2425 | found = 0; |
| 2426 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2427 | if (savedmap->ref.targetId == |
| 2428 | newmap->ref.targetId) { |
| 2429 | found = 1; |
| 2430 | if (savedmap->policy[thisVf] != |
| 2431 | newmap->policy[thisVf]) { |
| 2432 | doscan = 1; |
| 2433 | goto out; |
| 2434 | } |
| 2435 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2436 | newmap = (struct MR_LD_VF_MAP *) |
| 2437 | ((unsigned char *)newmap + |
| 2438 | newmap->size); |
| 2439 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2440 | if (!found && savedmap->policy[thisVf] != |
| 2441 | MR_LD_ACCESS_HIDDEN) { |
| 2442 | doscan = 1; |
| 2443 | goto out; |
| 2444 | } |
| 2445 | savedmap = (struct MR_LD_VF_MAP *) |
| 2446 | ((unsigned char *)savedmap + |
| 2447 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2451 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2452 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2453 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2454 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2455 | new_affiliation->size); |
| 2456 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2457 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2458 | |
| 2459 | if (new_affiliation) |
| 2460 | pci_free_consistent(instance->pdev, |
| 2461 | (MAX_LOGICAL_DRIVES + 1) * |
| 2462 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2463 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2464 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2465 | |
| 2466 | return retval; |
| 2467 | } |
| 2468 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2469 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2470 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2471 | int initial) |
| 2472 | { |
| 2473 | int retval; |
| 2474 | |
| 2475 | if (instance->PlasmaFW111) |
| 2476 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2477 | else |
| 2478 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2479 | return retval; |
| 2480 | } |
| 2481 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2482 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2483 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2484 | int initial) |
| 2485 | { |
| 2486 | struct megasas_cmd *cmd; |
| 2487 | struct megasas_dcmd_frame *dcmd; |
| 2488 | int retval = 0; |
| 2489 | |
| 2490 | cmd = megasas_get_cmd(instance); |
| 2491 | |
| 2492 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2493 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2494 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2495 | instance->host->host_no); |
| 2496 | return -ENOMEM; |
| 2497 | } |
| 2498 | |
| 2499 | dcmd = &cmd->frame->dcmd; |
| 2500 | |
| 2501 | if (initial) { |
| 2502 | instance->hb_host_mem = |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 2503 | pci_zalloc_consistent(instance->pdev, |
| 2504 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2505 | &instance->hb_host_mem_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2506 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2507 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2508 | " memory for heartbeat host memory for scsi%d\n", |
| 2509 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2510 | retval = -ENOMEM; |
| 2511 | goto out; |
| 2512 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2516 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2517 | 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] | 2518 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2519 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2520 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2521 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2522 | dcmd->timeout = 0; |
| 2523 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2524 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2525 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 2526 | |
| 2527 | megasas_set_dma_settings(instance, dcmd, instance->hb_host_mem_h, |
| 2528 | sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2529 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2530 | 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] | 2531 | instance->host->host_no); |
| 2532 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2533 | if ((instance->adapter_type != MFI_SERIES) && |
| 2534 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2535 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2536 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2537 | else |
| 2538 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2539 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2540 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2541 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2542 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2543 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2544 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2545 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | out: |
| 2549 | megasas_return_cmd(instance, cmd); |
| 2550 | |
| 2551 | return retval; |
| 2552 | } |
| 2553 | |
| 2554 | /* Handler for SR-IOV heartbeat */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2555 | static void megasas_sriov_heartbeat_handler(struct timer_list *t) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2556 | { |
| 2557 | struct megasas_instance *instance = |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2558 | from_timer(instance, t, sriov_heartbeat_timer); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2559 | |
| 2560 | if (instance->hb_host_mem->HB.fwCounter != |
| 2561 | instance->hb_host_mem->HB.driverCounter) { |
| 2562 | instance->hb_host_mem->HB.driverCounter = |
| 2563 | instance->hb_host_mem->HB.fwCounter; |
| 2564 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2565 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2566 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2567 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2568 | "completed for scsi%d\n", instance->host->host_no); |
| 2569 | schedule_work(&instance->work_init); |
| 2570 | } |
| 2571 | } |
| 2572 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2573 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2574 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2575 | * @instance: Adapter soft state |
| 2576 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2577 | * 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] | 2578 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2579 | * are pending after this time period. It also marks the controller dead. |
| 2580 | */ |
| 2581 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2582 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2583 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2584 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2585 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2586 | unsigned long flags; |
| 2587 | struct list_head clist_local; |
| 2588 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2589 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2590 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2591 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2592 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2593 | __func__, __LINE__); |
| 2594 | return FAILED; |
| 2595 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2596 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2597 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2598 | |
| 2599 | INIT_LIST_HEAD(&clist_local); |
| 2600 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2601 | list_splice_init(&instance->internal_reset_pending_q, |
| 2602 | &clist_local); |
| 2603 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2604 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2605 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2606 | for (i = 0; i < wait_time; i++) { |
| 2607 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2608 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2609 | break; |
| 2610 | } |
| 2611 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2612 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2613 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2614 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2615 | return FAILED; |
| 2616 | } |
| 2617 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2618 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2619 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2620 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2621 | struct megasas_cmd, list); |
| 2622 | list_del_init(&reset_cmd->list); |
| 2623 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 2624 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2625 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2626 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2627 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2628 | |
| 2629 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2630 | megasas_return_cmd(instance, reset_cmd); |
| 2631 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2632 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2633 | "reset queue\n", |
| 2634 | reset_cmd); |
| 2635 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2636 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2637 | instance->instancet->fire_cmd(instance, |
| 2638 | reset_cmd->frame_phys_addr, |
| 2639 | 0, instance->reg_set); |
| 2640 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2641 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2642 | "cmds lst\n", |
| 2643 | reset_cmd); |
| 2644 | } |
| 2645 | reset_index++; |
| 2646 | } |
| 2647 | |
| 2648 | return SUCCESS; |
| 2649 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2650 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2651 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2652 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2653 | |
| 2654 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2655 | break; |
| 2656 | |
| 2657 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2658 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2659 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2660 | /* |
| 2661 | * Call cmd completion routine. Cmd to be |
| 2662 | * be completed directly without depending on isr. |
| 2663 | */ |
| 2664 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | msleep(1000); |
| 2668 | } |
| 2669 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2670 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2671 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2672 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2673 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2674 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2675 | goto no_outstanding; |
| 2676 | |
| 2677 | if (instance->disableOnlineCtrlReset) |
| 2678 | goto kill_hba_and_failed; |
| 2679 | do { |
| 2680 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2681 | dev_info(&instance->pdev->dev, |
| 2682 | "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, oustanding 0x%x\n", |
| 2683 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2684 | if (i == 3) |
| 2685 | goto kill_hba_and_failed; |
| 2686 | megasas_do_ocr(instance); |
| 2687 | |
| 2688 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2689 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2690 | __func__, __LINE__); |
| 2691 | return FAILED; |
| 2692 | } |
| 2693 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2694 | __func__, __LINE__); |
| 2695 | |
| 2696 | for (sl = 0; sl < 10; sl++) |
| 2697 | msleep(500); |
| 2698 | |
| 2699 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2700 | |
| 2701 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
| 2702 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2703 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2704 | } |
| 2705 | i++; |
| 2706 | } while (i <= 3); |
| 2707 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2708 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2709 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2710 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2711 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2712 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2713 | |
| 2714 | kill_hba_and_failed: |
| 2715 | |
| 2716 | /* Reset not supported, kill adapter */ |
| 2717 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2718 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2719 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2720 | atomic_read(&instance->fw_outstanding)); |
| 2721 | megasas_dump_pending_frames(instance); |
| 2722 | megaraid_sas_kill_hba(instance); |
| 2723 | |
| 2724 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | /** |
| 2728 | * megasas_generic_reset - Generic reset routine |
| 2729 | * @scmd: Mid-layer SCSI command |
| 2730 | * |
| 2731 | * This routine implements a generic reset handler for device, bus and host |
| 2732 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2733 | * function after they do their specific tasks. |
| 2734 | */ |
| 2735 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2736 | { |
| 2737 | int ret_val; |
| 2738 | struct megasas_instance *instance; |
| 2739 | |
| 2740 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2741 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2742 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2743 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2744 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2745 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2746 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2747 | return FAILED; |
| 2748 | } |
| 2749 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2750 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2751 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2752 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2753 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2754 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2755 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2756 | return ret_val; |
| 2757 | } |
| 2758 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2759 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2760 | * megasas_reset_timer - quiesce the adapter if required |
| 2761 | * @scmd: scsi cmnd |
| 2762 | * |
| 2763 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2764 | * cmd has not been completed within the timeout period. |
| 2765 | */ |
| 2766 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2767 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2768 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2769 | struct megasas_instance *instance; |
| 2770 | unsigned long flags; |
| 2771 | |
| 2772 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2773 | (scmd_timeout * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2774 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2777 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2778 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2779 | /* FW is busy, throttle IO */ |
| 2780 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2781 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2782 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2783 | instance->last_time = jiffies; |
| 2784 | instance->flag |= MEGASAS_FW_BUSY; |
| 2785 | |
| 2786 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2787 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2788 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | /** |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2792 | * megasas_dump_frame - This function will dump MPT/MFI frame |
| 2793 | */ |
| 2794 | static inline void |
| 2795 | megasas_dump_frame(void *mpi_request, int sz) |
| 2796 | { |
| 2797 | int i; |
| 2798 | __le32 *mfp = (__le32 *)mpi_request; |
| 2799 | |
| 2800 | printk(KERN_INFO "IO request frame:\n\t"); |
Dan Carpenter | 40a4c2c | 2017-02-14 19:38:55 +0300 | [diff] [blame] | 2801 | for (i = 0; i < sz / sizeof(__le32); i++) { |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2802 | if (i && ((i % 8) == 0)) |
| 2803 | printk("\n\t"); |
| 2804 | printk("%08x ", le32_to_cpu(mfp[i])); |
| 2805 | } |
| 2806 | printk("\n"); |
| 2807 | } |
| 2808 | |
| 2809 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2810 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2811 | */ |
| 2812 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2813 | { |
| 2814 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2815 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2816 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2817 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2818 | |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2819 | scmd_printk(KERN_INFO, scmd, |
| 2820 | "Controller reset is requested due to IO timeout\n" |
| 2821 | "SCSI command pointer: (%p)\t SCSI host state: %d\t" |
| 2822 | " SCSI host busy: %d\t FW outstanding: %d\n", |
| 2823 | scmd, scmd->device->host->shost_state, |
| 2824 | atomic_read((atomic_t *)&scmd->device->host->host_busy), |
| 2825 | atomic_read(&instance->fw_outstanding)); |
| 2826 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2827 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2828 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2829 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2830 | if (instance->adapter_type == MFI_SERIES) { |
| 2831 | ret = megasas_generic_reset(scmd); |
| 2832 | } else { |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2833 | struct megasas_cmd_fusion *cmd; |
| 2834 | cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr; |
| 2835 | if (cmd) |
| 2836 | megasas_dump_frame(cmd->io_request, |
Shivasharan S | 5dd977e | 2017-08-23 04:47:07 -0700 | [diff] [blame] | 2837 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2838 | ret = megasas_reset_fusion(scmd->device->host, |
| 2839 | SCSIIO_TIMEOUT_OCR); |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2840 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2841 | |
| 2842 | return ret; |
| 2843 | } |
| 2844 | |
| 2845 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2846 | * megasas_task_abort - Issues task abort request to firmware |
| 2847 | * (supported only for fusion adapters) |
| 2848 | * @scmd: SCSI command pointer |
| 2849 | */ |
| 2850 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 2851 | { |
| 2852 | int ret; |
| 2853 | struct megasas_instance *instance; |
| 2854 | |
| 2855 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2856 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2857 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2858 | ret = megasas_task_abort_fusion(scmd); |
| 2859 | else { |
| 2860 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 2861 | ret = FAILED; |
| 2862 | } |
| 2863 | |
| 2864 | return ret; |
| 2865 | } |
| 2866 | |
| 2867 | /** |
| 2868 | * megasas_reset_target: Issues target reset request to firmware |
| 2869 | * (supported only for fusion adapters) |
| 2870 | * @scmd: SCSI command pointer |
| 2871 | */ |
| 2872 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 2873 | { |
| 2874 | int ret; |
| 2875 | struct megasas_instance *instance; |
| 2876 | |
| 2877 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2878 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2879 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2880 | ret = megasas_reset_target_fusion(scmd); |
| 2881 | else { |
| 2882 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 2883 | ret = FAILED; |
| 2884 | } |
| 2885 | |
| 2886 | return ret; |
| 2887 | } |
| 2888 | |
| 2889 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2890 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2891 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2892 | * @bdev: block device |
| 2893 | * @capacity: drive capacity |
| 2894 | * @geom: geometry parameters |
| 2895 | */ |
| 2896 | static int |
| 2897 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2898 | sector_t capacity, int geom[]) |
| 2899 | { |
| 2900 | int heads; |
| 2901 | int sectors; |
| 2902 | sector_t cylinders; |
| 2903 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2904 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2905 | /* Default heads (64) & sectors (32) */ |
| 2906 | heads = 64; |
| 2907 | sectors = 32; |
| 2908 | |
| 2909 | tmp = heads * sectors; |
| 2910 | cylinders = capacity; |
| 2911 | |
| 2912 | sector_div(cylinders, tmp); |
| 2913 | |
| 2914 | /* |
| 2915 | * Handle extended translation size for logical drives > 1Gb |
| 2916 | */ |
| 2917 | |
| 2918 | if (capacity >= 0x200000) { |
| 2919 | heads = 255; |
| 2920 | sectors = 63; |
| 2921 | tmp = heads*sectors; |
| 2922 | cylinders = capacity; |
| 2923 | sector_div(cylinders, tmp); |
| 2924 | } |
| 2925 | |
| 2926 | geom[0] = heads; |
| 2927 | geom[1] = sectors; |
| 2928 | geom[2] = cylinders; |
| 2929 | |
| 2930 | return 0; |
| 2931 | } |
| 2932 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2933 | static void megasas_aen_polling(struct work_struct *work); |
| 2934 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2935 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2936 | * megasas_service_aen - Processes an event notification |
| 2937 | * @instance: Adapter soft state |
| 2938 | * @cmd: AEN command completed by the ISR |
| 2939 | * |
| 2940 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2941 | * event occurs. When an event of interest occurs, FW completes the command |
| 2942 | * that it was previously holding. |
| 2943 | * |
| 2944 | * This routines sends SIGIO signal to processes that have registered with the |
| 2945 | * driver for AEN. |
| 2946 | */ |
| 2947 | static void |
| 2948 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2949 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2950 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2951 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2952 | /* |
| 2953 | * Don't signal app if it is just an aborted previously registered aen |
| 2954 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2955 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2956 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2957 | megasas_poll_wait_aen = 1; |
| 2958 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2959 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2960 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2961 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2962 | else |
| 2963 | cmd->abort_aen = 0; |
| 2964 | |
| 2965 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2966 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2967 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2968 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2969 | if ((instance->unload == 0) && |
| 2970 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2971 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2972 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2973 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2974 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2975 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2976 | } else { |
| 2977 | ev->instance = instance; |
| 2978 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2979 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2980 | megasas_aen_polling); |
| 2981 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2982 | } |
| 2983 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2984 | } |
| 2985 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2986 | static ssize_t |
| 2987 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 2988 | struct device_attribute *attr, const char *buf, size_t count) |
| 2989 | { |
| 2990 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2991 | struct megasas_instance *instance = |
| 2992 | (struct megasas_instance *) shost->hostdata; |
| 2993 | int val = 0; |
| 2994 | unsigned long flags; |
| 2995 | |
| 2996 | if (kstrtoint(buf, 0, &val) != 0) |
| 2997 | return -EINVAL; |
| 2998 | |
| 2999 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3000 | instance->fw_crash_buffer_offset = val; |
| 3001 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3002 | return strlen(buf); |
| 3003 | } |
| 3004 | |
| 3005 | static ssize_t |
| 3006 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 3007 | struct device_attribute *attr, char *buf) |
| 3008 | { |
| 3009 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3010 | struct megasas_instance *instance = |
| 3011 | (struct megasas_instance *) shost->hostdata; |
| 3012 | u32 size; |
| 3013 | unsigned long buff_addr; |
| 3014 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 3015 | unsigned long src_addr; |
| 3016 | unsigned long flags; |
| 3017 | u32 buff_offset; |
| 3018 | |
| 3019 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3020 | buff_offset = instance->fw_crash_buffer_offset; |
| 3021 | if (!instance->crash_dump_buf && |
| 3022 | !((instance->fw_crash_state == AVAILABLE) || |
| 3023 | (instance->fw_crash_state == COPYING))) { |
| 3024 | dev_err(&instance->pdev->dev, |
| 3025 | "Firmware crash dump is not available\n"); |
| 3026 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3027 | return -EINVAL; |
| 3028 | } |
| 3029 | |
| 3030 | buff_addr = (unsigned long) buf; |
| 3031 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3032 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3033 | dev_err(&instance->pdev->dev, |
| 3034 | "Firmware crash dump offset is out of range\n"); |
| 3035 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3036 | return 0; |
| 3037 | } |
| 3038 | |
| 3039 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 3040 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 3041 | |
| 3042 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 3043 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3044 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3045 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3046 | |
| 3047 | return size; |
| 3048 | } |
| 3049 | |
| 3050 | static ssize_t |
| 3051 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 3052 | struct device_attribute *attr, char *buf) |
| 3053 | { |
| 3054 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3055 | struct megasas_instance *instance = |
| 3056 | (struct megasas_instance *) shost->hostdata; |
| 3057 | |
| 3058 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 3059 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 3060 | } |
| 3061 | |
| 3062 | static ssize_t |
| 3063 | megasas_fw_crash_state_store(struct device *cdev, |
| 3064 | struct device_attribute *attr, const char *buf, size_t count) |
| 3065 | { |
| 3066 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3067 | struct megasas_instance *instance = |
| 3068 | (struct megasas_instance *) shost->hostdata; |
| 3069 | int val = 0; |
| 3070 | unsigned long flags; |
| 3071 | |
| 3072 | if (kstrtoint(buf, 0, &val) != 0) |
| 3073 | return -EINVAL; |
| 3074 | |
| 3075 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 3076 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 3077 | "firmware crash state\n"); |
| 3078 | return -EINVAL; |
| 3079 | } |
| 3080 | |
| 3081 | instance->fw_crash_state = val; |
| 3082 | |
| 3083 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 3084 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3085 | megasas_free_host_crash_buffer(instance); |
| 3086 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3087 | if (val == COPY_ERROR) |
| 3088 | dev_info(&instance->pdev->dev, "application failed to " |
| 3089 | "copy Firmware crash dump\n"); |
| 3090 | else |
| 3091 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3092 | "copied successfully\n"); |
| 3093 | } |
| 3094 | return strlen(buf); |
| 3095 | } |
| 3096 | |
| 3097 | static ssize_t |
| 3098 | megasas_fw_crash_state_show(struct device *cdev, |
| 3099 | struct device_attribute *attr, char *buf) |
| 3100 | { |
| 3101 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3102 | struct megasas_instance *instance = |
| 3103 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3104 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3105 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 3106 | } |
| 3107 | |
| 3108 | static ssize_t |
| 3109 | megasas_page_size_show(struct device *cdev, |
| 3110 | struct device_attribute *attr, char *buf) |
| 3111 | { |
| 3112 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 3113 | } |
| 3114 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3115 | static ssize_t |
| 3116 | megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
| 3117 | char *buf) |
| 3118 | { |
| 3119 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3120 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3121 | |
| 3122 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 3123 | } |
| 3124 | |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3125 | static ssize_t |
| 3126 | megasas_fw_cmds_outstanding_show(struct device *cdev, |
| 3127 | struct device_attribute *attr, char *buf) |
| 3128 | { |
| 3129 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3130 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3131 | |
| 3132 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding)); |
| 3133 | } |
| 3134 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3135 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 3136 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 3137 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 3138 | megasas_fw_crash_buffer_size_show, NULL); |
| 3139 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 3140 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 3141 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 3142 | megasas_page_size_show, NULL); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3143 | static DEVICE_ATTR(ldio_outstanding, S_IRUGO, |
| 3144 | megasas_ldio_outstanding_show, NULL); |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3145 | static DEVICE_ATTR(fw_cmds_outstanding, S_IRUGO, |
| 3146 | megasas_fw_cmds_outstanding_show, NULL); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3147 | |
| 3148 | struct device_attribute *megaraid_host_attrs[] = { |
| 3149 | &dev_attr_fw_crash_buffer_size, |
| 3150 | &dev_attr_fw_crash_buffer, |
| 3151 | &dev_attr_fw_crash_state, |
| 3152 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3153 | &dev_attr_ldio_outstanding, |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3154 | &dev_attr_fw_cmds_outstanding, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3155 | NULL, |
| 3156 | }; |
| 3157 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3158 | /* |
| 3159 | * Scsi host template for megaraid_sas driver |
| 3160 | */ |
| 3161 | static struct scsi_host_template megasas_template = { |
| 3162 | |
| 3163 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 3164 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3165 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 3166 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 3167 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3168 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3169 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3170 | .eh_target_reset_handler = megasas_reset_target, |
| 3171 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3172 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3173 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3174 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3175 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3176 | .use_clustering = ENABLE_CLUSTERING, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3177 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3178 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3179 | }; |
| 3180 | |
| 3181 | /** |
| 3182 | * megasas_complete_int_cmd - Completes an internal command |
| 3183 | * @instance: Adapter soft state |
| 3184 | * @cmd: Command to be completed |
| 3185 | * |
| 3186 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3187 | * after it issues a command. This function wakes up that waiting routine by |
| 3188 | * calling wake_up() on the wait queue. |
| 3189 | */ |
| 3190 | static void |
| 3191 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3192 | struct megasas_cmd *cmd) |
| 3193 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3194 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3195 | wake_up(&instance->int_cmd_wait_q); |
| 3196 | } |
| 3197 | |
| 3198 | /** |
| 3199 | * megasas_complete_abort - Completes aborting a command |
| 3200 | * @instance: Adapter soft state |
| 3201 | * @cmd: Cmd that was issued to abort another cmd |
| 3202 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3203 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3204 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3205 | * wakes up all functions waiting on the same wait queue. |
| 3206 | */ |
| 3207 | static void |
| 3208 | megasas_complete_abort(struct megasas_instance *instance, |
| 3209 | struct megasas_cmd *cmd) |
| 3210 | { |
| 3211 | if (cmd->sync_cmd) { |
| 3212 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3213 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3214 | wake_up(&instance->abort_cmd_wait_q); |
| 3215 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3219 | * megasas_complete_cmd - Completes a command |
| 3220 | * @instance: Adapter soft state |
| 3221 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3222 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3223 | * SCSI mid-layer instead of the value returned |
| 3224 | * by the FW. This should be used if caller wants |
| 3225 | * an alternate status (as in the case of aborted |
| 3226 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3227 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3228 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3229 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3230 | u8 alt_status) |
| 3231 | { |
| 3232 | int exception = 0; |
| 3233 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3234 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3235 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3236 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3237 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3238 | /* flag for the retry reset */ |
| 3239 | cmd->retry_for_fw_reset = 0; |
| 3240 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3241 | if (cmd->scmd) |
| 3242 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3243 | |
| 3244 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3245 | case MFI_CMD_INVALID: |
| 3246 | /* Some older 1068 controller FW may keep a pended |
| 3247 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3248 | when booting the kdump kernel. Ignore this command to |
| 3249 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3250 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3251 | "completed\n"); |
| 3252 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3253 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3254 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3255 | case MFI_CMD_PD_SCSI_IO: |
| 3256 | case MFI_CMD_LD_SCSI_IO: |
| 3257 | |
| 3258 | /* |
| 3259 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3260 | * issued either through an IO path or an IOCTL path. If it |
| 3261 | * was via IOCTL, we will send it to internal completion. |
| 3262 | */ |
| 3263 | if (cmd->sync_cmd) { |
| 3264 | cmd->sync_cmd = 0; |
| 3265 | megasas_complete_int_cmd(instance, cmd); |
| 3266 | break; |
| 3267 | } |
| 3268 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3269 | case MFI_CMD_LD_READ: |
| 3270 | case MFI_CMD_LD_WRITE: |
| 3271 | |
| 3272 | if (alt_status) { |
| 3273 | cmd->scmd->result = alt_status << 16; |
| 3274 | exception = 1; |
| 3275 | } |
| 3276 | |
| 3277 | if (exception) { |
| 3278 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3279 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3280 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3281 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3282 | cmd->scmd->scsi_done(cmd->scmd); |
| 3283 | megasas_return_cmd(instance, cmd); |
| 3284 | |
| 3285 | break; |
| 3286 | } |
| 3287 | |
| 3288 | switch (hdr->cmd_status) { |
| 3289 | |
| 3290 | case MFI_STAT_OK: |
| 3291 | cmd->scmd->result = DID_OK << 16; |
| 3292 | break; |
| 3293 | |
| 3294 | case MFI_STAT_SCSI_IO_FAILED: |
| 3295 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3296 | cmd->scmd->result = |
| 3297 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3298 | break; |
| 3299 | |
| 3300 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3301 | |
| 3302 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3303 | |
| 3304 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3305 | memset(cmd->scmd->sense_buffer, 0, |
| 3306 | SCSI_SENSE_BUFFERSIZE); |
| 3307 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3308 | hdr->sense_len); |
| 3309 | |
| 3310 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3311 | } |
| 3312 | |
| 3313 | break; |
| 3314 | |
| 3315 | case MFI_STAT_LD_OFFLINE: |
| 3316 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3317 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3318 | break; |
| 3319 | |
| 3320 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3321 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3322 | hdr->cmd_status); |
| 3323 | cmd->scmd->result = DID_ERROR << 16; |
| 3324 | break; |
| 3325 | } |
| 3326 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3327 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3328 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3329 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3330 | cmd->scmd->scsi_done(cmd->scmd); |
| 3331 | megasas_return_cmd(instance, cmd); |
| 3332 | |
| 3333 | break; |
| 3334 | |
| 3335 | case MFI_CMD_SMP: |
| 3336 | case MFI_CMD_STP: |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3337 | megasas_complete_int_cmd(instance, cmd); |
| 3338 | break; |
| 3339 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3340 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3341 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3342 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3343 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3344 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3345 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3346 | spin_lock_irqsave(instance->host->host_lock, flags); |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3347 | status = cmd->frame->hdr.cmd_status; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3348 | instance->map_update_cmd = NULL; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3349 | if (status != MFI_STAT_OK) { |
| 3350 | if (status != MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3351 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3352 | cmd->frame->hdr.cmd_status); |
| 3353 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3354 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3355 | spin_unlock_irqrestore( |
| 3356 | instance->host->host_lock, |
| 3357 | flags); |
| 3358 | break; |
| 3359 | } |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3360 | } |
| 3361 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3362 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3363 | |
| 3364 | /* |
| 3365 | * Set fast path IO to ZERO. |
| 3366 | * Validate Map will set proper value. |
| 3367 | * Meanwhile all IOs will go as LD IO. |
| 3368 | */ |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3369 | if (status == MFI_STAT_OK && |
| 3370 | (MR_ValidateMapInfo(instance, (instance->map_id + 1)))) { |
| 3371 | instance->map_id++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3372 | fusion->fast_path_io = 1; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3373 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3374 | fusion->fast_path_io = 0; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3375 | } |
| 3376 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3377 | megasas_sync_map_info(instance); |
| 3378 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3379 | flags); |
| 3380 | break; |
| 3381 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3382 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3383 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3384 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3385 | megasas_poll_wait_aen = 0; |
| 3386 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3387 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3388 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3389 | /* FW has an updated PD sequence */ |
| 3390 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3391 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3392 | |
| 3393 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3394 | status = cmd->frame->hdr.cmd_status; |
| 3395 | instance->jbod_seq_cmd = NULL; |
| 3396 | megasas_return_cmd(instance, cmd); |
| 3397 | |
| 3398 | if (status == MFI_STAT_OK) { |
| 3399 | instance->pd_seq_map_id++; |
| 3400 | /* Re-register a pd sync seq num cmd */ |
| 3401 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3402 | instance->use_seqnum_jbod_fp = false; |
| 3403 | } else |
| 3404 | instance->use_seqnum_jbod_fp = false; |
| 3405 | |
| 3406 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3407 | break; |
| 3408 | } |
| 3409 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3410 | /* |
| 3411 | * See if got an event notification |
| 3412 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3413 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3414 | megasas_service_aen(instance, cmd); |
| 3415 | else |
| 3416 | megasas_complete_int_cmd(instance, cmd); |
| 3417 | |
| 3418 | break; |
| 3419 | |
| 3420 | case MFI_CMD_ABORT: |
| 3421 | /* |
| 3422 | * Cmd issued to abort another cmd returned |
| 3423 | */ |
| 3424 | megasas_complete_abort(instance, cmd); |
| 3425 | break; |
| 3426 | |
| 3427 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3428 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3429 | hdr->cmd); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3430 | megasas_complete_int_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3431 | break; |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3436 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3437 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3438 | * @instance: Adapter soft state |
| 3439 | */ |
| 3440 | static inline void |
| 3441 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3442 | { |
| 3443 | struct megasas_cmd *cmd; |
| 3444 | struct list_head clist_local; |
| 3445 | union megasas_evt_class_locale class_locale; |
| 3446 | unsigned long flags; |
| 3447 | u32 seq_num; |
| 3448 | |
| 3449 | INIT_LIST_HEAD(&clist_local); |
| 3450 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3451 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3452 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3453 | |
| 3454 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3455 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3456 | struct megasas_cmd, list); |
| 3457 | list_del_init(&cmd->list); |
| 3458 | |
| 3459 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3460 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3461 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3462 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3463 | |
| 3464 | cmd->retry_for_fw_reset++; |
| 3465 | |
| 3466 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3467 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3468 | "was tried multiple times during reset." |
| 3469 | "Shutting down the HBA\n", |
| 3470 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3471 | instance->instancet->disable_intr(instance); |
| 3472 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3473 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3474 | return; |
| 3475 | } |
| 3476 | } |
| 3477 | |
| 3478 | if (cmd->sync_cmd == 1) { |
| 3479 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3480 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3481 | "cmd attached to internal command!\n"); |
| 3482 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3483 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3484 | "on the internal reset queue," |
| 3485 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3486 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3487 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3488 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3489 | 0, instance->reg_set); |
| 3490 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3491 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3492 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3493 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3494 | |
| 3495 | atomic_inc(&instance->fw_outstanding); |
| 3496 | instance->instancet->fire_cmd(instance, |
| 3497 | cmd->frame_phys_addr, |
| 3498 | cmd->frame_count-1, instance->reg_set); |
| 3499 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3500 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3501 | "internal reset defer list while re-issue!!\n", |
| 3502 | cmd); |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3507 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3508 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3509 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3510 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3514 | * Initiate AEN (Asynchronous Event Notification) |
| 3515 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3516 | seq_num = instance->last_seq_num; |
| 3517 | class_locale.members.reserved = 0; |
| 3518 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3519 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3520 | |
| 3521 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3522 | } |
| 3523 | |
| 3524 | /** |
| 3525 | * Move the internal reset pending commands to a deferred queue. |
| 3526 | * |
| 3527 | * We move the commands pending at internal reset time to a |
| 3528 | * pending queue. This queue would be flushed after successful |
| 3529 | * completion of the internal reset sequence. if the internal reset |
| 3530 | * did not complete in time, the kernel reset handler would flush |
| 3531 | * these commands. |
| 3532 | **/ |
| 3533 | static void |
| 3534 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3535 | { |
| 3536 | struct megasas_cmd *cmd; |
| 3537 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3538 | u16 max_cmd = instance->max_fw_cmds; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3539 | u32 defer_index; |
| 3540 | unsigned long flags; |
| 3541 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3542 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3543 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3544 | for (i = 0; i < max_cmd; i++) { |
| 3545 | cmd = instance->cmd_list[i]; |
| 3546 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3547 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3548 | "on the defer queue as internal\n", |
| 3549 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3550 | |
| 3551 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3552 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3553 | " moving this cmd:%p, %d %p, it was" |
| 3554 | "discovered on some list?\n", |
| 3555 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3556 | |
| 3557 | list_del_init(&cmd->list); |
| 3558 | } |
| 3559 | defer_index++; |
| 3560 | list_add_tail(&cmd->list, |
| 3561 | &instance->internal_reset_pending_q); |
| 3562 | } |
| 3563 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3564 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | |
| 3568 | static void |
| 3569 | process_fw_state_change_wq(struct work_struct *work) |
| 3570 | { |
| 3571 | struct megasas_instance *instance = |
| 3572 | container_of(work, struct megasas_instance, work_init); |
| 3573 | u32 wait; |
| 3574 | unsigned long flags; |
| 3575 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3576 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3577 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3578 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3579 | return ; |
| 3580 | } |
| 3581 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3582 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3583 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3584 | "state, restarting it...\n"); |
| 3585 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3586 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3587 | atomic_set(&instance->fw_outstanding, 0); |
| 3588 | |
| 3589 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3590 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3591 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3592 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3593 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3594 | "initiating next stage...\n"); |
| 3595 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3596 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3597 | "state 2 starting...\n"); |
| 3598 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3599 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3600 | for (wait = 0; wait < 30; wait++) { |
| 3601 | msleep(1000); |
| 3602 | } |
| 3603 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3604 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3605 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3606 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3607 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3608 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3609 | return ; |
| 3610 | } |
| 3611 | |
| 3612 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3613 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3614 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3615 | ) { |
| 3616 | *instance->consumer = *instance->producer; |
| 3617 | } else { |
| 3618 | *instance->consumer = 0; |
| 3619 | *instance->producer = 0; |
| 3620 | } |
| 3621 | |
| 3622 | megasas_issue_init_mfi(instance); |
| 3623 | |
| 3624 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3625 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3626 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3627 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3628 | |
| 3629 | megasas_issue_pending_cmds_again(instance); |
| 3630 | instance->issuepend_done = 1; |
| 3631 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3635 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3636 | * @instance: Adapter soft state |
| 3637 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3638 | * SCSI mid-layer instead of the status |
| 3639 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3640 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3641 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3642 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3643 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3644 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3645 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3646 | u32 mfiStatus; |
| 3647 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3648 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3649 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3650 | instance->reg_set)) == 1) { |
| 3651 | return IRQ_HANDLED; |
| 3652 | } |
| 3653 | |
| 3654 | if ((mfiStatus = instance->instancet->clear_intr( |
| 3655 | instance->reg_set) |
| 3656 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3657 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3658 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3659 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | instance->mfiStatus = mfiStatus; |
| 3663 | |
| 3664 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3665 | fw_state = instance->instancet->read_fw_status_reg( |
| 3666 | instance->reg_set) & MFI_STATE_MASK; |
| 3667 | |
| 3668 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3669 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3670 | fw_state); |
| 3671 | } |
| 3672 | |
| 3673 | if ((fw_state == MFI_STATE_FAULT) && |
| 3674 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3675 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3676 | |
| 3677 | if ((instance->pdev->device == |
| 3678 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3679 | (instance->pdev->device == |
| 3680 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3681 | (instance->pdev->device == |
| 3682 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3683 | |
| 3684 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3685 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3689 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3690 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3691 | instance->issuepend_done = 0; |
| 3692 | |
| 3693 | atomic_set(&instance->fw_outstanding, 0); |
| 3694 | megasas_internal_reset_defer_cmds(instance); |
| 3695 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3696 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3697 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3698 | |
| 3699 | schedule_work(&instance->work_init); |
| 3700 | return IRQ_HANDLED; |
| 3701 | |
| 3702 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3703 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3704 | fw_state, instance->disableOnlineCtrlReset); |
| 3705 | } |
| 3706 | } |
| 3707 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3708 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3709 | return IRQ_HANDLED; |
| 3710 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3711 | /** |
| 3712 | * megasas_isr - isr entry point |
| 3713 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3714 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3715 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3716 | struct megasas_irq_context *irq_context = devp; |
| 3717 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3718 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3719 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3720 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3721 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3722 | return IRQ_HANDLED; |
| 3723 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3724 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3725 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3726 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3727 | |
| 3728 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | /** |
| 3732 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3733 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3734 | * |
| 3735 | * During the initialization, FW passes can potentially be in any one of |
| 3736 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3737 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3738 | * has to wait for the ready state. |
| 3739 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3740 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3741 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3742 | { |
| 3743 | int i; |
| 3744 | u8 max_wait; |
| 3745 | u32 fw_state; |
| 3746 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3747 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3748 | |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3749 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3750 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3751 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3752 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3753 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3754 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3755 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3756 | while (fw_state != MFI_STATE_READY) { |
| 3757 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3758 | switch (fw_state) { |
| 3759 | |
| 3760 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3761 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3762 | if (ocr) { |
| 3763 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3764 | cur_state = MFI_STATE_FAULT; |
| 3765 | break; |
| 3766 | } else |
| 3767 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3768 | |
| 3769 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3770 | /* |
| 3771 | * Set the CLR bit in inbound doorbell |
| 3772 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3773 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3774 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3775 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3776 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3777 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3778 | writel( |
| 3779 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3780 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3781 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3782 | writel( |
| 3783 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3784 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3785 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3786 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3787 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3788 | break; |
| 3789 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3790 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3791 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3792 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3793 | (instance->pdev->device == |
| 3794 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3795 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3796 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3797 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3798 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3799 | writel(MFI_INIT_HOTPLUG, |
| 3800 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3801 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3802 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3803 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3804 | break; |
| 3805 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3806 | case MFI_STATE_OPERATIONAL: |
| 3807 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3808 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3809 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3810 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3811 | if ((instance->pdev->device == |
| 3812 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3813 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3814 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3815 | (instance->adapter_type != MFI_SERIES)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3816 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3817 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3818 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3819 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3820 | for (i = 0; i < (10 * 1000); i += 20) { |
| 3821 | if (readl( |
| 3822 | &instance-> |
| 3823 | reg_set-> |
| 3824 | doorbell) & 1) |
| 3825 | msleep(20); |
| 3826 | else |
| 3827 | break; |
| 3828 | } |
| 3829 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3830 | } else |
| 3831 | writel(MFI_RESET_FLAGS, |
| 3832 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3833 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3834 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3835 | cur_state = MFI_STATE_OPERATIONAL; |
| 3836 | break; |
| 3837 | |
| 3838 | case MFI_STATE_UNDEFINED: |
| 3839 | /* |
| 3840 | * This state should not last for more than 2 seconds |
| 3841 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3842 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3843 | cur_state = MFI_STATE_UNDEFINED; |
| 3844 | break; |
| 3845 | |
| 3846 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3847 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3848 | cur_state = MFI_STATE_BB_INIT; |
| 3849 | break; |
| 3850 | |
| 3851 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3852 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3853 | cur_state = MFI_STATE_FW_INIT; |
| 3854 | break; |
| 3855 | |
| 3856 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3857 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3858 | cur_state = MFI_STATE_FW_INIT_2; |
| 3859 | break; |
| 3860 | |
| 3861 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3862 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3863 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3864 | break; |
| 3865 | |
| 3866 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3867 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3868 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3869 | break; |
| 3870 | |
| 3871 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3872 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3873 | fw_state); |
| 3874 | return -ENODEV; |
| 3875 | } |
| 3876 | |
| 3877 | /* |
| 3878 | * The cur_state should not last for more than max_wait secs |
| 3879 | */ |
| 3880 | for (i = 0; i < (max_wait * 1000); i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3881 | curr_abs_state = instance->instancet-> |
| 3882 | read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3883 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3884 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3885 | msleep(1); |
| 3886 | } else |
| 3887 | break; |
| 3888 | } |
| 3889 | |
| 3890 | /* |
| 3891 | * Return error if fw_state hasn't changed after max_wait |
| 3892 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3893 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3894 | 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] | 3895 | "in %d secs\n", fw_state, max_wait); |
| 3896 | return -ENODEV; |
| 3897 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3898 | |
| 3899 | abs_state = curr_abs_state; |
| 3900 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3901 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3902 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3903 | |
| 3904 | return 0; |
| 3905 | } |
| 3906 | |
| 3907 | /** |
| 3908 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3909 | * @instance: Adapter soft state |
| 3910 | */ |
| 3911 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3912 | { |
| 3913 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3914 | u16 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3915 | struct megasas_cmd *cmd; |
| 3916 | |
| 3917 | if (!instance->frame_dma_pool) |
| 3918 | return; |
| 3919 | |
| 3920 | /* |
| 3921 | * Return all frames to pool |
| 3922 | */ |
| 3923 | for (i = 0; i < max_cmd; i++) { |
| 3924 | |
| 3925 | cmd = instance->cmd_list[i]; |
| 3926 | |
| 3927 | if (cmd->frame) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3928 | dma_pool_free(instance->frame_dma_pool, cmd->frame, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3929 | cmd->frame_phys_addr); |
| 3930 | |
| 3931 | if (cmd->sense) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3932 | dma_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3933 | cmd->sense_phys_addr); |
| 3934 | } |
| 3935 | |
| 3936 | /* |
| 3937 | * Now destroy the pool itself |
| 3938 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3939 | dma_pool_destroy(instance->frame_dma_pool); |
| 3940 | dma_pool_destroy(instance->sense_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3941 | |
| 3942 | instance->frame_dma_pool = NULL; |
| 3943 | instance->sense_dma_pool = NULL; |
| 3944 | } |
| 3945 | |
| 3946 | /** |
| 3947 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3948 | * @instance: Adapter soft state |
| 3949 | * |
| 3950 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3951 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3952 | * function creates those DMA memory buffers for each command packet by using |
| 3953 | * PCI pool facility. |
| 3954 | */ |
| 3955 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3956 | { |
| 3957 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3958 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3959 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3960 | u32 frame_count; |
| 3961 | struct megasas_cmd *cmd; |
| 3962 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3963 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3964 | |
| 3965 | /* |
| 3966 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 3967 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 3968 | */ |
| 3969 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 3970 | sizeof(struct megasas_sge32); |
| 3971 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3972 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3973 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3974 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3975 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3976 | * For MFI controllers. |
| 3977 | * max_num_sge = 60 |
| 3978 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 3979 | * Total 960 byte (15 MFI frame of 64 byte) |
| 3980 | * |
| 3981 | * Fusion adapter require only 3 extra frame. |
| 3982 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 3983 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 3984 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3985 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3986 | frame_count = (instance->adapter_type == MFI_SERIES) ? |
| 3987 | (15 + 1) : (3 + 1); |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 3988 | instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3989 | /* |
| 3990 | * Use DMA pool facility provided by PCI layer |
| 3991 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3992 | instance->frame_dma_pool = dma_pool_create("megasas frame pool", |
| 3993 | &instance->pdev->dev, |
| 3994 | instance->mfi_frame_size, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3995 | |
| 3996 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3997 | 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] | 3998 | return -ENOMEM; |
| 3999 | } |
| 4000 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4001 | instance->sense_dma_pool = dma_pool_create("megasas sense pool", |
| 4002 | &instance->pdev->dev, 128, |
| 4003 | 4, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4004 | |
| 4005 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4006 | 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] | 4007 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4008 | dma_pool_destroy(instance->frame_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4009 | instance->frame_dma_pool = NULL; |
| 4010 | |
| 4011 | return -ENOMEM; |
| 4012 | } |
| 4013 | |
| 4014 | /* |
| 4015 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 4016 | * By making cmd->index as the context instead of the &cmd, we can |
| 4017 | * always use 32bit context regardless of the architecture |
| 4018 | */ |
| 4019 | for (i = 0; i < max_cmd; i++) { |
| 4020 | |
| 4021 | cmd = instance->cmd_list[i]; |
| 4022 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4023 | cmd->frame = dma_pool_alloc(instance->frame_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4024 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 4025 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4026 | cmd->sense = dma_pool_alloc(instance->sense_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4027 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 4028 | |
| 4029 | /* |
| 4030 | * megasas_teardown_frame_pool() takes care of freeing |
| 4031 | * whatever has been allocated |
| 4032 | */ |
| 4033 | if (!cmd->frame || !cmd->sense) { |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4034 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "dma_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4035 | megasas_teardown_frame_pool(instance); |
| 4036 | return -ENOMEM; |
| 4037 | } |
| 4038 | |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 4039 | memset(cmd->frame, 0, instance->mfi_frame_size); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4040 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4041 | cmd->frame->io.pad_0 = 0; |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4042 | if ((instance->adapter_type == MFI_SERIES) && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 4043 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | /** |
| 4050 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 4051 | * @instance: Adapter soft state |
| 4052 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4053 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4054 | { |
| 4055 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4056 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4057 | /* First free the MFI frame pool */ |
| 4058 | megasas_teardown_frame_pool(instance); |
| 4059 | |
| 4060 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4061 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 4062 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4063 | kfree(instance->cmd_list[i]); |
| 4064 | |
| 4065 | /* Free the cmd_list buffer itself */ |
| 4066 | kfree(instance->cmd_list); |
| 4067 | instance->cmd_list = NULL; |
| 4068 | |
| 4069 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 4070 | } |
| 4071 | |
| 4072 | /** |
| 4073 | * megasas_alloc_cmds - Allocates the command packets |
| 4074 | * @instance: Adapter soft state |
| 4075 | * |
| 4076 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 4077 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 4078 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 4079 | * the FW. |
| 4080 | * |
| 4081 | * Each frame has a 32-bit field called context (tag). This context is used |
| 4082 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 4083 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 4084 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 4085 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 4086 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 4087 | * This array is used only to look up the megasas_cmd given the context. The |
| 4088 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 4089 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4090 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4091 | { |
| 4092 | int i; |
| 4093 | int j; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4094 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4095 | struct megasas_cmd *cmd; |
| 4096 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4097 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4098 | |
| 4099 | /* |
| 4100 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 4101 | * Allocate the dynamic array first and then allocate individual |
| 4102 | * commands. |
| 4103 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4104 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4105 | |
| 4106 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4107 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4108 | return -ENOMEM; |
| 4109 | } |
| 4110 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4111 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4112 | |
| 4113 | for (i = 0; i < max_cmd; i++) { |
| 4114 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 4115 | GFP_KERNEL); |
| 4116 | |
| 4117 | if (!instance->cmd_list[i]) { |
| 4118 | |
| 4119 | for (j = 0; j < i; j++) |
| 4120 | kfree(instance->cmd_list[j]); |
| 4121 | |
| 4122 | kfree(instance->cmd_list); |
| 4123 | instance->cmd_list = NULL; |
| 4124 | |
| 4125 | return -ENOMEM; |
| 4126 | } |
| 4127 | } |
| 4128 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4129 | for (i = 0; i < max_cmd; i++) { |
| 4130 | cmd = instance->cmd_list[i]; |
| 4131 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 4132 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4133 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4134 | cmd->instance = instance; |
| 4135 | |
| 4136 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 4137 | } |
| 4138 | |
| 4139 | /* |
| 4140 | * Create a frame pool and assign one frame to each cmd |
| 4141 | */ |
| 4142 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4143 | 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] | 4144 | megasas_free_cmds(instance); |
| 4145 | } |
| 4146 | |
| 4147 | return 0; |
| 4148 | } |
| 4149 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4150 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4151 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 4152 | * @instance: Adapter soft state |
| 4153 | * |
| 4154 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 4155 | * or FW is not under OCR. |
| 4156 | */ |
| 4157 | inline int |
| 4158 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 4159 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4160 | if (instance->adapter_type == MFI_SERIES) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4161 | return KILL_ADAPTER; |
| 4162 | else if (instance->unload || |
| 4163 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 4164 | return IGNORE_TIMEOUT; |
| 4165 | else |
| 4166 | return INITIATE_OCR; |
| 4167 | } |
| 4168 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4169 | static void |
| 4170 | megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4171 | { |
| 4172 | int ret; |
| 4173 | struct megasas_cmd *cmd; |
| 4174 | struct megasas_dcmd_frame *dcmd; |
| 4175 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4176 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 4177 | u16 device_id = 0; |
| 4178 | |
| 4179 | device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4180 | cmd = megasas_get_cmd(instance); |
| 4181 | |
| 4182 | if (!cmd) { |
| 4183 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4184 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | dcmd = &cmd->frame->dcmd; |
| 4188 | |
| 4189 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4190 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4191 | |
| 4192 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4193 | dcmd->cmd = MFI_CMD_DCMD; |
| 4194 | dcmd->cmd_status = 0xFF; |
| 4195 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4196 | dcmd->flags = MFI_FRAME_DIR_READ; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4197 | dcmd->timeout = 0; |
| 4198 | dcmd->pad_0 = 0; |
| 4199 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4200 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4201 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4202 | megasas_set_dma_settings(instance, dcmd, instance->pd_info_h, |
| 4203 | sizeof(struct MR_PD_INFO)); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4204 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4205 | if ((instance->adapter_type != MFI_SERIES) && |
| 4206 | !instance->mask_interrupts) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4207 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4208 | else |
| 4209 | ret = megasas_issue_polled(instance, cmd); |
| 4210 | |
| 4211 | switch (ret) { |
| 4212 | case DCMD_SUCCESS: |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4213 | mr_device_priv_data = sdev->hostdata; |
| 4214 | le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType); |
| 4215 | mr_device_priv_data->interface_type = |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4216 | instance->pd_info->state.ddf.pdType.intf; |
| 4217 | break; |
| 4218 | |
| 4219 | case DCMD_TIMEOUT: |
| 4220 | |
| 4221 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4222 | case INITIATE_OCR: |
| 4223 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4224 | megasas_reset_fusion(instance->host, |
| 4225 | MFI_IO_TIMEOUT_OCR); |
| 4226 | break; |
| 4227 | case KILL_ADAPTER: |
| 4228 | megaraid_sas_kill_hba(instance); |
| 4229 | break; |
| 4230 | case IGNORE_TIMEOUT: |
| 4231 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4232 | __func__, __LINE__); |
| 4233 | break; |
| 4234 | } |
| 4235 | |
| 4236 | break; |
| 4237 | } |
| 4238 | |
| 4239 | if (ret != DCMD_TIMEOUT) |
| 4240 | megasas_return_cmd(instance, cmd); |
| 4241 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4242 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4243 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4244 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4245 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4246 | * @instance: Adapter soft state |
| 4247 | * @pd_list: pd_list structure |
| 4248 | * |
| 4249 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4250 | * list structure. This information is mainly used to find out SYSTEM |
| 4251 | * supported by the FW. |
| 4252 | */ |
| 4253 | static int |
| 4254 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4255 | { |
| 4256 | int ret = 0, pd_index = 0; |
| 4257 | struct megasas_cmd *cmd; |
| 4258 | struct megasas_dcmd_frame *dcmd; |
| 4259 | struct MR_PD_LIST *ci; |
| 4260 | struct MR_PD_ADDRESS *pd_addr; |
| 4261 | dma_addr_t ci_h = 0; |
| 4262 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4263 | if (instance->pd_list_not_supported) { |
| 4264 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4265 | "not supported by firmware\n"); |
| 4266 | return ret; |
| 4267 | } |
| 4268 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4269 | ci = instance->pd_list_buf; |
| 4270 | ci_h = instance->pd_list_buf_h; |
| 4271 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4272 | cmd = megasas_get_cmd(instance); |
| 4273 | |
| 4274 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4275 | 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] | 4276 | return -ENOMEM; |
| 4277 | } |
| 4278 | |
| 4279 | dcmd = &cmd->frame->dcmd; |
| 4280 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4281 | memset(ci, 0, sizeof(*ci)); |
| 4282 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4283 | |
| 4284 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4285 | dcmd->mbox.b[1] = 0; |
| 4286 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4287 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4288 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4289 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4290 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4291 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4292 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4293 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4294 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4295 | megasas_set_dma_settings(instance, dcmd, instance->pd_list_buf_h, |
| 4296 | (MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST))); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4297 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4298 | if ((instance->adapter_type != MFI_SERIES) && |
| 4299 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4300 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4301 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4302 | else |
| 4303 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4304 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4305 | switch (ret) { |
| 4306 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4307 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4308 | "failed/not supported by firmware\n"); |
| 4309 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4310 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4311 | megaraid_sas_kill_hba(instance); |
| 4312 | else |
| 4313 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4314 | break; |
| 4315 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4316 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4317 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4318 | case INITIATE_OCR: |
| 4319 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4320 | /* |
| 4321 | * DCMD failed from AEN path. |
| 4322 | * AEN path already hold reset_mutex to avoid PCI access |
| 4323 | * while OCR is in progress. |
| 4324 | */ |
| 4325 | mutex_unlock(&instance->reset_mutex); |
| 4326 | megasas_reset_fusion(instance->host, |
| 4327 | MFI_IO_TIMEOUT_OCR); |
| 4328 | mutex_lock(&instance->reset_mutex); |
| 4329 | break; |
| 4330 | case KILL_ADAPTER: |
| 4331 | megaraid_sas_kill_hba(instance); |
| 4332 | break; |
| 4333 | case IGNORE_TIMEOUT: |
| 4334 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4335 | __func__, __LINE__); |
| 4336 | break; |
| 4337 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4338 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4339 | break; |
| 4340 | |
| 4341 | case DCMD_SUCCESS: |
| 4342 | pd_addr = ci->addr; |
| 4343 | |
| 4344 | if ((le32_to_cpu(ci->count) > |
| 4345 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4346 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4347 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4348 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4349 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4350 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4351 | 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] | 4352 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4353 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4354 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4355 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4356 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4357 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4358 | pd_addr++; |
| 4359 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4360 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4361 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4362 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4363 | break; |
| 4364 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4365 | } |
| 4366 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4367 | if (ret != DCMD_TIMEOUT) |
| 4368 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4369 | |
| 4370 | return ret; |
| 4371 | } |
| 4372 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4373 | /* |
| 4374 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4375 | * @instance: Adapter soft state |
| 4376 | * @ld_list: ld_list structure |
| 4377 | * |
| 4378 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4379 | * list structure. This information is mainly used to find out SYSTEM |
| 4380 | * supported by the FW. |
| 4381 | */ |
| 4382 | static int |
| 4383 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4384 | { |
| 4385 | int ret = 0, ld_index = 0, ids = 0; |
| 4386 | struct megasas_cmd *cmd; |
| 4387 | struct megasas_dcmd_frame *dcmd; |
| 4388 | struct MR_LD_LIST *ci; |
| 4389 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4390 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4391 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4392 | ci = instance->ld_list_buf; |
| 4393 | ci_h = instance->ld_list_buf_h; |
| 4394 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4395 | cmd = megasas_get_cmd(instance); |
| 4396 | |
| 4397 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4398 | 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] | 4399 | return -ENOMEM; |
| 4400 | } |
| 4401 | |
| 4402 | dcmd = &cmd->frame->dcmd; |
| 4403 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4404 | memset(ci, 0, sizeof(*ci)); |
| 4405 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4406 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4407 | if (instance->supportmax256vd) |
| 4408 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4409 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4410 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4411 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4412 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4413 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4414 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4415 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4416 | dcmd->pad_0 = 0; |
| 4417 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4418 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4419 | sizeof(struct MR_LD_LIST)); |
| 4420 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4421 | if ((instance->adapter_type != MFI_SERIES) && |
| 4422 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4423 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4424 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4425 | else |
| 4426 | ret = megasas_issue_polled(instance, cmd); |
| 4427 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4428 | ld_count = le32_to_cpu(ci->ldCount); |
| 4429 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4430 | switch (ret) { |
| 4431 | case DCMD_FAILED: |
| 4432 | megaraid_sas_kill_hba(instance); |
| 4433 | break; |
| 4434 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4435 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4436 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4437 | case INITIATE_OCR: |
| 4438 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4439 | /* |
| 4440 | * DCMD failed from AEN path. |
| 4441 | * AEN path already hold reset_mutex to avoid PCI access |
| 4442 | * while OCR is in progress. |
| 4443 | */ |
| 4444 | mutex_unlock(&instance->reset_mutex); |
| 4445 | megasas_reset_fusion(instance->host, |
| 4446 | MFI_IO_TIMEOUT_OCR); |
| 4447 | mutex_lock(&instance->reset_mutex); |
| 4448 | break; |
| 4449 | case KILL_ADAPTER: |
| 4450 | megaraid_sas_kill_hba(instance); |
| 4451 | break; |
| 4452 | case IGNORE_TIMEOUT: |
| 4453 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4454 | __func__, __LINE__); |
| 4455 | break; |
| 4456 | } |
| 4457 | |
| 4458 | break; |
| 4459 | |
| 4460 | case DCMD_SUCCESS: |
| 4461 | if (ld_count > instance->fw_supported_vd_count) |
| 4462 | break; |
| 4463 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4464 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4465 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4466 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4467 | if (ci->ldList[ld_index].state != 0) { |
| 4468 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4469 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4470 | } |
| 4471 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4472 | |
| 4473 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4474 | } |
| 4475 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4476 | if (ret != DCMD_TIMEOUT) |
| 4477 | megasas_return_cmd(instance, cmd); |
| 4478 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4479 | return ret; |
| 4480 | } |
| 4481 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4482 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4483 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4484 | * @instance: Adapter soft state |
| 4485 | * @ld_list: ld_list structure |
| 4486 | * |
| 4487 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4488 | * list structure. This information is mainly used to find out SYSTEM |
| 4489 | * supported by the FW. |
| 4490 | */ |
| 4491 | static int |
| 4492 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4493 | { |
| 4494 | int ret = 0, ld_index = 0, ids = 0; |
| 4495 | struct megasas_cmd *cmd; |
| 4496 | struct megasas_dcmd_frame *dcmd; |
| 4497 | struct MR_LD_TARGETID_LIST *ci; |
| 4498 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4499 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4500 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4501 | ci = instance->ld_targetid_list_buf; |
| 4502 | ci_h = instance->ld_targetid_list_buf_h; |
| 4503 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4504 | cmd = megasas_get_cmd(instance); |
| 4505 | |
| 4506 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4507 | dev_warn(&instance->pdev->dev, |
| 4508 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4509 | return -ENOMEM; |
| 4510 | } |
| 4511 | |
| 4512 | dcmd = &cmd->frame->dcmd; |
| 4513 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4514 | memset(ci, 0, sizeof(*ci)); |
| 4515 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4516 | |
| 4517 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4518 | if (instance->supportmax256vd) |
| 4519 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4520 | |
| 4521 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4522 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4523 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4524 | dcmd->flags = MFI_FRAME_DIR_READ; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4525 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4526 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4527 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4528 | dcmd->pad_0 = 0; |
| 4529 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4530 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4531 | sizeof(struct MR_LD_TARGETID_LIST)); |
| 4532 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4533 | if ((instance->adapter_type != MFI_SERIES) && |
| 4534 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4535 | 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] | 4536 | else |
| 4537 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4538 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4539 | switch (ret) { |
| 4540 | case DCMD_FAILED: |
| 4541 | dev_info(&instance->pdev->dev, |
| 4542 | "DCMD not supported by firmware - %s %d\n", |
| 4543 | __func__, __LINE__); |
| 4544 | ret = megasas_get_ld_list(instance); |
| 4545 | break; |
| 4546 | case DCMD_TIMEOUT: |
| 4547 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4548 | case INITIATE_OCR: |
| 4549 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4550 | /* |
| 4551 | * DCMD failed from AEN path. |
| 4552 | * AEN path already hold reset_mutex to avoid PCI access |
| 4553 | * while OCR is in progress. |
| 4554 | */ |
| 4555 | mutex_unlock(&instance->reset_mutex); |
| 4556 | megasas_reset_fusion(instance->host, |
| 4557 | MFI_IO_TIMEOUT_OCR); |
| 4558 | mutex_lock(&instance->reset_mutex); |
| 4559 | break; |
| 4560 | case KILL_ADAPTER: |
| 4561 | megaraid_sas_kill_hba(instance); |
| 4562 | break; |
| 4563 | case IGNORE_TIMEOUT: |
| 4564 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4565 | __func__, __LINE__); |
| 4566 | break; |
| 4567 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4568 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4569 | break; |
| 4570 | case DCMD_SUCCESS: |
| 4571 | tgtid_count = le32_to_cpu(ci->count); |
| 4572 | |
| 4573 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4574 | break; |
| 4575 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4576 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4577 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4578 | ids = ci->targetId[ld_index]; |
| 4579 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4580 | } |
| 4581 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4582 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4585 | if (ret != DCMD_TIMEOUT) |
| 4586 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4587 | |
| 4588 | return ret; |
| 4589 | } |
| 4590 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4591 | /* |
| 4592 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4593 | * instance : Controller's instance |
| 4594 | */ |
| 4595 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4596 | { |
| 4597 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4598 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4599 | |
| 4600 | fusion = instance->ctrl_context; |
| 4601 | /* For MFI based controllers return dummy success */ |
| 4602 | if (!fusion) |
| 4603 | return; |
| 4604 | |
| 4605 | instance->supportmax256vd = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4606 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4607 | /* Below is additional check to address future FW enhancement */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4608 | if (instance->ctrl_info_buf->max_lds > 64) |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4609 | instance->supportmax256vd = 1; |
| 4610 | |
| 4611 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4612 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4613 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4614 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4615 | if (instance->supportmax256vd) { |
| 4616 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4617 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4618 | } else { |
| 4619 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4620 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4621 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4622 | |
| 4623 | dev_info(&instance->pdev->dev, |
| 4624 | "firmware type\t: %s\n", |
| 4625 | instance->supportmax256vd ? "Extended VD(240 VD)firmware" : |
| 4626 | "Legacy(64 VD) firmware"); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4627 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4628 | if (instance->max_raid_mapsize) { |
| 4629 | ventura_map_sz = instance->max_raid_mapsize * |
| 4630 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4631 | fusion->current_map_sz = ventura_map_sz; |
| 4632 | fusion->max_map_sz = ventura_map_sz; |
| 4633 | } else { |
| 4634 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4635 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4636 | (instance->fw_supported_vd_count - 1)); |
| 4637 | fusion->new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4638 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4639 | fusion->max_map_sz = |
| 4640 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4641 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4642 | if (instance->supportmax256vd) |
| 4643 | fusion->current_map_sz = fusion->new_map_sz; |
| 4644 | else |
| 4645 | fusion->current_map_sz = fusion->old_map_sz; |
| 4646 | } |
| 4647 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4648 | fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4649 | } |
| 4650 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4651 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4652 | * megasas_get_controller_info - Returns FW's controller structure |
| 4653 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4654 | * |
| 4655 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4656 | * This information is mainly used to find out the maximum IO transfer per |
| 4657 | * command supported by the FW. |
| 4658 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4659 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4660 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4661 | { |
| 4662 | int ret = 0; |
| 4663 | struct megasas_cmd *cmd; |
| 4664 | struct megasas_dcmd_frame *dcmd; |
| 4665 | struct megasas_ctrl_info *ci; |
| 4666 | dma_addr_t ci_h = 0; |
| 4667 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4668 | ci = instance->ctrl_info_buf; |
| 4669 | ci_h = instance->ctrl_info_buf_h; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4670 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4671 | cmd = megasas_get_cmd(instance); |
| 4672 | |
| 4673 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4674 | 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] | 4675 | return -ENOMEM; |
| 4676 | } |
| 4677 | |
| 4678 | dcmd = &cmd->frame->dcmd; |
| 4679 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4680 | memset(ci, 0, sizeof(*ci)); |
| 4681 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4682 | |
| 4683 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4684 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4685 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4686 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4687 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4688 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4689 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4690 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4691 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4692 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4693 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4694 | sizeof(struct megasas_ctrl_info)); |
| 4695 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4696 | if ((instance->adapter_type != MFI_SERIES) && |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame^] | 4697 | !instance->mask_interrupts) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4698 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame^] | 4699 | } else { |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4700 | ret = megasas_issue_polled(instance, cmd); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame^] | 4701 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4702 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4703 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4704 | switch (ret) { |
| 4705 | case DCMD_SUCCESS: |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4706 | /* Save required controller information in |
| 4707 | * CPU endianness format. |
| 4708 | */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4709 | le32_to_cpus((u32 *)&ci->properties.OnOffProperties); |
| 4710 | le32_to_cpus((u32 *)&ci->adapterOperations2); |
| 4711 | le32_to_cpus((u32 *)&ci->adapterOperations3); |
| 4712 | le16_to_cpus((u16 *)&ci->adapter_operations4); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4713 | |
| 4714 | /* Update the latest Ext VD info. |
| 4715 | * From Init path, store current firmware details. |
| 4716 | * From OCR path, detect any firmware properties changes. |
| 4717 | * in case of Firmware upgrade without system reboot. |
| 4718 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4719 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4720 | instance->use_seqnum_jbod_fp = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4721 | ci->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4722 | instance->support_morethan256jbod = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4723 | ci->adapter_operations4.support_pd_map_target_id; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4724 | |
| 4725 | /*Check whether controller is iMR or MR */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4726 | instance->is_imr = (ci->memory_size ? 0 : 1); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4727 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4728 | "controller type\t: %s(%dMB)\n", |
| 4729 | instance->is_imr ? "iMR" : "MR", |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4730 | le16_to_cpu(ci->memory_size)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4731 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 4732 | instance->disableOnlineCtrlReset = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4733 | ci->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4734 | instance->secure_jbod_support = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4735 | ci->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4736 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 4737 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4738 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 4739 | instance->secure_jbod_support ? "Yes" : "No"); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4740 | break; |
| 4741 | |
| 4742 | case DCMD_TIMEOUT: |
| 4743 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4744 | case INITIATE_OCR: |
| 4745 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4746 | megasas_reset_fusion(instance->host, |
| 4747 | MFI_IO_TIMEOUT_OCR); |
| 4748 | break; |
| 4749 | case KILL_ADAPTER: |
| 4750 | megaraid_sas_kill_hba(instance); |
| 4751 | break; |
| 4752 | case IGNORE_TIMEOUT: |
| 4753 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4754 | __func__, __LINE__); |
| 4755 | break; |
| 4756 | } |
| 4757 | case DCMD_FAILED: |
| 4758 | megaraid_sas_kill_hba(instance); |
| 4759 | break; |
| 4760 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4761 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4762 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4763 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4764 | |
| 4765 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4766 | return ret; |
| 4767 | } |
| 4768 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4769 | /* |
| 4770 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 4771 | * to firmware |
| 4772 | * |
| 4773 | * @instance: Adapter soft state |
| 4774 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 4775 | MR_CRASH_BUF_TURN_OFF = 0 |
| 4776 | MR_CRASH_BUF_TURN_ON = 1 |
| 4777 | * @return 0 on success non-zero on failure. |
| 4778 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 4779 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 4780 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 4781 | * crash dump feature is supported by the FW. |
| 4782 | * |
| 4783 | */ |
| 4784 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 4785 | u8 crash_buf_state) |
| 4786 | { |
| 4787 | int ret = 0; |
| 4788 | struct megasas_cmd *cmd; |
| 4789 | struct megasas_dcmd_frame *dcmd; |
| 4790 | |
| 4791 | cmd = megasas_get_cmd(instance); |
| 4792 | |
| 4793 | if (!cmd) { |
| 4794 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4795 | return -ENOMEM; |
| 4796 | } |
| 4797 | |
| 4798 | |
| 4799 | dcmd = &cmd->frame->dcmd; |
| 4800 | |
| 4801 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4802 | dcmd->mbox.b[0] = crash_buf_state; |
| 4803 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4804 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4805 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4806 | dcmd->flags = MFI_FRAME_DIR_NONE; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4807 | dcmd->timeout = 0; |
| 4808 | dcmd->pad_0 = 0; |
| 4809 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4810 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4811 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4812 | megasas_set_dma_settings(instance, dcmd, instance->crash_dump_h, |
| 4813 | CRASH_DMA_BUF_SIZE); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4814 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4815 | if ((instance->adapter_type != MFI_SERIES) && |
| 4816 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4817 | 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] | 4818 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4819 | ret = megasas_issue_polled(instance, cmd); |
| 4820 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4821 | if (ret == DCMD_TIMEOUT) { |
| 4822 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4823 | case INITIATE_OCR: |
| 4824 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4825 | megasas_reset_fusion(instance->host, |
| 4826 | MFI_IO_TIMEOUT_OCR); |
| 4827 | break; |
| 4828 | case KILL_ADAPTER: |
| 4829 | megaraid_sas_kill_hba(instance); |
| 4830 | break; |
| 4831 | case IGNORE_TIMEOUT: |
| 4832 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4833 | __func__, __LINE__); |
| 4834 | break; |
| 4835 | } |
| 4836 | } else |
| 4837 | megasas_return_cmd(instance, cmd); |
| 4838 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4839 | return ret; |
| 4840 | } |
| 4841 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4842 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4843 | * megasas_issue_init_mfi - Initializes the FW |
| 4844 | * @instance: Adapter soft state |
| 4845 | * |
| 4846 | * Issues the INIT MFI cmd |
| 4847 | */ |
| 4848 | static int |
| 4849 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 4850 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 4851 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4852 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4853 | struct megasas_init_frame *init_frame; |
| 4854 | struct megasas_init_queue_info *initq_info; |
| 4855 | dma_addr_t init_frame_h; |
| 4856 | dma_addr_t initq_info_h; |
| 4857 | |
| 4858 | /* |
| 4859 | * Prepare a init frame. Note the init frame points to queue info |
| 4860 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 4861 | * this frame - since we don't need any SGL - we use SGL's space as |
| 4862 | * queue info structure |
| 4863 | * |
| 4864 | * We will not get a NULL command below. We just created the pool. |
| 4865 | */ |
| 4866 | cmd = megasas_get_cmd(instance); |
| 4867 | |
| 4868 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 4869 | initq_info = (struct megasas_init_queue_info *) |
| 4870 | ((unsigned long)init_frame + 64); |
| 4871 | |
| 4872 | init_frame_h = cmd->frame_phys_addr; |
| 4873 | initq_info_h = init_frame_h + 64; |
| 4874 | |
| 4875 | context = init_frame->context; |
| 4876 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 4877 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 4878 | init_frame->context = context; |
| 4879 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4880 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 4881 | 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] | 4882 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4883 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 4884 | 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] | 4885 | |
| 4886 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4887 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4888 | init_frame->queue_info_new_phys_addr_lo = |
| 4889 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 4890 | init_frame->queue_info_new_phys_addr_hi = |
| 4891 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4892 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4893 | 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] | 4894 | |
| 4895 | /* |
| 4896 | * disable the intr before firing the init frame to FW |
| 4897 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4898 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4899 | |
| 4900 | /* |
| 4901 | * Issue the init frame in polled mode |
| 4902 | */ |
| 4903 | |
| 4904 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4905 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4906 | megasas_return_cmd(instance, cmd); |
| 4907 | goto fail_fw_init; |
| 4908 | } |
| 4909 | |
| 4910 | megasas_return_cmd(instance, cmd); |
| 4911 | |
| 4912 | return 0; |
| 4913 | |
| 4914 | fail_fw_init: |
| 4915 | return -EINVAL; |
| 4916 | } |
| 4917 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4918 | static u32 |
| 4919 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4920 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4921 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4922 | u32 context_sz; |
| 4923 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4924 | |
| 4925 | reg_set = instance->reg_set; |
| 4926 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4927 | /* |
| 4928 | * Get various operational parameters from status register |
| 4929 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4930 | 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] | 4931 | /* |
| 4932 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 4933 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 4934 | * does not exceed max cmds that the FW can support |
| 4935 | */ |
| 4936 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4937 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4938 | 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] | 4939 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4940 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4941 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 4942 | * are reserved for IOCTL + driver's internal DCMDs. |
| 4943 | */ |
| 4944 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 4945 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 4946 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4947 | MEGASAS_SKINNY_INT_CMDS); |
| 4948 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 4949 | } else { |
| 4950 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4951 | MEGASAS_INT_CMDS); |
| 4952 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 4953 | } |
| 4954 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 4955 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4956 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4957 | * Create a pool of commands |
| 4958 | */ |
| 4959 | if (megasas_alloc_cmds(instance)) |
| 4960 | goto fail_alloc_cmds; |
| 4961 | |
| 4962 | /* |
| 4963 | * Allocate memory for reply queue. Length of reply queue should |
| 4964 | * be _one_ more than the maximum commands handled by the firmware. |
| 4965 | * |
| 4966 | * Note: When FW completes commands, it places corresponding contex |
| 4967 | * values in this circular reply queue. This circular queue is a fairly |
| 4968 | * typical producer-consumer queue. FW is the producer (of completed |
| 4969 | * commands) and the driver is the consumer. |
| 4970 | */ |
| 4971 | context_sz = sizeof(u32); |
| 4972 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 4973 | |
| 4974 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 4975 | reply_q_sz, |
| 4976 | &instance->reply_queue_h); |
| 4977 | |
| 4978 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4979 | 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] | 4980 | goto fail_reply_queue; |
| 4981 | } |
| 4982 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4983 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4984 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4985 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4986 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4987 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 4988 | "Fail from %s %d\n", instance->unique_id, |
| 4989 | __func__, __LINE__); |
| 4990 | goto fail_fw_init; |
| 4991 | } |
| 4992 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4993 | instance->fw_support_ieee = 0; |
| 4994 | instance->fw_support_ieee = |
| 4995 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 4996 | 0x04000000); |
| 4997 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4998 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4999 | instance->fw_support_ieee); |
| 5000 | |
| 5001 | if (instance->fw_support_ieee) |
| 5002 | instance->flag_ieee = 1; |
| 5003 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5004 | return 0; |
| 5005 | |
| 5006 | fail_fw_init: |
| 5007 | |
| 5008 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 5009 | instance->reply_queue, instance->reply_queue_h); |
| 5010 | fail_reply_queue: |
| 5011 | megasas_free_cmds(instance); |
| 5012 | |
| 5013 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5014 | return 1; |
| 5015 | } |
| 5016 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5017 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5018 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5019 | * @instance: Adapter soft state |
| 5020 | * |
| 5021 | * Do not enable interrupt, only setup ISRs. |
| 5022 | * |
| 5023 | * Return 0 on success. |
| 5024 | */ |
| 5025 | static int |
| 5026 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 5027 | { |
| 5028 | struct pci_dev *pdev; |
| 5029 | |
| 5030 | pdev = instance->pdev; |
| 5031 | instance->irq_context[0].instance = instance; |
| 5032 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5033 | if (request_irq(pci_irq_vector(pdev, 0), |
| 5034 | instance->instancet->service_isr, IRQF_SHARED, |
| 5035 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5036 | dev_err(&instance->pdev->dev, |
| 5037 | "Failed to register IRQ from %s %d\n", |
| 5038 | __func__, __LINE__); |
| 5039 | return -1; |
| 5040 | } |
| 5041 | return 0; |
| 5042 | } |
| 5043 | |
| 5044 | /** |
| 5045 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 5046 | * @instance: Adapter soft state |
| 5047 | * @is_probe: Driver probe check |
| 5048 | * |
| 5049 | * Do not enable interrupt, only setup ISRs. |
| 5050 | * |
| 5051 | * Return 0 on success. |
| 5052 | */ |
| 5053 | static int |
| 5054 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 5055 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5056 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5057 | struct pci_dev *pdev; |
| 5058 | |
| 5059 | pdev = instance->pdev; |
| 5060 | |
| 5061 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5062 | for (i = 0; i < instance->msix_vectors; i++) { |
| 5063 | instance->irq_context[i].instance = instance; |
| 5064 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5065 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5066 | instance->instancet->service_isr, 0, "megasas", |
| 5067 | &instance->irq_context[i])) { |
| 5068 | dev_err(&instance->pdev->dev, |
| 5069 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5070 | for (j = 0; j < i; j++) |
| 5071 | free_irq(pci_irq_vector(pdev, j), |
| 5072 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5073 | /* Retry irq register for IO_APIC*/ |
| 5074 | instance->msix_vectors = 0; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5075 | if (is_probe) { |
| 5076 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5077 | return megasas_setup_irqs_ioapic(instance); |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5078 | } else { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5079 | return -1; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5080 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5081 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5082 | } |
| 5083 | return 0; |
| 5084 | } |
| 5085 | |
| 5086 | /* |
| 5087 | * megasas_destroy_irqs- unregister interrupts. |
| 5088 | * @instance: Adapter soft state |
| 5089 | * return: void |
| 5090 | */ |
| 5091 | static void |
| 5092 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 5093 | |
| 5094 | int i; |
| 5095 | |
| 5096 | if (instance->msix_vectors) |
| 5097 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5098 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5099 | &instance->irq_context[i]); |
| 5100 | } |
| 5101 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5102 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 5103 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5104 | } |
| 5105 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5106 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5107 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 5108 | * @instance: Adapter soft state |
| 5109 | * @is_probe: Driver probe check |
| 5110 | * |
| 5111 | * Return 0 on success. |
| 5112 | */ |
| 5113 | void |
| 5114 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 5115 | { |
| 5116 | int i; |
| 5117 | struct fusion_context *fusion = instance->ctrl_context; |
| 5118 | u32 pd_seq_map_sz; |
| 5119 | |
| 5120 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 5121 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 5122 | |
| 5123 | if (reset_devices || !fusion || |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5124 | !instance->ctrl_info_buf->adapterOperations3.useSeqNumJbodFP) { |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5125 | dev_info(&instance->pdev->dev, |
| 5126 | "Jbod map is not supported %s %d\n", |
| 5127 | __func__, __LINE__); |
| 5128 | instance->use_seqnum_jbod_fp = false; |
| 5129 | return; |
| 5130 | } |
| 5131 | |
| 5132 | if (fusion->pd_seq_sync[0]) |
| 5133 | goto skip_alloc; |
| 5134 | |
| 5135 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 5136 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 5137 | (&instance->pdev->dev, pd_seq_map_sz, |
| 5138 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 5139 | if (!fusion->pd_seq_sync[i]) { |
| 5140 | dev_err(&instance->pdev->dev, |
| 5141 | "Failed to allocate memory from %s %d\n", |
| 5142 | __func__, __LINE__); |
| 5143 | if (i == 1) { |
| 5144 | dma_free_coherent(&instance->pdev->dev, |
| 5145 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 5146 | fusion->pd_seq_phys[0]); |
| 5147 | fusion->pd_seq_sync[0] = NULL; |
| 5148 | } |
| 5149 | instance->use_seqnum_jbod_fp = false; |
| 5150 | return; |
| 5151 | } |
| 5152 | } |
| 5153 | |
| 5154 | skip_alloc: |
| 5155 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5156 | !megasas_sync_pd_seq_num(instance, true)) |
| 5157 | instance->use_seqnum_jbod_fp = true; |
| 5158 | else |
| 5159 | instance->use_seqnum_jbod_fp = false; |
| 5160 | } |
| 5161 | |
| 5162 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5163 | * megasas_init_fw - Initializes the FW |
| 5164 | * @instance: Adapter soft state |
| 5165 | * |
| 5166 | * This is the main function for initializing firmware |
| 5167 | */ |
| 5168 | |
| 5169 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5170 | { |
| 5171 | u32 max_sectors_1; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5172 | u32 max_sectors_2, tmp_sectors, msix_enable; |
| 5173 | u32 scratch_pad_2, scratch_pad_3, scratch_pad_4; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5174 | resource_size_t base_addr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5175 | struct megasas_register_set __iomem *reg_set; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5176 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5177 | unsigned long bar_list; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5178 | int i, j, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5179 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5180 | struct fusion_context *fusion; |
| 5181 | |
| 5182 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5183 | |
| 5184 | /* Find first memory bar */ |
| 5185 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5186 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5187 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5188 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5189 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5190 | return -EBUSY; |
| 5191 | } |
| 5192 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5193 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5194 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5195 | |
| 5196 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5197 | 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] | 5198 | goto fail_ioremap; |
| 5199 | } |
| 5200 | |
| 5201 | reg_set = instance->reg_set; |
| 5202 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5203 | if (instance->adapter_type != MFI_SERIES) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5204 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5205 | else { |
| 5206 | switch (instance->pdev->device) { |
| 5207 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5208 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5209 | instance->instancet = &megasas_instance_template_ppc; |
| 5210 | break; |
| 5211 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5212 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5213 | instance->instancet = &megasas_instance_template_gen2; |
| 5214 | break; |
| 5215 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5216 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5217 | instance->instancet = &megasas_instance_template_skinny; |
| 5218 | break; |
| 5219 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5220 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5221 | default: |
| 5222 | instance->instancet = &megasas_instance_template_xscale; |
| 5223 | instance->pd_list_not_supported = 1; |
| 5224 | break; |
| 5225 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5226 | } |
| 5227 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5228 | if (megasas_transition_to_ready(instance, 0)) { |
| 5229 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5230 | instance->instancet->adp_reset |
| 5231 | (instance, instance->reg_set); |
| 5232 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 5233 | dev_info(&instance->pdev->dev, |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5234 | "FW restarted successfully from %s!\n", |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5235 | __func__); |
| 5236 | |
| 5237 | /*waitting for about 30 second before retry*/ |
| 5238 | ssleep(30); |
| 5239 | |
| 5240 | if (megasas_transition_to_ready(instance, 0)) |
| 5241 | goto fail_ready_state; |
| 5242 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5243 | |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5244 | megasas_init_ctrl_params(instance); |
| 5245 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5246 | if (megasas_set_dma_mask(instance)) |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5247 | goto fail_ready_state; |
| 5248 | |
| 5249 | if (megasas_alloc_ctrl_mem(instance)) |
| 5250 | goto fail_alloc_dma_buf; |
| 5251 | |
| 5252 | if (megasas_alloc_ctrl_dma_buffers(instance)) |
| 5253 | goto fail_alloc_dma_buf; |
| 5254 | |
| 5255 | fusion = instance->ctrl_context; |
| 5256 | |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame] | 5257 | if (instance->adapter_type == VENTURA_SERIES) { |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5258 | scratch_pad_3 = |
| 5259 | readl(&instance->reg_set->outbound_scratch_pad_3); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5260 | instance->max_raid_mapsize = ((scratch_pad_3 >> |
| 5261 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5262 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5263 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5264 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5265 | /* Check if MSI-X is supported while in ready state */ |
| 5266 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 5267 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5268 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5269 | int irq_flags = PCI_IRQ_MSIX; |
| 5270 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5271 | scratch_pad_2 = readl |
| 5272 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5273 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5274 | if (fusion) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5275 | if (instance->adapter_type == THUNDERBOLT_SERIES) { |
| 5276 | /* Thunderbolt Series*/ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5277 | instance->msix_vectors = (scratch_pad_2 |
| 5278 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 5279 | fw_msix_count = instance->msix_vectors; |
| 5280 | } else { /* Invader series supports more than 8 MSI-x vectors*/ |
| 5281 | instance->msix_vectors = ((scratch_pad_2 |
| 5282 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5283 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5284 | if (instance->msix_vectors > 16) |
| 5285 | instance->msix_combined = true; |
| 5286 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5287 | if (rdpq_enable) |
| 5288 | instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? |
| 5289 | 1 : 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5290 | fw_msix_count = instance->msix_vectors; |
| 5291 | /* Save 1-15 reply post index address to local memory |
| 5292 | * Index 0 is already saved from reg offset |
| 5293 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5294 | */ |
| 5295 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5296 | instance->reply_post_host_index_addr[loop] = |
| 5297 | (u32 __iomem *) |
| 5298 | ((u8 __iomem *)instance->reg_set + |
| 5299 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5300 | + (loop * 0x10)); |
| 5301 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5302 | } |
| 5303 | if (msix_vectors) |
| 5304 | instance->msix_vectors = min(msix_vectors, |
| 5305 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5306 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5307 | instance->msix_vectors = 1; |
| 5308 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 5309 | instance->msix_vectors = min(instance->msix_vectors, |
| 5310 | (unsigned int)num_online_cpus()); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5311 | if (smp_affinity_enable) |
| 5312 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5313 | i = pci_alloc_irq_vectors(instance->pdev, 1, |
| 5314 | instance->msix_vectors, irq_flags); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 5315 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5316 | instance->msix_vectors = i; |
| 5317 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5318 | instance->msix_vectors = 0; |
| 5319 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5320 | /* |
| 5321 | * MSI-X host index 0 is common for all adapter. |
| 5322 | * It is used for all MPT based Adapters. |
| 5323 | */ |
| 5324 | if (instance->msix_combined) { |
| 5325 | instance->reply_post_host_index_addr[0] = |
| 5326 | (u32 *)((u8 *)instance->reg_set + |
| 5327 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 5328 | } else { |
| 5329 | instance->reply_post_host_index_addr[0] = |
| 5330 | (u32 *)((u8 *)instance->reg_set + |
| 5331 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 5332 | } |
| 5333 | |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5334 | if (!instance->msix_vectors) { |
| 5335 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 5336 | if (i < 0) |
| 5337 | goto fail_setup_irqs; |
| 5338 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5339 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5340 | dev_info(&instance->pdev->dev, |
| 5341 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5342 | dev_info(&instance->pdev->dev, |
| 5343 | "current msix/online cpus\t: (%d/%d)\n", |
| 5344 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5345 | dev_info(&instance->pdev->dev, |
| 5346 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5347 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5348 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5349 | (unsigned long)instance); |
| 5350 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5351 | /* |
| 5352 | * Below are default value for legacy Firmware. |
| 5353 | * non-fusion based controllers |
| 5354 | */ |
| 5355 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5356 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5357 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5358 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5359 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5360 | |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame] | 5361 | if (instance->adapter_type == VENTURA_SERIES) { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5362 | scratch_pad_4 = |
| 5363 | readl(&instance->reg_set->outbound_scratch_pad_4); |
| 5364 | if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >= |
| 5365 | MR_DEFAULT_NVME_PAGE_SHIFT) |
| 5366 | instance->nvme_page_size = |
| 5367 | (1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK)); |
| 5368 | |
| 5369 | dev_info(&instance->pdev->dev, |
| 5370 | "NVME page size\t: (%d)\n", instance->nvme_page_size); |
| 5371 | } |
| 5372 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5373 | if (instance->msix_vectors ? |
| 5374 | megasas_setup_irqs_msix(instance, 1) : |
| 5375 | megasas_setup_irqs_ioapic(instance)) |
| 5376 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5377 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5378 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5379 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 5380 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5381 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5382 | megasas_setup_jbod_map(instance); |
| 5383 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5384 | /** for passthrough |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5385 | * the following function will get the PD LIST. |
| 5386 | */ |
| 5387 | memset(instance->pd_list, 0, |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5388 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5389 | if (megasas_get_pd_list(instance) < 0) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5390 | dev_err(&instance->pdev->dev, "failed to get PD list\n"); |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5391 | goto fail_get_ld_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5392 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5393 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5394 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5395 | |
| 5396 | /* stream detection initialization */ |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame] | 5397 | if (instance->adapter_type == VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5398 | fusion->stream_detect_by_ld = |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 5399 | kzalloc(sizeof(struct LD_STREAM_DETECT *) |
| 5400 | * MAX_LOGICAL_DRIVES_EXT, |
| 5401 | GFP_KERNEL); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5402 | if (!fusion->stream_detect_by_ld) { |
| 5403 | dev_err(&instance->pdev->dev, |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 5404 | "unable to allocate stream detection for pool of LDs\n"); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5405 | goto fail_get_ld_pd_list; |
| 5406 | } |
| 5407 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 5408 | fusion->stream_detect_by_ld[i] = |
Shivasharan S | e05ee4e | 2018-01-05 05:27:36 -0800 | [diff] [blame] | 5409 | kzalloc(sizeof(struct LD_STREAM_DETECT), |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5410 | GFP_KERNEL); |
| 5411 | if (!fusion->stream_detect_by_ld[i]) { |
| 5412 | dev_err(&instance->pdev->dev, |
| 5413 | "unable to allocate stream detect by LD\n "); |
| 5414 | for (j = 0; j < i; ++j) |
| 5415 | kfree(fusion->stream_detect_by_ld[j]); |
| 5416 | kfree(fusion->stream_detect_by_ld); |
| 5417 | fusion->stream_detect_by_ld = NULL; |
| 5418 | goto fail_get_ld_pd_list; |
| 5419 | } |
| 5420 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 5421 | = MR_STREAM_BITMAP; |
| 5422 | } |
| 5423 | } |
| 5424 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5425 | if (megasas_ld_list_query(instance, |
| 5426 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5427 | goto fail_get_ld_pd_list; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5428 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5429 | /* |
| 5430 | * Compute the max allowed sectors per IO: The controller info has two |
| 5431 | * limits on max sectors. Driver should use the minimum of these two. |
| 5432 | * |
| 5433 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5434 | * |
| 5435 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5436 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5437 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5438 | tmp_sectors = 0; |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5439 | ctrl_info = instance->ctrl_info_buf; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5440 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5441 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5442 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5443 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5444 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5445 | 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] | 5446 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 5447 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 5448 | instance->passive = ctrl_info->cluster.passive; |
| 5449 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5450 | instance->UnevenSpanSupport = |
| 5451 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5452 | if (instance->UnevenSpanSupport) { |
| 5453 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 5454 | if (MR_ValidateMapInfo(instance, instance->map_id)) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5455 | fusion->fast_path_io = 1; |
| 5456 | else |
| 5457 | fusion->fast_path_io = 0; |
| 5458 | |
| 5459 | } |
| 5460 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5461 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5462 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5463 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5464 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5465 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5466 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5467 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5468 | |
| 5469 | if (instance->PlasmaFW111) { |
| 5470 | iovPtr = (struct IOV_111 *) |
| 5471 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5472 | instance->requestorId = iovPtr->requestorId; |
| 5473 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5474 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5475 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5476 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5477 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5478 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5479 | instance->crash_dump_fw_support = |
| 5480 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5481 | instance->crash_dump_drv_support = |
| 5482 | (instance->crash_dump_fw_support && |
| 5483 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5484 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5485 | megasas_set_crash_dump_params(instance, |
| 5486 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5487 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5488 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5489 | if (instance->crash_dump_buf) |
| 5490 | pci_free_consistent(instance->pdev, |
| 5491 | CRASH_DMA_BUF_SIZE, |
| 5492 | instance->crash_dump_buf, |
| 5493 | instance->crash_dump_h); |
| 5494 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5495 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5496 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5497 | |
| 5498 | dev_info(&instance->pdev->dev, |
| 5499 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5500 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5501 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5502 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5503 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5504 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 5505 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5506 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 5507 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5508 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 5509 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5510 | |
| 5511 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5512 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 5513 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5514 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 5515 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5516 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5517 | /* Check for valid throttlequeuedepth module parameter */ |
| 5518 | if (throttlequeuedepth && |
| 5519 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 5520 | instance->throttlequeuedepth = throttlequeuedepth; |
| 5521 | else |
| 5522 | instance->throttlequeuedepth = |
| 5523 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 5524 | |
Shivasharan S | e636a7a | 2017-08-23 04:46:56 -0700 | [diff] [blame] | 5525 | if ((resetwaittime < 1) || |
| 5526 | (resetwaittime > MEGASAS_RESET_WAIT_TIME)) |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 5527 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 5528 | |
| 5529 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 5530 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5531 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5532 | /* Launch SR-IOV heartbeat timer */ |
| 5533 | if (instance->requestorId) { |
| 5534 | if (!megasas_sriov_start_heartbeat(instance, 1)) |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 5535 | megasas_start_timer(instance); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5536 | else |
| 5537 | instance->skip_heartbeat_timer_del = 1; |
| 5538 | } |
| 5539 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5540 | return 0; |
| 5541 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5542 | fail_get_ld_pd_list: |
| 5543 | instance->instancet->disable_intr(instance); |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5544 | fail_init_adapter: |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5545 | megasas_destroy_irqs(instance); |
| 5546 | fail_setup_irqs: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5547 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5548 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5549 | instance->msix_vectors = 0; |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5550 | fail_alloc_dma_buf: |
| 5551 | megasas_free_ctrl_dma_buffers(instance); |
| 5552 | megasas_free_ctrl_mem(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5553 | fail_ready_state: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5554 | iounmap(instance->reg_set); |
| 5555 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5556 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5557 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5558 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5559 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 5560 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5561 | return -EINVAL; |
| 5562 | } |
| 5563 | |
| 5564 | /** |
| 5565 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 5566 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5567 | */ |
| 5568 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 5569 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5570 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5571 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5572 | if (instance->reply_queue) |
| 5573 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5574 | instance->reply_queue, instance->reply_queue_h); |
| 5575 | |
| 5576 | megasas_free_cmds(instance); |
| 5577 | |
| 5578 | iounmap(instance->reg_set); |
| 5579 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5580 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | /** |
| 5584 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 5585 | * @instance: Adapter soft state |
| 5586 | * @eli: FW event log sequence numbers information |
| 5587 | * |
| 5588 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 5589 | * usually find out the latest sequence number of the events, the seq number at |
| 5590 | * the boot etc. They would "read" all the events below the latest seq number |
| 5591 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 5592 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 5593 | * wait for the events to happen. |
| 5594 | */ |
| 5595 | static int |
| 5596 | megasas_get_seq_num(struct megasas_instance *instance, |
| 5597 | struct megasas_evt_log_info *eli) |
| 5598 | { |
| 5599 | struct megasas_cmd *cmd; |
| 5600 | struct megasas_dcmd_frame *dcmd; |
| 5601 | struct megasas_evt_log_info *el_info; |
| 5602 | dma_addr_t el_info_h = 0; |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5603 | int ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5604 | |
| 5605 | cmd = megasas_get_cmd(instance); |
| 5606 | |
| 5607 | if (!cmd) { |
| 5608 | return -ENOMEM; |
| 5609 | } |
| 5610 | |
| 5611 | dcmd = &cmd->frame->dcmd; |
| 5612 | el_info = pci_alloc_consistent(instance->pdev, |
| 5613 | sizeof(struct megasas_evt_log_info), |
| 5614 | &el_info_h); |
| 5615 | |
| 5616 | if (!el_info) { |
| 5617 | megasas_return_cmd(instance, cmd); |
| 5618 | return -ENOMEM; |
| 5619 | } |
| 5620 | |
| 5621 | memset(el_info, 0, sizeof(*el_info)); |
| 5622 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5623 | |
| 5624 | dcmd->cmd = MFI_CMD_DCMD; |
| 5625 | dcmd->cmd_status = 0x0; |
| 5626 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5627 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5628 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5629 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5630 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 5631 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5632 | |
| 5633 | megasas_set_dma_settings(instance, dcmd, el_info_h, |
| 5634 | sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5635 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5636 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 5637 | if (ret != DCMD_SUCCESS) { |
| 5638 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 5639 | __func__, __LINE__); |
| 5640 | goto dcmd_failed; |
| 5641 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5642 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5643 | /* |
| 5644 | * Copy the data back into callers buffer |
| 5645 | */ |
| 5646 | eli->newest_seq_num = el_info->newest_seq_num; |
| 5647 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 5648 | eli->clear_seq_num = el_info->clear_seq_num; |
| 5649 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 5650 | eli->boot_seq_num = el_info->boot_seq_num; |
| 5651 | |
| 5652 | dcmd_failed: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5653 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 5654 | el_info, el_info_h); |
| 5655 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5656 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5657 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5658 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * megasas_register_aen - Registers for asynchronous event notification |
| 5663 | * @instance: Adapter soft state |
| 5664 | * @seq_num: The starting sequence number |
| 5665 | * @class_locale: Class of the event |
| 5666 | * |
| 5667 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 5668 | * to be notified if and only if the event is of type @class_locale |
| 5669 | */ |
| 5670 | static int |
| 5671 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 5672 | u32 class_locale_word) |
| 5673 | { |
| 5674 | int ret_val; |
| 5675 | struct megasas_cmd *cmd; |
| 5676 | struct megasas_dcmd_frame *dcmd; |
| 5677 | union megasas_evt_class_locale curr_aen; |
| 5678 | union megasas_evt_class_locale prev_aen; |
| 5679 | |
| 5680 | /* |
| 5681 | * If there an AEN pending already (aen_cmd), check if the |
| 5682 | * class_locale of that pending AEN is inclusive of the new |
| 5683 | * AEN request we currently have. If it is, then we don't have |
| 5684 | * to do anything. In other words, whichever events the current |
| 5685 | * AEN request is subscribing to, have already been subscribed |
| 5686 | * to. |
| 5687 | * |
| 5688 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 5689 | * that command, form a class_locale that is superset of both |
| 5690 | * old and current and re-issue to the FW |
| 5691 | */ |
| 5692 | |
| 5693 | curr_aen.word = class_locale_word; |
| 5694 | |
| 5695 | if (instance->aen_cmd) { |
| 5696 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 5697 | prev_aen.word = |
| 5698 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5699 | |
Shivasharan S | 91b3d9f | 2017-08-23 04:47:01 -0700 | [diff] [blame] | 5700 | if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) || |
| 5701 | (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) { |
| 5702 | dev_info(&instance->pdev->dev, |
| 5703 | "%s %d out of range class %d send by application\n", |
| 5704 | __func__, __LINE__, curr_aen.members.class); |
| 5705 | return 0; |
| 5706 | } |
| 5707 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5708 | /* |
| 5709 | * A class whose enum value is smaller is inclusive of all |
| 5710 | * higher values. If a PROGRESS (= -1) was previously |
| 5711 | * registered, then a new registration requests for higher |
| 5712 | * classes need not be sent to FW. They are automatically |
| 5713 | * included. |
| 5714 | * |
| 5715 | * Locale numbers don't have such hierarchy. They are bitmap |
| 5716 | * values |
| 5717 | */ |
| 5718 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5719 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5720 | curr_aen.members.locale)) { |
| 5721 | /* |
| 5722 | * Previously issued event registration includes |
| 5723 | * current request. Nothing to do. |
| 5724 | */ |
| 5725 | return 0; |
| 5726 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5727 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5728 | |
| 5729 | if (prev_aen.members.class < curr_aen.members.class) |
| 5730 | curr_aen.members.class = prev_aen.members.class; |
| 5731 | |
| 5732 | instance->aen_cmd->abort_aen = 1; |
| 5733 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 5734 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5735 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5736 | |
| 5737 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5738 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5739 | "previous AEN command\n"); |
| 5740 | return ret_val; |
| 5741 | } |
| 5742 | } |
| 5743 | } |
| 5744 | |
| 5745 | cmd = megasas_get_cmd(instance); |
| 5746 | |
| 5747 | if (!cmd) |
| 5748 | return -ENOMEM; |
| 5749 | |
| 5750 | dcmd = &cmd->frame->dcmd; |
| 5751 | |
| 5752 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 5753 | |
| 5754 | /* |
| 5755 | * Prepare DCMD for aen registration |
| 5756 | */ |
| 5757 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5758 | |
| 5759 | dcmd->cmd = MFI_CMD_DCMD; |
| 5760 | dcmd->cmd_status = 0x0; |
| 5761 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5762 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5763 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5764 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5765 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 5766 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 5767 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5768 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5769 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5770 | |
| 5771 | megasas_set_dma_settings(instance, dcmd, instance->evt_detail_h, |
| 5772 | sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5773 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5774 | if (instance->aen_cmd != NULL) { |
| 5775 | megasas_return_cmd(instance, cmd); |
| 5776 | return 0; |
| 5777 | } |
| 5778 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5779 | /* |
| 5780 | * Store reference to the cmd used to register for AEN. When an |
| 5781 | * application wants us to register for AEN, we have to abort this |
| 5782 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 5783 | */ |
| 5784 | instance->aen_cmd = cmd; |
| 5785 | |
| 5786 | /* |
| 5787 | * Issue the aen registration frame |
| 5788 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5789 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5790 | |
| 5791 | return 0; |
| 5792 | } |
| 5793 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5794 | /* megasas_get_target_prop - Send DCMD with below details to firmware. |
| 5795 | * |
| 5796 | * This DCMD will fetch few properties of LD/system PD defined |
| 5797 | * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value. |
| 5798 | * |
| 5799 | * DCMD send by drivers whenever new target is added to the OS. |
| 5800 | * |
| 5801 | * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP |
| 5802 | * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD. |
| 5803 | * 0 = system PD, 1 = LD. |
| 5804 | * dcmd.mbox.s[1] - TargetID for LD/system PD. |
| 5805 | * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES. |
| 5806 | * |
| 5807 | * @instance: Adapter soft state |
| 5808 | * @sdev: OS provided scsi device |
| 5809 | * |
| 5810 | * Returns 0 on success non-zero on failure. |
| 5811 | */ |
| 5812 | static int |
| 5813 | megasas_get_target_prop(struct megasas_instance *instance, |
| 5814 | struct scsi_device *sdev) |
| 5815 | { |
| 5816 | int ret; |
| 5817 | struct megasas_cmd *cmd; |
| 5818 | struct megasas_dcmd_frame *dcmd; |
| 5819 | u16 targetId = (sdev->channel % 2) + sdev->id; |
| 5820 | |
| 5821 | cmd = megasas_get_cmd(instance); |
| 5822 | |
| 5823 | if (!cmd) { |
| 5824 | dev_err(&instance->pdev->dev, |
| 5825 | "Failed to get cmd %s\n", __func__); |
| 5826 | return -ENOMEM; |
| 5827 | } |
| 5828 | |
| 5829 | dcmd = &cmd->frame->dcmd; |
| 5830 | |
| 5831 | memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop)); |
| 5832 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5833 | dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev); |
| 5834 | |
| 5835 | dcmd->mbox.s[1] = cpu_to_le16(targetId); |
| 5836 | dcmd->cmd = MFI_CMD_DCMD; |
| 5837 | dcmd->cmd_status = 0xFF; |
| 5838 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5839 | dcmd->flags = MFI_FRAME_DIR_READ; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5840 | dcmd->timeout = 0; |
| 5841 | dcmd->pad_0 = 0; |
| 5842 | dcmd->data_xfer_len = |
| 5843 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 5844 | dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5845 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5846 | megasas_set_dma_settings(instance, dcmd, instance->tgt_prop_h, |
| 5847 | sizeof(struct MR_TARGET_PROPERTIES)); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5848 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5849 | if ((instance->adapter_type != MFI_SERIES) && |
| 5850 | !instance->mask_interrupts) |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5851 | ret = megasas_issue_blocked_cmd(instance, |
| 5852 | cmd, MFI_IO_TIMEOUT_SECS); |
| 5853 | else |
| 5854 | ret = megasas_issue_polled(instance, cmd); |
| 5855 | |
| 5856 | switch (ret) { |
| 5857 | case DCMD_TIMEOUT: |
| 5858 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5859 | case INITIATE_OCR: |
| 5860 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5861 | megasas_reset_fusion(instance->host, |
| 5862 | MFI_IO_TIMEOUT_OCR); |
| 5863 | break; |
| 5864 | case KILL_ADAPTER: |
| 5865 | megaraid_sas_kill_hba(instance); |
| 5866 | break; |
| 5867 | case IGNORE_TIMEOUT: |
| 5868 | dev_info(&instance->pdev->dev, |
| 5869 | "Ignore DCMD timeout: %s %d\n", |
| 5870 | __func__, __LINE__); |
| 5871 | break; |
| 5872 | } |
| 5873 | break; |
| 5874 | |
| 5875 | default: |
| 5876 | megasas_return_cmd(instance, cmd); |
| 5877 | } |
| 5878 | if (ret != DCMD_SUCCESS) |
| 5879 | dev_err(&instance->pdev->dev, |
| 5880 | "return from %s %d return value %d\n", |
| 5881 | __func__, __LINE__, ret); |
| 5882 | |
| 5883 | return ret; |
| 5884 | } |
| 5885 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5886 | /** |
| 5887 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 5888 | * @instance: Adapter soft state |
| 5889 | */ |
| 5890 | static int megasas_start_aen(struct megasas_instance *instance) |
| 5891 | { |
| 5892 | struct megasas_evt_log_info eli; |
| 5893 | union megasas_evt_class_locale class_locale; |
| 5894 | |
| 5895 | /* |
| 5896 | * Get the latest sequence number from FW |
| 5897 | */ |
| 5898 | memset(&eli, 0, sizeof(eli)); |
| 5899 | |
| 5900 | if (megasas_get_seq_num(instance, &eli)) |
| 5901 | return -1; |
| 5902 | |
| 5903 | /* |
| 5904 | * Register AEN with FW for latest sequence number plus 1 |
| 5905 | */ |
| 5906 | class_locale.members.reserved = 0; |
| 5907 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 5908 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 5909 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5910 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5911 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5912 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | /** |
| 5916 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 5917 | * @instance: Adapter soft state |
| 5918 | */ |
| 5919 | static int megasas_io_attach(struct megasas_instance *instance) |
| 5920 | { |
| 5921 | struct Scsi_Host *host = instance->host; |
| 5922 | |
| 5923 | /* |
| 5924 | * Export parameters required by SCSI mid-layer |
| 5925 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5926 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5927 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5928 | host->this_id = instance->init_id; |
| 5929 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 5930 | |
| 5931 | if (instance->fw_support_ieee) |
| 5932 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 5933 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5934 | /* |
| 5935 | * Check if the module parameter value for max_sectors can be used |
| 5936 | */ |
| 5937 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 5938 | instance->max_sectors_per_req = max_sectors; |
| 5939 | else { |
| 5940 | if (max_sectors) { |
| 5941 | if (((instance->pdev->device == |
| 5942 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 5943 | (instance->pdev->device == |
| 5944 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 5945 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 5946 | instance->max_sectors_per_req = max_sectors; |
| 5947 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5948 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5949 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 5950 | instance->max_sectors_per_req); |
| 5951 | } |
| 5952 | } |
| 5953 | } |
| 5954 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5955 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5956 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5957 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 5958 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5959 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 5960 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5961 | |
| 5962 | /* |
| 5963 | * Notify the mid-layer about the new controller |
| 5964 | */ |
| 5965 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5966 | dev_err(&instance->pdev->dev, |
| 5967 | "Failed to add host from %s %d\n", |
| 5968 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5969 | return -ENODEV; |
| 5970 | } |
| 5971 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5972 | return 0; |
| 5973 | } |
| 5974 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5975 | /** |
| 5976 | * megasas_set_dma_mask - Set DMA mask for supported controllers |
| 5977 | * |
| 5978 | * @instance: Adapter soft state |
| 5979 | * Description: |
| 5980 | * |
| 5981 | * For Ventura, driver/FW will operate in 64bit DMA addresses. |
| 5982 | * |
| 5983 | * For invader- |
| 5984 | * By default, driver/FW will operate in 32bit DMA addresses |
| 5985 | * for consistent DMA mapping but if 32 bit consistent |
| 5986 | * DMA mask fails, driver will try with 64 bit consistent |
| 5987 | * mask provided FW is true 64bit DMA capable |
| 5988 | * |
| 5989 | * For older controllers(Thunderbolt and MFI based adapters)- |
| 5990 | * driver/FW will operate in 32 bit consistent DMA addresses. |
| 5991 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5992 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5993 | megasas_set_dma_mask(struct megasas_instance *instance) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5994 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5995 | u64 consistent_mask; |
| 5996 | struct pci_dev *pdev; |
| 5997 | u32 scratch_pad_2; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5998 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5999 | pdev = instance->pdev; |
| 6000 | consistent_mask = (instance->adapter_type == VENTURA_SERIES) ? |
| 6001 | DMA_BIT_MASK(64) : DMA_BIT_MASK(32); |
| 6002 | |
| 6003 | if (IS_DMA64) { |
| 6004 | if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 6005 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6006 | goto fail_set_dma_mask; |
| 6007 | |
| 6008 | if ((*pdev->dev.dma_mask == DMA_BIT_MASK(64)) && |
| 6009 | (dma_set_coherent_mask(&pdev->dev, consistent_mask) && |
| 6010 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))) { |
| 6011 | /* |
| 6012 | * If 32 bit DMA mask fails, then try for 64 bit mask |
| 6013 | * for FW capable of handling 64 bit DMA. |
| 6014 | */ |
| 6015 | scratch_pad_2 = readl |
| 6016 | (&instance->reg_set->outbound_scratch_pad_2); |
| 6017 | |
| 6018 | if (!(scratch_pad_2 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET)) |
| 6019 | goto fail_set_dma_mask; |
| 6020 | else if (dma_set_mask_and_coherent(&pdev->dev, |
| 6021 | DMA_BIT_MASK(64))) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6022 | goto fail_set_dma_mask; |
| 6023 | } |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6024 | } else if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6025 | goto fail_set_dma_mask; |
| 6026 | |
| 6027 | if (pdev->dev.coherent_dma_mask == DMA_BIT_MASK(32)) |
| 6028 | instance->consistent_mask_64bit = false; |
| 6029 | else |
| 6030 | instance->consistent_mask_64bit = true; |
| 6031 | |
| 6032 | dev_info(&pdev->dev, "%s bit DMA mask and %s bit consistent mask\n", |
| 6033 | ((*pdev->dev.dma_mask == DMA_BIT_MASK(64)) ? "64" : "32"), |
| 6034 | (instance->consistent_mask_64bit ? "64" : "32")); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6035 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6036 | return 0; |
| 6037 | |
| 6038 | fail_set_dma_mask: |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6039 | dev_err(&pdev->dev, "Failed to set DMA mask\n"); |
| 6040 | return -1; |
| 6041 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6042 | } |
| 6043 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6044 | /* |
| 6045 | * megasas_set_adapter_type - Set adapter type. |
| 6046 | * Supported controllers can be divided in |
| 6047 | * 4 categories- enum MR_ADAPTER_TYPE { |
| 6048 | * MFI_SERIES = 1, |
| 6049 | * THUNDERBOLT_SERIES = 2, |
| 6050 | * INVADER_SERIES = 3, |
| 6051 | * VENTURA_SERIES = 4, |
| 6052 | * }; |
| 6053 | * @instance: Adapter soft state |
| 6054 | * return: void |
| 6055 | */ |
| 6056 | static inline void megasas_set_adapter_type(struct megasas_instance *instance) |
| 6057 | { |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6058 | if ((instance->pdev->vendor == PCI_VENDOR_ID_DELL) && |
| 6059 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5)) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6060 | instance->adapter_type = MFI_SERIES; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6061 | } else { |
| 6062 | switch (instance->pdev->device) { |
| 6063 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 6064 | case PCI_DEVICE_ID_LSI_CRUSADER: |
| 6065 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 6066 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 6067 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 6068 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 6069 | instance->adapter_type = VENTURA_SERIES; |
| 6070 | break; |
| 6071 | case PCI_DEVICE_ID_LSI_FUSION: |
| 6072 | case PCI_DEVICE_ID_LSI_PLASMA: |
| 6073 | instance->adapter_type = THUNDERBOLT_SERIES; |
| 6074 | break; |
| 6075 | case PCI_DEVICE_ID_LSI_INVADER: |
| 6076 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 6077 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
| 6078 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 6079 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
| 6080 | case PCI_DEVICE_ID_LSI_FURY: |
| 6081 | instance->adapter_type = INVADER_SERIES; |
| 6082 | break; |
| 6083 | default: /* For all other supported controllers */ |
| 6084 | instance->adapter_type = MFI_SERIES; |
| 6085 | break; |
| 6086 | } |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6087 | } |
| 6088 | } |
| 6089 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6090 | static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance) |
| 6091 | { |
| 6092 | instance->producer = pci_alloc_consistent(instance->pdev, sizeof(u32), |
| 6093 | &instance->producer_h); |
| 6094 | instance->consumer = pci_alloc_consistent(instance->pdev, sizeof(u32), |
| 6095 | &instance->consumer_h); |
| 6096 | |
| 6097 | if (!instance->producer || !instance->consumer) { |
| 6098 | dev_err(&instance->pdev->dev, |
| 6099 | "Failed to allocate memory for producer, consumer\n"); |
| 6100 | return -1; |
| 6101 | } |
| 6102 | |
| 6103 | *instance->producer = 0; |
| 6104 | *instance->consumer = 0; |
| 6105 | return 0; |
| 6106 | } |
| 6107 | |
| 6108 | /** |
| 6109 | * megasas_alloc_ctrl_mem - Allocate per controller memory for core data |
| 6110 | * structures which are not common across MFI |
| 6111 | * adapters and fusion adapters. |
| 6112 | * For MFI based adapters, allocate producer and |
| 6113 | * consumer buffers. For fusion adapters, allocate |
| 6114 | * memory for fusion context. |
| 6115 | * @instance: Adapter soft state |
| 6116 | * return: 0 for SUCCESS |
| 6117 | */ |
| 6118 | static int megasas_alloc_ctrl_mem(struct megasas_instance *instance) |
| 6119 | { |
| 6120 | switch (instance->adapter_type) { |
| 6121 | case MFI_SERIES: |
| 6122 | if (megasas_alloc_mfi_ctrl_mem(instance)) |
| 6123 | return -ENOMEM; |
| 6124 | break; |
| 6125 | case VENTURA_SERIES: |
| 6126 | case THUNDERBOLT_SERIES: |
| 6127 | case INVADER_SERIES: |
| 6128 | if (megasas_alloc_fusion_context(instance)) |
| 6129 | return -ENOMEM; |
| 6130 | break; |
| 6131 | } |
| 6132 | |
| 6133 | return 0; |
| 6134 | } |
| 6135 | |
| 6136 | /* |
| 6137 | * megasas_free_ctrl_mem - Free fusion context for fusion adapters and |
| 6138 | * producer, consumer buffers for MFI adapters |
| 6139 | * |
| 6140 | * @instance - Adapter soft instance |
| 6141 | * |
| 6142 | */ |
| 6143 | static inline void megasas_free_ctrl_mem(struct megasas_instance *instance) |
| 6144 | { |
| 6145 | if (instance->adapter_type == MFI_SERIES) { |
| 6146 | if (instance->producer) |
| 6147 | pci_free_consistent(instance->pdev, sizeof(u32), |
| 6148 | instance->producer, |
| 6149 | instance->producer_h); |
| 6150 | if (instance->consumer) |
| 6151 | pci_free_consistent(instance->pdev, sizeof(u32), |
| 6152 | instance->consumer, |
| 6153 | instance->consumer_h); |
| 6154 | } else { |
| 6155 | megasas_free_fusion_context(instance); |
| 6156 | } |
| 6157 | } |
| 6158 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6159 | /** |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6160 | * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during |
| 6161 | * driver load time |
| 6162 | * |
| 6163 | * @instance- Adapter soft instance |
| 6164 | * @return- O for SUCCESS |
| 6165 | */ |
| 6166 | static inline |
| 6167 | int megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6168 | { |
| 6169 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6170 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6171 | |
| 6172 | instance->evt_detail = |
| 6173 | pci_alloc_consistent(pdev, |
| 6174 | sizeof(struct megasas_evt_detail), |
| 6175 | &instance->evt_detail_h); |
| 6176 | |
| 6177 | if (!instance->evt_detail) { |
| 6178 | dev_err(&instance->pdev->dev, |
| 6179 | "Failed to allocate event detail buffer\n"); |
| 6180 | return -ENOMEM; |
| 6181 | } |
| 6182 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6183 | if (fusion) { |
| 6184 | fusion->ioc_init_request = |
| 6185 | dma_alloc_coherent(&pdev->dev, |
| 6186 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6187 | &fusion->ioc_init_request_phys, |
| 6188 | GFP_KERNEL); |
| 6189 | |
| 6190 | if (!fusion->ioc_init_request) { |
| 6191 | dev_err(&pdev->dev, |
| 6192 | "Failed to allocate PD list buffer\n"); |
| 6193 | return -ENOMEM; |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | instance->pd_list_buf = |
| 6198 | pci_alloc_consistent(pdev, |
| 6199 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 6200 | &instance->pd_list_buf_h); |
| 6201 | |
| 6202 | if (!instance->pd_list_buf) { |
| 6203 | dev_err(&pdev->dev, "Failed to allocate PD list buffer\n"); |
| 6204 | return -ENOMEM; |
| 6205 | } |
| 6206 | |
| 6207 | instance->ctrl_info_buf = |
| 6208 | pci_alloc_consistent(pdev, |
| 6209 | sizeof(struct megasas_ctrl_info), |
| 6210 | &instance->ctrl_info_buf_h); |
| 6211 | |
| 6212 | if (!instance->ctrl_info_buf) { |
| 6213 | dev_err(&pdev->dev, |
| 6214 | "Failed to allocate controller info buffer\n"); |
| 6215 | return -ENOMEM; |
| 6216 | } |
| 6217 | |
| 6218 | instance->ld_list_buf = |
| 6219 | pci_alloc_consistent(pdev, |
| 6220 | sizeof(struct MR_LD_LIST), |
| 6221 | &instance->ld_list_buf_h); |
| 6222 | |
| 6223 | if (!instance->ld_list_buf) { |
| 6224 | dev_err(&pdev->dev, "Failed to allocate LD list buffer\n"); |
| 6225 | return -ENOMEM; |
| 6226 | } |
| 6227 | |
| 6228 | instance->ld_targetid_list_buf = |
| 6229 | pci_alloc_consistent(pdev, |
| 6230 | sizeof(struct MR_LD_TARGETID_LIST), |
| 6231 | &instance->ld_targetid_list_buf_h); |
| 6232 | |
| 6233 | if (!instance->ld_targetid_list_buf) { |
| 6234 | dev_err(&pdev->dev, |
| 6235 | "Failed to allocate LD targetid list buffer\n"); |
| 6236 | return -ENOMEM; |
| 6237 | } |
| 6238 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6239 | if (!reset_devices) { |
| 6240 | instance->system_info_buf = |
| 6241 | pci_alloc_consistent(pdev, |
| 6242 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6243 | &instance->system_info_h); |
| 6244 | instance->pd_info = |
| 6245 | pci_alloc_consistent(pdev, |
| 6246 | sizeof(struct MR_PD_INFO), |
| 6247 | &instance->pd_info_h); |
| 6248 | instance->tgt_prop = |
| 6249 | pci_alloc_consistent(pdev, |
| 6250 | sizeof(struct MR_TARGET_PROPERTIES), |
| 6251 | &instance->tgt_prop_h); |
| 6252 | instance->crash_dump_buf = |
| 6253 | pci_alloc_consistent(pdev, |
| 6254 | CRASH_DMA_BUF_SIZE, |
| 6255 | &instance->crash_dump_h); |
| 6256 | |
| 6257 | if (!instance->system_info_buf) |
| 6258 | dev_err(&instance->pdev->dev, |
| 6259 | "Failed to allocate system info buffer\n"); |
| 6260 | |
| 6261 | if (!instance->pd_info) |
| 6262 | dev_err(&instance->pdev->dev, |
| 6263 | "Failed to allocate pd_info buffer\n"); |
| 6264 | |
| 6265 | if (!instance->tgt_prop) |
| 6266 | dev_err(&instance->pdev->dev, |
| 6267 | "Failed to allocate tgt_prop buffer\n"); |
| 6268 | |
| 6269 | if (!instance->crash_dump_buf) |
| 6270 | dev_err(&instance->pdev->dev, |
| 6271 | "Failed to allocate crash dump buffer\n"); |
| 6272 | } |
| 6273 | |
| 6274 | return 0; |
| 6275 | } |
| 6276 | |
| 6277 | /* |
| 6278 | * megasas_free_ctrl_dma_buffers - Free consistent DMA buffers allocated |
| 6279 | * during driver load time |
| 6280 | * |
| 6281 | * @instance- Adapter soft instance |
| 6282 | * |
| 6283 | */ |
| 6284 | static inline |
| 6285 | void megasas_free_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6286 | { |
| 6287 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6288 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6289 | |
| 6290 | if (instance->evt_detail) |
| 6291 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6292 | instance->evt_detail, |
| 6293 | instance->evt_detail_h); |
| 6294 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6295 | if (fusion && fusion->ioc_init_request) |
| 6296 | dma_free_coherent(&pdev->dev, |
| 6297 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6298 | fusion->ioc_init_request, |
| 6299 | fusion->ioc_init_request_phys); |
| 6300 | |
| 6301 | if (instance->pd_list_buf) |
| 6302 | pci_free_consistent(pdev, |
| 6303 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 6304 | instance->pd_list_buf, |
| 6305 | instance->pd_list_buf_h); |
| 6306 | |
| 6307 | if (instance->ld_list_buf) |
| 6308 | pci_free_consistent(pdev, sizeof(struct MR_LD_LIST), |
| 6309 | instance->ld_list_buf, |
| 6310 | instance->ld_list_buf_h); |
| 6311 | |
| 6312 | if (instance->ld_targetid_list_buf) |
| 6313 | pci_free_consistent(pdev, sizeof(struct MR_LD_TARGETID_LIST), |
| 6314 | instance->ld_targetid_list_buf, |
| 6315 | instance->ld_targetid_list_buf_h); |
| 6316 | |
| 6317 | if (instance->ctrl_info_buf) |
| 6318 | pci_free_consistent(pdev, sizeof(struct megasas_ctrl_info), |
| 6319 | instance->ctrl_info_buf, |
| 6320 | instance->ctrl_info_buf_h); |
| 6321 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6322 | if (instance->system_info_buf) |
| 6323 | pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6324 | instance->system_info_buf, |
| 6325 | instance->system_info_h); |
| 6326 | |
| 6327 | if (instance->pd_info) |
| 6328 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6329 | instance->pd_info, instance->pd_info_h); |
| 6330 | |
| 6331 | if (instance->tgt_prop) |
| 6332 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6333 | instance->tgt_prop, instance->tgt_prop_h); |
| 6334 | |
| 6335 | if (instance->crash_dump_buf) |
| 6336 | pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE, |
| 6337 | instance->crash_dump_buf, |
| 6338 | instance->crash_dump_h); |
| 6339 | } |
| 6340 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6341 | /* |
| 6342 | * megasas_init_ctrl_params - Initialize controller's instance |
| 6343 | * parameters before FW init |
| 6344 | * @instance - Adapter soft instance |
| 6345 | * @return - void |
| 6346 | */ |
| 6347 | static inline void megasas_init_ctrl_params(struct megasas_instance *instance) |
| 6348 | { |
| 6349 | instance->fw_crash_state = UNAVAILABLE; |
| 6350 | |
| 6351 | megasas_poll_wait_aen = 0; |
| 6352 | instance->issuepend_done = 1; |
| 6353 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
| 6354 | |
| 6355 | /* |
| 6356 | * Initialize locks and queues |
| 6357 | */ |
| 6358 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 6359 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
| 6360 | |
| 6361 | atomic_set(&instance->fw_outstanding, 0); |
| 6362 | |
| 6363 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 6364 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 6365 | |
| 6366 | spin_lock_init(&instance->crashdump_lock); |
| 6367 | spin_lock_init(&instance->mfi_pool_lock); |
| 6368 | spin_lock_init(&instance->hba_lock); |
| 6369 | spin_lock_init(&instance->stream_lock); |
| 6370 | spin_lock_init(&instance->completion_lock); |
| 6371 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6372 | mutex_init(&instance->reset_mutex); |
| 6373 | |
| 6374 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 6375 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
| 6376 | instance->flag_ieee = 1; |
| 6377 | |
| 6378 | megasas_dbg_lvl = 0; |
| 6379 | instance->flag = 0; |
| 6380 | instance->unload = 1; |
| 6381 | instance->last_time = 0; |
| 6382 | instance->disableOnlineCtrlReset = 1; |
| 6383 | instance->UnevenSpanSupport = 0; |
| 6384 | |
| 6385 | if (instance->adapter_type != MFI_SERIES) { |
| 6386 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
| 6387 | INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq); |
| 6388 | } else { |
| 6389 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
| 6390 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | /** |
| 6394 | * megasas_probe_one - PCI hotplug entry point |
| 6395 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 6396 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6397 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6398 | static int megasas_probe_one(struct pci_dev *pdev, |
| 6399 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6400 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6401 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6402 | struct Scsi_Host *host; |
| 6403 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6404 | u16 control = 0; |
| 6405 | |
| 6406 | /* Reset MSI-X in the kdump kernel */ |
| 6407 | if (reset_devices) { |
| 6408 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 6409 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6410 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6411 | &control); |
| 6412 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 6413 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 6414 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6415 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6416 | control & |
| 6417 | ~PCI_MSIX_FLAGS_ENABLE); |
| 6418 | } |
| 6419 | } |
| 6420 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6421 | |
| 6422 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6423 | * PCI prepping: enable device set bus mastering and dma mask |
| 6424 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6425 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6426 | |
| 6427 | if (rval) { |
| 6428 | return rval; |
| 6429 | } |
| 6430 | |
| 6431 | pci_set_master(pdev); |
| 6432 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6433 | host = scsi_host_alloc(&megasas_template, |
| 6434 | sizeof(struct megasas_instance)); |
| 6435 | |
| 6436 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6437 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6438 | goto fail_alloc_instance; |
| 6439 | } |
| 6440 | |
| 6441 | instance = (struct megasas_instance *)host->hostdata; |
| 6442 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6443 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6444 | |
| 6445 | /* |
| 6446 | * Initialize PCI related and misc parameters |
| 6447 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6448 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6449 | instance->host = host; |
| 6450 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 6451 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
| 6452 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6453 | megasas_set_adapter_type(instance); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6454 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6455 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 6456 | * Initialize MFI Firmware |
| 6457 | */ |
| 6458 | if (megasas_init_fw(instance)) |
| 6459 | goto fail_init_mfi; |
| 6460 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6461 | if (instance->requestorId) { |
| 6462 | if (instance->PlasmaFW111) { |
| 6463 | instance->vf_affiliation_111 = |
| 6464 | pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6465 | &instance->vf_affiliation_111_h); |
| 6466 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6467 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6468 | "memory for VF affiliation buffer\n"); |
| 6469 | } else { |
| 6470 | instance->vf_affiliation = |
| 6471 | pci_alloc_consistent(pdev, |
| 6472 | (MAX_LOGICAL_DRIVES + 1) * |
| 6473 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6474 | &instance->vf_affiliation_h); |
| 6475 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6476 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6477 | "memory for VF affiliation buffer\n"); |
| 6478 | } |
| 6479 | } |
| 6480 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6481 | /* |
| 6482 | * Store instance in PCI softstate |
| 6483 | */ |
| 6484 | pci_set_drvdata(pdev, instance); |
| 6485 | |
| 6486 | /* |
| 6487 | * Add this controller to megasas_mgmt_info structure so that it |
| 6488 | * can be exported to management applications |
| 6489 | */ |
| 6490 | megasas_mgmt_info.count++; |
| 6491 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 6492 | megasas_mgmt_info.max_index++; |
| 6493 | |
| 6494 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6495 | * Register with SCSI mid-layer |
| 6496 | */ |
| 6497 | if (megasas_io_attach(instance)) |
| 6498 | goto fail_io_attach; |
| 6499 | |
| 6500 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6501 | /* |
| 6502 | * Trigger SCSI to scan our drives |
| 6503 | */ |
| 6504 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6505 | |
| 6506 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6507 | * Initiate AEN (Asynchronous Event Notification) |
| 6508 | */ |
| 6509 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6510 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6511 | goto fail_start_aen; |
| 6512 | } |
| 6513 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 6514 | /* Get current SR-IOV LD/VF affiliation */ |
| 6515 | if (instance->requestorId) |
| 6516 | megasas_get_ld_vf_affiliation(instance, 1); |
| 6517 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6518 | return 0; |
| 6519 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6520 | fail_start_aen: |
| 6521 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6522 | megasas_mgmt_info.count--; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6523 | megasas_mgmt_info.max_index--; |
weiping zhang | 61f0c3c | 2017-08-08 01:26:57 +0800 | [diff] [blame] | 6524 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6525 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6526 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6527 | megasas_destroy_irqs(instance); |
| 6528 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6529 | if (instance->adapter_type != MFI_SERIES) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6530 | megasas_release_fusion(instance); |
| 6531 | else |
| 6532 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6533 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6534 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6535 | fail_init_mfi: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6536 | scsi_host_put(host); |
| 6537 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6538 | fail_alloc_instance: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6539 | pci_disable_device(pdev); |
| 6540 | |
| 6541 | return -ENODEV; |
| 6542 | } |
| 6543 | |
| 6544 | /** |
| 6545 | * megasas_flush_cache - Requests FW to flush all its caches |
| 6546 | * @instance: Adapter soft state |
| 6547 | */ |
| 6548 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 6549 | { |
| 6550 | struct megasas_cmd *cmd; |
| 6551 | struct megasas_dcmd_frame *dcmd; |
| 6552 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6553 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6554 | return; |
| 6555 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6556 | cmd = megasas_get_cmd(instance); |
| 6557 | |
| 6558 | if (!cmd) |
| 6559 | return; |
| 6560 | |
| 6561 | dcmd = &cmd->frame->dcmd; |
| 6562 | |
| 6563 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6564 | |
| 6565 | dcmd->cmd = MFI_CMD_DCMD; |
| 6566 | dcmd->cmd_status = 0x0; |
| 6567 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6568 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6569 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6570 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6571 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6572 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6573 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 6574 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6575 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6576 | != DCMD_SUCCESS) { |
| 6577 | dev_err(&instance->pdev->dev, |
| 6578 | "return from %s %d\n", __func__, __LINE__); |
| 6579 | return; |
| 6580 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6581 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6582 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6583 | } |
| 6584 | |
| 6585 | /** |
| 6586 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 6587 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6588 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6589 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6590 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 6591 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6592 | { |
| 6593 | struct megasas_cmd *cmd; |
| 6594 | struct megasas_dcmd_frame *dcmd; |
| 6595 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6596 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6597 | return; |
| 6598 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6599 | cmd = megasas_get_cmd(instance); |
| 6600 | |
| 6601 | if (!cmd) |
| 6602 | return; |
| 6603 | |
| 6604 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6605 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6606 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6607 | if (instance->map_update_cmd) |
| 6608 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6609 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6610 | if (instance->jbod_seq_cmd) |
| 6611 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6612 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6613 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6614 | dcmd = &cmd->frame->dcmd; |
| 6615 | |
| 6616 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6617 | |
| 6618 | dcmd->cmd = MFI_CMD_DCMD; |
| 6619 | dcmd->cmd_status = 0x0; |
| 6620 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6621 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6622 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6623 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6624 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6625 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6626 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6627 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6628 | != DCMD_SUCCESS) { |
| 6629 | dev_err(&instance->pdev->dev, |
| 6630 | "return from %s %d\n", __func__, __LINE__); |
| 6631 | return; |
| 6632 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6633 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6634 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6635 | } |
| 6636 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6637 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6638 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6639 | * megasas_suspend - driver suspend entry point |
| 6640 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6641 | * @state: PCI power state to suspend routine |
| 6642 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6643 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6644 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6645 | { |
| 6646 | struct Scsi_Host *host; |
| 6647 | struct megasas_instance *instance; |
| 6648 | |
| 6649 | instance = pci_get_drvdata(pdev); |
| 6650 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6651 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6652 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6653 | /* Shutdown SR-IOV heartbeat timer */ |
| 6654 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6655 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6656 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6657 | megasas_flush_cache(instance); |
| 6658 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6659 | |
| 6660 | /* cancel the delayed work if this work still in queue */ |
| 6661 | if (instance->ev != NULL) { |
| 6662 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6663 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6664 | instance->ev = NULL; |
| 6665 | } |
| 6666 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6667 | tasklet_kill(&instance->isr_tasklet); |
| 6668 | |
| 6669 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6670 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6671 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6672 | megasas_destroy_irqs(instance); |
| 6673 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6674 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6675 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6676 | |
| 6677 | pci_save_state(pdev); |
| 6678 | pci_disable_device(pdev); |
| 6679 | |
| 6680 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 6681 | |
| 6682 | return 0; |
| 6683 | } |
| 6684 | |
| 6685 | /** |
| 6686 | * megasas_resume- driver resume entry point |
| 6687 | * @pdev: PCI device structure |
| 6688 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6689 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6690 | megasas_resume(struct pci_dev *pdev) |
| 6691 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6692 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6693 | struct Scsi_Host *host; |
| 6694 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6695 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6696 | |
| 6697 | instance = pci_get_drvdata(pdev); |
| 6698 | host = instance->host; |
| 6699 | pci_set_power_state(pdev, PCI_D0); |
| 6700 | pci_enable_wake(pdev, PCI_D0, 0); |
| 6701 | pci_restore_state(pdev); |
| 6702 | |
| 6703 | /* |
| 6704 | * PCI prepping: enable device set bus mastering and dma mask |
| 6705 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6706 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6707 | |
| 6708 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6709 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6710 | return rval; |
| 6711 | } |
| 6712 | |
| 6713 | pci_set_master(pdev); |
| 6714 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6715 | /* |
| 6716 | * We expect the FW state to be READY |
| 6717 | */ |
| 6718 | if (megasas_transition_to_ready(instance, 0)) |
| 6719 | goto fail_ready_state; |
| 6720 | |
| 6721 | if (megasas_set_dma_mask(instance)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6722 | goto fail_set_dma_mask; |
| 6723 | |
| 6724 | /* |
| 6725 | * Initialize MFI Firmware |
| 6726 | */ |
| 6727 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6728 | atomic_set(&instance->fw_outstanding, 0); |
Shivasharan S | 41fae9a | 2018-01-05 05:27:39 -0800 | [diff] [blame] | 6729 | atomic_set(&instance->ldio_outstanding, 0); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6730 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6731 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6732 | if (instance->msix_vectors) { |
| 6733 | irq_flags = PCI_IRQ_MSIX; |
| 6734 | if (smp_affinity_enable) |
| 6735 | irq_flags |= PCI_IRQ_AFFINITY; |
| 6736 | } |
| 6737 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 6738 | instance->msix_vectors ? |
| 6739 | instance->msix_vectors : 1, irq_flags); |
| 6740 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6741 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6742 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6743 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6744 | megasas_reset_reply_desc(instance); |
| 6745 | if (megasas_ioc_init_fusion(instance)) { |
| 6746 | megasas_free_cmds(instance); |
| 6747 | megasas_free_cmds_fusion(instance); |
| 6748 | goto fail_init_mfi; |
| 6749 | } |
| 6750 | if (!megasas_get_map_info(instance)) |
| 6751 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6752 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6753 | *instance->producer = 0; |
| 6754 | *instance->consumer = 0; |
| 6755 | if (megasas_issue_init_mfi(instance)) |
| 6756 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6757 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6758 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6759 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 6760 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6761 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6762 | if (instance->msix_vectors ? |
| 6763 | megasas_setup_irqs_msix(instance, 0) : |
| 6764 | megasas_setup_irqs_ioapic(instance)) |
| 6765 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6766 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6767 | /* Re-launch SR-IOV heartbeat timer */ |
| 6768 | if (instance->requestorId) { |
| 6769 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 6770 | megasas_start_timer(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6771 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6772 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6773 | goto fail_init_mfi; |
| 6774 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6775 | } |
| 6776 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6777 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6778 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6779 | instance->unload = 0; |
| 6780 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6781 | /* |
| 6782 | * Initiate AEN (Asynchronous Event Notification) |
| 6783 | */ |
| 6784 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6785 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6786 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6787 | return 0; |
| 6788 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6789 | fail_init_mfi: |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6790 | megasas_free_ctrl_dma_buffers(instance); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6791 | megasas_free_ctrl_mem(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6792 | scsi_host_put(host); |
| 6793 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6794 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6795 | fail_set_dma_mask: |
| 6796 | fail_ready_state: |
| 6797 | |
| 6798 | pci_disable_device(pdev); |
| 6799 | |
| 6800 | return -ENODEV; |
| 6801 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6802 | #else |
| 6803 | #define megasas_suspend NULL |
| 6804 | #define megasas_resume NULL |
| 6805 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6806 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6807 | static inline int |
| 6808 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 6809 | { |
| 6810 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 6811 | int i; |
| 6812 | |
| 6813 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
| 6814 | return 1; |
| 6815 | |
| 6816 | for (i = 0; i < wait_time; i++) { |
| 6817 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
| 6818 | break; |
| 6819 | |
| 6820 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 6821 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 6822 | |
| 6823 | msleep(1000); |
| 6824 | } |
| 6825 | |
| 6826 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
| 6827 | dev_info(&instance->pdev->dev, "%s timed out while waiting for HBA to recover.\n", |
| 6828 | __func__); |
| 6829 | return 1; |
| 6830 | } |
| 6831 | |
| 6832 | return 0; |
| 6833 | } |
| 6834 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6835 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6836 | * megasas_detach_one - PCI hot"un"plug entry point |
| 6837 | * @pdev: PCI device structure |
| 6838 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6839 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6840 | { |
| 6841 | int i; |
| 6842 | struct Scsi_Host *host; |
| 6843 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6844 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6845 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6846 | |
| 6847 | instance = pci_get_drvdata(pdev); |
| 6848 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6849 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6850 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6851 | /* Shutdown SR-IOV heartbeat timer */ |
| 6852 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6853 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6854 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6855 | if (instance->fw_crash_state != UNAVAILABLE) |
| 6856 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6857 | scsi_remove_host(instance->host); |
Shivasharan S | f3f7920 | 2018-01-05 05:27:41 -0800 | [diff] [blame] | 6858 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6859 | |
| 6860 | if (megasas_wait_for_adapter_operational(instance)) |
| 6861 | goto skip_firing_dcmds; |
| 6862 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6863 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6864 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6865 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6866 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6867 | /* cancel the delayed work if this work still in queue*/ |
| 6868 | if (instance->ev != NULL) { |
| 6869 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6870 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6871 | instance->ev = NULL; |
| 6872 | } |
| 6873 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6874 | /* cancel all wait events */ |
| 6875 | wake_up_all(&instance->int_cmd_wait_q); |
| 6876 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 6877 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6878 | |
| 6879 | /* |
| 6880 | * Take the instance off the instance array. Note that we will not |
| 6881 | * decrement the max_index. We let this array be sparse array |
| 6882 | */ |
| 6883 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6884 | if (megasas_mgmt_info.instance[i] == instance) { |
| 6885 | megasas_mgmt_info.count--; |
| 6886 | megasas_mgmt_info.instance[i] = NULL; |
| 6887 | |
| 6888 | break; |
| 6889 | } |
| 6890 | } |
| 6891 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6892 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6893 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6894 | megasas_destroy_irqs(instance); |
| 6895 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6896 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6897 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6898 | |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame] | 6899 | if (instance->adapter_type == VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6900 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 6901 | kfree(fusion->stream_detect_by_ld[i]); |
| 6902 | kfree(fusion->stream_detect_by_ld); |
| 6903 | fusion->stream_detect_by_ld = NULL; |
| 6904 | } |
| 6905 | |
| 6906 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6907 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6908 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6909 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 6910 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 6911 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6912 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6913 | if (fusion->ld_map[i]) |
| 6914 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6915 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6916 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6917 | fusion->ld_map_phys[i]); |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 6918 | if (fusion->ld_drv_map[i]) { |
| 6919 | if (is_vmalloc_addr(fusion->ld_drv_map[i])) |
| 6920 | vfree(fusion->ld_drv_map[i]); |
| 6921 | else |
| 6922 | free_pages((ulong)fusion->ld_drv_map[i], |
| 6923 | fusion->drv_map_pages); |
| 6924 | } |
| 6925 | |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 6926 | if (fusion->pd_seq_sync[i]) |
| 6927 | dma_free_coherent(&instance->pdev->dev, |
| 6928 | pd_seq_map_sz, |
| 6929 | fusion->pd_seq_sync[i], |
| 6930 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6931 | } |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6932 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6933 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6934 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6935 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6936 | if (instance->vf_affiliation) |
| 6937 | pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) * |
| 6938 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6939 | instance->vf_affiliation, |
| 6940 | instance->vf_affiliation_h); |
| 6941 | |
| 6942 | if (instance->vf_affiliation_111) |
| 6943 | pci_free_consistent(pdev, |
| 6944 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6945 | instance->vf_affiliation_111, |
| 6946 | instance->vf_affiliation_111_h); |
| 6947 | |
| 6948 | if (instance->hb_host_mem) |
| 6949 | pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 6950 | instance->hb_host_mem, |
| 6951 | instance->hb_host_mem_h); |
| 6952 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6953 | megasas_free_ctrl_dma_buffers(instance); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6954 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6955 | megasas_free_ctrl_mem(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6956 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6957 | scsi_host_put(host); |
| 6958 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6959 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | /** |
| 6963 | * megasas_shutdown - Shutdown entry point |
| 6964 | * @device: Generic device structure |
| 6965 | */ |
| 6966 | static void megasas_shutdown(struct pci_dev *pdev) |
| 6967 | { |
| 6968 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6969 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6970 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6971 | |
| 6972 | if (megasas_wait_for_adapter_operational(instance)) |
| 6973 | goto skip_firing_dcmds; |
| 6974 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6975 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 6976 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6977 | |
| 6978 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6979 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6980 | megasas_destroy_irqs(instance); |
| 6981 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6982 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6983 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | /** |
| 6987 | * megasas_mgmt_open - char node "open" entry point |
| 6988 | */ |
| 6989 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 6990 | { |
| 6991 | /* |
| 6992 | * Allow only those users with admin rights |
| 6993 | */ |
| 6994 | if (!capable(CAP_SYS_ADMIN)) |
| 6995 | return -EACCES; |
| 6996 | |
| 6997 | return 0; |
| 6998 | } |
| 6999 | |
| 7000 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7001 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 7002 | * |
| 7003 | * This function adds the calling process to a driver global queue. When an |
| 7004 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 7005 | */ |
| 7006 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 7007 | { |
| 7008 | int rc; |
| 7009 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7010 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7011 | |
| 7012 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 7013 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7014 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7015 | |
| 7016 | if (rc >= 0) { |
| 7017 | /* For sanity check when we get ioctl */ |
| 7018 | filep->private_data = filep; |
| 7019 | return 0; |
| 7020 | } |
| 7021 | |
| 7022 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 7023 | |
| 7024 | return rc; |
| 7025 | } |
| 7026 | |
| 7027 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7028 | * megasas_mgmt_poll - char node "poll" entry point |
| 7029 | * */ |
| 7030 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 7031 | { |
| 7032 | unsigned int mask; |
| 7033 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7034 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7035 | poll_wait(file, &megasas_poll_wait, wait); |
| 7036 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 7037 | if (megasas_poll_wait_aen) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7038 | mask = (POLLIN | POLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7039 | else |
| 7040 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7041 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7042 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 7043 | return mask; |
| 7044 | } |
| 7045 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7046 | /* |
| 7047 | * megasas_set_crash_dump_params_ioctl: |
| 7048 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 7049 | * @cmd: MFI command frame |
| 7050 | */ |
| 7051 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7052 | 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] | 7053 | { |
| 7054 | struct megasas_instance *local_instance; |
| 7055 | int i, error = 0; |
| 7056 | int crash_support; |
| 7057 | |
| 7058 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 7059 | |
| 7060 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7061 | local_instance = megasas_mgmt_info.instance[i]; |
| 7062 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7063 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7064 | MEGASAS_HBA_OPERATIONAL) && |
| 7065 | !megasas_set_crash_dump_params(local_instance, |
| 7066 | crash_support)) { |
| 7067 | local_instance->crash_dump_app_support = |
| 7068 | crash_support; |
| 7069 | dev_info(&local_instance->pdev->dev, |
| 7070 | "Application firmware crash " |
| 7071 | "dump mode set success\n"); |
| 7072 | error = 0; |
| 7073 | } else { |
| 7074 | dev_info(&local_instance->pdev->dev, |
| 7075 | "Application firmware crash " |
| 7076 | "dump mode set failed\n"); |
| 7077 | error = -1; |
| 7078 | } |
| 7079 | } |
| 7080 | } |
| 7081 | return error; |
| 7082 | } |
| 7083 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7084 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7085 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 7086 | * @instance: Adapter soft state |
| 7087 | * @argp: User's ioctl packet |
| 7088 | */ |
| 7089 | static int |
| 7090 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 7091 | struct megasas_iocpacket __user * user_ioc, |
| 7092 | struct megasas_iocpacket *ioc) |
| 7093 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7094 | struct megasas_sge64 *kern_sge64 = NULL; |
| 7095 | struct megasas_sge32 *kern_sge32 = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7096 | struct megasas_cmd *cmd; |
| 7097 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 7098 | dma_addr_t buf_handle = 0; |
| 7099 | int error = 0, i; |
| 7100 | void *sense = NULL; |
| 7101 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7102 | unsigned long *sense_ptr; |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7103 | u32 opcode = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7104 | |
| 7105 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 7106 | |
| 7107 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7108 | 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] | 7109 | ioc->sge_count, MAX_IOCTL_SGE); |
| 7110 | return -EINVAL; |
| 7111 | } |
| 7112 | |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7113 | if (ioc->frame.hdr.cmd >= MFI_CMD_OP_COUNT) { |
| 7114 | dev_err(&instance->pdev->dev, |
| 7115 | "Received invalid ioctl command 0x%x\n", |
| 7116 | ioc->frame.hdr.cmd); |
| 7117 | return -ENOTSUPP; |
| 7118 | } |
| 7119 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7120 | cmd = megasas_get_cmd(instance); |
| 7121 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7122 | 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] | 7123 | return -ENOMEM; |
| 7124 | } |
| 7125 | |
| 7126 | /* |
| 7127 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 7128 | * frames into our cmd's frames. cmd->frame's context will get |
| 7129 | * overwritten when we copy from user's frames. So set that value |
| 7130 | * alone separately |
| 7131 | */ |
| 7132 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7133 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7134 | cmd->frame->hdr.pad_0 = 0; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7135 | |
| 7136 | cmd->frame->hdr.flags &= (~MFI_FRAME_IEEE); |
| 7137 | |
| 7138 | if (instance->consistent_mask_64bit) |
| 7139 | cmd->frame->hdr.flags |= cpu_to_le16((MFI_FRAME_SGL64 | |
| 7140 | MFI_FRAME_SENSE64)); |
| 7141 | else |
| 7142 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_SGL64 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7143 | MFI_FRAME_SENSE64)); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7144 | |
| 7145 | if (cmd->frame->hdr.cmd == MFI_CMD_DCMD) |
| 7146 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7147 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7148 | if (opcode == MR_DCMD_CTRL_SHUTDOWN) { |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 7149 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) { |
| 7150 | megasas_return_cmd(instance, cmd); |
| 7151 | return -1; |
| 7152 | } |
| 7153 | } |
| 7154 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7155 | if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7156 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 7157 | megasas_return_cmd(instance, cmd); |
| 7158 | return error; |
| 7159 | } |
| 7160 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7161 | /* |
| 7162 | * The management interface between applications and the fw uses |
| 7163 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 7164 | * etc are accomplishes through different kinds of MFI frames. The |
| 7165 | * driver needs to care only about substituting user buffers with |
| 7166 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 7167 | * struct iocpacket itself. |
| 7168 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7169 | if (instance->consistent_mask_64bit) |
| 7170 | kern_sge64 = (struct megasas_sge64 *) |
| 7171 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 7172 | else |
| 7173 | kern_sge32 = (struct megasas_sge32 *) |
| 7174 | ((unsigned long)cmd->frame + ioc->sgl_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7175 | |
| 7176 | /* |
| 7177 | * For each user buffer, create a mirror buffer and copy in |
| 7178 | */ |
| 7179 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 7180 | if (!ioc->sgl[i].iov_len) |
| 7181 | continue; |
| 7182 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7183 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7184 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7185 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7186 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7187 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 7188 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7189 | error = -ENOMEM; |
| 7190 | goto out; |
| 7191 | } |
| 7192 | |
| 7193 | /* |
| 7194 | * We don't change the dma_coherent_mask, so |
| 7195 | * pci_alloc_consistent only returns 32bit addresses |
| 7196 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7197 | if (instance->consistent_mask_64bit) { |
| 7198 | kern_sge64[i].phys_addr = cpu_to_le64(buf_handle); |
| 7199 | kern_sge64[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 7200 | } else { |
| 7201 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 7202 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 7203 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7204 | |
| 7205 | /* |
| 7206 | * We created a kernel buffer corresponding to the |
| 7207 | * user buffer. Now copy in from the user buffer |
| 7208 | */ |
| 7209 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 7210 | (u32) (ioc->sgl[i].iov_len))) { |
| 7211 | error = -EFAULT; |
| 7212 | goto out; |
| 7213 | } |
| 7214 | } |
| 7215 | |
| 7216 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7217 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 7218 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7219 | if (!sense) { |
| 7220 | error = -ENOMEM; |
| 7221 | goto out; |
| 7222 | } |
| 7223 | |
| 7224 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7225 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7226 | if (instance->consistent_mask_64bit) |
| 7227 | *sense_ptr = cpu_to_le64(sense_handle); |
| 7228 | else |
| 7229 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7230 | } |
| 7231 | |
| 7232 | /* |
| 7233 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 7234 | * cmd to the SCSI mid-layer |
| 7235 | */ |
| 7236 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7237 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 7238 | cmd->sync_cmd = 0; |
| 7239 | dev_err(&instance->pdev->dev, |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7240 | "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 7241 | __func__, __LINE__, cmd->frame->hdr.cmd, opcode, |
| 7242 | cmd->cmd_status_drv); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7243 | return -EBUSY; |
| 7244 | } |
| 7245 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7246 | cmd->sync_cmd = 0; |
| 7247 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 7248 | if (instance->unload == 1) { |
| 7249 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 7250 | "don't submit data to application\n"); |
| 7251 | goto out; |
| 7252 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7253 | /* |
| 7254 | * copy out the kernel buffers to user buffers |
| 7255 | */ |
| 7256 | for (i = 0; i < ioc->sge_count; i++) { |
| 7257 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 7258 | ioc->sgl[i].iov_len)) { |
| 7259 | error = -EFAULT; |
| 7260 | goto out; |
| 7261 | } |
| 7262 | } |
| 7263 | |
| 7264 | /* |
| 7265 | * copy out the sense |
| 7266 | */ |
| 7267 | if (ioc->sense_len) { |
| 7268 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7269 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7270 | * sense buffer address |
| 7271 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7272 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 7273 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7274 | |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 7275 | if (copy_to_user((void __user *)((unsigned long) |
| 7276 | get_unaligned((unsigned long *)sense_ptr)), |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7277 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7278 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 7279 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7280 | error = -EFAULT; |
| 7281 | goto out; |
| 7282 | } |
| 7283 | } |
| 7284 | |
| 7285 | /* |
| 7286 | * copy the status codes returned by the fw |
| 7287 | */ |
| 7288 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 7289 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7290 | 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] | 7291 | error = -EFAULT; |
| 7292 | } |
| 7293 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7294 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7295 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7296 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7297 | sense, sense_handle); |
| 7298 | } |
| 7299 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7300 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7301 | if (kbuff_arr[i]) { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7302 | if (instance->consistent_mask_64bit) |
| 7303 | dma_free_coherent(&instance->pdev->dev, |
| 7304 | le32_to_cpu(kern_sge64[i].length), |
| 7305 | kbuff_arr[i], |
| 7306 | le64_to_cpu(kern_sge64[i].phys_addr)); |
| 7307 | else |
| 7308 | dma_free_coherent(&instance->pdev->dev, |
| 7309 | le32_to_cpu(kern_sge32[i].length), |
| 7310 | kbuff_arr[i], |
| 7311 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 7312 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7313 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7314 | } |
| 7315 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7316 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7317 | return error; |
| 7318 | } |
| 7319 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7320 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 7321 | { |
| 7322 | struct megasas_iocpacket __user *user_ioc = |
| 7323 | (struct megasas_iocpacket __user *)arg; |
| 7324 | struct megasas_iocpacket *ioc; |
| 7325 | struct megasas_instance *instance; |
| 7326 | int error; |
| 7327 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 7328 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 7329 | if (IS_ERR(ioc)) |
| 7330 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7331 | |
| 7332 | instance = megasas_lookup_instance(ioc->host_no); |
| 7333 | if (!instance) { |
| 7334 | error = -ENODEV; |
| 7335 | goto out_kfree_ioc; |
| 7336 | } |
| 7337 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7338 | /* Block ioctls in VF mode */ |
| 7339 | if (instance->requestorId && !allow_vf_ioctls) { |
| 7340 | error = -ENODEV; |
| 7341 | goto out_kfree_ioc; |
| 7342 | } |
| 7343 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7344 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7345 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7346 | error = -ENODEV; |
| 7347 | goto out_kfree_ioc; |
| 7348 | } |
| 7349 | |
| 7350 | if (instance->unload == 1) { |
| 7351 | error = -ENODEV; |
| 7352 | goto out_kfree_ioc; |
| 7353 | } |
| 7354 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7355 | if (down_interruptible(&instance->ioctl_sem)) { |
| 7356 | error = -ERESTARTSYS; |
| 7357 | goto out_kfree_ioc; |
| 7358 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7359 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 7360 | if (megasas_wait_for_adapter_operational(instance)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7361 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 7362 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7363 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7364 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7365 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7366 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7367 | up(&instance->ioctl_sem); |
| 7368 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7369 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7370 | kfree(ioc); |
| 7371 | return error; |
| 7372 | } |
| 7373 | |
| 7374 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 7375 | { |
| 7376 | struct megasas_instance *instance; |
| 7377 | struct megasas_aen aen; |
| 7378 | int error; |
| 7379 | |
| 7380 | if (file->private_data != file) { |
| 7381 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 7382 | "called first\n"); |
| 7383 | return -EINVAL; |
| 7384 | } |
| 7385 | |
| 7386 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 7387 | return -EFAULT; |
| 7388 | |
| 7389 | instance = megasas_lookup_instance(aen.host_no); |
| 7390 | |
| 7391 | if (!instance) |
| 7392 | return -ENODEV; |
| 7393 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7394 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7395 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7396 | } |
| 7397 | |
| 7398 | if (instance->unload == 1) { |
| 7399 | return -ENODEV; |
| 7400 | } |
| 7401 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 7402 | if (megasas_wait_for_adapter_operational(instance)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7403 | return -ENODEV; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7404 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7405 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7406 | error = megasas_register_aen(instance, aen.seq_num, |
| 7407 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7408 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7409 | return error; |
| 7410 | } |
| 7411 | |
| 7412 | /** |
| 7413 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 7414 | */ |
| 7415 | static long |
| 7416 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 7417 | { |
| 7418 | switch (cmd) { |
| 7419 | case MEGASAS_IOC_FIRMWARE: |
| 7420 | return megasas_mgmt_ioctl_fw(file, arg); |
| 7421 | |
| 7422 | case MEGASAS_IOC_GET_AEN: |
| 7423 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7424 | } |
| 7425 | |
| 7426 | return -ENOTTY; |
| 7427 | } |
| 7428 | |
| 7429 | #ifdef CONFIG_COMPAT |
| 7430 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 7431 | { |
| 7432 | struct compat_megasas_iocpacket __user *cioc = |
| 7433 | (struct compat_megasas_iocpacket __user *)arg; |
| 7434 | struct megasas_iocpacket __user *ioc = |
| 7435 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 7436 | int i; |
| 7437 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7438 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7439 | u32 local_sense_off; |
| 7440 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7441 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7442 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7443 | if (clear_user(ioc, sizeof(*ioc))) |
| 7444 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7445 | |
| 7446 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 7447 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 7448 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 7449 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 7450 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 7451 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 7452 | return -EFAULT; |
| 7453 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7454 | /* |
| 7455 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 7456 | * sense_len is not null, so prepare the 64bit value under |
| 7457 | * the same condition. |
| 7458 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7459 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 7460 | get_user(local_sense_len, &ioc->sense_len) || |
| 7461 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7462 | return -EFAULT; |
| 7463 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7464 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7465 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7466 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7467 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7468 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7469 | if (get_user(ptr, sense_cioc_ptr) || |
| 7470 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 7471 | return -EFAULT; |
| 7472 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7473 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7474 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7475 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 7476 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 7477 | copy_in_user(&ioc->sgl[i].iov_len, |
| 7478 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 7479 | return -EFAULT; |
| 7480 | } |
| 7481 | |
| 7482 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 7483 | |
| 7484 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 7485 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 7486 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 7487 | return -EFAULT; |
| 7488 | } |
| 7489 | return error; |
| 7490 | } |
| 7491 | |
| 7492 | static long |
| 7493 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 7494 | unsigned long arg) |
| 7495 | { |
| 7496 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 7497 | case MEGASAS_IOC_FIRMWARE32: |
| 7498 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7499 | case MEGASAS_IOC_GET_AEN: |
| 7500 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7501 | } |
| 7502 | |
| 7503 | return -ENOTTY; |
| 7504 | } |
| 7505 | #endif |
| 7506 | |
| 7507 | /* |
| 7508 | * File operations structure for management interface |
| 7509 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 7510 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7511 | .owner = THIS_MODULE, |
| 7512 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7513 | .fasync = megasas_mgmt_fasync, |
| 7514 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7515 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7516 | #ifdef CONFIG_COMPAT |
| 7517 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 7518 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 7519 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7520 | }; |
| 7521 | |
| 7522 | /* |
| 7523 | * PCI hotplug support registration structure |
| 7524 | */ |
| 7525 | static struct pci_driver megasas_pci_driver = { |
| 7526 | |
| 7527 | .name = "megaraid_sas", |
| 7528 | .id_table = megasas_pci_table, |
| 7529 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7530 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7531 | .suspend = megasas_suspend, |
| 7532 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7533 | .shutdown = megasas_shutdown, |
| 7534 | }; |
| 7535 | |
| 7536 | /* |
| 7537 | * Sysfs driver attributes |
| 7538 | */ |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7539 | static ssize_t version_show(struct device_driver *dd, char *buf) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7540 | { |
| 7541 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 7542 | MEGASAS_VERSION); |
| 7543 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7544 | static DRIVER_ATTR_RO(version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7545 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7546 | static ssize_t release_date_show(struct device_driver *dd, char *buf) |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7547 | { |
| 7548 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 7549 | MEGASAS_RELDATE); |
| 7550 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7551 | static DRIVER_ATTR_RO(release_date); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7552 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7553 | static ssize_t support_poll_for_event_show(struct device_driver *dd, char *buf) |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7554 | { |
| 7555 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 7556 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7557 | static DRIVER_ATTR_RO(support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7558 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7559 | static ssize_t support_device_change_show(struct device_driver *dd, char *buf) |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7560 | { |
| 7561 | return sprintf(buf, "%u\n", support_device_change); |
| 7562 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7563 | static DRIVER_ATTR_RO(support_device_change); |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7564 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7565 | static ssize_t dbg_lvl_show(struct device_driver *dd, char *buf) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7566 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7567 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7568 | } |
| 7569 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7570 | static ssize_t dbg_lvl_store(struct device_driver *dd, const char *buf, |
| 7571 | size_t count) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7572 | { |
| 7573 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7574 | |
| 7575 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7576 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 7577 | retval = -EINVAL; |
| 7578 | } |
| 7579 | return retval; |
| 7580 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7581 | static DRIVER_ATTR_RW(dbg_lvl); |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7582 | |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 7583 | static inline void megasas_remove_scsi_device(struct scsi_device *sdev) |
| 7584 | { |
| 7585 | sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n"); |
| 7586 | scsi_remove_device(sdev); |
| 7587 | scsi_device_put(sdev); |
| 7588 | } |
| 7589 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7590 | static void |
| 7591 | megasas_aen_polling(struct work_struct *work) |
| 7592 | { |
| 7593 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7594 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7595 | struct megasas_instance *instance = ev->instance; |
| 7596 | union megasas_evt_class_locale class_locale; |
| 7597 | struct Scsi_Host *host; |
| 7598 | struct scsi_device *sdev1; |
| 7599 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7600 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7601 | int i, j, doscan = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7602 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7603 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7604 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7605 | |
| 7606 | if (!instance) { |
| 7607 | printk(KERN_ERR "invalid instance!\n"); |
| 7608 | kfree(ev); |
| 7609 | return; |
| 7610 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7611 | |
| 7612 | /* Adjust event workqueue thread wait time for VF mode */ |
| 7613 | if (instance->requestorId) |
| 7614 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 7615 | |
| 7616 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7617 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7618 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7619 | instance->ev = NULL; |
| 7620 | host = instance->host; |
| 7621 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 7622 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7623 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7624 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7625 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7626 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7627 | case MR_EVT_PD_REMOVED: |
| 7628 | dcmd_ret = megasas_get_pd_list(instance); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7629 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7630 | doscan = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7631 | break; |
| 7632 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7633 | case MR_EVT_LD_OFFLINE: |
| 7634 | case MR_EVT_CFG_CLEARED: |
| 7635 | case MR_EVT_LD_DELETED: |
| 7636 | case MR_EVT_LD_CREATED: |
| 7637 | if (!instance->requestorId || |
| 7638 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7639 | 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] | 7640 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7641 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7642 | doscan = SCAN_VD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7643 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7644 | break; |
| 7645 | |
| 7646 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 7647 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 7648 | case MR_EVT_LD_STATE_CHANGE: |
| 7649 | dcmd_ret = megasas_get_pd_list(instance); |
| 7650 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7651 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7652 | break; |
| 7653 | |
| 7654 | if (!instance->requestorId || |
| 7655 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7656 | dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 7657 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7658 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7659 | break; |
| 7660 | |
| 7661 | doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL; |
| 7662 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 7663 | instance->host->host_no); |
| 7664 | break; |
| 7665 | |
| 7666 | case MR_EVT_CTRL_PROP_CHANGED: |
| 7667 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 7668 | break; |
| 7669 | default: |
| 7670 | doscan = 0; |
| 7671 | break; |
| 7672 | } |
| 7673 | } else { |
| 7674 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 7675 | mutex_unlock(&instance->reset_mutex); |
| 7676 | kfree(ev); |
| 7677 | return; |
| 7678 | } |
| 7679 | |
| 7680 | mutex_unlock(&instance->reset_mutex); |
| 7681 | |
| 7682 | if (doscan & SCAN_PD_CHANNEL) { |
| 7683 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 7684 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7685 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7686 | sdev1 = scsi_device_lookup(host, i, j, 0); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7687 | if (instance->pd_list[pd_index].driveState == |
| 7688 | MR_PD_STATE_SYSTEM) { |
| 7689 | if (!sdev1) |
| 7690 | scsi_add_device(host, i, j, 0); |
| 7691 | else |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7692 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7693 | } else { |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 7694 | if (sdev1) |
| 7695 | megasas_remove_scsi_device(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7696 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7697 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7698 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7699 | } |
| 7700 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7701 | if (doscan & SCAN_VD_CHANNEL) { |
| 7702 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 7703 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7704 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 7705 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7706 | if (instance->ld_ids[ld_index] != 0xff) { |
| 7707 | if (!sdev1) |
| 7708 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7709 | else |
| 7710 | scsi_device_put(sdev1); |
| 7711 | } else { |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 7712 | if (sdev1) |
| 7713 | megasas_remove_scsi_device(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7714 | } |
| 7715 | } |
| 7716 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7717 | } |
| 7718 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7719 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7720 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 7721 | else |
| 7722 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7723 | |
| 7724 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 7725 | class_locale.members.reserved = 0; |
| 7726 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 7727 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7728 | |
| 7729 | if (instance->aen_cmd != NULL) { |
| 7730 | kfree(ev); |
| 7731 | return; |
| 7732 | } |
| 7733 | |
| 7734 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7735 | error = megasas_register_aen(instance, seq_num, |
| 7736 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7737 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7738 | dev_err(&instance->pdev->dev, |
| 7739 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7740 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7741 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7742 | kfree(ev); |
| 7743 | } |
| 7744 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7745 | /** |
| 7746 | * megasas_init - Driver load entry point |
| 7747 | */ |
| 7748 | static int __init megasas_init(void) |
| 7749 | { |
| 7750 | int rval; |
| 7751 | |
| 7752 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 7753 | * Booted in kdump kernel, minimize memory footprints by |
| 7754 | * disabling few features |
| 7755 | */ |
| 7756 | if (reset_devices) { |
| 7757 | msix_vectors = 1; |
| 7758 | rdpq_enable = 0; |
| 7759 | dual_qdepth_disable = 1; |
| 7760 | } |
| 7761 | |
| 7762 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7763 | * Announce driver version and other information |
| 7764 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 7765 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7766 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 7767 | spin_lock_init(&poll_aen_lock); |
| 7768 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7769 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7770 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7771 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7772 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 7773 | |
| 7774 | /* |
| 7775 | * Register character device node |
| 7776 | */ |
| 7777 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 7778 | |
| 7779 | if (rval < 0) { |
| 7780 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 7781 | return rval; |
| 7782 | } |
| 7783 | |
| 7784 | megasas_mgmt_majorno = rval; |
| 7785 | |
| 7786 | /* |
| 7787 | * Register ourselves as PCI hotplug module |
| 7788 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 7789 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7790 | |
| 7791 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 7792 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7793 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7794 | } |
| 7795 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7796 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7797 | &driver_attr_version); |
| 7798 | if (rval) |
| 7799 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7800 | |
| 7801 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7802 | &driver_attr_release_date); |
| 7803 | if (rval) |
| 7804 | goto err_dcf_rel_date; |
| 7805 | |
| 7806 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7807 | &driver_attr_support_poll_for_event); |
| 7808 | if (rval) |
| 7809 | goto err_dcf_support_poll_for_event; |
| 7810 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7811 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7812 | &driver_attr_dbg_lvl); |
| 7813 | if (rval) |
| 7814 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7815 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7816 | &driver_attr_support_device_change); |
| 7817 | if (rval) |
| 7818 | goto err_dcf_support_device_change; |
| 7819 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7820 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7821 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7822 | err_dcf_support_device_change: |
| 7823 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7824 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7825 | err_dcf_dbg_lvl: |
| 7826 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7827 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7828 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7829 | driver_remove_file(&megasas_pci_driver.driver, |
| 7830 | &driver_attr_release_date); |
| 7831 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7832 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 7833 | err_dcf_attr_ver: |
| 7834 | pci_unregister_driver(&megasas_pci_driver); |
| 7835 | err_pcidrv: |
| 7836 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 7837 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | /** |
| 7841 | * megasas_exit - Driver unload entry point |
| 7842 | */ |
| 7843 | static void __exit megasas_exit(void) |
| 7844 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7845 | driver_remove_file(&megasas_pci_driver.driver, |
| 7846 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7847 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7848 | &driver_attr_support_poll_for_event); |
| 7849 | driver_remove_file(&megasas_pci_driver.driver, |
| 7850 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7851 | driver_remove_file(&megasas_pci_driver.driver, |
| 7852 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7853 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7854 | |
| 7855 | pci_unregister_driver(&megasas_pci_driver); |
| 7856 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 7857 | } |
| 7858 | |
| 7859 | module_init(megasas_init); |
| 7860 | module_exit(megasas_exit); |